GDTCORPlatformTest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #import <GoogleDataTransport/GDTCORPlatform.h>
  17. #import <GoogleDataTransport/GDTCORReachability.h>
  18. #import "GDTCORTests/Unit/GDTCORTestCase.h"
  19. @interface GDTCORPlatformTest : GDTCORTestCase
  20. @end
  21. @implementation GDTCORPlatformTest
  22. /** Tests the reachability of mobile network connection in current platform. */
  23. - (void)testMobileConnectionReachability {
  24. SCNetworkReachabilityFlags reachabilityFlags;
  25. XCTAssertNoThrow(reachabilityFlags = [GDTCORReachability currentFlags]);
  26. XCTAssertNotEqual(reachabilityFlags, 0);
  27. // The mobile network connection should be always false in simulator logic test.
  28. XCTAssertFalse(GDTCORReachabilityFlagsContainWWAN(reachabilityFlags));
  29. }
  30. /** Tests network connection type message generating in current platform. */
  31. - (void)testGetNetworkConnectionType {
  32. NSInteger networkConnectionType;
  33. XCTAssertNoThrow(networkConnectionType = GDTCORNetworkTypeMessage());
  34. // The network connection type should be always WIFI in simulator logic test.
  35. XCTAssertEqual(networkConnectionType, GDTCORNetworkTypeWIFI);
  36. }
  37. /** Tests mobile network connection subtype generating in current platform. */
  38. - (void)testGetNetworkMobileSubtype {
  39. NSInteger networkMobileSubtype;
  40. XCTAssertNoThrow(networkMobileSubtype = GDTCORNetworkMobileSubTypeMessage());
  41. // The network connection moblie subtype should be always UNKNOWN in simulator logic test.
  42. XCTAssertEqual(networkMobileSubtype, GDTCORNetworkMobileSubtypeUNKNOWN);
  43. }
  44. /** Tests the designated initializer of GDTCORApplication. */
  45. - (void)testInitializeGDTCORApplication {
  46. GDTCORApplication *application;
  47. XCTAssertNoThrow(application = [[GDTCORApplication alloc] init]);
  48. XCTAssertNotNil(application);
  49. XCTAssertFalse(application.isRunningInBackground);
  50. }
  51. /** Tests the sharedApplication generating of GDTCORApplication. */
  52. - (void)testGenerateSharedGDTCORApplication {
  53. GDTCORApplication *application;
  54. XCTAssertNoThrow(application = [GDTCORApplication sharedApplication]);
  55. XCTAssertNotNil(application);
  56. }
  57. /** Tests background task creating of GDTCORApplication. */
  58. - (void)testGDTCORApplicationBeginBackgroundTask {
  59. GDTCORApplication *application;
  60. application = [[GDTCORApplication alloc] init];
  61. __block GDTCORBackgroundIdentifier bgID;
  62. XCTAssertNoThrow(bgID = [application beginBackgroundTaskWithName:@"GDTCORPlatformTest"
  63. expirationHandler:^{
  64. [application endBackgroundTask:bgID];
  65. bgID = GDTCORBackgroundIdentifierInvalid;
  66. }]);
  67. XCTAssertNoThrow([application endBackgroundTask:bgID]);
  68. }
  69. @end