diff options
author | Wouter van Oortmerssen <aardappel@gmail.com> | 2023-05-11 18:08:42 -0700 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2023-05-11 18:14:27 -0700 |
commit | 950a71ab893e96147c30dd91735af6db73f72ae0 (patch) | |
tree | d785e704206a175b0456070e70b7f0a7ebc515da /tests | |
parent | 86486a1735bc38f5629447251206934ef205f6e4 (diff) | |
download | flatbuffers-950a71ab893e96147c30dd91735af6db73f72ae0.tar.gz flatbuffers-950a71ab893e96147c30dd91735af6db73f72ae0.tar.bz2 flatbuffers-950a71ab893e96147c30dd91735af6db73f72ae0.zip |
Rename GenerateText
to make it a compile-time breaking change, to alert any users to the new meaning of the return value
Diffstat (limited to 'tests')
-rw-r--r-- | tests/fuzz_test.cpp | 3 | ||||
-rw-r--r-- | tests/fuzzer/flatbuffers_monster_fuzzer.cc | 4 | ||||
-rw-r--r-- | tests/fuzzer/flatbuffers_scalar_fuzzer.cc | 7 | ||||
-rw-r--r-- | tests/json_test.cpp | 11 | ||||
-rw-r--r-- | tests/monster_test.cpp | 8 | ||||
-rw-r--r-- | tests/parser_test.cpp | 17 | ||||
-rw-r--r-- | tests/proto_test.cpp | 3 | ||||
-rw-r--r-- | tests/test.cpp | 14 |
8 files changed, 29 insertions, 38 deletions
diff --git a/tests/fuzz_test.cpp b/tests/fuzz_test.cpp index 4e42549a..1c9adbc5 100644 --- a/tests/fuzz_test.cpp +++ b/tests/fuzz_test.cpp @@ -273,8 +273,7 @@ void FuzzTest2() { std::string jsongen; parser.opts.indent_step = 0; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); TEST_NULL(result); if (jsongen != json) { diff --git a/tests/fuzzer/flatbuffers_monster_fuzzer.cc b/tests/fuzzer/flatbuffers_monster_fuzzer.cc index 4b8b7906..71a68027 100644 --- a/tests/fuzzer/flatbuffers_monster_fuzzer.cc +++ b/tests/fuzzer/flatbuffers_monster_fuzzer.cc @@ -78,8 +78,8 @@ std::string do_test(const flatbuffers::IDLOptions &opts, flatbuffers::Verifier verifier(parser_.builder_.GetBufferPointer(), parser_.builder_.GetSize()); TEST_EQ(true, MyGame::Example::VerifyMonsterBuffer(verifier)); - TEST_ASSERT( - GenerateText(parser_, parser_.builder_.GetBufferPointer(), &jsongen)); + TEST_NULL( + GenText(parser_, parser_.builder_.GetBufferPointer(), &jsongen)); } else if (check_parser) { TEST_OUTPUT_LINE("parser failed with JSON:\n%s", input_json.c_str()); TEST_EQ_STR("", parser_.error_.c_str()); diff --git a/tests/fuzzer/flatbuffers_scalar_fuzzer.cc b/tests/fuzzer/flatbuffers_scalar_fuzzer.cc index faa069e1..cd43506f 100644 --- a/tests/fuzzer/flatbuffers_scalar_fuzzer.cc +++ b/tests/fuzzer/flatbuffers_scalar_fuzzer.cc @@ -218,8 +218,7 @@ bool Parse(flatbuffers::Parser &parser, const std::string &json, std::string *_text) { auto done = parser.ParseJson(json.c_str()); if (done) { - TEST_EQ(GenerateText(parser, parser.builder_.GetBufferPointer(), _text), - true); + TEST_NULL(GenText(parser, parser.builder_.GetBufferPointer(), _text)); } else { *_text = parser.error_; } @@ -358,9 +357,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } // Compare with print. std::string ref_string, def_string; - FLATBUFFERS_ASSERT(GenerateText( + FLATBUFFERS_ASSERT(!GenText( parser, parser.builder_.GetBufferPointer(), &ref_string)); - FLATBUFFERS_ASSERT(GenerateText( + FLATBUFFERS_ASSERT(!GenText( def_parser, def_parser.builder_.GetBufferPointer(), &def_string)); if (ref_string != def_string) { TEST_OUTPUT_LINE("Stage 3.2 failed: '%s' != '%s'", def_string.c_str(), diff --git a/tests/json_test.cpp b/tests/json_test.cpp index 86367eec..2a328638 100644 --- a/tests/json_test.cpp +++ b/tests/json_test.cpp @@ -36,7 +36,7 @@ void JsonDefaultTest(const std::string &tests_data_path) { color_monster.add_name(name); FinishMonsterBuffer(builder, color_monster.Finish()); std::string jsongen; - auto result = GenerateText(parser, builder.GetBufferPointer(), &jsongen); + auto result = GenText(parser, builder.GetBufferPointer(), &jsongen); TEST_NULL(result); // default value of the "color" field is Blue TEST_EQ(std::string::npos != jsongen.find("color: \"Blue\""), true); @@ -65,7 +65,7 @@ void JsonEnumsTest(const std::string &tests_data_path) { color_monster.add_color(Color(Color_Blue | Color_Red)); FinishMonsterBuffer(builder, color_monster.Finish()); std::string jsongen; - auto result = GenerateText(parser, builder.GetBufferPointer(), &jsongen); + auto result = GenText(parser, builder.GetBufferPointer(), &jsongen); TEST_NULL(result); TEST_EQ(std::string::npos != jsongen.find("color: \"Red Blue\""), true); // Test forward compatibility with 'output_enum_identifiers = true'. @@ -78,7 +78,7 @@ void JsonEnumsTest(const std::string &tests_data_path) { future_color.add_color( static_cast<Color>((1u << 2) | Color_Blue | Color_Red)); FinishMonsterBuffer(builder, future_color.Finish()); - result = GenerateText(parser, builder.GetBufferPointer(), &future_json); + result = GenText(parser, builder.GetBufferPointer(), &future_json); TEST_NULL(result); TEST_EQ(std::string::npos != future_json.find("color: 13"), true); } @@ -119,8 +119,7 @@ void JsonOptionalTest(const std::string &tests_data_path, // to ensure it is correct, we now generate text back from the binary, // and compare the two: std::string jsongen; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); TEST_NULL(result); TEST_EQ_STR(jsongen.c_str(), jsonfile.c_str()); } @@ -199,7 +198,7 @@ root_type JsonUnionStructTest; // now generate text back from the binary, and compare the two: std::string json_generated; auto generate_result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &json_generated); + GenText(parser, parser.builder_.GetBufferPointer(), &json_generated); 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 d44f118e..8ec031a3 100644 --- a/tests/monster_test.cpp +++ b/tests/monster_test.cpp @@ -646,7 +646,7 @@ void TestMonsterExtraFloats(const std::string &tests_data_path) { TEST_EQ(def_extra->d2(), +infinity_d); TEST_EQ(def_extra->d3(), -infinity_d); std::string jsongen; - auto result = GenerateText(parser, def_obj, &jsongen); + auto result = GenText(parser, def_obj, &jsongen); TEST_NULL(result); // Check expected default values. TEST_EQ(std::string::npos != jsongen.find("f0: nan"), true); @@ -796,8 +796,7 @@ void ParseAndGenerateTextTest(const std::string &tests_data_path, bool binary) { // to ensure it is correct, we now generate text back from the binary, // and compare the two: std::string jsongen; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); TEST_NULL(result); TEST_EQ_STR(jsongen.c_str(), jsonfile.c_str()); @@ -836,8 +835,7 @@ 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_NULL( - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen_utf8)); + TEST_NULL(GenText(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 83c67e85..085c2fe0 100644 --- a/tests/parser_test.cpp +++ b/tests/parser_test.cpp @@ -484,8 +484,7 @@ T TestValue(const char *json, const char *type_name, // Check with print. std::string print_back; parser.opts.indent_step = -1; - TEST_NULL( - GenerateText(parser, parser.builder_.GetBufferPointer(), &print_back)); + TEST_NULL(GenText(parser, parser.builder_.GetBufferPointer(), &print_back)); // restore value from its default if (check_default) { TEST_EQ(parser.Parse(print_back.c_str()), true); } @@ -740,8 +739,7 @@ void UnicodeTest() { true); std::string jsongen; parser.opts.indent_step = -1; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); TEST_NULL(result); TEST_EQ_STR(jsongen.c_str(), "{F: \"\\u20AC\\u00A2\\u30E6\\u30FC\\u30B6\\u30FC" @@ -760,8 +758,7 @@ void UnicodeTestAllowNonUTF8() { true); std::string jsongen; parser.opts.indent_step = -1; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); TEST_NULL(result); TEST_EQ_STR( jsongen.c_str(), @@ -783,11 +780,10 @@ void UnicodeTestGenerateTextFailsOnNonUTF8() { true); std::string jsongen; parser.opts.indent_step = -1; - // Now, disallow non-UTF-8 (the default behavior) so GenerateText indicates + // Now, disallow non-UTF-8 (the default behavior) so GenText indicates // failure. parser.opts.allow_non_utf8 = false; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); TEST_EQ_STR(result, "string contains non-utf8 bytes"); } @@ -825,8 +821,7 @@ void UnknownFieldsTest() { std::string jsongen; parser.opts.indent_step = -1; - auto result = - GenerateText(parser, parser.builder_.GetBufferPointer(), &jsongen); + auto result = GenText(parser, parser.builder_.GetBufferPointer(), &jsongen); 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 6fb3ef35..90c70bdb 100644 --- a/tests/proto_test.cpp +++ b/tests/proto_test.cpp @@ -324,7 +324,8 @@ 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 err = flatbuffers::GenerateText( + auto err = + flatbuffers::GenText( parser, parser.builder_.GetBufferPointer(), &text); TEST_NULL(err); TEST_EQ_STR(text.c_str(), diff --git a/tests/test.cpp b/tests/test.cpp index 49018d1b..5d483893 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -119,13 +119,13 @@ void GenerateTableTextTest(const std::string &tests_data_path) { TEST_EQ(abilities->Get(2)->distance(), 12); std::string jsongen; - auto result = GenerateTextFromTable(parser, monster, "MyGame.Example.Monster", + auto result = GenTextFromTable(parser, monster, "MyGame.Example.Monster", &jsongen); TEST_NULL(result); // Test sub table const Vec3 *pos = monster->pos(); jsongen.clear(); - result = GenerateTextFromTable(parser, pos, "MyGame.Example.Vec3", &jsongen); + result = GenTextFromTable(parser, pos, "MyGame.Example.Vec3", &jsongen); TEST_NULL(result); TEST_EQ_STR( jsongen.c_str(), @@ -133,13 +133,13 @@ void GenerateTableTextTest(const std::string &tests_data_path) { const Test &test3 = pos->test3(); jsongen.clear(); result = - GenerateTextFromTable(parser, &test3, "MyGame.Example.Test", &jsongen); + GenTextFromTable(parser, &test3, "MyGame.Example.Test", &jsongen); 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); + GenTextFromTable(parser, test4, "MyGame.Example.Test", &jsongen); 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); + auto result = GenText(parser, fbb.GetBufferPointer(), &jsongen); TEST_NULL(result); TEST_EQ_STR(jsongen.c_str(), "{\n" @@ -957,7 +957,7 @@ void FixedLengthArrayJsonTest(const std::string &tests_data_path, bool binary) { // Export to JSON std::string jsonGen; TEST_NULL( - GenerateText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen)); + GenText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen)); // Import from JSON TEST_EQ(parserGen.Parse(jsonGen.c_str()), true); @@ -1083,7 +1083,7 @@ void TestEmbeddedBinarySchema(const std::string &tests_data_path) { // Export to JSON std::string jsonGen; TEST_NULL( - GenerateText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen)); + GenText(parserOrg, parserOrg.builder_.GetBufferPointer(), &jsonGen)); // Import from JSON TEST_EQ(parserGen.Parse(jsonGen.c_str()), true); |