mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-08 06:05:17 +00:00
UnPackTo disable merge by default (#7527)
* UnPackTo disable merge by default * avoid double free in test * remove merge parameter * remove shrink to fit
This commit is contained in:
@@ -6,9 +6,9 @@
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/registry.h"
|
||||
#include "flatbuffers/verifier.h"
|
||||
#include "is_quiet_nan.h"
|
||||
#include "monster_extra_generated.h"
|
||||
#include "monster_test_generated.h"
|
||||
#include "is_quiet_nan.h"
|
||||
#include "test_assert.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
@@ -170,7 +170,7 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {
|
||||
|
||||
FinishMonsterBuffer(builder, mloc);
|
||||
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_TEST_VERBOSE
|
||||
// print byte data for debugging:
|
||||
auto p = builder.GetBufferPointer();
|
||||
@@ -195,7 +195,7 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length, bool pooled) {
|
||||
verifier.SetFlexReuseTracker(&flex_reuse_tracker);
|
||||
TEST_EQ(VerifyMonsterBuffer(verifier), true);
|
||||
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
#ifdef FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE
|
||||
std::vector<uint8_t> test_buff;
|
||||
test_buff.resize(length * 2);
|
||||
@@ -715,7 +715,7 @@ void TypeAliasesTest() {
|
||||
|
||||
// example of parsing text straight into a buffer, and generating
|
||||
// text back from it:
|
||||
void ParseAndGenerateTextTest(const std::string& tests_data_path, bool binary) {
|
||||
void ParseAndGenerateTextTest(const std::string &tests_data_path, bool binary) {
|
||||
// load FlatBuffer schema (.fbs) and JSON from disk
|
||||
std::string schemafile;
|
||||
std::string jsonfile;
|
||||
@@ -810,5 +810,36 @@ void ParseAndGenerateTextTest(const std::string& tests_data_path, bool binary) {
|
||||
TEST_EQ_STR(jsongen_utf8.c_str(), jsonfile_utf8.c_str());
|
||||
}
|
||||
|
||||
void UnPackTo(const uint8_t *flatbuf) {
|
||||
// Get a monster that has a name and no enemy
|
||||
auto orig_monster = GetMonster(flatbuf);
|
||||
TEST_EQ_STR(orig_monster->name()->c_str(), "MyMonster");
|
||||
TEST_ASSERT(orig_monster->enemy() == nullptr);
|
||||
|
||||
// Create an enemy
|
||||
MonsterT *enemy = new MonsterT();
|
||||
enemy->name = "Enemy";
|
||||
|
||||
// And create another monster owning the enemy,
|
||||
MonsterT mon;
|
||||
mon.name = "I'm monster 1";
|
||||
mon.enemy.reset(enemy);
|
||||
TEST_ASSERT(mon.enemy != nullptr);
|
||||
|
||||
// Assert that all the Monster objects are correct.
|
||||
TEST_EQ_STR(mon.name.c_str(), "I'm monster 1");
|
||||
TEST_EQ_STR(enemy->name.c_str(), "Enemy");
|
||||
TEST_EQ_STR(mon.enemy->name.c_str(), "Enemy");
|
||||
|
||||
// Now unpack monster ("MyMonster") into monster
|
||||
orig_monster->UnPackTo(&mon);
|
||||
|
||||
// Monster name should be from monster
|
||||
TEST_EQ_STR(mon.name.c_str(), "MyMonster");
|
||||
|
||||
// The monster shouldn't have any enemies, because monster didn't.
|
||||
TEST_ASSERT(mon.enemy == nullptr);
|
||||
}
|
||||
|
||||
} // namespace tests
|
||||
} // namespace flatbuffers
|
||||
Reference in New Issue
Block a user