Skip to content

Commit 1ce982d

Browse files
authored
Port FSTSyncEngine to C++ SyncEngine 2/2 (#3741)
1 parent f0f0aeb commit 1ce982d

File tree

16 files changed

+418
-778
lines changed

16 files changed

+418
-778
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 14 additions & 16 deletions
Large diffs are not rendered by default.

Firestore/Example/Tests/Core/FSTEventManagerTests.mm

Lines changed: 0 additions & 179 deletions
This file was deleted.

Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h

Lines changed: 0 additions & 35 deletions
This file was deleted.

Firestore/Example/Tests/Integration/FSTDatastoreTests.mm

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
using firebase::firestore::remote::GrpcConnection;
6666
using firebase::firestore::remote::RemoteEvent;
6767
using firebase::firestore::remote::RemoteStore;
68+
using firebase::firestore::remote::RemoteStoreCallback;
6869
using firebase::firestore::testutil::Map;
6970
using firebase::firestore::testutil::WrapObject;
7071
using firebase::firestore::util::AsyncQueue;
@@ -75,7 +76,7 @@
7576

7677
#pragma mark - FSTRemoteStoreEventCapture
7778

78-
@interface FSTRemoteStoreEventCapture : NSObject <FSTRemoteSyncer>
79+
@interface FSTRemoteStoreEventCapture : NSObject
7980

8081
- (instancetype)init __attribute__((unavailable("Use initWithTestCase:")));
8182

@@ -153,6 +154,48 @@ - (void)rejectListenWithTargetID:(const TargetId)targetID error:(NSError *)error
153154

154155
@end
155156

157+
class RemoteStoreEventCapture : public RemoteStoreCallback {
158+
public:
159+
explicit RemoteStoreEventCapture(XCTestCase *test_case) {
160+
underlying_capture_ = [[FSTRemoteStoreEventCapture alloc] initWithTestCase:test_case];
161+
}
162+
163+
void ExpectWriteEvent(NSString *description) {
164+
[underlying_capture_ expectWriteEventWithDescription:description];
165+
}
166+
167+
void ExpectListenEvent(NSString *description) {
168+
[underlying_capture_ expectListenEventWithDescription:description];
169+
}
170+
171+
void ApplyRemoteEvent(const RemoteEvent &remote_event) override {
172+
[underlying_capture_ applyRemoteEvent:remote_event];
173+
}
174+
175+
void HandleRejectedListen(TargetId target_id, Status error) override {
176+
[underlying_capture_ rejectListenWithTargetID:target_id error:error.ToNSError()];
177+
}
178+
179+
void HandleSuccessfulWrite(const MutationBatchResult &batch_result) override {
180+
[underlying_capture_ applySuccessfulWriteWithResult:batch_result];
181+
}
182+
183+
void HandleRejectedWrite(BatchId batch_id, Status error) override {
184+
[underlying_capture_ rejectFailedWriteWithBatchID:batch_id error:error.ToNSError()];
185+
}
186+
187+
void HandleOnlineStateChange(OnlineState online_state) override {
188+
HARD_FAIL("Not implemented");
189+
}
190+
191+
model::DocumentKeySet GetRemoteKeys(TargetId target_id) const override {
192+
return [underlying_capture_ remoteKeysForTarget:target_id];
193+
}
194+
195+
private:
196+
FSTRemoteStoreEventCapture *underlying_capture_;
197+
};
198+
156199
#pragma mark - FSTDatastoreTests
157200

158201
@interface FSTDatastoreTests : XCTestCase
@@ -217,10 +260,10 @@ - (void)testCommit {
217260
}
218261

219262
- (void)testStreamingWrite {
220-
FSTRemoteStoreEventCapture *capture = [[FSTRemoteStoreEventCapture alloc] initWithTestCase:self];
221-
[capture expectWriteEventWithDescription:@"write mutations"];
263+
RemoteStoreEventCapture capture = RemoteStoreEventCapture(self);
264+
capture.ExpectWriteEvent(@"write mutations");
222265

223-
_remoteStore->set_sync_engine(capture);
266+
_remoteStore->set_sync_engine(&capture);
224267

225268
auto mutation = testutil::SetMutation("rooms/eros", Map("name", "Eros"));
226269
MutationBatch batch = MutationBatch(23, Timestamp::Now(), {}, {mutation});

0 commit comments

Comments
 (0)