Skip to content

Commit dd242dc

Browse files
authored
Add tests for GDTCORPlatform (#4972)
* add GDTCORPlatformTest * styled * tests changes * add endbackgroundtest assert
1 parent a310248 commit dd242dc

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2020 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <GoogleDataTransport/GDTCORPlatform.h>
18+
#import <GoogleDataTransport/GDTCORReachability.h>
19+
20+
#import "GDTCORTests/Unit/GDTCORTestCase.h"
21+
22+
@interface GDTCORPlatformTest : GDTCORTestCase
23+
24+
@end
25+
26+
@implementation GDTCORPlatformTest
27+
28+
/** Tests the reachability of mobile network connection in current platform. */
29+
- (void)testMobileConnectionReachability {
30+
SCNetworkReachabilityFlags reachabilityFlags;
31+
XCTAssertNoThrow(reachabilityFlags = [GDTCORReachability currentFlags]);
32+
XCTAssertNotEqual(reachabilityFlags, 0);
33+
// The mobile network connection should be always false in simulator logic test.
34+
XCTAssertFalse(GDTCORReachabilityFlagsContainWWAN(reachabilityFlags));
35+
}
36+
37+
/** Tests network connection type message generating in current platform. */
38+
- (void)testGetNetworkConnectionType {
39+
NSInteger networkConnectionType;
40+
XCTAssertNoThrow(networkConnectionType = GDTCORNetworkTypeMessage());
41+
// The network connection type should be always WIFI in simulator logic test.
42+
XCTAssertEqual(networkConnectionType, GDTCORNetworkTypeWIFI);
43+
}
44+
45+
/** Tests mobile network connection subtype generating in current platform. */
46+
- (void)testGetNetworkMobileSubtype {
47+
NSInteger networkMobileSubtype;
48+
XCTAssertNoThrow(networkMobileSubtype = GDTCORNetworkMobileSubTypeMessage());
49+
// The network connection moblie subtype should be always UNKNOWN in simulator logic test.
50+
XCTAssertEqual(networkMobileSubtype, GDTCORNetworkMobileSubtypeUNKNOWN);
51+
}
52+
53+
/** Tests the designated initializer of GDTCORApplication. */
54+
- (void)testInitializeGDTCORApplication {
55+
GDTCORApplication *application;
56+
XCTAssertNoThrow(application = [[GDTCORApplication alloc] init]);
57+
XCTAssertNotNil(application);
58+
XCTAssertFalse(application.isRunningInBackground);
59+
}
60+
61+
/** Tests the sharedApplication generating of GDTCORApplication. */
62+
- (void)testGenerateSharedGDTCORApplication {
63+
GDTCORApplication *application;
64+
XCTAssertNoThrow(application = [GDTCORApplication sharedApplication]);
65+
XCTAssertNotNil(application);
66+
}
67+
68+
/** Tests background task creating of GDTCORApplication. */
69+
- (void)testGDTCORApplicationBeginBackgroundTask {
70+
GDTCORApplication *application;
71+
application = [[GDTCORApplication alloc] init];
72+
__block GDTCORBackgroundIdentifier bgID;
73+
XCTAssertNoThrow(bgID = [application beginBackgroundTaskWithName:@"GDTCORPlatformTest"
74+
expirationHandler:^{
75+
[application endBackgroundTask:bgID];
76+
bgID = GDTCORBackgroundIdentifierInvalid;
77+
}]);
78+
XCTAssertNoThrow([application endBackgroundTask:bgID]);
79+
}
80+
81+
@end

0 commit comments

Comments
 (0)