Skip to content

Commit dbac00f

Browse files
authored
Merge pull request #833 from BranchMetrics/share-source-DEVEX-332
Clean Up Source for Sharing Between Projects DEVEX-332
2 parents 5124cb9 + 067801e commit dbac00f

35 files changed

+409
-303
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# *.xcscmblueprint # We should probably check this in.
1010
*.o
1111

12+
# merge-repo commit/discard file
13+
merge-repo-commit
14+
1215
# Pods
1316
Pods/
1417
Podfile.lock
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
@file BNCApplication+BNCTest.h
3+
@package Branch-SDK-Tests
4+
@brief Expose BNCApplication interfaces for testing.
5+
6+
@author Edward Smith
7+
@date May 4, 2018
8+
@copyright Copyright © 2018 Branch. All rights reserved.
9+
*/
10+
11+
#import <Foundation/Foundation.h>
12+
#import "BNCApplication.h"
13+
14+
@interface BNCApplication (BNCTest)
15+
16+
- (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
17+
firstInstallDate:(NSDate*)firstInstallDate
18+
lastUpdateDate:(NSDate*)lastUpdateDate;
19+
20+
@end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
@file BNCApplication+BNCTest.m
3+
@package Branch-SDK-Tests
4+
@brief Expose BNCApplication interfaces for testing.
5+
6+
@author Edward Smith
7+
@date May 4, 2018
8+
@copyright Copyright © 2018 Branch. All rights reserved.
9+
*/
10+
11+
#import "BNCApplication+BNCTest.h"

Branch-SDK-Tests/Branch-SDK-Tests/BNCDebug.Test.m

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1+
/**
2+
@file BNCDebug.Test.m
3+
@package Branch-SDK
4+
@brief Tests for BNCDebug.
15
6+
@author Edward Smith
7+
@date October 2016
8+
@copyright Copyright © 2016 Branch. All rights reserved.
9+
*/
210

3-
//--------------------------------------------------------------------------------------------------
4-
//
5-
// BNCDebug.Test.m
6-
// Branch.framework
7-
//
8-
// Debugging Support
9-
// Edward Smith, October 2016
10-
//
11-
// -©- Copyright © 2016 Branch, all rights reserved. -©-
12-
//
13-
//--------------------------------------------------------------------------------------------------
14-
15-
16-
#import <XCTest/XCTest.h>
1711
#import "BNCDebug.h"
1812
#import "BNCTestCase.h"
1913

20-
2114
#pragma mark Test DumpClass
2215

2316
@interface DumpClass : NSObject {
@@ -190,7 +183,7 @@ - (void) testClassList {
190183

191184
- (void) testBreakpoint {
192185
// if (BNCDebuggerIsAttached()) {
193-
if (self.class.testBreakpoints) {
186+
if (self.class.breakpointsAreEnabledInTests) {
194187
BNCDebugBreakpoint();
195188
}
196189
}

Branch-SDK-Tests/Branch-SDK-Tests/BNCError.Test.m

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1+
/**
2+
@file BNCError.Test.m
3+
@package Branch-SDK
4+
@brief Branch error tests.
15
2-
3-
//--------------------------------------------------------------------------------------------------
4-
//
5-
// BNCError.Test.m
6-
// BranchTests
7-
//
8-
// Error Tests
9-
// Edward Smith, August 2017
10-
//
11-
// -©- Copyright © 2017 Branch, all rights reserved. -©-
12-
//
13-
//--------------------------------------------------------------------------------------------------
14-
6+
@author Edward Smith
7+
@date August 2017
8+
@copyright Copyright © 2017 Branch. All rights reserved.
9+
*/
1510

1611
#import "BNCTestCase.h"
1712
#import "BNCError.h"
1813
#import "BNCLocalization.h"
1914

20-
2115
@interface BNCErrorTest : BNCTestCase
2216
@end
2317

24-
2518
@implementation BNCErrorTest
2619

2720
- (void) testErrorBasic {

Branch-SDK-Tests/Branch-SDK-Tests/BNCKeyChain.Test.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#import "BNCTestCase.h"
1212
#import "BNCKeyChain.h"
13-
#import "BNCApplication.h"
13+
//#import "BNCApplication.h"
1414

1515
@interface BNCKeyChainTest : BNCTestCase
1616
@end
@@ -46,6 +46,7 @@ - (void)testKeyChain {
4646
value = [BNCKeyChain retrieveValueForService:kServiceName key:@"key3" error:&error];
4747
XCTAssertTrue(value == nil && error.code == errSecItemNotFound);
4848

49+
// TODO: Fix this.
4950
if ([UIApplication sharedApplication] == nil) {
5051
NSLog(@"No host application for keychain testing!");
5152
return;

Branch-SDK-Tests/Branch-SDK-Tests/BNCLocalization.Test.m

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
1+
/**
2+
@file BNCLocalization.Test.m
3+
@package Branch-SDK
4+
@brief Branch string localization tests.
15
2-
3-
//--------------------------------------------------------------------------------------------------
4-
//
5-
// BNCLocalization.Test.m
6-
// BranchTests
7-
//
8-
// Localization Tests
9-
// Edward Smith, July 2017
10-
//
11-
// -©- Copyright © 2017 Branch, all rights reserved. -©-
12-
//
13-
//--------------------------------------------------------------------------------------------------
14-
6+
@author Edward Smith
7+
@date July 2017
8+
@copyright Copyright © 2017 Branch. All rights reserved.
9+
*/
1510

1611
#import "BNCTestCase.h"
1712
#import "BNCLocalization.h"
1813

19-
2014
@interface BNCLocalizationTest : BNCTestCase
2115
@end
2216

23-
2417
@implementation BNCLocalizationTest
2518

2619
- (void) testLocalizationBasic {
@@ -37,10 +30,13 @@ - (void) testLocalizationBasic {
3730
string = BNCLocalizedString(truth);
3831
XCTAssertEqualObjects(string, truth);
3932

33+
#pragma clang diagnostic push
34+
#pragma clang diagnostic ignored "-Wall"
4035
// Nil input should return empty string output.
4136
truth = @"";
4237
string = BNCLocalizedString(nil);
4338
XCTAssertEqualObjects(string, truth);
39+
#pragma clang diagnostic pop
4440

4541
// Test formatted language strings.
4642
truth = @"Test formatted language strings.";
@@ -52,9 +48,12 @@ - (void) testLocalizationBasic {
5248
string = BNCLocalizedFormattedString(@"Test formatted %@ strings float %1.2f.", @"language", 1.0);
5349
XCTAssertEqualObjects(string, truth);
5450

51+
#pragma clang diagnostic push
52+
#pragma clang diagnostic ignored "-Wall"
5553
truth = @"";
5654
string = BNCLocalizedFormattedString(nil, 1.0);
5755
XCTAssertEqualObjects(string, truth);
56+
#pragma clang diagnostic pop
5857
}
5958

6059
- (void) testLocalizationRussian {

Branch-SDK-Tests/Branch-SDK-Tests/BNCLog.Test.m

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
1-
2-
3-
//--------------------------------------------------------------------------------------------------
4-
//
5-
// BNCLog.Test.m
6-
// BranchTests
7-
//
8-
// Simple logging functions
9-
// Edward Smith, October 2016
10-
//
11-
// -©- Copyright © 2016 Branch, all rights reserved. -©-
12-
//
13-
//--------------------------------------------------------------------------------------------------
14-
1+
/**
2+
@file BNCLog.Test.m
3+
@package BranchTests
4+
@brief Tests for BNCLog.
5+
6+
@author Edward Smith
7+
@date October 2016
8+
@copyright Copyright © 2016 Branch. All rights reserved.
9+
*/
1510

1611
#import <XCTest/XCTest.h>
1712
#import "BNCLog.h"
1813
#import "NSString+Branch.h"
1914
#import "BNCTestCase.h"
2015

21-
2216
static NSString* globalTestLogString = nil;
2317

24-
2518
void TestLogProcedure(NSDate*timestamp, BNCLogLevel level, NSString* message) {
2619
globalTestLogString = [message copy];
2720
}
2821

29-
3022
@interface BNCLogTest : BNCTestCase
3123
@end
3224

33-
3425
@implementation BNCLogTest
3526

3627
- (void) dealloc {
@@ -63,7 +54,7 @@ - (void) testLogLineNumbers {
6354
BNCLog(@"Debug message with no parameters.");
6455
BNCLogFlushMessages();
6556
XCTAssertEqualObjects(globalTestLogString,
66-
@"[branch.io] BNCLog.Test.m(63) Log: Debug message with no parameters.");
57+
@"[branch.io] BNCLog.Test.m(54) Log: Debug message with no parameters.");
6758
}
6859

6960
- (void) testLog {
@@ -95,7 +86,7 @@ - (void) testLog {
9586

9687
// Test breakpoints --
9788

98-
if (self.class.testBreakpoints) { // Test break points too:
89+
if (self.class.breakpointsAreEnabledInTests) { // Test break points too:
9990
BNCLogSetBreakPointsEnabled(YES);
10091
BNCLogBreakPoint();
10192
XCTAssert([globalTestLogString bnc_isEqualToMaskedString:
@@ -298,7 +289,10 @@ - (void) testTripleLengthLogMessages {
298289
- (void) testLogObject {
299290
BNCLogSetOutputFunction(TestLogProcedure);
300291
NSData *data = [@"Test string." dataUsingEncoding:NSUTF8StringEncoding];
301-
BNCLog(data);
292+
#pragma clang diagnostic push
293+
#pragma clang diagnostic ignored "-Wformat-security"
294+
BNCLog((id)data);
295+
#pragma clang diagnostic pop
302296
BNCLogFlushMessages();
303297
XCTAssert([globalTestLogString bnc_isEqualToMaskedString:
304298
@"[branch.io] BNCLog.Test.m(***) Log: "

Branch-SDK-Tests/Branch-SDK-Tests/BNCServerInterface.Test.m

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ - (void)testParamAddForBranchKey {
4949
if (callCount == 1) {
5050
BOOL foundIt = ([request.URL.query rangeOfString:@"branch_key=key_"].location != NSNotFound);
5151
XCTAssertTrue(foundIt, @"Branch Key not added");
52-
BNCAfterSecondsPerformBlock(0.01, ^{ [expectation fulfill]; });
52+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [expectation fulfill]; });
5353
return YES;
5454
}
5555
return NO;
@@ -108,7 +108,10 @@ - (void)testGetRequestAsyncRetriesWhenAppropriate {
108108
// Return actual data afterwards
109109
++successfulConnections;
110110
XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections);
111-
BNCAfterSecondsPerformBlock(0.01, ^{ NSLog(@"==> Fullfill."); [successExpectation fulfill]; });
111+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
112+
NSLog(@"==> Fullfill.");
113+
[successExpectation fulfill];
114+
});
112115

113116
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
114117
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
@@ -153,7 +156,7 @@ - (void)testGetRequestAsyncRetriesWhenInappropriateResponse {
153156
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
154157
connectionAttempts++;
155158
XCTAssertEqual(connectionAttempts, 1);
156-
BNCAfterSecondsPerformBlock(0.01, ^ {
159+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ {
157160
[successExpectation fulfill];
158161
});
159162
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
@@ -191,7 +194,7 @@ - (void)testGetRequestAsyncRetriesWhenInappropriateRetryCount {
191194
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
192195
connectionAttempts++;
193196
XCTAssertEqual(connectionAttempts, 1);
194-
BNCAfterSecondsPerformBlock(0.01, ^{
197+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
195198
[successExpectation fulfill];
196199
});
197200
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
@@ -243,7 +246,10 @@ - (void)testPostRequestAsyncRetriesWhenAppropriate {
243246
++successfulConnections;
244247
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
245248
XCTAssertEqual(connectionAttempts, failedConnections + successfulConnections);
246-
BNCAfterSecondsPerformBlock(0.01, ^ { NSLog(@"==>> Fullfill <<=="); [successExpectation fulfill]; });
249+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^ {
250+
NSLog(@"==>> Fullfill <<==");
251+
[successExpectation fulfill];
252+
});
247253
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
248254

249255
} else {
@@ -284,8 +290,7 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateResponse {
284290
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
285291
connectionAttempts++;
286292
XCTAssertEqual(connectionAttempts, 1);
287-
BNCAfterSecondsPerformBlock(0.01, ^{ [successExpectation fulfill]; });
288-
293+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; });
289294
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
290295

291296
}];
@@ -321,10 +326,8 @@ - (void)testPostRequestAsyncRetriesWhenInappropriateRetryCount {
321326
NSDictionary* dummyJSONResponse = @{@"key": @"value"};
322327
connectionAttempts++;
323328
XCTAssertEqual(connectionAttempts, 1);
324-
BNCAfterSecondsPerformBlock(0.01, ^{ [successExpectation fulfill]; });
325-
329+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{ [successExpectation fulfill]; });
326330
return [OHHTTPStubsResponse responseWithJSONObject:dummyJSONResponse statusCode:200 headers:nil];
327-
328331
}];
329332

330333
[serverInterface getRequest:nil url:@"http://foo" key:@"key_live_foo" callback:NULL];

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ - (void)testCloseRequestsArentPersisted {
154154
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
155155
if ([reqs isKindOfClass:[NSArray class]]) {
156156
XCTAssert(reqs.count == 0);
157-
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
157+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
158+
[self safelyFulfillExpectation:expectation];
159+
});
158160
return YES;
159161
}
160162
return NO;
@@ -182,7 +184,9 @@ - (void)testDebugRequestsArentPersisted {
182184
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
183185
if ([reqs isKindOfClass:[NSArray class]]) {
184186
XCTAssert(reqs.count == 0);
185-
BNCAfterSecondsPerformBlock(0.01, ^{ [self safelyFulfillExpectation:expectation]; });
187+
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
188+
[self safelyFulfillExpectation:expectation];
189+
});
186190
return YES;
187191
}
188192
return NO;

0 commit comments

Comments
 (0)