GIDProfileData+Testing.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/GIDProfileData+Testing.h"
  15. #import "GoogleSignIn/Sources/GIDProfileData_Private.h"
  16. NSString *const kEmail = @"nobody@gmail.com";
  17. NSString *const kName = @"Nobody Here";
  18. NSString *const kGivenName = @"Nobody";
  19. NSString *const kFamilyName = @"Here";
  20. NSString *const kImageURL = @"http://no.domain/empty";
  21. @implementation GIDProfileData (Testing)
  22. - (BOOL)isEqual:(id)object {
  23. if (self == object) {
  24. return YES;
  25. }
  26. if (![object isKindOfClass:[GIDProfileData class]]) {
  27. return NO;
  28. }
  29. return [self isEqualToProfileData:(GIDProfileData *)object];
  30. }
  31. - (BOOL)isEqualToProfileData:(GIDProfileData *)other {
  32. return [self.email isEqual:other.email] &&
  33. [self.name isEqual:other.name] &&
  34. [self.givenName isEqual:other.givenName] &&
  35. [self.familyName isEqual:other.familyName] &&
  36. // Not something you want to use in production. Should compare _imageURL instead.
  37. [[self imageURLWithDimension:0].absoluteString isEqual:
  38. [other imageURLWithDimension:0].absoluteString];
  39. }
  40. // Not the hash implemention you want to use on prod, but just to match |isEqual:| here.
  41. - (NSUInteger)hash {
  42. return [self.email hash] ^
  43. [self.name hash] ^
  44. [self.givenName hash] ^
  45. [self.familyName hash] ^
  46. [[self imageURLWithDimension:0] hash];
  47. }
  48. + (instancetype)testInstance {
  49. return [self testInstanceWithImageURL:kImageURL];
  50. }
  51. + (instancetype)testInstanceWithImageURL:(NSString *)imageURL {
  52. return [[GIDProfileData alloc] initWithEmail:kEmail
  53. name:kName
  54. givenName:kGivenName
  55. familyName:kFamilyName
  56. imageURL:[NSURL URLWithString:imageURL]];
  57. }
  58. @end