@@ -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,25 @@ 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
181
+
217
182
#if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
218
183
// Desktop is a stub and returns the same ID, but on mobile it
219
184
// 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
- }
185
+ FLAKY_EXPECT_NE (*id.result (), first_id);
224
186
#endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
225
187
// TARGET_OS_IPHONE)
188
+
226
189
return true ;
227
190
},
228
191
installations_)) {
@@ -241,35 +204,13 @@ TEST_F(FirebaseInstallationsTest, TestGettingTokenTwiceMatches) {
241
204
[](firebase::installations::Installations* installations) {
242
205
firebase::Future<std::string> token =
243
206
installations->GetToken (false );
244
- WaitForCompletionAnyResult (token, " GetToken" );
245
- if (token.error () != 0 ) {
246
- LogError (" GetToken returned error %d: %s" , token.error (),
247
- token.error_message ());
248
- return false ;
249
- }
250
- if (*token.result () == " " ) {
251
- LogError (" GetToken returned blank" );
252
- return false ;
253
- }
207
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken" );
208
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
254
209
std::string first_token = *token.result ();
255
210
token = installations->GetToken (false );
256
- WaitForCompletionAnyResult (token, " GetToken 2" );
257
- if (token.error () != 0 ) {
258
- LogError (" GetId 2 returned error %d: %s" , token.error (),
259
- token.error_message ());
260
- return false ;
261
- }
262
- if (*token.result () == " " ) {
263
- LogError (" GetToken 2 returned blank" );
264
- return false ;
265
- }
266
- if (*token.result () != first_token) {
267
- LogError (
268
- " GetToken 2 returned non-matching token: first(%s) vs "
269
- " second(%s)" ,
270
- first_token.c_str (), token.result ()->c_str ());
271
- return false ;
272
- }
211
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken 2" );
212
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
213
+ FLAKY_EXPECT_EQ (*token.result (), first_token);
273
214
return true ;
274
215
},
275
216
installations_)) {
@@ -282,48 +223,25 @@ TEST_F(FirebaseInstallationsTest, TestDeleteGivesNewTokenNextTime) {
282
223
[](firebase::installations::Installations* installations) {
283
224
firebase::Future<std::string> token =
284
225
installations->GetToken (false );
285
- WaitForCompletionAnyResult (token, " GetToken" );
286
- if (token.error () != 0 ) {
287
- LogError (" GetToken returned error %d: %s" , token.error (),
288
- token.error_message ());
289
- return false ;
290
- }
291
- if (*token.result () == " " ) {
292
- LogError (" GetToken returned blank" );
293
- return false ;
294
- }
226
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken" );
227
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
295
228
std::string first_token = *token.result ();
296
229
297
230
firebase::Future<void > del = installations->Delete ();
298
- WaitForCompletionAnyResult (del, " Delete" );
299
- if (del.error () != 0 ) {
300
- LogError (" Delete returned error %d: %s" , token.error (),
301
- token.error_message ());
302
- return false ;
303
- }
231
+ FLAKY_WAIT_FOR_COMPLETION (del, " Delete" );
304
232
305
233
// Ensure that we now get a different installations token.
306
234
token = installations->GetToken (false );
307
- WaitForCompletionAnyResult (token, " GetToken 2" );
308
- if (token.error () != 0 ) {
309
- LogError (" GetToken 2 returned error %d: %s" , token.error (),
310
- token.error_message ());
311
- return false ;
312
- }
313
- if (*token.result () == " " ) {
314
- LogError (" GetToken 2 returned blank" );
315
- return false ;
316
- }
235
+ FLAKY_WAIT_FOR_COMPLETION (token, " GetToken 2" );
236
+ FLAKY_EXPECT_NE (*token.result (), " " ); // ensure non-blank
237
+
317
238
#if defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
318
239
// Desktop is a stub and returns the same token, but on mobile it
319
240
// should return a new token.
320
- if (*token.result () == first_token) {
321
- LogError (" Tokens match (should be different): %s" ,
322
- first_token.c_str ());
323
- return false ;
324
- }
241
+ FLAKY_EXPECT_EQ (*token.result (), first_token);
325
242
#endif // defined(__ANDROID__) || (defined(TARGET_OS_IPHONE) &&
326
243
// TARGET_OS_IPHONE)
244
+
327
245
return true ;
328
246
},
329
247
installations_)) {
0 commit comments