The parser and flatc now allow include directories to be specified.

Bug: 17139854
Change-Id: I0eac65d054951e00a8811ad1d80ba8c37012dbf0
Tested: on Linux.
This commit is contained in:
Wouter van Oortmerssen
2014-09-11 17:13:21 -07:00
parent cb58fc6fa1
commit e57b86bb9f
10 changed files with 77 additions and 35 deletions

View File

@@ -192,8 +192,9 @@ 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(), "tests/"), true);
TEST_EQ(parser.Parse(jsonfile.c_str(), "tests/"), true);
const char *include_directories[] = { "tests", nullptr };
TEST_EQ(parser.Parse(schemafile.c_str(), include_directories), true);
TEST_EQ(parser.Parse(jsonfile.c_str(), include_directories), true);
// here, parser.builder_ contains a binary buffer that is the parsed data.
@@ -406,12 +407,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 +444,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));
}
@@ -498,10 +499,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:
@@ -513,11 +514,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);
}
void UnicodeTest() {
@@ -525,7 +526,7 @@ void UnicodeTest() {
TEST_EQ(parser.Parse("table T { F:string; }"
"root_type T;"
"{ F:\"\\u20AC\\u00A2\\u30E6\\u30FC\\u30B6\\u30FC"
"\\u5225\\u30B5\\u30A4\\u30C8\\x01\\x80\" }", ""), true);
"\\u5225\\u30B5\\u30A4\\u30C8\\x01\\x80\" }"), true);
std::string jsongen;
flatbuffers::GeneratorOptions opts;
opts.indent_step = -1;