Skip to content

Remove STLPort support from public API. #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ if (IOS)
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_change.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_reference.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_snapshot.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/event_listener.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/field_path.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/field_value.h
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/listener_registration.h
Expand Down
4 changes: 0 additions & 4 deletions firestore/integration_test/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,6 @@ TEST_F(FirebaseFirestoreBasicTest, TestSetDelete) {
}

TEST_F(FirebaseFirestoreBasicTest, TestDocumentListener) {
SKIP_TEST_IF_USING_STLPORT; // STLPort uses EventListener<T> rather than
// std::function.
#if !defined(STLPORT)
SignIn();

firebase::firestore::DocumentReference document = Doc();
Expand Down Expand Up @@ -487,7 +484,6 @@ TEST_F(FirebaseFirestoreBasicTest, TestDocumentListener) {
{"val", firebase::firestore::FieldValue::String("start")}},
firebase::firestore::MapFieldValue{
{"val", firebase::firestore::FieldValue::String("update")}}));
#endif // !defined(STLPORT)
}

TEST_F(FirebaseFirestoreBasicTest, TestBatchWrite) {
Expand Down
10 changes: 0 additions & 10 deletions firestore/integration_test_internal/src/cleanup_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,8 @@ void ExpectAllMethodsAreNoOps(DocumentReference* ptr) {

EXPECT_TRUE(ptr->Delete() == FailedFuture<void>());

#if defined(FIREBASE_USE_STD_FUNCTION)
ptr->AddSnapshotListener(
[](const DocumentSnapshot&, Error, const std::string&) {});
#else
ptr->AddSnapshotListener(nullptr);
#endif
}

void ExpectAllMethodsAreNoOps(DocumentSnapshot* ptr) {
Expand Down Expand Up @@ -217,12 +213,8 @@ void ExpectAllMethodsAreNoOps(Query* ptr) {

EXPECT_TRUE(ptr->Get() == FailedFuture<QuerySnapshot>());

#if defined(FIREBASE_USE_STD_FUNCTION)
ptr->AddSnapshotListener(
[](const QuerySnapshot&, Error, const std::string&) {});
#else
ptr->AddSnapshotListener(nullptr);
#endif
}

void ExpectAllMethodsAreNoOps(QuerySnapshot* ptr) {
Expand Down Expand Up @@ -360,7 +352,6 @@ TEST_F(CleanupTest, FieldValueIsBlankAfterCleanup) {
// after cleanup. Thus, there is no case where a user could be accessing
// a "blank" Firestore instance.

#if defined(FIREBASE_USE_STD_FUNCTION)
TEST_F(CleanupTest, ListenerRegistrationIsBlankAfterCleanup) {
{
ListenerRegistration default_constructed;
Expand All @@ -375,7 +366,6 @@ TEST_F(CleanupTest, ListenerRegistrationIsBlankAfterCleanup) {
SCOPED_TRACE("ListenerRegistration.AfterCleanup");
ExpectAllMethodsAreNoOps(&reg);
}
#endif

// Note: `Query` cleanup is tested as part of `CollectionReference` cleanup
// (`CollectionReference` is derived from `Query`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ class EventAccumulator;
// An EventListener class for writing tests. This listener counts the number of
// events as well as keeps track of the last result.
template <typename T>
class TestEventListener : public EventListener<T> {
class TestEventListener {
public:
explicit TestEventListener(std::string name) : name_(std::move(name)) {}

~TestEventListener() override {}
virtual ~TestEventListener() {}

void OnEvent(const T& value,
Error error_code,
const std::string& error_message) override {
virtual void OnEvent(const T& value,
Error error_code,
const std::string& error_message) {
if (print_debug_info_) {
std::cout << "TestEventListener got: ";
if (error_code == Error::kErrorOk) {
Expand Down Expand Up @@ -110,20 +110,14 @@ class TestEventListener : public EventListener<T> {
return last_results_[last_results_.size() - 1 - i];
}

// Hides the STLPort-related quirk that `AddSnapshotListener` has different
// signatures depending on whether `std::function` is available.
template <typename U>
ListenerRegistration AttachTo(
U* ref, MetadataChanges metadata_changes = MetadataChanges::kExclude) {
#if defined(FIREBASE_USE_STD_FUNCTION)
return ref->AddSnapshotListener(
metadata_changes, [this](const T& result, Error error_code,
const std::string& error_message) {
OnEvent(result, error_code, error_message);
});
#else
return ref->AddSnapshotListener(metadata_changes, this);
#endif
}

std::string first_error_message() {
Expand Down
18 changes: 0 additions & 18 deletions firestore/integration_test_internal/src/firestore_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,26 +671,10 @@ TEST_F(FirestoreIntegrationTest,
EXPECT_EQ(1, test_data.GetEventCount());
test_data.ClearEvents();

#if defined(FIREBASE_USE_STD_FUNCTION)
ListenerRegistration sync_registration =
TestFirestore()->AddSnapshotsInSyncListener(
[&test_data] { test_data.AddEvent("snapshots-in-sync"); });

#else
class SyncEventListener : public EventListener<void> {
public:
explicit SyncEventListener(TestData& test_data) : test_data_(test_data) {}

void OnEvent(Error) override { test_data_.AddEvent("snapshots-in-sync"); }

private:
TestData& test_data_;
};
SyncEventListener sync_listener{test_data};
ListenerRegistration sync_registration =
TestFirestore()->AddSnapshotsInSyncListener(sync_listener);
#endif // defined(FIREBASE_USE_STD_FUNCTION)

Await(document.Set(MapFieldValue{{"foo", FieldValue::Double(3.0)}}));
// Wait for the snapshots-in-sync listener to fire afterwards.
test_data.WaitForEventCount("snapshots-in-sync", 2);
Expand Down Expand Up @@ -737,7 +721,6 @@ TEST_F(FirestoreIntegrationTest, TestQueriesAreValidatedOnClient) {
// The test harness will generate Java JUnit test regardless whether this is
// inside a #if or not. So we move #if inside instead of enclose the whole case.
TEST_F(FirestoreIntegrationTest, TestListenCanBeCalledMultipleTimes) {
#if defined(FIREBASE_USE_STD_FUNCTION)
class TestData {
public:
void SetDocumentSnapshot(const DocumentSnapshot& document_snapshot) {
Expand Down Expand Up @@ -781,7 +764,6 @@ TEST_F(FirestoreIntegrationTest, TestListenCanBeCalledMultipleTimes) {

EXPECT_THAT(test_data.WaitForDocumentSnapshot().GetData(),
ContainerEq(MapFieldValue{{"foo", FieldValue::String("bar")}}));
#endif // defined(FIREBASE_USE_STD_FUNCTION)
}

TEST_F(FirestoreIntegrationTest, TestDocumentSnapshotEventsNonExistent) {
Expand Down
4 changes: 2 additions & 2 deletions firestore/integration_test_internal/src/includes_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class IncludesTest : public testing::Test {

namespace {

struct TestListener : EventListener<int> {
void OnEvent(const int&, Error, const std::string&) override {}
struct TestListener {
void OnEvent(const int&, Error, const std::string&) {}
};

struct TestTransactionFunction : TransactionFunction {
Expand Down
4 changes: 0 additions & 4 deletions firestore/integration_test_internal/src/integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,6 @@ TEST_F(FirebaseFirestoreBasicTest, TestSetDelete) {
}

TEST_F(FirebaseFirestoreBasicTest, TestDocumentListener) {
SKIP_TEST_IF_USING_STLPORT; // STLPort uses EventListener<T> rather than
// std::function.
#if !defined(STLPORT)
SignIn();

firebase::firestore::DocumentReference document = Doc();
Expand Down Expand Up @@ -487,7 +484,6 @@ TEST_F(FirebaseFirestoreBasicTest, TestDocumentListener) {
{"val", firebase::firestore::FieldValue::String("start")}},
firebase::firestore::MapFieldValue{
{"val", firebase::firestore::FieldValue::String("update")}}));
#endif // !defined(STLPORT)
}

TEST_F(FirebaseFirestoreBasicTest, TestBatchWrite) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,31 +248,26 @@ TEST_F(ServerTimestampTest,
}

TEST_F(ServerTimestampTest, TestServerTimestampsWorkViaTransactionSet) {
#if defined(FIREBASE_USE_STD_FUNCTION)
Await(TestFirestore()->RunTransaction(
[this](Transaction& transaction, std::string&) -> Error {
transaction.Set(doc_, set_data_);
return Error::kErrorOk;
}));
VerifyTimestampsAreResolved(accumulator_.AwaitRemoteEvent());
#endif // defined(FIREBASE_USE_STD_FUNCTION)
}

TEST_F(ServerTimestampTest, TestServerTimestampsWorkViaTransactionUpdate) {
#if defined(FIREBASE_USE_STD_FUNCTION)
WriteInitialData();
Await(TestFirestore()->RunTransaction(
[this](Transaction& transaction, std::string&) -> Error {
transaction.Update(doc_, update_data_);
return Error::kErrorOk;
}));
VerifyTimestampsAreResolved(accumulator_.AwaitRemoteEvent());
#endif // defined(FIREBASE_USE_STD_FUNCTION)
}

TEST_F(ServerTimestampTest,
TestServerTimestampsFailViaTransactionUpdateOnNonexistentDocument) {
#if defined(FIREBASE_USE_STD_FUNCTION)
Future<void> future = TestFirestore()->RunTransaction(
[this](Transaction& transaction, std::string&) -> Error {
transaction.Update(doc_, update_data_);
Expand All @@ -281,7 +276,6 @@ TEST_F(ServerTimestampTest,
Await(future);
EXPECT_EQ(FutureStatus::kFutureStatusComplete, future.status());
EXPECT_EQ(Error::kErrorNotFound, future.error());
#endif // defined(FIREBASE_USE_STD_FUNCTION)
}

TEST_F(ServerTimestampTest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ namespace firestore {

using TransactionExtraTest = FirestoreIntegrationTest;

#if defined(FIREBASE_USE_STD_FUNCTION)

TEST_F(TransactionExtraTest,
TestRetriesWhenDocumentThatWasReadWithoutBeingWrittenChanges) {
DocumentReference doc1 = TestFirestore()->Collection("counter").Document();
Expand Down Expand Up @@ -105,7 +103,5 @@ TEST_F(TransactionExtraTest, TestReadingADocTwiceWithDifferentVersions) {
DocumentSnapshot snapshot = ReadDocument(doc);
}

#endif // defined(FIREBASE_USE_STD_FUNCTION)

} // namespace firestore
} // namespace firebase
6 changes: 0 additions & 6 deletions firestore/integration_test_internal/src/transaction_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ using ::testing::HasSubstr;

class TransactionTest : public FirestoreIntegrationTest {
protected:
#if defined(FIREBASE_USE_STD_FUNCTION)
// We occasionally get transient error like "Could not reach Cloud Firestore
// backend. Backend didn't respond within 10 seconds". Transaction requires
// online and thus will not retry. So we do the retry in the testcase.
Expand Down Expand Up @@ -90,7 +89,6 @@ class TransactionTest : public FirestoreIntegrationTest {
FAIL() << "Unexpected error code: " << error;
}
}
#endif // defined(FIREBASE_USE_STD_FUNCTION)
};

class TestTransactionFunction : public TransactionFunction {
Expand Down Expand Up @@ -127,8 +125,6 @@ TEST_F(TransactionTest, TestGetNonexistentDocumentThenCreatePortableVersion) {
snapshot.Get(transaction.key()));
}

#if defined(FIREBASE_USE_STD_FUNCTION)

class TransactionStage {
public:
TransactionStage(
Expand Down Expand Up @@ -737,7 +733,5 @@ TEST_F(TransactionTest, TestCancellationOnError) {
EXPECT_FALSE(snapshot.exists());
}

#endif // defined(FIREBASE_USE_STD_FUNCTION)

} // namespace firestore
} // namespace firebase
4 changes: 0 additions & 4 deletions firestore/integration_test_internal/src/validation_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ class ValidationTest : public FirestoreIntegrationTest {
EXPECT_ERROR(TestFirestore()->batch().Update(document, data), reason);
}

#if defined(FIREBASE_USE_STD_FUNCTION)
Await(TestFirestore()->RunTransaction(
[data, reason, include_sets, include_updates, document](
Transaction& transaction, std::string& error_message) -> Error {
Expand All @@ -106,7 +105,6 @@ class ValidationTest : public FirestoreIntegrationTest {
}
return Error::kErrorOk;
}));
#endif // defined(FIREBASE_USE_STD_FUNCTION)
}

/**
Expand Down Expand Up @@ -339,7 +337,6 @@ TEST_F(ValidationTest, WritesMayContainIndirectlyNestedLists) {
Await(document.Update(data));
Await(TestFirestore()->batch().Update(document, data).Commit());

#if defined(FIREBASE_USE_STD_FUNCTION)
Await(TestFirestore()->RunTransaction(
[data, document, another_document](Transaction& transaction,
std::string& error_message) -> Error {
Expand All @@ -349,7 +346,6 @@ TEST_F(ValidationTest, WritesMayContainIndirectlyNestedLists) {
transaction.Set(another_document, data);
return Error::kErrorOk;
}));
#endif // defined(FIREBASE_USE_STD_FUNCTION)
}

// TODO(zxu): There is no way to create Firestore with different project id yet.
Expand Down
5 changes: 1 addition & 4 deletions firestore/src/android/document_reference_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ Future<void> DocumentReferenceInternal::Delete() {
return promises_.NewFuture<void>(env, AsyncFn::kDelete, task);
}

#if defined(FIREBASE_USE_STD_FUNCTION)

ListenerRegistration DocumentReferenceInternal::AddSnapshotListener(
MetadataChanges metadata_changes,
std::function<void(const DocumentSnapshot&, Error, const std::string&)>
Expand All @@ -175,8 +173,7 @@ ListenerRegistration DocumentReferenceInternal::AddSnapshotListener(
/*passing_listener_ownership=*/true);
}

#endif // defined(FIREBASE_USE_STD_FUNCTION)

// TODO(b/191969080): Remove the passing_listener_ownership if possible.
ListenerRegistration DocumentReferenceInternal::AddSnapshotListener(
MetadataChanges metadata_changes,
EventListener<DocumentSnapshot>* listener,
Expand Down
5 changes: 0 additions & 5 deletions firestore/src/android/document_reference_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class DocumentReferenceInternal : public Wrapper {
*/
Future<void> Delete();

#if defined(FIREBASE_USE_STD_FUNCTION)
/**
* @brief Starts listening to the document referenced by this
* DocumentReference.
Expand All @@ -144,15 +143,11 @@ class DocumentReferenceInternal : public Wrapper {
* called, snapshot value is valid if and only if error is Error::kErrorOk.
*
* @return A registration object that can be used to remove the listener.
*
* @note This method is not available when using the STLPort C++ runtime
* library.
*/
ListenerRegistration AddSnapshotListener(
MetadataChanges metadata_changes,
std::function<void(const DocumentSnapshot&, Error, const std::string&)>
callback);
#endif // defined(FIREBASE_USE_STD_FUNCTION)

/**
* Starts listening to the document referenced by this DocumentReference.
Expand Down
2 changes: 1 addition & 1 deletion firestore/src/android/event_listener_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#define FIREBASE_FIRESTORE_CLIENT_CPP_SRC_ANDROID_EVENT_LISTENER_ANDROID_H_

#include "firestore/src/android/firestore_android.h"
#include "firestore/src/common/event_listener.h"
#include "firestore/src/include/firebase/firestore/document_snapshot.h"
#include "firestore/src/include/firebase/firestore/event_listener.h"
#include "firestore/src/jni/jni_fwd.h"

namespace firebase {
Expand Down
10 changes: 0 additions & 10 deletions firestore/src/android/firestore_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -448,23 +448,17 @@ Future<void> FirestoreInternal::RunTransaction(TransactionFunction* update,

if (!env.ok()) return {};

#if defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)
auto* completion =
static_cast<LambdaTransactionFunction*>(is_lambda ? update : nullptr);
return promises_->NewFuture<void>(env, AsyncFn::kRunTransaction, task,
completion);
#else // defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)
return promises_->NewFuture<void>(env, AsyncFn::kRunTransaction, task);
#endif // defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)
}

#if defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)
Future<void> FirestoreInternal::RunTransaction(
std::function<Error(Transaction&, std::string&)> update) {
auto* lambda_update = new LambdaTransactionFunction(Move(update));
return RunTransaction(lambda_update, /*is_lambda=*/true);
}
#endif // defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)

Future<void> FirestoreInternal::DisableNetwork() {
Env env = GetEnv();
Expand Down Expand Up @@ -510,17 +504,13 @@ ListenerRegistration FirestoreInternal::AddSnapshotsInSyncListener(
this, listener, passing_listener_ownership, java_registration));
}

#if defined(FIREBASE_USE_STD_FUNCTION)

ListenerRegistration FirestoreInternal::AddSnapshotsInSyncListener(
std::function<void()> callback) {
auto* listener = new LambdaEventListener<void>(firebase::Move(callback));
return AddSnapshotsInSyncListener(listener,
/*passing_listener_ownership=*/true);
}

#endif // defined(FIREBASE_USE_STD_FUNCTION)

void FirestoreInternal::RegisterListenerRegistration(
ListenerRegistrationInternal* registration) {
MutexLock lock(listener_registration_mutex_);
Expand Down
Loading