mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-16 17:22:21 +00:00
[C++] Refactor to conform to Google C++ style guide (#5608)
* Automatic refractor of C++ headers to Google C++ style guide * Automatic refractor of C++ source to Google C++ style guide * Automatic refractor of C++ tests to Google C++ style guide * Fixed clang-format issues by running clang-format twice to correct itself. Kotlin was missing clang-format on after turning it off, so it was changed,
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
e837d5a296
commit
f0f0efe7b8
@@ -1,13 +1,13 @@
|
||||
#include "native_type_test_impl.h"
|
||||
|
||||
#include "native_type_test_generated.h"
|
||||
|
||||
namespace flatbuffers {
|
||||
Geometry::Vector3D Pack(const Native::Vector3D &obj) {
|
||||
return Geometry::Vector3D(obj.x, obj.y, obj.z);
|
||||
}
|
||||
|
||||
const Native::Vector3D UnPack(const Geometry::Vector3D &obj) {
|
||||
return Native::Vector3D(obj.x(), obj.y(), obj.z());
|
||||
}
|
||||
Geometry::Vector3D Pack(const Native::Vector3D &obj) {
|
||||
return Geometry::Vector3D(obj.x, obj.y, obj.z);
|
||||
}
|
||||
|
||||
const Native::Vector3D UnPack(const Geometry::Vector3D &obj) {
|
||||
return Native::Vector3D(obj.x(), obj.y(), obj.z());
|
||||
}
|
||||
} // namespace flatbuffers
|
||||
|
||||
@@ -2,23 +2,31 @@
|
||||
#define NATIVE_TYPE_TEST_IMPL_H
|
||||
|
||||
namespace Native {
|
||||
struct Vector3D {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
struct Vector3D {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
|
||||
Vector3D() { x = 0; y = 0; z = 0; };
|
||||
Vector3D(float _x, float _y, float _z) { this->x = _x; this->y = _y; this->z = _z; }
|
||||
Vector3D() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
};
|
||||
}
|
||||
Vector3D(float _x, float _y, float _z) {
|
||||
this->x = _x;
|
||||
this->y = _y;
|
||||
this->z = _z;
|
||||
}
|
||||
};
|
||||
} // namespace Native
|
||||
|
||||
namespace Geometry {
|
||||
struct Vector3D;
|
||||
namespace Geometry {
|
||||
struct Vector3D;
|
||||
}
|
||||
|
||||
namespace flatbuffers {
|
||||
Geometry::Vector3D Pack(const Native::Vector3D &obj);
|
||||
const Native::Vector3D UnPack(const Geometry::Vector3D &obj);
|
||||
}
|
||||
Geometry::Vector3D Pack(const Native::Vector3D &obj);
|
||||
const Native::Vector3D UnPack(const Geometry::Vector3D &obj);
|
||||
} // namespace flatbuffers
|
||||
|
||||
#endif // VECTOR3D_PACK_H
|
||||
#endif // VECTOR3D_PACK_H
|
||||
|
||||
258
tests/test.cpp
258
tests/test.cpp
@@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <cmath>
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "flatbuffers/idl.h"
|
||||
#include "flatbuffers/minireflect.h"
|
||||
@@ -35,7 +36,7 @@
|
||||
#include "union_vector/union_vector_generated.h"
|
||||
#include "monster_extra_generated.h"
|
||||
#if !defined(_MSC_VER) || _MSC_VER >= 1700
|
||||
#include "arrays_test_generated.h"
|
||||
# include "arrays_test_generated.h"
|
||||
#endif
|
||||
|
||||
#include "native_type_test_generated.h"
|
||||
@@ -43,7 +44,6 @@
|
||||
|
||||
#include "flatbuffers/flexbuffers.h"
|
||||
|
||||
|
||||
// clang-format off
|
||||
// Check that char* and uint8_t* are interoperable types.
|
||||
// The reinterpret_cast<> between the pointers are used to simplify data loading.
|
||||
@@ -72,7 +72,8 @@ void FlatBufferBuilderTest();
|
||||
// http://en.wikipedia.org/wiki/Park%E2%80%93Miller_random_number_generator
|
||||
uint32_t lcg_seed = 48271;
|
||||
uint32_t lcg_rand() {
|
||||
return lcg_seed = (static_cast<uint64_t>(lcg_seed) * 279470273UL) % 4294967291UL;
|
||||
return lcg_seed =
|
||||
(static_cast<uint64_t>(lcg_seed) * 279470273UL) % 4294967291UL;
|
||||
}
|
||||
void lcg_reset() { lcg_seed = 48271; }
|
||||
|
||||
@@ -200,14 +201,13 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {
|
||||
auto vecofcolors = builder.CreateVectorScalarCast<uint8_t, Color>(colors, 2);
|
||||
|
||||
// shortcut for creating monster with all fields set:
|
||||
auto mloc = CreateMonster(builder, &vec, 150, 80, name, inventory, Color_Blue,
|
||||
Any_Monster, mlocs[1].Union(), // Store a union.
|
||||
testv, vecofstrings, vecoftables, 0,
|
||||
nested_flatbuffer_vector, 0, false, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 3.14159f, 3.0f, 0.0f, vecofstrings2,
|
||||
vecofstructs, flex, testv2, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, AnyUniqueAliases_NONE, 0,
|
||||
AnyAmbiguousAliases_NONE, 0, vecofcolors);
|
||||
auto mloc = CreateMonster(
|
||||
builder, &vec, 150, 80, name, inventory, Color_Blue, Any_Monster,
|
||||
mlocs[1].Union(), // Store a union.
|
||||
testv, vecofstrings, vecoftables, 0, nested_flatbuffer_vector, 0, false,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 3.14159f, 3.0f, 0.0f, vecofstrings2,
|
||||
vecofstructs, flex, testv2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
AnyUniqueAliases_NONE, 0, AnyAmbiguousAliases_NONE, 0, vecofcolors);
|
||||
|
||||
FinishMonsterBuffer(builder, mloc);
|
||||
|
||||
@@ -567,8 +567,7 @@ void SizePrefixedTest() {
|
||||
// Create size prefixed buffer.
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
FinishSizePrefixedMonsterBuffer(
|
||||
fbb,
|
||||
CreateMonster(fbb, 0, 200, 300, fbb.CreateString("bob")));
|
||||
fbb, CreateMonster(fbb, 0, 200, 300, fbb.CreateString("bob")));
|
||||
|
||||
// Verify it.
|
||||
flatbuffers::Verifier verifier(fbb.GetBufferPointer(), fbb.GetSize());
|
||||
@@ -598,7 +597,8 @@ void JsonDefaultTest() {
|
||||
// load FlatBuffer schema (.fbs) from disk
|
||||
std::string schemafile;
|
||||
TEST_EQ(flatbuffers::LoadFile((test_data_path + "monster_test.fbs").c_str(),
|
||||
false, &schemafile), true);
|
||||
false, &schemafile),
|
||||
true);
|
||||
// parse schema first, so we can use it to parse the data after
|
||||
flatbuffers::Parser parser;
|
||||
auto include_test_path =
|
||||
@@ -771,7 +771,7 @@ void ParseAndGenerateTextTest(bool binary) {
|
||||
true);
|
||||
|
||||
auto include_test_path =
|
||||
flatbuffers::ConCatPathFileName(test_data_path, "include_test");
|
||||
flatbuffers::ConCatPathFileName(test_data_path, "include_test");
|
||||
const char *include_directories[] = { test_data_path.c_str(),
|
||||
include_test_path.c_str(), nullptr };
|
||||
|
||||
@@ -782,8 +782,10 @@ void ParseAndGenerateTextTest(bool binary) {
|
||||
reinterpret_cast<const uint8_t *>(schemafile.c_str()),
|
||||
schemafile.size());
|
||||
TEST_EQ(reflection::VerifySchemaBuffer(verifier), true);
|
||||
//auto schema = reflection::GetSchema(schemafile.c_str());
|
||||
TEST_EQ(parser.Deserialize((const uint8_t *)schemafile.c_str(), schemafile.size()), true);
|
||||
// auto schema = reflection::GetSchema(schemafile.c_str());
|
||||
TEST_EQ(parser.Deserialize((const uint8_t *)schemafile.c_str(),
|
||||
schemafile.size()),
|
||||
true);
|
||||
} else {
|
||||
TEST_EQ(parser.Parse(schemafile.c_str(), include_directories), true);
|
||||
}
|
||||
@@ -1029,7 +1031,8 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
|
||||
}
|
||||
|
||||
void MiniReflectFlatBuffersTest(uint8_t *flatbuf) {
|
||||
auto s = flatbuffers::FlatBufferToString(flatbuf, Monster::MiniReflectTypeTable());
|
||||
auto s =
|
||||
flatbuffers::FlatBufferToString(flatbuf, Monster::MiniReflectTypeTable());
|
||||
TEST_EQ_STR(
|
||||
s.c_str(),
|
||||
"{ "
|
||||
@@ -1060,15 +1063,15 @@ void MiniReflectFlatBuffersTest(uint8_t *flatbuf) {
|
||||
"}");
|
||||
|
||||
Test test(16, 32);
|
||||
Vec3 vec(1,2,3, 1.5, Color_Red, test);
|
||||
Vec3 vec(1, 2, 3, 1.5, Color_Red, test);
|
||||
flatbuffers::FlatBufferBuilder vec_builder;
|
||||
vec_builder.Finish(vec_builder.CreateStruct(vec));
|
||||
auto vec_buffer = vec_builder.Release();
|
||||
auto vec_str = flatbuffers::FlatBufferToString(vec_buffer.data(),
|
||||
Vec3::MiniReflectTypeTable());
|
||||
TEST_EQ_STR(
|
||||
vec_str.c_str(),
|
||||
"{ x: 1.0, y: 2.0, z: 3.0, test1: 1.5, test2: Red, test3: { a: 16, b: 32 } }");
|
||||
TEST_EQ_STR(vec_str.c_str(),
|
||||
"{ x: 1.0, y: 2.0, z: 3.0, test1: 1.5, test2: Red, test3: { a: "
|
||||
"16, b: 32 } }");
|
||||
}
|
||||
|
||||
// Parse a .proto schema, output as .fbs
|
||||
@@ -1085,11 +1088,10 @@ void ParseProtoTest() {
|
||||
flatbuffers::LoadFile((test_data_path + "prototest/test.golden").c_str(),
|
||||
false, &goldenfile),
|
||||
true);
|
||||
TEST_EQ(
|
||||
flatbuffers::LoadFile((test_data_path +
|
||||
"prototest/test_union.golden").c_str(),
|
||||
false, &goldenunionfile),
|
||||
true);
|
||||
TEST_EQ(flatbuffers::LoadFile(
|
||||
(test_data_path + "prototest/test_union.golden").c_str(), false,
|
||||
&goldenunionfile),
|
||||
true);
|
||||
|
||||
flatbuffers::IDLOptions opts;
|
||||
opts.include_dependence_headers = false;
|
||||
@@ -1526,9 +1528,9 @@ bool FloatCompare(float a, float b) { return fabs(a - b) < 0.001; }
|
||||
// Additional parser testing not covered elsewhere.
|
||||
void ValueTest() {
|
||||
// Test scientific notation numbers.
|
||||
TEST_EQ(FloatCompare(TestValue<float>("{ Y:0.0314159e+2 }", "float"),
|
||||
3.14159f),
|
||||
true);
|
||||
TEST_EQ(
|
||||
FloatCompare(TestValue<float>("{ Y:0.0314159e+2 }", "float"), 3.14159f),
|
||||
true);
|
||||
// number in string
|
||||
TEST_EQ(FloatCompare(TestValue<float>("{ Y:\"0.0314159e+2\" }", "float"),
|
||||
3.14159f),
|
||||
@@ -1566,7 +1568,6 @@ void ValueTest() {
|
||||
// check comments before and after json object
|
||||
TEST_EQ(TestValue<int>("/*before*/ { Y:1 } /*after*/", "int"), 1);
|
||||
TEST_EQ(TestValue<int>("//before \n { Y:1 } //after", "int"), 1);
|
||||
|
||||
}
|
||||
|
||||
void NestedListTest() {
|
||||
@@ -1608,8 +1609,8 @@ void EnumNamesTest() {
|
||||
// For details see C++17 standard or explanation on the SO:
|
||||
// stackoverflow.com/questions/18195312/what-happens-if-you-static-cast-invalid-value-to-enum-class
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(0)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY-1)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY+1)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY - 1)));
|
||||
TEST_EQ_STR("", EnumNameColor(static_cast<Color>(Color_ANY + 1)));
|
||||
}
|
||||
|
||||
void EnumOutOfRangeTest() {
|
||||
@@ -1629,12 +1630,14 @@ void EnumOutOfRangeTest() {
|
||||
TestError("enum X:uint { Y = -1 }", "enum value does not fit");
|
||||
TestError("enum X:uint { Y = 4294967297 }", "enum value does not fit");
|
||||
TestError("enum X:long { Y = 9223372036854775808 }", "does not fit");
|
||||
TestError("enum X:long { Y = 9223372036854775807, Z }", "enum value does not fit");
|
||||
TestError("enum X:long { Y = 9223372036854775807, Z }",
|
||||
"enum value does not fit");
|
||||
TestError("enum X:ulong { Y = -1 }", "does not fit");
|
||||
TestError("enum X:ubyte (bit_flags) { Y=8 }", "bit flag out");
|
||||
TestError("enum X:byte (bit_flags) { Y=7 }", "must be unsigned"); // -128
|
||||
TestError("enum X:byte (bit_flags) { Y=7 }", "must be unsigned"); // -128
|
||||
// bit_flgs out of range
|
||||
TestError("enum X:ubyte (bit_flags) { Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8 }", "out of range");
|
||||
TestError("enum X:ubyte (bit_flags) { Y0,Y1,Y2,Y3,Y4,Y5,Y6,Y7,Y8 }",
|
||||
"out of range");
|
||||
}
|
||||
|
||||
void EnumValueTest() {
|
||||
@@ -1734,11 +1737,12 @@ void IntegerOutOfRangeTest() {
|
||||
|
||||
void IntegerBoundaryTest() {
|
||||
// Check numerical compatibility with non-C++ languages.
|
||||
// By the C++ standard, std::numerical_limits<int64_t>::min() == -9223372036854775807 (-2^63+1) or less*
|
||||
// The Flatbuffers grammar and most of the languages (C#, Java, Rust) expect
|
||||
// that minimum values are: -128, -32768,.., -9223372036854775808.
|
||||
// Since C++20, static_cast<int64>(0x8000000000000000ULL) is well-defined two's complement cast.
|
||||
// Therefore -9223372036854775808 should be valid negative value.
|
||||
// By the C++ standard, std::numerical_limits<int64_t>::min() ==
|
||||
// -9223372036854775807 (-2^63+1) or less* The Flatbuffers grammar and most of
|
||||
// the languages (C#, Java, Rust) expect that minimum values are: -128,
|
||||
// -32768,.., -9223372036854775808. Since C++20,
|
||||
// static_cast<int64>(0x8000000000000000ULL) is well-defined two's complement
|
||||
// cast. Therefore -9223372036854775808 should be valid negative value.
|
||||
TEST_EQ(flatbuffers::numeric_limits<int8_t>::min(), -128);
|
||||
TEST_EQ(flatbuffers::numeric_limits<int8_t>::max(), 127);
|
||||
TEST_EQ(flatbuffers::numeric_limits<int16_t>::min(), -32768);
|
||||
@@ -1810,11 +1814,11 @@ void ValidFloatTest() {
|
||||
TEST_EQ(TestValue<float>("{ Y:5 }", "float"), 5.0f);
|
||||
TEST_EQ(TestValue<float>("{ Y:\"5\" }", "float"), 5.0f);
|
||||
|
||||
#if defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
||||
#if defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
||||
// Old MSVC versions may have problem with this check.
|
||||
// https://www.exploringbinary.com/visual-c-plus-plus-strtod-still-broken/
|
||||
TEST_EQ(TestValue<double>("{ Y:6.9294956446009195e15 }", "double"),
|
||||
6929495644600920.0);
|
||||
6929495644600920.0);
|
||||
// check nan's
|
||||
TEST_EQ(std::isnan(TestValue<double>("{ Y:nan }", "double")), true);
|
||||
TEST_EQ(std::isnan(TestValue<float>("{ Y:nan }", "float")), true);
|
||||
@@ -1936,8 +1940,8 @@ void GenerateTableTextTest() {
|
||||
TEST_EQ(ok, true);
|
||||
auto include_test_path =
|
||||
flatbuffers::ConCatPathFileName(test_data_path, "include_test");
|
||||
const char *include_directories[] = {test_data_path.c_str(),
|
||||
include_test_path.c_str(), nullptr};
|
||||
const char *include_directories[] = { test_data_path.c_str(),
|
||||
include_test_path.c_str(), nullptr };
|
||||
flatbuffers::IDLOptions opt;
|
||||
opt.indent_step = -1;
|
||||
flatbuffers::Parser parser(opt);
|
||||
@@ -2237,7 +2241,7 @@ void InvalidUTF8Test() {
|
||||
// Check independence of identifier from locale.
|
||||
std::string locale_ident;
|
||||
locale_ident += "table T { F";
|
||||
locale_ident += static_cast<char>(-32); // unsigned 0xE0
|
||||
locale_ident += static_cast<char>(-32); // unsigned 0xE0
|
||||
locale_ident += " :string; }";
|
||||
locale_ident += "root_type T;";
|
||||
locale_ident += "{}";
|
||||
@@ -2311,8 +2315,8 @@ void UnionVectorTest() {
|
||||
// load FlatBuffer fbs schema and json.
|
||||
std::string schemafile, jsonfile;
|
||||
TEST_EQ(flatbuffers::LoadFile(
|
||||
(test_data_path + "union_vector/union_vector.fbs").c_str(),
|
||||
false, &schemafile),
|
||||
(test_data_path + "union_vector/union_vector.fbs").c_str(), false,
|
||||
&schemafile),
|
||||
true);
|
||||
TEST_EQ(flatbuffers::LoadFile(
|
||||
(test_data_path + "union_vector/union_vector.json").c_str(),
|
||||
@@ -2420,70 +2424,67 @@ void UnionVectorTest() {
|
||||
"characters: [ { books_read: 7 }, { sword_attack_damage: 5 }, "
|
||||
"{ books_read: 2 }, \"Other\", \"Unused\" ] }");
|
||||
|
||||
|
||||
flatbuffers::ToStringVisitor visitor("\n", true, " ");
|
||||
IterateFlatBuffer(fbb.GetBufferPointer(), MovieTypeTable(), &visitor);
|
||||
TEST_EQ_STR(
|
||||
visitor.s.c_str(),
|
||||
"{\n"
|
||||
" \"main_character_type\": \"Rapunzel\",\n"
|
||||
" \"main_character\": {\n"
|
||||
" \"hair_length\": 6\n"
|
||||
" },\n"
|
||||
" \"characters_type\": [\n"
|
||||
" \"Belle\",\n"
|
||||
" \"MuLan\",\n"
|
||||
" \"BookFan\",\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ],\n"
|
||||
" \"characters\": [\n"
|
||||
" {\n"
|
||||
" \"books_read\": 7\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"sword_attack_damage\": 5\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"books_read\": 2\n"
|
||||
" },\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ]\n"
|
||||
"}");
|
||||
TEST_EQ_STR(visitor.s.c_str(),
|
||||
"{\n"
|
||||
" \"main_character_type\": \"Rapunzel\",\n"
|
||||
" \"main_character\": {\n"
|
||||
" \"hair_length\": 6\n"
|
||||
" },\n"
|
||||
" \"characters_type\": [\n"
|
||||
" \"Belle\",\n"
|
||||
" \"MuLan\",\n"
|
||||
" \"BookFan\",\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ],\n"
|
||||
" \"characters\": [\n"
|
||||
" {\n"
|
||||
" \"books_read\": 7\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"sword_attack_damage\": 5\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"books_read\": 2\n"
|
||||
" },\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ]\n"
|
||||
"}");
|
||||
|
||||
// Generate text using parsed schema.
|
||||
std::string jsongen;
|
||||
auto result = GenerateText(parser, fbb.GetBufferPointer(), &jsongen);
|
||||
TEST_EQ(result, true);
|
||||
TEST_EQ_STR(
|
||||
jsongen.c_str(),
|
||||
"{\n"
|
||||
" main_character_type: \"Rapunzel\",\n"
|
||||
" main_character: {\n"
|
||||
" hair_length: 6\n"
|
||||
" },\n"
|
||||
" characters_type: [\n"
|
||||
" \"Belle\",\n"
|
||||
" \"MuLan\",\n"
|
||||
" \"BookFan\",\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ],\n"
|
||||
" characters: [\n"
|
||||
" {\n"
|
||||
" books_read: 7\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" sword_attack_damage: 5\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" books_read: 2\n"
|
||||
" },\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ]\n"
|
||||
"}\n");
|
||||
TEST_EQ_STR(jsongen.c_str(),
|
||||
"{\n"
|
||||
" main_character_type: \"Rapunzel\",\n"
|
||||
" main_character: {\n"
|
||||
" hair_length: 6\n"
|
||||
" },\n"
|
||||
" characters_type: [\n"
|
||||
" \"Belle\",\n"
|
||||
" \"MuLan\",\n"
|
||||
" \"BookFan\",\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ],\n"
|
||||
" characters: [\n"
|
||||
" {\n"
|
||||
" books_read: 7\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" sword_attack_damage: 5\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" books_read: 2\n"
|
||||
" },\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ]\n"
|
||||
"}\n");
|
||||
|
||||
// Simple test with reflection.
|
||||
parser.Serialize();
|
||||
@@ -2496,7 +2497,8 @@ void UnionVectorTest() {
|
||||
TEST_EQ(parser2.Parse("struct Bool { b:bool; }"
|
||||
"union Any { Bool }"
|
||||
"table Root { a:Any; }"
|
||||
"root_type Root;"), true);
|
||||
"root_type Root;"),
|
||||
true);
|
||||
TEST_EQ(parser2.Parse("{a_type:Bool,a:{b:true}}"), true);
|
||||
}
|
||||
|
||||
@@ -2703,7 +2705,7 @@ void TypeAliasesTest() {
|
||||
TEST_EQ(ta->u64(), flatbuffers::numeric_limits<uint64_t>::max());
|
||||
TEST_EQ(ta->f32(), 2.3f);
|
||||
TEST_EQ(ta->f64(), 2.3);
|
||||
using namespace flatbuffers; // is_same
|
||||
using namespace flatbuffers; // is_same
|
||||
static_assert(is_same<decltype(ta->i8()), int8_t>::value, "invalid type");
|
||||
static_assert(is_same<decltype(ta->i16()), int16_t>::value, "invalid type");
|
||||
static_assert(is_same<decltype(ta->i32()), int32_t>::value, "invalid type");
|
||||
@@ -2729,14 +2731,16 @@ void UninitializedVectorTest() {
|
||||
flatbuffers::FlatBufferBuilder builder;
|
||||
|
||||
Test *buf = nullptr;
|
||||
auto vector_offset = builder.CreateUninitializedVectorOfStructs<Test>(2, &buf);
|
||||
auto vector_offset =
|
||||
builder.CreateUninitializedVectorOfStructs<Test>(2, &buf);
|
||||
TEST_NOTNULL(buf);
|
||||
buf[0] = Test(10, 20);
|
||||
buf[1] = Test(30, 40);
|
||||
|
||||
auto required_name = builder.CreateString("myMonster");
|
||||
auto monster_builder = MonsterBuilder(builder);
|
||||
monster_builder.add_name(required_name); // required field mandated for monster.
|
||||
monster_builder.add_name(
|
||||
required_name); // required field mandated for monster.
|
||||
monster_builder.add_test4(vector_offset);
|
||||
builder.Finish(monster_builder.Finish());
|
||||
|
||||
@@ -2781,11 +2785,11 @@ void EqualOperatorTest() {
|
||||
// For testing any binaries, e.g. from fuzzing.
|
||||
void LoadVerifyBinaryTest() {
|
||||
std::string binary;
|
||||
if (flatbuffers::LoadFile((test_data_path +
|
||||
"fuzzer/your-filename-here").c_str(),
|
||||
true, &binary)) {
|
||||
if (flatbuffers::LoadFile(
|
||||
(test_data_path + "fuzzer/your-filename-here").c_str(), true,
|
||||
&binary)) {
|
||||
flatbuffers::Verifier verifier(
|
||||
reinterpret_cast<const uint8_t *>(binary.data()), binary.size());
|
||||
reinterpret_cast<const uint8_t *>(binary.data()), binary.size());
|
||||
TEST_EQ(VerifyMonsterBuffer(verifier), true);
|
||||
}
|
||||
}
|
||||
@@ -2801,24 +2805,28 @@ void CreateSharedStringTest() {
|
||||
TEST_EQ(onetwo.o != two.o, true);
|
||||
|
||||
// Support for embedded nulls
|
||||
const char chars_b[] = {'a', '\0', 'b'};
|
||||
const char chars_c[] = {'a', '\0', 'c'};
|
||||
const char chars_b[] = { 'a', '\0', 'b' };
|
||||
const char chars_c[] = { 'a', '\0', 'c' };
|
||||
const auto null_b1 = builder.CreateSharedString(chars_b, sizeof(chars_b));
|
||||
const auto null_c = builder.CreateSharedString(chars_c, sizeof(chars_c));
|
||||
const auto null_b2 = builder.CreateSharedString(chars_b, sizeof(chars_b));
|
||||
TEST_EQ(null_b1.o != null_c.o, true); // Issue#5058 repro
|
||||
TEST_EQ(null_b1.o != null_c.o, true); // Issue#5058 repro
|
||||
TEST_EQ(null_b1.o, null_b2.o);
|
||||
|
||||
// Put the strings into an array for round trip verification.
|
||||
const flatbuffers::Offset<flatbuffers::String> array[7] = { one1, two, one2, onetwo, null_b1, null_c, null_b2 };
|
||||
const auto vector_offset = builder.CreateVector(array, flatbuffers::uoffset_t(7));
|
||||
const flatbuffers::Offset<flatbuffers::String> array[7] = {
|
||||
one1, two, one2, onetwo, null_b1, null_c, null_b2
|
||||
};
|
||||
const auto vector_offset =
|
||||
builder.CreateVector(array, flatbuffers::uoffset_t(7));
|
||||
MonsterBuilder monster_builder(builder);
|
||||
monster_builder.add_name(two);
|
||||
monster_builder.add_testarrayofstring(vector_offset);
|
||||
builder.Finish(monster_builder.Finish());
|
||||
|
||||
// Read the Monster back.
|
||||
const auto *monster = flatbuffers::GetRoot<Monster>(builder.GetBufferPointer());
|
||||
const auto *monster =
|
||||
flatbuffers::GetRoot<Monster>(builder.GetBufferPointer());
|
||||
TEST_EQ_STR(monster->name()->c_str(), "two");
|
||||
const auto *testarrayofstring = monster->testarrayofstring();
|
||||
TEST_EQ(testarrayofstring->size(), flatbuffers::uoffset_t(7));
|
||||
@@ -2831,7 +2839,8 @@ void CreateSharedStringTest() {
|
||||
TEST_EQ(a[5]->str(), (std::string(chars_c, sizeof(chars_c))));
|
||||
TEST_EQ(a[6]->str(), (std::string(chars_b, sizeof(chars_b))));
|
||||
|
||||
// Make sure String::operator< works, too, since it is related to StringOffsetCompare.
|
||||
// Make sure String::operator< works, too, since it is related to
|
||||
// StringOffsetCompare.
|
||||
TEST_EQ((*a[0]) < (*a[1]), true);
|
||||
TEST_EQ((*a[1]) < (*a[0]), false);
|
||||
TEST_EQ((*a[1]) < (*a[2]), false);
|
||||
@@ -2943,16 +2952,17 @@ void NativeTypeTest() {
|
||||
src_data.vectors.reserve(N);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
src_data.vectors.push_back (Native::Vector3D(10 * i + 0.1f, 10 * i + 0.2f, 10 * i + 0.3f));
|
||||
src_data.vectors.push_back(
|
||||
Native::Vector3D(10 * i + 0.1f, 10 * i + 0.2f, 10 * i + 0.3f));
|
||||
}
|
||||
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
fbb.Finish(Geometry::ApplicationData::Pack(fbb, &src_data));
|
||||
|
||||
auto dstDataT = Geometry::UnPackApplicationData(fbb.GetBufferPointer());
|
||||
auto dstDataT = Geometry::UnPackApplicationData(fbb.GetBufferPointer());
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
Native::Vector3D& v = dstDataT->vectors[i];
|
||||
Native::Vector3D &v = dstDataT->vectors[i];
|
||||
TEST_EQ(v.x, 10 * i + 0.1f);
|
||||
TEST_EQ(v.y, 10 * i + 0.2f);
|
||||
TEST_EQ(v.z, 10 * i + 0.3f);
|
||||
@@ -3107,7 +3117,7 @@ int FlatBufferTests() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/ []) {
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
InitTestEngine();
|
||||
|
||||
std::string req_locale;
|
||||
|
||||
@@ -31,7 +31,7 @@ void TestEqStr(const char *expval, const char *val, const char *exp,
|
||||
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && defined(_MSC_VER) && \
|
||||
defined(_DEBUG)
|
||||
#define FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC
|
||||
# define FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC
|
||||
#endif
|
||||
|
||||
void InitTestEngine(TestFailEventListener listener) {
|
||||
@@ -58,12 +58,12 @@ void InitTestEngine(TestFailEventListener listener) {
|
||||
|
||||
int CloseTestEngine(bool force_report) {
|
||||
if (!testing_fails || force_report) {
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC)
|
||||
auto flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||
flags &= ~_CRTDBG_DELAY_FREE_MEM_DF;
|
||||
flags |= _CRTDBG_LEAK_CHECK_DF;
|
||||
_CrtSetDbgFlag(flags);
|
||||
#endif
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING_MSVC)
|
||||
auto flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||
flags &= ~_CRTDBG_DELAY_FREE_MEM_DF;
|
||||
flags |= _CRTDBG_LEAK_CHECK_DF;
|
||||
_CrtSetDbgFlag(flags);
|
||||
#endif
|
||||
}
|
||||
return (0 != testing_fails);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "flatbuffers/stl_emulation.h"
|
||||
|
||||
#include "monster_test_generated.h"
|
||||
#include "test_builder.h"
|
||||
|
||||
#include "flatbuffers/stl_emulation.h"
|
||||
#include "monster_test_generated.h"
|
||||
|
||||
using namespace MyGame::Example;
|
||||
|
||||
const std::string m1_name = "Cyberdemon";
|
||||
@@ -13,7 +13,7 @@ const Color m2_color = Color_Green;
|
||||
struct OwnedAllocator : public flatbuffers::DefaultAllocator {};
|
||||
|
||||
class TestHeapBuilder : public flatbuffers::FlatBufferBuilder {
|
||||
private:
|
||||
private:
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
TestHeapBuilder(const TestHeapBuilder &);
|
||||
@@ -21,15 +21,15 @@ private:
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
public:
|
||||
TestHeapBuilder()
|
||||
: flatbuffers::FlatBufferBuilder(2048, new OwnedAllocator(), true) {}
|
||||
: flatbuffers::FlatBufferBuilder(2048, new OwnedAllocator(), true) {}
|
||||
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
TestHeapBuilder(TestHeapBuilder &&other)
|
||||
: FlatBufferBuilder(std::move(other)) { }
|
||||
: FlatBufferBuilder(std::move(other)) {}
|
||||
|
||||
TestHeapBuilder &operator=(TestHeapBuilder &&other) {
|
||||
FlatBufferBuilder::operator=(std::move(other));
|
||||
@@ -47,16 +47,16 @@ struct AllocatorMember {
|
||||
|
||||
struct GrpcLikeMessageBuilder : private AllocatorMember,
|
||||
public flatbuffers::FlatBufferBuilder {
|
||||
private:
|
||||
private:
|
||||
GrpcLikeMessageBuilder(const GrpcLikeMessageBuilder &);
|
||||
GrpcLikeMessageBuilder &operator=(const GrpcLikeMessageBuilder &);
|
||||
|
||||
public:
|
||||
public:
|
||||
GrpcLikeMessageBuilder()
|
||||
: flatbuffers::FlatBufferBuilder(1024, &member_allocator_, false) {}
|
||||
: flatbuffers::FlatBufferBuilder(1024, &member_allocator_, false) {}
|
||||
|
||||
GrpcLikeMessageBuilder(GrpcLikeMessageBuilder &&other)
|
||||
: FlatBufferBuilder(1024, &member_allocator_, false) {
|
||||
: FlatBufferBuilder(1024, &member_allocator_, false) {
|
||||
// Default construct and swap idiom.
|
||||
Swap(other);
|
||||
}
|
||||
@@ -77,53 +77,63 @@ public:
|
||||
void Swap(GrpcLikeMessageBuilder &other) {
|
||||
// No need to swap member_allocator_ because it's stateless.
|
||||
FlatBufferBuilder::Swap(other);
|
||||
// After swapping the FlatBufferBuilder, we swap back the allocator, which restores
|
||||
// the original allocator back in place. This is necessary because MessageBuilder's
|
||||
// allocator is its own member (SliceAllocatorMember). The allocator passed to
|
||||
// FlatBufferBuilder::vector_downward must point to this member.
|
||||
// After swapping the FlatBufferBuilder, we swap back the allocator, which
|
||||
// restores the original allocator back in place. This is necessary because
|
||||
// MessageBuilder's allocator is its own member (SliceAllocatorMember). The
|
||||
// allocator passed to FlatBufferBuilder::vector_downward must point to this
|
||||
// member.
|
||||
buf_.swap_allocator(other.buf_);
|
||||
}
|
||||
};
|
||||
|
||||
flatbuffers::Offset<Monster> populate1(flatbuffers::FlatBufferBuilder &builder) {
|
||||
flatbuffers::Offset<Monster> populate1(
|
||||
flatbuffers::FlatBufferBuilder &builder) {
|
||||
auto name_offset = builder.CreateString(m1_name);
|
||||
return CreateMonster(builder, nullptr, 0, 0, name_offset, 0, m1_color);
|
||||
}
|
||||
|
||||
flatbuffers::Offset<Monster> populate2(flatbuffers::FlatBufferBuilder &builder) {
|
||||
flatbuffers::Offset<Monster> populate2(
|
||||
flatbuffers::FlatBufferBuilder &builder) {
|
||||
auto name_offset = builder.CreateString(m2_name);
|
||||
return CreateMonster(builder, nullptr, 0, 0, name_offset, 0, m2_color);
|
||||
}
|
||||
|
||||
uint8_t *release_raw_base(flatbuffers::FlatBufferBuilder &fbb, size_t &size, size_t &offset) {
|
||||
uint8_t *release_raw_base(flatbuffers::FlatBufferBuilder &fbb, size_t &size,
|
||||
size_t &offset) {
|
||||
return fbb.ReleaseRaw(size, offset);
|
||||
}
|
||||
|
||||
void free_raw(flatbuffers::grpc::MessageBuilder &, uint8_t *) {
|
||||
// release_raw_base calls FlatBufferBuilder::ReleaseRaw on the argument MessageBuilder.
|
||||
// It's semantically wrong as MessageBuilder has its own ReleaseRaw member function that
|
||||
// takes three arguments. In such cases though, ~MessageBuilder() invokes
|
||||
// ~SliceAllocator() that takes care of deleting memory as it calls grpc_slice_unref.
|
||||
// Obviously, this behavior is very surprising as the pointer returned by
|
||||
// FlatBufferBuilder::ReleaseRaw is not valid as soon as MessageBuilder goes out of scope.
|
||||
// This problem does not occur with FlatBufferBuilder.
|
||||
// release_raw_base calls FlatBufferBuilder::ReleaseRaw on the argument
|
||||
// MessageBuilder. It's semantically wrong as MessageBuilder has its own
|
||||
// ReleaseRaw member function that takes three arguments. In such cases
|
||||
// though, ~MessageBuilder() invokes ~SliceAllocator() that takes care of
|
||||
// deleting memory as it calls grpc_slice_unref. Obviously, this behavior is
|
||||
// very surprising as the pointer returned by FlatBufferBuilder::ReleaseRaw is
|
||||
// not valid as soon as MessageBuilder goes out of scope. This problem does
|
||||
// not occur with FlatBufferBuilder.
|
||||
}
|
||||
|
||||
void free_raw(flatbuffers::FlatBufferBuilder &, uint8_t *buf) {
|
||||
flatbuffers::DefaultAllocator().deallocate(buf, 0);
|
||||
}
|
||||
|
||||
bool verify(const flatbuffers::DetachedBuffer &buf, const std::string &expected_name, Color color) {
|
||||
bool verify(const flatbuffers::DetachedBuffer &buf,
|
||||
const std::string &expected_name, Color color) {
|
||||
const Monster *monster = flatbuffers::GetRoot<Monster>(buf.data());
|
||||
return (monster->name()->str() == expected_name) && (monster->color() == color);
|
||||
return (monster->name()->str() == expected_name) &&
|
||||
(monster->color() == color);
|
||||
}
|
||||
|
||||
bool verify(const uint8_t *buf, size_t offset, const std::string &expected_name, Color color) {
|
||||
const Monster *monster = flatbuffers::GetRoot<Monster>(buf+offset);
|
||||
return (monster->name()->str() == expected_name) && (monster->color() == color);
|
||||
bool verify(const uint8_t *buf, size_t offset, const std::string &expected_name,
|
||||
Color color) {
|
||||
const Monster *monster = flatbuffers::GetRoot<Monster>(buf + offset);
|
||||
return (monster->name()->str() == expected_name) &&
|
||||
(monster->color() == color);
|
||||
}
|
||||
|
||||
bool release_n_verify(flatbuffers::FlatBufferBuilder &fbb, const std::string &expected_name, Color color) {
|
||||
bool release_n_verify(flatbuffers::FlatBufferBuilder &fbb,
|
||||
const std::string &expected_name, Color color) {
|
||||
flatbuffers::DetachedBuffer buf = fbb.Release();
|
||||
return verify(buf, expected_name, color);
|
||||
}
|
||||
@@ -136,13 +146,15 @@ void FlatBufferBuilderTest() {
|
||||
BuilderTests<GrpcLikeMessageBuilder>::all_tests();
|
||||
|
||||
BuilderReuseTestSelector tests[4] = {
|
||||
REUSABLE_AFTER_RELEASE,
|
||||
REUSABLE_AFTER_RELEASE_RAW,
|
||||
REUSABLE_AFTER_RELEASE, REUSABLE_AFTER_RELEASE_RAW,
|
||||
REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN,
|
||||
REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN
|
||||
};
|
||||
|
||||
BuilderReuseTests<FlatBufferBuilder, FlatBufferBuilder>::run_tests(TestSelector(tests, tests+4));
|
||||
BuilderReuseTests<TestHeapBuilder, TestHeapBuilder>::run_tests(TestSelector(tests, tests+4));
|
||||
BuilderReuseTests<GrpcLikeMessageBuilder, GrpcLikeMessageBuilder>::run_tests(TestSelector(tests, tests+4));
|
||||
BuilderReuseTests<FlatBufferBuilder, FlatBufferBuilder>::run_tests(
|
||||
TestSelector(tests, tests + 4));
|
||||
BuilderReuseTests<TestHeapBuilder, TestHeapBuilder>::run_tests(
|
||||
TestSelector(tests, tests + 4));
|
||||
BuilderReuseTests<GrpcLikeMessageBuilder, GrpcLikeMessageBuilder>::run_tests(
|
||||
TestSelector(tests, tests + 4));
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
#include "monster_test_generated.h"
|
||||
|
||||
#include "flatbuffers/flatbuffers.h"
|
||||
#include "monster_test_generated.h"
|
||||
#include "test_assert.h"
|
||||
|
||||
using MyGame::Example::Color;
|
||||
@@ -14,17 +15,11 @@ namespace flatbuffers {
|
||||
namespace grpc {
|
||||
class MessageBuilder;
|
||||
}
|
||||
}
|
||||
} // namespace flatbuffers
|
||||
|
||||
template <class T, class U>
|
||||
struct is_same {
|
||||
static const bool value = false;
|
||||
};
|
||||
template<class T, class U> struct is_same { static const bool value = false; };
|
||||
|
||||
template <class T>
|
||||
struct is_same<T, T> {
|
||||
static const bool value = true;
|
||||
};
|
||||
template<class T> struct is_same<T, T> { static const bool value = true; };
|
||||
|
||||
extern const std::string m1_name;
|
||||
extern const Color m1_color;
|
||||
@@ -34,30 +29,36 @@ extern const Color m2_color;
|
||||
flatbuffers::Offset<Monster> populate1(flatbuffers::FlatBufferBuilder &builder);
|
||||
flatbuffers::Offset<Monster> populate2(flatbuffers::FlatBufferBuilder &builder);
|
||||
|
||||
uint8_t *release_raw_base(flatbuffers::FlatBufferBuilder &fbb, size_t &size, size_t &offset);
|
||||
uint8_t *release_raw_base(flatbuffers::FlatBufferBuilder &fbb, size_t &size,
|
||||
size_t &offset);
|
||||
|
||||
void free_raw(flatbuffers::grpc::MessageBuilder &mbb, uint8_t *buf);
|
||||
void free_raw(flatbuffers::FlatBufferBuilder &fbb, uint8_t *buf);
|
||||
|
||||
bool verify(const flatbuffers::DetachedBuffer &buf, const std::string &expected_name, Color color);
|
||||
bool verify(const uint8_t *buf, size_t offset, const std::string &expected_name, Color color);
|
||||
bool verify(const flatbuffers::DetachedBuffer &buf,
|
||||
const std::string &expected_name, Color color);
|
||||
bool verify(const uint8_t *buf, size_t offset, const std::string &expected_name,
|
||||
Color color);
|
||||
|
||||
bool release_n_verify(flatbuffers::FlatBufferBuilder &fbb, const std::string &expected_name, Color color);
|
||||
bool release_n_verify(flatbuffers::grpc::MessageBuilder &mbb, const std::string &expected_name, Color color);
|
||||
bool release_n_verify(flatbuffers::FlatBufferBuilder &fbb,
|
||||
const std::string &expected_name, Color color);
|
||||
bool release_n_verify(flatbuffers::grpc::MessageBuilder &mbb,
|
||||
const std::string &expected_name, Color color);
|
||||
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
// Invokes this function when testing the following Builder types
|
||||
// FlatBufferBuilder, TestHeapBuilder, and GrpcLikeMessageBuilder
|
||||
template <class Builder>
|
||||
template<class Builder>
|
||||
void builder_move_assign_after_releaseraw_test(Builder b1) {
|
||||
auto root_offset1 = populate1(b1);
|
||||
b1.Finish(root_offset1);
|
||||
size_t size, offset;
|
||||
std::shared_ptr<uint8_t> raw(b1.ReleaseRaw(size, offset), [size](uint8_t *ptr) {
|
||||
flatbuffers::DefaultAllocator::dealloc(ptr, size);
|
||||
});
|
||||
std::shared_ptr<uint8_t> raw(
|
||||
b1.ReleaseRaw(size, offset), [size](uint8_t *ptr) {
|
||||
flatbuffers::DefaultAllocator::dealloc(ptr, size);
|
||||
});
|
||||
Builder src;
|
||||
auto root_offset2 = populate2(src);
|
||||
src.Finish(root_offset2);
|
||||
@@ -72,9 +73,10 @@ void builder_move_assign_after_releaseraw_test(Builder b1) {
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
void builder_move_assign_after_releaseraw_test(flatbuffers::grpc::MessageBuilder b1);
|
||||
void builder_move_assign_after_releaseraw_test(
|
||||
flatbuffers::grpc::MessageBuilder b1);
|
||||
|
||||
template <class DestBuilder, class SrcBuilder = DestBuilder>
|
||||
template<class DestBuilder, class SrcBuilder = DestBuilder>
|
||||
struct BuilderTests {
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
@@ -164,9 +166,10 @@ struct BuilderTests {
|
||||
#endif // !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
|
||||
static void builder_swap_before_finish_test(bool run = is_same<DestBuilder, SrcBuilder>::value) {
|
||||
static void builder_swap_before_finish_test(
|
||||
bool run = is_same<DestBuilder, SrcBuilder>::value) {
|
||||
/// Swap is allowed only when lhs and rhs are the same concrete type.
|
||||
if(run) {
|
||||
if (run) {
|
||||
SrcBuilder src;
|
||||
auto root_offset1 = populate1(src);
|
||||
auto size1 = src.GetSize();
|
||||
@@ -183,9 +186,10 @@ struct BuilderTests {
|
||||
}
|
||||
}
|
||||
|
||||
static void builder_swap_after_finish_test(bool run = is_same<DestBuilder, SrcBuilder>::value) {
|
||||
static void builder_swap_after_finish_test(
|
||||
bool run = is_same<DestBuilder, SrcBuilder>::value) {
|
||||
/// Swap is allowed only when lhs and rhs are the same concrete type.
|
||||
if(run) {
|
||||
if (run) {
|
||||
SrcBuilder src;
|
||||
auto root_offset1 = populate1(src);
|
||||
src.Finish(root_offset1);
|
||||
@@ -233,12 +237,9 @@ enum BuilderReuseTestSelector {
|
||||
|
||||
typedef std::set<BuilderReuseTestSelector> TestSelector;
|
||||
|
||||
template <class DestBuilder, class SrcBuilder>
|
||||
struct BuilderReuseTests {
|
||||
template<class DestBuilder, class SrcBuilder> struct BuilderReuseTests {
|
||||
static void builder_reusable_after_release_test(TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE)) {
|
||||
return;
|
||||
}
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE)) { return; }
|
||||
|
||||
DestBuilder fbb;
|
||||
std::vector<flatbuffers::DetachedBuffer> buffers;
|
||||
@@ -251,9 +252,7 @@ struct BuilderReuseTests {
|
||||
}
|
||||
|
||||
static void builder_reusable_after_releaseraw_test(TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW)) {
|
||||
return;
|
||||
}
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW)) { return; }
|
||||
|
||||
DestBuilder fbb;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
@@ -269,10 +268,9 @@ struct BuilderReuseTests {
|
||||
// clang-format off
|
||||
#if !defined(FLATBUFFERS_CPP98_STL)
|
||||
// clang-format on
|
||||
static void builder_reusable_after_release_and_move_assign_test(TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) {
|
||||
return;
|
||||
}
|
||||
static void builder_reusable_after_release_and_move_assign_test(
|
||||
TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_AND_MOVE_ASSIGN)) { return; }
|
||||
|
||||
DestBuilder dst;
|
||||
std::vector<flatbuffers::DetachedBuffer> buffers;
|
||||
@@ -287,10 +285,9 @@ struct BuilderReuseTests {
|
||||
}
|
||||
}
|
||||
|
||||
static void builder_reusable_after_releaseraw_and_move_assign_test(TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN)) {
|
||||
return;
|
||||
}
|
||||
static void builder_reusable_after_releaseraw_and_move_assign_test(
|
||||
TestSelector selector) {
|
||||
if (!selector.count(REUSABLE_AFTER_RELEASE_RAW_AND_MOVE_ASSIGN)) { return; }
|
||||
|
||||
DestBuilder dst;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
@@ -323,4 +320,4 @@ struct BuilderReuseTests {
|
||||
}
|
||||
};
|
||||
|
||||
#endif // TEST_BUILDER_H
|
||||
#endif // TEST_BUILDER_H
|
||||
|
||||
Reference in New Issue
Block a user