2018-09-24 19:03:31 +00:00
|
|
|
#ifndef TEST_ASSERT_H
|
|
|
|
#define TEST_ASSERT_H
|
|
|
|
|
|
|
|
#include "flatbuffers/util.h"
|
|
|
|
|
2018-11-16 17:24:06 +00:00
|
|
|
// clang-format off
|
|
|
|
|
2018-09-24 19:03:31 +00:00
|
|
|
#ifdef __ANDROID__
|
2018-11-16 17:24:06 +00:00
|
|
|
#include <android/log.h>
|
2018-09-24 19:03:31 +00:00
|
|
|
#define TEST_OUTPUT_LINE(...) \
|
2018-11-16 17:24:06 +00:00
|
|
|
__android_log_print(ANDROID_LOG_INFO, "FlatBuffers", __VA_ARGS__)
|
2018-09-24 19:03:31 +00:00
|
|
|
#define FLATBUFFERS_NO_FILE_TESTS
|
|
|
|
#else
|
2018-11-16 17:24:06 +00:00
|
|
|
#define TEST_OUTPUT_LINE(...) \
|
|
|
|
{ printf(__VA_ARGS__); printf("\n"); }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TEST_EQ(exp, val) TestEq(exp, val, #exp, __FILE__, __LINE__)
|
|
|
|
#define TEST_ASSERT(exp) TestEq(exp, true, #exp, __FILE__, __LINE__)
|
|
|
|
#define TEST_NOTNULL(exp) TestEq(exp == NULL, false, #exp, __FILE__, __LINE__)
|
|
|
|
#define TEST_EQ_STR(exp, val) TestEqStr(exp, val, #exp, __FILE__, __LINE__)
|
|
|
|
|
|
|
|
#ifdef WIN32
|
|
|
|
#define TEST_ASSERT_FUNC(exp) TestEq(exp, true, #exp, __FILE__, __LINE__, __FUNCTION__)
|
|
|
|
#define TEST_EQ_FUNC(exp, val) TestEq(exp, val, #exp, __FILE__, __LINE__, __FUNCTION__)
|
|
|
|
#else
|
|
|
|
#define TEST_ASSERT_FUNC(exp) TestEq(exp, true, #exp, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
|
|
|
#define TEST_EQ_FUNC(exp, val) TestEq(exp, val, #exp, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
2018-09-24 19:03:31 +00:00
|
|
|
#endif
|
2018-11-16 17:24:06 +00:00
|
|
|
|
2018-09-24 19:03:31 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
extern int testing_fails;
|
|
|
|
|
2018-10-22 22:44:18 +00:00
|
|
|
// Listener of TestFail, like 'gtest::OnTestPartResult' event handler.
|
|
|
|
// Called in TestFail after a failed assertion.
|
|
|
|
typedef bool (*TestFailEventListener)(const char *expval, const char *val,
|
2018-11-16 17:24:06 +00:00
|
|
|
const char *exp, const char *file,
|
|
|
|
int line, const char *func);
|
2018-10-03 19:04:14 +00:00
|
|
|
|
2018-10-22 22:44:18 +00:00
|
|
|
// Prepare test engine (MSVC assertion setup, etc).
|
|
|
|
// listener - this function will be notified on each TestFail call.
|
|
|
|
void InitTestEngine(TestFailEventListener listener = nullptr);
|
|
|
|
|
|
|
|
// Write captured state to a log and terminate test run.
|
2018-09-24 19:03:31 +00:00
|
|
|
void TestFail(const char *expval, const char *val, const char *exp,
|
|
|
|
const char *file, int line, const char *func = 0);
|
|
|
|
|
|
|
|
void TestEqStr(const char *expval, const char *val, const char *exp,
|
|
|
|
const char *file, int line);
|
|
|
|
|
|
|
|
template<typename T, typename U>
|
2018-11-16 17:24:06 +00:00
|
|
|
void TestEq(T expval, U val, const char *exp, const char *file, int line,
|
|
|
|
const char *func = 0) {
|
2018-09-24 19:03:31 +00:00
|
|
|
if (U(expval) != val) {
|
|
|
|
TestFail(flatbuffers::NumToString(expval).c_str(),
|
|
|
|
flatbuffers::NumToString(val).c_str(), exp, file, line, func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-16 17:24:06 +00:00
|
|
|
#endif // !TEST_ASSERT_H
|