FIRQuerySnapshotTests.mm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/FIRQuerySnapshot.h>
  17. #import <XCTest/XCTest.h>
  18. #import "Firestore/Source/Model/FSTPath.h"
  19. #import "Firestore/Example/Tests/API/FSTAPIHelpers.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface FIRQuerySnapshotTests : XCTestCase
  22. @end
  23. @implementation FIRQuerySnapshotTests
  24. - (void)testEquals {
  25. FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO);
  26. FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO);
  27. FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot(@"bar", @{},
  28. @{ @"a" : @{@"a" : @1} }, YES, NO);
  29. FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot(@"foo",
  30. @{ @"a" : @{@"b" : @1} }, @{}, YES, NO);
  31. FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot(@"foo", @{},
  32. @{ @"a" : @{@"a" : @1} }, NO, NO);
  33. FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot(@"foo", @{},
  34. @{ @"a" : @{@"a" : @1} }, YES, YES);
  35. XCTAssertEqualObjects(foo, fooDup);
  36. XCTAssertNotEqualObjects(foo, differentPath);
  37. XCTAssertNotEqualObjects(foo, differentDoc);
  38. XCTAssertNotEqualObjects(foo, noPendingWrites);
  39. XCTAssertNotEqualObjects(foo, fromCache);
  40. XCTAssertEqual([foo hash], [fooDup hash]);
  41. XCTAssertNotEqual([foo hash], [differentPath hash]);
  42. XCTAssertNotEqual([foo hash], [differentDoc hash]);
  43. XCTAssertNotEqual([foo hash], [noPendingWrites hash]);
  44. XCTAssertNotEqual([foo hash], [fromCache hash]);
  45. }
  46. @end
  47. NS_ASSUME_NONNULL_END