Skip to content

Commit 1ef2bd6

Browse files
committed
cleaning up UnitTests.m
1 parent 7c171b3 commit 1ef2bd6

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,11 @@ - (void)backgroundModesDisabledInXcode {
136136
}
137137

138138
- (void)registerForPushNotifications {
139+
#pragma clang diagnostic push
140+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
139141
[OneSignal registerForPushNotifications];
140-
[self backgroundApp];
141-
}
142-
143-
- (void)backgroundApp {
144-
UIApplicationOverrider.currentUIApplicationState = UIApplicationStateBackground;
145-
if (@available(iOS 13.0, *)) {
146-
NSDictionary *sceneManifest = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIApplicationSceneManifest"];
147-
if (sceneManifest) {
148-
[[NSNotificationCenter defaultCenter] postNotificationName:UISceneWillDeactivateNotification object:nil];
149-
[[NSNotificationCenter defaultCenter] postNotificationName:UISceneDidEnterBackgroundNotification object:nil];
150-
return;
151-
}
152-
}
153-
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationWillResignActiveNotification object:nil];
154-
[[NSNotificationCenter defaultCenter] postNotificationName:UIApplicationDidEnterBackgroundNotification object:nil];
155-
142+
#pragma clang diagnostic pop
143+
[UnitTestCommonMethods backgroundApp];
156144
}
157145

158146
- (UNNotificationResponse*)createBasiciOSNotificationResponse {
@@ -394,7 +382,7 @@ - (void)testCallingMethodsWorks_beforeInit {
394382
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"tags"][@"key"], @"value");
395383
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 2);
396384

397-
[self backgroundApp];
385+
[UnitTestCommonMethods backgroundApp];
398386
[UnitTestCommonMethods runBackgroundThreads];
399387
[UnitTestCommonMethods clearStateForAppRestart:self];
400388

@@ -600,7 +588,7 @@ - (void)testPermissionChangeObserverWithNativeiOS10PromptCall {
600588
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
601589
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
602590
completionHandler:^(BOOL granted, NSError* error) {}];
603-
[self backgroundApp];
591+
[UnitTestCommonMethods backgroundApp];
604592
[UnitTestCommonMethods runBackgroundThreads];
605593

606594
XCTAssertEqual(observer->fireCount, 1);
@@ -633,7 +621,7 @@ - (void)testTestPermissionChangeObserverWithNativeiOS10PromptCall {
633621
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
634622
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert + UNAuthorizationOptionSound + UNAuthorizationOptionBadge)
635623
completionHandler:^(BOOL granted, NSError* error) {}];
636-
[self backgroundApp];
624+
[UnitTestCommonMethods backgroundApp];
637625
// Full bug details explained in answerNotifiationPrompt
638626
[UnitTestCommonMethods answerNotificationPrompt:true];
639627
[UnitTestCommonMethods runBackgroundThreads];
@@ -655,7 +643,7 @@ - (void)testDeliverQuietly {
655643
OSPermissionStateTestObserver* observer = [OSPermissionStateTestObserver new];
656644
[OneSignal addPermissionObserver:observer];
657645

658-
[self backgroundApp];
646+
[UnitTestCommonMethods backgroundApp];
659647

660648
//answer the prompt to allow notification
661649
[UnitTestCommonMethods answerNotificationPrompt:true];
@@ -817,7 +805,7 @@ - (void)testPromptForPushNotificationsWithUserResponse {
817805
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
818806
didAccept = accepted;
819807
}];
820-
[self backgroundApp];
808+
[UnitTestCommonMethods backgroundApp];
821809
[UnitTestCommonMethods answerNotificationPrompt:true];
822810
[UnitTestCommonMethods runBackgroundThreads];
823811
XCTAssertTrue(didAccept);
@@ -833,7 +821,7 @@ - (void)testPromptForPushNotificationsWithUserResponseOnIOS8 {
833821
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
834822
didAccept = accepted;
835823
}];
836-
[self backgroundApp];
824+
[UnitTestCommonMethods backgroundApp];
837825
[UnitTestCommonMethods answerNotificationPrompt:true];
838826
[UnitTestCommonMethods runBackgroundThreads];
839827
XCTAssertTrue(didAccept);
@@ -849,7 +837,7 @@ - (void)testPromptForPushNotificationsWithUserResponseOnIOS7 {
849837
[OneSignal promptForPushNotificationsWithUserResponse:^(BOOL accepted) {
850838
didAccept = accepted;
851839
}];
852-
[self backgroundApp];
840+
[UnitTestCommonMethods backgroundApp];
853841
[UnitTestCommonMethods answerNotificationPrompt:true];
854842
[UnitTestCommonMethods runBackgroundThreads];
855843
XCTAssertTrue(didAccept);
@@ -932,9 +920,12 @@ - (void)testIdsAvailableNotAcceptingNotifications {
932920
settings:@{kOSSettingsKeyAutoPrompt: @false}];
933921

934922
__block BOOL idsAvailable1Called = false;
923+
#pragma clang diagnostic push
924+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
935925
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
936926
idsAvailable1Called = true;
937927
}];
928+
#pragma clang diagnostic pop
938929

939930
[UnitTestCommonMethods runBackgroundThreads];
940931

@@ -951,9 +942,12 @@ - (void)testIdsAvailableNotAcceptingNotifications {
951942
settings:@{kOSSettingsKeyAutoPrompt: @false}];
952943

953944
__block BOOL idsAvailable2Called = false;
945+
#pragma clang diagnostic push
946+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
954947
[OneSignal IdsAvailable:^(NSString *userId, NSString *pushToken) {
955948
idsAvailable2Called = true;
956949
}];
950+
#pragma clang diagnostic pop
957951

958952
[UnitTestCommonMethods runBackgroundThreads];
959953
XCTAssertTrue(idsAvailable2Called);
@@ -1444,6 +1438,8 @@ -(void)assertLocalNotification:(NSDictionary*)userInfo {
14441438
XCTAssertEqualObjects(localNotif.category, @"__dynamic__");
14451439
XCTAssertEqualObjects(localNotif.userInfo, userInfo);
14461440

1441+
#pragma clang diagnostic push
1442+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
14471443
let categories = [UIApplication sharedApplication].currentUserNotificationSettings.categories;
14481444

14491445
XCTAssertEqual(categories.count, 1);
@@ -1452,6 +1448,7 @@ -(void)assertLocalNotification:(NSDictionary*)userInfo {
14521448
XCTAssertEqualObjects(category.identifier, @"__dynamic__");
14531449

14541450
let actions = [category actionsForContext:UIUserNotificationActionContextDefault];
1451+
#pragma clang diagnostic pop
14551452
XCTAssertEqualObjects(actions[0].identifier, @"id1");
14561453
XCTAssertEqualObjects(actions[0].title, @"text1");
14571454
}
@@ -1460,7 +1457,7 @@ -(void)assertLocalNotification:(NSDictionary*)userInfo {
14601457
- (void)testGeneratingLocalNotificationWithButtonsiOS8_osdata_format {
14611458
OneSignalHelperOverrider.mockIOSVersion = 8;
14621459
[UnitTestCommonMethods initOneSignalAndThreadWait];
1463-
[self backgroundApp];
1460+
[UnitTestCommonMethods backgroundApp];
14641461

14651462
let userInfo = @{@"aps": @{@"content_available": @1},
14661463
@"os_data": @{
@@ -1479,7 +1476,7 @@ - (void)testGeneratingLocalNotificationWithButtonsiOS8_osdata_format {
14791476
- (void)testGeneratingLocalNotificationWithButtonsiOS8 {
14801477
OneSignalHelperOverrider.mockIOSVersion = 8;
14811478
[UnitTestCommonMethods initOneSignalAndThreadWait];
1482-
[self backgroundApp];
1479+
[UnitTestCommonMethods backgroundApp];
14831480

14841481
let userInfo = @{@"aps": @{@"content_available": @1},
14851482
@"m": @"alert body only",
@@ -1709,8 +1706,8 @@ - (void)permissionChangedInSettingsOutsideOfApp: (BOOL)useSceneDelegate {
17091706

17101707
XCTAssertEqualObjects(OneSignalClientOverrider.lastHTTPRequest[@"notification_types"], @0);
17111708
XCTAssertNil(OneSignalClientOverrider.lastHTTPRequest[@"identifier"]);
1712-
1713-
[self backgroundApp];
1709+
1710+
[UnitTestCommonMethods backgroundApp];
17141711
[UnitTestCommonMethods setCurrentNotificationPermission:true];
17151712
[UnitTestCommonMethods foregroundApp];
17161713
[UnitTestCommonMethods runBackgroundThreads];
@@ -1727,7 +1724,7 @@ - (void)testPermissionChangedOutsideOfAppOverWithNewSession {
17271724
[self backgroundModesDisabledInXcode];
17281725

17291726
[UnitTestCommonMethods initOneSignalAndThreadWait];
1730-
[self backgroundApp];
1727+
[UnitTestCommonMethods backgroundApp];
17311728
[UnitTestCommonMethods runBackgroundThreads];
17321729
[UnitTestCommonMethods setCurrentNotificationPermission:true];
17331730

@@ -1750,15 +1747,15 @@ - (void) testOnSessionWhenResuming {
17501747
[UnitTestCommonMethods initOneSignalAndThreadWait];
17511748

17521749
// Don't make an on_session call if only out of the app for 20 secounds
1753-
[self backgroundApp];
1754-
NSDateOverrider.timeOffset = 10;
1750+
[UnitTestCommonMethods backgroundApp];
1751+
[NSDateOverrider advanceSystemTimeBy:10];
17551752
[UnitTestCommonMethods foregroundApp];
17561753
[UnitTestCommonMethods runBackgroundThreads];
17571754
XCTAssertEqual(OneSignalClientOverrider.networkRequestCount, 2);
17581755

17591756
// Anything over 30 secounds should count as a session.
1760-
[self backgroundApp];
1761-
NSDateOverrider.timeOffset = 41;
1757+
[UnitTestCommonMethods backgroundApp];
1758+
[NSDateOverrider advanceSystemTimeBy:41];
17621759
[UnitTestCommonMethods foregroundApp];
17631760
[UnitTestCommonMethods runBackgroundThreads];
17641761

@@ -1772,7 +1769,7 @@ - (void) testOnSessionOnColdStart {
17721769
[UnitTestCommonMethods initOneSignalAndThreadWait];
17731770

17741771
// 2. Kill the app and wait 31 seconds
1775-
[self backgroundApp];
1772+
[UnitTestCommonMethods backgroundApp];
17761773
[UnitTestCommonMethods runBackgroundThreads];
17771774
[UnitTestCommonMethods clearStateForAppRestart:self];
17781775
[NSDateOverrider advanceSystemTimeBy:31];
@@ -2812,8 +2809,11 @@ - (void)testAllowsIncreasedAPNSTokenSize
28122809
}
28132810

28142811
- (void)testHexStringFromDataWithInvalidValues {
2812+
#pragma clang diagnostic push
2813+
#pragma clang diagnostic ignored "-Wnonnull"
28152814
XCTAssertNil([NSString hexStringFromData:nil]);
28162815
XCTAssertNil([NSString hexStringFromData:NULL]);
2816+
#pragma clang diagnostic pop
28172817
XCTAssertNil([NSString hexStringFromData:[NSData new]]);
28182818
}
28192819

0 commit comments

Comments
 (0)