FIRQuerySnapshotTests.mm 2.2 KB

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