|
| 1 | +// |
| 2 | +// BNCDeviceInfoTests.m |
| 3 | +// Branch-SDK-Tests |
| 4 | +// |
| 5 | +// Created by Ernest Cho on 11/21/19. |
| 6 | +// Copyright © 2019 Branch, Inc. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import <XCTest/XCTest.h> |
| 10 | +#import "BNCDeviceInfo.h" |
| 11 | + |
| 12 | +@interface BNCDeviceInfoTests : XCTestCase |
| 13 | +@property (nonatomic, strong, readwrite) BNCDeviceInfo *deviceInfo; |
| 14 | +@end |
| 15 | + |
| 16 | +@implementation BNCDeviceInfoTests |
| 17 | + |
| 18 | +- (void)setUp { |
| 19 | + self.deviceInfo = [BNCDeviceInfo new]; |
| 20 | +} |
| 21 | + |
| 22 | +- (void)tearDown { |
| 23 | + |
| 24 | +} |
| 25 | + |
| 26 | +- (void)testAppVersion { |
| 27 | + // checks test app version |
| 28 | + XCTAssert([@"1.1" isEqualToString:self.deviceInfo.applicationVersion]); |
| 29 | +} |
| 30 | + |
| 31 | +- (void)testBrandName { |
| 32 | + XCTAssert([@"Apple" isEqualToString:self.deviceInfo.brandName]); |
| 33 | +} |
| 34 | + |
| 35 | +- (void)testModelName_Simulator { |
| 36 | + XCTAssert([@"x86_64" isEqualToString:self.deviceInfo.modelName]); |
| 37 | +} |
| 38 | + |
| 39 | +//- (void)testModelName_iPhone7 { |
| 40 | +// XCTAssert([@"iPhone9,3" isEqualToString:self.deviceInfo.modelName]); |
| 41 | +//} |
| 42 | + |
| 43 | +- (void)testOSName { |
| 44 | + XCTAssertNotNil(self.deviceInfo.osName); |
| 45 | + XCTAssert([self.deviceInfo.osName isEqualToString:[UIDevice currentDevice].systemName]); |
| 46 | +} |
| 47 | + |
| 48 | +- (void)testOSVersion { |
| 49 | + XCTAssertNotNil(self.deviceInfo.osVersion); |
| 50 | + XCTAssert([self.deviceInfo.osVersion isEqualToString:[UIDevice currentDevice].systemVersion]); |
| 51 | +} |
| 52 | + |
| 53 | +- (void)testOSBuildVersion { |
| 54 | + XCTAssertNotNil(self.deviceInfo.osBuildVersion); |
| 55 | +} |
| 56 | + |
| 57 | +- (void)testExtensionType { |
| 58 | + XCTAssert([@"FULL_APP" isEqualToString:self.deviceInfo.extensionType]); |
| 59 | +} |
| 60 | + |
| 61 | +- (void)testCpuType_Simulator { |
| 62 | + NSNumber *expected = @(7); |
| 63 | + XCTAssert([expected isEqualToNumber:self.deviceInfo.cpuType]); |
| 64 | +} |
| 65 | + |
| 66 | +//- (void)testCpuType_iPhone7 { |
| 67 | +// NSNumber *expected = @(16777228); |
| 68 | +// XCTAssert([expected isEqualToNumber:self.deviceInfo.cpuType]); |
| 69 | +//} |
| 70 | + |
| 71 | +- (void)testScreenWidth { |
| 72 | + XCTAssert(self.deviceInfo.screenWidth.intValue > 320); |
| 73 | +} |
| 74 | + |
| 75 | +- (void)testScreenHeight { |
| 76 | + XCTAssert(self.deviceInfo.screenHeight.intValue > 320); |
| 77 | +} |
| 78 | + |
| 79 | +- (void)testScreenScale { |
| 80 | + XCTAssert(self.deviceInfo.screenScale.intValue > 0); |
| 81 | +} |
| 82 | + |
| 83 | +- (void)testCarrierName_Simulator { |
| 84 | + XCTAssertNil(self.deviceInfo.carrierName); |
| 85 | +} |
| 86 | + |
| 87 | +//- (void)testCarrierName_Att { |
| 88 | +// XCTAssert([@"AT&T" isEqualToString:self.deviceInfo.carrierName]); |
| 89 | +//} |
| 90 | + |
| 91 | +- (void)testLocale { |
| 92 | + NSString *locale = [NSLocale currentLocale].localeIdentifier; |
| 93 | + XCTAssertNotNil(locale); |
| 94 | + XCTAssert([locale isEqualToString:self.deviceInfo.locale]); |
| 95 | +} |
| 96 | + |
| 97 | +- (void)testCountry { |
| 98 | + NSString *locale = [NSLocale currentLocale].localeIdentifier; |
| 99 | + XCTAssertNotNil(locale); |
| 100 | + XCTAssert([locale containsString:self.deviceInfo.country]); |
| 101 | +} |
| 102 | + |
| 103 | +- (void)testLanguage { |
| 104 | + NSString *locale = [NSLocale currentLocale].localeIdentifier; |
| 105 | + XCTAssertNotNil(locale); |
| 106 | + XCTAssert([locale containsString:self.deviceInfo.language]); |
| 107 | +} |
| 108 | + |
| 109 | +- (void)testUserAgentString { |
| 110 | + // Currently this method is a trivial pass through to the BNCUserAgentCollector singleton |
| 111 | + // Eventually remove the singleton to enable easier testing |
| 112 | +} |
| 113 | + |
| 114 | +- (void)testPlugin { |
| 115 | + XCTAssertNil(self.deviceInfo.pluginName); |
| 116 | + XCTAssertNil(self.deviceInfo.pluginVersion); |
| 117 | + |
| 118 | + NSString *expectedName = @"react native"; |
| 119 | + NSString *expectedVersion = @"1.0.0"; |
| 120 | + |
| 121 | + [self.deviceInfo registerPluginName:expectedName version:expectedVersion]; |
| 122 | + |
| 123 | + XCTAssert([expectedName isEqualToString:self.deviceInfo.pluginName]); |
| 124 | + XCTAssert([expectedVersion isEqualToString:self.deviceInfo.pluginVersion]); |
| 125 | +} |
| 126 | + |
| 127 | +- (void)testLocalIPAddress { |
| 128 | + NSString *address = [self.deviceInfo localIPAddress]; |
| 129 | + XCTAssertNotNil(address); |
| 130 | + |
| 131 | + // shortest ipv4 is 7 |
| 132 | + XCTAssert(address.length >= 7); |
| 133 | +} |
| 134 | + |
| 135 | +// just a sanity check on the V2 dictionary |
| 136 | +- (void)testV2Dictionary { |
| 137 | + NSDictionary *dict = [self.deviceInfo v2dictionary]; |
| 138 | + XCTAssertNotNil(dict); |
| 139 | + XCTAssertNotNil([dict objectForKey:@"brand"]); |
| 140 | + XCTAssertNotNil([dict objectForKey:@"os"]); |
| 141 | + XCTAssertNotNil([dict objectForKey:@"sdk"]); |
| 142 | + XCTAssertNotNil([dict objectForKey:@"sdk_version"]); |
| 143 | +} |
| 144 | + |
| 145 | +@end |
0 commit comments