2727namespace firebase {
2828namespace firestore {
2929
30- #if defined(__ANDROID__)
31-
3230using DocumentChangeTest = FirestoreIntegrationTest;
3331
32+ #if defined(__ANDROID__)
33+
3434TEST_F (DocumentChangeTest, Construction) {
3535 testutil::AssertWrapperConstructionContract<DocumentChange,
3636 DocumentChangeInternal>();
@@ -59,7 +59,7 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
5959 snapshot = listener.last_result ();
6060
6161 std::vector<DocumentChange> changes = snapshot.DocumentChanges ();
62- EXPECT_EQ (changes.size (), 1 );
62+ ASSERT_EQ (changes.size (), 1 );
6363
6464 EXPECT_EQ (changes[0 ].type (), DocumentChange::Type::kAdded );
6565 EXPECT_EQ (changes[0 ].document ().id (), doc1.id ());
@@ -71,7 +71,7 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
7171 snapshot = listener.last_result ();
7272
7373 changes = snapshot.DocumentChanges ();
74- EXPECT_EQ (changes.size (), 1 );
74+ ASSERT_EQ (changes.size (), 1 );
7575 EXPECT_EQ (changes[0 ].type (), DocumentChange::Type::kAdded );
7676 EXPECT_EQ (changes[0 ].document ().id (), doc2.id ());
7777 EXPECT_EQ (changes[0 ].old_index (), DocumentChange::npos);
@@ -83,7 +83,7 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
8383 snapshot = listener.last_result ();
8484
8585 changes = snapshot.DocumentChanges ();
86- EXPECT_EQ (changes.size (), 1 );
86+ ASSERT_EQ (changes.size (), 1 );
8787 EXPECT_EQ (changes[0 ].type (), DocumentChange::Type::kModified );
8888 EXPECT_EQ (changes[0 ].document ().id (), doc2.id ());
8989 EXPECT_EQ (changes[0 ].old_index (), 1 );
@@ -92,5 +92,67 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
9292
9393#endif // defined(__ANDROID__)
9494
95+ TEST_F (DocumentChangeTest, Equality) {
96+ DocumentChange invalid_change_1 = DocumentChange ();
97+ DocumentChange invalid_change_2 = DocumentChange ();
98+
99+ EXPECT_TRUE (invalid_change_1 == invalid_change_2);
100+ EXPECT_FALSE (invalid_change_1 != invalid_change_2);
101+
102+ CollectionReference collection = Collection ();
103+ Query query = collection.OrderBy (" a" );
104+
105+ DocumentReference doc1 = collection.Document (" 1" );
106+ DocumentReference doc2 = collection.Document (" 2" );
107+
108+ TestEventListener<QuerySnapshot> listener (" TestDocumentChanges" );
109+ ListenerRegistration registration = listener.AttachTo (&query);
110+ Await (listener);
111+ QuerySnapshot snapshot = listener.last_result ();
112+ EXPECT_EQ (snapshot.size (), 0 );
113+
114+ WriteDocument (doc1, MapFieldValue{{" a" , FieldValue::Integer (1 )}});
115+ Await (listener);
116+ snapshot = listener.last_result ();
117+
118+ std::vector<DocumentChange> changes = snapshot.DocumentChanges ();
119+ ASSERT_EQ (changes.size (), 1 );
120+ // First change: Added doc1.
121+ auto change1 = changes[0 ];
122+ EXPECT_TRUE (change1 == change1);
123+ EXPECT_TRUE (change1 != invalid_change_1);
124+ EXPECT_FALSE (change1 != change1);
125+ EXPECT_FALSE (change1 == invalid_change_1);
126+
127+ WriteDocument (doc2, MapFieldValue{{" a" , FieldValue::Integer (2 )}});
128+ Await (listener, 2 );
129+ snapshot = listener.last_result ();
130+
131+ changes = snapshot.DocumentChanges ();
132+ ASSERT_EQ (changes.size (), 1 );
133+ // Second change: Added doc2.
134+ auto change2 = changes[0 ];
135+ EXPECT_TRUE (change2 != change1);
136+ EXPECT_TRUE (change2 != invalid_change_1);
137+ EXPECT_FALSE (change2 == change1);
138+ EXPECT_FALSE (change2 == invalid_change_1);
139+
140+ // Make doc2 ordered before doc1.
141+ WriteDocument (doc2, MapFieldValue{{" a" , FieldValue::Integer (0 )}});
142+ Await (listener, 3 );
143+ snapshot = listener.last_result ();
144+
145+ changes = snapshot.DocumentChanges ();
146+ ASSERT_EQ (changes.size (), 1 );
147+ // Third change: Modified doc2.
148+ auto change3 = changes[0 ];
149+ EXPECT_TRUE (change3 != change1);
150+ EXPECT_TRUE (change3 != change2);
151+ EXPECT_TRUE (change3 != invalid_change_1);
152+ EXPECT_FALSE (change3 == change1);
153+ EXPECT_FALSE (change3 == change2);
154+ EXPECT_FALSE (change3 == invalid_change_1);
155+ }
156+
95157} // namespace firestore
96158} // namespace firebase
0 commit comments