From a080e481b5e6fcbc2b645920051cf20fc8cad7a7 Mon Sep 17 00:00:00 2001 From: Gil Date: Sat, 5 May 2018 08:10:51 -0700 Subject: Port FSTDocumentKeySet to C++ DocumentKeySet (#1229) * Define a Comparator for DocumentKey * Automated migration from FSTDocumentKeySet to DocumentKeySet * Manual fixups for DocumentKeySet * Delete FSTDocumentKeySet --- .../Example/Tests/Core/FSTQueryListenerTests.mm | 24 +++++---- Firestore/Example/Tests/Core/FSTViewTests.mm | 61 +++++++++++----------- .../Example/Tests/Local/FSTLocalSerializerTests.mm | 2 +- .../Example/Tests/Local/FSTLocalStoreTests.mm | 12 +++-- .../Example/Tests/Local/FSTQueryCacheTests.mm | 15 +++--- .../Example/Tests/Remote/FSTRemoteEventTests.mm | 31 +++++------ Firestore/Example/Tests/SpecTests/FSTSpecTests.mm | 11 ++-- Firestore/Example/Tests/Util/FSTHelpers.h | 4 -- Firestore/Example/Tests/Util/FSTHelpers.mm | 24 ++++----- 9 files changed, 91 insertions(+), 93 deletions(-) (limited to 'Firestore/Example/Tests') diff --git a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm index 0454152..7ae9704 100644 --- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm @@ -27,6 +27,8 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" +using firebase::firestore::model::DocumentKeySet; + NS_ASSUME_NONNULL_BEGIN @interface FSTQueryListenerTests : XCTestCase @@ -53,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum]; FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2prime ], nil); @@ -107,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil); FSTTargetChange *ackTarget = @@ -136,7 +138,7 @@ NS_ASSUME_NONNULL_BEGIN [listener mute]; }]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], nil); FSTViewSnapshot *viewSnapshot2 = FSTTestApplyChanges(view, @[ doc2 ], nil); @@ -178,7 +180,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryListener *fullListener = [self listenToQuery:query options:options accumulatingSnapshots:fullAccum]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil); FSTTargetChange *ackTarget = @@ -218,7 +220,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryListener *fullListener = [self listenToQuery:query options:options accumulatingSnapshots:fullAccum]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], nil); FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], nil); @@ -265,7 +267,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryListener *fullListener = [self listenToQuery:query options:options accumulatingSnapshots:fullAccum]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], nil); FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], nil); @@ -298,7 +300,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQueryListener *filteredListener = [self listenToQuery:query accumulatingSnapshots:filteredAccum]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime, doc3 ], nil); @@ -331,7 +333,7 @@ NS_ASSUME_NONNULL_BEGIN waitForSyncWhenOnline:YES] accumulatingSnapshots:events]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil); FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil); FSTViewSnapshot *snap3 = @@ -374,7 +376,7 @@ NS_ASSUME_NONNULL_BEGIN waitForSyncWhenOnline:YES] accumulatingSnapshots:events]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil); FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil); @@ -415,7 +417,7 @@ NS_ASSUME_NONNULL_BEGIN options:[FSTListenOptions defaultOptions] accumulatingSnapshots:events]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil); [listener applyChangedOnlineState:FSTOnlineStateOnline]; // no event @@ -441,7 +443,7 @@ NS_ASSUME_NONNULL_BEGIN options:[FSTListenOptions defaultOptions] accumulatingSnapshots:events]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil); [listener applyChangedOnlineState:FSTOnlineStateOffline]; // no event diff --git a/Firestore/Example/Tests/Core/FSTViewTests.mm b/Firestore/Example/Tests/Core/FSTViewTests.mm index 63ce711..ec62d82 100644 --- a/Firestore/Example/Tests/Core/FSTViewTests.mm +++ b/Firestore/Example/Tests/Core/FSTViewTests.mm @@ -34,6 +34,7 @@ namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::ResourcePath; +using firebase::firestore::model::DocumentKeySet; NS_ASSUME_NONNULL_BEGIN @@ -49,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testAddsDocumentsBasedOnQuery { FSTQuery *query = [self queryForMessages]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); @@ -77,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRemovesDocuments { FSTQuery *query = [self queryForMessages]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); @@ -108,7 +109,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testReturnsNilIfThereAreNoChanges { FSTQuery *query = [self queryForMessages]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); @@ -123,7 +124,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testDoesNotReturnNilForFirstChanges { FSTQuery *query = [self queryForMessages]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[], nil); XCTAssertNotNil(snapshot); @@ -137,7 +138,7 @@ NS_ASSUME_NONNULL_BEGIN value:[FSTDoubleValue doubleValue:2]]; query = [query queryByAddingFilter:filter]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{ @"sort" : @1 }, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"sort" : @2 }, NO); FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/3", 0, @{ @"sort" : @3 }, NO); @@ -169,7 +170,7 @@ NS_ASSUME_NONNULL_BEGIN value:[FSTDoubleValue doubleValue:2]]; query = [query queryByAddingFilter:filter]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{ @"sort" : @1 }, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"sort" : @3 }, NO); FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/3", 0, @{ @"sort" : @2 }, NO); @@ -205,7 +206,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRemovesDocumentsForQueryWithLimit { FSTQuery *query = [self queryForMessages]; query = [query queryBySettingLimit:2]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); @@ -239,7 +240,7 @@ NS_ASSUME_NONNULL_BEGIN query = [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("num") ascending:YES]]; query = [query queryBySettingLimit:2]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{ @"num" : @1 }, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"num" : @2 }, NO); @@ -283,7 +284,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testKeepsTrackOfLimboDocuments { FSTQuery *query = [self queryForMessages]; - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); @@ -339,8 +340,8 @@ NS_ASSUME_NONNULL_BEGIN // Unlike other cases, here the view is initialized with a set of previously synced documents // which happens when listening to a previously listened-to query. - FSTView *view = [[FSTView alloc] initWithQuery:query - remoteDocuments:FSTTestDocKeySet(@[ doc1.key, doc2.key ])]; + FSTView *view = + [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{doc1.key, doc2.key}]; FSTTargetChange *markCurrent = [FSTTargetChange changeWithDocuments:@[] @@ -361,7 +362,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [[self queryForMessages] queryBySettingLimit:2]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = @@ -394,7 +395,7 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{ @"order" : @1 }, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{ @"order" : @2 }, NO); FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"order" : @3 }, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = @@ -430,7 +431,7 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"order" : @3 }, NO); FSTDocument *doc4 = FSTTestDoc("rooms/eros/messages/3", 0, @{ @"order" : @4 }, NO); FSTDocument *doc5 = FSTTestDoc("rooms/eros/messages/4", 0, @{ @"order" : @5 }, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = @@ -460,7 +461,7 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"order" : @3 }, NO); FSTDocument *doc4 = FSTTestDoc("rooms/eros/messages/3", 0, @{ @"order" : @4 }, NO); FSTDocument *doc5 = FSTTestDoc("rooms/eros/messages/4", 0, @{ @"order" : @5 }, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = @@ -483,7 +484,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [[self queryForMessages] queryBySettingLimit:2]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = @@ -506,7 +507,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [[self queryForMessages] queryBySettingLimit:20]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewDocumentChanges *changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1, doc2 ])]; @@ -528,7 +529,7 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [[self queryForMessages] queryBySettingLimit:2]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = @@ -551,69 +552,69 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [self queryForMessages]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1, doc2 ])]; [view applyChangesToDocuments:changes]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[])); + XCTAssertEqual(changes.mutatedKeys, DocumentKeySet{}); FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, YES); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ])]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc3.key ])); + XCTAssertEqual(changes.mutatedKeys, DocumentKeySet{doc3.key}); } - (void)testRemovesKeysFromMutatedKeysWhenNewDocHasNoLocalChanges { FSTQuery *query = [self queryForMessages]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, YES); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1, doc2 ])]; [view applyChangesToDocuments:changes]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); + XCTAssertEqual(changes.mutatedKeys, (DocumentKeySet{doc2.key})); FSTDocument *doc2Prime = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc2Prime ])]; [view applyChangesToDocuments:changes]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[])); + XCTAssertEqual(changes.mutatedKeys, DocumentKeySet{}); } - (void)testRemembersLocalMutationsFromPreviousSnapshot { FSTQuery *query = [self queryForMessages]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, YES); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1, doc2 ])]; [view applyChangesToDocuments:changes]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); + XCTAssertEqual(changes.mutatedKeys, (DocumentKeySet{doc2.key})); FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ])]; [view applyChangesToDocuments:changes]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); + XCTAssertEqual(changes.mutatedKeys, (DocumentKeySet{doc2.key})); } - (void)testRemembersLocalMutationsFromPreviousCallToComputeChangesWithDocuments { FSTQuery *query = [self queryForMessages]; FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, YES); - FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; + FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; // Start with a full view. FSTViewDocumentChanges *changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1, doc2 ])]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); + XCTAssertEqual(changes.mutatedKeys, (DocumentKeySet{doc2.key})); FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ]) previousChanges:changes]; - XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); + XCTAssertEqual(changes.mutatedKeys, (DocumentKeySet{doc2.key})); } @end diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm index 421f244..0e160c0 100644 --- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm @@ -125,7 +125,7 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqual(decoded.batchID, model.batchID); XCTAssertEqualObjects(decoded.localWriteTime, model.localWriteTime); XCTAssertEqualObjects(decoded.mutations, model.mutations); - XCTAssertEqualObjects([decoded keys], [model keys]); + XCTAssertEqual([decoded keys], [model keys]); } - (void)testEncodesDocumentAsMaybeDocument { diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm index 4175118..c417646 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm @@ -46,6 +46,7 @@ namespace testutil = firebase::firestore::testutil; using firebase::firestore::auth::User; using firebase::firestore::model::SnapshotVersion; +using firebase::firestore::model::DocumentKeySet; NS_ASSUME_NONNULL_BEGIN @@ -230,8 +231,8 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:1 localWriteTime:[FIRTimestamp timestamp] mutations:@[ set1, set2 ]]; - FSTDocumentKeySet *keys = [batch keys]; - XCTAssertEqual(keys.count, 2); + DocumentKeySet keys = [batch keys]; + XCTAssertEqual(keys.size(), 2u); } - (void)testHandlesSetMutation { @@ -856,13 +857,14 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self.localStore locallyWriteMutations:@[ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) ]]; - FSTDocumentKeySet *keys = [self.localStore remoteDocumentKeysForTarget:2]; - FSTAssertEqualSets(keys, (@[ FSTTestDocKey(@"foo/bar"), FSTTestDocKey(@"foo/baz") ])); + DocumentKeySet keys = [self.localStore remoteDocumentKeysForTarget:2]; + DocumentKeySet expected{testutil::Key("foo/bar"), testutil::Key("foo/baz")}; + XCTAssertEqual(keys, expected); [self restartWithNoopGarbageCollector]; keys = [self.localStore remoteDocumentKeysForTarget:2]; - FSTAssertEqualSets(keys, (@[ FSTTestDocKey(@"foo/bar"), FSTTestDocKey(@"foo/baz") ])); + XCTAssertEqual(keys, (DocumentKeySet{testutil::Key("foo/bar"), testutil::Key("foo/baz")})); } @end diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm index 5d07516..44b49de 100644 --- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm @@ -32,6 +32,7 @@ namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DocumentKey; using firebase::firestore::model::SnapshotVersion; +using firebase::firestore::model::DocumentKeySet; NS_ASSUME_NONNULL_BEGIN @@ -278,12 +279,12 @@ NS_ASSUME_NONNULL_BEGIN [self addMatchingKey:key2 forTargetID:1]; [self addMatchingKey:key3 forTargetID:2]; - FSTAssertEqualSets([self.queryCache matchingKeysForTargetID:1], (@[ key1, key2 ])); - FSTAssertEqualSets([self.queryCache matchingKeysForTargetID:2], @[ key3 ]); + XCTAssertEqual([self.queryCache matchingKeysForTargetID:1], (DocumentKeySet{key1, key2})); + XCTAssertEqual([self.queryCache matchingKeysForTargetID:2], (DocumentKeySet{key3})); [self addMatchingKey:key1 forTargetID:2]; - FSTAssertEqualSets([self.queryCache matchingKeysForTargetID:1], (@[ key1, key2 ])); - FSTAssertEqualSets([self.queryCache matchingKeysForTargetID:2], (@[ key1, key3 ])); + XCTAssertEqual([self.queryCache matchingKeysForTargetID:1], (DocumentKeySet{key1, key2})); + XCTAssertEqual([self.queryCache matchingKeysForTargetID:2], (DocumentKeySet{key1, key3})); }); } @@ -428,14 +429,12 @@ NS_ASSUME_NONNULL_BEGIN } - (void)addMatchingKey:(const DocumentKey &)key forTargetID:(FSTTargetID)targetID { - FSTDocumentKeySet *keys = [FSTDocumentKeySet keySet]; - keys = [keys setByAddingObject:key]; + DocumentKeySet keys{key}; [self.queryCache addMatchingKeys:keys forTargetID:targetID]; } - (void)removeMatchingKey:(const DocumentKey &)key forTargetID:(FSTTargetID)targetID { - FSTDocumentKeySet *keys = [FSTDocumentKeySet keySet]; - keys = [keys setByAddingObject:key]; + DocumentKeySet keys{key}; [self.queryCache removeMatchingKeys:keys forTargetID:targetID]; } diff --git a/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm b/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm index e2cb8cc..84d0fa1 100644 --- a/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm +++ b/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm @@ -33,6 +33,7 @@ namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DocumentKey; +using firebase::firestore::model::DocumentKeySet; NS_ASSUME_NONNULL_BEGIN @@ -575,7 +576,7 @@ NS_ASSUME_NONNULL_BEGIN FSTDeletedDocument *expected = [FSTDeletedDocument documentWithKey:synthesized version:event.snapshotVersion]; XCTAssertEqualObjects(expected, event.documentUpdates.at(synthesized)); - XCTAssertTrue([event.limboDocumentChanges containsObject:synthesized]); + XCTAssertTrue(event.limboDocumentChanges.contains(synthesized)); } - (void)testDoesntSynthesizeDeletesForWrongState { @@ -590,7 +591,7 @@ NS_ASSUME_NONNULL_BEGIN DocumentKey notSynthesized = DocumentKey::FromPathString("docs/no1"); [event synthesizeDeleteForLimboTargetChange:event.targetChanges[@2] key:notSynthesized]; XCTAssertEqual(event.documentUpdates.find(notSynthesized), event.documentUpdates.end()); - XCTAssertFalse([event.limboDocumentChanges containsObject:notSynthesized]); + XCTAssertFalse(event.limboDocumentChanges.contains(notSynthesized)); } - (void)testDoesntSynthesizeDeletesForExistingDoc { @@ -609,7 +610,7 @@ NS_ASSUME_NONNULL_BEGIN [event synthesizeDeleteForLimboTargetChange:event.targetChanges[@3] key:doc.key]; FSTMaybeDocument *docData = event.documentUpdates.at(doc.key); XCTAssertFalse([docData isKindOfClass:[FSTDeletedDocument class]]); - XCTAssertFalse([event.limboDocumentChanges containsObject:doc.key]); + XCTAssertFalse(event.limboDocumentChanges.contains(doc.key)); } - (void)testFilterUpdates { @@ -631,24 +632,24 @@ NS_ASSUME_NONNULL_BEGIN outstanding:_noPendingResponses changes:@[ newDocChange, existingDocChange ]]; FSTRemoteEvent *event = [aggregator remoteEvent]; - FSTDocumentKeySet *existingKeys = [[FSTDocumentKeySet keySet] setByAddingObject:existingDoc.key]; + DocumentKeySet existingKeys = DocumentKeySet{existingDoc.key}; FSTTargetChange *updateChange = event.targetChanges[@1]; XCTAssertTrue([updateChange.mapping isKindOfClass:[FSTUpdateMapping class]]); FSTUpdateMapping *update = (FSTUpdateMapping *)updateChange.mapping; FSTDocumentKey *existingDocKey = existingDoc.key; FSTDocumentKey *newDocKey = newDoc.key; - XCTAssertTrue([update.addedDocuments containsObject:existingDocKey]); + XCTAssertTrue(update.addedDocuments.contains(existingDocKey)); [update filterUpdatesUsingExistingKeys:existingKeys]; // Now it's been filtered, since it already existed. - XCTAssertFalse([update.addedDocuments containsObject:existingDocKey]); - XCTAssertTrue([update.addedDocuments containsObject:newDocKey]); + XCTAssertFalse(update.addedDocuments.contains(existingDocKey)); + XCTAssertTrue(update.addedDocuments.contains(newDocKey)); } - (void)testDoesntFilterResets { FSTDocument *existingDoc = FSTTestDoc("docs/existing", 1, @{@"some" : @"data"}, NO); - FSTDocumentKey *existingDocKey = existingDoc.key; + const DocumentKey &existingDocKey = existingDoc.key; FSTWatchTargetChange *resetTargetChange = [FSTWatchTargetChange changeWithState:FSTWatchTargetChangeStateReset targetIDs:@[ @2 ] @@ -663,16 +664,16 @@ NS_ASSUME_NONNULL_BEGIN outstanding:_noPendingResponses changes:@[ resetTargetChange, existingDocChange ]]; FSTRemoteEvent *event = [aggregator remoteEvent]; - FSTDocumentKeySet *existingKeys = [[FSTDocumentKeySet keySet] setByAddingObject:existingDocKey]; + DocumentKeySet existingKeys = DocumentKeySet{existingDocKey}; FSTTargetChange *resetChange = event.targetChanges[@2]; XCTAssertTrue([resetChange.mapping isKindOfClass:[FSTResetMapping class]]); FSTResetMapping *resetMapping = (FSTResetMapping *)resetChange.mapping; - XCTAssertTrue([resetMapping.documents containsObject:existingDocKey]); + XCTAssertTrue(resetMapping.documents.contains(existingDocKey)); [resetMapping filterUpdatesUsingExistingKeys:existingKeys]; // Document is still there, even though it already exists. Reset mappings don't get filtered. - XCTAssertTrue([resetMapping.documents containsObject:existingDocKey]); + XCTAssertTrue(resetMapping.documents.contains(existingDocKey)); } - (void)testTracksLimboDocuments { @@ -715,13 +716,13 @@ NS_ASSUME_NONNULL_BEGIN [aggregator addWatchChanges:@[ docChange1, docChange2, docChange3, targetsChange ]]; FSTRemoteEvent *event = [aggregator remoteEvent]; - FSTDocumentKeySet *limboDocChanges = event.limboDocumentChanges; + DocumentKeySet limboDocChanges = event.limboDocumentChanges; // Doc1 is in both limbo and non-limbo targets, therefore not tracked as limbo - XCTAssertFalse([limboDocChanges containsObject:doc1.key]); + XCTAssertFalse(limboDocChanges.contains(doc1.key)); // Doc2 is only in the limbo target, so is tracked as a limbo document - XCTAssertTrue([limboDocChanges containsObject:doc2.key]); + XCTAssertTrue(limboDocChanges.contains(doc2.key)); // Doc3 is only in the non-limbo target, therefore not tracked as limbo - XCTAssertFalse([limboDocChanges containsObject:doc3.key]); + XCTAssertFalse(limboDocChanges.contains(doc3.key)); } @end diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm index 12be590..5a7cb72 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm @@ -603,10 +603,13 @@ static NSString *const kNoIOSTag = @"no-ios"; // XCTAssertEqualObjects(actualTargets[targetID], queryData); FSTQueryData *actual = actualTargets[targetID]; - XCTAssertEqualObjects(actual.query, queryData.query); - XCTAssertEqual(actual.targetID, queryData.targetID); - XCTAssertEqual(actual.snapshotVersion, queryData.snapshotVersion); - XCTAssertEqualObjects(actual.resumeToken, queryData.resumeToken); + XCTAssertNotNil(actual); + if (actual) { + XCTAssertEqualObjects(actual.query, queryData.query); + XCTAssertEqual(actual.targetID, queryData.targetID); + XCTAssertEqual(actual.snapshotVersion, queryData.snapshotVersion); + XCTAssertEqualObjects(actual.resumeToken, queryData.resumeToken); + } [actualTargets removeObjectForKey:targetID]; }]; diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index f80f163..ccc01ca 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -21,7 +21,6 @@ #import "Firestore/Source/Core/FSTTypes.h" #import "Firestore/Source/Model/FSTDocumentDictionary.h" -#import "Firestore/Source/Model/FSTDocumentKeySet.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" #include "Firestore/core/src/firebase/firestore/model/field_value.h" @@ -181,9 +180,6 @@ FSTObjectValue *FSTTestObjectValue(NSDictionary *data); /** A convenience method for creating document keys for tests. */ FSTDocumentKey *FSTTestDocKey(NSString *path); -/** A convenience method for creating a document key set for tests. */ -FSTDocumentKeySet *FSTTestDocKeySet(NSArray *keys); - /** Allow tests to just use an int literal for versions. */ typedef int64_t FSTTestSnapshotVersion; diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm index 92eb730..dbd19aa 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.mm +++ b/Firestore/Example/Tests/Util/FSTHelpers.mm @@ -44,6 +44,7 @@ #include "Firestore/core/src/firebase/firestore/model/database_id.h" #include "Firestore/core/src/firebase/firestore/model/document_key.h" +#include "Firestore/core/src/firebase/firestore/model/document_key_set.h" #include "Firestore/core/src/firebase/firestore/model/field_mask.h" #include "Firestore/core/src/firebase/firestore/model/field_transform.h" #include "Firestore/core/src/firebase/firestore/model/field_value.h" @@ -66,6 +67,7 @@ using firebase::firestore::model::Precondition; using firebase::firestore::model::ResourcePath; using firebase::firestore::model::ServerTimestampTransform; using firebase::firestore::model::TransformOperation; +using firebase::firestore::model::DocumentKeySet; NS_ASSUME_NONNULL_BEGIN @@ -146,14 +148,6 @@ FSTDocumentKey *FSTTestDocKey(NSString *path) { return [FSTDocumentKey keyWithPathString:path]; } -FSTDocumentKeySet *FSTTestDocKeySet(NSArray *keys) { - FSTDocumentKeySet *result = [FSTDocumentKeySet keySet]; - for (FSTDocumentKey *key in keys) { - result = [result setByAddingObject:key]; - } - return result; -} - FSTDocument *FSTTestDoc(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary *data, @@ -343,17 +337,17 @@ NSData *_Nullable FSTTestResumeTokenFromSnapshotVersion(FSTTestSnapshotVersion s FSTLocalViewChanges *FSTTestViewChanges(FSTQuery *query, NSArray *addedKeys, NSArray *removedKeys) { - FSTDocumentKeySet *added = [FSTDocumentKeySet keySet]; + DocumentKeySet added; for (NSString *keyPath in addedKeys) { - FSTDocumentKey *key = FSTTestDocKey(keyPath); - added = [added setByAddingObject:key]; + added = added.insert(testutil::Key(util::MakeStringView(keyPath))); } - FSTDocumentKeySet *removed = [FSTDocumentKeySet keySet]; + DocumentKeySet removed; for (NSString *keyPath in removedKeys) { - FSTDocumentKey *key = FSTTestDocKey(keyPath); - removed = [removed setByAddingObject:key]; + removed = removed.insert(testutil::Key(util::MakeStringView(keyPath))); } - return [FSTLocalViewChanges changesForQuery:query addedKeys:added removedKeys:removed]; + return [FSTLocalViewChanges changesForQuery:query + addedKeys:std::move(added) + removedKeys:std::move(removed)]; } NS_ASSUME_NONNULL_END -- cgit v1.2.3