...
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.
9struct 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 const char *func = nullptr) {
15 (void)expval;
16 (void)val;
17 (void)exp;
18 (void)file;
19 (void)line;
20 (void)func;
21 // FLATBUFFERS_ASSERT redefined to be fully independent of the Flatbuffers
22 // library implementation (see test_assert.h for details).
23 fuzzer_assert_impl(false); // terminate
24 return false;
25 }
26
27 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 InitTestEngine(OneTimeTestInit::TestFailListener);
31
32 // Read a locale for the test.
33 if (flatbuffers::ReadEnvironmentVariable("FLATBUFFERS_TEST_LOCALE",
34 &test_locale_)) {
35 TEST_OUTPUT_LINE("The environment variable FLATBUFFERS_TEST_LOCALE=%s",
36 test_locale_.c_str());
37 test_locale_ = flatbuffers::RemoveStringQuotes(test_locale_);
38 has_locale_ = true;
39 }
40 }
41
42 static const char *test_locale() {
43 return one_time_init_.has_locale_ ? nullptr
44 : one_time_init_.test_locale_.c_str();
45 }
46
47 bool has_locale_;
48 std::string test_locale_;
49 static OneTimeTestInit one_time_init_;
50};
51
52#endif // !FUZZER_TEST_INIT_H_
View as plain text