FIRDocumentSnapshotTests.mm 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <FirebaseFirestore/FIRDocumentSnapshot.h>
  17. #import <XCTest/XCTest.h>
  18. #import "Firestore/Example/Tests/API/FSTAPIHelpers.h"
  19. NS_ASSUME_NONNULL_BEGIN
  20. @interface FIRDocumentSnapshotTests : XCTestCase
  21. @end
  22. @implementation FIRDocumentSnapshotTests
  23. - (void)testEquals {
  24. FIRDocumentSnapshot *base = FSTTestDocSnapshot("rooms/foo", 1, @{@"a" : @1}, NO, NO);
  25. FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot("rooms/foo", 1, @{@"a" : @1}, NO, NO);
  26. FIRDocumentSnapshot *nilData = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO);
  27. FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO);
  28. FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot("rooms/bar", 1, @{@"a" : @1}, NO, NO);
  29. FIRDocumentSnapshot *differentData = FSTTestDocSnapshot("rooms/bar", 1, @{@"b" : @1}, NO, NO);
  30. FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot("rooms/bar", 1, @{@"a" : @1}, YES, NO);
  31. FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot("rooms/bar", 1, @{@"a" : @1}, NO, YES);
  32. XCTAssertEqualObjects(base, baseDup);
  33. XCTAssertEqualObjects(nilData, nilDataDup);
  34. XCTAssertNotEqualObjects(base, nilData);
  35. XCTAssertNotEqualObjects(nilData, base);
  36. XCTAssertNotEqualObjects(base, differentPath);
  37. XCTAssertNotEqualObjects(base, differentData);
  38. XCTAssertNotEqualObjects(base, hasMutations);
  39. XCTAssertNotEqualObjects(base, fromCache);
  40. XCTAssertEqual([base hash], [baseDup hash]);
  41. XCTAssertEqual([nilData hash], [nilDataDup hash]);
  42. XCTAssertNotEqual([base hash], [nilData hash]);
  43. XCTAssertNotEqual([base hash], [differentPath hash]);
  44. XCTAssertNotEqual([base hash], [differentData hash]);
  45. XCTAssertNotEqual([base hash], [hasMutations hash]);
  46. XCTAssertNotEqual([base hash], [fromCache hash]);
  47. }
  48. @end
  49. NS_ASSUME_NONNULL_END