Skip to content

Commit 3f44e15

Browse files
committed
Release 2.1.2
1 parent e4471ea commit 3f44e15

File tree

308 files changed

+13851
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

308 files changed

+13851
-858
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCDeviceInfoTests.m

Lines changed: 84 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import <XCTest/XCTest.h>
1010
#import "BNCDeviceInfo.h"
11+
#import "BNCUserAgentCollector.h"
1112

1213
@interface BNCDeviceInfoTests : XCTestCase
1314
@property (nonatomic, strong, readwrite) BNCDeviceInfo *deviceInfo;
@@ -16,16 +17,85 @@ @interface BNCDeviceInfoTests : XCTestCase
1617
@implementation BNCDeviceInfoTests
1718

1819
- (void)setUp {
20+
[self workaroundUserAgentLazyLoad];
1921
self.deviceInfo = [BNCDeviceInfo new];
2022
}
2123

24+
// user agent needs to be loaded
25+
- (void)workaroundUserAgentLazyLoad {
26+
__block XCTestExpectation *expectation = [self expectationWithDescription:@"setup"];
27+
[[BNCUserAgentCollector instance] loadUserAgentWithCompletion:^(NSString * _Nullable userAgent) {
28+
[expectation fulfill];
29+
}];
30+
[self waitForExpectationsWithTimeout:5.0 handler:^(NSError * _Nullable error) { }];
31+
}
32+
2233
- (void)tearDown {
2334

2435
}
2536

26-
- (void)testAppVersion {
27-
// checks test app version
28-
XCTAssert([@"1.1" isEqualToString:self.deviceInfo.applicationVersion]);
37+
- (void)testHardwareId {
38+
XCTAssertNotNil(self.deviceInfo.hardwareId);
39+
40+
// verify hardwareId is a valid UUID
41+
NSUUID *hardwareId = [[NSUUID alloc] initWithUUIDString:self.deviceInfo.hardwareId];
42+
XCTAssertNotNil(hardwareId);
43+
}
44+
45+
- (void)testHardwareIdType {
46+
// without ATT, this is the IDFV. Branch servers expect it as vendor_id
47+
XCTAssert([self.deviceInfo.hardwareIdType isEqualToString:@"vendor_id"]);
48+
}
49+
50+
- (void)testIsRealHardwareId {
51+
XCTAssert(self.deviceInfo.isRealHardwareId);
52+
}
53+
54+
- (void)testAdvertiserId {
55+
// the testbed does not show the ATT prompt.
56+
XCTAssertNil(self.deviceInfo.advertiserId);
57+
}
58+
59+
- (void)testVendorId {
60+
XCTAssertNotNil(self.deviceInfo.vendorId);
61+
62+
// verify vendorId is a valid UUID
63+
NSUUID *vendorId = [[NSUUID alloc] initWithUUIDString:self.deviceInfo.vendorId];
64+
XCTAssertNotNil(vendorId);
65+
}
66+
67+
- (void)testAnonId {
68+
XCTAssertNotNil(self.deviceInfo.anonId);
69+
70+
// verify anonId is a valid UUID
71+
NSUUID *anonId = [[NSUUID alloc] initWithUUIDString:self.deviceInfo.anonId];
72+
XCTAssertNotNil(anonId);
73+
}
74+
75+
- (void)testOptedInStatus {
76+
// the testbed does not show the ATT prompt.
77+
XCTAssert([self.deviceInfo.optedInStatus isEqualToString:@"not_determined"]);
78+
}
79+
80+
- (void)testIsFirstOptIn {
81+
// the testbed does not show the ATT prompt.
82+
XCTAssert(self.deviceInfo.isFirstOptIn == NO);
83+
}
84+
85+
- (void)testIsAdTrackingEnabled {
86+
// on iOS 14+, this is always NO
87+
XCTAssert(self.deviceInfo.isAdTrackingEnabled == NO);
88+
}
89+
90+
- (void)testLocalIPAddress {
91+
NSString *address = [self.deviceInfo localIPAddress];
92+
XCTAssertNotNil(address);
93+
XCTAssert(address.length > 7);
94+
}
95+
96+
- (void)testConnectionType {
97+
// simulator is on wifi
98+
XCTAssert([[self.deviceInfo connectionType] isEqualToString:@"wifi"]);
2999
}
30100

31101
- (void)testBrandName {
@@ -42,13 +112,9 @@ - (void)testModelName_Simulator {
42112
XCTAssert(x86_64 || arm64);
43113
}
44114

45-
//- (void)testModelName_iPhone7 {
46-
// XCTAssert([@"iPhone9,3" isEqualToString:self.deviceInfo.modelName]);
47-
//}
48-
49115
- (void)testOSName {
50116
XCTAssertNotNil(self.deviceInfo.osName);
51-
XCTAssert([self.deviceInfo.osName isEqualToString:[UIDevice currentDevice].systemName]);
117+
XCTAssert([@"iOS" isEqualToString:self.deviceInfo.osName]);
52118
}
53119

54120
- (void)testOSVersion {
@@ -61,6 +127,7 @@ - (void)testOSBuildVersion {
61127
}
62128

63129
- (void)testEnvironment {
130+
// currently not running unit tests on extensions
64131
XCTAssert([@"FULL_APP" isEqualToString:self.deviceInfo.environment]);
65132
}
66133

@@ -75,25 +142,21 @@ - (void)testCpuType_Simulator {
75142
}
76143

77144
- (void)testScreenWidth {
78-
XCTAssert(self.deviceInfo.screenWidth.intValue > 320);
145+
XCTAssert(self.deviceInfo.screenWidth.intValue >= 320);
79146
}
80147

81148
- (void)testScreenHeight {
82-
XCTAssert(self.deviceInfo.screenHeight.intValue > 320);
149+
XCTAssert(self.deviceInfo.screenHeight.intValue >= 320);
83150
}
84151

85152
- (void)testScreenScale {
86-
XCTAssert(self.deviceInfo.screenScale.intValue > 0);
153+
XCTAssert(self.deviceInfo.screenScale.intValue >= 1);
87154
}
88155

89156
- (void)testCarrierName_Simulator {
90157
XCTAssertNil(self.deviceInfo.carrierName);
91158
}
92159

93-
//- (void)testCarrierName_Att {
94-
// XCTAssert([@"AT&T" isEqualToString:self.deviceInfo.carrierName]);
95-
//}
96-
97160
- (void)testLocale {
98161
NSString *locale = [NSLocale currentLocale].localeIdentifier;
99162
XCTAssertNotNil(locale);
@@ -113,11 +176,14 @@ - (void)testLanguage {
113176
}
114177

115178
- (void)testUserAgentString {
116-
// Currently this method is a trivial pass through to the BNCUserAgentCollector singleton
117-
// Eventually remove the singleton to enable easier testing
179+
XCTAssert([self.deviceInfo.userAgentString containsString:@"AppleWebKit"]);
118180
}
119181

120-
- (void)testPlugin {
182+
- (void)testApplicationVersion_TestBed {
183+
XCTAssert([@"1.1" isEqualToString:self.deviceInfo.applicationVersion]);
184+
}
185+
186+
- (void)testRegisterPluginNameVersion {
121187
XCTAssertNil(self.deviceInfo.pluginName);
122188
XCTAssertNil(self.deviceInfo.pluginVersion);
123189

@@ -130,14 +196,6 @@ - (void)testPlugin {
130196
XCTAssert([expectedVersion isEqualToString:self.deviceInfo.pluginVersion]);
131197
}
132198

133-
- (void)testLocalIPAddress {
134-
NSString *address = [self.deviceInfo localIPAddress];
135-
XCTAssertNotNil(address);
136-
137-
// shortest ipv4 is 7
138-
XCTAssert(address.length >= 7);
139-
}
140-
141199
// just a sanity check on the V2 dictionary
142200
- (void)testV2Dictionary {
143201
NSDictionary *dict = [self.deviceInfo v2dictionary];

Branch-TestBed/Branch-SDK-Tests/BNCDeviceSystemTests.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ - (void)testMachine_Simulator {
4040
XCTAssert(x86_64 || arm64);
4141
}
4242

43-
/* Commenting out until this can be made more robust/portable/updated/whatever.
4443
- (void)testCPUType_Simulator {
4544
// intel processor
4645
bool x86 = [@(7) isEqualToNumber:self.deviceSystem.cpuType];
@@ -51,12 +50,13 @@ - (void)testCPUType_Simulator {
5150
bool arm_sub = [@(2) isEqualToNumber:self.deviceSystem.cpuSubType];
5251

5352
XCTAssert(x86 || arm);
54-
if (x86) {
55-
XCTAssert(x86_sub);
56-
} else {
57-
XCTAssert(arm_sub);
58-
}
53+
54+
// cpu subtype is different on cloud runners
55+
// if (x86) {
56+
// XCTAssert(x86_sub);
57+
// } else {
58+
// XCTAssert(arm_sub);
59+
// }
5960
}
60-
// */
6161

6262
@end
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//
2+
// BNCNetworkInterfaceTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Ernest Cho on 3/10/23.
6+
// Copyright © 2023 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import <arpa/inet.h>
11+
#import "BNCNetworkInterface.h"
12+
13+
// Category using inet_pton to validate
14+
@implementation NSString (Test)
15+
16+
- (BOOL)isValidIPAddress {
17+
const char *utf8 = [self UTF8String];
18+
int success;
19+
20+
struct in_addr dst;
21+
success = inet_pton(AF_INET, utf8, &dst);
22+
if (success != 1) {
23+
struct in6_addr dst6;
24+
success = inet_pton(AF_INET6, utf8, &dst6);
25+
}
26+
27+
return success == 1;
28+
}
29+
30+
@end
31+
32+
@interface BNCNetworkInterfaceTests : XCTestCase
33+
34+
@end
35+
36+
@implementation BNCNetworkInterfaceTests
37+
38+
- (void)setUp {
39+
40+
}
41+
42+
- (void)tearDown {
43+
44+
}
45+
46+
// verify tooling method works
47+
- (void)testIPValidationCategory {
48+
XCTAssert(![@"" isValidIPAddress]);
49+
50+
// ipv4
51+
XCTAssert([@"0.0.0.0" isValidIPAddress]);
52+
XCTAssert([@"127.0.0.1" isValidIPAddress]);
53+
XCTAssert([@"10.1.2.3" isValidIPAddress]);
54+
XCTAssert([@"172.0.0.0" isValidIPAddress]);
55+
XCTAssert([@"192.0.0.0" isValidIPAddress]);
56+
XCTAssert([@"255.255.255.255" isValidIPAddress]);
57+
58+
// invalid ipv4
59+
XCTAssert(![@"-1.0.0.0" isValidIPAddress]);
60+
XCTAssert(![@"256.0.0.0" isValidIPAddress]);
61+
62+
// ipv6
63+
XCTAssert([@"2001:0db8:0000:0000:0000:8a2e:0370:7334" isValidIPAddress]);
64+
XCTAssert([@"2001:db8::8a2e:370:7334" isValidIPAddress]);
65+
66+
// invalid ipv6
67+
XCTAssert(![@"2001:0db8:0000:0000:0000:8a2e:0370:733g" isValidIPAddress]);
68+
XCTAssert(![@"2001:0db8:0000:0000:0000:8a2e:0370:7330:1234" isValidIPAddress]);
69+
}
70+
71+
- (void)testLocalIPAddress {
72+
XCTAssert([[BNCNetworkInterface localIPAddress] isValidIPAddress]);
73+
}
74+
75+
- (void)testAllIPAddresses {
76+
// All IP addresses is a debug method that returns object descriptions
77+
for (NSString *address in BNCNetworkInterface.allIPAddresses) {
78+
XCTAssert([address containsString:@"BNCNetworkInterface"]);
79+
}
80+
}
81+
82+
@end

0 commit comments

Comments
 (0)