27
27
namespace firebase {
28
28
namespace firestore {
29
29
30
- #if defined(__ANDROID__)
31
-
32
30
using DocumentChangeTest = FirestoreIntegrationTest;
33
31
32
+ #if defined(__ANDROID__)
33
+
34
34
TEST_F (DocumentChangeTest, Construction) {
35
35
testutil::AssertWrapperConstructionContract<DocumentChange,
36
36
DocumentChangeInternal>();
@@ -59,7 +59,7 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
59
59
snapshot = listener.last_result ();
60
60
61
61
std::vector<DocumentChange> changes = snapshot.DocumentChanges ();
62
- EXPECT_EQ (changes.size (), 1 );
62
+ ASSERT_EQ (changes.size (), 1 );
63
63
64
64
EXPECT_EQ (changes[0 ].type (), DocumentChange::Type::kAdded );
65
65
EXPECT_EQ (changes[0 ].document ().id (), doc1.id ());
@@ -71,7 +71,7 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
71
71
snapshot = listener.last_result ();
72
72
73
73
changes = snapshot.DocumentChanges ();
74
- EXPECT_EQ (changes.size (), 1 );
74
+ ASSERT_EQ (changes.size (), 1 );
75
75
EXPECT_EQ (changes[0 ].type (), DocumentChange::Type::kAdded );
76
76
EXPECT_EQ (changes[0 ].document ().id (), doc2.id ());
77
77
EXPECT_EQ (changes[0 ].old_index (), DocumentChange::npos);
@@ -83,7 +83,7 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
83
83
snapshot = listener.last_result ();
84
84
85
85
changes = snapshot.DocumentChanges ();
86
- EXPECT_EQ (changes.size (), 1 );
86
+ ASSERT_EQ (changes.size (), 1 );
87
87
EXPECT_EQ (changes[0 ].type (), DocumentChange::Type::kModified );
88
88
EXPECT_EQ (changes[0 ].document ().id (), doc2.id ());
89
89
EXPECT_EQ (changes[0 ].old_index (), 1 );
@@ -92,5 +92,67 @@ TEST_F(DocumentChangeTest, TestDocumentChanges) {
92
92
93
93
#endif // defined(__ANDROID__)
94
94
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
+
95
157
} // namespace firestore
96
158
} // namespace firebase
0 commit comments