Skip to content

Commit 3177560

Browse files
authored
Roll back #486 (#495)
1 parent 6ba480a commit 3177560

32 files changed

+396
-26
lines changed

app/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ if (IOS)
468468
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_change.h
469469
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_reference.h
470470
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/document_snapshot.h
471+
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/event_listener.h
471472
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/field_path.h
472473
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/field_value.h
473474
${FIREBASE_SOURCE_DIR}/firestore/src/include/firebase/firestore/listener_registration.h

firestore/integration_test/src/integration_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ TEST_F(FirebaseFirestoreBasicTest, TestSetDelete) {
448448
}
449449

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

453456
firebase::firestore::DocumentReference document = Doc();
@@ -484,6 +487,7 @@ TEST_F(FirebaseFirestoreBasicTest, TestDocumentListener) {
484487
{"val", firebase::firestore::FieldValue::String("start")}},
485488
firebase::firestore::MapFieldValue{
486489
{"val", firebase::firestore::FieldValue::String("update")}}));
490+
#endif // !defined(STLPORT)
487491
}
488492

489493
TEST_F(FirebaseFirestoreBasicTest, TestBatchWrite) {

firestore/integration_test_internal/src/cleanup_test.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ void ExpectAllMethodsAreNoOps(DocumentReference* ptr) {
9999

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

102+
#if defined(FIREBASE_USE_STD_FUNCTION)
102103
ptr->AddSnapshotListener(
103104
[](const DocumentSnapshot&, Error, const std::string&) {});
105+
#else
106+
ptr->AddSnapshotListener(nullptr);
107+
#endif
104108
}
105109

106110
void ExpectAllMethodsAreNoOps(DocumentSnapshot* ptr) {
@@ -211,8 +215,12 @@ void ExpectAllMethodsAreNoOps(Query* ptr) {
211215

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

218+
#if defined(FIREBASE_USE_STD_FUNCTION)
214219
ptr->AddSnapshotListener(
215220
[](const QuerySnapshot&, Error, const std::string&) {});
221+
#else
222+
ptr->AddSnapshotListener(nullptr);
223+
#endif
216224
}
217225

218226
void ExpectAllMethodsAreNoOps(QuerySnapshot* ptr) {
@@ -350,6 +358,7 @@ TEST_F(CleanupTest, FieldValueIsBlankAfterCleanup) {
350358
// after cleanup. Thus, there is no case where a user could be accessing
351359
// a "blank" Firestore instance.
352360

361+
#if defined(FIREBASE_USE_STD_FUNCTION)
353362
TEST_F(CleanupTest, ListenerRegistrationIsBlankAfterCleanup) {
354363
{
355364
ListenerRegistration default_constructed;
@@ -364,6 +373,7 @@ TEST_F(CleanupTest, ListenerRegistrationIsBlankAfterCleanup) {
364373
SCOPED_TRACE("ListenerRegistration.AfterCleanup");
365374
ExpectAllMethodsAreNoOps(&reg);
366375
}
376+
#endif
367377

368378
// Note: `Query` cleanup is tested as part of `CollectionReference` cleanup
369379
// (`CollectionReference` is derived from `Query`).

firestore/integration_test_internal/src/firestore_integration_test.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,20 @@ class TestEventListener : public EventListener<T> {
108108
return last_results_[last_results_.size() - 1 - i];
109109
}
110110

111+
// Hides the STLPort-related quirk that `AddSnapshotListener` has different
112+
// signatures depending on whether `std::function` is available.
111113
template <typename U>
112114
ListenerRegistration AttachTo(
113115
U* ref, MetadataChanges metadata_changes = MetadataChanges::kExclude) {
116+
#if defined(FIREBASE_USE_STD_FUNCTION)
114117
return ref->AddSnapshotListener(
115118
metadata_changes, [this](const T& result, Error error_code,
116119
const std::string& error_message) {
117120
OnEvent(result, error_code, error_message);
118121
});
122+
#else
123+
return ref->AddSnapshotListener(metadata_changes, this);
124+
#endif
119125
}
120126

121127
std::string first_error_message() {

firestore/integration_test_internal/src/firestore_test.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,10 +669,26 @@ TEST_F(FirestoreIntegrationTest,
669669
EXPECT_EQ(1, test_data.GetEventCount());
670670
test_data.ClearEvents();
671671

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

677+
#else
678+
class SyncEventListener : public EventListener<void> {
679+
public:
680+
explicit SyncEventListener(TestData& test_data) : test_data_(test_data) {}
681+
682+
void OnEvent(Error) override { test_data_.AddEvent("snapshots-in-sync"); }
683+
684+
private:
685+
TestData& test_data_;
686+
};
687+
SyncEventListener sync_listener{test_data};
688+
ListenerRegistration sync_registration =
689+
TestFirestore()->AddSnapshotsInSyncListener(sync_listener);
690+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
691+
676692
Await(document.Set(MapFieldValue{{"foo", FieldValue::Double(3.0)}}));
677693
// Wait for the snapshots-in-sync listener to fire afterwards.
678694
test_data.WaitForEventCount("snapshots-in-sync", 2);
@@ -719,6 +735,7 @@ TEST_F(FirestoreIntegrationTest, TestQueriesAreValidatedOnClient) {
719735
// The test harness will generate Java JUnit test regardless whether this is
720736
// inside a #if or not. So we move #if inside instead of enclose the whole case.
721737
TEST_F(FirestoreIntegrationTest, TestListenCanBeCalledMultipleTimes) {
738+
#if defined(FIREBASE_USE_STD_FUNCTION)
722739
class TestData {
723740
public:
724741
void SetDocumentSnapshot(const DocumentSnapshot& document_snapshot) {
@@ -762,6 +779,7 @@ TEST_F(FirestoreIntegrationTest, TestListenCanBeCalledMultipleTimes) {
762779

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

767785
TEST_F(FirestoreIntegrationTest, TestDocumentSnapshotEventsNonExistent) {

firestore/integration_test_internal/src/integration_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ TEST_F(FirebaseFirestoreBasicTest, TestSetDelete) {
448448
}
449449

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

453456
firebase::firestore::DocumentReference document = Doc();
@@ -484,6 +487,7 @@ TEST_F(FirebaseFirestoreBasicTest, TestDocumentListener) {
484487
{"val", firebase::firestore::FieldValue::String("start")}},
485488
firebase::firestore::MapFieldValue{
486489
{"val", firebase::firestore::FieldValue::String("update")}}));
490+
#endif // !defined(STLPORT)
487491
}
488492

489493
TEST_F(FirebaseFirestoreBasicTest, TestBatchWrite) {

firestore/integration_test_internal/src/server_timestamp_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,26 +246,31 @@ TEST_F(ServerTimestampTest,
246246
}
247247

248248
TEST_F(ServerTimestampTest, TestServerTimestampsWorkViaTransactionSet) {
249+
#if defined(FIREBASE_USE_STD_FUNCTION)
249250
Await(TestFirestore()->RunTransaction(
250251
[this](Transaction& transaction, std::string&) -> Error {
251252
transaction.Set(doc_, set_data_);
252253
return Error::kErrorOk;
253254
}));
254255
VerifyTimestampsAreResolved(accumulator_.AwaitRemoteEvent());
256+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
255257
}
256258

257259
TEST_F(ServerTimestampTest, TestServerTimestampsWorkViaTransactionUpdate) {
260+
#if defined(FIREBASE_USE_STD_FUNCTION)
258261
WriteInitialData();
259262
Await(TestFirestore()->RunTransaction(
260263
[this](Transaction& transaction, std::string&) -> Error {
261264
transaction.Update(doc_, update_data_);
262265
return Error::kErrorOk;
263266
}));
264267
VerifyTimestampsAreResolved(accumulator_.AwaitRemoteEvent());
268+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
265269
}
266270

267271
TEST_F(ServerTimestampTest,
268272
TestServerTimestampsFailViaTransactionUpdateOnNonexistentDocument) {
273+
#if defined(FIREBASE_USE_STD_FUNCTION)
269274
Future<void> future = TestFirestore()->RunTransaction(
270275
[this](Transaction& transaction, std::string&) -> Error {
271276
transaction.Update(doc_, update_data_);
@@ -274,6 +279,7 @@ TEST_F(ServerTimestampTest,
274279
Await(future);
275280
EXPECT_EQ(FutureStatus::kFutureStatusComplete, future.status());
276281
EXPECT_EQ(Error::kErrorNotFound, future.error());
282+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
277283
}
278284

279285
TEST_F(ServerTimestampTest,

firestore/integration_test_internal/src/transaction_extra_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ namespace firestore {
2424

2525
using TransactionExtraTest = FirestoreIntegrationTest;
2626

27+
#if defined(FIREBASE_USE_STD_FUNCTION)
28+
2729
TEST_F(TransactionExtraTest,
2830
TestRetriesWhenDocumentThatWasReadWithoutBeingWrittenChanges) {
2931
DocumentReference doc1 = TestFirestore()->Collection("counter").Document();
@@ -101,5 +103,7 @@ TEST_F(TransactionExtraTest, TestReadingADocTwiceWithDifferentVersions) {
101103
DocumentSnapshot snapshot = ReadDocument(doc);
102104
}
103105

106+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
107+
104108
} // namespace firestore
105109
} // namespace firebase

firestore/integration_test_internal/src/transaction_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ using ::testing::HasSubstr;
3737

3838
class TransactionTest : public FirestoreIntegrationTest {
3939
protected:
40+
#if defined(FIREBASE_USE_STD_FUNCTION)
4041
// We occasionally get transient error like "Could not reach Cloud Firestore
4142
// backend. Backend didn't respond within 10 seconds". Transaction requires
4243
// online and thus will not retry. So we do the retry in the testcase.
@@ -87,6 +88,7 @@ class TransactionTest : public FirestoreIntegrationTest {
8788
FAIL() << "Unexpected error code: " << error;
8889
}
8990
}
91+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
9092
};
9193

9294
class TestTransactionFunction : public TransactionFunction {
@@ -123,6 +125,8 @@ TEST_F(TransactionTest, TestGetNonexistentDocumentThenCreatePortableVersion) {
123125
snapshot.Get(transaction.key()));
124126
}
125127

128+
#if defined(FIREBASE_USE_STD_FUNCTION)
129+
126130
class TransactionStage {
127131
public:
128132
TransactionStage(
@@ -731,5 +735,7 @@ TEST_F(TransactionTest, TestCancellationOnError) {
731735
EXPECT_FALSE(snapshot.exists());
732736
}
733737

738+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
739+
734740
} // namespace firestore
735741
} // namespace firebase

firestore/integration_test_internal/src/validation_test.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class ValidationTest : public FirestoreIntegrationTest {
9090
EXPECT_ERROR(TestFirestore()->batch().Update(document, data), reason);
9191
}
9292

93+
#if defined(FIREBASE_USE_STD_FUNCTION)
9394
Await(TestFirestore()->RunTransaction(
9495
[data, reason, include_sets, include_updates, document](
9596
Transaction& transaction, std::string& error_message) -> Error {
@@ -103,6 +104,7 @@ class ValidationTest : public FirestoreIntegrationTest {
103104
}
104105
return Error::kErrorOk;
105106
}));
107+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
106108
}
107109

108110
/**
@@ -335,6 +337,7 @@ TEST_F(ValidationTest, WritesMayContainIndirectlyNestedLists) {
335337
Await(document.Update(data));
336338
Await(TestFirestore()->batch().Update(document, data).Commit());
337339

340+
#if defined(FIREBASE_USE_STD_FUNCTION)
338341
Await(TestFirestore()->RunTransaction(
339342
[data, document, another_document](Transaction& transaction,
340343
std::string& error_message) -> Error {
@@ -344,6 +347,7 @@ TEST_F(ValidationTest, WritesMayContainIndirectlyNestedLists) {
344347
transaction.Set(another_document, data);
345348
return Error::kErrorOk;
346349
}));
350+
#endif // defined(FIREBASE_USE_STD_FUNCTION)
347351
}
348352

349353
// TODO(zxu): There is no way to create Firestore with different project id yet.

0 commit comments

Comments
 (0)