mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-13 16:15:26 +00:00
Schemas now support include files.
Bug: 15521443 Change-Id: I2e1ef97e7225a1a0ecf2ca65e31d49d443003747 Tested: on Linux.
This commit is contained in:
5
tests/include_test1.fbs
Normal file
5
tests/include_test1.fbs
Normal file
@@ -0,0 +1,5 @@
|
||||
include "include_test2.fbs";
|
||||
include "include_test2.fbs"; // should be skipped
|
||||
include "include_test1.fbs"; // should be skipped
|
||||
|
||||
|
||||
4
tests/include_test2.fbs
Normal file
4
tests/include_test2.fbs
Normal file
@@ -0,0 +1,4 @@
|
||||
include "include_test2.fbs"; // should be skipped
|
||||
|
||||
enum FromInclude:long { IncludeVal }
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
// example IDL file
|
||||
|
||||
include "include_test1.fbs";
|
||||
|
||||
namespace MyGame.Example;
|
||||
|
||||
enum Color:byte (bit_flags) { Red = 0, Green, Blue = 3 }
|
||||
|
||||
@@ -192,8 +192,8 @@ void ParseAndGenerateTextTest() {
|
||||
|
||||
// parse schema first, so we can use it to parse the data after
|
||||
flatbuffers::Parser parser;
|
||||
TEST_EQ(parser.Parse(schemafile.c_str()), true);
|
||||
TEST_EQ(parser.Parse(jsonfile.c_str()), true);
|
||||
TEST_EQ(parser.Parse(schemafile.c_str(), "tests/"), true);
|
||||
TEST_EQ(parser.Parse(jsonfile.c_str(), "tests/"), true);
|
||||
|
||||
// here, parser.builder_ contains a binary buffer that is the parsed data.
|
||||
|
||||
@@ -406,12 +406,12 @@ void FuzzTest2() {
|
||||
|
||||
// Parse the schema, parse the generated data, then generate text back
|
||||
// from the binary and compare against the original.
|
||||
TEST_EQ(parser.Parse(schema.c_str()), true);
|
||||
TEST_EQ(parser.Parse(schema.c_str(), ""), true);
|
||||
|
||||
const std::string &json =
|
||||
definitions[num_definitions - 1].instances[0] + "\n";
|
||||
|
||||
TEST_EQ(parser.Parse(json.c_str()), true);
|
||||
TEST_EQ(parser.Parse(json.c_str(), ""), true);
|
||||
|
||||
std::string jsongen;
|
||||
flatbuffers::GeneratorOptions opts;
|
||||
@@ -443,7 +443,7 @@ void FuzzTest2() {
|
||||
// Test that parser errors are actually generated.
|
||||
void TestError(const char *src, const char *error_substr) {
|
||||
flatbuffers::Parser parser;
|
||||
TEST_EQ(parser.Parse(src), false); // Must signal error
|
||||
TEST_EQ(parser.Parse(src, ""), false); // Must signal error
|
||||
// Must be the error we're expecting
|
||||
TEST_NOTNULL(strstr(parser.error_.c_str(), error_substr));
|
||||
}
|
||||
@@ -495,10 +495,10 @@ void ScientificTest() {
|
||||
flatbuffers::Parser parser;
|
||||
|
||||
// Simple schema.
|
||||
TEST_EQ(parser.Parse("table X { Y:float; } root_type X;"), true);
|
||||
TEST_EQ(parser.Parse("table X { Y:float; } root_type X;", ""), true);
|
||||
|
||||
// Test scientific notation numbers.
|
||||
TEST_EQ(parser.Parse("{ Y:0.0314159e+2 }"), true);
|
||||
TEST_EQ(parser.Parse("{ Y:0.0314159e+2 }", ""), true);
|
||||
auto root = flatbuffers::GetRoot<float>(parser.builder_.GetBufferPointer());
|
||||
// root will point to the table, which is a 32bit vtable offset followed
|
||||
// by a float:
|
||||
@@ -509,11 +509,11 @@ void EnumStringsTest() {
|
||||
flatbuffers::Parser parser1;
|
||||
TEST_EQ(parser1.Parse("enum E:byte { A, B, C } table T { F:[E]; }"
|
||||
"root_type T;"
|
||||
"{ F:[ A, B, \"C\", \"A B C\" ] }"), true);
|
||||
"{ F:[ A, B, \"C\", \"A B C\" ] }", ""), true);
|
||||
flatbuffers::Parser parser2;
|
||||
TEST_EQ(parser2.Parse("enum E:byte { A, B, C } table T { F:[int]; }"
|
||||
"root_type T;"
|
||||
"{ F:[ \"E.C\", \"E.A E.B E.C\" ] }"), true);
|
||||
"{ F:[ \"E.C\", \"E.A E.B E.C\" ] }", ""), true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user