MCPcopy Create free account
hub / github.com/alibaba/MNN / ParseProtoTest

Function ParseProtoTest

3rd_party/flatbuffers/tests/test.cpp:878–927  ·  view source on GitHub ↗

Parse a .proto schema, output as .fbs

Source from the content-addressed store, hash-verified

876
877// Parse a .proto schema, output as .fbs
878void ParseProtoTest() {
879 // load the .proto and the golden file from disk
880 std::string protofile;
881 std::string goldenfile;
882 std::string goldenunionfile;
883 TEST_EQ(
884 flatbuffers::LoadFile((test_data_path + "prototest/test.proto").c_str(),
885 false, &protofile),
886 true);
887 TEST_EQ(
888 flatbuffers::LoadFile((test_data_path + "prototest/test.golden").c_str(),
889 false, &goldenfile),
890 true);
891 TEST_EQ(
892 flatbuffers::LoadFile((test_data_path +
893 "prototest/test_union.golden").c_str(),
894 false, &goldenunionfile),
895 true);
896
897 flatbuffers::IDLOptions opts;
898 opts.include_dependence_headers = false;
899 opts.proto_mode = true;
900
901 // Parse proto.
902 flatbuffers::Parser parser(opts);
903 auto protopath = test_data_path + "prototest/";
904 const char *include_directories[] = { protopath.c_str(), nullptr };
905 TEST_EQ(parser.Parse(protofile.c_str(), include_directories), true);
906
907 // Generate fbs.
908 auto fbs = flatbuffers::GenerateFBS(parser, "test");
909
910 // Ensure generated file is parsable.
911 flatbuffers::Parser parser2;
912 TEST_EQ(parser2.Parse(fbs.c_str(), nullptr), true);
913 TEST_EQ_STR(fbs.c_str(), goldenfile.c_str());
914
915 // Parse proto with --oneof-union option.
916 opts.proto_oneof_union = true;
917 flatbuffers::Parser parser3(opts);
918 TEST_EQ(parser3.Parse(protofile.c_str(), include_directories), true);
919
920 // Generate fbs.
921 auto fbs_union = flatbuffers::GenerateFBS(parser3, "test");
922
923 // Ensure generated file is parsable.
924 flatbuffers::Parser parser4;
925 TEST_EQ(parser4.Parse(fbs_union.c_str(), nullptr), true);
926 TEST_EQ_STR(fbs_union.c_str(), goldenunionfile.c_str());
927}
928
929template<typename T>
930void CompareTableFieldValue(flatbuffers::Table *table,

Callers 1

FlatBufferTestsFunction · 0.85

Calls 4

LoadFileFunction · 0.85
GenerateFBSFunction · 0.85
c_strMethod · 0.45
ParseMethod · 0.45

Tested by

no test coverage detected