aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/Example/Tests/Core/FSTQueryListenerTests.mm')
-rw-r--r--Firestore/Example/Tests/Core/FSTQueryListenerTests.mm57
1 files changed, 32 insertions, 25 deletions
diff --git a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
index 0454152..5629075 100644
--- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
+++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm
@@ -15,6 +15,7 @@
*/
#import <XCTest/XCTest.h>
+#include <memory>
#import "Firestore/Source/Core/FSTEventManager.h"
#import "Firestore/Source/Core/FSTQuery.h"
@@ -23,21 +24,29 @@
#import "Firestore/Source/Model/FSTDocumentSet.h"
#import "Firestore/Source/Remote/FSTRemoteEvent.h"
#import "Firestore/Source/Util/FSTAsyncQueryListener.h"
-#import "Firestore/Source/Util/FSTDispatchQueue.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
+#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h"
+#include "absl/memory/memory.h"
+
+using firebase::firestore::util::internal::ExecutorLibdispatch;
+using firebase::firestore::model::DocumentKeySet;
+
NS_ASSUME_NONNULL_BEGIN
@interface FSTQueryListenerTests : XCTestCase
-@property(nonatomic, strong, readonly) FSTDispatchQueue *asyncQueue;
@end
-@implementation FSTQueryListenerTests
+@implementation FSTQueryListenerTests {
+ std::unique_ptr<ExecutorLibdispatch> _executor;
+}
- (void)setUp {
- _asyncQueue = [FSTDispatchQueue
- queueWith:dispatch_queue_create("FSTQueryListenerTests Queue", DISPATCH_QUEUE_SERIAL)];
+ // TODO(varconst): moving this test to C++, it should be possible to store Executor as a value,
+ // not a pointer, and initialize it in the constructor.
+ _executor = absl::make_unique<ExecutorLibdispatch>(
+ dispatch_queue_create("FSTQueryListenerTests Queue", DISPATCH_QUEUE_SERIAL));
}
- (void)testRaisesCollectionEvents {
@@ -53,7 +62,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum];
FSTQueryListener *otherListener = [self listenToQuery:query accumulatingSnapshots:otherAccum];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2prime ], nil);
@@ -107,7 +116,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryListener *listener = [self listenToQuery:query accumulatingSnapshots:accum];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);
FSTTargetChange *ackTarget =
@@ -129,14 +138,14 @@ NS_ASSUME_NONNULL_BEGIN
FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, NO);
FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, NO);
- __block FSTAsyncQueryListener *listener = [[FSTAsyncQueryListener alloc]
- initWithDispatchQueue:self.asyncQueue
- snapshotHandler:^(FSTViewSnapshot *snapshot, NSError *error) {
- [accum addObject:snapshot];
- [listener mute];
- }];
+ __block FSTAsyncQueryListener *listener =
+ [[FSTAsyncQueryListener alloc] initWithExecutor:_executor.get()
+ snapshotHandler:^(FSTViewSnapshot *snapshot, NSError *error) {
+ [accum addObject:snapshot];
+ [listener mute];
+ }];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
FSTViewSnapshot *viewSnapshot2 = FSTTestApplyChanges(view, @[ doc2 ], nil);
@@ -146,9 +155,7 @@ NS_ASSUME_NONNULL_BEGIN
// Drain queue
XCTestExpectation *expectation = [self expectationWithDescription:@"Queue drained"];
- [self.asyncQueue dispatchAsync:^{
- [expectation fulfill];
- }];
+ _executor->Execute([=] { [expectation fulfill]; });
[self waitForExpectationsWithTimeout:4.0
handler:^(NSError *_Nullable expectationError) {
@@ -178,7 +185,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryListener *fullListener =
[self listenToQuery:query options:options accumulatingSnapshots:fullAccum];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
FSTTargetChange *ackTarget =
@@ -218,7 +225,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryListener *fullListener =
[self listenToQuery:query options:options accumulatingSnapshots:fullAccum];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], nil);
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], nil);
@@ -265,7 +272,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryListener *fullListener =
[self listenToQuery:query options:options accumulatingSnapshots:fullAccum];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime ], nil);
FSTViewSnapshot *snap3 = FSTTestApplyChanges(view, @[ doc3 ], nil);
@@ -298,7 +305,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryListener *filteredListener =
[self listenToQuery:query accumulatingSnapshots:filteredAccum];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1, doc2 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc1Prime, doc3 ], nil);
@@ -331,7 +338,7 @@ NS_ASSUME_NONNULL_BEGIN
waitForSyncWhenOnline:YES]
accumulatingSnapshots:events];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil);
FSTViewSnapshot *snap3 =
@@ -374,7 +381,7 @@ NS_ASSUME_NONNULL_BEGIN
waitForSyncWhenOnline:YES]
accumulatingSnapshots:events];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[ doc1 ], nil);
FSTViewSnapshot *snap2 = FSTTestApplyChanges(view, @[ doc2 ], nil);
@@ -415,7 +422,7 @@ NS_ASSUME_NONNULL_BEGIN
options:[FSTListenOptions defaultOptions]
accumulatingSnapshots:events];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);
[listener applyChangedOnlineState:FSTOnlineStateOnline]; // no event
@@ -441,7 +448,7 @@ NS_ASSUME_NONNULL_BEGIN
options:[FSTListenOptions defaultOptions]
accumulatingSnapshots:events];
- FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:[FSTDocumentKeySet keySet]];
+ FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}];
FSTViewSnapshot *snap1 = FSTTestApplyChanges(view, @[], nil);
[listener applyChangedOnlineState:FSTOnlineStateOffline]; // no event