Skip to content

Commit dae4adb

Browse files
author
Edward Smith
committed
Merge from Apple-Shared-Source.
1 parent b2cd3c4 commit dae4adb

File tree

7 files changed

+27
-87
lines changed

7 files changed

+27
-87
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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//--------------------------------------------------------------------------------------------------
1414

1515

16-
#import <XCTest/XCTest.h>
1716
#import "BNCDebug.h"
1817
#import "BNCTestCase.h"
1918

@@ -190,7 +189,7 @@ - (void) testClassList {
190189

191190
- (void) testBreakpoint {
192191
// if (BNCDebuggerIsAttached()) {
193-
if (self.class.testBreakpoints) {
192+
if (self.class.breakpointsAreEnabledInTests) {
194193
BNCDebugBreakpoint();
195194
}
196195
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ - (void) testLog {
9595

9696
// Test breakpoints --
9797

98-
if (self.class.testBreakpoints) { // Test break points too:
98+
if (self.class.breakpointsAreEnabledInTests) { // Test break points too:
9999
BNCLogSetBreakPointsEnabled(YES);
100100
BNCLogBreakPoint();
101101
XCTAssert([globalTestLogString bnc_isEqualToMaskedString:
@@ -298,7 +298,10 @@ - (void) testTripleLengthLogMessages {
298298
- (void) testLogObject {
299299
BNCLogSetOutputFunction(TestLogProcedure);
300300
NSData *data = [@"Test string." dataUsingEncoding:NSUTF8StringEncoding];
301-
BNCLog(data);
301+
#pragma clang diagnostic push
302+
#pragma clang diagnostic ignored "-Wformat-security"
303+
BNCLog((id)data);
304+
#pragma clang diagnostic pop
302305
BNCLogFlushMessages();
303306
XCTAssert([globalTestLogString bnc_isEqualToMaskedString:
304307
@"[branch.io] BNCLog.Test.m(***) Log: "

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

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,14 @@
22
// BNCTestCase.h
33
// Branch-TestBed
44
//
5-
// Created by Graham Mueller on 4/27/15.
6-
// Copyright (c) 2015 Branch Metrics. All rights reserved.
5+
// Created by Edward Smith on 4/27/17.
6+
// Copyright (c) 2017 Branch Metrics. All rights reserved.
77
//
88

99
#import <XCTest/XCTest.h>
1010
#import <OCMock/OCMock.h>
11-
#import "Branch.h"
1211
#import "NSString+Branch.h"
13-
14-
static inline dispatch_time_t BNCDispatchTimeFromSeconds(NSTimeInterval seconds) {
15-
return dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC);
16-
}
17-
18-
static inline void BNCAfterSecondsPerformBlock(NSTimeInterval seconds, dispatch_block_t block) {
19-
dispatch_after(BNCDispatchTimeFromSeconds(seconds), dispatch_get_main_queue(), block);
20-
}
21-
22-
static inline void BNCSleepForTimeInterval(NSTimeInterval seconds) {
23-
double secPart = trunc(seconds);
24-
double nanoPart = trunc((seconds - secPart) * ((double)NSEC_PER_SEC));
25-
struct timespec sleepTime;
26-
sleepTime.tv_sec = (__typeof(sleepTime.tv_sec)) secPart;
27-
sleepTime.tv_nsec = (__typeof(sleepTime.tv_nsec)) nanoPart;
28-
nanosleep(&sleepTime, NULL);
29-
}
12+
#import "BNCUtilities.h"
3013

3114
#define BNCTAssertEqualMaskedString(string, mask) { \
3215
if ((id)string != nil && (id)mask != nil && [string bnc_isEqualToMaskedString:mask]) { \
@@ -52,11 +35,6 @@ extern BOOL BNCTestStringMatchesRegex(NSString *string, NSString *regex);
5235
- (NSString*)stringFromBundleWithKey:(NSString*)key;
5336
- (NSMutableDictionary*) mutableDictionaryFromBundleJSONWithKey:(NSString*)key;
5437

55-
+ (BOOL) testBreakpoints;
56-
57-
+ (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
58-
firstInstallDate:(NSDate*)firstInstallDate
59-
lastUpdateDate:(NSDate*)lastUpdateDate
60-
previousUpdateDate:(NSDate*)previousUpdateDate;
38+
+ (BOOL) breakpointsAreEnabledInTests;
6139

6240
@end

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

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,21 @@
22
// BNCTestCase.m
33
// Branch-TestBed
44
//
5-
// Created by Graham Mueller on 4/27/15.
6-
// Copyright (c) 2015 Branch Metrics. All rights reserved.
5+
// Created by Edward Smith on 4/27/17.
6+
// Copyright (c) 2017 Branch Metrics. All rights reserved.
77
//
88

99
#import "BNCTestCase.h"
10-
#import "BNCApplication.h"
1110
#import "BNCLog.h"
12-
#import "BNCPreferenceHelper.h"
1311

14-
@interface BNCApplication (BNCTestCase)
15-
- (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
16-
firstInstallDate:(NSDate*)firstInstallDate
17-
lastUpdateDate:(NSDate*)lastUpdateDate;
18-
@end
12+
NSString* kTestStringResourceName = @"BNCTestCase"; // File is 'BNCTestCase.strings'. Omit the '.string'.
1913

2014
#pragma mark - BNCTestStringMatchesRegex
2115

2216
BOOL BNCTestStringMatchesRegex(NSString *string, NSString *regex) {
2317
NSError *error = nil;
24-
NSRegularExpression* nsregex = [NSRegularExpression regularExpressionWithPattern:regex options:0 error:&error];
18+
NSRegularExpression* nsregex =
19+
[NSRegularExpression regularExpressionWithPattern:regex options:0 error:&error];
2520
if (error) {
2621
NSLog(@"Error in regex pattern: %@.", error);
2722
return NO;
@@ -39,34 +34,11 @@ @interface BNCTestCase ()
3934

4035
@implementation BNCTestCase
4136

42-
+ (void)setUp {
43-
[super setUp];
44-
45-
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
46-
if (!preferenceHelper.deviceFingerprintID) {
47-
preferenceHelper.deviceFingerprintID = @"foo_fingerprint";
48-
}
49-
if (!preferenceHelper.identityID) {
50-
preferenceHelper.identityID = @"foo_identity";
51-
}
52-
if (!preferenceHelper.sessionID) {
53-
preferenceHelper.sessionID = @"foo_sesion";
54-
}
55-
preferenceHelper.isDebug = NO;
56-
}
57-
5837
- (void)setUp {
5938
[super setUp];
6039
[self resetExpectations];
6140
}
6241

63-
- (void) testFailure {
64-
// Un-comment the next line to test a failure case:
65-
// XCTAssert(NO, @"Testing a test failure!");
66-
NSString * bundleID = [NSBundle mainBundle].bundleIdentifier;
67-
NSLog(@"The test bundleID is '%@'.", bundleID);
68-
}
69-
7042
- (void)resetExpectations {
7143
self.hasExceededExpectations = NO;
7244
}
@@ -99,13 +71,13 @@ - (id)stringMatchingPattern:(NSString *)pattern {
9971
- (NSString*) stringFromBundleWithKey:(NSString*)key {
10072
NSString *const kItemNotFound = @"<Item-Not-Found>";
10173
NSString *resource =
102-
[[NSBundle bundleForClass:self.class] localizedStringForKey:key value:kItemNotFound table:@"Branch-SDK-Tests"];
74+
[[NSBundle bundleForClass:self.class]
75+
localizedStringForKey:key value:kItemNotFound table:kTestStringResourceName];
10376
if ([resource isEqualToString:kItemNotFound]) resource = nil;
10477
return resource;
10578
}
10679

10780
- (NSMutableDictionary*) mutableDictionaryFromBundleJSONWithKey:(NSString*)key {
108-
10981
NSString *jsonString = [self stringFromBundleWithKey:key];
11082
XCTAssertTrue(jsonString, @"Can't load '%@' resource from bundle JSON!", key);
11183

@@ -119,10 +91,10 @@ - (NSMutableDictionary*) mutableDictionaryFromBundleJSONWithKey:(NSString*)key {
11991
return mutableDictionary;
12092
}
12193

122-
static BOOL _testBreakpoints = NO;
94+
static BOOL _breakpointsAreEnabledInTests = NO;
12395

124-
+ (BOOL) testBreakpoints {
125-
return _testBreakpoints;
96+
+ (BOOL) breakpointsAreEnabledInTests {
97+
return _breakpointsAreEnabledInTests;
12698
}
12799

128100
+ (void) initialize {
@@ -132,24 +104,10 @@ + (void) initialize {
132104
// Load test options from environment variables:
133105

134106
NSDictionary<NSString*, NSString*> *environment = [NSProcessInfo processInfo].environment;
135-
NSString *BNCTestBreakpoints = environment[@"BNCTestBreakpoints"];
107+
NSString *BNCTestBreakpoints = environment[@"BNCTestBreakpointsEnabled"];
136108
if ([BNCTestBreakpoints boolValue]) {
137-
_testBreakpoints = YES;
109+
_breakpointsAreEnabledInTests = YES;
138110
}
139111
}
140112

141-
+ (void) setAppOriginalInstallDate:(NSDate*)originalInstallDate
142-
firstInstallDate:(NSDate*)firstInstallDate
143-
lastUpdateDate:(NSDate*)lastUpdateDate
144-
previousUpdateDate:(NSDate*)previousUpdateDate {
145-
146-
BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper preferenceHelper];
147-
BNCApplication *application = [BNCApplication currentApplication];
148-
[application setAppOriginalInstallDate:originalInstallDate
149-
firstInstallDate:firstInstallDate
150-
lastUpdateDate:lastUpdateDate];
151-
preferenceHelper.previousAppBuildDate = previousUpdateDate; // previous_update_time
152-
[preferenceHelper synchronize];
153-
}
154-
155113
@end

Branch-SDK-Tests/Branch-SDK-Tests/NSString+Branch.Test.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//--------------------------------------------------------------------------------------------------
1414

1515

16-
#import <XCTest/XCTest.h>
1716
#import "NSString+Branch.h"
1817
#import "BNCTestCase.h"
1918

Branch-SDK/Branch-SDK/BNCLog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ extern void BNCLogWriteMessageFormat(
132132
BNCLogLevel logLevel,
133133
const char *_Nullable sourceFileName,
134134
int32_t sourceLineNumber,
135-
id _Nullable messageFormat,
135+
NSString* _Nullable messageFormat,
136136
...
137-
);
137+
) NS_FORMAT_FUNCTION(4,5);
138138

139139
/// Swift-friendly wrapper for BNCLogWriteMessageFormat
140140
extern void BNCLogWriteMessage(

0 commit comments

Comments
 (0)