Skip to content

Commit 97c2a9c

Browse files
Merge branch 'mrschmidt/fieldvalue' of github.com:firebase/firebase-cpp-sdk into mrschmidt/fieldvalue
2 parents e12fb04 + fb68ec7 commit 97c2a9c

File tree

10 files changed

+154
-12
lines changed

10 files changed

+154
-12
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ iOS, and desktop platforms. It includes the following Firebase libraries:
88
- [Firebase Authentication](https://firebase.google.com/docs/auth/)
99
- [Firebase Realtime Database](https://firebase.google.com/docs/database/)
1010
- [Firebase Dynamic Links](https://firebase.google.com/docs/dynamic-links/)
11+
- [Cloud Firestore](https://firebase.google.com/docs/firestore/)
1112
- [Cloud Functions for Firebase](https://firebase.google.com/docs/functions/)
1213
- [Firebase Invites](https://firebase.google.com/docs/invites/)
1314
- [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging/)
@@ -65,7 +66,7 @@ required packages:
6566
The following prerequisites are required when building the libraries for
6667
desktop platforms.
6768

68-
- [OpenSSL](https://www.openssl.org/), needed for Realtime Database
69+
- [OpenSSL](https://www.openssl.org/), needed for Realtime Database and Cloud Firestore
6970
- [Protobuf](https://github.com/protocolbuffers/protobuf/blob/master/src/README.md),
7071
needed for Remote Config
7172

@@ -135,6 +136,7 @@ The CMake following targets are available to build and link with:
135136
| Firebase Authentication | firebase_auth |
136137
| Firebase Realtime Database | firebase_database |
137138
| Firebase Dynamic Links | firebase_dynamic_links |
139+
| Cloud Firestore | firebase_firestore |
138140
| Cloud Functions for Firebase | firebase_functions |
139141
| Firebase Invites | firebase_invites |
140142
| Firebase Cloud Messaging | firebase_messaging |
@@ -240,6 +242,7 @@ release version of each Firebase library is:
240242
| Firebase Authentication | :auth:assembleRelease |
241243
| Firebase Realtime Database | :database:assembleRelease |
242244
| Firebase Dynamic Links | :dynamic_links:assembleRelease |
245+
| Cloud Firestore | :firestore:assembleRelease |
243246
| Cloud Functions for Firebase | :functions:assembleRelease |
244247
| Firebase Invites | :invites:assembleRelease |
245248
| Firebase Cloud Messaging | :messaging:assembleRelease |

database/integration_test/src/integration_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,9 +1266,17 @@ TEST_F(FirebaseDatabaseTest, TestInvalidatingReferencesWhenDeletingApp) {
12661266

12671267
TEST_F(FirebaseDatabaseTest, TestInfoConnected) {
12681268
SignIn();
1269+
1270+
// The entire test can be a bit flaky on iOS, as the iOS SDK's
1271+
// .info/connected is not quite perfect.
1272+
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
1273+
FLAKY_TEST_SECTION_BEGIN();
1274+
#endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
1275+
12691276
firebase::database::DatabaseReference ref = CreateWorkingPath();
12701277
// Force getting a value so that we are connected to the database.
12711278
WaitForCompletion(ref.GetValue(), "GetValue 1 [ignored]");
1279+
12721280
firebase::database::DatabaseReference info =
12731281
database_->GetReference(".info").Child("connected");
12741282
{
@@ -1299,6 +1307,10 @@ TEST_F(FirebaseDatabaseTest, TestInfoConnected) {
12991307
WaitForCompletion(reconnected, "GetValue 5");
13001308
EXPECT_EQ(reconnected.result()->value(), true);
13011309
}
1310+
1311+
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
1312+
FLAKY_TEST_SECTION_END();
1313+
#endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
13021314
}
13031315

13041316
TEST_F(FirebaseDatabaseTest, TestGetReferenceWillNullArgument) {

firestore/integration_test_internal/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ set(FIREBASE_INTEGRATION_TEST_PORTABLE_TEST_SRCS
9595
src/query_test.cc
9696
src/sanity_test.cc
9797
src/server_timestamp_test.cc
98+
src/settings_test.cc
9899
src/smoke_test.cc
99100
src/source_test.cc
100101
src/transaction_test.cc
@@ -205,6 +206,7 @@ include_directories(${FIREBASE_CPP_SDK_DIR})
205206
# Additional public headers from Firestore core SDK.
206207
include_directories(${PROJECT_BINARY_DIR}/bin/external/src/firestore)
207208
include_directories(${PROJECT_BINARY_DIR}/bin/external/src/nanopb)
209+
include_directories(${PROJECT_BINARY_DIR}/bin/external/src/firestore/Firestore/Protos/nanopb)
208210
# Additional public headers for absl.
209211
include_directories(${ABSEIL_CPP_ROOT})
210212
# Allow testing internal Firebase APIs.

firestore/integration_test_internal/src/android/settings_android_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ namespace {
1414

1515
using jni::Env;
1616

17-
using SettingsTest = FirestoreIntegrationTest;
17+
using SettingsTestAndroid = FirestoreIntegrationTest;
1818

19-
TEST_F(SettingsTest, ConverterBoolsAllTrue) {
19+
TEST_F(SettingsTestAndroid, ConverterBoolsAllTrue) {
2020
Env env;
2121

2222
Settings settings;
@@ -34,7 +34,7 @@ TEST_F(SettingsTest, ConverterBoolsAllTrue) {
3434
EXPECT_EQ(result.cache_size_bytes(), five_mb);
3535
}
3636

37-
TEST_F(SettingsTest, ConverterBoolsAllFalse) {
37+
TEST_F(SettingsTestAndroid, ConverterBoolsAllFalse) {
3838
Env env;
3939

4040
Settings settings;

firestore/integration_test_internal/src/cleanup_test.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ void ExpectEqualityToWork(T* ptr) {
4343
EXPECT_FALSE(*ptr != T());
4444
}
4545

46+
// Checks that `operator==` and `operator!=` work correctly by comparing to
47+
// a default-constructed instance.
48+
template <typename T>
49+
void ExpectEqualityToWork(const T& ref) {
50+
EXPECT_TRUE(ref == T());
51+
EXPECT_FALSE(ref != T());
52+
}
53+
4654
// `ExpectAllMethodsAreNoOps` calls all the public API methods on the given
4755
// `ptr` and checks that the calls don't crash and, where applicable, return
4856
// value-initialized values.
@@ -122,8 +130,7 @@ void ExpectAllMethodsAreNoOps(DocumentSnapshot* ptr) {
122130
EXPECT_FALSE(ptr->exists());
123131

124132
EXPECT_EQ(ptr->reference(), DocumentReference());
125-
// TODO(b/137966104): implement == on `SnapshotMetadata`
126-
ptr->metadata();
133+
ExpectEqualityToWork(ptr->metadata());
127134

128135
EXPECT_EQ(ptr->GetData(), MapFieldValue());
129136

@@ -236,8 +243,7 @@ void ExpectAllMethodsAreNoOps(QuerySnapshot* ptr) {
236243

237244
EXPECT_EQ(ptr->query(), Query());
238245

239-
// TODO(b/137966104): implement == on `SnapshotMetadata`
240-
ptr->metadata();
246+
ExpectEqualityToWork(ptr->metadata());
241247

242248
EXPECT_TRUE(ptr->DocumentChanges().empty());
243249
EXPECT_TRUE(ptr->documents().empty());
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Copyright 2021 Google LLC
2+
3+
#include <stdint.h>
4+
5+
#include "firebase/firestore.h"
6+
7+
#include "gtest/gtest.h"
8+
9+
namespace firebase {
10+
namespace firestore {
11+
namespace {
12+
13+
TEST(SettingsTest, Equality) {
14+
constexpr int64_t kFiveMb = 5 * 1024 * 1024;
15+
constexpr int64_t kSixMb = 6 * 1024 * 1024;
16+
17+
Settings settings1;
18+
settings1.set_host("foo");
19+
settings1.set_ssl_enabled(true);
20+
settings1.set_persistence_enabled(true);
21+
settings1.set_cache_size_bytes(kFiveMb);
22+
23+
Settings settings2;
24+
settings2.set_host("bar");
25+
settings2.set_ssl_enabled(true);
26+
settings2.set_persistence_enabled(true);
27+
settings2.set_cache_size_bytes(kFiveMb);
28+
29+
Settings settings3;
30+
settings3.set_host("foo");
31+
settings3.set_ssl_enabled(false);
32+
settings3.set_persistence_enabled(true);
33+
settings3.set_cache_size_bytes(kFiveMb);
34+
35+
Settings settings4;
36+
settings4.set_host("foo");
37+
settings4.set_ssl_enabled(true);
38+
settings4.set_persistence_enabled(false);
39+
settings4.set_cache_size_bytes(kFiveMb);
40+
41+
Settings settings5;
42+
settings5.set_host("foo");
43+
settings5.set_ssl_enabled(true);
44+
settings5.set_persistence_enabled(true);
45+
settings5.set_cache_size_bytes(kSixMb);
46+
47+
// This is the same as settings4.
48+
Settings settings6;
49+
settings6.set_host("foo");
50+
settings6.set_ssl_enabled(true);
51+
settings6.set_persistence_enabled(false);
52+
settings6.set_cache_size_bytes(kFiveMb);
53+
54+
EXPECT_TRUE(settings1 == settings1);
55+
EXPECT_TRUE(settings6 == settings4);
56+
57+
EXPECT_FALSE(settings1 == settings2);
58+
EXPECT_FALSE(settings1 == settings3);
59+
EXPECT_FALSE(settings1 == settings4);
60+
EXPECT_FALSE(settings1 == settings5);
61+
EXPECT_FALSE(settings2 == settings3);
62+
EXPECT_FALSE(settings2 == settings4);
63+
EXPECT_FALSE(settings2 == settings5);
64+
EXPECT_FALSE(settings3 == settings4);
65+
EXPECT_FALSE(settings3 == settings5);
66+
EXPECT_FALSE(settings4 == settings5);
67+
68+
EXPECT_FALSE(settings1 != settings1);
69+
EXPECT_FALSE(settings6 != settings4);
70+
71+
EXPECT_TRUE(settings1 != settings2);
72+
EXPECT_TRUE(settings1 != settings3);
73+
EXPECT_TRUE(settings1 != settings4);
74+
EXPECT_TRUE(settings1 != settings5);
75+
EXPECT_TRUE(settings2 != settings3);
76+
EXPECT_TRUE(settings2 != settings4);
77+
EXPECT_TRUE(settings2 != settings5);
78+
EXPECT_TRUE(settings3 != settings4);
79+
EXPECT_TRUE(settings3 != settings5);
80+
EXPECT_TRUE(settings4 != settings5);
81+
}
82+
83+
} // namespace
84+
} // namespace firestore
85+
} // namespace firebase

firestore/src/include/firebase/firestore/settings.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,19 @@ class Settings final {
228228
#endif
229229
};
230230

231+
/** Checks `lhs` and `rhs` for equality. */
232+
inline bool operator==(const Settings& lhs, const Settings& rhs) {
233+
return lhs.host() == rhs.host() &&
234+
lhs.is_ssl_enabled() == rhs.is_ssl_enabled() &&
235+
lhs.is_persistence_enabled() == rhs.is_persistence_enabled() &&
236+
lhs.cache_size_bytes() == rhs.cache_size_bytes();
237+
}
238+
239+
/** Checks `lhs` and `rhs` for inequality. */
240+
inline bool operator!=(const Settings& lhs, const Settings& rhs) {
241+
return !(lhs == rhs);
242+
}
243+
231244
} // namespace firestore
232245
} // namespace firebase
233246

firestore/src/include/firebase/firestore/snapshot_metadata.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ class SnapshotMetadata final {
140140
bool is_from_cache_ = false;
141141
};
142142

143+
/** Checks `lhs` and `rhs` for equality. */
144+
inline bool operator==(const SnapshotMetadata& lhs,
145+
const SnapshotMetadata& rhs) {
146+
return lhs.has_pending_writes() == rhs.has_pending_writes() &&
147+
lhs.is_from_cache() == rhs.is_from_cache();
148+
}
149+
150+
/** Checks `lhs` and `rhs` for inequality. */
151+
inline bool operator!=(const SnapshotMetadata& lhs,
152+
const SnapshotMetadata& rhs) {
153+
return !(lhs == rhs);
154+
}
155+
143156
} // namespace firestore
144157
} // namespace firebase
145158

release_build_files/readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ code.
570570
### 8.4.0
571571
- Changes
572572
- General: Updating Android and iOS dependencies to the latest.
573+
- Firestore: Added `operator==` and `operator!=` for `SnapshotMetadata`
574+
and `Settings`.
573575

574576
### 8.3.0
575577
- Changes

storage/integration_test/src/integration_test.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -901,11 +901,14 @@ TEST_F(FirebaseStorageTest, TestInvalidatingReferencesWhenDeletingStorage) {
901901
CreateFolder().Child("TestFile-InvalidateReferencesDeletingStorage.txt");
902902
// Don't clean up, will be manually deleted.
903903

904-
WaitForCompletion(ref.PutBytes(&kSimpleTestFile[0], kSimpleTestFile.size()),
904+
WaitForCompletion(RunWithRetry([&]() {
905+
return ref.PutBytes(&kSimpleTestFile[0],
906+
kSimpleTestFile.size());
907+
}),
905908
"PutBytes");
906909
ASSERT_NE(ref.PutBytesLastResult().result(), nullptr);
907910
firebase::storage::Metadata metadata = *ref.PutBytesLastResult().result();
908-
WaitForCompletion(ref.Delete(), "Delete");
911+
WaitForCompletion(RunWithRetry([&]() { return ref.Delete(); }), "Delete");
909912

910913
ASSERT_TRUE(ref.is_valid());
911914
ASSERT_TRUE(metadata.is_valid());
@@ -924,11 +927,14 @@ TEST_F(FirebaseStorageTest, TestInvalidatingReferencesWhenDeletingApp) {
924927
CreateFolder().Child("TestFile-InvalidateReferencesDeletingApp.txt");
925928
// Don't clean up, will be manually deleted.
926929

927-
WaitForCompletion(ref.PutBytes(&kSimpleTestFile[0], kSimpleTestFile.size()),
930+
WaitForCompletion(RunWithRetry([&]() {
931+
return ref.PutBytes(&kSimpleTestFile[0],
932+
kSimpleTestFile.size());
933+
}),
928934
"PutBytes");
929935
ASSERT_NE(ref.PutBytesLastResult().result(), nullptr);
930936
firebase::storage::Metadata metadata = *ref.PutBytesLastResult().result();
931-
WaitForCompletion(ref.Delete(), "Delete");
937+
WaitForCompletion(RunWithRetry([&]() { return ref.Delete(); }), "Delete");
932938

933939
ASSERT_TRUE(ref.is_valid());
934940
ASSERT_TRUE(metadata.is_valid());

0 commit comments

Comments
 (0)