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
2216BOOL 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
0 commit comments