@@ -388,10 +388,20 @@ class FirebaseTest : public testing::Test {
388
388
// Google Play services version. Otherwise, returns 0.
389
389
static int GetGooglePlayServicesVersion ();
390
390
391
+ // Returns true if the future completed with one of the expected
392
+ // error codes, fails the test and returns false otherwise.
393
+ static bool WaitForCompletion (const firebase::FutureBase& future,
394
+ const char * name,
395
+ std::vector<int > expected_errors = {});
396
+
391
397
// Returns true if the future completed as expected, fails the test and
392
398
// returns false otherwise.
393
399
static bool WaitForCompletion (const firebase::FutureBase& future,
394
- const char * name, int expected_error = 0 );
400
+ const char * name, int expected_error) {
401
+ std::vector<int > error_list;
402
+ error_list.push_back (expected_error);
403
+ return WaitForCompletion (future, name, error_list);
404
+ }
395
405
396
406
// Just wait for completion, not caring what the result is (as long as
397
407
// it's not Invalid). Returns true, unless Invalid.
@@ -429,7 +439,7 @@ class FirebaseTest : public testing::Test {
429
439
// exponential backoff if the operation fails.
430
440
//
431
441
// Blocks until the operation succeeds (the Future completes, with error
432
- // matching expected_error ) or if the final attempt is started (in which case
442
+ // matching expected_errors ) or if the final attempt is started (in which case
433
443
// the Future returned may still be in progress). You should use
434
444
// WaitForCompletion to await the results of this function in any case.
435
445
//
@@ -445,10 +455,9 @@ class FirebaseTest : public testing::Test {
445
455
// return auth->DeleteUser(auth->current_user());
446
456
// }, auth_), "DeleteUser"));
447
457
template <class CallbackType , class ContextType >
448
- static firebase::FutureBase RunWithRetry (CallbackType run_future_typed,
449
- ContextType* context_typed,
450
- const char * name = " " ,
451
- int expected_error = 0 ) {
458
+ static firebase::FutureBase RunWithRetry (
459
+ CallbackType run_future_typed, ContextType* context_typed,
460
+ const char * name = " " , std::vector<int > expected_errors = {}) {
452
461
struct RunData {
453
462
CallbackType callback;
454
463
ContextType* context;
@@ -460,7 +469,7 @@ class FirebaseTest : public testing::Test {
460
469
ContextType* context = static_cast <RunData*>(ctx)->context ;
461
470
return static_cast <firebase::FutureBase>(callback (context));
462
471
},
463
- static_cast <void *>(&run_data), name, expected_error );
472
+ static_cast <void *>(&run_data), name, expected_errors );
464
473
}
465
474
466
475
// Same as RunWithRetry, but templated to return a Future<ResultType>
@@ -470,7 +479,7 @@ class FirebaseTest : public testing::Test {
470
479
template <class ResultType , class CallbackType , class ContextType >
471
480
static firebase::Future<ResultType> RunWithRetry (
472
481
CallbackType run_future_typed, ContextType* context_typed,
473
- const char * name = " " , int expected_error = 0 ) {
482
+ const char * name = " " , std::vector< int > expected_errors = {} ) {
474
483
struct RunData {
475
484
CallbackType callback;
476
485
ContextType* context;
@@ -486,15 +495,15 @@ class FirebaseTest : public testing::Test {
486
495
firebase::Future<ResultType> future_result = callback (context);
487
496
return static_cast <firebase::FutureBase>(future_result);
488
497
},
489
- static_cast <void *>(&run_data), name, expected_error );
498
+ static_cast <void *>(&run_data), name, expected_errors );
490
499
// Future<T> and FutureBase are reinterpret_cast-compatible, by design.
491
500
return *reinterpret_cast <firebase::Future<ResultType>*>(&result_base);
492
501
}
493
502
494
503
// Same as RunWithRetry above, but use std::function to allow captures.
495
504
static firebase::FutureBase RunWithRetry (
496
505
std::function<firebase::FutureBase()> run_future, const char* name = "",
497
- int expected_error = 0 ) {
506
+ std::vector< int> expected_errors = {} ) {
498
507
struct RunData {
499
508
std::function<firebase::FutureBase()>* callback;
500
509
};
@@ -504,13 +513,13 @@ class FirebaseTest : public testing::Test {
504
513
auto & callback = *static_cast <RunData*>(ctx)->callback ;
505
514
return static_cast <firebase::FutureBase>(callback ());
506
515
},
507
- static_cast <void *>(&run_data), name, expected_error );
516
+ static_cast <void *>(&run_data), name, expected_errors );
508
517
}
509
518
// Same as RunWithRetry<type>, but use std::function to allow captures.
510
519
template <class ResultType >
511
520
static firebase::Future<ResultType> RunWithRetry (
512
521
std::function<firebase::Future<ResultType>()> run_future,
513
- const char* name = "", int expected_error = 0 ) {
522
+ const char* name = "", std::vector< int> expected_errors = {} ) {
514
523
struct RunData {
515
524
std::function<firebase::Future<ResultType>()>* callback;
516
525
};
@@ -524,7 +533,7 @@ class FirebaseTest : public testing::Test {
524
533
firebase::Future<ResultType> future_result = callback ();
525
534
return static_cast <firebase::FutureBase>(future_result);
526
535
},
527
- static_cast <void *>(&run_data), name, expected_error );
536
+ static_cast <void *>(&run_data), name, expected_errors );
528
537
// Future<T> and FutureBase are reinterpret_cast-compatible, by design.
529
538
return *reinterpret_cast <firebase::Future<ResultType>*>(&result_base);
530
539
}
@@ -569,7 +578,17 @@ class FirebaseTest : public testing::Test {
569
578
// for type safety.
570
579
static firebase::FutureBase RunWithRetryBase (
571
580
firebase::FutureBase (*run_future)(void * context), void * context,
572
- const char * name, int expected_error);
581
+ const char * name, std::vector<int > expected_errors);
582
+
583
+ // Untyped version of RunWithRetry with one expected error.
584
+ static firebase::FutureBase RunWithRetryBase (
585
+ firebase::FutureBase (*run_future)(void * context), void * context,
586
+ const char * name, int expected_error) {
587
+ std::vector<int > error_list;
588
+ error_list.push_back (expected_error);
589
+ return RunWithRetryBase (run_future, context, name, error_list);
590
+ }
591
+
573
592
// Untyped version of RunFlakyBlock, with implementation.
574
593
// This is kept private because the templated version should be used instead,
575
594
// for type safety.
0 commit comments