mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 04:58:57 +00:00
Added .proto parsing and convertion to .fbs.
Bug: 15777858 Change-Id: Iabef9b8c8044e593bb89510feebdee00d2f1840b Tested: on Linux and Windows.
This commit is contained in:
@@ -182,7 +182,6 @@ void AccessFlatBufferTest(const std::string &flatbuf) {
|
||||
// example of parsing text straight into a buffer, and generating
|
||||
// text back from it:
|
||||
void ParseAndGenerateTextTest() {
|
||||
|
||||
// load FlatBuffer schema (.fbs) and JSON from disk
|
||||
std::string schemafile;
|
||||
std::string jsonfile;
|
||||
@@ -216,6 +215,34 @@ void ParseAndGenerateTextTest() {
|
||||
}
|
||||
}
|
||||
|
||||
// Parse a .proto schema, output as .fbs
|
||||
void ParseProtoTest() {
|
||||
// load the .proto and the golden file from disk
|
||||
std::string protofile;
|
||||
std::string goldenfile;
|
||||
TEST_EQ(flatbuffers::LoadFile(
|
||||
"tests/prototest/test.proto", false, &protofile), true);
|
||||
TEST_EQ(flatbuffers::LoadFile(
|
||||
"tests/prototest/test.golden", false, &goldenfile), true);
|
||||
|
||||
// Parse proto.
|
||||
flatbuffers::Parser parser(true);
|
||||
TEST_EQ(parser.Parse(protofile.c_str(), nullptr), true);
|
||||
|
||||
// Generate fbs.
|
||||
flatbuffers::GeneratorOptions opts;
|
||||
auto fbs = flatbuffers::GenerateFBS(parser, "test", opts);
|
||||
|
||||
// Ensure generated file is parsable.
|
||||
flatbuffers::Parser parser2;
|
||||
TEST_EQ(parser2.Parse(fbs.c_str(), nullptr), true);
|
||||
|
||||
if (fbs != goldenfile) {
|
||||
printf("%s----------------\n%s", fbs.c_str(), goldenfile.c_str());
|
||||
TEST_NOTNULL(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void CompareTableFieldValue(flatbuffers::Table *table,
|
||||
flatbuffers::voffset_t voffset,
|
||||
T val) {
|
||||
@@ -544,6 +571,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
|
||||
#ifndef __ANDROID__ // requires file access
|
||||
ParseAndGenerateTextTest();
|
||||
ParseProtoTest();
|
||||
#endif
|
||||
|
||||
FuzzTest1();
|
||||
|
||||
Reference in New Issue
Block a user