Skip to content

Commit ffdc328

Browse files
authored
Migrate FSTDocumentState to C++ DocumentState (#3225)
1 parent b645037 commit ffdc328

27 files changed

+497
-478
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,9 +1352,9 @@
13521352
5495EB012040E90200EBA509 /* Codable */ = {
13531353
isa = PBXGroup;
13541354
children = (
1355-
1235769422B86E65007DDFA9 /* FirestoreEncoderTests.swift */,
13561355
5495EB022040E90200EBA509 /* CodableGeoPointTests.swift */,
13571356
7B65C996438B84DBC7616640 /* CodableTimestampTests.swift */,
1357+
1235769422B86E65007DDFA9 /* FirestoreEncoderTests.swift */,
13581358
);
13591359
path = Codable;
13601360
sourceTree = "<group>";
@@ -1392,9 +1392,9 @@
13921392
54C9EDF22040E16300A969CD /* SwiftTests */ = {
13931393
isa = PBXGroup;
13941394
children = (
1395-
620C1427763BA5D3CCFB5A1F /* BridgingHeader.h */,
13961395
544A20ED20F6C046004E52CD /* API */,
13971396
5495EB012040E90200EBA509 /* Codable */,
1397+
620C1427763BA5D3CCFB5A1F /* BridgingHeader.h */,
13981398
54C9EDF52040E16300A969CD /* Info.plist */,
13991399
);
14001400
name = SwiftTests;

Firestore/Example/Tests/API/FIRQuerySnapshotTests.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
using firebase::firestore::model::DocumentComparator;
4646
using firebase::firestore::model::DocumentKeySet;
4747
using firebase::firestore::model::DocumentSet;
48+
using firebase::firestore::model::DocumentState;
4849

4950
NS_ASSUME_NONNULL_BEGIN
5051

@@ -78,11 +79,11 @@ - (void)testEquals {
7879
}
7980

8081
- (void)testIncludeMetadataChanges {
81-
FSTDocument *doc1Old = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, FSTDocumentStateLocalMutations);
82-
FSTDocument *doc1New = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, FSTDocumentStateSynced);
82+
FSTDocument *doc1Old = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, DocumentState::kLocalMutations);
83+
FSTDocument *doc1New = FSTTestDoc("foo/bar", 1, @{@"a" : @"b"}, DocumentState::kSynced);
8384

84-
FSTDocument *doc2Old = FSTTestDoc("foo/baz", 1, @{@"a" : @"b"}, FSTDocumentStateSynced);
85-
FSTDocument *doc2New = FSTTestDoc("foo/baz", 1, @{@"a" : @"c"}, FSTDocumentStateSynced);
85+
FSTDocument *doc2Old = FSTTestDoc("foo/baz", 1, @{@"a" : @"b"}, DocumentState::kSynced);
86+
FSTDocument *doc2New = FSTTestDoc("foo/baz", 1, @{@"a" : @"c"}, DocumentState::kSynced);
8687

8788
DocumentSet oldDocuments = FSTTestDocSet(DocumentComparator::ByKey(), @[ doc1Old, doc2Old ]);
8889
DocumentSet newDocuments = FSTTestDocSet(DocumentComparator::ByKey(), @[ doc2New, doc2New ]);

Firestore/Example/Tests/API/FSTAPIHelpers.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#import "Firestore/Source/Model/FSTDocument.h"
3535

3636
#include "Firestore/core/src/firebase/firestore/core/view_snapshot.h"
37+
#include "Firestore/core/src/firebase/firestore/model/document.h"
3738
#include "Firestore/core/src/firebase/firestore/model/document_set.h"
3839
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
3940
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
@@ -47,6 +48,7 @@
4748
using firebase::firestore::model::DocumentComparator;
4849
using firebase::firestore::model::DocumentKeySet;
4950
using firebase::firestore::model::DocumentSet;
51+
using firebase::firestore::model::DocumentState;
5052

5153
NS_ASSUME_NONNULL_BEGIN
5254

@@ -74,7 +76,7 @@
7476
BOOL fromCache) {
7577
FSTDocument *doc =
7678
data ? FSTTestDoc(path, version, data,
77-
hasMutations ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced)
79+
hasMutations ? DocumentState::kLocalMutations : DocumentState::kSynced)
7880
: nil;
7981
return [[FIRDocumentSnapshot alloc] initWithFirestore:FSTTestFirestore().wrapped
8082
documentKey:testutil::Key(path)
@@ -106,7 +108,7 @@
106108
for (NSString *key in oldDocs) {
107109
oldDocuments = oldDocuments.insert(
108110
FSTTestDoc(util::StringFormat("%s/%s", path, key), 1, oldDocs[key],
109-
hasPendingWrites ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced));
111+
hasPendingWrites ? DocumentState::kLocalMutations : DocumentState::kSynced));
110112
if (hasPendingWrites) {
111113
const std::string documentKey = util::StringFormat("%s/%s", path, key);
112114
mutatedKeys = mutatedKeys.insert(testutil::Key(documentKey));
@@ -117,7 +119,7 @@
117119
for (NSString *key in docsToAdd) {
118120
FSTDocument *docToAdd =
119121
FSTTestDoc(util::StringFormat("%s/%s", path, key), 1, docsToAdd[key],
120-
hasPendingWrites ? FSTDocumentStateLocalMutations : FSTDocumentStateSynced);
122+
hasPendingWrites ? DocumentState::kLocalMutations : DocumentState::kSynced);
121123
newDocuments = newDocuments.insert(docToAdd);
122124
documentChanges.emplace_back(docToAdd, DocumentViewChange::Type::kAdded);
123125
if (hasPendingWrites) {

Firestore/Example/Tests/Core/FSTQueryListenerTests.mm

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
using firebase::firestore::core::ViewSnapshot;
5050
using firebase::firestore::model::DocumentKeySet;
5151
using firebase::firestore::model::DocumentSet;
52+
using firebase::firestore::model::DocumentState;
5253
using firebase::firestore::model::OnlineState;
5354
using firebase::firestore::remote::TargetChange;
5455
using firebase::firestore::util::DelayedConstructor;
@@ -103,10 +104,10 @@ - (void)testRaisesCollectionEvents {
103104
std::vector<ViewSnapshot> otherAccum;
104105

105106
FSTQuery *query = FSTTestQuery("rooms");
106-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
107-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
107+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
108+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
108109
FSTDocument *doc2prime = FSTTestDoc("rooms/Hades", 3, @{@"name" : @"Hades", @"owner" : @"Jonny"},
109-
FSTDocumentStateSynced);
110+
DocumentState::kSynced);
110111

111112
auto listener = QueryListener::Create(query, _includeMetadataChanges, Accumulating(&accum));
112113
auto otherListener = QueryListener::Create(query, Accumulating(&otherAccum));
@@ -174,8 +175,8 @@ - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
174175
std::vector<ViewSnapshot> accum;
175176

176177
FSTQuery *query = FSTTestQuery("rooms/Eros");
177-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
178-
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, FSTDocumentStateSynced);
178+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, DocumentState::kSynced);
179+
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, DocumentState::kSynced);
179180

180181
std::shared_ptr<AsyncEventListener<ViewSnapshot>> listener =
181182
AsyncEventListener<ViewSnapshot>::Create(
@@ -212,8 +213,8 @@ - (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified {
212213
std::vector<ViewSnapshot> fullAccum;
213214

214215
FSTQuery *query = FSTTestQuery("rooms");
215-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
216-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
216+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
217+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
217218

218219
auto filteredListener = QueryListener::Create(query, Accumulating(&filteredAccum));
219220
auto fullListener =
@@ -245,11 +246,11 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
245246

246247
FSTQuery *query = FSTTestQuery("rooms");
247248
FSTDocument *doc1 =
248-
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
249-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
249+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kLocalMutations);
250+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
250251
FSTDocument *doc1Prime =
251-
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
252-
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);
252+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
253+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, DocumentState::kSynced);
253254

254255
ListenOptions options(
255256
/*include_query_metadata_changes=*/false,
@@ -292,14 +293,14 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
292293

293294
FSTQuery *query = FSTTestQuery("rooms");
294295
FSTDocument *doc1 =
295-
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
296+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kLocalMutations);
296297
FSTDocument *doc2 =
297-
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateLocalMutations);
298+
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kLocalMutations);
298299
FSTDocument *doc1Prime =
299-
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
300+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
300301
FSTDocument *doc2Prime =
301-
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
302-
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);
302+
FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
303+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, DocumentState::kSynced);
303304

304305
ListenOptions options(
305306
/*include_query_metadata_changes=*/true,
@@ -338,11 +339,11 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
338339

339340
FSTQuery *query = FSTTestQuery("rooms");
340341
FSTDocument *doc1 =
341-
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateLocalMutations);
342-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
342+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kLocalMutations);
343+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
343344
FSTDocument *doc1Prime =
344-
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
345-
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, FSTDocumentStateSynced);
345+
FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
346+
FSTDocument *doc3 = FSTTestDoc("rooms/Other", 3, @{@"name" : @"Other"}, DocumentState::kSynced);
346347

347348
auto filteredListener = QueryListener::Create(query, Accumulating(&filteredAccum));
348349

@@ -370,8 +371,8 @@ - (void)testWillWaitForSyncIfOnline {
370371
std::vector<ViewSnapshot> events;
371372

372373
FSTQuery *query = FSTTestQuery("rooms");
373-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
374-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
374+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
375+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
375376

376377
ListenOptions options(
377378
/*include_query_metadata_changes=*/false,
@@ -409,8 +410,8 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
409410
std::vector<ViewSnapshot> events;
410411

411412
FSTQuery *query = FSTTestQuery("rooms");
412-
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, FSTDocumentStateSynced);
413-
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, FSTDocumentStateSynced);
413+
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 1, @{@"name" : @"Eros"}, DocumentState::kSynced);
414+
FSTDocument *doc2 = FSTTestDoc("rooms/Hades", 2, @{@"name" : @"Hades"}, DocumentState::kSynced);
414415

415416
ListenOptions options(
416417
/*include_query_metadata_changes=*/false,

0 commit comments

Comments
 (0)