Minireflect fixed array (#6129)

* CMakeLists: also really generate optional_scalars as needed by test elsewhere

* [C++] Handle fixed-length array in minireflection

Fixes #6128
This commit is contained in:
Mark Nauwelaerts
2020-09-23 02:57:01 +02:00
committed by GitHub
parent 96d5e35977
commit 34d67b425e
16 changed files with 127 additions and 73 deletions

View File

@@ -1108,6 +1108,30 @@ void MiniReflectFlatBuffersTest(uint8_t *flatbuf) {
"16, b: 32 } }");
}
void MiniReflectFixedLengthArrayTest() {
// VS10 does not support typed enums, exclude from tests
#if !defined(_MSC_VER) || _MSC_VER >= 1700
flatbuffers::FlatBufferBuilder fbb;
MyGame::Example::ArrayStruct aStruct(2, 12, 1);
auto aTable = MyGame::Example::CreateArrayTable(fbb, &aStruct);
fbb.Finish(aTable);
auto flatbuf = fbb.Release();
auto s = flatbuffers::FlatBufferToString(
flatbuf.data(), MyGame::Example::ArrayTableTypeTable());
TEST_EQ_STR(
"{ "
"a: { a: 2.0, "
"b: [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "
"c: 12, "
"d: [ { a: [ 0, 0 ], b: A, c: [ A, A ], d: [ 0, 0 ] }, "
"{ a: [ 0, 0 ], b: A, c: [ A, A ], d: [ 0, 0 ] } ], "
"e: 1, f: [ 0, 0 ] } "
"}",
s.c_str());
#endif
}
// Parse a .proto schema, output as .fbs
void ParseProtoTest() {
// load the .proto and the golden file from disk
@@ -3566,6 +3590,7 @@ int FlatBufferTests() {
ObjectFlatBuffersTest(flatbuf.data());
MiniReflectFlatBuffersTest(flatbuf.data());
MiniReflectFixedLengthArrayTest();
SizePrefixedTest();