Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit f434192

Browse files
Adlai Hollerappleguy
authored andcommitted
[Tests] Two Minor Cleanups (#1977)
* [Tests] Use XCTestExpectation instead of rolling our own in ASMultiplexImageNode * [Tests] Remove do-nothing ASCollectionView test method
1 parent a79c69a commit f434192

2 files changed

Lines changed: 2 additions & 53 deletions

File tree

AsyncDisplayKitTests/ASCollectionViewTests.mm

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,6 @@ - (void)testThatRegisteringASupplementaryNodeStoresItForIntrospection
142142
XCTAssertEqualObjects([collectionView supplementaryNodeKindsInDataController:nil], @[UICollectionElementKindSectionHeader]);
143143
}
144144

145-
- (void)testCollectionViewController
146-
{
147-
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];
148-
149-
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
150-
[containerView addSubview:testController.view];
151-
152-
[testController.collectionView reloadData];
153-
154-
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
155-
}
156-
157145
- (void)testSelection
158146
{
159147
ASCollectionViewTestController *testController = [[ASCollectionViewTestController alloc] initWithNibName:nil bundle:nil];

AsyncDisplayKitTests/ASMultiplexImageNodeTests.m

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -45,42 +45,6 @@ - (UIImage *)_testImage
4545
return [[[UIImage alloc] initWithContentsOfFile:[self _testImageURL].path] autorelease];
4646
}
4747

48-
static BOOL ASInvokeConditionBlockWithBarriers(BOOL (^block)()) {
49-
// In case the block does multiple comparisons, ensure it has a consistent view of memory by issuing read-write
50-
// barriers on either side of the block.
51-
OSMemoryBarrier();
52-
BOOL result = block();
53-
OSMemoryBarrier();
54-
return result;
55-
}
56-
57-
static BOOL ASRunRunLoopUntilBlockIsTrue(BOOL (^block)())
58-
{
59-
// Time out after 30 seconds.
60-
CFTimeInterval timeoutDate = CACurrentMediaTime() + 30.0f;
61-
BOOL passed = NO;
62-
63-
while (true) {
64-
passed = ASInvokeConditionBlockWithBarriers(block);
65-
66-
if (passed) {
67-
break;
68-
}
69-
70-
CFTimeInterval now = CACurrentMediaTime();
71-
if (now > timeoutDate) {
72-
break;
73-
}
74-
75-
// Run 1000 times a second until the poll timeout or until timeoutDate, whichever is first.
76-
CFTimeInterval runLoopTimeout = MIN(0.001, timeoutDate - now);
77-
CFRunLoopRunInMode(kCFRunLoopDefaultMode, runLoopTimeout, true);
78-
}
79-
80-
return passed;
81-
}
82-
83-
8448
#pragma mark -
8549
#pragma mark Unit tests.
8650

@@ -360,14 +324,11 @@ - (void)testUncachedDownload
360324
[imageNode reloadImageIdentifierSources];
361325

362326
// Wait until the image is loaded.
363-
ASRunRunLoopUntilBlockIsTrue(^BOOL{
364-
return [(id)imageNode.loadedImageIdentifier isEqual:imageIdentifier];
365-
});
327+
[self expectationForPredicate:[NSPredicate predicateWithFormat:@"loadedImageIdentifier = %@", imageIdentifier] evaluatedWithObject:imageNode handler:nil];
328+
[self waitForExpectationsWithTimeout:30 handler:nil];
366329

367330
// Verify the delegation.
368331
[mockDelegate verify];
369-
// Also verify that it's acutally loaded (could be false if we timed out above).
370-
XCTAssertEqualObjects(imageNode.loadedImageIdentifier, imageIdentifier, @"Failed to load image");
371332

372333
[imageNode release];
373334
}

0 commit comments

Comments
 (0)