GULAppEnvironmentUtilTest.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 <OCMock/OCMock.h>
  16. #import <XCTest/XCTest.h>
  17. #import "GoogleUtilities/Environment/Private/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. @end