mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-11 15:37:27 +00:00
Make the Parser independent from the global C-locale (#5028)
* Make the Parser independent from the global C-locale * Set a specific test locale using the environment variable FLATBUFFERS_TEST_LOCALE * Remove redundant static qualifiers
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
d6b1ce09cf
commit
5f32f94810
@@ -1,18 +1,33 @@
|
||||
#ifndef TEST_ASSERT_H
|
||||
#define TEST_ASSERT_H
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#include <android/log.h>
|
||||
#define TEST_OUTPUT_LINE(...) \
|
||||
__android_log_print(ANDROID_LOG_INFO, "FlatBuffers", __VA_ARGS__)
|
||||
__android_log_print(ANDROID_LOG_INFO, "FlatBuffers", __VA_ARGS__)
|
||||
#define FLATBUFFERS_NO_FILE_TESTS
|
||||
#else
|
||||
#define TEST_OUTPUT_LINE(...) \
|
||||
{ printf(__VA_ARGS__); printf("\n"); }
|
||||
#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__)
|
||||
#endif
|
||||
|
||||
// clang-format on
|
||||
|
||||
extern int testing_fails;
|
||||
@@ -20,8 +35,8 @@ extern int testing_fails;
|
||||
// Listener of TestFail, like 'gtest::OnTestPartResult' event handler.
|
||||
// Called in TestFail after a failed assertion.
|
||||
typedef bool (*TestFailEventListener)(const char *expval, const char *val,
|
||||
const char *exp, const char *file, int line,
|
||||
const char *func);
|
||||
const char *exp, const char *file,
|
||||
int line, const char *func);
|
||||
|
||||
// Prepare test engine (MSVC assertion setup, etc).
|
||||
// listener - this function will be notified on each TestFail call.
|
||||
@@ -35,23 +50,12 @@ void TestEqStr(const char *expval, const char *val, const char *exp,
|
||||
const char *file, int line);
|
||||
|
||||
template<typename T, typename U>
|
||||
void TestEq(T expval, U val, const char *exp, const char *file, int line, const char *func = 0) {
|
||||
void TestEq(T expval, U val, const char *exp, const char *file, int line,
|
||||
const char *func = 0) {
|
||||
if (U(expval) != val) {
|
||||
TestFail(flatbuffers::NumToString(expval).c_str(),
|
||||
flatbuffers::NumToString(val).c_str(), exp, file, line, func);
|
||||
}
|
||||
}
|
||||
|
||||
#define TEST_EQ(exp, val) TestEq(exp, val, #exp, __FILE__, __LINE__)
|
||||
#define TEST_ASSERT(exp) TestEq(exp, true, #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__)
|
||||
#endif
|
||||
#define TEST_NOTNULL(exp) TestEq(exp == NULL, false, #exp, __FILE__, __LINE__)
|
||||
#define TEST_EQ_STR(exp, val) TestEqStr(exp, val, #exp, __FILE__, __LINE__)
|
||||
|
||||
#endif // TEST_ASSERT_H
|
||||
#endif // !TEST_ASSERT_H
|
||||
|
||||
Reference in New Issue
Block a user