Skip to content

Commit 60f17d2

Browse files
committed
Move test macros to a header
1 parent 05bc664 commit 60f17d2

2 files changed

Lines changed: 34 additions & 31 deletions

File tree

tests/basictests.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,7 @@
1414
#include <unistd.h>
1515

1616
#include "simdjson.h"
17-
18-
#ifndef SIMDJSON_BENCHMARK_DATA_DIR
19-
#define SIMDJSON_BENCHMARK_DATA_DIR "jsonexamples/"
20-
#endif
21-
const char *TWITTER_JSON = SIMDJSON_BENCHMARK_DATA_DIR "twitter.json";
22-
const char *TWITTER_TIMELINE_JSON = SIMDJSON_BENCHMARK_DATA_DIR "twitter_timeline.json";
23-
const char *REPEAT_JSON = SIMDJSON_BENCHMARK_DATA_DIR "repeat.json";
24-
const char *AMAZON_CELLPHONES_NDJSON = SIMDJSON_BENCHMARK_DATA_DIR "amazon_cellphones.ndjson";
25-
26-
#define SIMDJSON_BENCHMARK_SMALLDATA_DIR SIMDJSON_BENCHMARK_DATA_DIR "small/"
27-
28-
const char *ADVERSARIAL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "adversarial.json";
29-
const char *FLATADVERSARIAL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "flatadversarial.json";
30-
const char *DEMO_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "demo.json";
31-
const char *SMALLDEMO_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "smalldemo.json";
32-
const char *TRUENULL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "truenull.json";
33-
34-
35-
36-
template<typename T>
37-
bool equals_expected(T actual, T expected) {
38-
return actual == expected;
39-
}
40-
template<>
41-
bool equals_expected<const char *>(const char *actual, const char *expected) {
42-
return !strcmp(actual, expected);
43-
}
44-
45-
#define ASSERT_EQUAL(ACTUAL, EXPECTED) if (!equals_expected(ACTUAL, EXPECTED)) { std::cerr << "Expected " << #ACTUAL << " to be " << (EXPECTED) << ", got " << (ACTUAL) << " instead!" << std::endl; return false; }
46-
#define ASSERT(RESULT, MESSAGE) if (!(RESULT)) { std::cerr << MESSAGE << std::endl; return false; }
47-
#define ASSERT_SUCCESS(ERROR) if (ERROR) { std::cerr << (ERROR) << std::endl; return false; }
17+
#include "test_macros.h"
4818

4919
namespace number_tests {
5020

tests/test_macros.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef TEST_MACROS_H
2+
#define TEST_MACROS_H
3+
4+
#ifndef SIMDJSON_BENCHMARK_DATA_DIR
5+
#define SIMDJSON_BENCHMARK_DATA_DIR "jsonexamples/"
6+
#endif
7+
const char *TWITTER_JSON = SIMDJSON_BENCHMARK_DATA_DIR "twitter.json";
8+
const char *TWITTER_TIMELINE_JSON = SIMDJSON_BENCHMARK_DATA_DIR "twitter_timeline.json";
9+
const char *REPEAT_JSON = SIMDJSON_BENCHMARK_DATA_DIR "repeat.json";
10+
const char *AMAZON_CELLPHONES_NDJSON = SIMDJSON_BENCHMARK_DATA_DIR "amazon_cellphones.ndjson";
11+
12+
#define SIMDJSON_BENCHMARK_SMALLDATA_DIR SIMDJSON_BENCHMARK_DATA_DIR "small/"
13+
14+
const char *ADVERSARIAL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "adversarial.json";
15+
const char *FLATADVERSARIAL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "flatadversarial.json";
16+
const char *DEMO_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "demo.json";
17+
const char *SMALLDEMO_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "smalldemo.json";
18+
const char *TRUENULL_JSON = SIMDJSON_BENCHMARK_SMALLDATA_DIR "truenull.json";
19+
20+
// For the ASSERT_EQUAL macro
21+
template<typename T>
22+
bool equals_expected(T actual, T expected) {
23+
return actual == expected;
24+
}
25+
template<>
26+
bool equals_expected<const char *>(const char *actual, const char *expected) {
27+
return !strcmp(actual, expected);
28+
}
29+
#define ASSERT_EQUAL(ACTUAL, EXPECTED) if (!equals_expected(ACTUAL, EXPECTED)) { std::cerr << "Expected " << #ACTUAL << " to be " << (EXPECTED) << ", got " << (ACTUAL) << " instead!" << std::endl; return false; }
30+
#define ASSERT(RESULT, MESSAGE) if (!(RESULT)) { std::cerr << MESSAGE << std::endl; return false; }
31+
#define ASSERT_SUCCESS(ERROR) if (ERROR) { std::cerr << (ERROR) << std::endl; return false; }
32+
33+
#endif // TEST_MACROS_H

0 commit comments

Comments
 (0)