GIDConfigurationTest.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. GIDConfiguration *configuration = [GIDConfiguration testInstance];
  71. NSData *data = [NSKeyedArchiver archivedDataWithRootObject:configuration];
  72. GIDConfiguration *newConfiguration = [NSKeyedUnarchiver unarchiveObjectWithData:data];
  73. XCTAssertEqualObjects(configuration, newConfiguration);
  74. XCTAssertTrue(GIDConfiguration.supportsSecureCoding);
  75. }
  76. @end