File tree 2 files changed +43
-2
lines changed
Example/Tests/Integration/API 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change @@ -252,6 +252,35 @@ - (void)testQueriesFireFromCacheWhenOffline {
252
252
[registration remove ];
253
253
}
254
254
255
+ - (void )testDocumentChangesUseNSNotFound {
256
+ NSDictionary *testDocs = @{
257
+ @" a" : @{@" foo" : @1 },
258
+ };
259
+ FIRCollectionReference *collection = [self collectionRefWithDocuments: testDocs];
260
+
261
+ id <FIRListenerRegistration> registration =
262
+ [collection addSnapshotListener: self .eventAccumulator.valueEventHandler];
263
+
264
+ FIRQuerySnapshot *querySnap = [self .eventAccumulator awaitEventWithName: @" initial event" ];
265
+ XCTAssertEqual (querySnap.documentChanges .count , 1 );
266
+
267
+ FIRDocumentChange *change = querySnap.documentChanges [0 ];
268
+ XCTAssertEqual (change.oldIndex , NSNotFound );
269
+ XCTAssertEqual (change.newIndex , 0 );
270
+
271
+ FIRDocumentReference *doc = change.document .reference ;
272
+ [self deleteDocumentRef: doc];
273
+
274
+ querySnap = [self .eventAccumulator awaitEventWithName: @" delete" ];
275
+ XCTAssertEqual (querySnap.documentChanges .count , 1 );
276
+
277
+ change = querySnap.documentChanges [0 ];
278
+ XCTAssertEqual (change.oldIndex , 0 );
279
+ XCTAssertEqual (change.newIndex , NSNotFound );
280
+
281
+ [registration remove ];
282
+ }
283
+
255
284
- (void )testCanHaveMultipleMutationsWhileOffline {
256
285
FIRCollectionReference *col = [self collectionRef ];
257
286
Original file line number Diff line number Diff line change 25
25
26
26
NS_ASSUME_NONNULL_BEGIN
27
27
28
+ namespace {
29
+
30
+ /* *
31
+ * Converts from C++ document change indexes to Objective-C document change
32
+ * indexes. Objective-C's NSNotFound is signed NSIntegerMax, not unsigned -1.
33
+ */
34
+ constexpr NSUInteger MakeIndex (size_t index) {
35
+ return index == DocumentChange::npos ? NSNotFound : index ;
36
+ }
37
+
38
+ } // namespace
39
+
28
40
@implementation FIRDocumentChange {
29
41
DocumentChange _documentChange;
30
42
}
@@ -66,11 +78,11 @@ - (FIRQueryDocumentSnapshot *)document {
66
78
}
67
79
68
80
- (NSUInteger )oldIndex {
69
- return _documentChange.old_index ();
81
+ return MakeIndex ( _documentChange.old_index () );
70
82
}
71
83
72
84
- (NSUInteger )newIndex {
73
- return _documentChange.new_index ();
85
+ return MakeIndex ( _documentChange.new_index () );
74
86
}
75
87
76
88
@end
You can’t perform that action at this time.
0 commit comments