Skip to content

Commit 900c491

Browse files
Fix EXPECT_EQ and FreeNanoPb message
1 parent e311459 commit 900c491

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

Firestore/core/src/model/object_value.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ inline bool operator==(const MutableObjectValue& lhs,
120120

121121
inline std::ostream& operator<<(std::ostream& out,
122122
const MutableObjectValue& object_value) {
123-
return out << CanonicalId(*object_value.value_);
123+
return out << "ObjectValue(" << *object_value.value_ << ")";
124124
}
125125

126126
} // namespace model

Firestore/core/src/model/value_util.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ bool ObjectEquals(const firebase::firestore::google_firestore_v1_Value& left,
305305
return true;
306306
}
307307

308-
bool operator==(const google_firestore_v1_Value& lhs,
309-
const google_firestore_v1_Value& rhs) {
308+
bool Equals(const google_firestore_v1_Value& lhs,
309+
const google_firestore_v1_Value& rhs) {
310310
TypeOrder left_type = GetTypeOrder(lhs);
311311
TypeOrder right_type = GetTypeOrder(rhs);
312312
if (left_type != right_type) {

Firestore/core/src/model/value_util.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ TypeOrder GetTypeOrder(const google_firestore_v1_Value& value);
5454
util::ComparisonResult Compare(const google_firestore_v1_Value& left,
5555
const google_firestore_v1_Value& right);
5656

57+
bool Equals(const google_firestore_v1_Value& left,
58+
const google_firestore_v1_Value& right);
59+
5760
/**
5861
* Generate the canonical ID for the provided field value (as used in Target
5962
* serialization).
@@ -63,15 +66,23 @@ std::string CanonicalId(const google_firestore_v1_Value& value);
6366
/** Creates a copy of the contents of the Value proto. */
6467
google_firestore_v1_Value DeepClone(google_firestore_v1_Value source);
6568

66-
bool operator==(const google_firestore_v1_Value& lhs,
67-
const google_firestore_v1_Value& rhs);
69+
} // namespace model
70+
71+
inline bool operator==(const google_firestore_v1_Value& lhs,
72+
const google_firestore_v1_Value& rhs) {
73+
return model::Equals(lhs, rhs);
74+
}
6875

6976
inline bool operator!=(const google_firestore_v1_Value& lhs,
7077
const google_firestore_v1_Value& rhs) {
71-
return !(lhs == rhs);
78+
return !model::Equals(lhs, rhs);
79+
}
80+
81+
inline std::ostream& operator<<(std::ostream& out,
82+
const google_firestore_v1_Value& value) {
83+
return out << model::CanonicalId(value);
7284
}
7385

74-
} // namespace model
7586
} // namespace firestore
7687
} // namespace firebase
7788

Firestore/core/src/nanopb/fields_array.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ inline const pb_field_t* FieldsArray<google_protobuf_Empty>() {
164164
return google_protobuf_Empty_fields;
165165
}
166166

167-
template <typename T>
168-
void FreeFieldsArray(T* message) {
169-
FreeNanopbMessage(FieldsArray<T>(), message);
170-
}
171-
172167
} // namespace nanopb
173168
} // namespace firestore
174169
} // namespace firebase

Firestore/core/src/nanopb/message.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ std::string MakeStdString(const Message<T>& message) {
227227
return writer.Release();
228228
}
229229

230+
231+
/** Free the dynamically-allocated memory for the fields array of type T. */
232+
template <typename T>
233+
void FreeFieldsArray(T* message) {
234+
FreeNanopbMessage(FieldsArray<T>(), message);
235+
}
236+
230237
} // namespace nanopb
231238
} // namespace firestore
232239
} // namespace firebase

Firestore/core/test/unit/model/value_util_test.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ class ValueUtilTest : public ::testing::Test {
103103
bool expected_equals) {
104104
for (const auto& val1 : left) {
105105
for (const auto& val2 : right) {
106-
EXPECT_EQ(expected_equals, val1 == val2)
107-
<< "Equality check failed for '" << CanonicalId(val1) << "' and '"
108-
<< CanonicalId(val2) << "' (expected " << expected_equals << ")";
106+
if (expected_equals) {
107+
EXPECT_EQ(val1, val2);
108+
} else {
109+
EXPECT_NE(val1, val2);
110+
}
109111
}
110112
}
111113
}
@@ -138,16 +140,12 @@ class ValueUtilTest : public ::testing::Test {
138140

139141
[&] {
140142
nanopb::Message<google_firestore_v1_Value> clone2{DeepClone(value)};
141-
EXPECT_TRUE(value == *clone2)
142-
<< "Equality failed for '" << CanonicalId(value) << "' and '"
143-
<< CanonicalId(*clone2) << "'";
143+
EXPECT_EQ(value, *clone2);
144144
clone1 = nanopb::Message<google_firestore_v1_Value>{DeepClone(*clone2)};
145145
}();
146146

147147
// `clone2` is destroyed at this point, but `clone1` should be still valid.
148-
EXPECT_TRUE(value == *clone1)
149-
<< "Equality failed for '" << CanonicalId(value) << "' and '"
150-
<< CanonicalId(*clone1) << "'";
148+
EXPECT_EQ(value, *clone1);
151149
}
152150

153151
private:

0 commit comments

Comments
 (0)