[C++] support native_inline attribute for vector of tables (#7479)

This commit is contained in:
sssooonnnggg
2022-08-30 03:48:10 +08:00
committed by GitHub
parent 694add668b
commit 6a87427540
8 changed files with 347 additions and 24 deletions

View File

@@ -30,6 +30,7 @@
#include "monster_test.h"
#include "monster_test_generated.h"
#include "optional_scalars_test.h"
#include "native_inline_table_test_generated.h"
#include "parser_test.h"
#include "proto_test.h"
#include "reflection_test.h"
@@ -1362,6 +1363,30 @@ void VectorSpanTest() {
}
}
void NativeInlineTableVectorTest() {
TestNativeInlineTableT test;
for (int i = 0; i < 10; ++i) {
NativeInlineTableT t;
t.a = i;
test.t.push_back(t);
}
flatbuffers::FlatBufferBuilder fbb;
auto offset = TestNativeInlineTable::Pack(fbb, &test);
fbb.Finish(offset);
auto *root =
flatbuffers::GetRoot<TestNativeInlineTable>(fbb.GetBufferPointer());
TestNativeInlineTableT unpacked;
root->UnPackTo(&unpacked);
for (int i = 0; i < 10; ++i) {
TEST_ASSERT(unpacked.t[i] == test.t[i]);
}
TEST_ASSERT(unpacked.t == test.t);
}
int FlatBufferTests(const std::string &tests_data_path) {
// Run our various test suites:
@@ -1460,6 +1485,7 @@ int FlatBufferTests(const std::string &tests_data_path) {
PrivateAnnotationsLeaks();
JsonUnsortedArrayTest();
VectorSpanTest();
NativeInlineTableVectorTest();
return 0;
}
} // namespace