Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start a thrash test suite for the collection node #1246

Merged
merged 12 commits into from
Jan 3, 2019
Prev Previous commit
Next Next commit
Lint
  • Loading branch information
mikezucc committed Dec 18, 2018
commit 03c2a7edf154a99f4a014bd85e3e4b603af51c7b
6 changes: 4 additions & 2 deletions Tests/ASCollectionViewThrashTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ @interface ASCollectionViewThrashTests : XCTestCase

@end

@implementation ASCollectionViewThrashTests {
@implementation ASCollectionViewThrashTests
{
// The current update, which will be logged in case of a failure.
ASThrashUpdate *_update;
BOOL _failed;
Expand Down Expand Up @@ -163,7 +164,8 @@ - (void)testThrashingWildlyDispatchWildly

- (void)applyUpdateUsingBatchUpdates:(ASThrashUpdate *)update
toDataSource:(ASThrashDataSource *)dataSource animated:(BOOL)animated
useXCTestWait:(BOOL)wait {
useXCTestWait:(BOOL)wait
{
CollectionView *collectionView = dataSource.collectionView;

XCTestExpectation *expectation;
Expand Down
24 changes: 16 additions & 8 deletions Tests/ASTableViewThrashTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
@interface ASTableViewThrashTests: XCTestCase
@end

@implementation ASTableViewThrashTests {
@implementation ASTableViewThrashTests
{
// The current update, which will be logged in case of a failure.
ASThrashUpdate *_update;
BOOL _failed;
}

#pragma mark Overrides

- (void)tearDown {
- (void)tearDown
{
if (_failed && _update != nil) {
NSLog(@"Failed update %@: %@", _update, _update.logFriendlyBase64Representation);
}
Expand All @@ -35,21 +37,24 @@ - (void)tearDown {
}

// NOTE: Despite the documentation, this is not always called if an exception is caught.
- (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filePath atLine:(NSUInteger)lineNumber expected:(BOOL)expected {
- (void)recordFailureWithDescription:(NSString *)description inFile:(NSString *)filePath atLine:(NSUInteger)lineNumber expected:(BOOL)expected
{
_failed = YES;
[super recordFailureWithDescription:description inFile:filePath atLine:lineNumber expected:expected];
}

#pragma mark Test Methods

// Disabled temporarily due to issue where cell nodes are not marked invisible before deallocation.
- (void)testInitialDataRead {
- (void)testInitialDataRead
{
ASThrashDataSource *ds = [[ASThrashDataSource alloc] initTableViewDataSourceWithData:[ASThrashTestSection sectionsWithCount:kInitialSectionCount]];
[self verifyDataSource:ds];
}

/// Replays the Base64 representation of an ASThrashUpdate from "ASThrashTestRecordedCase" file
- (void)testRecordedThrashCase {
- (void)testRecordedThrashCase
{
NSURL *caseURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ASThrashTestRecordedCase" withExtension:nil subdirectory:@"TestResources"];
NSString *base64 = [NSString stringWithContentsOfURL:caseURL encoding:NSUTF8StringEncoding error:NULL];

Expand All @@ -65,7 +70,8 @@ - (void)testRecordedThrashCase {
}

// Disabled temporarily due to issue where cell nodes are not marked invisible before deallocation.
- (void)testThrashingWildly {
- (void)testThrashingWildly
{
for (NSInteger i = 0; i < kThrashingIterationCount; i++) {
[self setUp];
@autoreleasepool {
Expand All @@ -85,7 +91,8 @@ - (void)testThrashingWildly {

#pragma mark Helpers

- (void)applyUpdate:(ASThrashUpdate *)update toDataSource:(ASThrashDataSource *)dataSource {
- (void)applyUpdate:(ASThrashUpdate *)update toDataSource:(ASThrashDataSource *)dataSource
{
TableView *tableView = dataSource.tableView;

[tableView beginUpdates];
Expand Down Expand Up @@ -122,7 +129,8 @@ - (void)applyUpdate:(ASThrashUpdate *)update toDataSource:(ASThrashDataSource *)
}
}

- (void)verifyDataSource:(ASThrashDataSource *)ds {
- (void)verifyDataSource:(ASThrashDataSource *)ds
{
TableView *tableView = ds.tableView;
NSArray <ASThrashTestSection *> *data = [ds data];
XCTAssertEqual(data.count, tableView.numberOfSections);
Expand Down
Loading