16
16
17
17
#import " Firestore/Example/Tests/Local/FSTRemoteDocumentCacheTests.h"
18
18
19
+ #include < memory>
20
+
19
21
#import " Firestore/Source/Core/FSTQuery.h"
20
22
#import " Firestore/Source/Local/FSTPersistence.h"
21
23
#import " Firestore/Source/Model/FSTDocument.h"
22
24
#import " Firestore/Source/Model/FSTDocumentSet.h"
23
25
24
26
#import " Firestore/Example/Tests/Util/FSTHelpers.h"
25
27
28
+ #include " Firestore/core/src/firebase/firestore/local/memory_remote_document_cache.h"
29
+ #include " Firestore/core/src/firebase/firestore/local/remote_document_cache.h"
26
30
#include " Firestore/core/src/firebase/firestore/model/document_key.h"
27
31
#include " Firestore/core/src/firebase/firestore/model/document_key_set.h"
28
32
#include " Firestore/core/src/firebase/firestore/model/document_map.h"
32
36
33
37
namespace testutil = firebase::firestore::testutil;
34
38
namespace util = firebase::firestore::util;
39
+ using firebase::firestore::local::RemoteDocumentCache;
35
40
using firebase::firestore::model::DocumentKey;
36
41
using firebase::firestore::model::DocumentKeySet;
37
42
using firebase::firestore::model::DocumentMap;
@@ -62,15 +67,15 @@ - (void)testReadDocumentNotInCache {
62
67
if (!self.remoteDocumentCache ) return ;
63
68
64
69
self.persistence .run (" testReadDocumentNotInCache" , [&]() {
65
- XCTAssertNil ([ self .remoteDocumentCache entryForKey: testutil: :Key (kDocPath )] );
70
+ XCTAssertNil (self.remoteDocumentCache -> Get ( testutil::Key (kDocPath )) );
66
71
});
67
72
}
68
73
69
74
// Helper for next two tests.
70
75
- (void )setAndReadADocumentAtPath : (const absl::string_view)path {
71
76
self.persistence .run (" setAndReadADocumentAtPath" , [&]() {
72
77
FSTDocument *written = [self setTestDocumentAtPath: path];
73
- FSTMaybeDocument *read = [ self .remoteDocumentCache entryForKey: testutil: :Key (path)] ;
78
+ FSTMaybeDocument *read = self.remoteDocumentCache -> Get ( testutil::Key (path)) ;
74
79
XCTAssertEqualObjects (read , written);
75
80
});
76
81
}
@@ -87,8 +92,8 @@ - (void)testSetAndReadSeveralDocuments {
87
92
self.persistence .run (" testSetAndReadSeveralDocuments" , [=]() {
88
93
NSArray <FSTDocument *> *written =
89
94
@[ [self setTestDocumentAtPath: kDocPath ], [self setTestDocumentAtPath: kLongDocPath ] ];
90
- MaybeDocumentMap read = [ self .remoteDocumentCache
91
- entriesForKeys: DocumentKeySet{testutil::Key (kDocPath ), testutil::Key (kLongDocPath )}] ;
95
+ MaybeDocumentMap read = self.remoteDocumentCache -> GetAll (
96
+ DocumentKeySet{testutil::Key (kDocPath ), testutil::Key (kLongDocPath )}) ;
92
97
[self expectMap: read hasDocsInArray: written exactly: YES ];
93
98
});
94
99
}
@@ -99,12 +104,11 @@ - (void)testSetAndReadSeveralDocumentsIncludingMissingDocument {
99
104
self.persistence .run (" testSetAndReadSeveralDocumentsIncludingMissingDocument" , [=]() {
100
105
NSArray <FSTDocument *> *written =
101
106
@[ [self setTestDocumentAtPath: kDocPath ], [self setTestDocumentAtPath: kLongDocPath ] ];
102
- MaybeDocumentMap read =
103
- [self .remoteDocumentCache entriesForKeys: DocumentKeySet{
104
- testutil::Key (kDocPath ),
105
- testutil::Key (kLongDocPath ),
106
- testutil::Key (" foo/nonexistent" ),
107
- }];
107
+ MaybeDocumentMap read = self.remoteDocumentCache ->GetAll (DocumentKeySet{
108
+ testutil::Key (kDocPath ),
109
+ testutil::Key (kLongDocPath ),
110
+ testutil::Key (" foo/nonexistent" ),
111
+ });
108
112
[self expectMap: read hasDocsInArray: written exactly: NO ];
109
113
auto found = read .find (DocumentKey::FromPathString (" foo/nonexistent" ));
110
114
XCTAssertTrue (found != read .end ());
@@ -123,10 +127,9 @@ - (void)testSetAndReadDeletedDocument {
123
127
124
128
self.persistence .run (" testSetAndReadDeletedDocument" , [&]() {
125
129
FSTDeletedDocument *deletedDoc = FSTTestDeletedDoc (kDocPath , kVersion , NO );
126
- [ self .remoteDocumentCache addEntry: deletedDoc] ;
130
+ self.remoteDocumentCache -> AddEntry ( deletedDoc) ;
127
131
128
- XCTAssertEqualObjects ([self .remoteDocumentCache entryForKey: testutil: :Key (kDocPath )],
129
- deletedDoc);
132
+ XCTAssertEqualObjects (self.remoteDocumentCache ->Get (testutil::Key (kDocPath )), deletedDoc);
130
133
});
131
134
}
132
135
@@ -136,8 +139,8 @@ - (void)testSetDocumentToNewValue {
136
139
self.persistence .run (" testSetDocumentToNewValue" , [&]() {
137
140
[self setTestDocumentAtPath: kDocPath ];
138
141
FSTDocument *newDoc = FSTTestDoc (kDocPath , kVersion , @{@" data" : @2 }, FSTDocumentStateSynced);
139
- [ self .remoteDocumentCache addEntry: newDoc] ;
140
- XCTAssertEqualObjects ([ self .remoteDocumentCache entryForKey: testutil: :Key (kDocPath )] , newDoc);
142
+ self.remoteDocumentCache -> AddEntry ( newDoc) ;
143
+ XCTAssertEqualObjects (self.remoteDocumentCache -> Get ( testutil::Key (kDocPath )) , newDoc);
141
144
});
142
145
}
143
146
@@ -146,9 +149,9 @@ - (void)testRemoveDocument {
146
149
147
150
self.persistence .run (" testRemoveDocument" , [&]() {
148
151
[self setTestDocumentAtPath: kDocPath ];
149
- [ self .remoteDocumentCache removeEntryForKey: testutil: :Key (kDocPath )] ;
152
+ self.remoteDocumentCache -> RemoveEntry ( testutil::Key (kDocPath )) ;
150
153
151
- XCTAssertNil ([ self .remoteDocumentCache entryForKey: testutil: :Key (kDocPath )] );
154
+ XCTAssertNil (self.remoteDocumentCache -> Get ( testutil::Key (kDocPath )) );
152
155
});
153
156
}
154
157
@@ -157,7 +160,7 @@ - (void)testRemoveNonExistentDocument {
157
160
158
161
self.persistence .run (" testRemoveNonExistentDocument" , [&]() {
159
162
// no-op, but make sure it doesn't throw.
160
- XCTAssertNoThrow ([ self .remoteDocumentCache removeEntryForKey: testutil: :Key (kDocPath )] );
163
+ XCTAssertNoThrow (self.remoteDocumentCache -> RemoveEntry ( testutil::Key (kDocPath )) );
161
164
});
162
165
}
163
166
@@ -174,7 +177,7 @@ - (void)testDocumentsMatchingQuery {
174
177
[self setTestDocumentAtPath: " c/1" ];
175
178
176
179
FSTQuery *query = FSTTestQuery (" b" );
177
- DocumentMap results = [ self .remoteDocumentCache documentsMatchingQuery: query] ;
180
+ DocumentMap results = self.remoteDocumentCache -> GetMatchingDocuments ( query) ;
178
181
[self expectMap: results.underlying_map ()
179
182
hasDocsInArray: @[
180
183
FSTTestDoc (" b/1" , kVersion , _kDocData, FSTDocumentStateSynced),
@@ -189,7 +192,7 @@ - (void)testDocumentsMatchingQuery {
189
192
190
193
- (FSTDocument *)setTestDocumentAtPath : (const absl::string_view)path {
191
194
FSTDocument *doc = FSTTestDoc (path, kVersion , _kDocData, FSTDocumentStateSynced);
192
- [ self .remoteDocumentCache addEntry: doc] ;
195
+ self.remoteDocumentCache -> AddEntry ( doc) ;
193
196
return doc;
194
197
}
195
198
0 commit comments