summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/fuzz_test.cpp2
-rw-r--r--tests/json_test.cpp10
-rw-r--r--tests/monster_test.cpp9
-rw-r--r--tests/parser_test.cpp12
-rw-r--r--tests/proto_test.cpp4
-rw-r--r--tests/test.cpp20
-rw-r--r--tests/test_assert.h1
7 files changed, 28 insertions, 30 deletions
diff --git a/tests/fuzz_test.cpp b/tests/fuzz_test.cpp
index b0ba3cd3..f6ee238d 100644
--- a/tests/fuzz_test.cpp
+++ b/tests/fuzz_test.cpp
@@ -275,7 +275,7 @@ void FuzzTest2() {
parser.opts.indent_step = 0;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
if (jsongen != json) {
// These strings are larger than a megabyte, so we show the bytes around
diff --git a/tests/json_test.cpp b/tests/json_test.cpp
index e4249f9e..8acbb10e 100644
--- a/tests/json_test.cpp
+++ b/tests/json_test.cpp
@@ -37,7 +37,7 @@ void JsonDefaultTest(const std::string& tests_data_path) {
FinishMonsterBuffer(builder, color_monster.Finish());
std::string jsongen;
auto result = GenerateText(parser, builder.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
// default value of the "color" field is Blue
TEST_EQ(std::string::npos != jsongen.find("color: \"Blue\""), true);
// default value of the "testf" field is 3.14159
@@ -66,7 +66,7 @@ void JsonEnumsTest(const std::string& tests_data_path) {
FinishMonsterBuffer(builder, color_monster.Finish());
std::string jsongen;
auto result = GenerateText(parser, builder.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ(std::string::npos != jsongen.find("color: \"Red Blue\""), true);
// Test forward compatibility with 'output_enum_identifiers = true'.
// Current Color doesn't have '(1u << 2)' field, let's add it.
@@ -79,7 +79,7 @@ void JsonEnumsTest(const std::string& tests_data_path) {
static_cast<Color>((1u << 2) | Color_Blue | Color_Red));
FinishMonsterBuffer(builder, future_color.Finish());
result = GenerateText(parser, builder.GetBufferPointer(), &future_json);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ(std::string::npos != future_json.find("color: 13"), true);
}
@@ -120,7 +120,7 @@ void JsonOptionalTest(const std::string& tests_data_path, bool default_scalars)
std::string jsongen;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(), jsonfile.c_str());
}
@@ -199,7 +199,7 @@ root_type JsonUnionStructTest;
std::string json_generated;
auto generate_result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &json_generated);
- TEST_EQ(true, generate_result);
+ TEST_NULL(generate_result);
TEST_EQ_STR(json_source, json_generated.c_str());
}
diff --git a/tests/monster_test.cpp b/tests/monster_test.cpp
index ed6d55bf..2ca3277a 100644
--- a/tests/monster_test.cpp
+++ b/tests/monster_test.cpp
@@ -626,7 +626,7 @@ void TestMonsterExtraFloats(const std::string &tests_data_path) {
TEST_EQ(def_extra->d3(), -infinity_d);
std::string jsongen;
auto result = GenerateText(parser, def_obj, &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
// Check expected default values.
TEST_EQ(std::string::npos != jsongen.find("f0: nan"), true);
TEST_EQ(std::string::npos != jsongen.find("f1: nan"), true);
@@ -777,7 +777,7 @@ void ParseAndGenerateTextTest(const std::string &tests_data_path, bool binary) {
std::string jsongen;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(), jsonfile.c_str());
// We can also do the above using the convenient Registry that knows about
@@ -815,9 +815,8 @@ void ParseAndGenerateTextTest(const std::string &tests_data_path, bool binary) {
// request natural printing for utf-8 strings
parser.opts.natural_utf8 = true;
parser.opts.strict_json = true;
- TEST_EQ(
- GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen_utf8),
- true);
+ TEST_NULL(
+ GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen_utf8));
TEST_EQ_STR(jsongen_utf8.c_str(), jsonfile_utf8.c_str());
}
diff --git a/tests/parser_test.cpp b/tests/parser_test.cpp
index 4d9e0762..7bcf62bf 100644
--- a/tests/parser_test.cpp
+++ b/tests/parser_test.cpp
@@ -455,8 +455,8 @@ T TestValue(const char *json, const char *type_name,
// Check with print.
std::string print_back;
parser.opts.indent_step = -1;
- TEST_EQ(GenerateText(parser, parser.builder_.GetBufferPointer(), &print_back),
- true);
+ TEST_NULL(
+ GenerateText(parser, parser.builder_.GetBufferPointer(), &print_back));
// restore value from its default
if (check_default) { TEST_EQ(parser.Parse(print_back.c_str()), true); }
@@ -713,7 +713,7 @@ void UnicodeTest() {
parser.opts.indent_step = -1;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(),
"{F: \"\\u20AC\\u00A2\\u30E6\\u30FC\\u30B6\\u30FC"
"\\u5225\\u30B5\\u30A4\\u30C8\\u20AC\\u0080\\uD83D\\uDE0E\"}");
@@ -733,7 +733,7 @@ void UnicodeTestAllowNonUTF8() {
parser.opts.indent_step = -1;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(
jsongen.c_str(),
"{F: \"\\u20AC\\u00A2\\u30E6\\u30FC\\u30B6\\u30FC"
@@ -759,7 +759,7 @@ void UnicodeTestGenerateTextFailsOnNonUTF8() {
parser.opts.allow_non_utf8 = false;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, false);
+ TEST_EQ_STR(result, "string contains non-utf8 bytes");
}
void UnicodeSurrogatesTest() {
@@ -800,7 +800,7 @@ void UnknownFieldsTest() {
parser.opts.indent_step = -1;
auto result =
GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(), "{str: \"test\",i: 10}");
}
diff --git a/tests/proto_test.cpp b/tests/proto_test.cpp
index 6c98bc14..3480bc57 100644
--- a/tests/proto_test.cpp
+++ b/tests/proto_test.cpp
@@ -317,9 +317,9 @@ void ParseProtoBufAsciiTest() {
TEST_EQ(parser.Parse("{ A [1 2] C { B:2 }}"), true);
// Similarly, in text output, it should omit these.
std::string text;
- auto ok = flatbuffers::GenerateText(
+ auto err = flatbuffers::GenerateText(
parser, parser.builder_.GetBufferPointer(), &text);
- TEST_EQ(ok, true);
+ TEST_NULL(err);
TEST_EQ_STR(text.c_str(),
"{\n A [\n 1\n 2\n ]\n C {\n B: 2\n }\n}\n");
}
diff --git a/tests/test.cpp b/tests/test.cpp
index 6bc23ed6..e7d154d4 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -120,12 +120,12 @@ void GenerateTableTextTest(const std::string &tests_data_path) {
std::string jsongen;
auto result = GenerateTextFromTable(parser, monster, "MyGame.Example.Monster",
&jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
// Test sub table
const Vec3 *pos = monster->pos();
jsongen.clear();
result = GenerateTextFromTable(parser, pos, "MyGame.Example.Vec3", &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(
jsongen.c_str(),
"{x: 1.0,y: 2.0,z: 3.0,test1: 3.0,test2: \"Green\",test3: {a: 5,b: 6}}");
@@ -133,13 +133,13 @@ void GenerateTableTextTest(const std::string &tests_data_path) {
jsongen.clear();
result =
GenerateTextFromTable(parser, &test3, "MyGame.Example.Test", &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(), "{a: 5,b: 6}");
const Test *test4 = monster->test4()->Get(0);
jsongen.clear();
result =
GenerateTextFromTable(parser, test4, "MyGame.Example.Test", &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(), "{a: 10,b: 20}");
}
@@ -337,7 +337,7 @@ void UnionVectorTest(const std::string &tests_data_path) {
// Generate text using parsed schema.
std::string jsongen;
auto result = GenerateText(parser, fbb.GetBufferPointer(), &jsongen);
- TEST_EQ(result, true);
+ TEST_NULL(result);
TEST_EQ_STR(jsongen.c_str(),
"{\n"
" main_character_type: \"Rapunzel\",\n"
@@ -955,9 +955,8 @@ void FixedLengthArrayJsonTest(const std::string &tests_data_path, bool binary) {
// Export to JSON
std::string jsonGen;
- TEST_EQ(
- GenerateText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen),
- true);
+ TEST_NULL(
+ GenerateText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen));
// Import from JSON
TEST_EQ(parserGen.Parse(jsonGen.c_str()), true);
@@ -1082,9 +1081,8 @@ void TestEmbeddedBinarySchema(const std::string &tests_data_path) {
// Export to JSON
std::string jsonGen;
- TEST_EQ(
- GenerateText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen),
- true);
+ TEST_NULL(
+ GenerateText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen));
// Import from JSON
TEST_EQ(parserGen.Parse(jsonGen.c_str()), true);
diff --git a/tests/test_assert.h b/tests/test_assert.h
index 8b413382..75e5c518 100644
--- a/tests/test_assert.h
+++ b/tests/test_assert.h
@@ -19,6 +19,7 @@
#define TEST_EQ(exp, val) TestEq(exp, val, "'" #exp "' != '" #val "'", __FILE__, __LINE__, "")
#define TEST_NE(exp, val) TestNe(exp, val, "'" #exp "' == '" #val "'", __FILE__, __LINE__, "")
#define TEST_ASSERT(val) TestEq(true, !!(val), "'" "true" "' != '" #val "'", __FILE__, __LINE__, "")
+#define TEST_NULL(val) TestEq(true, (val) == nullptr, "'" "nullptr" "' != '" #val "'", __FILE__, __LINE__, "")
#define TEST_NOTNULL(val) TestEq(true, (val) != nullptr, "'" "nullptr" "' == '" #val "'", __FILE__, __LINE__, "")
#define TEST_EQ_STR(exp, val) TestEqStr(exp, val, "'" #exp "' != '" #val "'", __FILE__, __LINE__, "")