/src/flatbuffers/tests/fuzzer/test_init.h
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | #ifndef FUZZER_TEST_INIT_H_ |
3 | | #define FUZZER_TEST_INIT_H_ |
4 | | |
5 | | #include "fuzzer_assert.h" |
6 | | #include "test_assert.h" |
7 | | |
8 | | // Utility for test run. |
9 | | struct OneTimeTestInit { |
10 | | // Declare trap for the Flatbuffers test engine. |
11 | | // This hook terminate program both in Debug and Release. |
12 | | static bool TestFailListener(const char *expval, const char *val, |
13 | | const char *exp, const char *file, int line, |
14 | 0 | const char *func = nullptr) { |
15 | 0 | (void)expval; |
16 | 0 | (void)val; |
17 | 0 | (void)exp; |
18 | 0 | (void)file; |
19 | 0 | (void)line; |
20 | 0 | (void)func; |
21 | | // FLATBUFFERS_ASSERT redefined to be fully independent of the Flatbuffers |
22 | | // library implementation (see test_assert.h for details). |
23 | 0 | fuzzer_assert_impl(false); // terminate |
24 | 0 | return false; |
25 | 0 | } |
26 | | |
27 | 2 | OneTimeTestInit() : has_locale_(false) { |
28 | | // Fuzzer test should be independent of the test engine implementation. |
29 | | // This hook will terminate test if TEST_EQ/TEST_ASSERT asserted. |
30 | 2 | InitTestEngine(OneTimeTestInit::TestFailListener); |
31 | | |
32 | | // Read a locale for the test. |
33 | 2 | if (flatbuffers::ReadEnvironmentVariable("FLATBUFFERS_TEST_LOCALE", |
34 | 2 | &test_locale_)) { |
35 | 0 | TEST_OUTPUT_LINE("The environment variable FLATBUFFERS_TEST_LOCALE=%s", |
36 | 0 | test_locale_.c_str()); |
37 | 0 | test_locale_ = flatbuffers::RemoveStringQuotes(test_locale_); |
38 | 0 | has_locale_ = true; |
39 | 0 | } |
40 | 2 | } |
41 | | |
42 | 0 | static const char *test_locale() { |
43 | 0 | return one_time_init_.has_locale_ ? nullptr |
44 | 0 | : one_time_init_.test_locale_.c_str(); |
45 | 0 | } |
46 | | |
47 | | bool has_locale_; |
48 | | std::string test_locale_; |
49 | | static OneTimeTestInit one_time_init_; |
50 | | }; |
51 | | |
52 | | #endif // !FUZZER_TEST_INIT_H_ |