-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathfirebase_test_framework.h
More file actions
645 lines (578 loc) · 27.7 KB
/
firebase_test_framework.h
File metadata and controls
645 lines (578 loc) · 27.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
// Copyright 2019 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef FIREBASE_TEST_FRAMEWORK_H_ // NOLINT
#define FIREBASE_TEST_FRAMEWORK_H_ // NOLINT
#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "app_framework.h" // NOLINT
#include "firebase/app.h"
#include "firebase/future.h"
#include "firebase/internal/platform.h"
#include "firebase/util.h"
#include "firebase/variant.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
// Include this internal header so we have access to UnitTestImpl and
// ClearTestPartResults. We are not supposed to use these, but we do anyway as a
// workaround for handling flaky test sections.
#include "gtest/../../src/gtest-internal-inl.h"
namespace firebase_test_framework {
// Use this macro to skip an entire test if it is an non UI Test and we are
// not running it in UItest mode (for example, on UI Test workflow).
#define TEST_DOES_NOT_REQUIRE_USER_INTERACTION \
if (!ShouldRunNonUITests()) { \
app_framework::LogInfo( \
"Skipping %s, as it is a Non UI Test.", \
::testing::UnitTest::GetInstance()->current_test_info()->name()); \
GTEST_SKIP(); \
return; \
}
// Use this macro to skip an entire test if it requires interactivity and we are
// not running in interactive mode (for example, on FTL).
#define TEST_REQUIRES_USER_INTERACTION \
if (!ShouldRunUITests()) { \
app_framework::LogInfo( \
"Skipping %s, as it requires user interaction.", \
::testing::UnitTest::GetInstance()->current_test_info()->name()); \
GTEST_SKIP(); \
return; \
}
#define RUN_TEST_ONLY_AGAINST_FIRESTORE_EMULATOR \
{ \
if (std::getenv("USE_FIRESTORE_EMULATOR") == nullptr) { \
app_framework::LogInfo( \
"Skipping %s on non firestore emulator environment.", \
test_info_->name()); \
GTEST_SKIP(); \
return; \
} \
}
#if TARGET_OS_IPHONE
#define TEST_REQUIRES_USER_INTERACTION_ON_IOS TEST_REQUIRES_USER_INTERACTION
#define TEST_REQUIRES_USER_INTERACTION_ON_ANDROID ((void)0)
#elif defined(ANDROID)
#define TEST_REQUIRES_USER_INTERACTION_ON_IOS ((void)0)
#define TEST_REQUIRES_USER_INTERACTION_ON_ANDROID TEST_REQUIRES_USER_INTERACTION
#else
#define TEST_REQUIRES_USER_INTERACTION_ON_IOS ((void)0)
#define TEST_REQUIRES_USER_INTERACTION_ON_ANDROID ((void)0)
#endif // TARGET_OS_IPHONE
// Macros for skipping tests on various platforms.
//
// Simply place the macro at the top of the test to skip that test on
// the given platform.
// For example:
// TEST_F(MyFirebaseTest, TestThatFailsOnDesktop) {
// SKIP_TEST_ON_DESKTOP;
// EXPECT_TRUE(do_test_things(...))
// }
//
// SKIP_TEST_ON_MOBILE
// SKIP_TEST_ON_IOS
// SKIP_TEST_ON_ANDROID
// SKIP_TEST_ON_DESKTOP
// SKIP_TEST_ON_LINUX
// SKIP_TEST_ON_WINDOWS
// SKIP_TEST_ON_MACOS
// SKIP_TEST_ON_SIMULATOR / SKIP_TEST_ON_EMULATOR (identical)
// SKIP_TEST_ON_IOS_SIMULATOR / SKIP_TEST_ON_ANDROID_EMULATOR
// SKIP_TEST_ON_ANDROID_IF_GOOGLE_PLAY_SERVICES_IS_OLDER_THAN(version_code)
//
// Also includes a special macro SKIP_TEST_IF_USING_STLPORT if compiling for
// Android STLPort, which does not fully support C++11.
#if !defined(ANDROID) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#define SKIP_TEST_ON_DESKTOP \
{ \
app_framework::LogInfo("Skipping %s on desktop.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_DESKTOP ((void)0)
#endif // !defined(ANDROID) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#if (defined(TARGET_OS_OSX) && TARGET_OS_OSX)
#define SKIP_TEST_ON_MACOS \
{ \
app_framework::LogInfo("Skipping %s on MacOS.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_MACOS ((void)0)
#endif // (defined(TARGET_OS_OSX) && TARGET_OS_OSX)
#if defined(_WIN32)
// defined when the compilation target is 32-bit ARM, 64-bit ARM, x86, x64
#define SKIP_TEST_ON_WINDOWS \
{ \
app_framework::LogInfo("Skipping %s on Windows.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#if !defined(_WIN64)
// _WIN64 is defined for 64-bit targets (e.g., x64, 64-bit ARM).
// Its absence on a Windows build indicates a 32-bit target.
#define SKIP_TEST_ON_WINDOWS_32BIT \
{ \
app_framework::LogInfo("Skipping %s on 32-bit Windows.", \
test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_WINDOWS_32BIT ((void)0)
#endif // !defined(_WIN64)
#else
#define SKIP_TEST_ON_WINDOWS ((void)0)
#define SKIP_TEST_ON_WINDOWS_32BIT ((void)0)
#endif // defined(_WIN32)
#if defined(__linux__)
#define SKIP_TEST_ON_LINUX \
{ \
app_framework::LogInfo("Skipping %s on Linux.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_LINUX ((void)0)
#endif // defined(__linux__)
#if defined(ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#define SKIP_TEST_ON_MOBILE \
{ \
app_framework::LogInfo("Skipping %s on mobile.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_MOBILE ((void)0)
#endif // defined(ANDROID) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#if (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#define SKIP_TEST_ON_IOS \
{ \
app_framework::LogInfo("Skipping %s on iOS.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_IOS ((void)0)
#endif // (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
#if (defined(TARGET_OS_TV) && TARGET_OS_TV)
#define SKIP_TEST_ON_TVOS \
{ \
app_framework::LogInfo("Skipping %s on tvOS.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_TVOS ((void)0)
#endif // (defined(TARGET_OS_TV) && TARGET_OS_TV)
#if defined(ANDROID)
#define SKIP_TEST_ON_ANDROID \
{ \
app_framework::LogInfo("Skipping %s on Android.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_ANDROID ((void)0)
#endif // defined(ANDROID)
// Skip on physical mobile device.
#if !defined(ANDROID) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
// Allow desktop.
#define SKIP_TEST_ON_MOBILE_HARDWARE ((void)0)
#else
// Android needs to determine emulator at runtime, so we can't just use #ifdef.
#define SKIP_TEST_ON_MOBILE_HARDWARE \
{ \
if (!IsRunningOnEmulator()) { \
app_framework::LogInfo("Skipping %s on mobile hardware.", \
test_info_->name()); \
GTEST_SKIP(); \
return; \
} \
}
#endif // !defined(ANDROID) && !(defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
// Android needs to determine emulator at runtime, so we can't just use #ifdef.
#define SKIP_TEST_ON_SIMULATOR \
{ \
if (IsRunningOnEmulator()) { \
app_framework::LogInfo("Skipping %s on simulator/emulator.", \
test_info_->name()); \
GTEST_SKIP(); \
return; \
} \
}
// Accept either name, simulator or emulator.
#define SKIP_TEST_ON_EMULATOR SKIP_TEST_ON_SIMULATOR
#if defined(ANDROID)
#define SKIP_TEST_ON_ANDROID_EMULATOR SKIP_TEST_ON_EMULATOR
#define SKIP_TEST_ON_IOS_SIMULATOR ((void)0)
#elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
#define SKIP_TEST_ON_ANDROID_EMULATOR ((void)0)
#define SKIP_TEST_ON_IOS_SIMULATOR SKIP_TEST_ON_SIMULATOR
#else
#define SKIP_TEST_ON_IOS_SIMULATOR ((void)0)
#define SKIP_TEST_ON_ANDROID_EMULATOR ((void)0)
#endif
#if defined(ANDROID)
#define SKIP_TEST_ON_ANDROID_IF_GOOGLE_PLAY_SERVICES_IS_OLDER_THAN(x) \
{ \
int _required_ver_ = (x); \
/* Example: 23.1.2 has version code 230102???. */ \
/* Allow specifying version as 230102 or as 230102000. */ \
if (_required_ver_ < 10000000) { \
_required_ver_ *= 1000; \
} \
int _actual_ver_ = GetGooglePlayServicesVersion(); \
if (_actual_ver_ > 0 && _actual_ver_ < _required_ver_) { \
app_framework::LogInfo( \
"Skipping %s, as Google Play services %d is below required %d", \
test_info_->name(), _actual_ver_, _required_ver_); \
GTEST_SKIP(); \
return; \
} \
}
#else
#define SKIP_TEST_ON_ANDROID_IF_GOOGLE_PLAY_SERVICES_IS_OLDER_THAN(x) ((void)0)
#endif // defined(ANDROID)
#if defined(STLPORT)
#define SKIP_TEST_IF_USING_STLPORT \
{ \
app_framework::LogInfo("Skipping %s due to incompatibility with STLPort.", \
test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_IF_USING_STLPORT ((void)0)
#endif // defined(STLPORT)
#if defined(QUICK_CHECK)
#define SKIP_TEST_ON_QUICK_CHECK \
{ \
app_framework::LogInfo("Skipping %s on quick check.", test_info_->name()); \
GTEST_SKIP(); \
return; \
}
#else
#define SKIP_TEST_ON_QUICK_CHECK ((void)0)
#endif // defined(QUICK_CHECK)
#define KNOWN_FAILURE(explanation) \
{ FAIL() << test_info_->name() << " has a known failure: " << explanation; }
#if FIREBASE_PLATFORM_LINUX || FIREBASE_PLATFORM_OSX
#define DEATHTEST_SIGABRT "SIGABRT"
#else
#define DEATHTEST_SIGABRT ""
#endif
// Macros to surround a flaky section of your test.
// If this section fails, it will retry several times until it succeeds.
#define FLAKY_TEST_SECTION_BEGIN() RunFlakyTestSection([&]() { (void)0
#define FLAKY_TEST_SECTION_END() \
})
class FirebaseTest : public testing::Test {
public:
FirebaseTest();
~FirebaseTest() override;
void SetUp() override;
void TearDown() override;
// Check the given directory, the current directory, and the directory
// containing the binary for google-services.json, and change to whichever
// directory contains it.
static void FindFirebaseConfig(const char* try_directory);
static void SetArgs(int argc, char* argv[]) {
argc_ = argc;
argv_ = argv;
}
// Convert a Variant into a string (including all nested Variants) for
// debugging.
static std::string VariantToString(const firebase::Variant& variant);
// Run an operation that returns a bool. If it fails (and the bool returns
// false), try it again, after a short delay. Returns true once it succeeds,
// or if it fails enough times, returns false.
// This is designed to allow you to try a flaky set of operations multiple
// times until it succeeds.
//
// Note that the callback must return a bool or a type implicitly convertable
// to bool.
template <class CallbackType, class ContextType>
static bool RunFlakyBlock(CallbackType flaky_callback,
ContextType* context_typed, const char* name = "") {
struct RunData {
CallbackType callback;
ContextType* context;
};
RunData run_data = {flaky_callback, context_typed};
return RunFlakyBlockBase(
[](void* ctx) {
CallbackType callback = static_cast<RunData*>(ctx)->callback;
ContextType* context = static_cast<RunData*>(ctx)->context;
return callback(context);
},
static_cast<void*>(&run_data), name);
}
// Same as RunFlakyBlock above, but use std::function to allow captures.
static bool RunFlakyBlock(std::function<bool()> flaky_callback,
const char* name = "") {
struct RunData {
std::function<bool()>* callback;
};
RunData run_data = {&flaky_callback};
return RunFlakyBlockBase(
[](void* ctx) {
auto& callback = *static_cast<RunData*>(ctx)->callback;
return callback();
},
static_cast<void*>(&run_data), name);
}
protected:
// Set up firebase::App with default settings.
void InitializeApp();
// Shut down firebase::App.
void TerminateApp();
// Returns true if interactive tests are allowed, false if only
// fully-automated tests should be run.
bool AreInteractiveTestsAllowed();
// Give the static helper methods "public" visibility so that they can be used
// by helper functions defined outside of subclasses of `FirebaseTest`, such
// as functions defined in anonymous namespaces.
public:
// Get a persistent string value that was previously set via
// SetPersistentString. Returns true if the value was set, false if not or if
// something went wrong.
static bool GetPersistentString(const char* key, std::string* value_out);
// Set a persistent string value that can be accessed the next time the test
// loads. Specify nullptr for value to delete the key. Returns true if
// successful, false if something went wrong.
static bool SetPersistentString(const char* key, const char* value);
// Return true if the app is running on simulator/emulator, false if
// on a real device (or on desktop).
static bool IsRunningOnEmulator();
// If on Android and Google Play services is available, returns the
// Google Play services version. Otherwise, returns 0.
static int GetGooglePlayServicesVersion();
// Returns true if the future completed with one of the expected
// error codes, fails the test and returns false otherwise.
static bool WaitForCompletion(const firebase::FutureBase& future,
const char* name,
std::vector<int> expected_errors = {});
// Returns true if the future completed as expected, fails the test and
// returns false otherwise.
static bool WaitForCompletion(const firebase::FutureBase& future,
const char* name, int expected_error) {
std::vector<int> error_list;
error_list.push_back(expected_error);
return WaitForCompletion(future, name, error_list);
}
// Just wait for completion, not caring what the result is (as long as
// it's not Invalid). Returns true, unless Invalid.
static bool WaitForCompletionAnyResult(const firebase::FutureBase& future,
const char* name);
// Run a flaky section of a test. If any expectations fail, it will clear
// those failures and retry the section.
//
// Typically, you wouldn't use this method directly. Instead, you should use
// it via the FLAKY_TEST_SECTION_BEGIN() and FLAKY_TEST_SECTION_END() macros
// defined above.
//
// For example:
// TEST_F(MyTestClass, MyTestCase) {
// /* do some non-flaky stuff here */
// FLAKY_TEST_SECTION_BEGIN();
// /* do some stuff that might need to be retried here */
// FLAKY_TEST_SECTION_END();
// /* do some more non-flaky stuff here */
// }
void RunFlakyTestSection(std::function<void()> flaky_test_section) {
// Save the current state of test results.
auto saved_test_results = SaveTestPartResults();
RunFlakyBlock([&]() {
RestoreTestPartResults(saved_test_results);
flaky_test_section();
return !HasFailure();
});
}
// Run an operation that returns a Future (via a callback), retrying with
// exponential backoff if the operation fails.
//
// Blocks until the operation succeeds (the Future completes, with error
// matching expected_errors) or if the final attempt is started (in which case
// the Future returned may still be in progress). You should use
// WaitForCompletion to await the results of this function in any case.
//
// For example, to add retry, you would change:
//
// bool success = WaitForCompletion(
// auth_->DeleteUser(auth->current_user()),
// "DeleteUser");
// To this:
//
// bool success = WaitForCompletion(RunWithRetry(
// [](Auth* auth) {
// return auth->DeleteUser(auth->current_user());
// }, auth_), "DeleteUser"));
template <class CallbackType, class ContextType>
static firebase::FutureBase RunWithRetry(
CallbackType run_future_typed, ContextType* context_typed,
const char* name = "", std::vector<int> expected_errors = {}) {
struct RunData {
CallbackType callback;
ContextType* context;
};
RunData run_data = {run_future_typed, context_typed};
return RunWithRetryBase(
[](void* ctx) {
CallbackType callback = static_cast<RunData*>(ctx)->callback;
ContextType* context = static_cast<RunData*>(ctx)->context;
return static_cast<firebase::FutureBase>(callback(context));
},
static_cast<void*>(&run_data), name, expected_errors);
}
// Same as RunWithRetry, but templated to return a Future<ResultType>
// rather than a FutureBase, in case you want to use the result data
// of the Future. You need to explicitly provide the template parameter,
// e.g. RunWithRetry<int>(..) to return a Future<int>.
template <class ResultType, class CallbackType, class ContextType>
static firebase::Future<ResultType> RunWithRetry(
CallbackType run_future_typed, ContextType* context_typed,
const char* name = "", std::vector<int> expected_errors = {}) {
struct RunData {
CallbackType callback;
ContextType* context;
};
RunData run_data = {run_future_typed, context_typed};
firebase::FutureBase result_base = RunWithRetryBase(
[](void* ctx) {
CallbackType callback = static_cast<RunData*>(ctx)->callback;
ContextType* context = static_cast<RunData*>(ctx)->context;
// The following line checks that CallbackType actually returns a
// Future<ResultType>. If it returns any other type, the compiler will
// complain about implicit conversion to Future<ResultType> here.
firebase::Future<ResultType> future_result = callback(context);
return static_cast<firebase::FutureBase>(future_result);
},
static_cast<void*>(&run_data), name, expected_errors);
// Future<T> and FutureBase are reinterpret_cast-compatible, by design.
return *reinterpret_cast<firebase::Future<ResultType>*>(&result_base);
}
// Same as RunWithRetry above, but use std::function to allow captures.
static firebase::FutureBase RunWithRetry(
std::function<firebase::FutureBase()> run_future, const char* name = "",
std::vector<int> expected_errors = {}) {
struct RunData {
std::function<firebase::FutureBase()>* callback;
};
RunData run_data = {&run_future};
return RunWithRetryBase(
[](void* ctx) {
auto& callback = *static_cast<RunData*>(ctx)->callback;
return static_cast<firebase::FutureBase>(callback());
},
static_cast<void*>(&run_data), name, expected_errors);
}
// Same as RunWithRetry<type>, but use std::function to allow captures.
template <class ResultType>
static firebase::Future<ResultType> RunWithRetry(
std::function<firebase::Future<ResultType>()> run_future,
const char* name = "", std::vector<int> expected_errors = {}) {
struct RunData {
std::function<firebase::Future<ResultType>()>* callback;
};
RunData run_data = {&run_future};
firebase::FutureBase result_base = RunWithRetryBase(
[](void* ctx) {
auto& callback = *static_cast<RunData*>(ctx)->callback;
// The following line checks that CallbackType actually returns a
// Future<ResultType>. If it returns any other type, the compiler will
// complain about implicit conversion to Future<ResultType> here.
firebase::Future<ResultType> future_result = callback();
return static_cast<firebase::FutureBase>(future_result);
},
static_cast<void*>(&run_data), name, expected_errors);
// Future<T> and FutureBase are reinterpret_cast-compatible, by design.
return *reinterpret_cast<firebase::Future<ResultType>*>(&result_base);
}
// Blocking HTTP request helper function, for testing only.
static bool SendHttpGetRequest(
const char* url, const std::map<std::string, std::string>& headers,
int* response_code, std::string* response);
// Blocking HTTP request helper function, for testing only.
static bool SendHttpPostRequest(
const char* url, const std::map<std::string, std::string>& headers,
const std::string& post_body, int* response_code, std::string* response);
// Open a URL in a browser window, for testing only.
static bool OpenUrlInBrowser(const char* url);
// Returns true if we run tests that require interaction, false if not.
static bool ShouldRunUITests();
// Returns true if we run tests that do not require interaction, false if
// not.
static bool ShouldRunNonUITests();
// Encode a binary string to base64. Returns true if the encoding succeeded,
// false if it failed.
static bool Base64Encode(const std::string& input, std::string* output);
// Decode a base64 string to binary. Returns true if the decoding succeeded,
// false if it failed.
static bool Base64Decode(const std::string& input, std::string* output);
static std::string GetDebugDeviceId();
// Get the current time in seconds since epoch. On desktop, this will use the
// local machine's time. On mobile, it will retrieve UTC time from a server if
// possible, otherwise use the local machine's time.
int64_t GetCurrentTimeInSecondsSinceEpoch();
firebase::App* app_;
static int argc_;
static char** argv_;
static bool found_config_;
private:
// Untyped version of RunWithRetry, with implementation.
// This is kept private because the templated version should be used instead,
// for type safety.
static firebase::FutureBase RunWithRetryBase(
firebase::FutureBase (*run_future)(void* context), void* context,
const char* name, std::vector<int> expected_errors);
// Untyped version of RunWithRetry with one expected error.
static firebase::FutureBase RunWithRetryBase(
firebase::FutureBase (*run_future)(void* context), void* context,
const char* name, int expected_error) {
std::vector<int> error_list;
error_list.push_back(expected_error);
return RunWithRetryBase(run_future, context, name, error_list);
}
// Untyped version of RunFlakyBlock, with implementation.
// This is kept private because the templated version should be used instead,
// for type safety.
static bool RunFlakyBlockBase(bool (*flaky_block)(void* context),
void* context, const char* name = "");
std::vector<::testing::TestPartResult> SaveTestPartResults() {
return ::testing::internal::TestResultAccessor::test_part_results(
*::testing::internal::GetUnitTestImpl()->current_test_result());
}
void RestoreTestPartResults(
const std::vector<::testing::TestPartResult>& test_part_results) {
const std::vector<testing::TestPartResult>& existing_results =
::testing::internal::TestResultAccessor::test_part_results(
*::testing::internal::GetUnitTestImpl()->current_test_result());
// Overwrite the existing test_part_results with the previously-saved
// version.
const_cast<std::vector<testing::TestPartResult>&>(existing_results)
.assign(test_part_results.begin(), test_part_results.end());
}
};
} // namespace firebase_test_framework
namespace firebase {
// Define an operator<< for Variant so that googletest can output its values
// nicely.
std::ostream& operator<<(std::ostream& os, const Variant& v);
} // namespace firebase
extern "C" int common_main(int argc, char* argv[]);
#endif // FIREBASE_TEST_FRAMEWORK_H_ // NOLINT