15
15
*/
16
16
17
17
#import < XCTest/XCTest.h>
18
+
18
19
#include < memory>
20
+ #include < vector>
19
21
20
22
#import " Firestore/Source/Core/FSTEventManager.h"
21
23
#import " Firestore/Source/Core/FSTQuery.h"
26
28
27
29
#import " Firestore/Example/Tests/Util/FSTHelpers.h"
28
30
31
+ #include " Firestore/core/src/firebase/firestore/core/view_snapshot.h"
29
32
#include " Firestore/core/src/firebase/firestore/model/types.h"
30
33
#include " Firestore/core/src/firebase/firestore/remote/remote_event.h"
31
34
#include " Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"
32
35
#include " absl/memory/memory.h"
33
36
34
- using firebase::firestore::core::DocumentViewChangeType ;
37
+ using firebase::firestore::core::DocumentViewChange ;
35
38
using firebase::firestore::model::DocumentKeySet;
36
39
using firebase::firestore::model::OnlineState;
37
40
using firebase::firestore::remote::TargetChange;
@@ -88,28 +91,24 @@ - (void)testRaisesCollectionEvents {
88
91
FSTViewSnapshot *snap1 = FSTTestApplyChanges (view, @[ doc1, doc2 ], absl::nullopt);
89
92
FSTViewSnapshot *snap2 = FSTTestApplyChanges (view, @[ doc2prime ], absl::nullopt);
90
93
91
- FSTDocumentViewChange *change1 =
92
- [FSTDocumentViewChange changeWithDocument: doc1 type:DocumentViewChangeType: :kAdded ];
93
- FSTDocumentViewChange *change2 =
94
- [FSTDocumentViewChange changeWithDocument: doc2 type:DocumentViewChangeType: :kAdded ];
95
- FSTDocumentViewChange *change3 =
96
- [FSTDocumentViewChange changeWithDocument: doc2prime type:DocumentViewChangeType: :kModified ];
97
- FSTDocumentViewChange *change4 =
98
- [FSTDocumentViewChange changeWithDocument: doc2prime type:DocumentViewChangeType: :kAdded ];
94
+ DocumentViewChange change1{doc1, DocumentViewChange::Type::kAdded };
95
+ DocumentViewChange change2{doc2, DocumentViewChange::Type::kAdded };
96
+ DocumentViewChange change3{doc2prime, DocumentViewChange::Type::kModified };
97
+ DocumentViewChange change4{doc2prime, DocumentViewChange::Type::kAdded };
99
98
100
99
[listener queryDidChangeViewSnapshot: snap1];
101
100
[listener queryDidChangeViewSnapshot: snap2];
102
101
[otherListener queryDidChangeViewSnapshot: snap2];
103
102
104
103
XCTAssertEqualObjects (accum, (@[ snap1, snap2 ]));
105
- XCTAssertEqualObjects ( accum[0 ].documentChanges , (@[ change1, change2 ] ));
106
- XCTAssertEqualObjects (accum[1 ].documentChanges , (@[ change3 ]) );
104
+ XCTAssertTrue (( accum[0 ].documentChanges == std::vector<DocumentViewChange>{ change1, change2} ));
105
+ XCTAssertTrue (accum[1 ].documentChanges == std::vector<DocumentViewChange>{ change3} );
107
106
108
107
FSTViewSnapshot *expectedSnap2 = [[FSTViewSnapshot alloc ]
109
108
initWithQuery: snap2.query
110
109
documents: snap2.documents
111
110
oldDocuments: [FSTDocumentSet documentSetWithComparator: snap2.query.comparator]
112
- documentChanges: @[ change1, change4 ]
111
+ documentChanges: { change1, change4}
113
112
fromCache: snap2.fromCache
114
113
mutatedKeys: snap2.mutatedKeys
115
114
syncStateChanged: YES
@@ -253,14 +252,10 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
253
252
FSTViewSnapshot *snap2 = FSTTestApplyChanges (view, @[ doc1Prime ], absl::nullopt);
254
253
FSTViewSnapshot *snap3 = FSTTestApplyChanges (view, @[ doc3 ], absl::nullopt);
255
254
256
- FSTDocumentViewChange *change1 =
257
- [FSTDocumentViewChange changeWithDocument: doc1 type:DocumentViewChangeType: :kAdded ];
258
- FSTDocumentViewChange *change2 =
259
- [FSTDocumentViewChange changeWithDocument: doc2 type:DocumentViewChangeType: :kAdded ];
260
- FSTDocumentViewChange *change3 =
261
- [FSTDocumentViewChange changeWithDocument: doc1Prime type:DocumentViewChangeType: :kMetadata ];
262
- FSTDocumentViewChange *change4 =
263
- [FSTDocumentViewChange changeWithDocument: doc3 type:DocumentViewChangeType: :kAdded ];
255
+ DocumentViewChange change1{doc1, DocumentViewChange::Type::kAdded };
256
+ DocumentViewChange change2{doc2, DocumentViewChange::Type::kAdded };
257
+ DocumentViewChange change3{doc1Prime, DocumentViewChange::Type::kMetadata };
258
+ DocumentViewChange change4{doc3, DocumentViewChange::Type::kAdded };
264
259
265
260
[filteredListener queryDidChangeViewSnapshot: snap1];
266
261
[filteredListener queryDidChangeViewSnapshot: snap2];
@@ -273,13 +268,15 @@ - (void)testRaisesDocumentMetadataEventsOnlyWhenSpecified {
273
268
[self setExcludesMetadataChanges: YES snapshot: snap1],
274
269
[self setExcludesMetadataChanges: YES snapshot: snap3]
275
270
]));
276
- XCTAssertEqualObjects (filteredAccum[0 ].documentChanges , (@[ change1, change2 ]));
277
- XCTAssertEqualObjects (filteredAccum[1 ].documentChanges , (@[ change4 ]));
271
+ XCTAssertTrue (
272
+ (filteredAccum[0 ].documentChanges == std::vector<DocumentViewChange>{change1, change2}));
273
+ XCTAssertTrue ((filteredAccum[1 ].documentChanges == std::vector<DocumentViewChange>{change4}));
278
274
279
275
XCTAssertEqualObjects (fullAccum, (@[ snap1, snap2, snap3 ]));
280
- XCTAssertEqualObjects (fullAccum[0 ].documentChanges , (@[ change1, change2 ]));
281
- XCTAssertEqualObjects (fullAccum[1 ].documentChanges , (@[ change3 ]));
282
- XCTAssertEqualObjects (fullAccum[2 ].documentChanges , (@[ change4 ]));
276
+ XCTAssertTrue (
277
+ (fullAccum[0 ].documentChanges == std::vector<DocumentViewChange>{change1, change2}));
278
+ XCTAssertTrue ((fullAccum[1 ].documentChanges == std::vector<DocumentViewChange>{change3}));
279
+ XCTAssertTrue ((fullAccum[2 ].documentChanges == std::vector<DocumentViewChange>{change4}));
283
280
}
284
281
285
282
- (void )testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
@@ -318,7 +315,7 @@ - (void)testRaisesQueryMetadataEventsOnlyWhenHasPendingWritesOnTheQueryChanges {
318
315
[[FSTViewSnapshot alloc ] initWithQuery: snap4.query
319
316
documents: snap4.documents
320
317
oldDocuments: snap3.documents
321
- documentChanges: @[]
318
+ documentChanges: {}
322
319
fromCache: snap4.fromCache
323
320
mutatedKeys: snap4.mutatedKeys
324
321
syncStateChanged: snap4.syncStateChanged
@@ -347,16 +344,15 @@ - (void)testMetadataOnlyDocumentChangesAreFilteredOutWhenIncludeDocumentMetadata
347
344
FSTViewSnapshot *snap1 = FSTTestApplyChanges (view, @[ doc1, doc2 ], absl::nullopt);
348
345
FSTViewSnapshot *snap2 = FSTTestApplyChanges (view, @[ doc1Prime, doc3 ], absl::nullopt);
349
346
350
- FSTDocumentViewChange *change3 =
351
- [FSTDocumentViewChange changeWithDocument: doc3 type:DocumentViewChangeType: :kAdded ];
347
+ DocumentViewChange change3{doc3, DocumentViewChange::Type::kAdded };
352
348
353
349
[filteredListener queryDidChangeViewSnapshot: snap1];
354
350
[filteredListener queryDidChangeViewSnapshot: snap2];
355
351
356
352
FSTViewSnapshot *expectedSnap2 = [[FSTViewSnapshot alloc ] initWithQuery: snap2.query
357
353
documents: snap2.documents
358
354
oldDocuments: snap1.documents
359
- documentChanges: @[ change3 ]
355
+ documentChanges: { change3}
360
356
fromCache: snap2.isFromCache
361
357
mutatedKeys: snap2.mutatedKeys
362
358
syncStateChanged: snap2.syncStateChanged
@@ -391,15 +387,13 @@ - (void)testWillWaitForSyncIfOnline {
391
387
[listener queryDidChangeViewSnapshot: snap2];
392
388
[listener queryDidChangeViewSnapshot: snap3];
393
389
394
- FSTDocumentViewChange *change1 =
395
- [FSTDocumentViewChange changeWithDocument: doc1 type:DocumentViewChangeType: :kAdded ];
396
- FSTDocumentViewChange *change2 =
397
- [FSTDocumentViewChange changeWithDocument: doc2 type:DocumentViewChangeType: :kAdded ];
390
+ DocumentViewChange change1{doc1, DocumentViewChange::Type::kAdded };
391
+ DocumentViewChange change2{doc2, DocumentViewChange::Type::kAdded };
398
392
FSTViewSnapshot *expectedSnap = [[FSTViewSnapshot alloc ]
399
393
initWithQuery: snap3.query
400
394
documents: snap3.documents
401
395
oldDocuments: [FSTDocumentSet documentSetWithComparator: snap3.query.comparator]
402
- documentChanges: @[ change1, change2 ]
396
+ documentChanges: { change1, change2}
403
397
fromCache: NO
404
398
mutatedKeys: snap3.mutatedKeys
405
399
syncStateChanged: YES
@@ -431,23 +425,21 @@ - (void)testWillRaiseInitialEventWhenGoingOffline {
431
425
[listener applyChangedOnlineState: OnlineState: :Offline]; // no event
432
426
[listener queryDidChangeViewSnapshot: snap2]; // another event
433
427
434
- FSTDocumentViewChange *change1 =
435
- [FSTDocumentViewChange changeWithDocument: doc1 type:DocumentViewChangeType: :kAdded ];
436
- FSTDocumentViewChange *change2 =
437
- [FSTDocumentViewChange changeWithDocument: doc2 type:DocumentViewChangeType: :kAdded ];
428
+ DocumentViewChange change1{doc1, DocumentViewChange::Type::kAdded };
429
+ DocumentViewChange change2{doc2, DocumentViewChange::Type::kAdded };
438
430
FSTViewSnapshot *expectedSnap1 = [[FSTViewSnapshot alloc ]
439
431
initWithQuery: query
440
432
documents: snap1.documents
441
433
oldDocuments: [FSTDocumentSet documentSetWithComparator: snap1.query.comparator]
442
- documentChanges: @[ change1 ]
434
+ documentChanges: { change1}
443
435
fromCache: YES
444
436
mutatedKeys: snap1.mutatedKeys
445
437
syncStateChanged: YES
446
438
excludesMetadataChanges: YES ];
447
439
FSTViewSnapshot *expectedSnap2 = [[FSTViewSnapshot alloc ] initWithQuery: query
448
440
documents: snap2.documents
449
441
oldDocuments: snap1.documents
450
- documentChanges: @[ change2 ]
442
+ documentChanges: { change2}
451
443
fromCache: YES
452
444
mutatedKeys: snap2.mutatedKeys
453
445
syncStateChanged: NO
@@ -474,7 +466,7 @@ - (void)testWillRaiseInitialEventWhenGoingOfflineAndThereAreNoDocs {
474
466
initWithQuery: query
475
467
documents: snap1.documents
476
468
oldDocuments: [FSTDocumentSet documentSetWithComparator: snap1.query.comparator]
477
- documentChanges: @[]
469
+ documentChanges: {}
478
470
fromCache: YES
479
471
mutatedKeys: snap1.mutatedKeys
480
472
syncStateChanged: YES
@@ -500,7 +492,7 @@ - (void)testWillRaiseInitialEventWhenStartingOfflineAndThereAreNoDocs {
500
492
initWithQuery: query
501
493
documents: snap1.documents
502
494
oldDocuments: [FSTDocumentSet documentSetWithComparator: snap1.query.comparator]
503
- documentChanges: @[]
495
+ documentChanges: {}
504
496
fromCache: YES
505
497
mutatedKeys: snap1.mutatedKeys
506
498
syncStateChanged: YES
0 commit comments