File: test_init.h

package info (click to toggle)
golang-github-google-flatbuffers 24.12.23-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,704 kB
  • sloc: cpp: 53,217; python: 6,900; cs: 5,566; java: 4,370; php: 1,460; javascript: 1,061; xml: 1,016; sh: 886; makefile: 13
file content (52 lines) | stat: -rw-r--r-- 1,719 bytes parent folder | download | duplicates (10)
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

#ifndef FUZZER_TEST_INIT_H_
#define FUZZER_TEST_INIT_H_

#include "fuzzer_assert.h"
#include "test_assert.h"

// Utility for test run.
struct OneTimeTestInit {
  // Declare trap for the Flatbuffers test engine.
  // This hook terminate program both in Debug and Release.
  static bool TestFailListener(const char *expval, const char *val,
                               const char *exp, const char *file, int line,
                               const char *func = nullptr) {
    (void)expval;
    (void)val;
    (void)exp;
    (void)file;
    (void)line;
    (void)func;
    // FLATBUFFERS_ASSERT redefined to be fully independent of the Flatbuffers
    // library implementation (see test_assert.h for details).
    fuzzer_assert_impl(false);  // terminate
    return false;
  }

  OneTimeTestInit() : has_locale_(false) {
    // Fuzzer test should be independent of the test engine implementation.
    // This hook will terminate test if TEST_EQ/TEST_ASSERT asserted.
    InitTestEngine(OneTimeTestInit::TestFailListener);

    // Read a locale for the test.
    if (flatbuffers::ReadEnvironmentVariable("FLATBUFFERS_TEST_LOCALE",
                                             &test_locale_)) {
      TEST_OUTPUT_LINE("The environment variable FLATBUFFERS_TEST_LOCALE=%s",
                       test_locale_.c_str());
      test_locale_ = flatbuffers::RemoveStringQuotes(test_locale_);
      has_locale_ = true;
    }
  }

  static const char *test_locale() {
    return one_time_init_.has_locale_ ? nullptr
                                      : one_time_init_.test_locale_.c_str();
  }

  bool has_locale_;
  std::string test_locale_;
  static OneTimeTestInit one_time_init_;
};

#endif  // !FUZZER_TEST_INIT_H_