aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/SpecTests
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-02-15 17:23:08 -0500
committerGravatar GitHub <noreply@github.com>2018-02-15 17:23:08 -0500
commitfd9fd271d0dba3935a6f5611a1554f2c59b696af (patch)
treebe6d8355254891cb83201c7bfac2082c0f95978f /Firestore/Example/Tests/SpecTests
parent6889850b251ab56186bc13765baee0c3d0f1ae61 (diff)
replacing Auth/FSTUser by C++ auth implementation (#804)
* replacing Auth/FSTUser by C++ auth implementation * address changes
Diffstat (limited to 'Firestore/Example/Tests/SpecTests')
-rw-r--r--Firestore/Example/Tests/SpecTests/FSTSpecTests.mm21
-rw-r--r--Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h20
-rw-r--r--Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm50
3 files changed, 56 insertions, 35 deletions
diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
index 3335990..87e3213 100644
--- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
+++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
@@ -19,7 +19,6 @@
#import <FirebaseFirestore/FIRFirestoreErrors.h>
#import <GRPCClient/GRPCCall.h>
-#import "Firestore/Source/Auth/FSTUser.h"
#import "Firestore/Source/Core/FSTEventManager.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
@@ -43,6 +42,12 @@
#import "Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
+#include "Firestore/core/src/firebase/firestore/auth/user.h"
+#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+
+namespace util = firebase::firestore::util;
+using firebase::firestore::auth::User;
+
NS_ASSUME_NONNULL_BEGIN
// Disables all other tests; useful for debugging. Multiple tests can have this tag and they'll all
@@ -327,15 +332,19 @@ static NSString *const kNoIOSTag = @"no-ios";
}
- (void)doChangeUser:(id)UID {
- FSTUser *user = [UID isEqual:[NSNull null]] ? [FSTUser unauthenticatedUser]
- : [[FSTUser alloc] initWithUID:UID];
- [self.driver changeUser:user];
+ if (UID == nil || [UID isEqual:[NSNull null]]) {
+ [self.driver changeUser:User::Unauthenticated()];
+ } else {
+ XCTAssert([UID isKindOfClass:[NSString class]]);
+ [self.driver changeUser:User(UID)];
+ }
}
- (void)doRestart {
// Any outstanding user writes should be automatically re-sent, so we want to preserve them
// when re-creating the driver.
- FSTOutstandingWriteQueues *outstandingWrites = self.driver.outstandingWrites;
+ FSTOutstandingWriteQueues outstandingWrites = self.driver.outstandingWrites;
+ User currentUser = self.driver.currentUser;
[self.driver shutdown];
@@ -347,7 +356,7 @@ static NSString *const kNoIOSTag = @"no-ios";
self.driver = [[FSTSyncEngineTestDriver alloc] initWithPersistence:self.driverPersistence
garbageCollector:self.garbageCollector
- initialUser:self.driver.currentUser
+ initialUser:currentUser
outstandingWrites:outstandingWrites];
[self.driver start];
}
diff --git a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h
index 46601d7..466a347 100644
--- a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h
+++ b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h
@@ -16,16 +16,19 @@
#import <Foundation/Foundation.h>
+#include <unordered_map>
+
#import "Firestore/Source/Core/FSTTypes.h"
#import "Firestore/Source/Remote/FSTRemoteStore.h"
+#include "Firestore/core/src/firebase/firestore/auth/user.h"
+
@class FSTDocumentKey;
@class FSTMutation;
@class FSTMutationResult;
@class FSTQuery;
@class FSTQueryData;
@class FSTSnapshotVersion;
-@class FSTUser;
@class FSTViewSnapshot;
@class FSTWatchChange;
@protocol FSTGarbageCollector;
@@ -54,7 +57,10 @@ NS_ASSUME_NONNULL_BEGIN
@end
/** Mapping of user => array of FSTMutations for that user. */
-typedef NSDictionary<FSTUser *, NSArray<FSTOutstandingWrite *> *> FSTOutstandingWriteQueues;
+typedef std::unordered_map<firebase::firestore::auth::User,
+ NSMutableArray<FSTOutstandingWrite *> *,
+ firebase::firestore::auth::HashUser>
+ FSTOutstandingWriteQueues;
/**
* A test driver for FSTSyncEngine that allows simulated event delivery and capture. As much as
@@ -93,8 +99,8 @@ typedef NSDictionary<FSTUser *, NSArray<FSTOutstandingWrite *> *> FSTOutstanding
*/
- (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
garbageCollector:(id<FSTGarbageCollector>)garbageCollector
- initialUser:(FSTUser *)initialUser
- outstandingWrites:(FSTOutstandingWriteQueues *)outstandingWrites
+ initialUser:(const firebase::firestore::auth::User &)initialUser
+ outstandingWrites:(const FSTOutstandingWriteQueues &)outstandingWrites
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@@ -222,7 +228,7 @@ typedef NSDictionary<FSTUser *, NSArray<FSTOutstandingWrite *> *> FSTOutstanding
* each user, so future receiveWriteAck/Error operations will validate the write sent to the mock
* datastore matches the next outstanding write for that user.
*/
-- (void)changeUser:(FSTUser *)user;
+- (void)changeUser:(const firebase::firestore::auth::User &)user;
/**
* Returns all query events generated by the FSTSyncEngine in response to the event injection
@@ -246,10 +252,10 @@ typedef NSDictionary<FSTUser *, NSArray<FSTOutstandingWrite *> *> FSTOutstanding
* sentWritesCount, but not necessarily, since the FSTRemoteStore limits the number of
* outstanding writes to the backend at a given time.
*/
-@property(nonatomic, strong, readonly) FSTOutstandingWriteQueues *outstandingWrites;
+@property(nonatomic, assign, readonly) const FSTOutstandingWriteQueues &outstandingWrites;
/** The current user for the FSTSyncEngine; determines which mutation queue is active. */
-@property(nonatomic, strong, readonly) FSTUser *currentUser;
+@property(nonatomic, assign, readonly) const firebase::firestore::auth::User &currentUser;
/** The current set of documents in limbo. */
@property(nonatomic, strong, readonly)
diff --git a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm
index a4de615..1c7eadf 100644
--- a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm
+++ b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm
@@ -16,10 +16,11 @@
#import "Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h"
+#include <unordered_map>
+
#import <FirebaseFirestore/FIRFirestoreErrors.h>
#import <GRPCClient/GRPCCall.h>
-#import "Firestore/Source/Auth/FSTUser.h"
#import "Firestore/Source/Core/FSTEventManager.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Core/FSTSnapshotVersion.h"
@@ -36,6 +37,11 @@
#import "Firestore/Example/Tests/Core/FSTSyncEngine+Testing.h"
#import "Firestore/Example/Tests/SpecTests/FSTMockDatastore.h"
+#include "Firestore/core/src/firebase/firestore/auth/user.h"
+
+using firebase::firestore::auth::HashUser;
+using firebase::firestore::auth::User;
+
NS_ASSUME_NONNULL_BEGIN
@implementation FSTQueryEvent
@@ -71,35 +77,32 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, strong, readonly)
NSMutableDictionary<FSTQuery *, FSTQueryListener *> *queryListeners;
-#pragma mark - Other data structures.
-@property(nonatomic, strong, readwrite) FSTUser *currentUser;
-
@end
@implementation FSTSyncEngineTestDriver {
// ivar is declared as mutable.
- NSMutableDictionary<FSTUser *, NSMutableArray<FSTOutstandingWrite *> *> *_outstandingWrites;
+ std::unordered_map<User, NSMutableArray<FSTOutstandingWrite *> *, HashUser> _outstandingWrites;
+
+ User _currentUser;
}
- (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
garbageCollector:(id<FSTGarbageCollector>)garbageCollector {
return [self initWithPersistence:persistence
garbageCollector:garbageCollector
- initialUser:[FSTUser unauthenticatedUser]
- outstandingWrites:@{}];
+ initialUser:User::Unauthenticated()
+ outstandingWrites:{}];
}
- (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
garbageCollector:(id<FSTGarbageCollector>)garbageCollector
- initialUser:(FSTUser *)initialUser
- outstandingWrites:(FSTOutstandingWriteQueues *)outstandingWrites {
+ initialUser:(const User &)initialUser
+ outstandingWrites:(const FSTOutstandingWriteQueues &)outstandingWrites {
if (self = [super init]) {
- // Create mutable copy of outstandingWrites.
- _outstandingWrites = [NSMutableDictionary dictionary];
- [outstandingWrites enumerateKeysAndObjectsUsingBlock:^(
- FSTUser *user, NSArray<FSTOutstandingWrite *> *writes, BOOL *stop) {
- _outstandingWrites[user] = [writes mutableCopy];
- }];
+ // Do a deep copy.
+ for (const auto &pair : outstandingWrites) {
+ _outstandingWrites[pair.first] = [pair.second mutableCopy];
+ }
_events = [NSMutableArray array];
@@ -139,9 +142,12 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (NSDictionary<FSTUser *, NSMutableArray<FSTOutstandingWrite *> *> *)outstandingWrites {
- return static_cast<NSDictionary<FSTUser *, NSMutableArray<FSTOutstandingWrite *> *> *>(
- _outstandingWrites);
+- (const FSTOutstandingWriteQueues &)outstandingWrites {
+ return _outstandingWrites;
+}
+
+- (const User &)currentUser {
+ return _currentUser;
}
- (void)applyChangedOnlineState:(FSTOnlineState)onlineState {
@@ -200,8 +206,8 @@ NS_ASSUME_NONNULL_BEGIN
[self.remoteStore enableNetwork];
}
-- (void)changeUser:(FSTUser *)user {
- self.currentUser = user;
+- (void)changeUser:(const User &)user {
+ _currentUser = user;
[self.syncEngine userDidChange:user];
}
@@ -309,10 +315,10 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Helper Methods
- (NSMutableArray<FSTOutstandingWrite *> *)currentOutstandingWrites {
- NSMutableArray<FSTOutstandingWrite *> *writes = _outstandingWrites[self.currentUser];
+ NSMutableArray<FSTOutstandingWrite *> *writes = _outstandingWrites[_currentUser];
if (!writes) {
writes = [NSMutableArray array];
- _outstandingWrites[self.currentUser] = writes;
+ _outstandingWrites[_currentUser] = writes;
}
return writes;
}