GIDConfigurationTest.m 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // Copyright 2021 Google LLC
  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 "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
  15. #import <XCTest/XCTest.h>
  16. #import <objc/runtime.h>
  17. #import "GoogleSignIn/Tests/Unit/GIDConfiguration+Testing.h"
  18. #import "GoogleSignIn/Tests/Unit/OIDAuthorizationRequest+Testing.h"
  19. #import "GoogleSignIn/Tests/Unit/OIDTokenResponse+Testing.h"
  20. @interface GIDConfigurationTest : XCTestCase
  21. @end
  22. @implementation GIDConfigurationTest
  23. #pragma mark - Tests
  24. - (void)testClientIDInitializer {
  25. GIDConfiguration *configuration =
  26. [[GIDConfiguration alloc] initWithClientID:OIDAuthorizationRequestTestingClientID];
  27. XCTAssertEqualObjects(configuration.clientID, OIDAuthorizationRequestTestingClientID);
  28. XCTAssertNil(configuration.serverClientID);
  29. XCTAssertNil(configuration.hostedDomain);
  30. XCTAssertNil(configuration.openIDRealm);
  31. }
  32. - (void)testClientIDServerIDInitializer {
  33. GIDConfiguration *configuration =
  34. [[GIDConfiguration alloc] initWithClientID:OIDAuthorizationRequestTestingClientID
  35. serverClientID:kServerClientID];
  36. XCTAssertEqualObjects(configuration.clientID, OIDAuthorizationRequestTestingClientID);
  37. XCTAssertEqualObjects(configuration.serverClientID, kServerClientID);
  38. XCTAssertNil(configuration.hostedDomain);
  39. XCTAssertNil(configuration.openIDRealm);
  40. }
  41. - (void)testFullInitializer {
  42. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  43. XCTAssertEqualObjects(configuration.clientID, OIDAuthorizationRequestTestingClientID);
  44. XCTAssertEqualObjects(configuration.serverClientID, kServerClientID);
  45. XCTAssertEqualObjects(configuration.hostedDomain, kHostedDomain);
  46. XCTAssertEqualObjects(configuration.openIDRealm, kOpenIDRealm);
  47. }
  48. - (void)testDescription {
  49. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  50. NSString *propertyString = @"";
  51. unsigned int outCount, c;
  52. objc_property_t *properties = class_copyPropertyList([configuration class], &outCount);
  53. NSString *propertyName;
  54. for (c = 0; c < outCount; c++) {
  55. propertyName = [NSString stringWithUTF8String:property_getName(properties[c])];
  56. propertyString = [propertyString stringByAppendingFormat:@", %@: %@",
  57. propertyName, [configuration valueForKey:propertyName]];
  58. }
  59. NSString *expectedDescription =
  60. [NSString stringWithFormat:@"<GIDConfiguration: %p%@>", configuration, propertyString];
  61. XCTAssertEqualObjects(configuration.description, expectedDescription);
  62. }
  63. - (void)testCopying {
  64. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  65. GIDConfiguration *copiedConfiguration = [configuration copy];
  66. // Should be the same object.
  67. XCTAssertEqual(configuration, copiedConfiguration);
  68. }
  69. - (void)testCoding {
  70. if (@available(iOS 11, macOS 10.13, *)) {
  71. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  72. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration
  73. requiringSecureCoding:YES
  74. error:nil];
  75. GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchivedObjectOfClass:[GIDConfiguration class]
  76. fromData:data
  77. error:nil];
  78. XCTAssertEqualObjects(configuration, newConfiguration);
  79. XCTAssertTrue(GIDConfiguration.supportsSecureCoding);
  80. } else {
  81. XCTSkip(@"Required API is not available for this test.");
  82. }
  83. }
  84. #if TARGET_OS_IOS || TARGET_OS_MACCATALYST
  85. // Deprecated in iOS 13 and macOS 10.14
  86. - (void)testLegacyCoding {
  87. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  88. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration];
  89. GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  90. XCTAssertEqualObjects(configuration, newConfiguration);
  91. XCTAssertTrue(GIDConfiguration.supportsSecureCoding);
  92. }
  93. #endif
  94. @end