Skip to content

Commit f08a8bc

Browse files
authored
C++ migration: port FSTTargetChange (#2318)
1 parent 06d9e6d commit f08a8bc

File tree

14 files changed

+306
-321
lines changed

14 files changed

+306
-321
lines changed

Firestore/Example/Tests/Core/FSTQueryListenerTests.mm

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
2929

3030
#include "Firestore/core/src/firebase/firestore/model/types.h"
31+
#include "Firestore/core/src/firebase/firestore/remote/remote_event.h"
3132
#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"
3233
#include "absl/memory/memory.h"
3334

3435
using firebase::firestore::core::DocumentViewChangeType;
3536
using firebase::firestore::model::DocumentKeySet;
3637
using firebase::firestore::model::OnlineState;
38+
using firebase::firestore::remote::TargetChange;
3739
using firebase::firestore::util::ExecutorLibdispatch;
3840

3941
NS_ASSUME_NONNULL_BEGIN
@@ -84,8 +86,8 @@ - (void)testRaisesCollectionEvents {
8486
FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum];
8587

8688
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
87-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
88-
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2prime ], nil);
89+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
90+
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2prime ], absl::nullopt);
8991

9092
FSTDocumentViewChange *change1 =
9193
[FSTDocumentViewChange changeWithDocument:doc1 type:DocumentViewChangeType::kAdded];
@@ -142,7 +144,7 @@ - (void)testRaisesEventForEmptyCollectionAfterSync {
142144
accumulatingSnapshots:accum];
143145

144146
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
145-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);
147+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], absl::nullopt);
146148
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[], FSTTestTargetChangeMarkCurrent());
147149

148150
[listener queryDidChangeViewSnapshot:snap1];
@@ -167,8 +169,8 @@ - (void)testMutingAsyncListenerPreventsAllSubsequentEvents {
167169
}];
168170

169171
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
170-
FSTViewSnapshot *viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
171-
FSTViewSnapshot *viewSnapshot2 = FSTTestApplyChanges(view, @[ doc2 ], nil);
172+
FSTViewSnapshot *viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], absl::nullopt);
173+
FSTViewSnapshot *viewSnapshot2 = FSTTestApplyChanges(view, @[ doc2 ], absl::nullopt);
172174

173175
FSTViewSnapshotHandler handler = listener.asyncSnapshotHandler;
174176
handler(viewSnapshot1, nil);
@@ -204,11 +206,11 @@ - (void)testDoesNotRaiseEventsForMetadataChangesUnlessSpecified {
204206
accumulatingSnapshots:fullAccum];
205207

206208
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
207-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
209+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], absl::nullopt);
208210

209-
FSTTargetChange *ackTarget = FSTTestTargetChangeAckDocuments({doc1.key});
211+
TargetChange ackTarget = FSTTestTargetChangeAckDocuments({doc1.key});
210212
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[], ackTarget);
211-
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc2 ], nil);
213+
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc2 ], absl::nullopt);
212214

213215
[filteredListener queryDidChangeViewSnapshot:snap1]; // local event
214216
[filteredListener queryDidChangeViewSnapshot:snap2]; // no event
@@ -248,9 +250,9 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
248250
accumulatingSnapshots:fullAccum];
249251

250252
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
251-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
252-
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], nil);
253-
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], nil);
253+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
254+
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], absl::nullopt);
255+
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], absl::nullopt);
254256

255257
FSTDocumentViewChange *change1 =
256258
[FSTDocumentViewChange changeWithDocument:doc1 type:DocumentViewChangeType::kAdded];
@@ -303,10 +305,10 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
303305
accumulatingSnapshots:fullAccum];
304306

305307
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
306-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
307-
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], nil);
308-
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], nil);
309-
FSTViewSnapshot *snap4 = FSTTestApplyChanges(view, @[ doc2Prime ], nil);
308+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
309+
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], absl::nullopt);
310+
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], absl::nullopt);
311+
FSTViewSnapshot *snap4 = FSTTestApplyChanges(view, @[ doc2Prime ], absl::nullopt);
310312

311313
[fullListener queryDidChangeViewSnapshot:snap1];
312314
[fullListener queryDidChangeViewSnapshot:snap2]; // Emits no events.
@@ -343,8 +345,8 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
343345
accumulatingSnapshots:filteredAccum];
344346

345347
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
346-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
347-
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime, doc3 ], nil);
348+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
349+
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime, doc3 ], absl::nullopt);
348350

349351
FSTDocumentViewChange *change3 =
350352
[FSTDocumentViewChange changeWithDocument:doc3 type:DocumentViewChangeType::kAdded];
@@ -378,8 +380,8 @@ - (void)testWillWaitForSyncIfOnline {
378380
accumulatingSnapshots:events];
379381

380382
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
381-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
382-
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil);
383+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], absl::nullopt);
384+
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], absl::nullopt);
383385
FSTViewSnapshot *snap3 =
384386
FSTTestApplyChanges(view, @[], FSTTestTargetChangeAckDocuments({doc1.key, doc2.key}));
385387

@@ -420,8 +422,8 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
420422
accumulatingSnapshots:events];
421423

422424
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
423-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
424-
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil);
425+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], absl::nullopt);
426+
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], absl::nullopt);
425427

426428
[listener applyChangedOnlineState:OnlineState::Online]; // no event
427429
[listener queryDidChangeViewSnapshot:snap1]; // no event
@@ -463,7 +465,7 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
463465
accumulatingSnapshots:events];
464466

465467
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
466-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);
468+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], absl::nullopt);
467469

468470
[listener applyChangedOnlineState:OnlineState::Online]; // no event
469471
[listener queryDidChangeViewSnapshot:snap1]; // no event
@@ -490,7 +492,7 @@ - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
490492
accumulatingSnapshots:events];
491493

492494
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
493-
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);
495+
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], absl::nullopt);
494496

495497
[listener applyChangedOnlineState:OnlineState::Offline]; // no event
496498
[listener queryDidChangeViewSnapshot:snap1]; // event

Firestore/Example/Tests/Core/FSTViewTests.mm

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "Firestore/core/src/firebase/firestore/model/resource_path.h"
3232
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
33+
#include "absl/types/optional.h"
3334

3435
namespace testutil = firebase::firestore::testutil;
3536
using firebase::firestore::core::DocumentViewChangeType;
@@ -89,7 +90,7 @@ - (void)testRemovesDocuments {
8990
FSTTestDoc("rooms/eros/messages/3", 0, @{@"text" : @"msg3"}, FSTDocumentStateSynced);
9091

9192
// initial state
92-
FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
93+
FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
9394

9495
// delete doc2, add doc3
9596
FSTViewSnapshot *snapshot =
@@ -120,18 +121,18 @@ - (void)testReturnsNilIfThereAreNoChanges {
120121
FSTTestDoc("rooms/eros/messages/2", 0, @{@"text" : @"msg2"}, FSTDocumentStateSynced);
121122

122123
// initial state
123-
FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
124+
FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
124125

125126
// reapply same docs, no changes
126-
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
127+
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
127128
XCTAssertNil(snapshot);
128129
}
129130

130131
- (void)testDoesNotReturnNilForFirstChanges {
131132
FSTQuery *query = [self queryForMessages];
132133
FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
133134

134-
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[], nil);
135+
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[], absl::nullopt);
135136
XCTAssertNotNil(snapshot);
136137
}
137138

@@ -155,7 +156,8 @@ - (void)testFiltersDocumentsBasedOnQueryWithFilter {
155156
FSTDocument *doc5 =
156157
FSTTestDoc("rooms/eros/messages/5", 0, @{@"sort" : @1}, FSTDocumentStateSynced);
157158

158-
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2, doc3, doc4, doc5 ], nil);
159+
FSTViewSnapshot *snapshot =
160+
FSTTestApplyChanges(view, @[ doc1, doc2, doc3, doc4, doc5 ], absl::nullopt);
159161

160162
XCTAssertEqual(snapshot.query, query);
161163

@@ -189,7 +191,7 @@ - (void)testUpdatesDocumentsBasedOnQueryWithFilter {
189191
FSTTestDoc("rooms/eros/messages/3", 0, @{@"sort" : @2}, FSTDocumentStateSynced);
190192
FSTDocument *doc4 = FSTTestDoc("rooms/eros/messages/4", 0, @{}, FSTDocumentStateSynced);
191193

192-
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2, doc3, doc4 ], nil);
194+
FSTViewSnapshot *snapshot = FSTTestApplyChanges(view, @[ doc1, doc2, doc3, doc4 ], absl::nullopt);
193195

194196
XCTAssertEqual(snapshot.query, query);
195197

@@ -202,7 +204,7 @@ - (void)testUpdatesDocumentsBasedOnQueryWithFilter {
202204
FSTDocument *newDoc4 =
203205
FSTTestDoc("rooms/eros/messages/4", 1, @{@"sort" : @0}, FSTDocumentStateSynced);
204206

205-
snapshot = FSTTestApplyChanges(view, @[ newDoc2, newDoc3, newDoc4 ], nil);
207+
snapshot = FSTTestApplyChanges(view, @[ newDoc2, newDoc3, newDoc4 ], absl::nullopt);
206208

207209
XCTAssertEqual(snapshot.query, query);
208210

@@ -232,7 +234,7 @@ - (void)testRemovesDocumentsForQueryWithLimit {
232234
FSTTestDoc("rooms/eros/messages/3", 0, @{@"text" : @"msg3"}, FSTDocumentStateSynced);
233235

234236
// initial state
235-
FSTTestApplyChanges(view, @[ doc1, doc3 ], nil);
237+
FSTTestApplyChanges(view, @[ doc1, doc3 ], absl::nullopt);
236238

237239
// add doc2, which should push out doc3
238240
FSTViewSnapshot *snapshot = FSTTestApplyChanges(
@@ -269,7 +271,7 @@ - (void)testDoesntReportChangesForDocumentBeyondLimitOfQuery {
269271
FSTTestDoc("rooms/eros/messages/4", 0, @{@"num" : @4}, FSTDocumentStateSynced);
270272

271273
// initial state
272-
FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
274+
FSTTestApplyChanges(view, @[ doc1, doc2 ], absl::nullopt);
273275

274276
// change doc2 to 5, and add doc3 and doc4.
275277
// doc2 will be modified + removed = removed

0 commit comments

Comments
 (0)