diff --git a/tests/unittests/obj-c/ODWLogConfigurationTests.mm b/tests/unittests/obj-c/ODWLogConfigurationTests.mm index e20550932..ea6df957b 100644 --- a/tests/unittests/obj-c/ODWLogConfigurationTests.mm +++ b/tests/unittests/obj-c/ODWLogConfigurationTests.mm @@ -10,6 +10,7 @@ #import #import "ODWLogConfiguration.h" +#import "ODWLogConfiguration_private.h" #include "LogManager.hpp" using namespace Microsoft::Applications::Events; @@ -61,4 +62,22 @@ - (void)testSetHost { XCTAssertEqualObjects(config.host, @"testHost"); } +- (void)testConfigurationCopiesRemainIndependent { + ODWLogConfiguration *first = [ODWLogConfiguration getLogConfigurationCopy]; + [first set:@"copyIsolation" withValue:@"first"]; + [first setHost:@"firstHost"]; + + ODWLogConfiguration *second = [ODWLogConfiguration getLogConfigurationCopy]; + [second set:@"copyIsolation" withValue:@"second"]; + [second setHost:@"secondHost"]; + + XCTAssertEqualObjects([first valueForKey:@"copyIsolation"], @"first"); + XCTAssertEqualObjects(first.host, @"firstHost"); + XCTAssertEqualObjects([second valueForKey:@"copyIsolation"], @"second"); + XCTAssertEqualObjects(second.host, @"secondHost"); + + ODWLogConfiguration *third = [ODWLogConfiguration getLogConfigurationCopy]; + XCTAssertFalse([third getWrappedConfiguration]->HasConfig("copyIsolation")); +} + @end diff --git a/wrappers/obj-c/ODWLogConfiguration.mm b/wrappers/obj-c/ODWLogConfiguration.mm index 611b92940..53945a1ab 100644 --- a/wrappers/obj-c/ODWLogConfiguration.mm +++ b/wrappers/obj-c/ODWLogConfiguration.mm @@ -7,6 +7,7 @@ #import "ODWLogConfiguration_private.h" #import "ODWLogger_private.h" #import "LogManager.hpp" +#include using namespace Microsoft::Applications::Events; @@ -293,24 +294,26 @@ The minimum time (ms) between storage full notifications. NSString *const ODWCFG_BOOL_SESSION_RESET_ENABLED = @"sessionResetEnabled"; @implementation ODWLogConfiguration +{ + std::unique_ptr _wrappedConfiguration; +} static bool _enableTrace; static bool _enableConsoleLogging; static bool _enableSessionReset; static bool _surfaceCppExceptions; - ILogConfiguration* _wrappedConfiguration; -(instancetype)initWithILogConfiguration:(ILogConfiguration*)config { self = [super init]; if(self) { - _wrappedConfiguration = config; + _wrappedConfiguration.reset(config); } return self; } -(nullable ILogConfiguration*)getWrappedConfiguration { - return _wrappedConfiguration; + return _wrappedConfiguration.get(); } +(nullable ODWLogConfiguration *)getLogConfigurationCopy diff --git a/wrappers/obj-c/ODWLogConfiguration_private.h b/wrappers/obj-c/ODWLogConfiguration_private.h index 63607f6dd..ba7d367c8 100644 --- a/wrappers/obj-c/ODWLogConfiguration_private.h +++ b/wrappers/obj-c/ODWLogConfiguration_private.h @@ -16,7 +16,7 @@ using namespace MAT; @interface ODWLogConfiguration (Private) /*! - @brief Constructs an ODWLogConfiguration object, taking internal API config pointer. This method might be only used internally by wrapper. + @brief Constructs an ODWLogConfiguration object, taking ownership of the internal API config pointer. This method might be only used internally by wrapper. */ -(instancetype)initWithILogConfiguration:(ILogConfiguration*)config;