From 2b0bcd40eaabe7fe1f89a3369792d647cafc2c96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ca=CC=86ta=CC=86lin=20Stan?= Date: Fri, 18 Jun 2021 23:08:35 +0200 Subject: [PATCH] Add tests for `memoryPhysicalFootprint` and `memoryPhysicalFootprintString` --- .../CSSystemInfoHelper/CSSystemInfoHelper.h | 6 +- .../Sources/CSSystemInfoHelper.m | 12 +- .../CSSystemInfoHelperTests.m | 160 ++++++++++++++++-- .../CSSystemInfoProviderMock.h | 2 + .../CSSystemInfoProviderMock.m | 32 ++++ 5 files changed, 191 insertions(+), 21 deletions(-) diff --git a/CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h b/CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h index ebc31f3..7aae0ab 100644 --- a/CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h +++ b/CSSystemInfoHelper/Headers/CSSystemInfoHelper/CSSystemInfoHelper.h @@ -74,11 +74,11 @@ FOUNDATION_EXPORT NSString * const CSSystemInfoHelperIPAddressNone DEPRECATED_AT /// Gets the physical memory footprint size of the process, as reported by /// @c task_info // @see https://www.gnu.org/software/hurd/gnumach-doc/Task-Information.html -@property (nonatomic, readonly) vm_size_t memotyPhysicalFootprint; +@property (nonatomic, readonly) vm_size_t memoryPhysicalFootprint; /// A human-readable, formatted byte count string. from the value returned by -/// @c -memotyPhysicalFootprint -@property (nonatomic, readonly, copy) NSString *memotyPhysicalFootprintString; +/// @c -memoryPhysicalFootprint +@property (nonatomic, readonly, copy) NSString *memoryPhysicalFootprintString; /// @name UUID of the current device diff --git a/CSSystemInfoHelper/Sources/CSSystemInfoHelper.m b/CSSystemInfoHelper/Sources/CSSystemInfoHelper.m index 467d384..8568e18 100644 --- a/CSSystemInfoHelper/Sources/CSSystemInfoHelper.m +++ b/CSSystemInfoHelper/Sources/CSSystemInfoHelper.m @@ -118,18 +118,18 @@ - (NSString *)memoryUsageString { return [self formatByteCount:self.memoryUsage]; } -- (vm_size_t)memotyPhysicalFootprint { +- (vm_size_t)memoryPhysicalFootprint { NSError *error; - vm_size_t memotyPhysicalFootprint = 0; - if (![self.systemInfoProvider getPhysFootprint:&memotyPhysicalFootprint error:&error]) { + vm_size_t memoryPhysicalFootprint = 0; + if (![self.systemInfoProvider getPhysFootprint:&memoryPhysicalFootprint error:&error]) { NSLog(@"Error getting physical memory footprint: %@. %@.", error.localizedDescription, error.localizedFailureReason); return 0; } - return memotyPhysicalFootprint; + return memoryPhysicalFootprint; } -- (NSString *)memotyPhysicalFootprintString { - return [self formatByteCount:self.memotyPhysicalFootprint]; +- (NSString *)memoryPhysicalFootprintString { + return [self formatByteCount:self.memoryPhysicalFootprint]; } #if TARGET_OS_OSX diff --git a/CSSystemInfoHelperTests/CSSystemInfoHelperTests.m b/CSSystemInfoHelperTests/CSSystemInfoHelperTests.m index ef80de6..2731bca 100644 --- a/CSSystemInfoHelperTests/CSSystemInfoHelperTests.m +++ b/CSSystemInfoHelperTests/CSSystemInfoHelperTests.m @@ -17,6 +17,8 @@ @interface CSSystemInfoHelperTests : XCTestCase @implementation CSSystemInfoHelperTests +#pragma mark - sharedHelper + - (void)test_sharedHelper_ShouldNotBeNil { XCTAssertNotNil([CSSystemInfoHelper sharedHelper]); } @@ -27,6 +29,8 @@ - (void)test_sharedHelper_IsSigleton { XCTAssertEqual(helper1.hash, helper2.hash); } +#pragma mark - networkInterfaces + - (void)test_networkInterfaces_withFailingSystemInfoProvider_ShouldBeNil { CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -42,6 +46,8 @@ - (void)test_networkInterfaces_withSucceedingSystemInfoProvider_ShouldReturnProv XCTAssertEqual(expectedInterfaces, helper.networkInterfaces); } +#pragma mark - systemInfo + - (void)test_SystemInfo_DoesNotThow { CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:nil]; XCTAssertNoThrow(helper.systemInfo); @@ -67,6 +73,8 @@ - (void)test_SystemInfo_AllKeys_ShouldNotBeEmpty { XCTAssertGreaterThan(helper.systemInfo[CSSystemInfoKeyMachine].length, 0, @"The key CSSystemInfoKeyMachine is empty"); } +#pragma mark - systemInfoString + - (void)test_SystemInfoString_DoesNotThrow { CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:nil]; XCTAssertNoThrow(helper.systemInfoString); @@ -82,6 +90,8 @@ - (void)test_SystemInfoString_ShouldNotBeEmpty { XCTAssertGreaterThan(helper.systemInfoString.length, 0); } +#pragma mark - systemVersionString + - (void)test_SystemVersionString_DoesNotThrow { CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:nil]; XCTAssertNoThrow(helper.systemVersionString); @@ -97,6 +107,8 @@ - (void)test_SystemVersionString_ShouldNotBeEmpty { XCTAssertGreaterThan(helper.systemVersionString.length, 0); } +#pragma mark - memoryUsage + - (void)test_memoryUsage_withFailingSystemInfoProvider_ShouldBeZero { CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -120,35 +132,37 @@ - (void)test_memoryUsage_withSucceedingSystemInfoProvider_ShouldReturnProvidedVa XCTAssertEqual(helper.memoryUsage, residentSize); } -- (void)test_MemoryUsageString_withFailingSystemInfoProvider_DoesNotThrow { +#pragma mark - memoryUsageString + +- (void)test_memoryUsageString_withFailingSystemInfoProvider_DoesNotThrow { CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; XCTAssertNoThrow(helper.memoryUsageString); } -- (void)test_MemoryUsageString_withFailingSystemInfoProvider_ShouldNotBeNil { +- (void)test_memoryUsageString_withFailingSystemInfoProvider_ShouldNotBeNil { CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; XCTAssertNotNil(helper.memoryUsageString); } -- (void)test_MemoryUsageString_withFailingSystemInfoProvider_ShouldNotBeEmpty { +- (void)test_memoryUsageString_withFailingSystemInfoProvider_ShouldNotBeEmpty { CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; XCTAssertGreaterThan(helper.memoryUsageString.length, 0); } -- (void)test_MemoryUsageString_withFailingSystemInfoProvider_ShouldEvnaluateTo0 { +- (void)test_memoryUsageString_withFailingSystemInfoProvider_ShouldEvnaluateTo0 { CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; XCTAssertEqual(helper.memoryUsageString.integerValue, 0); } -- (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_DoesNotThrow { +- (void)test_memoryUsageString_withFailingSystemInfoProviderThatReturnsValue_DoesNotThrow { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithResidentSize:&residentSize error:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -156,7 +170,7 @@ - (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_Doe XCTAssertNoThrow(helper.memoryUsageString); } -- (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_ShouldNotBeNil { +- (void)test_memoryUsageString_withFailingSystemInfoProviderThatReturnsValue_ShouldNotBeNil { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithResidentSize:&residentSize error:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -164,7 +178,7 @@ - (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_Sho XCTAssertNotNil(helper.memoryUsageString); } -- (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_ShouldNotBeEmpty { +- (void)test_memoryUsageString_withFailingSystemInfoProviderThatReturnsValue_ShouldNotBeEmpty { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithResidentSize:&residentSize error:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -172,7 +186,7 @@ - (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_Sho XCTAssertGreaterThan(helper.memoryUsageString.length, 0); } -- (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_ShouldEvnaluateTo0 { +- (void)test_memoryUsageString_withFailingSystemInfoProviderThatReturnsValue_ShouldEvnaluateTo0 { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithResidentSize:&residentSize error:nil]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -180,7 +194,7 @@ - (void)test_MemoryUsageString_withFailingSystemInfoProviderThatReturnsValue_Sho XCTAssertEqual(helper.memoryUsageString.integerValue, 0); } -- (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_DoesNotThrow { +- (void)test_memoryUsageString_withSucceedingSystemInfoProvider_DoesNotThrow { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithResidentSize:&residentSize]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -188,7 +202,7 @@ - (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_DoesNotThrow { XCTAssertNoThrow(helper.memoryUsageString); } -- (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_ShouldNotBeNil { +- (void)test_memoryUsageString_withSucceedingSystemInfoProvider_ShouldNotBeNil { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithResidentSize:&residentSize]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -196,7 +210,7 @@ - (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_ShouldNotBeNil { XCTAssertNotNil(helper.memoryUsageString); } -- (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_ShouldNotBeEmpty { +- (void)test_memoryUsageString_withSucceedingSystemInfoProvider_ShouldNotBeEmpty { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithResidentSize:&residentSize]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -204,7 +218,7 @@ - (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_ShouldNotBeEmpty XCTAssertGreaterThan(helper.memoryUsageString.length, 0); } -- (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_ShouldReturnFormattedProvidedValue { +- (void)test_memoryUsageString_withSucceedingSystemInfoProvider_ShouldReturnFormattedProvidedValue { vm_size_t residentSize = arc4random(); CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithResidentSize:&residentSize]; CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; @@ -213,6 +227,128 @@ - (void)test_MemoryUsageString_withSucceedingSystemInfoProvider_ShouldReturnForm XCTAssertEqualObjects(helper.memoryUsageString, expectedString); } +#pragma mark - memoryPhysicalFootprint + +- (void)test_memoryPhysicalFootprint_withFailingSystemInfoProvider_ShouldBeZero { + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertEqual(helper.memoryPhysicalFootprint, 0); +} + +- (void)test_memoryPhysicalFootprint_withFailingSystemInfoProviderThatReturnsValue_ShouldBeZero { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithPhysFootprint:&physFootprint error:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertEqual(helper.memoryPhysicalFootprint, 0); +} + +- (void)test_memoryPhysicalFootprint_withSucceedingSystemInfoProvider_ShouldReturnProvidedValue { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithPhysFootprint:&physFootprint]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertEqual(helper.memoryPhysicalFootprint, physFootprint); +} + +#pragma mark - memoryPhysicalFootprintString + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProvider_DoesNotThrow { + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertNoThrow(helper.memoryPhysicalFootprintString); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProvider_ShouldNotBeNil { + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertNotNil(helper.memoryPhysicalFootprintString); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProvider_ShouldNotBeEmpty { + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertGreaterThan(helper.memoryPhysicalFootprintString.length, 0); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProvider_ShouldEvnaluateTo0 { + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithError:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertEqual(helper.memoryPhysicalFootprintString.integerValue, 0); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProviderThatReturnsValue_DoesNotThrow { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithPhysFootprint:&physFootprint error:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertNoThrow(helper.memoryPhysicalFootprintString); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProviderThatReturnsValue_ShouldNotBeNil { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithPhysFootprint:&physFootprint error:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertNotNil(helper.memoryPhysicalFootprintString); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProviderThatReturnsValue_ShouldNotBeEmpty { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithPhysFootprint:&physFootprint error:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertGreaterThan(helper.memoryPhysicalFootprintString.length, 0); +} + +- (void)test_memoryPhysicalFootprintString_withFailingSystemInfoProviderThatReturnsValue_ShouldEvnaluateTo0 { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock failingProviderWithPhysFootprint:&physFootprint error:nil]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertEqual(helper.memoryPhysicalFootprintString.integerValue, 0); +} + +- (void)test_memoryPhysicalFootprintString_withSucceedingSystemInfoProvider_DoesNotThrow { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithPhysFootprint:&physFootprint]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertNoThrow(helper.memoryPhysicalFootprintString); +} + +- (void)test_memoryPhysicalFootprintString_withSucceedingSystemInfoProvider_ShouldNotBeNil { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithPhysFootprint:&physFootprint]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertNotNil(helper.memoryPhysicalFootprintString); +} + +- (void)test_memoryPhysicalFootprintString_withSucceedingSystemInfoProvider_ShouldNotBeEmpty { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithPhysFootprint:&physFootprint]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + + XCTAssertGreaterThan(helper.memoryPhysicalFootprintString.length, 0); +} + +- (void)test_memoryPhysicalFootprintString_withSucceedingSystemInfoProvider_ShouldReturnFormattedProvidedValue { + vm_size_t physFootprint = arc4random(); + CSSystemInfoProviderMock *provider = [CSSystemInfoProviderMock succeedingProviderWithPhysFootprint:&physFootprint]; + CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:provider]; + NSString *expectedString = [helper formatByteCount:physFootprint]; + + XCTAssertEqualObjects(helper.memoryPhysicalFootprintString, expectedString); +} + +#pragma mark - platformUUID + #if TARGET_OS_OSX - (void)test_PlatformUUID_DoesNotThrow { CSSystemInfoHelper *helper = [[CSSystemInfoHelper alloc] initWithSystemInfoProvider:nil]; diff --git a/CSSystemInfoHelperTests/CSSystemInfoProviderMock.h b/CSSystemInfoHelperTests/CSSystemInfoProviderMock.h index ef9a0bb..cde2607 100644 --- a/CSSystemInfoHelperTests/CSSystemInfoProviderMock.h +++ b/CSSystemInfoHelperTests/CSSystemInfoProviderMock.h @@ -14,9 +14,11 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)failingProviderWithError:(NSError *_Nullable)error; + (instancetype)failingProviderWithResidentSize:(vm_size_t * _Nullable)residentSize error:(NSError *_Nullable)error; ++ (instancetype)failingProviderWithPhysFootprint:(vm_size_t * _Nullable)physFootprint error:(NSError *_Nullable)error; + (instancetype)succeedingProviderWithNetworkInterfaces:(NSArray *)networkInterfaces; + (instancetype)succeedingProviderWithResidentSize:(vm_size_t *)residentSize; ++ (instancetype)succeedingProviderWithPhysFootprint:(vm_size_t *)physFootprint; @end diff --git a/CSSystemInfoHelperTests/CSSystemInfoProviderMock.m b/CSSystemInfoHelperTests/CSSystemInfoProviderMock.m index 5d3d01b..dbbeb69 100644 --- a/CSSystemInfoHelperTests/CSSystemInfoProviderMock.m +++ b/CSSystemInfoHelperTests/CSSystemInfoProviderMock.m @@ -14,6 +14,7 @@ @interface CSSystemInfoProviderMock () @property NSError *error; @property NSArray *networkInterfaces; @property vm_size_t *residentSize; +@property vm_size_t *physFootprint; @end @@ -34,6 +35,15 @@ + (instancetype)failingProviderWithResidentSize:(vm_size_t *)residentSize error: return provider; } ++ (instancetype)failingProviderWithPhysFootprint:(vm_size_t *)physFootprint error:(NSError *)error { + CSSystemInfoProviderMock * provider = [CSSystemInfoProviderMock new]; + provider.shouldSucceed = NO; + provider.error = error; + provider.physFootprint = physFootprint; + return provider; + +} + + (instancetype)succeedingProviderWithNetworkInterfaces:(NSArray *)networkInterfaces { CSSystemInfoProviderMock * provider = [CSSystemInfoProviderMock new]; provider.shouldSucceed = YES; @@ -48,6 +58,13 @@ + (instancetype)succeedingProviderWithResidentSize:(vm_size_t *)residentSize { return provider; } ++ (instancetype)succeedingProviderWithPhysFootprint:(vm_size_t *)physFootprint { + CSSystemInfoProviderMock * provider = [CSSystemInfoProviderMock new]; + provider.shouldSucceed = YES; + provider.physFootprint = physFootprint; + return provider; +} + #pragma mark - CSSystemInfoProviderProtocol - (nullable NSArray *)queryNetworkInterfaces:(NSError *__autoreleasing _Nullable * _Nullable)error { @@ -76,5 +93,20 @@ - (BOOL)getResidentSize:(nonnull vm_size_t *)residentSize error:(NSError *__auto return YES; } +-(BOOL)getPhysFootprint:(vm_size_t *)physFootprint error:(NSError *__autoreleasing _Nullable *)error { + if (self.physFootprint) { + *physFootprint = *(self.physFootprint); + } + + if (!self.shouldSucceed) { + if (error) { + *error = self.error; + } + return NO; + } + + return YES; +} + @end