|
| 1 | +//// |
| 2 | +//// BNCPreInitBlockTests.m |
| 3 | +//// Branch-SDK-Tests |
| 4 | +//// |
| 5 | +//// Created by Benas Klastaitis on 12/9/19. |
| 6 | +//// Copyright © 2019 Branch, Inc. All rights reserved. |
| 7 | +//// |
1 | 8 | // |
2 | | -// BNCPreInitBlockTests.m |
3 | | -// Branch-SDK-Tests |
4 | | -// |
5 | | -// Created by Benas Klastaitis on 12/9/19. |
6 | | -// Copyright © 2019 Branch, Inc. All rights reserved. |
7 | | -// |
8 | | - |
9 | | -#import <XCTest/XCTest.h> |
10 | | -#import "Branch.h" |
11 | | - |
12 | | -@interface DispatchToIsolationQueueTests : XCTestCase |
13 | | -@property (nonatomic, strong, readwrite) Branch *branch; |
14 | | -@property (nonatomic, strong, readwrite) BNCPreferenceHelper *prefHelper; |
15 | | -@end |
16 | | - |
17 | | -// this is an integration test, needs to be moved to a new target |
18 | | -@implementation DispatchToIsolationQueueTests |
19 | | - |
20 | | -- (void)setUp { |
21 | | - self.branch = [Branch getInstance]; |
22 | | - self.prefHelper = [[BNCPreferenceHelper alloc] init]; |
23 | | -} |
24 | | - |
25 | | -- (void)tearDown { |
26 | | - [self.prefHelper setRequestMetadataKey:@"$marketing_cloud_visitor_id" value:@"dummy"]; |
27 | | -} |
28 | | - |
29 | | -- (void)testPreInitBlock { |
30 | | - __block XCTestExpectation *expectation = [self expectationWithDescription:@""]; |
31 | | - |
32 | | - [self.branch dispatchToIsolationQueue:^{ |
33 | | - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
34 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
35 | | - [self.branch setRequestMetadataKey:@"$marketing_cloud_visitor_id" value:@"adobeID123"]; |
36 | | - dispatch_semaphore_signal(semaphore); |
37 | | - }); |
38 | | - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
39 | | - }]; |
40 | | - |
41 | | - [self.branch initSessionWithLaunchOptions:nil andRegisterDeepLinkHandlerUsingBranchUniversalObject: |
42 | | - ^ (BranchUniversalObject * _Nullable universalObject, |
43 | | - BranchLinkProperties * _Nullable linkProperties, |
44 | | - NSError * _Nullable error) { |
45 | | - [expectation fulfill]; |
46 | | - }]; |
47 | | - |
48 | | - // test that session initialization blocking works |
49 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
50 | | - id initializationStatus = [self.branch valueForKey:@"initializationStatus"]; |
51 | | - XCTAssertTrue([self enumIntValueFromId:initializationStatus] == 0);// uninitialized |
52 | | - XCTAssertNil([[self.prefHelper requestMetadataDictionary] objectForKey:@"$marketing_cloud_visitor_id"]); |
53 | | - }); |
54 | | - |
55 | | - // test that initialization does happen afterwards and that pre init block was executed |
56 | | - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
57 | | - id initializationStatus = [self.branch valueForKey:@"initializationStatus"]; |
58 | | - XCTAssertTrue([self enumIntValueFromId:initializationStatus] == 2);// initialized |
59 | | - |
60 | | - XCTAssertTrue([[[self.prefHelper requestMetadataDictionary] objectForKey:@"$marketing_cloud_visitor_id"] isEqualToString:@"adobeID123"]); |
61 | | - }); |
62 | | - |
63 | | - |
64 | | - [self waitForExpectationsWithTimeout:6 handler:^(NSError * _Nullable error) { |
65 | | - NSLog(@"%@", error); |
66 | | - }]; |
67 | | -} |
68 | | - |
69 | | --(int)enumIntValueFromId:(id)enumValueId { |
70 | | - if (![enumValueId respondsToSelector:@selector(intValue)]) |
71 | | - return -1; |
72 | | - |
73 | | - return [enumValueId intValue]; |
74 | | -} |
75 | | - |
76 | | -@end |
| 9 | +//#import <XCTest/XCTest.h> |
| 10 | +//#import "Branch.h" |
| 11 | +// |
| 12 | +//@interface DispatchToIsolationQueueTests : XCTestCase |
| 13 | +//@property (nonatomic, strong, readwrite) Branch *branch; |
| 14 | +//@property (nonatomic, strong, readwrite) BNCPreferenceHelper *prefHelper; |
| 15 | +//@end |
| 16 | +// |
| 17 | +//// this is an integration test, needs to be moved to a new target |
| 18 | +//@implementation DispatchToIsolationQueueTests |
| 19 | +// |
| 20 | +//- (void)setUp { |
| 21 | +// self.branch = [Branch getInstance]; |
| 22 | +// self.prefHelper = [[BNCPreferenceHelper alloc] init]; |
| 23 | +//} |
| 24 | +// |
| 25 | +//- (void)tearDown { |
| 26 | +// [self.prefHelper setRequestMetadataKey:@"$marketing_cloud_visitor_id" value:@"dummy"]; |
| 27 | +//} |
| 28 | +// |
| 29 | +//- (void)testPreInitBlock { |
| 30 | +// __block XCTestExpectation *expectation = [self expectationWithDescription:@""]; |
| 31 | +// |
| 32 | +// [self.branch dispatchToIsolationQueue:^{ |
| 33 | +// dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); |
| 34 | +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 35 | +// [self.branch setRequestMetadataKey:@"$marketing_cloud_visitor_id" value:@"adobeID123"]; |
| 36 | +// dispatch_semaphore_signal(semaphore); |
| 37 | +// }); |
| 38 | +// dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
| 39 | +// }]; |
| 40 | +// |
| 41 | +// [self.branch initSessionWithLaunchOptions:nil andRegisterDeepLinkHandlerUsingBranchUniversalObject: |
| 42 | +// ^ (BranchUniversalObject * _Nullable universalObject, |
| 43 | +// BranchLinkProperties * _Nullable linkProperties, |
| 44 | +// NSError * _Nullable error) { |
| 45 | +// [expectation fulfill]; |
| 46 | +// }]; |
| 47 | +// |
| 48 | +// // test that session initialization blocking works |
| 49 | +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 50 | +// id initializationStatus = [self.branch valueForKey:@"initializationStatus"]; |
| 51 | +// XCTAssertTrue([self enumIntValueFromId:initializationStatus] == 0);// uninitialized |
| 52 | +// XCTAssertNil([[self.prefHelper requestMetadataDictionary] objectForKey:@"$marketing_cloud_visitor_id"]); |
| 53 | +// }); |
| 54 | +// |
| 55 | +// // test that initialization does happen afterwards and that pre init block was executed |
| 56 | +// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ |
| 57 | +// id initializationStatus = [self.branch valueForKey:@"initializationStatus"]; |
| 58 | +// XCTAssertTrue([self enumIntValueFromId:initializationStatus] == 2);// initialized |
| 59 | +// |
| 60 | +// XCTAssertTrue([[[self.prefHelper requestMetadataDictionary] objectForKey:@"$marketing_cloud_visitor_id"] isEqualToString:@"adobeID123"]); |
| 61 | +// }); |
| 62 | +// |
| 63 | +// |
| 64 | +// [self waitForExpectationsWithTimeout:6 handler:^(NSError * _Nullable error) { |
| 65 | +// NSLog(@"%@", error); |
| 66 | +// }]; |
| 67 | +//} |
| 68 | +// |
| 69 | +//-(int)enumIntValueFromId:(id)enumValueId { |
| 70 | +// if (![enumValueId respondsToSelector:@selector(intValue)]) |
| 71 | +// return -1; |
| 72 | +// |
| 73 | +// return [enumValueId intValue]; |
| 74 | +//} |
| 75 | +// |
| 76 | +//@end |
0 commit comments