GULAppEnvironmentUtilTest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2018 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. #import <XCTest/XCTest.h>
  16. #import "OCMock.h"
  17. #import "GoogleUtilities/Environment/Public/GoogleUtilities/GULAppEnvironmentUtil.h"
  18. @interface GULAppEnvironmentUtilTest : XCTestCase
  19. @property(nonatomic) id processInfoMock;
  20. @end
  21. @implementation GULAppEnvironmentUtilTest
  22. - (void)setUp {
  23. [super setUp];
  24. _processInfoMock = OCMPartialMock([NSProcessInfo processInfo]);
  25. }
  26. - (void)tearDown {
  27. [super tearDown];
  28. [_processInfoMock stopMocking];
  29. }
  30. // Remove the #if when iOS can remove iOS 7 support and also use processInfo instead of UIKit.
  31. #if TARGET_OS_OSX || TARGET_OS_TV
  32. - (void)testSystemVersionInfoMajorOnly {
  33. NSOperatingSystemVersion osTen = {.majorVersion = 10, .minorVersion = 0, .patchVersion = 0};
  34. OCMStub([self.processInfoMock operatingSystemVersion]).andReturn(osTen);
  35. XCTAssertTrue([[GULAppEnvironmentUtil systemVersion] isEqualToString:@"10.0"]);
  36. }
  37. - (void)testSystemVersionInfoMajorMinor {
  38. NSOperatingSystemVersion osTenTwo = {.majorVersion = 10, .minorVersion = 2, .patchVersion = 0};
  39. OCMStub([self.processInfoMock operatingSystemVersion]).andReturn(osTenTwo);
  40. XCTAssertTrue([[GULAppEnvironmentUtil systemVersion] isEqualToString:@"10.2"]);
  41. }
  42. - (void)testSystemVersionInfoMajorMinorPatch {
  43. NSOperatingSystemVersion osTenTwoOne = {.majorVersion = 10, .minorVersion = 2, .patchVersion = 1};
  44. OCMStub([self.processInfoMock operatingSystemVersion]).andReturn(osTenTwoOne);
  45. XCTAssertTrue([[GULAppEnvironmentUtil systemVersion] isEqualToString:@"10.2.1"]);
  46. }
  47. #endif
  48. - (void)testDeploymentType {
  49. #if SWIFT_PACKAGE
  50. NSString *deploymentType = @"swiftpm";
  51. #elif FIREBASE_BUILD_CARTHAGE
  52. NSString *deploymentType = @"carthage";
  53. #elif FIREBASE_BUILD_ZIP_FILE
  54. NSString *deploymentType = @"zip";
  55. #else
  56. NSString *deploymentType = @"cocoapods";
  57. #endif
  58. XCTAssertEqualObjects([GULAppEnvironmentUtil deploymentType], deploymentType);
  59. }
  60. - (void)testApplePlatform {
  61. // When a Catalyst app is run on macOS then both `TARGET_OS_MACCATALYST` and `TARGET_OS_IOS` are
  62. // `true`.
  63. #if TARGET_OS_MACCATALYST
  64. NSString *expectedPlatform = @"maccatalyst";
  65. #elif TARGET_OS_IOS
  66. NSString *expectedPlatform = @"ios";
  67. #endif // TARGET_OS_MACCATALYST
  68. #if TARGET_OS_TV
  69. NSString *expectedPlatform = @"tvos";
  70. #endif // TARGET_OS_TV
  71. #if TARGET_OS_OSX
  72. NSString *expectedPlatform = @"macos";
  73. #endif // TARGET_OS_OSX
  74. #if TARGET_OS_WATCH
  75. NSString *expectedPlatform = @"watchos";
  76. #endif // TARGET_OS_WATCH
  77. XCTAssertEqualObjects([GULAppEnvironmentUtil applePlatform], expectedPlatform);
  78. }
  79. - (void)testHasSwiftRuntime {
  80. XCTAssertFalse([GULAppEnvironmentUtil hasSwiftRuntime]);
  81. }
  82. @end