forked from BigfootDev/flatbuffers
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
#include "bigfoot_ref_test_impl.h"
|
|
|
|
#include "bigfoot_ref_test_generated.h"
|
|
#include "test_assert.h"
|
|
|
|
namespace flatbuffers {
|
|
BigfootRefTestNS::RefId Pack(const Native::RefId& obj) {
|
|
return BigfootRefTestNS::RefId(obj.value);
|
|
}
|
|
|
|
const Native::RefId UnPack(const BigfootRefTestNS::RefId& obj) {
|
|
return Native::RefId(obj.value());
|
|
}
|
|
} // namespace flatbuffers
|
|
|
|
namespace flatbuffers {
|
|
namespace tests {
|
|
|
|
// Exercises the --bigfoot_ref/--bigfoot_ref_wrapper flatc attributes (see
|
|
// tests/bigfoot_ref_test.fbs): a reference field never requires the
|
|
// referenced native type to be complete, and the generated header supplies
|
|
// its own forward declaration plus inline Pack/UnPack definitions, with no
|
|
// hand-written boilerplate anywhere in this file for `Thing`/`OtherThing`.
|
|
void BigfootRefTest() {
|
|
using BigfootRefTestNS::RefHolder;
|
|
using BigfootRefTestNS::RefHolderT;
|
|
|
|
RefHolderT src;
|
|
src.ref_a = Native::Ref<Native::Thing>(Native::RefId(1));
|
|
src.ref_a_again.push_back(Native::Ref<Native::Thing>(Native::RefId(2)));
|
|
src.ref_a_again.push_back(Native::Ref<Native::Thing>(Native::RefId(3)));
|
|
src.ref_b = Native::Ref<Native::OtherThing>(Native::RefId(4));
|
|
|
|
flatbuffers::FlatBufferBuilder fbb;
|
|
fbb.Finish(RefHolder::Pack(fbb, &src));
|
|
|
|
auto dst = BigfootRefTestNS::UnPackRefHolder(fbb.GetBufferPointer());
|
|
|
|
TEST_EQ(dst->ref_a.uuid.value, 1u);
|
|
TEST_EQ(dst->ref_a_again.size(), 2u);
|
|
TEST_EQ(dst->ref_a_again[0].uuid.value, 2u);
|
|
TEST_EQ(dst->ref_a_again[1].uuid.value, 3u);
|
|
TEST_EQ(dst->ref_b.uuid.value, 4u);
|
|
}
|
|
|
|
} // namespace tests
|
|
} // namespace flatbuffers
|