Skip to content

Commit

Permalink
[core] Flesh out the NIOperation tests to 100% coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
jverkoey committed Jan 27, 2012
1 parent 924d6c0 commit d1ca7db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Nimbus.xcodeproj/project.pbxproj
Expand Up @@ -32,6 +32,7 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
6607851C14D245BF00FE3283 /* NINetworkActivityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6607851B14D245BE00FE3283 /* NINetworkActivityTests.m */; };
6623EB6D1402ECE400E0E61A /* NITableViewModelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6623EB6C1402ECE400E0E61A /* NITableViewModelTests.m */; };
6623EB721402EDB100E0E61A /* libNimbusCore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 66A03C0913E6E85E00B514F3 /* libNimbusCore.a */; };
6626330C14995C4600B99898 /* NITableViewModel+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6626330B14995C4600B99898 /* NITableViewModel+Private.h */; };
Expand Down Expand Up @@ -582,6 +583,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
6607851B14D245BE00FE3283 /* NINetworkActivityTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NINetworkActivityTests.m; sourceTree = "<group>"; };
6623EB6C1402ECE400E0E61A /* NITableViewModelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NITableViewModelTests.m; sourceTree = "<group>"; };
6626330B14995C4600B99898 /* NITableViewModel+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NITableViewModel+Private.h"; sourceTree = "<group>"; };
66325D5613EB0301008D6EAD /* HACKERS.mdown */ = {isa = PBXFileReference; lastKnownFileType = text; name = HACKERS.mdown; path = ../HACKERS.mdown; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1626,6 +1628,7 @@
66A03CA213E6E90500B514F3 /* NIFoundationMethodsTests.m */,
66A03CA313E6E90500B514F3 /* NIMemoryCacheTests.m */,
FD01BED414179AAC0023D783 /* NINavigationAppearanceTests.m */,
6607851B14D245BE00FE3283 /* NINetworkActivityTests.m */,
66A03CA413E6E90500B514F3 /* NINonEmptyCollectionTestingTests.m */,
66A03CA513E6E90500B514F3 /* NINonRetainingCollectionsTests.m */,
66A03CA613E6E90500B514F3 /* NIOperationsTests.m */,
Expand Down Expand Up @@ -3243,6 +3246,7 @@
FD01BED814179AB60023D783 /* NINavigationAppearanceTests.m in Sources */,
6675E4BC145603DA007D172F /* NIViewRecyclerTests.m in Sources */,
66E8CED214D089E500600592 /* NICommonMetricsTests.m in Sources */,
6607851C14D245BF00FE3283 /* NINetworkActivityTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/NIOperations.m
Expand Up @@ -90,7 +90,7 @@ - (void)main {
[self operationDidFinish];
}

} else {
} else { // COV_NF_START
// Load the image from the network then.
[self operationDidStart];

Expand All @@ -112,7 +112,7 @@ - (void)main {

[self operationWillFinish];
[self operationDidFinish];
}
} // COV_NF_END
}

NI_RELEASE_SAFELY(pool);
Expand Down
21 changes: 20 additions & 1 deletion src/core/unittests/NIOperationsTests.m
Expand Up @@ -67,6 +67,9 @@ - (void)testReadFileFromDiskInitialization {
isDirectory:NO]]
autorelease];

op.tag = 5;
STAssertEquals(op.tag, 5, @"Tag should still be the same.");

STAssertNil(op.data, @"Data should be nil to start.");
}

Expand All @@ -84,6 +87,7 @@ - (void)testReadFileFromDisk {
[queue waitUntilAllOperationsAreFinished];

STAssertNotNil(op.data, @"Data should have been read from the image.");
STAssertNil(op.processedObject, @"Should not be any processed object.");

UIImage* image = [[[UIImage alloc] initWithData:op.data] autorelease];

Expand Down Expand Up @@ -125,11 +129,14 @@ - (void)testReadFileFromDiskWithDelegateSuccess {
// Run the operation synchronously.
[op main];

STAssertEquals([_delegateMethodsCalled count], (NSUInteger)2,
STAssertEquals([_delegateMethodsCalled count], (NSUInteger)3,
@"Start and finish should have been called.");
STAssertTrue([_delegateMethodsCalled containsObject:
NSStringFromSelector(@selector(operationDidStart:))],
@"operationDidStart: should have been called.");
STAssertTrue([_delegateMethodsCalled containsObject:
NSStringFromSelector(@selector(operationWillFinish:))],
@"operationWillFinish: should have been called.");
STAssertTrue([_delegateMethodsCalled containsObject:
NSStringFromSelector(@selector(operationDidFinish:))],
@"operationDidFinish: should have been called.");
Expand Down Expand Up @@ -176,12 +183,17 @@ - (void)testReadFileFromDiskWithBlocksSuccess {
autorelease];

__block BOOL didStart = NO;
__block BOOL willFinish = NO;
__block BOOL didFinish = NO;

op.didStartBlock = ^(NIOperation* blockOp) {
didStart = YES;
};

op.willFinishBlock = ^(NIOperation* blockOp) {
willFinish = YES;
};

op.didFinishBlock = ^(NIOperation* blockOp) {
didFinish = YES;
};
Expand All @@ -190,6 +202,7 @@ - (void)testReadFileFromDiskWithBlocksSuccess {
[op main];

STAssertTrue(didStart, @"didStartBlock should have been called.");
STAssertTrue(willFinish, @"willFinishBlock should have been called.");
STAssertTrue(didFinish, @"didFinishBlock should have been called.");
}

Expand Down Expand Up @@ -241,6 +254,12 @@ - (void)operationDidStart:(NSOperation *)operation {
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)operationWillFinish:(NSOperation *)operation {
[_delegateMethodsCalled addObject:NSStringFromSelector(_cmd)];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)operationDidFinish:(NSOperation *)operation {
[_delegateMethodsCalled addObject:NSStringFromSelector(_cmd)];
Expand Down

0 comments on commit d1ca7db

Please sign in to comment.