Added way to test two schemas for safe evolution.

Change-Id: I1dfc867e6df5932ab61dad431eb3cb02f15d04df
Tested: on Linux.
Bug: 30202327
This commit is contained in:
Wouter van Oortmerssen
2016-07-20 17:24:50 -07:00
parent 77e9122681
commit 05b00c50ad
5 changed files with 146 additions and 33 deletions

View File

@@ -1060,6 +1060,24 @@ void ParseUnionTest() {
"{ X:{ A:1 }, X_type: T }"), true);
}
void ConformTest() {
flatbuffers::Parser parser;
TEST_EQ(parser.Parse("table T { A:int; } enum E:byte { A }"), true);
auto test_conform = [&](const char *test, const char *expected_err) {
flatbuffers::Parser parser2;
TEST_EQ(parser2.Parse(test), true);
auto err = parser2.ConformTo(parser);
TEST_NOTNULL(strstr(err.c_str(), expected_err));
};
test_conform("table T { A:byte; }", "types differ for field");
test_conform("table T { B:int; A:int; }", "offsets differ for field");
test_conform("table T { A:int = 1; }", "defaults differ for field");
test_conform("table T { B:float; }", "field renamed to different type");
test_conform("enum E:byte { B, A }", "values differ for enum");
}
int main(int /*argc*/, const char * /*argv*/[]) {
// Run our various test suites:
@@ -1091,6 +1109,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
UnicodeInvalidSurrogatesTest();
UnknownFieldsTest();
ParseUnionTest();
ConformTest();
if (!testing_fails) {
TEST_OUTPUT_LINE("ALL TESTS PASSED");