@@ -388,10 +388,20 @@ class FirebaseTest : public testing::Test {
388388 // Google Play services version. Otherwise, returns 0.
389389 static int GetGooglePlayServicesVersion ();
390390
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+
391397 // Returns true if the future completed as expected, fails the test and
392398 // returns false otherwise.
393399 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+ }
395405
396406 // Just wait for completion, not caring what the result is (as long as
397407 // it's not Invalid). Returns true, unless Invalid.
@@ -429,7 +439,7 @@ class FirebaseTest : public testing::Test {
429439 // exponential backoff if the operation fails.
430440 //
431441 // 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
433443 // the Future returned may still be in progress). You should use
434444 // WaitForCompletion to await the results of this function in any case.
435445 //
@@ -445,10 +455,9 @@ class FirebaseTest : public testing::Test {
445455 // return auth->DeleteUser(auth->current_user());
446456 // }, auth_), "DeleteUser"));
447457 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 = {}) {
452461 struct RunData {
453462 CallbackType callback;
454463 ContextType* context;
@@ -460,7 +469,7 @@ class FirebaseTest : public testing::Test {
460469 ContextType* context = static_cast <RunData*>(ctx)->context ;
461470 return static_cast <firebase::FutureBase>(callback (context));
462471 },
463- static_cast <void *>(&run_data), name, expected_error );
472+ static_cast <void *>(&run_data), name, expected_errors );
464473 }
465474
466475 // Same as RunWithRetry, but templated to return a Future<ResultType>
@@ -470,7 +479,7 @@ class FirebaseTest : public testing::Test {
470479 template <class ResultType , class CallbackType , class ContextType >
471480 static firebase::Future<ResultType> RunWithRetry (
472481 CallbackType run_future_typed, ContextType* context_typed,
473- const char * name = " " , int expected_error = 0 ) {
482+ const char * name = " " , std::vector< int > expected_errors = {} ) {
474483 struct RunData {
475484 CallbackType callback;
476485 ContextType* context;
@@ -486,15 +495,15 @@ class FirebaseTest : public testing::Test {
486495 firebase::Future<ResultType> future_result = callback (context);
487496 return static_cast <firebase::FutureBase>(future_result);
488497 },
489- static_cast <void *>(&run_data), name, expected_error );
498+ static_cast <void *>(&run_data), name, expected_errors );
490499 // Future<T> and FutureBase are reinterpret_cast-compatible, by design.
491500 return *reinterpret_cast <firebase::Future<ResultType>*>(&result_base);
492501 }
493502
494503 // Same as RunWithRetry above, but use std::function to allow captures.
495504 static firebase::FutureBase RunWithRetry (
496505 std::function<firebase::FutureBase()> run_future, const char* name = "",
497- int expected_error = 0 ) {
506+ std::vector< int> expected_errors = {} ) {
498507 struct RunData {
499508 std::function<firebase::FutureBase()>* callback;
500509 };
@@ -504,13 +513,13 @@ class FirebaseTest : public testing::Test {
504513 auto & callback = *static_cast <RunData*>(ctx)->callback ;
505514 return static_cast <firebase::FutureBase>(callback ());
506515 },
507- static_cast <void *>(&run_data), name, expected_error );
516+ static_cast <void *>(&run_data), name, expected_errors );
508517 }
509518 // Same as RunWithRetry<type>, but use std::function to allow captures.
510519 template <class ResultType >
511520 static firebase::Future<ResultType> RunWithRetry (
512521 std::function<firebase::Future<ResultType>()> run_future,
513- const char* name = "", int expected_error = 0 ) {
522+ const char* name = "", std::vector< int> expected_errors = {} ) {
514523 struct RunData {
515524 std::function<firebase::Future<ResultType>()>* callback;
516525 };
@@ -524,7 +533,7 @@ class FirebaseTest : public testing::Test {
524533 firebase::Future<ResultType> future_result = callback ();
525534 return static_cast <firebase::FutureBase>(future_result);
526535 },
527- static_cast <void *>(&run_data), name, expected_error );
536+ static_cast <void *>(&run_data), name, expected_errors );
528537 // Future<T> and FutureBase are reinterpret_cast-compatible, by design.
529538 return *reinterpret_cast <firebase::Future<ResultType>*>(&result_base);
530539 }
@@ -569,7 +578,17 @@ class FirebaseTest : public testing::Test {
569578 // for type safety.
570579 static firebase::FutureBase RunWithRetryBase (
571580 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+
573592 // Untyped version of RunFlakyBlock, with implementation.
574593 // This is kept private because the templated version should be used instead,
575594 // for type safety.
0 commit comments