GIDAuthentication+Testing.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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/GIDAuthentication+Testing.h"
  15. @implementation GIDAuthentication (Testing)
  16. - (BOOL)isEqual:(id)object {
  17. if (self == object) {
  18. return YES;
  19. }
  20. if (![object isKindOfClass:[GIDAuthentication class]]) {
  21. return NO;
  22. }
  23. return [self isEqualToAuthentication:(GIDAuthentication *)object];
  24. }
  25. - (BOOL)isEqualToAuthentication:(GIDAuthentication *)other {
  26. return [self.clientID isEqual:other.clientID] &&
  27. [self.accessToken isEqual:other.accessToken] &&
  28. [self.accessTokenExpirationDate isEqual:other.accessTokenExpirationDate] &&
  29. [self.refreshToken isEqual:other.refreshToken] &&
  30. (self.idToken == other.idToken || [self.idToken isEqual:other.idToken]) &&
  31. (self.idTokenExpirationDate == other.idTokenExpirationDate ||
  32. [self.idTokenExpirationDate isEqual:other.idTokenExpirationDate]);
  33. }
  34. // Not the hash implemention you want to use on prod, but just to match |isEqual:| here.
  35. - (NSUInteger)hash {
  36. return [self.clientID hash] ^ [self.accessToken hash] ^ [self.accessTokenExpirationDate hash] ^
  37. [self.refreshToken hash] ^ [self.idToken hash] ^ [self.idTokenExpirationDate hash];
  38. }
  39. @end