Skip to content

Commit eba39be

Browse files
author
Edward Smith
committed
Fix unit tests for Xcode 8.3.2.
1 parent 6d93474 commit eba39be

File tree

4 files changed

+61
-51
lines changed

4 files changed

+61
-51
lines changed

Branch-TestBed-Swift/TestBed-Swift/AppDelegate.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
8989
let branchHandled = Branch.getInstance().application(application,
9090
open: url,
9191
sourceApplication: sourceApplication,
92-
annotation: annotation)
92+
annotation: annotation
93+
)
9394
if (!branchHandled) {
9495
// If not handled by Branch, do other deep link routing for the Facebook SDK, Pinterest SDK, etc
9596
}

Branch-TestBed/Branch-SDK-Tests/BNCServerRequestQueueTests.m

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -146,55 +146,58 @@ - (void)testPersistWhenArchiveFails {
146146
}
147147

148148
- (void)testCloseRequestsArentPersisted {
149-
XCTestExpectation *expectation = [self expectationWithDescription:@"PersistExpectation"];
150-
151-
id archiverMock = OCMClassMock([NSKeyedArchiver class]);
152-
[[archiverMock reject] archiveRootObject:[OCMArg any] toFile:[OCMArg any]];
153-
[[[archiverMock expect]
154-
andReturn:[NSData data]]
155-
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
156-
if ([reqs isKindOfClass:[NSArray class]]) {
157-
XCTAssert(reqs.count == 0);
158-
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
159-
return YES;
160-
}
161-
return NO;
162-
}]];
163-
164-
BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init];
165-
BranchCloseRequest *closeRequest = [[BranchCloseRequest alloc] init];
166-
[requestQueue enqueue:closeRequest];
167-
[requestQueue persistImmediately];
168-
169-
// Wait for operation to occur
170-
[self awaitExpectations];
171-
[archiverMock verify];
172-
//[archiverMock stopMocking];
149+
@autoreleasepool {
150+
XCTestExpectation *expectation = [self expectationWithDescription:@"PersistExpectation"];
151+
152+
id archiverMock = OCMClassMock([NSKeyedArchiver class]);
153+
[[archiverMock reject] archiveRootObject:[OCMArg any] toFile:[OCMArg any]];
154+
[[[archiverMock expect]
155+
andReturn:[NSData data]]
156+
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
157+
if ([reqs isKindOfClass:[NSArray class]]) {
158+
XCTAssert(reqs.count == 0);
159+
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
160+
return YES;
161+
}
162+
return NO;
163+
}]];
164+
165+
BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init];
166+
BranchCloseRequest *closeRequest = [[BranchCloseRequest alloc] init];
167+
[requestQueue enqueue:closeRequest];
168+
[requestQueue persistImmediately];
169+
170+
// Wait for operation to occur
171+
[self awaitExpectations];
172+
[archiverMock verify];
173+
BNCSleepForTimeInterval(0.001); // Allow for mock class to be un-mocked.
174+
}
173175
}
174176

175177
- (void)testDebugRequestsArentPersisted {
176-
177-
XCTestExpectation *expectation = [self expectationWithDescription:@"PersistExpectation"];
178-
id archiverMock = OCMClassMock([NSKeyedArchiver class]);
179-
[[archiverMock reject] archiveRootObject:[OCMArg any] toFile:[OCMArg any]];
180-
[[[archiverMock expect]
181-
andReturn:[NSData data]]
182-
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
183-
if ([reqs isKindOfClass:[NSArray class]]) {
184-
XCTAssert(reqs.count == 0);
185-
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
186-
return YES;
187-
}
188-
return NO;
189-
}]];
190-
191-
BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init];
192-
[requestQueue persistImmediately];
193-
194-
// Wait for operation to occur
195-
[self awaitExpectations];
196-
[archiverMock verify];
197-
//[archiverMock stopMocking];
178+
@autoreleasepool {
179+
XCTestExpectation *expectation = [self expectationWithDescription:@"PersistExpectation"];
180+
id archiverMock = OCMClassMock([NSKeyedArchiver class]);
181+
[[archiverMock reject] archiveRootObject:[OCMArg any] toFile:[OCMArg any]];
182+
[[[archiverMock expect]
183+
andReturn:[NSData data]]
184+
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
185+
if ([reqs isKindOfClass:[NSArray class]]) {
186+
XCTAssert(reqs.count == 0);
187+
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
188+
return YES;
189+
}
190+
return NO;
191+
}]];
192+
193+
BNCServerRequestQueue *requestQueue = [[BNCServerRequestQueue alloc] init];
194+
[requestQueue persistImmediately];
195+
196+
// Wait for operation to occur
197+
[self awaitExpectations];
198+
[archiverMock verify];
199+
BNCSleepForTimeInterval(0.001); // Allow for mock class to be un-mocked.
200+
}
198201
}
199202

200203
#pragma mark - Retrieve Tests

Branch-TestBed/Branch-SDK-Tests/BNCTestCase.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ static inline void BNCAfterSecondsPerformBlock(NSTimeInterval seconds, dispatch_
1818
dispatch_after(BNCDispatchTimeFromSeconds(seconds), dispatch_get_main_queue(), block);
1919
}
2020

21+
static inline void BNCSleepForTimeInterval(NSTimeInterval seconds) {
22+
double secPart = trunc(seconds);
23+
double nanoPart = trunc((seconds - secPart) * ((double)NSEC_PER_SEC));
24+
struct timespec sleepTime;
25+
sleepTime.tv_sec = (typeof(sleepTime.tv_sec)) secPart;
26+
sleepTime.tv_nsec = (typeof(sleepTime.tv_nsec)) nanoPart;
27+
nanosleep(&sleepTime, NULL);
28+
}
29+
2130

2231
@interface BNCTestCase : XCTestCase
2332

Branch-TestBed/Branch-SDK-Tests/BNCTestCase.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,12 @@ + (void)setUp {
2222
if (!preferenceHelper.deviceFingerprintID) {
2323
preferenceHelper.deviceFingerprintID = @"foo_fingerprint";
2424
}
25-
2625
if (!preferenceHelper.identityID) {
2726
preferenceHelper.identityID = @"foo_identity";
2827
}
29-
3028
if (!preferenceHelper.sessionID) {
3129
preferenceHelper.sessionID = @"foo_sesion";
3230
}
33-
3431
preferenceHelper.isDebug = NO;
3532
}
3633

@@ -40,7 +37,7 @@ - (void)setUp {
4037
}
4138

4239
- (void) testFailure {
43-
// Un-comment to test a failure case:
40+
// Un-comment the next line to test a failure case:
4441
// XCTAssert(NO, @"Testing a test failure!");
4542
NSString * bundleID = [NSBundle mainBundle].bundleIdentifier;
4643
NSLog(@"The test bundleID is '%@'.", bundleID);

0 commit comments

Comments
 (0)