@@ -147,30 +147,15 @@ TEST_F(FirebaseInstallationsTest, TestGettingIdTwiceMatches) {
147
147
if (!RunFlakyBlock (
148
148
[](firebase::installations::Installations* installations) {
149
149
firebase::Future<std::string> id = installations->GetId ();
150
- WaitForCompletionAnyResult (id, " GetId" );
151
- if (id.error () != 0 ) {
152
- LogError (" GetId returned error %d: %s" , id.error (),
153
- id.error_message ());
154
- return false ;
155
- }
156
- if (*id.result () == " " ) {
157
- LogError (" GetId returned blank" );
158
- return false ;
159
- }
150
+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId" );
151
+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
160
152
std::string first_id = *id.result ();
161
153
id = installations->GetId ();
162
- WaitForCompletionAnyResult (id, " GetId 2" );
163
- if (id.error () != 0 ) {
164
- LogError (" GetId 2 returned error %d: %s" , id.error (),
165
- id.error_message ());
166
- return false ;
167
- }
168
- if (*id.result () != first_id) {
169
- LogError (
170
- " GetId 2 returned non-matching ID: first(%s) vs second(%s)" ,
171
- first_id.c_str (), id.result ()->c_str ());
172
- return false ;
173
- }
154
+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId 2" );
155
+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
156
+
157
+ // Ensure the second ID returned is the same as the first.
158
+ FLAKY_EXPECT_EQ (*id.result (), first_id);
174
159
return true ;
175
160
},
176
161
installations_)) {
@@ -182,47 +167,24 @@ TEST_F(FirebaseInstallationsTest, TestDeleteGivesNewIdNextTime) {
182
167
if (!RunFlakyBlock (
183
168
[](firebase::installations::Installations* installations) {
184
169
firebase::Future<std::string> id = installations->GetId ();
185
- WaitForCompletionAnyResult (id, " GetId" );
186
- if (id.error () != 0 ) {
187
- LogError (" GetId returned error %d: %s" , id.error (),
188
- id.error_message ());
189
- return false ;
190
- }
191
- if (*id.result () == " " ) {
192
- LogError (" GetId returned blank" );
193
- return false ;
194
- }
170
+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId" );
171
+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
195
172
std::string first_id = *id.result ();
196
173
197
174
firebase::Future<void > del = installations->Delete ();
198
- WaitForCompletionAnyResult (del, " Delete" );
199
- if (del.error () != 0 ) {
200
- LogError (" Delete returned error %d: %s" , id.error (),
201
- id.error_message ());
202
- return false ;
203
- }
175
+ FLAKY_WAIT_FOR_COMPLETION (del, " Delete" );
204
176
205
177
// Ensure that we now get a different installations id.
206
178
id = installations->GetId ();
207
- WaitForCompletionAnyResult (id, " GetId 2" );
208
- if (id.error () != 0 ) {
209
- LogError (" GetId 2 returned error %d: %s" , id.error (),
210
- id.error_message ());
211
- return false ;
212
- }
213
- if (*id.result () == " " ) {
214
- LogError (" GetId 2 returned blank" );
215
- return false ;
216
- }
179
+ FLAKY_WAIT_FOR_COMPLETION (id, " GetId 2" );
180
+ FLAKY_EXPECT_NE (*id.result (), " " ); // ensure non-blank
217
181
#if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
218
182
// Desktop is a stub and returns the same ID, but on mobile it
219
183
// should return a new ID.
220
- if (*id.result () == first_id) {
221
- LogError (" IDs match (should be different): %s" , first_id.c_str ());
222
- return false ;
223
- }
184
+ FLAKY_EXPECT_NE (*id.result (), first_id);
224
185
#endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
225
186
// TARGET_OS_IPHONE)
187
+
226
188
return true ;
227
189
},
228
190
installations_)) {
@@ -237,34 +199,52 @@ TEST_F(FirebaseInstallationsTest, TestCanGetToken) {
237
199
}
238
200
239
201
TEST_F (FirebaseInstallationsTest, TestGettingTokenTwiceMatches) {
240
- firebase::Future<std::string> token = installations_->GetToken (false );
241
- WaitForCompletion (token, " GetToken" );
242
- EXPECT_NE (*token.result (), " " );
243
- std::string first_token = *token.result ();
244
- token = installations_->GetToken (false );
245
- WaitForCompletion (token, " GetToken 2" );
246
- EXPECT_EQ (*token.result (), first_token);
202
+ if (!RunFlakyBlock (
203
+ [](firebase::installations::Installations* installations) {
204
+ firebase::Future<std::string> token =
205
+ installations->GetToken (false );
206
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken" );
207
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
208
+ std::string first_token = *token.result ();
209
+ token = installations->GetToken (false );
210
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken 2" );
211
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
212
+ FLAKY_EXPECT_EQ (*token.result (), first_token);
213
+ return true ;
214
+ },
215
+ installations_)) {
216
+ FAIL () << " Test failed, check error log for details." ;
217
+ }
247
218
}
248
219
249
220
TEST_F (FirebaseInstallationsTest, TestDeleteGivesNewTokenNextTime) {
250
- firebase::Future<std::string> token = installations_->GetToken (false );
251
- WaitForCompletion (token, " GetToken" );
252
- EXPECT_NE (*token.result (), " " );
253
- std::string first_token = *token.result ();
221
+ if (!RunFlakyBlock (
222
+ [](firebase::installations::Installations* installations) {
223
+ firebase::Future<std::string> token =
224
+ installations->GetToken (false );
225
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken" );
226
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
227
+ std::string first_token = *token.result ();
254
228
255
- firebase::Future<void > del = installations_ ->Delete ();
256
- WaitForCompletion (del, " Delete" );
229
+ firebase::Future<void > del = installations ->Delete ();
230
+ FLAKY_WAIT_FOR_COMPLETION (del, " Delete" );
257
231
258
- // Ensure that we now get a different installations token.
259
- token = installations_ ->GetToken (false );
260
- WaitForCompletion (token, " GetToken 2" );
261
- EXPECT_NE (*token.result (), " " );
232
+ // Ensure that we now get a different installations token.
233
+ token = installations ->GetToken (false );
234
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken 2" );
235
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
262
236
#if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
263
- // Desktop is a stub and returns the same token, but on mobile it should
264
- // return a new token.
265
- EXPECT_NE (*token.result (), first_token);
237
+ // Desktop is a stub and returns the same token, but on mobile it
238
+ // should return a new token.
239
+ FLAKY_EXPECT_NE (*token.result (), first_token);
266
240
#endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
267
241
// TARGET_OS_IPHONE)
242
+
243
+ return true ;
244
+ },
245
+ installations_)) {
246
+ FAIL () << " Test failed, check error log for details." ;
247
+ }
268
248
}
269
249
270
250
TEST_F (FirebaseInstallationsTest, TestCanGetIdAndTokenTogether) {
0 commit comments