GIDGoogleUser+Testing.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/Tests/Unit/GIDGoogleUser+Testing.h"
  15. #import "GoogleSignIn/Sources/GIDGoogleUser_Private.h"
  16. #import "GoogleSignIn/Sources/GIDAuthentication.h"
  17. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDConfiguration.h"
  18. #import "GoogleSignIn/Sources/Public/GoogleSignIn/GIDToken.h"
  19. #import "GoogleSignIn/Tests/Unit/GIDConfiguration+Testing.h"
  20. #import "GoogleSignIn/Tests/Unit/GIDProfileData+Testing.h"
  21. // Key constants used for encode and decode.
  22. static NSString *const kProfileDataKey = @"profileData";
  23. static NSString *const kAuthentication = @"authentication";
  24. @implementation GIDGoogleUser (Testing)
  25. - (BOOL)isEqual:(id)object {
  26. if (self == object) {
  27. return YES;
  28. }
  29. if (![object isKindOfClass:[GIDGoogleUser class]]) {
  30. return NO;
  31. }
  32. return [self isEqualToGoogleUser:(GIDGoogleUser *)object];
  33. }
  34. - (BOOL)isEqualToGoogleUser:(GIDGoogleUser *)other {
  35. return [self.userID isEqual:other.userID] &&
  36. [self.profile isEqual:other.profile] &&
  37. [self.configuration isEqual:other.configuration] &&
  38. [self.idToken isEqual:other.idToken] &&
  39. [self.refreshToken isEqual:other.refreshToken] &&
  40. [self.accessToken isEqual:other.accessToken];
  41. }
  42. // Not the hash implemention you want to use on prod, but just to match |isEqual:| here.
  43. - (NSUInteger)hash {
  44. return [self.userID hash] ^ [self.configuration hash] ^ [self.profile hash] ^
  45. [self.idToken hash] ^ [self.refreshToken hash] ^ [self.accessToken hash];
  46. }
  47. @end
  48. @implementation GIDGoogleUserOldFormat {
  49. GIDAuthentication *_authentication;
  50. GIDProfileData *_profile;
  51. }
  52. - (instancetype)initWithAuthState:(OIDAuthState *)authState
  53. profileData:(GIDProfileData *)profileData {
  54. self = [super initWithAuthState:authState profileData:profileData];
  55. if (self) {
  56. _authentication = [[GIDAuthentication alloc] initWithAuthState:authState];
  57. _profile = profileData;
  58. }
  59. return self;
  60. }
  61. #pragma mark - NSSecureCoding
  62. - (void)encodeWithCoder:(NSCoder *)encoder {
  63. [encoder encodeObject:_profile forKey:kProfileDataKey];
  64. [encoder encodeObject:_authentication forKey:kAuthentication];
  65. }
  66. @end