From 4dc63f8d7cbf60417b88c6a77839ea32656627b9 Mon Sep 17 00:00:00 2001 From: Gil Date: Thu, 22 Feb 2018 08:26:22 -0800 Subject: Fix Firestore tests for M22 (#834) * Add FIRFirestoreTests to the Firestore Xcode project * Avoid waitForExpectations:timeout: This API was added in Xcode 8.3, but we still build production releases with Xcode 8.2. waitForExpectationsWithTimeout:handler: is available from Xcode 7.2. * Add AppForUnitTesting Add a utility for constructing a Firebase App for testing. * Handle the nil UID from FIRAuth * Avoid running CMake tests twice * Only build app_testing on Apple platforms * Revise test.sh messages --- .../auth/firebase_credentials_provider_apple.h | 5 +++-- .../auth/firebase_credentials_provider_apple.mm | 3 +-- Firestore/core/src/firebase/firestore/auth/user.h | 20 ++++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) (limited to 'Firestore/core/src/firebase/firestore/auth') diff --git a/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.h b/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.h index 65c4c65..66c3c87 100644 --- a/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.h +++ b/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.h @@ -26,6 +26,7 @@ #include #include // NOLINT(build/c++11) +#include #include "Firestore/core/src/firebase/firestore/auth/credentials_provider.h" #include "Firestore/core/src/firebase/firestore/auth/user.h" @@ -76,8 +77,8 @@ class FirebaseCredentialsProvider : public CredentialsProvider { * avoid races between notifications arriving and C++ object destruction. */ struct Contents { - Contents(FIRApp* app, const absl::string_view uid) - : app(app), current_user(uid), mutex() { + Contents(FIRApp* app, User&& user) + : app(app), current_user(std::move(user)), mutex() { } const FIRApp* app; diff --git a/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm b/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm index f463958..fe3cb24 100644 --- a/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm +++ b/Firestore/core/src/firebase/firestore/auth/firebase_credentials_provider_apple.mm @@ -28,8 +28,7 @@ namespace firestore { namespace auth { FirebaseCredentialsProvider::FirebaseCredentialsProvider(FIRApp* app) - : contents_( - std::make_shared(app, util::MakeStringView([app getUID]))) { + : contents_(std::make_shared(app, User::FromUid([app getUID]))) { std::weak_ptr weak_contents = contents_; auth_listener_handle_ = [[NSNotificationCenter defaultCenter] diff --git a/Firestore/core/src/firebase/firestore/auth/user.h b/Firestore/core/src/firebase/firestore/auth/user.h index cc7b66d..3918c61 100644 --- a/Firestore/core/src/firebase/firestore/auth/user.h +++ b/Firestore/core/src/firebase/firestore/auth/user.h @@ -43,12 +43,6 @@ class User { /** Construct an authenticated user with the given UID. */ explicit User(const absl::string_view uid); -#if defined(__OBJC__) - explicit User(NSString* uid) - : User(firebase::firestore::util::MakeStringView(uid)) { - } -#endif // defined(__OBJC__) - const std::string& uid() const { return uid_; } @@ -62,6 +56,20 @@ class User { /** Returns an unauthenticated instance. */ static const User& Unauthenticated(); +#if defined(__OBJC__) + /** + * Returns an authenticated user if uid is non-nil, otherwise an + * unauthenticated user. + */ + static User FromUid(NSString* _Nullable uid) { + if (uid == nil) { + return Unauthenticated(); + } else { + return User(util::MakeStringView(uid)); + } + } +#endif // defined(__OBJC__) + User& operator=(const User& other) = default; friend bool operator==(const User& lhs, const User& rhs); -- cgit v1.2.3