chromium/third_party/flatbuffers/src/tests/test_assert.h

#ifndef TEST_ASSERT_H
#define TEST_ASSERT_H

#include "flatbuffers/base.h"
#include "flatbuffers/util.h"

// clang-format off

#ifdef __ANDROID__
  #include <android/log.h>
  #define TEST_OUTPUT_LINE
  #define FLATBUFFERS_NO_FILE_TESTS
#else
  #define TEST_OUTPUT_LINE(...)
#endif

#define TEST_EQ(exp, val)
#define TEST_NE(exp, val)
#define TEST_ASSERT(val)
#define TEST_NULL(val)
#define TEST_NOTNULL(val)
#define TEST_EQ_STR(exp, val)

#ifdef _WIN32
  #define TEST_ASSERT_FUNC
  #define TEST_EQ_FUNC
#else
  #define TEST_ASSERT_FUNC(val)
  #define TEST_EQ_FUNC(exp, val)
#endif

// clang-format on

extern int testing_fails;

// Listener of TestFail, like 'gtest::OnTestPartResult' event handler.
// Called in TestFail after a failed assertion.
TestFailEventListener;

// Prepare test engine (MSVC assertion setup, etc).
// listener - this function will be notified on each TestFail call.
void InitTestEngine(TestFailEventListener listener = nullptr);

// Release all test-engine resources.
// Prints or schedule a debug report if all test passed.
// Returns 0 if all tests passed or 1 otherwise.
// Memory leak report: FLATBUFFERS_MEMORY_LEAK_TRACKING && _MSC_VER && _DEBUG.
int CloseTestEngine(bool force_report = false);

// Write captured state to a log and terminate test run.
void TestFail(const char *expval, const char *val, const char *exp,
              const char *file, int line, const char *func = nullptr);

void TestEqStr(const char *expval, const char *val, const char *exp,
               const char *file, int line, const char *func = nullptr);

// Workaround for `enum class` printing.
// There is an issue with the printing of enums with a fixed underlying type.
// These enums are generated by `flatc` if `--scoped-enums` is active.
// All modern compilers have problems with `std::stringstream&<<(T v)` if T is
// an enum with fixed type. For details see DR1601:
// http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1601
// https://stackoverflow.com/questions/34336024/ambiguous-overload-when-writing-an-enum-with-an-enum-base-but-only-with-clang

template<typename T, bool is_enum_type = flatbuffers::is_enum<T>::value>
struct underlying_of_scalar {};

underlying_of_scalar<T, true>;

template<typename T>
typename underlying_of_scalar<T>::type scalar_as_underlying(T v) {}

template<typename T, typename U>
void TestEq(T expval, U val, const char *exp, const char *file, int line,
            const char *func) {}

template<>
inline void TestEq<std::string, std::string>(std::string expval,
                                             std::string val, const char *exp,
                                             const char *file, int line,
                                             const char *func) {}

template<typename T, typename U>
void TestNe(T expval, U val, const char *exp, const char *file, int line,
            const char *func) {}

template<>
inline void TestNe<std::string, std::string>(std::string expval,
                                             std::string val, const char *exp,
                                             const char *file, int line,
                                             const char *func) {}

#endif  // !TEST_ASSERT_H