GIDConfigurationTest.m 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.loginHint);
  30. XCTAssertNil(configuration.hostedDomain);
  31. XCTAssertNil(configuration.openIDRealm);
  32. }
  33. - (void)testClientIDServerIDInitializer {
  34. GIDConfiguration *configuration =
  35. [[GIDConfiguration alloc] initWithClientID:OIDAuthorizationRequestTestingClientID
  36. serverClientID:kServerClientID];
  37. XCTAssertEqualObjects(configuration.clientID, OIDAuthorizationRequestTestingClientID);
  38. XCTAssertEqualObjects(configuration.serverClientID, kServerClientID);
  39. XCTAssertNil(configuration.loginHint);
  40. XCTAssertNil(configuration.hostedDomain);
  41. XCTAssertNil(configuration.openIDRealm);
  42. }
  43. - (void)testFullInitializer {
  44. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  45. XCTAssertEqualObjects(configuration.clientID, OIDAuthorizationRequestTestingClientID);
  46. XCTAssertEqualObjects(configuration.serverClientID, kServerClientID);
  47. XCTAssertEqualObjects(configuration.loginHint, kLoginHint);
  48. XCTAssertEqualObjects(configuration.hostedDomain, kHostedDomain);
  49. XCTAssertEqualObjects(configuration.openIDRealm, kOpenIDRealm);
  50. }
  51. - (void)testDescription {
  52. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  53. NSString *propertyString = @"";
  54. unsigned int outCount, c;
  55. objc_property_t *properties = class_copyPropertyList([configuration class], &outCount);
  56. NSString *propertyName;
  57. for (c = 0; c < outCount; c++) {
  58. propertyName = [NSString stringWithUTF8String:property_getName(properties[c])];
  59. propertyString = [propertyString stringByAppendingFormat:@", %@: %@",
  60. propertyName, [configuration valueForKey:propertyName]];
  61. }
  62. NSString *expectedDescription =
  63. [NSString stringWithFormat:@"<GIDConfiguration: %p%@>", configuration, propertyString];
  64. XCTAssertEqualObjects(configuration.description, expectedDescription);
  65. }
  66. - (void)testCopying {
  67. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  68. GIDConfiguration *copiedConfiguration = [configuration copy];
  69. // Should be the same object.
  70. XCTAssertEqual(configuration, copiedConfiguration);
  71. }
  72. - (void)testCoding {
  73. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  74. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration];
  75. GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  76. XCTAssertEqualObjects(configuration, newConfiguration);
  77. XCTAssertTrue(GIDConfiguration.supportsSecureCoding);
  78. }
  79. @end