2020-06-20 04:27:00 +08:00
|
|
|
#ifndef TEST_MACROS_H
|
|
|
|
#define TEST_MACROS_H
|
|
|
|
|
|
|
|
#ifndef SIMDJSON_BENCHMARK_DATA_DIR
|
|
|
|
#define SIMDJSON_BENCHMARK_DATA_DIR "jsonexamples/"
|
|
|
|
#endif
|
|
|
|
const char *TWITTER_JSON = SIMDJSON_BENCHMARK_DATA_DIR "twitter.json";
|
|
|
|
const char *TWITTER_TIMELINE_JSON = SIMDJSON_BENCHMARK_DATA_DIR "twitter_timeline.json";
|
|
|
|
const char *REPEAT_JSON = SIMDJSON_BENCHMARK_DATA_DIR "repeat.json";
|
|
|
|
const char *AMAZON_CELLPHONES_NDJSON = SIMDJSON_BENCHMARK_DATA_DIR "amazon_cellphones.ndjson";
|
|
|
|
|
|
|
|
#define SIMDJSON_BENCHMARK_SMALLDATA_DIR SIMDJSON_BENCHMARK_DATA_DIR "small/"
|
|
|
|
|
|
|
|
const char *ADVERSARIAL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "adversarial.json";
|
|
|
|
const char *FLATADVERSARIAL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "flatadversarial.json";
|
|
|
|
const char *DEMO_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "demo.json";
|
|
|
|
const char *SMALLDEMO_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "smalldemo.json";
|
|
|
|
const char *TRUENULL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "truenull.json";
|
|
|
|
|
|
|
|
// For the ASSERT_EQUAL macro
|
2020-06-22 05:36:38 +08:00
|
|
|
template<typename T, typename S>
|
2020-08-19 06:25:36 +08:00
|
|
|
simdjson_really_inline bool equals_expected(T actual, S expected) {
|
2020-06-22 05:36:38 +08:00
|
|
|
return actual == T(expected);
|
2020-06-20 04:27:00 +08:00
|
|
|
}
|
|
|
|
template<>
|
2020-08-19 06:25:36 +08:00
|
|
|
simdjson_really_inline bool equals_expected<const char *, const char *>(const char *actual, const char *expected) {
|
2020-06-20 04:27:00 +08:00
|
|
|
return !strcmp(actual, expected);
|
|
|
|
}
|
2020-06-21 13:03:57 +08:00
|
|
|
|
2020-08-19 06:25:36 +08:00
|
|
|
simdjson_really_inline simdjson::error_code to_error_code(simdjson::error_code error) {
|
2020-06-22 06:26:44 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
template<typename T>
|
2020-08-19 06:25:36 +08:00
|
|
|
simdjson_really_inline simdjson::error_code to_error_code(const simdjson::simdjson_result<T> &result) {
|
2020-06-22 06:26:44 +08:00
|
|
|
return result.error();
|
|
|
|
}
|
|
|
|
|
2020-06-21 13:03:57 +08:00
|
|
|
#define TEST_START() { cout << "Running " << __func__ << " ..." << endl; }
|
2020-06-22 05:36:38 +08:00
|
|
|
#define ASSERT_EQUAL(ACTUAL, EXPECTED) \
|
|
|
|
do { \
|
|
|
|
auto _actual = (ACTUAL); \
|
|
|
|
auto _expected = (EXPECTED); \
|
|
|
|
if (!equals_expected(_actual, _expected)) { \
|
|
|
|
std::cerr << "Expected " << (#ACTUAL) << " to be " << _expected << ", got " << _actual << " instead!" << std::endl; \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
} while(0);
|
2020-06-22 06:26:44 +08:00
|
|
|
#define ASSERT_ERROR(ACTUAL, EXPECTED) do { auto _actual = to_error_code(ACTUAL); auto _expected = to_error_code(EXPECTED); if (_actual != _expected) { std::cerr << "FAIL: Unexpected error \"" << _actual << "\" (expected \"" << _expected << "\")" << std::endl; return false; } } while (0);
|
2020-06-20 04:27:00 +08:00
|
|
|
#define ASSERT(RESULT, MESSAGE) if (!(RESULT)) { std::cerr << MESSAGE << std::endl; return false; }
|
2020-06-20 02:59:13 +08:00
|
|
|
#define RUN_TEST(RESULT) if (!RESULT) { return false; }
|
2020-06-22 06:26:44 +08:00
|
|
|
#define ASSERT_SUCCESS(ERROR) do { auto _error = to_error_code(ERROR); if (_error) { std::cerr << _error << std::endl; return false; } } while(0);
|
2020-06-21 13:03:57 +08:00
|
|
|
#define TEST_FAIL(MESSAGE) { std::cerr << "FAIL: " << (MESSAGE) << std::endl; return false; }
|
|
|
|
#define TEST_SUCCEED() { return true; }
|
2020-06-20 04:27:00 +08:00
|
|
|
|
|
|
|
#endif // TEST_MACROS_H
|