Skip to content

Commit 4e7296b

Browse files
authored
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
1 parent 1395c82 commit 4e7296b

37 files changed

+590
-527
lines changed

Firestore/Example/Tests/API/FIRDocumentSnapshotTests.mm

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ @interface FIRDocumentSnapshotTests : XCTestCase
2828
@implementation FIRDocumentSnapshotTests
2929

3030
- (void)testEquals {
31-
FIRDocumentSnapshot *base = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO);
32-
FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot(@"rooms/foo", 1, @{ @"a" : @1 }, NO, NO);
33-
FIRDocumentSnapshot *nilData = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO);
34-
FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot(@"rooms/foo", 1, nil, NO, NO);
35-
FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, NO);
36-
FIRDocumentSnapshot *differentData = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"b" : @1 }, NO, NO);
37-
FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, YES, NO);
38-
FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot(@"rooms/bar", 1, @{ @"a" : @1 }, NO, YES);
31+
FIRDocumentSnapshot *base = FSTTestDocSnapshot("rooms/foo", 1, @{ @"a" : @1 }, NO, NO);
32+
FIRDocumentSnapshot *baseDup = FSTTestDocSnapshot("rooms/foo", 1, @{ @"a" : @1 }, NO, NO);
33+
FIRDocumentSnapshot *nilData = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO);
34+
FIRDocumentSnapshot *nilDataDup = FSTTestDocSnapshot("rooms/foo", 1, nil, NO, NO);
35+
FIRDocumentSnapshot *differentPath = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, NO, NO);
36+
FIRDocumentSnapshot *differentData = FSTTestDocSnapshot("rooms/bar", 1, @{ @"b" : @1 }, NO, NO);
37+
FIRDocumentSnapshot *hasMutations = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, YES, NO);
38+
FIRDocumentSnapshot *fromCache = FSTTestDocSnapshot("rooms/bar", 1, @{ @"a" : @1 }, NO, YES);
3939
XCTAssertEqualObjects(base, baseDup);
4040
XCTAssertEqualObjects(nilData, nilDataDup);
4141
XCTAssertNotEqualObjects(base, nilData);

Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ @interface FIRQuerySnapshotTests : XCTestCase
2828
@implementation FIRQuerySnapshotTests
2929

3030
- (void)testEquals {
31-
FIRQuerySnapshot *foo = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO);
32-
FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot(@"foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO);
33-
FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot(@"bar", @{},
31+
FIRQuerySnapshot *foo = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO);
32+
FIRQuerySnapshot *fooDup = FSTTestQuerySnapshot("foo", @{}, @{ @"a" : @{@"a" : @1} }, YES, NO);
33+
FIRQuerySnapshot *differentPath = FSTTestQuerySnapshot("bar", @{},
3434
@{ @"a" : @{@"a" : @1} }, YES, NO);
35-
FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot(@"foo",
35+
FIRQuerySnapshot *differentDoc = FSTTestQuerySnapshot("foo",
3636
@{ @"a" : @{@"b" : @1} }, @{}, YES, NO);
37-
FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot(@"foo", @{},
37+
FIRQuerySnapshot *noPendingWrites = FSTTestQuerySnapshot("foo", @{},
3838
@{ @"a" : @{@"a" : @1} }, NO, NO);
39-
FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot(@"foo", @{},
39+
FIRQuerySnapshot *fromCache = FSTTestQuerySnapshot("foo", @{},
4040
@{ @"a" : @{@"a" : @1} }, YES, YES);
4141
XCTAssertEqualObjects(foo, fooDup);
4242
XCTAssertNotEqualObjects(foo, differentPath);

Firestore/Example/Tests/API/FSTAPIHelpers.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
2020

21+
#include "absl/strings/string_view.h"
22+
2123
@class FIRCollectionReference;
2224
@class FIRDocumentReference;
2325
@class FIRDocumentSnapshot;
@@ -34,7 +36,7 @@ extern "C" {
3436
FIRFirestore *FSTTestFirestore();
3537

3638
/** A convenience method for creating a doc snapshot for tests. */
37-
FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path,
39+
FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
3840
FSTTestSnapshotVersion version,
3941
NSDictionary<NSString *, id> *_Nullable data,
4042
BOOL hasMutations,
@@ -61,7 +63,7 @@ FIRDocumentReference *FSTTestDocRef(const absl::string_view path);
6163
* @returns A query snapshot that consists of both sets of documents.
6264
*/
6365
FIRQuerySnapshot *FSTTestQuerySnapshot(
64-
NSString *path,
66+
const absl::string_view path,
6567
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
6668
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
6769
BOOL hasPendingWrites,

Firestore/Example/Tests/API/FSTAPIHelpers.mm

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@
5858
return sharedInstance;
5959
}
6060

61-
FIRDocumentSnapshot *FSTTestDocSnapshot(NSString *path,
61+
FIRDocumentSnapshot *FSTTestDocSnapshot(const absl::string_view path,
6262
FSTTestSnapshotVersion version,
6363
NSDictionary<NSString *, id> *_Nullable data,
6464
BOOL hasMutations,
6565
BOOL fromCache) {
6666
FSTDocument *doc = data ? FSTTestDoc(path, version, data, hasMutations) : nil;
6767
return [FIRDocumentSnapshot snapshotWithFirestore:FSTTestFirestore()
68-
documentKey:FSTTestDocKey(path)
68+
documentKey:testutil::Key(path)
6969
document:doc
7070
fromCache:fromCache];
7171
}
@@ -82,7 +82,7 @@
8282

8383
/** A convenience method for creating a query snapshots for tests. */
8484
FIRQuerySnapshot *FSTTestQuerySnapshot(
85-
NSString *path,
85+
const absl::string_view path,
8686
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *oldDocs,
8787
NSDictionary<NSString *, NSDictionary<NSString *, id> *> *docsToAdd,
8888
BOOL hasPendingWrites,
@@ -92,30 +92,31 @@
9292
FSTDocumentSet *oldDocuments = FSTTestDocSet(FSTDocumentComparatorByKey, @[]);
9393
for (NSString *key in oldDocs) {
9494
oldDocuments = [oldDocuments
95-
documentSetByAddingDocument:FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1,
96-
oldDocs[key], hasPendingWrites)];
95+
documentSetByAddingDocument:FSTTestDoc(util::MakeStringView([NSString
96+
stringWithFormat:@"%s/%@", path.data(), key]),
97+
1, oldDocs[key], hasPendingWrites)];
9798
}
9899
FSTDocumentSet *newDocuments = oldDocuments;
99100
NSArray<FSTDocumentViewChange *> *documentChanges = [NSArray array];
100101
for (NSString *key in docsToAdd) {
101-
FSTDocument *docToAdd = FSTTestDoc([NSString stringWithFormat:@"%@/%@", path, key], 1,
102-
docsToAdd[key], hasPendingWrites);
102+
FSTDocument *docToAdd =
103+
FSTTestDoc(util::MakeStringView([NSString stringWithFormat:@"%s/%@", path.data(), key]), 1,
104+
docsToAdd[key], hasPendingWrites);
103105
newDocuments = [newDocuments documentSetByAddingDocument:docToAdd];
104106
documentChanges = [documentChanges
105107
arrayByAddingObject:[FSTDocumentViewChange
106108
changeWithDocument:docToAdd
107109
type:FSTDocumentViewChangeTypeAdded]];
108110
}
109-
FSTViewSnapshot *viewSnapshot =
110-
[[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(util::MakeStringView(path))
111-
documents:newDocuments
112-
oldDocuments:oldDocuments
113-
documentChanges:documentChanges
114-
fromCache:fromCache
115-
hasPendingWrites:hasPendingWrites
116-
syncStateChanged:YES];
111+
FSTViewSnapshot *viewSnapshot = [[FSTViewSnapshot alloc] initWithQuery:FSTTestQuery(path)
112+
documents:newDocuments
113+
oldDocuments:oldDocuments
114+
documentChanges:documentChanges
115+
fromCache:fromCache
116+
hasPendingWrites:hasPendingWrites
117+
syncStateChanged:YES];
117118
return [FIRQuerySnapshot snapshotWithFirestore:FSTTestFirestore()
118-
originalQuery:FSTTestQuery(util::MakeStringView(path))
119+
originalQuery:FSTTestQuery(path)
119120
snapshot:viewSnapshot
120121
metadata:metadata];
121122
}

Firestore/Example/Tests/Core/FSTQueryListenerTests.mm

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ - (void)testRaisesCollectionEvents {
4646
NSMutableArray<FSTViewSnapshot *> *otherAccum = [NSMutableArray array];
4747

4848
FSTQuery *query = FSTTestQuery("rooms");
49-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
50-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
49+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
50+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
5151
FSTDocument *doc2prime =
52-
FSTTestDoc(@"rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"}, NO);
52+
FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"}, NO);
5353

5454
FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum];
5555
FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum];
@@ -127,8 +127,8 @@ - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
127127
NSMutableArray<FSTViewSnapshot *> *accum = [NSMutableArray array];
128128

129129
FSTQuery *query = FSTTestQuery("rooms/Eros");
130-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 3, @{@"name" : @"Eros"}, NO);
131-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Eros", 4, @{@"name" : @"Eros2"}, NO);
130+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, NO);
131+
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, NO);
132132

133133
__block FSTAsyncQueryListener *listener = [[FSTAsyncQueryListener alloc]
134134
initWithDispatchQueue:self.asyncQueue
@@ -167,8 +167,8 @@ - (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified {
167167
NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array];
168168

169169
FSTQuery *query = FSTTestQuery("rooms");
170-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
171-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
170+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
171+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
172172

173173
FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
174174
includeDocumentMetadataChanges:NO
@@ -205,10 +205,10 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
205205
NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array];
206206

207207
FSTQuery *query = FSTTestQuery("rooms");
208-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
209-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
210-
FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
211-
FSTDocument *doc3 = FSTTestDoc(@"rooms/Other", 3, @{@"name" : @"Other"}, NO);
208+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
209+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
210+
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
211+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
212212

213213
FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
214214
includeDocumentMetadataChanges:YES
@@ -254,11 +254,11 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
254254
NSMutableArray<FSTViewSnapshot *> *fullAccum = [NSMutableArray array];
255255

256256
FSTQuery *query = FSTTestQuery("rooms");
257-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
258-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, YES);
259-
FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
260-
FSTDocument *doc2Prime = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
261-
FSTDocument *doc3 = FSTTestDoc(@"rooms/Other", 3, @{@"name" : @"Other"}, NO);
257+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
258+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, YES);
259+
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
260+
FSTDocument *doc2Prime = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
261+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
262262

263263
FSTListenOptions *options = [[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:YES
264264
includeDocumentMetadataChanges:NO
@@ -291,10 +291,10 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
291291
NSMutableArray<FSTViewSnapshot *> *filteredAccum = [NSMutableArray array];
292292

293293
FSTQuery *query = FSTTestQuery("rooms");
294-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
295-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
296-
FSTDocument *doc1Prime = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
297-
FSTDocument *doc3 = FSTTestDoc(@"rooms/Other", 3, @{@"name" : @"Other"}, NO);
294+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, YES);
295+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
296+
FSTDocument *doc1Prime = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
297+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, NO);
298298

299299
FSTQueryListener *filteredListener =
300300
[self listenToQuery:query accumulatingSnapshots:filteredAccum];
@@ -323,8 +323,8 @@ - (void)testWillWaitForSyncIfOnline {
323323
NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array];
324324

325325
FSTQuery *query = FSTTestQuery("rooms");
326-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
327-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
326+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
327+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
328328
FSTQueryListener *listener =
329329
[self listenToQuery:query
330330
options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO
@@ -366,8 +366,8 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
366366
NSMutableArray<FSTViewSnapshot *> *events = [NSMutableArray array];
367367

368368
FSTQuery *query = FSTTestQuery("rooms");
369-
FSTDocument *doc1 = FSTTestDoc(@"rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
370-
FSTDocument *doc2 = FSTTestDoc(@"rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
369+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, NO);
370+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, NO);
371371
FSTQueryListener *listener =
372372
[self listenToQuery:query
373373
options:[[FSTListenOptions alloc] initWithIncludeQueryMetadataChanges:NO

0 commit comments

Comments
 (0)