From 4e7296b080b9c8cea13e5e5eeee65f4312fb5e8a Mon Sep 17 00:00:00 2001 From: zxu Date: Fri, 16 Mar 2018 15:42:05 -0400 Subject: port `DocumentKey` to non-container types of `Model/*` (#930) * naively remove FSTPath import and source/test files. * port FieldPath, part I * port FieldPath, part II * port ResourcePath, part I * port ResourcePath, part II * the grand commit to fix build errors * use testutil:: helper instead of those from FSTHelpers * fix test and lint * use c_str in errmsg directly * fix * fix * make code clean * fix integration test I missed * fix to avoid naming collision in preprocessor * address changes * address changes * address changes * fix: fieldMask are actually shared with different context. * address changes * add converter function between two DocumentKey implementations * add unit test * address changes * fix lint * using DocumentKey in model except for the container types `FSTDocumentDictionary`, `FSTDocumentKeySet`, and `FSTDocumentVersionDictionary` * change other place w.r.t. the use of `DocumentKey` in model * update parameter of test helpers from NSString to string_view * revert a temporary change used in debug * address changes --- .../Example/Tests/API/FIRDocumentSnapshotTests.mm | 16 +- .../Example/Tests/API/FIRQuerySnapshotTests.mm | 12 +- Firestore/Example/Tests/API/FSTAPIHelpers.h | 6 +- Firestore/Example/Tests/API/FSTAPIHelpers.mm | 33 +-- .../Example/Tests/Core/FSTQueryListenerTests.mm | 48 ++-- Firestore/Example/Tests/Core/FSTQueryTests.mm | 148 ++++++------ .../Example/Tests/Core/FSTViewSnapshotTest.mm | 22 +- Firestore/Example/Tests/Core/FSTViewTests.mm | 150 ++++++------ .../Example/Tests/Local/FSTLocalSerializerTests.mm | 4 +- .../Example/Tests/Local/FSTLocalStoreTests.mm | 254 ++++++++++----------- .../Tests/Local/FSTRemoteDocumentCacheTests.mm | 33 +-- .../Local/FSTRemoteDocumentChangeBufferTests.mm | 6 +- .../Example/Tests/Model/FSTDocumentSetTests.mm | 10 +- Firestore/Example/Tests/Model/FSTDocumentTests.mm | 31 +-- Firestore/Example/Tests/Model/FSTMutationTests.mm | 49 ++-- .../Example/Tests/Remote/FSTRemoteEventTests.mm | 66 +++--- .../Example/Tests/Remote/FSTSerializerBetaTests.mm | 6 +- .../Example/Tests/Remote/FSTWatchChangeTests.mm | 2 +- Firestore/Example/Tests/SpecTests/FSTSpecTests.mm | 4 +- Firestore/Example/Tests/Util/FSTHelpers.h | 4 +- Firestore/Example/Tests/Util/FSTHelpers.mm | 11 +- Firestore/Source/Core/FSTQuery.mm | 2 +- Firestore/Source/Core/FSTTransaction.mm | 6 +- Firestore/Source/Core/FSTView.mm | 4 +- .../Source/Local/FSTLevelDBRemoteDocumentCache.mm | 6 +- .../Source/Local/FSTRemoteDocumentChangeBuffer.mm | 4 +- Firestore/Source/Model/FSTDocument.h | 9 +- Firestore/Source/Model/FSTDocument.mm | 37 +-- Firestore/Source/Model/FSTDocumentSet.h | 11 +- Firestore/Source/Model/FSTDocumentSet.mm | 20 +- Firestore/Source/Model/FSTMutation.h | 18 +- Firestore/Source/Model/FSTMutation.mm | 50 ++-- Firestore/Source/Model/FSTMutationBatch.h | 6 +- Firestore/Source/Model/FSTMutationBatch.mm | 11 +- Firestore/Source/Remote/FSTRemoteEvent.mm | 4 +- .../src/firebase/firestore/model/document_key.h | 9 +- .../test/firebase/firestore/testutil/testutil.h | 5 + 37 files changed, 590 insertions(+), 527 deletions(-) (limited to 'Firestore') diff --git a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm index 677d385..136fed6 100644 --- a/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm +++ b/Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm @@ -28,14 +28,14 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRDocumentSnapshotTests - (void)testEquals { - FIRDocumentSnapshot *base = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); - FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO); - FIRDocumentSnapshot *nilData = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); - FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO); - FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO); - FIRDocumentSnapshot *differentData = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"b" : @1 }, NO, NO); - FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, YES, NO); - FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, YES); + FIRDocumentSnapshot *base = FSTTestDocSnapshot("rooms/foo", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot("rooms/foo", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *nilData = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO); + FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO); + FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, NO, NO); + FIRDocumentSnapshot *differentData = FSTTestDocSnapshot("rooms/bar", 1, @{ @"b" : @1 }, NO, NO); + FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, YES, NO); + FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, NO, YES); XCTAssertEqualObjects(base, baseDup); XCTAssertEqualObjects(nilData, nilDataDup); XCTAssertNotEqualObjects(base, nilData); diff --git a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm index bb8110b..f8c7d60 100644 --- a/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm +++ b/Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm @@ -28,15 +28,15 @@ NS_ASSUME_NONNULL_BEGIN @implementation FIRQuerySnapshotTests - (void)testEquals { - FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); - FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); - FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot(@"bar", @{}, + FIRQuerySnapshot *foo = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); + FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot("bar", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO); - FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot(@"foo", + FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot("foo", @{ @"a" : @{@"b" : @1} }, @{}, YES, NO); - FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot(@"foo", @{}, + FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, NO, NO); - FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot(@"foo", @{}, + FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, YES); XCTAssertEqualObjects(foo, fooDup); XCTAssertNotEqualObjects(foo, differentPath); diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.h b/Firestore/Example/Tests/API/FSTAPIHelpers.h index 4edd7d5..2325c22 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.h +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.h @@ -18,6 +18,8 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "absl/strings/string_view.h" + @class FIRCollectionReference; @class FIRDocumentReference; @class FIRDocumentSnapshot; @@ -34,7 +36,7 @@ extern "C" { FIRFirestore *FSTTestFirestore(); /** A convenience method for creating a doc snapshot for tests. */ -FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, +FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary *_Nullable data, BOOL hasMutations, @@ -61,7 +63,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path); * @returns A query snapshot that consists of both sets of documents. */ FIRQuerySnapshot *FSTTestQuerySnapshot( - NSString *path, + const absl::string_view path, NSDictionary *> *oldDocs, NSDictionary *> *docsToAdd, BOOL hasPendingWrites, diff --git a/Firestore/Example/Tests/API/FSTAPIHelpers.mm b/Firestore/Example/Tests/API/FSTAPIHelpers.mm index c180dc4..1ccf22e 100644 --- a/Firestore/Example/Tests/API/FSTAPIHelpers.mm +++ b/Firestore/Example/Tests/API/FSTAPIHelpers.mm @@ -58,14 +58,14 @@ FIRFirestore *FSTTestFirestore() { return sharedInstance; } -FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path, +FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary *_Nullable data, BOOL hasMutations, BOOL fromCache) { FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil; return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore() - documentKey:FSTTestDocKey(path) + documentKey:testutil::Key(path) document:doc fromCache:fromCache]; } @@ -82,7 +82,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path) { /** A convenience method for creating a query snapshots for tests. */ FIRQuerySnapshot *FSTTestQuerySnapshot( - NSString *path, + const absl::string_view path, NSDictionary *> *oldDocs, NSDictionary *> *docsToAdd, BOOL hasPendingWrites, @@ -92,30 +92,31 @@ FIRQuerySnapshot *FSTTestQuerySnapshot( FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]); for (NSString *key in oldDocs) { oldDocuments = [oldDocuments - documentSetByAddingDocument:FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - oldDocs[key], hasPendingWrites)]; + documentSetByAddingDocument:FSTTestDoc(util::MakeStringView([NSString + stringWithFormat:@"%s/%@", path.data(), key]), + 1, oldDocs[key], hasPendingWrites)]; } FSTDocumentSet *newDocuments = oldDocuments; NSArray *documentChanges = [NSArray array]; for (NSString *key in docsToAdd) { - FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1, - docsToAdd[key], hasPendingWrites); + FSTDocument *docToAdd = + FSTTestDoc(util::MakeStringView([NSString stringWithFormat:@"%s/%@", path.data(), key]), 1, + docsToAdd[key], hasPendingWrites); newDocuments = [newDocuments documentSetByAddingDocument:docToAdd]; documentChanges = [documentChanges arrayByAddingObject:[FSTDocumentViewChange changeWithDocument:docToAdd type:FSTDocumentViewChangeTypeAdded]]; } - FSTViewSnapshot *viewSnapshot = - [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(util::MakeStringView(path)) - documents:newDocuments - oldDocuments:oldDocuments - documentChanges:documentChanges - fromCache:fromCache - hasPendingWrites:hasPendingWrites - syncStateChanged:YES]; + FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path) + documents:newDocuments + oldDocuments:oldDocuments + documentChanges:documentChanges + fromCache:fromCache + hasPendingWrites:hasPendingWrites + syncStateChanged:YES]; return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore() - originalQuery:FSTTestQuery(util::MakeStringView(path)) + originalQuery:FSTTestQuery(path) snapshot:viewSnapshot metadata:metadata]; } diff --git a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm index 55c4219..bc253d0 100644 --- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm @@ -46,10 +46,10 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *otherAccum = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTDocument *doc2prime = - FSTTestDoc(@"rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"}, NO); + FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"}, NO); FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum]; FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum]; @@ -127,8 +127,8 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *accum = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms/Eros"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 3, @{@"name" : @"Eros"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Eros", 4, @{@"name" : @"Eros2"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, NO); __block FSTAsyncQueryListener *listener = [[FSTAsyncQueryListener alloc] initWithDispatchQueue:self.asyncQueue @@ -167,8 +167,8 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *fullAccum = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES includeDocumentMetadataChanges:NO @@ -205,10 +205,10 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *fullAccum = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); - FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/Other", 3, @{@"name" : @"Other"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO); FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO includeDocumentMetadataChanges:YES @@ -254,11 +254,11 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *fullAccum = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, YES); - FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc2Prime = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/Other", 3, @{@"name" : @"Other"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, YES); + FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc2Prime = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO); FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES includeDocumentMetadataChanges:NO @@ -291,10 +291,10 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *filteredAccum = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); - FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/Other", 3, @{@"name" : @"Other"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO); FSTQueryListener *filteredListener = [self listenToQuery:query accumulatingSnapshots:filteredAccum]; @@ -323,8 +323,8 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *events = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTQueryListener *listener = [self listenToQuery:query options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO @@ -366,8 +366,8 @@ NS_ASSUME_NONNULL_BEGIN NSMutableArray *events = [NSMutableArray array]; FSTQuery *query = FSTTestQuery("rooms"); - FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO); FSTQueryListener *listener = [self listenToQuery:query options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO diff --git a/Firestore/Example/Tests/Core/FSTQueryTests.mm b/Firestore/Example/Tests/Core/FSTQueryTests.mm index 8b5b524..02310aa 100644 --- a/Firestore/Example/Tests/Core/FSTQueryTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryTests.mm @@ -88,9 +88,9 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testMatchesBasedOnDocumentKey { - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); // document query FSTQuery *query = FSTTestQuery("rooms/eros/messages/1"); @@ -100,10 +100,10 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testMatchesCorrectlyForShallowAncestorQuery { - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc1Meta = FSTTestDoc(@"rooms/eros/messages/1/meta/1", 0, @{@"meta" : @"mv"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc1Meta = FSTTestDoc("rooms/eros/messages/1/meta/1", 0, @{@"meta" : @"mv"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); // shallow ancestor query FSTQuery *query = FSTTestQuery("rooms/eros/messages"); @@ -114,8 +114,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEmptyFieldsAreAllowedForQueries { - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, NO); FSTQuery *query = [FSTTestQuery("rooms/eros/messages") queryByAddingFilter:FSTTestFilter("text", @"==", @"msg1")]; @@ -129,12 +129,12 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query2 = [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @"<=", @(2))]; - FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); - FSTDocument *doc3 = FSTTestDoc(@"collection/3", 0, @{ @"sort" : @3 }, NO); - FSTDocument *doc4 = FSTTestDoc(@"collection/4", 0, @{ @"sort" : @NO }, NO); - FSTDocument *doc5 = FSTTestDoc(@"collection/5", 0, @{@"sort" : @"string"}, NO); - FSTDocument *doc6 = FSTTestDoc(@"collection/6", 0, @{}, NO); + FSTDocument *doc1 = FSTTestDoc("collection/1", 0, @{ @"sort" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("collection/2", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc3 = FSTTestDoc("collection/3", 0, @{ @"sort" : @3 }, NO); + FSTDocument *doc4 = FSTTestDoc("collection/4", 0, @{ @"sort" : @NO }, NO); + FSTDocument *doc5 = FSTTestDoc("collection/5", 0, @{@"sort" : @"string"}, NO); + FSTDocument *doc6 = FSTTestDoc("collection/6", 0, @{}, NO); XCTAssertFalse([query1 matchesDocument:doc1]); XCTAssertTrue([query1 matchesDocument:doc2]); @@ -154,11 +154,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)testNullFilter { FSTQuery *query = [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @"==", [NSNull null])]; - FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{@"sort" : [NSNull null]}, NO); - FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); - FSTDocument *doc3 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @3.1 }, NO); - FSTDocument *doc4 = FSTTestDoc(@"collection/4", 0, @{ @"sort" : @NO }, NO); - FSTDocument *doc5 = FSTTestDoc(@"collection/5", 0, @{@"sort" : @"string"}, NO); + FSTDocument *doc1 = FSTTestDoc("collection/1", 0, @{@"sort" : [NSNull null]}, NO); + FSTDocument *doc2 = FSTTestDoc("collection/2", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc3 = FSTTestDoc("collection/2", 0, @{ @"sort" : @3.1 }, NO); + FSTDocument *doc4 = FSTTestDoc("collection/4", 0, @{ @"sort" : @NO }, NO); + FSTDocument *doc5 = FSTTestDoc("collection/5", 0, @{@"sort" : @"string"}, NO); XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc2]); @@ -170,11 +170,11 @@ NS_ASSUME_NONNULL_BEGIN - (void)testNanFilter { FSTQuery *query = [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @"==", @(NAN))]; - FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @(NAN) }, NO); - FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @2 }, NO); - FSTDocument *doc3 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @3.1 }, NO); - FSTDocument *doc4 = FSTTestDoc(@"collection/4", 0, @{ @"sort" : @NO }, NO); - FSTDocument *doc5 = FSTTestDoc(@"collection/5", 0, @{@"sort" : @"string"}, NO); + FSTDocument *doc1 = FSTTestDoc("collection/1", 0, @{ @"sort" : @(NAN) }, NO); + FSTDocument *doc2 = FSTTestDoc("collection/2", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc3 = FSTTestDoc("collection/2", 0, @{ @"sort" : @3.1 }, NO); + FSTDocument *doc4 = FSTTestDoc("collection/4", 0, @{ @"sort" : @NO }, NO); + FSTDocument *doc5 = FSTTestDoc("collection/5", 0, @{@"sort" : @"string"}, NO); XCTAssertTrue([query matchesDocument:doc1]); XCTAssertFalse([query matchesDocument:doc2]); @@ -189,13 +189,13 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query2 = [FSTTestQuery("collection") queryByAddingFilter:FSTTestFilter("sort", @">=", @(2))]; - FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @2 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @[] }, NO); - FSTDocument *doc3 = FSTTestDoc(@"collection/3", 0, @{ @"sort" : @[ @1 ] }, NO); - FSTDocument *doc4 = FSTTestDoc(@"collection/4", 0, @{ @"sort" : @{@"foo" : @2} }, NO); - FSTDocument *doc5 = FSTTestDoc(@"collection/5", 0, @{ @"sort" : @{@"foo" : @"bar"} }, NO); - FSTDocument *doc6 = FSTTestDoc(@"collection/6", 0, @{ @"sort" : @{} }, NO); // no sort field - FSTDocument *doc7 = FSTTestDoc(@"collection/7", 0, @{ @"sort" : @[ @3, @1 ] }, NO); + FSTDocument *doc1 = FSTTestDoc("collection/1", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc2 = FSTTestDoc("collection/2", 0, @{ @"sort" : @[] }, NO); + FSTDocument *doc3 = FSTTestDoc("collection/3", 0, @{ @"sort" : @[ @1 ] }, NO); + FSTDocument *doc4 = FSTTestDoc("collection/4", 0, @{ @"sort" : @{@"foo" : @2} }, NO); + FSTDocument *doc5 = FSTTestDoc("collection/5", 0, @{ @"sort" : @{@"foo" : @"bar"} }, NO); + FSTDocument *doc6 = FSTTestDoc("collection/6", 0, @{ @"sort" : @{} }, NO); // no sort field + FSTDocument *doc7 = FSTTestDoc("collection/7", 0, @{ @"sort" : @[ @3, @1 ] }, NO); XCTAssertTrue([query1 matchesDocument:doc1]); XCTAssertFalse([query1 matchesDocument:doc2]); @@ -219,12 +219,12 @@ NS_ASSUME_NONNULL_BEGIN queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("sort") ascending:YES]]; - FSTDocument *doc1 = FSTTestDoc(@"collection/1", 0, @{ @"sort" : @2 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"collection/2", 0, @{ @"sort" : @[] }, NO); - FSTDocument *doc3 = FSTTestDoc(@"collection/3", 0, @{ @"sort" : @[ @1 ] }, NO); - FSTDocument *doc4 = FSTTestDoc(@"collection/4", 0, @{ @"sort" : @{@"foo" : @2} }, NO); - FSTDocument *doc5 = FSTTestDoc(@"collection/5", 0, @{ @"sort" : @{@"foo" : @"bar"} }, NO); - FSTDocument *doc6 = FSTTestDoc(@"collection/6", 0, @{}, NO); + FSTDocument *doc1 = FSTTestDoc("collection/1", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc2 = FSTTestDoc("collection/2", 0, @{ @"sort" : @[] }, NO); + FSTDocument *doc3 = FSTTestDoc("collection/3", 0, @{ @"sort" : @[ @1 ] }, NO); + FSTDocument *doc4 = FSTTestDoc("collection/4", 0, @{ @"sort" : @{@"foo" : @2} }, NO); + FSTDocument *doc5 = FSTTestDoc("collection/5", 0, @{ @"sort" : @{@"foo" : @"bar"} }, NO); + FSTDocument *doc6 = FSTTestDoc("collection/6", 0, @{}, NO); XCTAssertTrue([query1 matchesDocument:doc1]); XCTAssertTrue([query1 matchesDocument:doc2]); @@ -236,7 +236,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testFiltersBasedOnArrayValue { FSTQuery *baseQuery = FSTTestQuery("collection"); - FSTDocument *doc1 = FSTTestDoc(@"collection/doc", 0, @{ @"tags" : @[ @"foo", @1, @YES ] }, NO); + FSTDocument *doc1 = FSTTestDoc("collection/doc", 0, @{ @"tags" : @[ @"foo", @1, @YES ] }, NO); NSArray> *matchingFilters = @[ FSTTestFilter("tags", @"==", @[ @"foo", @1, @YES ]) ]; @@ -259,7 +259,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testFiltersBasedOnObjectValue { FSTQuery *baseQuery = FSTTestQuery("collection"); FSTDocument *doc1 = - FSTTestDoc(@"collection/doc", 0, + FSTTestDoc("collection/doc", 0, @{ @"tags" : @{@"foo" : @"foo", @"a" : @0, @"b" : @YES, @"c" : @(NAN)} }, NO); NSArray> *matchingFilters = @[ @@ -315,20 +315,20 @@ NS_ASSUME_NONNULL_BEGIN // clang-format off NSArray *docs = @[ - FSTTestDoc(@"collection/1", 0, @{@"sort": [NSNull null]}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @NO}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @YES}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @1}, NO), - FSTTestDoc(@"collection/2", 0, @{@"sort": @1}, NO), // by key - FSTTestDoc(@"collection/3", 0, @{@"sort": @1}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort": @1.9}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @2}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @2.1}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @""}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @"a"}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @"ab"}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": @"b"}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort": + FSTTestDoc("collection/1", 0, @{@"sort": [NSNull null]}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @NO}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @YES}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @1}, NO), + FSTTestDoc("collection/2", 0, @{@"sort": @1}, NO), // by key + FSTTestDoc("collection/3", 0, @{@"sort": @1}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort": @1.9}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @2}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @2.1}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @""}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @"a"}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @"ab"}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": @"b"}, NO), + FSTTestDoc("collection/1", 0, @{@"sort": FSTTestRef("project", DatabaseId::kDefault, @"collection/id1")}, NO), ]; // clang-format on @@ -347,16 +347,16 @@ NS_ASSUME_NONNULL_BEGIN // clang-format off NSArray *docs = - @[FSTTestDoc(@"collection/1", 0, @{@"sort1": @1, @"sort2": @1}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort1": @1, @"sort2": @2}, NO), - FSTTestDoc(@"collection/2", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/3", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort1": @1, @"sort2": @3}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort1": @2, @"sort2": @1}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort1": @2, @"sort2": @2}, NO), - FSTTestDoc(@"collection/2", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/3", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort1": @2, @"sort2": @3}, NO), + @[FSTTestDoc("collection/1", 0, @{@"sort1": @1, @"sort2": @1}, NO), + FSTTestDoc("collection/1", 0, @{@"sort1": @1, @"sort2": @2}, NO), + FSTTestDoc("collection/2", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/3", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort1": @1, @"sort2": @3}, NO), + FSTTestDoc("collection/1", 0, @{@"sort1": @2, @"sort2": @1}, NO), + FSTTestDoc("collection/1", 0, @{@"sort1": @2, @"sort2": @2}, NO), + FSTTestDoc("collection/2", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/3", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort1": @2, @"sort2": @3}, NO), ]; // clang-format on @@ -374,16 +374,16 @@ NS_ASSUME_NONNULL_BEGIN // clang-format off NSArray *docs = - @[FSTTestDoc(@"collection/1", 0, @{@"sort1": @2, @"sort2": @3}, NO), - FSTTestDoc(@"collection/3", 0, @{@"sort1": @2, @"sort2": @2}, NO), - FSTTestDoc(@"collection/2", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort1": @2, @"sort2": @1}, NO), - FSTTestDoc(@"collection/1", 0, @{@"sort1": @1, @"sort2": @3}, NO), - FSTTestDoc(@"collection/3", 0, @{@"sort1": @1, @"sort2": @2}, NO), - FSTTestDoc(@"collection/2", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key - FSTTestDoc(@"collection/1", 0, @{@"sort1": @1, @"sort2": @1}, NO), + @[FSTTestDoc("collection/1", 0, @{@"sort1": @2, @"sort2": @3}, NO), + FSTTestDoc("collection/3", 0, @{@"sort1": @2, @"sort2": @2}, NO), + FSTTestDoc("collection/2", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort1": @2, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort1": @2, @"sort2": @1}, NO), + FSTTestDoc("collection/1", 0, @{@"sort1": @1, @"sort2": @3}, NO), + FSTTestDoc("collection/3", 0, @{@"sort1": @1, @"sort2": @2}, NO), + FSTTestDoc("collection/2", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort1": @1, @"sort2": @2}, NO), // by key + FSTTestDoc("collection/1", 0, @{@"sort1": @1, @"sort2": @1}, NO), ]; // clang-format on diff --git a/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm b/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm index c503684..ca8954e 100644 --- a/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm +++ b/Firestore/Example/Tests/Core/FSTViewSnapshotTest.mm @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTViewSnapshotTests - (void)testDocumentChangeConstructor { - FSTDocument *doc = FSTTestDoc(@"a/b", 0, @{}, NO); + FSTDocument *doc = FSTTestDoc("a/b", 0, @{}, NO); FSTDocumentViewChangeType type = FSTDocumentViewChangeTypeModified; FSTDocumentViewChange *change = [FSTDocumentViewChange changeWithDocument:doc type:type]; XCTAssertEqual(change.document, doc); @@ -42,15 +42,15 @@ NS_ASSUME_NONNULL_BEGIN - (void)testTrack { FSTDocumentViewChangeSet *set = [FSTDocumentViewChangeSet changeSet]; - FSTDocument *docAdded = FSTTestDoc(@"a/1", 0, @{}, NO); - FSTDocument *docRemoved = FSTTestDoc(@"a/2", 0, @{}, NO); - FSTDocument *docModified = FSTTestDoc(@"a/3", 0, @{}, NO); + FSTDocument *docAdded = FSTTestDoc("a/1", 0, @{}, NO); + FSTDocument *docRemoved = FSTTestDoc("a/2", 0, @{}, NO); + FSTDocument *docModified = FSTTestDoc("a/3", 0, @{}, NO); - FSTDocument *docAddedThenModified = FSTTestDoc(@"b/1", 0, @{}, NO); - FSTDocument *docAddedThenRemoved = FSTTestDoc(@"b/2", 0, @{}, NO); - FSTDocument *docRemovedThenAdded = FSTTestDoc(@"b/3", 0, @{}, NO); - FSTDocument *docModifiedThenRemoved = FSTTestDoc(@"b/4", 0, @{}, NO); - FSTDocument *docModifiedThenModified = FSTTestDoc(@"b/5", 0, @{}, NO); + FSTDocument *docAddedThenModified = FSTTestDoc("b/1", 0, @{}, NO); + FSTDocument *docAddedThenRemoved = FSTTestDoc("b/2", 0, @{}, NO); + FSTDocument *docRemovedThenAdded = FSTTestDoc("b/3", 0, @{}, NO); + FSTDocument *docModifiedThenRemoved = FSTTestDoc("b/4", 0, @{}, NO); + FSTDocument *docModifiedThenModified = FSTTestDoc("b/5", 0, @{}, NO); [set addChange:[FSTDocumentViewChange changeWithDocument:docAdded type:FSTDocumentViewChangeTypeAdded]]; @@ -109,9 +109,9 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = FSTTestQuery("a"); FSTDocumentSet *documents = [FSTDocumentSet documentSetWithComparator:FSTDocumentComparatorByKey]; FSTDocumentSet *oldDocuments = documents; - documents = [documents documentSetByAddingDocument:FSTTestDoc(@"c/a", 1, @{}, NO)]; + documents = [documents documentSetByAddingDocument:FSTTestDoc("c/a", 1, @{}, NO)]; NSArray *documentChanges = - @[ [FSTDocumentViewChange changeWithDocument:FSTTestDoc(@"c/a", 1, @{}, NO) + @[ [FSTDocumentViewChange changeWithDocument:FSTTestDoc("c/a", 1, @{}, NO) type:FSTDocumentViewChangeTypeAdded] ]; BOOL fromCache = YES; diff --git a/Firestore/Example/Tests/Core/FSTViewTests.mm b/Firestore/Example/Tests/Core/FSTViewTests.mm index 1e3ec1a..63ce711 100644 --- a/Firestore/Example/Tests/Core/FSTViewTests.mm +++ b/Firestore/Example/Tests/Core/FSTViewTests.mm @@ -51,9 +51,9 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [self queryForMessages]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/other/messages/1", 0, @{@"text" : @"msg3"}, NO); FSTViewSnapshot *_Nullable snapshot = FSTTestApplyChanges(view, @[ doc1, doc2, doc3 ], @@ -79,16 +79,16 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [self queryForMessages]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/3", 0, @{@"text" : @"msg3"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/3", 0, @{@"text" : @"msg3"}, NO); // initial state FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); // delete doc2, add doc3 FSTViewSnapshot *snapshot = - FSTTestApplyChanges(view, @[ FSTTestDeletedDoc(@"rooms/eros/messages/2", 0), doc3 ], + FSTTestApplyChanges(view, @[ FSTTestDeletedDoc("rooms/eros/messages/2", 0), doc3 ], [FSTTargetChange changeWithDocuments:@[ doc1, doc3 ] currentStatusUpdate:FSTCurrentStatusUpdateMarkCurrent]); @@ -110,8 +110,8 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [self queryForMessages]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); // initial state FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); @@ -138,11 +138,11 @@ NS_ASSUME_NONNULL_BEGIN query = [query queryByAddingFilter:filter]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - 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); - FSTDocument *doc4 = FSTTestDoc(@"rooms/eros/messages/4", 0, @{}, NO); // no sort, no match - FSTDocument *doc5 = FSTTestDoc(@"rooms/eros/messages/5", 0, @{ @"sort" : @1 }, NO); + 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); + FSTDocument *doc4 = FSTTestDoc("rooms/eros/messages/4", 0, @{}, NO); // no sort, no match + FSTDocument *doc5 = FSTTestDoc("rooms/eros/messages/5", 0, @{ @"sort" : @1 }, NO); FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2, doc3, doc4, doc5 ], nil); @@ -170,10 +170,10 @@ NS_ASSUME_NONNULL_BEGIN query = [query queryByAddingFilter:filter]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - 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); - FSTDocument *doc4 = FSTTestDoc(@"rooms/eros/messages/4", 0, @{}, NO); + 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); + FSTDocument *doc4 = FSTTestDoc("rooms/eros/messages/4", 0, @{}, NO); FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2, doc3, doc4 ], nil); @@ -181,9 +181,9 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqualObjects(snapshot.documents.arrayValue, (@[ doc1, doc3 ])); - FSTDocument *newDoc2 = FSTTestDoc(@"rooms/eros/messages/2", 1, @{ @"sort" : @2 }, NO); - FSTDocument *newDoc3 = FSTTestDoc(@"rooms/eros/messages/3", 1, @{ @"sort" : @3 }, NO); - FSTDocument *newDoc4 = FSTTestDoc(@"rooms/eros/messages/4", 1, @{ @"sort" : @0 }, NO); + FSTDocument *newDoc2 = FSTTestDoc("rooms/eros/messages/2", 1, @{ @"sort" : @2 }, NO); + FSTDocument *newDoc3 = FSTTestDoc("rooms/eros/messages/3", 1, @{ @"sort" : @3 }, NO); + FSTDocument *newDoc4 = FSTTestDoc("rooms/eros/messages/4", 1, @{ @"sort" : @0 }, NO); snapshot = FSTTestApplyChanges(view, @[ newDoc2, newDoc3, newDoc4 ], nil); @@ -207,9 +207,9 @@ NS_ASSUME_NONNULL_BEGIN query = [query queryBySettingLimit:2]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/3", 0, @{@"text" : @"msg3"}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{@"text" : @"msg1"}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/3", 0, @{@"text" : @"msg3"}, NO); // initial state FSTTestApplyChanges(view, @[ doc1, doc3 ], nil); @@ -241,10 +241,10 @@ NS_ASSUME_NONNULL_BEGIN query = [query queryBySettingLimit:2]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{ @"num" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{ @"num" : @2 }, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/3", 0, @{ @"num" : @3 }, NO); - FSTDocument *doc4 = FSTTestDoc(@"rooms/eros/messages/4", 0, @{ @"num" : @4 }, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/1", 0, @{ @"num" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/2", 0, @{ @"num" : @2 }, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/3", 0, @{ @"num" : @3 }, NO); + FSTDocument *doc4 = FSTTestDoc("rooms/eros/messages/4", 0, @{ @"num" : @4 }, NO); // initial state FSTTestApplyChanges(view, @[ doc1, doc2 ], nil); @@ -253,7 +253,7 @@ NS_ASSUME_NONNULL_BEGIN // doc2 will be modified + removed = removed // doc3 will be added // doc4 will be added + removed = nothing - doc2 = FSTTestDoc(@"rooms/eros/messages/2", 1, @{ @"num" : @5 }, NO); + doc2 = FSTTestDoc("rooms/eros/messages/2", 1, @{ @"num" : @5 }, NO); FSTViewDocumentChanges *viewDocChanges = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc2, doc3, doc4 ])]; XCTAssertTrue(viewDocChanges.needsRefill); @@ -285,9 +285,9 @@ NS_ASSUME_NONNULL_BEGIN FSTQuery *query = [self queryForMessages]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, NO); FSTViewChange *change = [view applyChangesToDocuments:[view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1 ])]]; @@ -323,7 +323,7 @@ NS_ASSUME_NONNULL_BEGIN @[ [FSTLimboDocumentChange changeWithType:FSTLimboDocumentChangeTypeAdded key:doc3.key] ]); change = [view applyChangesToDocuments:[view computeChangesWithDocuments:FSTTestDocUpdates(@[ - FSTTestDeletedDoc(@"rooms/eros/messages/2", + FSTTestDeletedDoc("rooms/eros/messages/2", 1) ])]]; // remove XCTAssertEqualObjects( @@ -334,8 +334,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testResumingQueryCreatesNoLimbos { FSTQuery *query = [self queryForMessages]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + FSTDocument *doc1 = FSTTestDoc("rooms/eros/messages/0", 0, @{}, NO); + FSTDocument *doc2 = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); // 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. @@ -359,8 +359,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testReturnsNeedsRefillOnDeleteInLimitQuery { FSTQuery *query = [[self queryForMessages] queryBySettingLimit:2]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + 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]]; // Start with a full view. @@ -373,7 +373,7 @@ NS_ASSUME_NONNULL_BEGIN // Remove one of the docs. changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ FSTTestDeletedDoc( - @"rooms/eros/messages/0", 0) ])]; + "rooms/eros/messages/0", 0) ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc2 ]]; XCTAssertTrue(changes.needsRefill); XCTAssertEqual(1, [changes.changeSet changes].count); @@ -391,9 +391,9 @@ NS_ASSUME_NONNULL_BEGIN [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("order") ascending:YES]]; query = [query queryBySettingLimit:2]; - 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); + 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]]; // Start with a full view. @@ -405,7 +405,7 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; // Move one of the docs. - doc2 = FSTTestDoc(@"rooms/eros/messages/1", 1, @{ @"order" : @2000 }, NO); + doc2 = FSTTestDoc("rooms/eros/messages/1", 1, @{ @"order" : @2000 }, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc2 ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc1, doc2 ]]; XCTAssertTrue(changes.needsRefill); @@ -425,11 +425,11 @@ NS_ASSUME_NONNULL_BEGIN [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("order") ascending:YES]]; query = [query queryBySettingLimit:3]; - 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); - FSTDocument *doc4 = FSTTestDoc(@"rooms/eros/messages/3", 0, @{ @"order" : @4 }, NO); - FSTDocument *doc5 = FSTTestDoc(@"rooms/eros/messages/4", 0, @{ @"order" : @5 }, NO); + 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); + 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]]; // Start with a full view. @@ -441,7 +441,7 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; // Move one of the docs. - doc1 = FSTTestDoc(@"rooms/eros/messages/0", 1, @{ @"order" : @3 }, NO); + doc1 = FSTTestDoc("rooms/eros/messages/0", 1, @{ @"order" : @3 }, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1 ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc2, doc3, doc1 ]]; XCTAssertFalse(changes.needsRefill); @@ -455,11 +455,11 @@ NS_ASSUME_NONNULL_BEGIN [query queryByAddingSortOrder:[FSTSortOrder sortOrderWithFieldPath:testutil::Field("order") ascending:YES]]; query = [query queryBySettingLimit:3]; - 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); - FSTDocument *doc4 = FSTTestDoc(@"rooms/eros/messages/3", 0, @{ @"order" : @4 }, NO); - FSTDocument *doc5 = FSTTestDoc(@"rooms/eros/messages/4", 0, @{ @"order" : @5 }, NO); + 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); + 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]]; // Start with a full view. @@ -471,7 +471,7 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; // Move one of the docs. - doc4 = FSTTestDoc(@"rooms/eros/messages/3", 1, @{ @"order" : @6 }, NO); + doc4 = FSTTestDoc("rooms/eros/messages/3", 1, @{ @"order" : @6 }, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc4 ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc1, doc2, doc3 ]]; XCTAssertFalse(changes.needsRefill); @@ -481,8 +481,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testDoesntNeedRefillForAdditionAfterTheLimit { FSTQuery *query = [[self queryForMessages] queryBySettingLimit:2]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + 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]]; // Start with a full view. @@ -494,7 +494,7 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; // Add a doc that is past the limit. - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/2", 1, @{}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 1, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc1, doc2 ]]; XCTAssertFalse(changes.needsRefill); @@ -504,8 +504,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testDoesntNeedRefillForDeletionsWhenNotNearTheLimit { FSTQuery *query = [[self queryForMessages] queryBySettingLimit:20]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + 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]]; FSTViewDocumentChanges *changes = @@ -517,7 +517,7 @@ NS_ASSUME_NONNULL_BEGIN // Remove one of the docs. changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ FSTTestDeletedDoc( - @"rooms/eros/messages/1", 0) ])]; + "rooms/eros/messages/1", 0) ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc1 ]]; XCTAssertFalse(changes.needsRefill); XCTAssertEqual(1, [changes.changeSet changes].count); @@ -526,8 +526,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testHandlesApplyingIrrelevantDocs { FSTQuery *query = [[self queryForMessages] queryBySettingLimit:2]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + 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]]; // Start with a full view. @@ -540,7 +540,7 @@ NS_ASSUME_NONNULL_BEGIN // Remove a doc that isn't even in the results. changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ FSTTestDeletedDoc( - @"rooms/eros/messages/2", 0) ])]; + "rooms/eros/messages/2", 0) ])]; [self assertDocSet:changes.documentSet containsDocs:@[ doc1, doc2 ]]; XCTAssertFalse(changes.needsRefill); XCTAssertEqual(0, [changes.changeSet changes].count); @@ -549,8 +549,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testComputesMutatedKeys { FSTQuery *query = [self queryForMessages]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + 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]]; // Start with a full view. @@ -559,15 +559,15 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[])); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, YES); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, YES); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ])]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ 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); + 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]]; // Start with a full view. @@ -576,7 +576,7 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); - FSTDocument *doc2Prime = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, NO); + FSTDocument *doc2Prime = FSTTestDoc("rooms/eros/messages/1", 0, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc2Prime ])]; [view applyChangesToDocuments:changes]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[])); @@ -584,8 +584,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRemembersLocalMutationsFromPreviousSnapshot { FSTQuery *query = [self queryForMessages]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, YES); + 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]]; // Start with a full view. @@ -594,7 +594,7 @@ NS_ASSUME_NONNULL_BEGIN [view applyChangesToDocuments:changes]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ])]; [view applyChangesToDocuments:changes]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); @@ -602,8 +602,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)testRemembersLocalMutationsFromPreviousCallToComputeChangesWithDocuments { FSTQuery *query = [self queryForMessages]; - FSTDocument *doc1 = FSTTestDoc(@"rooms/eros/messages/0", 0, @{}, NO); - FSTDocument *doc2 = FSTTestDoc(@"rooms/eros/messages/1", 0, @{}, YES); + 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]]; // Start with a full view. @@ -611,7 +611,7 @@ NS_ASSUME_NONNULL_BEGIN [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc1, doc2 ])]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); - FSTDocument *doc3 = FSTTestDoc(@"rooms/eros/messages/2", 0, @{}, NO); + FSTDocument *doc3 = FSTTestDoc("rooms/eros/messages/2", 0, @{}, NO); changes = [view computeChangesWithDocuments:FSTTestDocUpdates(@[ doc3 ]) previousChanges:changes]; XCTAssertEqualObjects(changes.mutatedKeys, FSTTestDocKeySet(@[ doc2.key ])); } diff --git a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm index 87242fa..d94925d 100644 --- a/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm @@ -126,7 +126,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesDocumentAsMaybeDocument { - FSTDocument *doc = FSTTestDoc(@"some/path", 42, @{@"foo" : @"bar"}, NO); + FSTDocument *doc = FSTTestDoc("some/path", 42, @{@"foo" : @"bar"}, NO); FSTPBMaybeDocument *maybeDocProto = [FSTPBMaybeDocument message]; maybeDocProto.document = [GCFSDocument message]; @@ -143,7 +143,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testEncodesDeletedDocumentAsMaybeDocument { - FSTDeletedDocument *deletedDoc = FSTTestDeletedDoc(@"some/path", 42); + FSTDeletedDocument *deletedDoc = FSTTestDeletedDoc("some/path", 42); FSTPBMaybeDocument *maybeDocProto = [FSTPBMaybeDocument message]; maybeDocProto.noDocument = [FSTPBNoDocument message]; diff --git a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm index 5a386b6..7c3b977 100644 --- a/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm +++ b/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm @@ -237,25 +237,25 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, if ([self isTestBaseClass]) return; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); [self acknowledgeMutationWithVersion:0]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO)); } - (void)testHandlesSetMutationThenDocument { if ([self isTestBaseClass]) return; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); [self applyRemoteEvent:FSTTestUpdateRemoteEvent( - FSTTestDoc(@"foo/bar", 2, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, YES)); + FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES)); } - (void)testHandlesAckThenRejectThenRemoteEvent { @@ -266,76 +266,76 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self allocateQuery:query]; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); // The last seen version is zero, so this ack must be held. [self acknowledgeMutationWithVersion:1]; FSTAssertChanged(@[]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); [self writeMutation:FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"})]; - FSTAssertChanged(@[ FSTTestDoc(@"bar/baz", 0, @{@"bar" : @"baz"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"bar/baz", 0, @{@"bar" : @"baz"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES) ]); + FSTAssertContains(FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES)); [self rejectMutation]; FSTAssertRemoved(@[ @"bar/baz" ]); FSTAssertNotContains(@"bar/baz"); [self applyRemoteEvent:FSTTestUpdateRemoteEvent( - FSTTestDoc(@"foo/bar", 2, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 2, @{@"it" : @"changed"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 2, @{@"it" : @"changed"}, NO)); + FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO)); FSTAssertNotContains(@"bar/baz"); } - (void)testHandlesDeletedDocumentThenSetMutationThenAck { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc(@"foo/bar", 2), @[ @1 ], @[])]; + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @1 ], @[])]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 2)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2)); [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); [self acknowledgeMutationWithVersion:3]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO)); } - (void)testHandlesSetMutationThenDeletedDocument { if ([self isTestBaseClass]) return; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc(@"foo/bar", 2), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @1 ], @[])]; + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); } - (void)testHandlesDocumentThenSetMutationThenAckThenDocument { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 2, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 2, @{@"it" : @"base"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 2, @{@"it" : @"base"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO)); [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES)); [self acknowledgeMutationWithVersion:3]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO)); [self applyRemoteEvent:FSTTestUpdateRemoteEvent( - FSTTestDoc(@"foo/bar", 3, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 3, @{@"it" : @"changed"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 3, @{@"it" : @"changed"}, NO)); + FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO)); } - (void)testHandlesPatchWithoutPriorDocument { @@ -357,14 +357,14 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertNotContains(@"foo/bar"); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES)); [self acknowledgeMutationWithVersion:2]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, NO)); } - (void)testHandlesPatchMutationThenAckThenDocument { @@ -378,10 +378,10 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTAssertRemoved(@[ @"foo/bar" ]); FSTAssertNotContains(@"foo/bar"); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO)); } - (void)testHandlesDeleteMutationThenAck { @@ -389,28 +389,28 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self writeMutation:FSTTestDeleteMutation(@"foo/bar")]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); [self acknowledgeMutationWithVersion:1]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); } - (void)testHandlesDocumentThenDeleteMutationThenAck { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO)); [self writeMutation:FSTTestDeleteMutation(@"foo/bar")]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); [self acknowledgeMutationWithVersion:2]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); } - (void)testHandlesDeleteMutationThenDocumentThenAck { @@ -418,59 +418,59 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self writeMutation:FSTTestDeleteMutation(@"foo/bar")]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); [self acknowledgeMutationWithVersion:2]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); } - (void)testHandlesDocumentThenDeletedDocumentThenDocument { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO)); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc(@"foo/bar", 2), @[ @1 ], @[])]; + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @1 ], @[])]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 2)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2)); [self applyRemoteEvent:FSTTestUpdateRemoteEvent( - FSTTestDoc(@"foo/bar", 3, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 3, @{@"it" : @"changed"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 3, @{@"it" : @"changed"}, NO)); + FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO), @[ @1 ], @[])]; + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO)); } - (void)testHandlesSetMutationThenPatchMutationThenDocumentThenAckThenAck { if ([self isTestBaseClass]) return; [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, YES)); [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"it" : @"base"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO), @[ @1 ], @[])]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES)); [self acknowledgeMutationWithVersion:2]; // delete mutation - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES)); [self acknowledgeMutationWithVersion:3]; // patch mutation - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO)); } - (void)testHandlesSetMutationAndPatchMutationTogether { @@ -481,8 +481,8 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {}) ]]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); } - (void)testHandlesSetMutationThenPatchMutationThenReject { @@ -490,14 +490,14 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"})]; [self acknowledgeMutationWithVersion:1]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO)); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO)); [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); [self rejectMutation]; - FSTAssertChanged(@[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO) ]); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO)); + FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO) ]); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO)); } - (void)testHandlesSetMutationsAndPatchMutationOfJustOneTogether { @@ -510,11 +510,11 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, ]]; FSTAssertChanged((@[ - FSTTestDoc(@"bar/baz", 0, @{@"bar" : @"baz"}, YES), - FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) + FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES), + FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ])); - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); - FSTAssertContains(FSTTestDoc(@"bar/baz", 0, @{@"bar" : @"baz"}, YES)); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertContains(FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES)); } - (void)testHandlesDeleteMutationThenPatchMutationThenAckThenAck { @@ -522,31 +522,31 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self writeMutation:FSTTestDeleteMutation(@"foo/bar")]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); [self acknowledgeMutationWithVersion:2]; // delete mutation FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); [self acknowledgeMutationWithVersion:3]; // patch mutation FSTAssertRemoved(@[ @"foo/bar" ]); - FSTAssertContains(FSTTestDeletedDoc(@"foo/bar", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0)); } - (void)testCollectsGarbageAfterChangeBatchWithNoTargetIDs { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc(@"foo/bar", 2), @[ @1 ], @[])]; + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @1 ], @[])]; FSTAssertRemoved(@[ @"foo/bar" ]); [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO), @[ @1 ], @[])]; [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); @@ -559,12 +559,12 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self allocateQuery:query]; FSTAssertTargetID(2); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO), @[ @2 ], @[])]; [self collectGarbage]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"bar"}, NO)); + FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO)); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 2, @{@"foo" : @"baz"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"foo" : @"baz"}, NO), @[], @[ @2 ])]; [self collectGarbage]; @@ -574,27 +574,27 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testCollectsGarbageAfterAcknowledgedMutation { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO), @[ @1 ], @[])]; [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; [self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})]; [self writeMutation:FSTTestDeleteMutation(@"foo/baz")]; [self collectGarbage]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); - FSTAssertContains(FSTTestDoc(@"foo/bah", 0, @{@"foo" : @"bah"}, YES)); - FSTAssertContains(FSTTestDeletedDoc(@"foo/baz", 0)); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES)); + FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0)); [self acknowledgeMutationWithVersion:3]; [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); - FSTAssertContains(FSTTestDoc(@"foo/bah", 0, @{@"foo" : @"bah"}, YES)); - FSTAssertContains(FSTTestDeletedDoc(@"foo/baz", 0)); + FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES)); + FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0)); [self acknowledgeMutationWithVersion:4]; [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); FSTAssertNotContains(@"foo/bah"); - FSTAssertContains(FSTTestDeletedDoc(@"foo/baz", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0)); [self acknowledgeMutationWithVersion:5]; [self collectGarbage]; @@ -606,27 +606,27 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, - (void)testCollectsGarbageAfterRejectedMutation { if ([self isTestBaseClass]) return; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"old"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO), @[ @1 ], @[])]; [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})]; [self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})]; [self writeMutation:FSTTestDeleteMutation(@"foo/baz")]; [self collectGarbage]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES)); - FSTAssertContains(FSTTestDoc(@"foo/bah", 0, @{@"foo" : @"bah"}, YES)); - FSTAssertContains(FSTTestDeletedDoc(@"foo/baz", 0)); + FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)); + FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES)); + FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0)); [self rejectMutation]; // patch mutation [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); - FSTAssertContains(FSTTestDoc(@"foo/bah", 0, @{@"foo" : @"bah"}, YES)); - FSTAssertContains(FSTTestDeletedDoc(@"foo/baz", 0)); + FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES)); + FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0)); [self rejectMutation]; // set mutation [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); FSTAssertNotContains(@"foo/bah"); - FSTAssertContains(FSTTestDeletedDoc(@"foo/baz", 0)); + FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0)); [self rejectMutation]; // delete mutation [self collectGarbage]; @@ -642,22 +642,22 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self allocateQuery:query]; FSTAssertTargetID(2); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO), @[ @2 ], @[])]; [self writeMutation:FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"})]; [self collectGarbage]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, NO)); - FSTAssertContains(FSTTestDoc(@"foo/baz", 0, @{@"foo" : @"baz"}, YES)); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO)); + FSTAssertContains(FSTTestDoc("foo/baz", 0, @{@"foo" : @"baz"}, YES)); [self notifyLocalViewChanges:FSTTestViewChanges(query, @[ @"foo/bar", @"foo/baz" ], @[])]; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO), @[], @[ @2 ])]; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/baz", 2, @{@"foo" : @"baz"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, NO), @[ @1 ], @[])]; [self acknowledgeMutationWithVersion:2]; [self collectGarbage]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{@"foo" : @"bar"}, NO)); - FSTAssertContains(FSTTestDoc(@"foo/baz", 2, @{@"foo" : @"baz"}, NO)); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO)); + FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, NO)); [self notifyLocalViewChanges:FSTTestViewChanges(query, @[], @[ @"foo/bar", @"foo/baz" ])]; [self collectGarbage]; @@ -670,9 +670,9 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, if ([self isTestBaseClass]) return; FSTTargetID targetID = 321; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 1, @{}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{}, NO), @[ @(targetID) ], @[])]; - FSTAssertContains(FSTTestDoc(@"foo/bar", 1, @{}, NO)); + FSTAssertContains(FSTTestDoc("foo/bar", 1, @{}, NO)); [self collectGarbage]; FSTAssertNotContains(@"foo/bar"); @@ -688,7 +688,7 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, ]]; FSTQuery *query = FSTTestQuery("foo/bar"); FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; - XCTAssertEqualObjects([docs values], @[ FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); + XCTAssertEqualObjects([docs values], @[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]); } - (void)testCanExecuteCollectionQueries { @@ -704,8 +704,8 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, FSTQuery *query = FSTTestQuery("foo"); FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; XCTAssertEqualObjects([docs values], (@[ - FSTTestDoc(@"foo/bar", 0, @{@"foo" : @"bar"}, YES), - FSTTestDoc(@"foo/baz", 0, @{@"foo" : @"baz"}, YES) + FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES), + FSTTestDoc("foo/baz", 0, @{@"foo" : @"baz"}, YES) ])); } @@ -716,18 +716,18 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self allocateQuery:query]; FSTAssertTargetID(2); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/baz", 10, @{@"a" : @"b"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, NO), @[ @2 ], @[])]; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 20, @{@"a" : @"b"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, NO), @[ @2 ], @[])]; [self.localStore locallyWriteMutations:@[ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) ]]; FSTDocumentDictionary *docs = [self.localStore executeQuery:query]; XCTAssertEqualObjects([docs values], (@[ - FSTTestDoc(@"foo/bar", 20, @{@"a" : @"b"}, NO), - FSTTestDoc(@"foo/baz", 10, @{@"a" : @"b"}, NO), - FSTTestDoc(@"foo/bonk", 0, @{@"a" : @"b"}, YES) + FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, NO), + FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, NO), + FSTTestDoc("foo/bonk", 0, @{@"a" : @"b"}, YES) ])); } @@ -775,9 +775,9 @@ FSTDocumentVersionDictionary *FSTVersionDictionary(FSTMutation *mutation, [self allocateQuery:query]; FSTAssertTargetID(2); - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/baz", 10, @{@"a" : @"b"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, NO), @[ @2 ], @[])]; - [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc(@"foo/bar", 20, @{@"a" : @"b"}, NO), + [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, NO), @[ @2 ], @[])]; [self.localStore locallyWriteMutations:@[ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) ]]; diff --git a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm index d056488..16b7185 100644 --- a/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm +++ b/Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.mm @@ -25,10 +25,17 @@ #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/src/firebase/firestore/util/string_apple.h" +#include "Firestore/core/test/firebase/firestore/testutil/testutil.h" +#include "absl/strings/string_view.h" + +namespace testutil = firebase::firestore::testutil; +namespace util = firebase::firestore::util; + NS_ASSUME_NONNULL_BEGIN -static NSString *const kDocPath = @"a/b"; -static NSString *const kLongDocPath = @"a/b/c/d/e/f"; +static const char *kDocPath = "a/b"; +static const char *kLongDocPath = "a/b/c/d/e/f"; static const int kVersion = 42; @implementation FSTRemoteDocumentCacheTests { @@ -49,7 +56,7 @@ static const int kVersion = 42; } // Helper for next two tests. -- (void)setAndReadADocumentAtPath:(NSString *)path { +- (void)setAndReadADocumentAtPath:(const absl::string_view)path { FSTDocument *written = [self setTestDocumentAtPath:path]; FSTMaybeDocument *read = [self readEntryAtPath:path]; XCTAssertEqualObjects(read, written); @@ -107,15 +114,15 @@ static const int kVersion = 42; // TODO(rsgowman): This just verifies that we do a prefix scan against the // query path. We'll need more tests once we add index support. - [self setTestDocumentAtPath:@"a/1"]; - [self setTestDocumentAtPath:@"b/1"]; - [self setTestDocumentAtPath:@"b/2"]; - [self setTestDocumentAtPath:@"c/1"]; + [self setTestDocumentAtPath:"a/1"]; + [self setTestDocumentAtPath:"b/1"]; + [self setTestDocumentAtPath:"b/2"]; + [self setTestDocumentAtPath:"c/1"]; FSTQuery *query = FSTTestQuery("b"); FSTDocumentDictionary *results = [self.remoteDocumentCache documentsMatchingQuery:query]; NSArray *expected = - @[ FSTTestDoc(@"b/1", kVersion, _kDocData, NO), FSTTestDoc(@"b/2", kVersion, _kDocData, NO) ]; + @[ FSTTestDoc("b/1", kVersion, _kDocData, NO), FSTTestDoc("b/2", kVersion, _kDocData, NO) ]; XCTAssertEqual([results count], [expected count]); for (FSTDocument *doc in expected) { XCTAssertEqualObjects([results objectForKey:doc.key], doc); @@ -124,7 +131,7 @@ static const int kVersion = 42; #pragma mark - Helpers -- (FSTDocument *)setTestDocumentAtPath:(NSString *)path { +- (FSTDocument *)setTestDocumentAtPath:(const absl::string_view)path { FSTDocument *doc = FSTTestDoc(path, kVersion, _kDocData, NO); [self addEntry:doc]; return doc; @@ -136,13 +143,13 @@ static const int kVersion = 42; [self.persistence commitGroup:group]; } -- (FSTMaybeDocument *_Nullable)readEntryAtPath:(NSString *)path { - return [self.remoteDocumentCache entryForKey:FSTTestDocKey(path)]; +- (FSTMaybeDocument *_Nullable)readEntryAtPath:(const absl::string_view)path { + return [self.remoteDocumentCache entryForKey:testutil::Key(path)]; } -- (void)removeEntryAtPath:(NSString *)path { +- (void)removeEntryAtPath:(const absl::string_view)path { FSTWriteGroup *group = [self.persistence startGroupWithAction:@"removeEntryAtPath"]; - [self.remoteDocumentCache removeEntryForKey:FSTTestDocKey(path) group:group]; + [self.remoteDocumentCache removeEntryForKey:testutil::Key(path) group:group]; [self.persistence commitGroup:group]; } diff --git a/Firestore/Example/Tests/Local/FSTRemoteDocumentChangeBufferTests.mm b/Firestore/Example/Tests/Local/FSTRemoteDocumentChangeBufferTests.mm index 1970779..36d3661 100644 --- a/Firestore/Example/Tests/Local/FSTRemoteDocumentChangeBufferTests.mm +++ b/Firestore/Example/Tests/Local/FSTRemoteDocumentChangeBufferTests.mm @@ -47,7 +47,7 @@ NS_ASSUME_NONNULL_BEGIN // Add a couple initial items to the cache. FSTWriteGroup *group = [_db startGroupWithAction:@"Add initial docs."]; - _kInitialADoc = FSTTestDoc(@"coll/a", 42, @{@"test" : @"data"}, NO); + _kInitialADoc = FSTTestDoc("coll/a", 42, @{@"test" : @"data"}, NO); [_remoteDocumentCache addEntry:_kInitialADoc group:group]; _kInitialBDoc = @@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testAddEntryAndReadItBack { - FSTMaybeDocument *newADoc = FSTTestDoc(@"coll/a", 43, @{@"new" : @"data"}, NO); + FSTMaybeDocument *newADoc = FSTTestDoc("coll/a", 43, @{@"new" : @"data"}, NO); [_remoteDocumentBuffer addEntry:newADoc]; XCTAssertEqualObjects([_remoteDocumentBuffer entryForKey:FSTTestDocKey(@"coll/a")], newADoc); @@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testApplyChanges { - FSTMaybeDocument *newADoc = FSTTestDoc(@"coll/a", 43, @{@"new" : @"data"}, NO); + FSTMaybeDocument *newADoc = FSTTestDoc("coll/a", 43, @{@"new" : @"data"}, NO); [_remoteDocumentBuffer addEntry:newADoc]; XCTAssertEqualObjects([_remoteDocumentBuffer entryForKey:FSTTestDocKey(@"coll/a")], newADoc); diff --git a/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm b/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm index d70c44d..65c4ddf 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm +++ b/Firestore/Example/Tests/Model/FSTDocumentSetTests.mm @@ -38,9 +38,9 @@ NS_ASSUME_NONNULL_BEGIN [super setUp]; _comp = FSTTestDocComparator("sort"); - _doc1 = FSTTestDoc(@"docs/1", 0, @{ @"sort" : @2 }, NO); - _doc2 = FSTTestDoc(@"docs/2", 0, @{ @"sort" : @3 }, NO); - _doc3 = FSTTestDoc(@"docs/3", 0, @{ @"sort" : @1 }, NO); + _doc1 = FSTTestDoc("docs/1", 0, @{ @"sort" : @2 }, NO); + _doc2 = FSTTestDoc("docs/2", 0, @{ @"sort" : @3 }, NO); + _doc3 = FSTTestDoc("docs/3", 0, @{ @"sort" : @1 }, NO); } - (void)testCount { @@ -97,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)testUpdates { FSTDocumentSet *set = FSTTestDocSet(_comp, @[ _doc1, _doc2, _doc3 ]); - FSTDocument *doc2Prime = FSTTestDoc(@"docs/2", 0, @{ @"sort" : @9 }, NO); + FSTDocument *doc2Prime = FSTTestDoc("docs/2", 0, @{ @"sort" : @9 }, NO); set = [set documentSetByAddingDocument:doc2Prime]; XCTAssertEqual([set count], 3); @@ -106,7 +106,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testAddsDocsWithEqualComparisonValues { - FSTDocument *doc4 = FSTTestDoc(@"docs/4", 0, @{ @"sort" : @2 }, NO); + FSTDocument *doc4 = FSTTestDoc("docs/4", 0, @{ @"sort" : @2 }, NO); FSTDocumentSet *set = FSTTestDocSet(_comp, @[ _doc1, doc4 ]); XCTAssertEqualObjects([[set documentEnumerator] allObjects], (@[ _doc1, doc4 ])); diff --git a/Firestore/Example/Tests/Model/FSTDocumentTests.mm b/Firestore/Example/Tests/Model/FSTDocumentTests.mm index 0527852..24858c5 100644 --- a/Firestore/Example/Tests/Model/FSTDocumentTests.mm +++ b/Firestore/Example/Tests/Model/FSTDocumentTests.mm @@ -19,14 +19,15 @@ #import #import "Firestore/Source/Core/FSTSnapshotVersion.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" namespace testutil = firebase::firestore::testutil; +using firebase::firestore::model::DocumentKey; NS_ASSUME_NONNULL_BEGIN @@ -36,7 +37,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTDocumentTests - (void)testConstructor { - FSTDocumentKey *key = FSTTestDocKey(@"messages/first"); + DocumentKey key = testutil::Key("messages/first"); FSTSnapshotVersion *version = FSTTestVersion(1); FSTObjectValue *data = FSTTestObjectValue(@{ @"a" : @1 }); FSTDocument *doc = @@ -49,7 +50,7 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testExtractsFields { - FSTDocumentKey *key = FSTTestDocKey(@"rooms/eros"); + DocumentKey key = testutil::Key("rooms/eros"); FSTSnapshotVersion *version = FSTTestVersion(1); FSTObjectValue *data = FSTTestObjectValue(@{ @"desc" : @"Discuss all the project related stuff", @@ -65,30 +66,30 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testIsEqual { - XCTAssertEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"b" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/second", 1, + FSTTestDoc("messages/second", 1, @{ @"b" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 2, + FSTTestDoc("messages/first", 2, @{ @"a" : @1 }, NO)); - XCTAssertNotEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertNotEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, NO), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, YES)); - XCTAssertEqualObjects(FSTTestDoc(@"messages/first", 1, + XCTAssertEqualObjects(FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, YES), - FSTTestDoc(@"messages/first", 1, + FSTTestDoc("messages/first", 1, @{ @"a" : @1 }, 5)); } diff --git a/Firestore/Example/Tests/Model/FSTMutationTests.mm b/Firestore/Example/Tests/Model/FSTMutationTests.mm index 5b056fb..40ded40 100644 --- a/Firestore/Example/Tests/Model/FSTMutationTests.mm +++ b/Firestore/Example/Tests/Model/FSTMutationTests.mm @@ -20,14 +20,15 @@ #import #import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/test/firebase/firestore/testutil/testutil.h" namespace testutil = firebase::firestore::testutil; +using firebase::firestore::model::DocumentKey; @interface FSTMutationTests : XCTestCase @end @@ -42,32 +43,32 @@ namespace testutil = firebase::firestore::testutil; - (void)testAppliesSetsToDocuments { NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *set = FSTTestSetMutation(@"collection/key", @{@"bar" : @"bar-value"}); FSTMaybeDocument *setDoc = [set applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{@"bar" : @"bar-value"}; - XCTAssertEqualObjects(setDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(setDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testAppliesPatchesToDocuments { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{ @"foo" : @{@"bar" : @"new-bar-value"}, @"baz" : @"baz-value" }; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testDeletesValuesFromTheFieldMask { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value", @"baz" : @"baz-value"} }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); - FSTDocumentKey *key = FSTTestDocKey(@"collection/key"); + DocumentKey key = testutil::Key("collection/key"); FSTFieldMask *mask = [[FSTFieldMask alloc] initWithFields:{testutil::Field("foo.bar")}]; FSTMutation *patch = [[FSTPatchMutation alloc] initWithKey:key fieldMask:mask @@ -77,23 +78,23 @@ namespace testutil = firebase::firestore::testutil; [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{ @"foo" : @{@"baz" : @"baz-value"} }; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testPatchesPrimitiveValue { NSDictionary *docData = @{@"foo" : @"foo-value", @"baz" : @"baz-value"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo.bar" : @"new-bar-value"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; NSDictionary *expectedData = @{ @"foo" : @{@"bar" : @"new-bar-value"}, @"baz" : @"baz-value" }; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, YES)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, YES)); } - (void)testPatchingDeletedDocumentsDoesNothing { - FSTMaybeDocument *baseDoc = FSTTestDeletedDoc(@"collection/key", 0); + FSTMaybeDocument *baseDoc = FSTTestDeletedDoc("collection/key", 0); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"bar"}, {}); FSTMaybeDocument *patchedDoc = [patch applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; @@ -102,7 +103,7 @@ namespace testutil = firebase::firestore::testutil; - (void)testAppliesLocalTransformsToDocuments { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *transform = FSTTestTransformMutation(@"collection/key", @[ @"foo.bar" ]); FSTMaybeDocument *transformedDoc = @@ -128,7 +129,7 @@ namespace testutil = firebase::firestore::testutil; - (void)testAppliesServerAckedTransformsToDocuments { NSDictionary *docData = @{ @"foo" : @{@"bar" : @"bar-value"}, @"baz" : @"baz-value" }; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *transform = FSTTestTransformMutation(@"collection/key", @[ @"foo.bar" ]); @@ -144,22 +145,22 @@ namespace testutil = firebase::firestore::testutil; NSDictionary *expectedData = @{ @"foo" : @{@"bar" : _timestamp.approximateDateValue}, @"baz" : @"baz-value" }; - XCTAssertEqualObjects(transformedDoc, FSTTestDoc(@"collection/key", 0, expectedData, NO)); + XCTAssertEqualObjects(transformedDoc, FSTTestDoc("collection/key", 0, expectedData, NO)); } - (void)testDeleteDeletes { NSDictionary *docData = @{@"foo" : @"bar"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *mutation = FSTTestDeleteMutation(@"collection/key"); FSTMaybeDocument *result = [mutation applyTo:baseDoc baseDocument:baseDoc localWriteTime:_timestamp]; - XCTAssertEqualObjects(result, FSTTestDeletedDoc(@"collection/key", 0)); + XCTAssertEqualObjects(result, FSTTestDeletedDoc("collection/key", 0)); } - (void)testSetWithMutationResult { NSDictionary *docData = @{@"foo" : @"bar"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *set = FSTTestSetMutation(@"collection/key", @{@"foo" : @"new-bar"}); FSTMutationResult *mutationResult = @@ -170,12 +171,12 @@ namespace testutil = firebase::firestore::testutil; mutationResult:mutationResult]; NSDictionary *expectedData = @{@"foo" : @"new-bar"}; - XCTAssertEqualObjects(setDoc, FSTTestDoc(@"collection/key", 0, expectedData, NO)); + XCTAssertEqualObjects(setDoc, FSTTestDoc("collection/key", 0, expectedData, NO)); } - (void)testPatchWithMutationResult { NSDictionary *docData = @{@"foo" : @"bar"}; - FSTDocument *baseDoc = FSTTestDoc(@"collection/key", 0, docData, NO); + FSTDocument *baseDoc = FSTTestDoc("collection/key", 0, docData, NO); FSTMutation *patch = FSTTestPatchMutation("collection/key", @{@"foo" : @"new-bar"}, {}); FSTMutationResult *mutationResult = @@ -186,7 +187,7 @@ namespace testutil = firebase::firestore::testutil; mutationResult:mutationResult]; NSDictionary *expectedData = @{@"foo" : @"new-bar"}; - XCTAssertEqualObjects(patchedDoc, FSTTestDoc(@"collection/key", 0, expectedData, NO)); + XCTAssertEqualObjects(patchedDoc, FSTTestDoc("collection/key", 0, expectedData, NO)); } #define ASSERT_VERSION_TRANSITION(mutation, base, expected) \ @@ -204,11 +205,11 @@ namespace testutil = firebase::firestore::testutil; * Tests the transition table documented in FSTMutation.h. */ - (void)testTransitions { - FSTDocument *docV0 = FSTTestDoc(@"collection/key", 0, @{}, NO); - FSTDeletedDocument *deletedV0 = FSTTestDeletedDoc(@"collection/key", 0); + FSTDocument *docV0 = FSTTestDoc("collection/key", 0, @{}, NO); + FSTDeletedDocument *deletedV0 = FSTTestDeletedDoc("collection/key", 0); - FSTDocument *docV3 = FSTTestDoc(@"collection/key", 3, @{}, NO); - FSTDeletedDocument *deletedV3 = FSTTestDeletedDoc(@"collection/key", 3); + FSTDocument *docV3 = FSTTestDoc("collection/key", 3, @{}, NO); + FSTDeletedDocument *deletedV3 = FSTTestDeletedDoc("collection/key", 3); FSTMutation *setMutation = FSTTestSetMutation(@"collection/key", @{}); FSTMutation *patchMutation = FSTTestPatchMutation("collection/key", {}, {}); diff --git a/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm b/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm index a947eb4..9fa8bc3 100644 --- a/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm +++ b/Firestore/Example/Tests/Remote/FSTRemoteEventTests.mm @@ -60,8 +60,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testWillAccumulateDocumentAddedAndRemovedEvents { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"docs/2", 2, @{ @"value" : @2 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 2, @{ @"value" : @2 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1, @2, @3 ] removedTargetIDs:@[ @4, @5, @6 ] @@ -80,8 +80,8 @@ NS_ASSUME_NONNULL_BEGIN FSTRemoteEvent *event = [aggregator remoteEvent]; XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 2); - XCTAssertEqualObjects(event.documentUpdates[doc1.key], doc1); - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1.key], doc1); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); XCTAssertEqual(event.targetChanges.count, 6); @@ -111,8 +111,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testWillIgnoreEventsForPendingTargets { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"docs/2", 2, @{ @"value" : @2 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 2, @{ @"value" : @2 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] removedTargetIDs:@[] @@ -144,13 +144,13 @@ NS_ASSUME_NONNULL_BEGIN // doc1 is ignored because it was part of an inactive target, but doc2 is in the changes // because it become active. XCTAssertEqual(event.documentUpdates.count, 1); - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); XCTAssertEqual(event.targetChanges.count, 1); } - (void)testWillIgnoreEventsForRemovedTargets { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] removedTargetIDs:@[] @@ -177,9 +177,9 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testWillKeepResetMappingEvenWithUpdates { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"docs/2", 2, @{ @"value" : @2 }, NO); - FSTDocument *doc3 = FSTTestDoc(@"docs/3", 3, @{ @"value" : @3 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 2, @{ @"value" : @2 }, NO); + FSTDocument *doc3 = FSTTestDoc("docs/3", 3, @{ @"value" : @3 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] removedTargetIDs:@[] @@ -214,9 +214,9 @@ NS_ASSUME_NONNULL_BEGIN FSTRemoteEvent *event = [aggregator remoteEvent]; XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 3); - XCTAssertEqualObjects(event.documentUpdates[doc1.key], doc1); - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); - XCTAssertEqualObjects(event.documentUpdates[doc3.key], doc3); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1.key], doc1); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc3.key], doc3); XCTAssertEqual(event.targetChanges.count, 1); @@ -247,8 +247,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testWillHandleTargetAddAndRemovalInSameBatch { - FSTDocument *doc1a = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); - FSTDocument *doc1b = FSTTestDoc(@"docs/1", 1, @{ @"value" : @2 }, NO); + FSTDocument *doc1a = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc1b = FSTTestDoc("docs/1", 1, @{ @"value" : @2 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] removedTargetIDs:@[ @2 ] @@ -266,7 +266,7 @@ NS_ASSUME_NONNULL_BEGIN FSTRemoteEvent *event = [aggregator remoteEvent]; XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 1); - XCTAssertEqualObjects(event.documentUpdates[doc1b.key], doc1b); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1b.key], doc1b); XCTAssertEqual(event.targetChanges.count, 2); @@ -298,8 +298,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testTargetAddedChangeWillResetPreviousState { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"docs/2", 2, @{ @"value" : @2 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 2, @{ @"value" : @2 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1, @3 ] removedTargetIDs:@[ @2 ] @@ -332,8 +332,8 @@ NS_ASSUME_NONNULL_BEGIN FSTRemoteEvent *event = [aggregator remoteEvent]; XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 2); - XCTAssertEqualObjects(event.documentUpdates[doc1.key], doc1); - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1.key], doc1); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); // target 1 and 3 are affected (1 because of re-add), target 2 is not because of remove XCTAssertEqual(event.targetChanges.count, 2); @@ -394,8 +394,8 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testExistenceFilterMismatchResetsTarget { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); - FSTDocument *doc2 = FSTTestDoc(@"docs/2", 2, @{ @"value" : @2 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 2, @{ @"value" : @2 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] removedTargetIDs:@[] @@ -419,8 +419,8 @@ NS_ASSUME_NONNULL_BEGIN FSTRemoteEvent *event = [aggregator remoteEvent]; XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 2); - XCTAssertEqualObjects(event.documentUpdates[doc1.key], doc1); - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1.key], doc1); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); XCTAssertEqual(event.targetChanges.count, 1); @@ -443,11 +443,11 @@ NS_ASSUME_NONNULL_BEGIN } - (void)testDocumentUpdate { - FSTDocument *doc1 = FSTTestDoc(@"docs/1", 1, @{ @"value" : @1 }, NO); + FSTDocument *doc1 = FSTTestDoc("docs/1", 1, @{ @"value" : @1 }, NO); FSTDeletedDocument *deletedDoc1 = [FSTDeletedDocument documentWithKey:doc1.key version:FSTTestVersion(3)]; - FSTDocument *doc2 = FSTTestDoc(@"docs/2", 2, @{ @"value" : @2 }, NO); - FSTDocument *doc3 = FSTTestDoc(@"docs/3", 3, @{ @"value" : @3 }, NO); + FSTDocument *doc2 = FSTTestDoc("docs/2", 2, @{ @"value" : @2 }, NO); + FSTDocument *doc3 = FSTTestDoc("docs/3", 3, @{ @"value" : @3 }, NO); FSTWatchChange *change1 = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1 ] removedTargetIDs:@[] @@ -466,8 +466,8 @@ NS_ASSUME_NONNULL_BEGIN FSTRemoteEvent *event = [aggregator remoteEvent]; XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 2); - XCTAssertEqualObjects(event.documentUpdates[doc1.key], doc1); - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1.key], doc1); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); // Update doc1 [event addDocumentUpdate:deletedDoc1]; @@ -476,11 +476,11 @@ NS_ASSUME_NONNULL_BEGIN XCTAssertEqualObjects(event.snapshotVersion, FSTTestVersion(3)); XCTAssertEqual(event.documentUpdates.count, 3); // doc1 is replaced - XCTAssertEqualObjects(event.documentUpdates[doc1.key], deletedDoc1); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc1.key], deletedDoc1); // doc2 is untouched - XCTAssertEqualObjects(event.documentUpdates[doc2.key], doc2); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc2.key], doc2); // doc3 is new - XCTAssertEqualObjects(event.documentUpdates[doc3.key], doc3); + XCTAssertEqualObjects(event.documentUpdates[(FSTDocumentKey *)doc3.key], doc3); // Target is unchanged XCTAssertEqual(event.targetChanges.count, 1); diff --git a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm index 4c3682f..64f4777 100644 --- a/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm +++ b/Firestore/Example/Tests/Remote/FSTSerializerBetaTests.mm @@ -741,7 +741,7 @@ NS_ASSUME_NONNULL_BEGIN initWithUpdatedTargetIDs:@[ @1, @2 ] removedTargetIDs:@[] documentKey:FSTTestDocKey(@"coll/1") - document:FSTTestDoc(@"coll/1", 5, @{@"foo" : @"bar"}, NO)]; + document:FSTTestDoc("coll/1", 5, @{@"foo" : @"bar"}, NO)]; GCFSListenResponse *listenResponse = [GCFSListenResponse message]; listenResponse.documentChange.document.name = @"projects/p/databases/d/documents/coll/1"; listenResponse.documentChange.document.updateTime.nanos = 5000; @@ -760,7 +760,7 @@ NS_ASSUME_NONNULL_BEGIN initWithUpdatedTargetIDs:@[ @2 ] removedTargetIDs:@[ @1 ] documentKey:FSTTestDocKey(@"coll/1") - document:FSTTestDoc(@"coll/1", 5, @{@"foo" : @"bar"}, NO)]; + document:FSTTestDoc("coll/1", 5, @{@"foo" : @"bar"}, NO)]; GCFSListenResponse *listenResponse = [GCFSListenResponse message]; listenResponse.documentChange.document.name = @"projects/p/databases/d/documents/coll/1"; listenResponse.documentChange.document.updateTime.nanos = 5000; @@ -779,7 +779,7 @@ NS_ASSUME_NONNULL_BEGIN [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[] removedTargetIDs:@[ @1, @2 ] documentKey:FSTTestDocKey(@"coll/1") - document:FSTTestDeletedDoc(@"coll/1", 5)]; + document:FSTTestDeletedDoc("coll/1", 5)]; GCFSListenResponse *listenResponse = [GCFSListenResponse message]; listenResponse.documentDelete.document = @"projects/p/databases/d/documents/coll/1"; listenResponse.documentDelete.readTime.nanos = 5000; diff --git a/Firestore/Example/Tests/Remote/FSTWatchChangeTests.mm b/Firestore/Example/Tests/Remote/FSTWatchChangeTests.mm index df2496b..d707e3c 100644 --- a/Firestore/Example/Tests/Remote/FSTWatchChangeTests.mm +++ b/Firestore/Example/Tests/Remote/FSTWatchChangeTests.mm @@ -32,7 +32,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTWatchChangeTests - (void)testDocumentChange { - FSTMaybeDocument *doc = FSTTestDoc(@"a/b", 1, @{}, NO); + FSTMaybeDocument *doc = FSTTestDoc("a/b", 1, @{}, NO); FSTDocumentWatchChange *change = [[FSTDocumentWatchChange alloc] initWithUpdatedTargetIDs:@[ @1, @2, @3 ] removedTargetIDs:@[ @4, @5 ] diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm index 0f57b81..10aa6c2 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm @@ -153,7 +153,9 @@ static NSString *const kNoIOSTag = @"no-ios"; } } NSNumber *version = change[1]; - FSTDocument *doc = FSTTestDoc(change[0], version.longLongValue, change[2], hasMutations); + XCTAssert([change[0] isKindOfClass:[NSString class]]); + FSTDocument *doc = FSTTestDoc(util::MakeStringView((NSString *)change[0]), version.longLongValue, + change[2], hasMutations); return [FSTDocumentViewChange changeWithDocument:doc type:type]; } diff --git a/Firestore/Example/Tests/Util/FSTHelpers.h b/Firestore/Example/Tests/Util/FSTHelpers.h index d86201b..d05c1f1 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.h +++ b/Firestore/Example/Tests/Util/FSTHelpers.h @@ -192,13 +192,13 @@ typedef int64_t FSTTestSnapshotVersion; FSTSnapshotVersion *FSTTestVersion(FSTTestSnapshotVersion version); /** A convenience method for creating docs for tests. */ -FSTDocument *FSTTestDoc(NSString *path, +FSTDocument *FSTTestDoc(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary *data, BOOL hasMutations); /** A convenience method for creating deleted docs for tests. */ -FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version); +FSTDeletedDocument *FSTTestDeletedDoc(const absl::string_view path, FSTTestSnapshotVersion version); /** * A convenience method for creating a document reference from a path string. diff --git a/Firestore/Example/Tests/Util/FSTHelpers.mm b/Firestore/Example/Tests/Util/FSTHelpers.mm index be02002..5751739 100644 --- a/Firestore/Example/Tests/Util/FSTHelpers.mm +++ b/Firestore/Example/Tests/Util/FSTHelpers.mm @@ -43,6 +43,7 @@ #import "Firestore/Source/Util/FSTAssert.h" #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/field_value.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" @@ -51,6 +52,7 @@ namespace util = firebase::firestore::util; namespace testutil = firebase::firestore::testutil; using firebase::firestore::model::DatabaseId; +using firebase::firestore::model::DocumentKey; using firebase::firestore::model::FieldPath; using firebase::firestore::model::FieldValue; using firebase::firestore::model::ResourcePath; @@ -148,19 +150,20 @@ FSTSnapshotVersion *FSTTestVersion(FSTTestSnapshotVersion versionMicroseconds) { return [FSTSnapshotVersion versionWithTimestamp:timestamp]; } -FSTDocument *FSTTestDoc(NSString *path, +FSTDocument *FSTTestDoc(const absl::string_view path, FSTTestSnapshotVersion version, NSDictionary *data, BOOL hasMutations) { - FSTDocumentKey *key = FSTTestDocKey(path); + DocumentKey key = testutil::Key(path); return [FSTDocument documentWithData:FSTTestObjectValue(data) key:key version:FSTTestVersion(version) hasLocalMutations:hasMutations]; } -FSTDeletedDocument *FSTTestDeletedDoc(NSString *path, FSTTestSnapshotVersion version) { - FSTDocumentKey *key = FSTTestDocKey(path); +FSTDeletedDocument *FSTTestDeletedDoc(const absl::string_view path, + FSTTestSnapshotVersion version) { + DocumentKey key = testutil::Key(path); return [FSTDeletedDocument documentWithKey:key version:FSTTestVersion(version)]; } diff --git a/Firestore/Source/Core/FSTQuery.mm b/Firestore/Source/Core/FSTQuery.mm index 43b6356..626bbb6 100644 --- a/Firestore/Source/Core/FSTQuery.mm +++ b/Firestore/Source/Core/FSTQuery.mm @@ -767,7 +767,7 @@ NSString *FSTStringFromQueryRelationOperator(FSTRelationFilterOperator filterOpe /* Returns YES if the document matches the path for the receiver. */ - (BOOL)pathMatchesDocument:(FSTDocument *)document { - const ResourcePath &documentPath = document.key.path; + const ResourcePath &documentPath = document.key.path(); if ([FSTDocumentKey isDocumentKey:_path]) { // Exact match for document queries. return self.path == documentPath; diff --git a/Firestore/Source/Core/FSTTransaction.mm b/Firestore/Source/Core/FSTTransaction.mm index f97888a..b980a4e 100644 --- a/Firestore/Source/Core/FSTTransaction.mm +++ b/Firestore/Source/Core/FSTTransaction.mm @@ -30,6 +30,8 @@ #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTUsageValidation.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + NS_ASSUME_NONNULL_BEGIN #pragma mark - FSTTransaction @@ -79,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN // when writing. docVersion = [FSTSnapshotVersion noVersion]; } - FSTSnapshotVersion *existingVersion = self.readVersions[doc.key]; + FSTSnapshotVersion *existingVersion = self.readVersions[(FSTDocumentKey *)doc.key]; if (existingVersion) { if (error) { *error = @@ -92,7 +94,7 @@ NS_ASSUME_NONNULL_BEGIN } return NO; } else { - self.readVersions[doc.key] = docVersion; + self.readVersions[(FSTDocumentKey *)doc.key] = docVersion; return YES; } } diff --git a/Firestore/Source/Core/FSTView.mm b/Firestore/Source/Core/FSTView.mm index b2a39cb..b3cf189 100644 --- a/Firestore/Source/Core/FSTView.mm +++ b/Firestore/Source/Core/FSTView.mm @@ -216,8 +216,8 @@ static NSComparisonResult FSTCompareDocumentViewChangeTypes(FSTDocumentViewChang newDoc = (FSTDocument *)maybeNewDoc; } if (newDoc) { - FSTAssert([key isEqual:newDoc.key], @"Mismatching key in document changes: %@ != %@", key, - newDoc.key); + FSTAssert([key isEqual:newDoc.key], @"Mismatching key in document changes: %@ != %s", key, + newDoc.key.ToString().c_str()); if (![self.query matchesDocument:newDoc]) { newDoc = nil; } diff --git a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm index c86318d..97f0ef1 100644 --- a/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm +++ b/Firestore/Source/Local/FSTLevelDBRemoteDocumentCache.mm @@ -111,7 +111,7 @@ static ReadOptions StandardReadOptions() { for (; it->Valid() && [currentKey decodeKey:it->key()]; it->Next()) { FSTMaybeDocument *maybeDoc = [self decodedMaybeDocument:it->value() withKey:currentKey.documentKey]; - if (!query.path.IsPrefixOf(maybeDoc.key.path)) { + if (!query.path.IsPrefixOf(maybeDoc.key.path())) { break; } else if ([maybeDoc isKindOfClass:[FSTDocument class]]) { results = [results dictionaryBySettingObject:(FSTDocument *)maybeDoc forKey:maybeDoc.key]; @@ -143,8 +143,8 @@ static ReadOptions StandardReadOptions() { FSTMaybeDocument *maybeDocument = [self.serializer decodedMaybeDocument:proto]; FSTAssert([maybeDocument.key isEqualToKey:documentKey], - @"Read document has key (%@) instead of expected key (%@).", maybeDocument.key, - documentKey); + @"Read document has key (%s) instead of expected key (%@).", + maybeDocument.key.ToString().c_str(), documentKey); return maybeDocument; } diff --git a/Firestore/Source/Local/FSTRemoteDocumentChangeBuffer.mm b/Firestore/Source/Local/FSTRemoteDocumentChangeBuffer.mm index bca587a..b228461 100644 --- a/Firestore/Source/Local/FSTRemoteDocumentChangeBuffer.mm +++ b/Firestore/Source/Local/FSTRemoteDocumentChangeBuffer.mm @@ -21,6 +21,8 @@ #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Util/FSTAssert.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + NS_ASSUME_NONNULL_BEGIN @interface FSTRemoteDocumentChangeBuffer () @@ -53,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)addEntry:(FSTMaybeDocument *)maybeDocument { [self assertValid]; - self.changes[maybeDocument.key] = maybeDocument; + self.changes[(FSTDocumentKey *)maybeDocument.key] = maybeDocument; } - (nullable FSTMaybeDocument *)entryForKey:(FSTDocumentKey *)documentKey { diff --git a/Firestore/Source/Model/FSTDocument.h b/Firestore/Source/Model/FSTDocument.h index 36237fd..47e4d28 100644 --- a/Firestore/Source/Model/FSTDocument.h +++ b/Firestore/Source/Model/FSTDocument.h @@ -16,9 +16,9 @@ #import +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" -@class FSTDocumentKey; @class FSTFieldValue; @class FSTObjectValue; @class FSTSnapshotVersion; @@ -31,14 +31,14 @@ NS_ASSUME_NONNULL_BEGIN */ @interface FSTMaybeDocument : NSObject - (id)init __attribute__((unavailable("Abstract base class"))); +- (const firebase::firestore::model::DocumentKey &)key; -@property(nonatomic, strong, readonly) FSTDocumentKey *key; @property(nonatomic, readonly) FSTSnapshotVersion *version; @end @interface FSTDocument : FSTMaybeDocument + (instancetype)documentWithData:(FSTObjectValue *)data - key:(FSTDocumentKey *)key + key:(firebase::firestore::model::DocumentKey)key version:(FSTSnapshotVersion *)version hasLocalMutations:(BOOL)mutations; @@ -50,7 +50,8 @@ NS_ASSUME_NONNULL_BEGIN @end @interface FSTDeletedDocument : FSTMaybeDocument -+ (instancetype)documentWithKey:(FSTDocumentKey *)key version:(FSTSnapshotVersion *)version; ++ (instancetype)documentWithKey:(firebase::firestore::model::DocumentKey)key + version:(FSTSnapshotVersion *)version; @end /** An NSComparator suitable for comparing docs using only their keys. */ diff --git a/Firestore/Source/Model/FSTDocument.mm b/Firestore/Source/Model/FSTDocument.mm index ca66da1..9898c2a 100644 --- a/Firestore/Source/Model/FSTDocument.mm +++ b/Firestore/Source/Model/FSTDocument.mm @@ -16,33 +16,38 @@ #import "Firestore/Source/Model/FSTDocument.h" +#include + #import "Firestore/Source/Core/FSTSnapshotVersion.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Util/FSTAssert.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" #include "Firestore/core/src/firebase/firestore/util/string_apple.h" namespace util = firebase::firestore::util; +using firebase::firestore::model::DocumentKey; using firebase::firestore::model::FieldPath; NS_ASSUME_NONNULL_BEGIN @interface FSTMaybeDocument () -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(DocumentKey)key version:(FSTSnapshotVersion *)version NS_DESIGNATED_INITIALIZER; @end -@implementation FSTMaybeDocument +@implementation FSTMaybeDocument { + DocumentKey _key; +} -- (instancetype)initWithKey:(FSTDocumentKey *)key version:(FSTSnapshotVersion *)version { +- (instancetype)initWithKey:(DocumentKey)key version:(FSTSnapshotVersion *)version { FSTAssert(!!version, @"Version must not be nil."); self = [super init]; if (self) { - _key = key; + _key = std::move(key); _version = version; } return self; @@ -53,23 +58,29 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (const DocumentKey &)key { + return _key; +} + @end @implementation FSTDocument + (instancetype)documentWithData:(FSTObjectValue *)data - key:(FSTDocumentKey *)key + key:(DocumentKey)key version:(FSTSnapshotVersion *)version hasLocalMutations:(BOOL)mutations { - return - [[FSTDocument alloc] initWithData:data key:key version:version hasLocalMutations:mutations]; + return [[FSTDocument alloc] initWithData:data + key:std::move(key) + version:version + hasLocalMutations:mutations]; } - (instancetype)initWithData:(FSTObjectValue *)data - key:(FSTDocumentKey *)key + key:(DocumentKey)key version:(FSTSnapshotVersion *)version hasLocalMutations:(BOOL)mutations { - self = [super initWithKey:key version:version]; + self = [super initWithKey:std::move(key) version:version]; if (self) { _data = data; _localMutations = mutations; @@ -100,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN - (NSString *)description { return [NSString stringWithFormat:@"", - self.key.path.CanonicalString().c_str(), self.version, + self.key.ToString().c_str(), self.version, self.localMutations ? @"YES" : @"NO", self.data]; } @@ -112,8 +123,8 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTDeletedDocument -+ (instancetype)documentWithKey:(FSTDocumentKey *)key version:(FSTSnapshotVersion *)version { - return [[FSTDeletedDocument alloc] initWithKey:key version:version]; ++ (instancetype)documentWithKey:(DocumentKey)key version:(FSTSnapshotVersion *)version { + return [[FSTDeletedDocument alloc] initWithKey:std::move(key) version:version]; } - (BOOL)isEqual:(id)other { diff --git a/Firestore/Source/Model/FSTDocumentSet.h b/Firestore/Source/Model/FSTDocumentSet.h index 022e900..b5521e7 100644 --- a/Firestore/Source/Model/FSTDocumentSet.h +++ b/Firestore/Source/Model/FSTDocumentSet.h @@ -18,8 +18,9 @@ #import "Firestore/Source/Model/FSTDocumentDictionary.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + @class FSTDocument; -@class FSTDocumentKey; NS_ASSUME_NONNULL_BEGIN @@ -41,10 +42,10 @@ NS_ASSUME_NONNULL_BEGIN - (BOOL)isEmpty; /** Returns YES if this set contains a document with the given key. */ -- (BOOL)containsKey:(FSTDocumentKey *)key; +- (BOOL)containsKey:(const firebase::firestore::model::DocumentKey &)key; /** Returns the document from this set with the given key if it exists or nil if it doesn't. */ -- (FSTDocument *_Nullable)documentForKey:(FSTDocumentKey *)key; +- (FSTDocument *_Nullable)documentForKey:(const firebase::firestore::model::DocumentKey &)key; /** * Returns the first document in the set according to its built in ordering, or nil if the set @@ -62,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN * Returns the index of the document with the provided key in the document set. Returns NSNotFound * if the key is not present. */ -- (NSUInteger)indexOfKey:(FSTDocumentKey *)key; +- (NSUInteger)indexOfKey:(const firebase::firestore::model::DocumentKey &)key; - (NSEnumerator *)documentEnumerator; @@ -79,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)documentSetByAddingDocument:(FSTDocument *_Nullable)document; /** Returns a new FSTDocumentSet that excludes any document associated with the given key. */ -- (instancetype)documentSetByRemovingKey:(FSTDocumentKey *)key; +- (instancetype)documentSetByRemovingKey:(const firebase::firestore::model::DocumentKey &)key; @end NS_ASSUME_NONNULL_END diff --git a/Firestore/Source/Model/FSTDocumentSet.mm b/Firestore/Source/Model/FSTDocumentSet.mm index 6f44799..2f0b42b 100644 --- a/Firestore/Source/Model/FSTDocumentSet.mm +++ b/Firestore/Source/Model/FSTDocumentSet.mm @@ -20,6 +20,10 @@ #import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/third_party/Immutable/FSTImmutableSortedSet.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + +using firebase::firestore::model::DocumentKey; + NS_ASSUME_NONNULL_BEGIN /** @@ -119,12 +123,12 @@ typedef FSTImmutableSortedSet SetType; return [self.index isEmpty]; } -- (BOOL)containsKey:(FSTDocumentKey *)key { - return [self.index objectForKey:key] != nil; +- (BOOL)containsKey:(const DocumentKey &)key { + return [self.index objectForKey:(FSTDocumentKey *)key] != nil; } -- (FSTDocument *_Nullable)documentForKey:(FSTDocumentKey *)key { - return [self.index objectForKey:key]; +- (FSTDocument *_Nullable)documentForKey:(const DocumentKey &)key { + return [self.index objectForKey:(FSTDocumentKey *)key]; } - (FSTDocument *_Nullable)firstDocument { @@ -135,8 +139,8 @@ typedef FSTImmutableSortedSet SetType; return [self.sortedSet lastObject]; } -- (NSUInteger)indexOfKey:(FSTDocumentKey *)key { - FSTDocument *doc = [self.index objectForKey:key]; +- (NSUInteger)indexOfKey:(const DocumentKey &)key { + FSTDocument *doc = [self.index objectForKey:(FSTDocumentKey *)key]; return doc ? [self.sortedSet indexOfObject:doc] : NSNotFound; } @@ -171,8 +175,8 @@ typedef FSTImmutableSortedSet SetType; return [[FSTDocumentSet alloc] initWithIndex:index set:set]; } -- (instancetype)documentSetByRemovingKey:(FSTDocumentKey *)key { - FSTDocument *doc = [self.index objectForKey:key]; +- (instancetype)documentSetByRemovingKey:(const DocumentKey &)key { + FSTDocument *doc = [self.index objectForKey:(FSTDocumentKey *)key]; if (!doc) { return self; } diff --git a/Firestore/Source/Model/FSTMutation.h b/Firestore/Source/Model/FSTMutation.h index 2d29dc9..4e4357d 100644 --- a/Firestore/Source/Model/FSTMutation.h +++ b/Firestore/Source/Model/FSTMutation.h @@ -18,10 +18,10 @@ #include +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" @class FSTDocument; -@class FSTDocumentKey; @class FSTFieldValue; @class FSTMaybeDocument; @class FSTObjectValue; @@ -155,7 +155,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { - (id)init NS_UNAVAILABLE; -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key precondition:(FSTPrecondition *)precondition NS_DESIGNATED_INITIALIZER; /** @@ -215,7 +215,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { baseDocument:(nullable FSTMaybeDocument *)baseDoc localWriteTime:(nullable FIRTimestamp *)localWriteTime; -@property(nonatomic, strong, readonly) FSTDocumentKey *key; +- (const firebase::firestore::model::DocumentKey &)key; /** The precondition for this mutation. */ @property(nonatomic, strong, readonly) FSTPrecondition *precondition; @@ -230,7 +230,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { */ @interface FSTSetMutation : FSTMutation -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key precondition:(FSTPrecondition *)precondition NS_UNAVAILABLE; /** @@ -241,7 +241,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { * key. * @param precondition The precondition for this mutation. */ -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key value:(FSTObjectValue *)value precondition:(FSTPrecondition *)precondition NS_DESIGNATED_INITIALIZER; @@ -263,7 +263,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { @interface FSTPatchMutation : FSTMutation /** Returns the precondition for the given FSTPrecondition. */ -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key precondition:(FSTPrecondition *)precondition NS_UNAVAILABLE; /** @@ -277,7 +277,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { * to determine the locations at which it should be applied). * @param precondition The precondition for this mutation. */ -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key fieldMask:(FSTFieldMask *)fieldMask value:(FSTObjectValue *)value precondition:(FSTPrecondition *)precondition NS_DESIGNATED_INITIALIZER; @@ -306,7 +306,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { */ @interface FSTTransformMutation : FSTMutation -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key precondition:(FSTPrecondition *)precondition NS_UNAVAILABLE; /** @@ -315,7 +315,7 @@ typedef NS_ENUM(NSUInteger, FSTPreconditionExists) { * @param key Identifies the location of the document to mutate. * @param fieldTransforms A list of FSTFieldTransform objects to perform to the document. */ -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(firebase::firestore::model::DocumentKey)key fieldTransforms:(NSArray *)fieldTransforms NS_DESIGNATED_INITIALIZER; diff --git a/Firestore/Source/Model/FSTMutation.mm b/Firestore/Source/Model/FSTMutation.mm index a61ee84..253a853 100644 --- a/Firestore/Source/Model/FSTMutation.mm +++ b/Firestore/Source/Model/FSTMutation.mm @@ -16,17 +16,20 @@ #import "Firestore/Source/Model/FSTMutation.h" +#include + #import "FIRTimestamp.h" #import "Firestore/Source/Core/FSTSnapshotVersion.h" #import "Firestore/Source/Model/FSTDocument.h" -#import "Firestore/Source/Model/FSTDocumentKey.h" #import "Firestore/Source/Model/FSTFieldValue.h" #import "Firestore/Source/Util/FSTAssert.h" #import "Firestore/Source/Util/FSTClasses.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" +using firebase::firestore::model::DocumentKey; using firebase::firestore::model::FieldPath; NS_ASSUME_NONNULL_BEGIN @@ -246,11 +249,13 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - FSTMutation -@implementation FSTMutation +@implementation FSTMutation { + DocumentKey _key; +} -- (instancetype)initWithKey:(FSTDocumentKey *)key precondition:(FSTPrecondition *)precondition { +- (instancetype)initWithKey:(DocumentKey)key precondition:(FSTPrecondition *)precondition { if (self = [super init]) { - _key = key; + _key = std::move(key); _precondition = precondition; } return self; @@ -270,24 +275,28 @@ NS_ASSUME_NONNULL_BEGIN [self applyTo:maybeDoc baseDocument:baseDoc localWriteTime:localWriteTime mutationResult:nil]; } +- (const DocumentKey &)key { + return _key; +} + @end #pragma mark - FSTSetMutation @implementation FSTSetMutation -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(DocumentKey)key value:(FSTObjectValue *)value precondition:(FSTPrecondition *)precondition { - if (self = [super initWithKey:key precondition:precondition]) { + if (self = [super initWithKey:std::move(key) precondition:precondition]) { _value = value; } return self; } - (NSString *)description { - return [NSString stringWithFormat:@"", self.key, - self.value, self.precondition]; + return [NSString stringWithFormat:@"", + self.key.ToString().c_str(), self.value, self.precondition]; } - (BOOL)isEqual:(id)other { @@ -347,11 +356,11 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTPatchMutation -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(DocumentKey)key fieldMask:(FSTFieldMask *)fieldMask value:(FSTObjectValue *)value precondition:(FSTPrecondition *)precondition { - self = [super initWithKey:key precondition:precondition]; + self = [super initWithKey:std::move(key) precondition:precondition]; if (self) { _fieldMask = fieldMask; _value = value; @@ -382,8 +391,9 @@ NS_ASSUME_NONNULL_BEGIN } - (NSString *)description { - return [NSString stringWithFormat:@"", - self.key, self.fieldMask, self.value, self.precondition]; + return [NSString stringWithFormat:@"", + self.key.ToString().c_str(), self.fieldMask, self.value, + self.precondition]; } - (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc @@ -401,7 +411,7 @@ NS_ASSUME_NONNULL_BEGIN BOOL hasLocalMutations = (mutationResult == nil); if (!maybeDoc || [maybeDoc isMemberOfClass:[FSTDeletedDocument class]]) { // Precondition applied, so create the document if necessary - FSTDocumentKey *key = maybeDoc ? maybeDoc.key : self.key; + const DocumentKey &key = maybeDoc ? maybeDoc.key : self.key; FSTSnapshotVersion *version = maybeDoc ? maybeDoc.version : [FSTSnapshotVersion noVersion]; maybeDoc = [FSTDocument documentWithData:[FSTObjectValue objectValue] key:key @@ -439,12 +449,13 @@ NS_ASSUME_NONNULL_BEGIN @implementation FSTTransformMutation -- (instancetype)initWithKey:(FSTDocumentKey *)key +- (instancetype)initWithKey:(DocumentKey)key fieldTransforms:(NSArray *)fieldTransforms { // NOTE: We set a precondition of exists: true as a safety-check, since we always combine // FSTTransformMutations with a FSTSetMutation or FSTPatchMutation which (if successful) should // end up with an existing document. - if (self = [super initWithKey:key precondition:[FSTPrecondition preconditionWithExists:YES]]) { + if (self = [super initWithKey:std::move(key) + precondition:[FSTPrecondition preconditionWithExists:YES]]) { _fieldTransforms = fieldTransforms; } return self; @@ -472,8 +483,9 @@ NS_ASSUME_NONNULL_BEGIN } - (NSString *)description { - return [NSString stringWithFormat:@"", - self.key, self.fieldTransforms, self.precondition]; + return [NSString stringWithFormat:@"", + self.key.ToString().c_str(), self.fieldTransforms, + self.precondition]; } - (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc @@ -584,8 +596,8 @@ NS_ASSUME_NONNULL_BEGIN } - (NSString *)description { - return [NSString - stringWithFormat:@"", self.key, self.precondition]; + return [NSString stringWithFormat:@"", + self.key.ToString().c_str(), self.precondition]; } - (nullable FSTMaybeDocument *)applyTo:(nullable FSTMaybeDocument *)maybeDoc diff --git a/Firestore/Source/Model/FSTMutationBatch.h b/Firestore/Source/Model/FSTMutationBatch.h index 1de79fe..3c82338 100644 --- a/Firestore/Source/Model/FSTMutationBatch.h +++ b/Firestore/Source/Model/FSTMutationBatch.h @@ -20,6 +20,8 @@ #import "Firestore/Source/Model/FSTDocumentKeySet.h" #import "Firestore/Source/Model/FSTDocumentVersionDictionary.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + @class FSTMutation; @class FIRTimestamp; @class FSTMutationResult; @@ -60,7 +62,7 @@ extern const FSTBatchID kFSTBatchIDUnknown; * their hasLocalMutations flag set. */ - (FSTMaybeDocument *_Nullable)applyTo:(FSTMaybeDocument *_Nullable)maybeDoc - documentKey:(FSTDocumentKey *)documentKey + documentKey:(const firebase::firestore::model::DocumentKey &)documentKey mutationBatchResult:(FSTMutationBatchResult *_Nullable)mutationBatchResult; /** @@ -68,7 +70,7 @@ extern const FSTBatchID kFSTBatchIDUnknown; * the backend). */ - (FSTMaybeDocument *_Nullable)applyTo:(FSTMaybeDocument *_Nullable)maybeDoc - documentKey:(FSTDocumentKey *)documentKey; + documentKey:(const firebase::firestore::model::DocumentKey &)documentKey; /** * Returns YES if this mutation batch has already been removed from the mutation queue. diff --git a/Firestore/Source/Model/FSTMutationBatch.mm b/Firestore/Source/Model/FSTMutationBatch.mm index 07aadbb..6598d27 100644 --- a/Firestore/Source/Model/FSTMutationBatch.mm +++ b/Firestore/Source/Model/FSTMutationBatch.mm @@ -24,6 +24,10 @@ #import "Firestore/Source/Model/FSTMutation.h" #import "Firestore/Source/Util/FSTAssert.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + +using firebase::firestore::model::DocumentKey; + NS_ASSUME_NONNULL_BEGIN const FSTBatchID kFSTBatchIDUnknown = -1; @@ -68,10 +72,11 @@ const FSTBatchID kFSTBatchIDUnknown = -1; } - (FSTMaybeDocument *_Nullable)applyTo:(FSTMaybeDocument *_Nullable)maybeDoc - documentKey:(FSTDocumentKey *)documentKey + documentKey:(const DocumentKey &)documentKey mutationBatchResult:(FSTMutationBatchResult *_Nullable)mutationBatchResult { FSTAssert(!maybeDoc || [maybeDoc.key isEqualToKey:documentKey], - @"applyTo: key %@ doesn't match maybeDoc key %@", documentKey, maybeDoc.key); + @"applyTo: key %s doesn't match maybeDoc key %s", documentKey.ToString().c_str(), + maybeDoc.key.ToString().c_str()); FSTMaybeDocument *baseDoc = maybeDoc; if (mutationBatchResult) { FSTAssert(mutationBatchResult.mutationResults.count == self.mutations.count, @@ -94,7 +99,7 @@ const FSTBatchID kFSTBatchIDUnknown = -1; } - (FSTMaybeDocument *_Nullable)applyTo:(FSTMaybeDocument *_Nullable)maybeDoc - documentKey:(FSTDocumentKey *)documentKey { + documentKey:(const DocumentKey &)documentKey { return [self applyTo:maybeDoc documentKey:documentKey mutationBatchResult:nil]; } diff --git a/Firestore/Source/Remote/FSTRemoteEvent.mm b/Firestore/Source/Remote/FSTRemoteEvent.mm index 88999e4..cd073b3 100644 --- a/Firestore/Source/Remote/FSTRemoteEvent.mm +++ b/Firestore/Source/Remote/FSTRemoteEvent.mm @@ -24,6 +24,8 @@ #import "Firestore/Source/Util/FSTClasses.h" #import "Firestore/Source/Util/FSTLogger.h" +#include "Firestore/core/src/firebase/firestore/model/document_key.h" + NS_ASSUME_NONNULL_BEGIN #pragma mark - FSTTargetMapping @@ -288,7 +290,7 @@ initWithSnapshotVersion:(FSTSnapshotVersion *)snapshotVersion /** Adds a document update to this remote event */ - (void)addDocumentUpdate:(FSTMaybeDocument *)document { - _documentUpdates[document.key] = document; + _documentUpdates[(FSTDocumentKey *)document.key] = document; } /** Handles an existence filter mismatch */ diff --git a/Firestore/core/src/firebase/firestore/model/document_key.h b/Firestore/core/src/firebase/firestore/model/document_key.h index 8e590d8..134bda5 100644 --- a/Firestore/core/src/firebase/firestore/model/document_key.h +++ b/Firestore/core/src/firebase/firestore/model/document_key.h @@ -55,6 +55,10 @@ class DocumentKey { operator FSTDocumentKey*() const { return [FSTDocumentKey keyWithPath:path()]; } + + std::string ToString() const { + return path().CanonicalString(); + } #endif /** @@ -83,11 +87,6 @@ class DocumentKey { return path_ ? *path_ : Empty().path(); } -#if defined(__OBJC__) - // Helper function to convert to FSTDocumentKey during the C++ migration. - FSTDocumentKey* ToFSTDocumentKey() const; -#endif // defined(__OBJC__) - private: // This is an optimization to make passing DocumentKey around cheaper (it's // copied often). diff --git a/Firestore/core/test/firebase/firestore/testutil/testutil.h b/Firestore/core/test/firebase/firestore/testutil/testutil.h index 094efc5..9c69784 100644 --- a/Firestore/core/test/firebase/firestore/testutil/testutil.h +++ b/Firestore/core/test/firebase/firestore/testutil/testutil.h @@ -17,6 +17,7 @@ #ifndef FIRESTORE_CORE_TEST_FIREBASE_FIRESTORE_TESTUTIL_TESTUTIL_H_ #define FIRESTORE_CORE_TEST_FIREBASE_FIRESTORE_TESTUTIL_TESTUTIL_H_ +#include "Firestore/core/src/firebase/firestore/model/document_key.h" #include "Firestore/core/src/firebase/firestore/model/field_path.h" #include "Firestore/core/src/firebase/firestore/model/resource_path.h" #include "absl/strings/string_view.h" @@ -27,6 +28,10 @@ namespace testutil { // Below are convenience methods for creating instances for tests. +inline model::DocumentKey Key(absl::string_view path) { + return model::DocumentKey::FromPathString(path); +} + inline model::FieldPath Field(absl::string_view field) { return model::FieldPath::FromServerFormat(field); } -- cgit v1.2.3