mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-25 14:38:40 +00:00
Run clang-format -i **/*.cpp (#8865)
This commit is contained in:
@@ -79,7 +79,7 @@ void Offset64Test() {
|
||||
}
|
||||
|
||||
{
|
||||
const RootTable *root_table = GetRootTable(builder.GetBufferPointer());
|
||||
const RootTable* root_table = GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Expect the far vector to be properly sized.
|
||||
TEST_EQ(root_table->far_vector()->size(), far_vector_size);
|
||||
@@ -130,12 +130,12 @@ void Offset64NestedFlatBuffer() {
|
||||
fbb.Finish(root_table_offset);
|
||||
|
||||
// Ensure the buffer is valid.
|
||||
const RootTable *root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
const RootTable* root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "nested: some near string");
|
||||
|
||||
// Copy the data out of the builder.
|
||||
std::vector<uint8_t> nested_data{ fbb.GetBufferPointer(),
|
||||
fbb.GetBufferPointer() + fbb.GetSize() };
|
||||
std::vector<uint8_t> nested_data{fbb.GetBufferPointer(),
|
||||
fbb.GetBufferPointer() + fbb.GetSize()};
|
||||
|
||||
{
|
||||
// Clear so we can reuse the builder.
|
||||
@@ -167,7 +167,7 @@ void Offset64NestedFlatBuffer() {
|
||||
}
|
||||
|
||||
{
|
||||
const RootTable *root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
const RootTable* root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
|
||||
// Test that the parent buffer field is ok.
|
||||
TEST_EQ_STR(root_table->near_string()->c_str(), "some near string");
|
||||
@@ -185,7 +185,7 @@ void Offset64CreateDirect() {
|
||||
FlatBufferBuilder64 fbb;
|
||||
|
||||
// Create a vector of some data
|
||||
std::vector<uint8_t> data{ 0, 1, 2 };
|
||||
std::vector<uint8_t> data{0, 1, 2};
|
||||
|
||||
// Call the "Direct" creation method to ensure that things are added to the
|
||||
// buffer in the correct order, Offset64 first followed by any Offsets.
|
||||
@@ -205,7 +205,7 @@ void Offset64CreateDirect() {
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
|
||||
// Verify the data.
|
||||
const RootTable *root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
const RootTable* root_table = GetRootTable(fbb.GetBufferPointer());
|
||||
TEST_EQ(root_table->far_vector()->size(), data.size());
|
||||
TEST_EQ(root_table->big_vector()->size(), data.size());
|
||||
TEST_EQ_STR(root_table->far_string()->c_str(), "some far string");
|
||||
@@ -214,8 +214,8 @@ void Offset64CreateDirect() {
|
||||
|
||||
void Offset64Evolution() {
|
||||
// Some common data for the tests.
|
||||
const std::vector<uint8_t> data = { 1, 2, 3, 4 };
|
||||
const std::vector<uint8_t> big_data = { 6, 7, 8, 9, 10 };
|
||||
const std::vector<uint8_t> data = {1, 2, 3, 4};
|
||||
const std::vector<uint8_t> big_data = {6, 7, 8, 9, 10};
|
||||
|
||||
// Built V1 read V2
|
||||
{
|
||||
@@ -301,13 +301,13 @@ void Offset64VectorOfStructs() {
|
||||
FlatBufferBuilder64 builder;
|
||||
|
||||
std::vector<LeafStruct> far_leaves;
|
||||
far_leaves.emplace_back(LeafStruct{ 123, 4.567 });
|
||||
far_leaves.emplace_back(LeafStruct{ 987, 6.543 });
|
||||
far_leaves.emplace_back(LeafStruct{123, 4.567});
|
||||
far_leaves.emplace_back(LeafStruct{987, 6.543});
|
||||
|
||||
std::vector<LeafStruct> big_leaves;
|
||||
big_leaves.emplace_back(LeafStruct{ 72, 72.8 });
|
||||
big_leaves.emplace_back(LeafStruct{ 82, 82.8 });
|
||||
big_leaves.emplace_back(LeafStruct{ 92, 92.8 });
|
||||
big_leaves.emplace_back(LeafStruct{72, 72.8});
|
||||
big_leaves.emplace_back(LeafStruct{82, 82.8});
|
||||
big_leaves.emplace_back(LeafStruct{92, 92.8});
|
||||
|
||||
// Add the two vectors of leaf structs.
|
||||
const Offset<RootTable> root_table_offset =
|
||||
@@ -327,7 +327,7 @@ void Offset64VectorOfStructs() {
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
|
||||
// Verify the data.
|
||||
const RootTable *root_table = GetRootTable(builder.GetBufferPointer());
|
||||
const RootTable* root_table = GetRootTable(builder.GetBufferPointer());
|
||||
TEST_EQ(root_table->far_struct_vector()->size(), far_leaves.size());
|
||||
TEST_EQ(root_table->far_struct_vector()->Get(0)->a(), 123);
|
||||
TEST_EQ(root_table->far_struct_vector()->Get(0)->b(), 4.567);
|
||||
@@ -369,7 +369,7 @@ void Offset64SizePrefix() {
|
||||
|
||||
TEST_EQ(VerifySizePrefixedRootTableBuffer(verifier), true);
|
||||
|
||||
const RootTable *root_table =
|
||||
const RootTable* root_table =
|
||||
GetSizePrefixedRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Verify the fields.
|
||||
@@ -432,7 +432,7 @@ void Offset64ManyVectors() {
|
||||
|
||||
TEST_EQ(VerifyRootTableBuffer(verifier), true);
|
||||
|
||||
const RootTable *root_table = GetRootTable(builder.GetBufferPointer());
|
||||
const RootTable* root_table = GetRootTable(builder.GetBufferPointer());
|
||||
|
||||
// Verify the fields.
|
||||
TEST_EQ_STR(root_table->far_string()->c_str(), "some far string");
|
||||
@@ -449,7 +449,7 @@ void Offset64ForceAlign() {
|
||||
|
||||
// Setup some data to serialize that is less than the force_align size of 32
|
||||
// bytes.
|
||||
std::vector<uint8_t> data{ 1, 2, 3 };
|
||||
std::vector<uint8_t> data{1, 2, 3};
|
||||
|
||||
// Use the CreateDirect which calls the ForceVectorAlign
|
||||
const auto root_table_offset =
|
||||
|
||||
@@ -48,22 +48,22 @@ using ::cpp17::MyGame::Example::Vec3;
|
||||
** Build some FB objects.
|
||||
*******************************************************************************/
|
||||
namespace {
|
||||
const Monster *BuildMonster(flatbuffers::FlatBufferBuilder &fbb) {
|
||||
const Monster* BuildMonster(flatbuffers::FlatBufferBuilder& fbb) {
|
||||
using ::cpp17::MyGame::Example::Color;
|
||||
using ::cpp17::MyGame::Example::MonsterBuilder;
|
||||
using ::cpp17::MyGame::Example::Test;
|
||||
auto name = fbb.CreateString("my_monster");
|
||||
auto inventory = fbb.CreateVector(std::vector<uint8_t>{ 4, 5, 6, 7 });
|
||||
auto inventory = fbb.CreateVector(std::vector<uint8_t>{4, 5, 6, 7});
|
||||
MonsterBuilder builder(fbb);
|
||||
auto vec3 = Vec3{ /*x=*/1.1f,
|
||||
/*y=*/2.2f,
|
||||
/*z=*/3.3f,
|
||||
/*test1=*/6.6,
|
||||
/*test2=*/Color::Green,
|
||||
/*test3=*/
|
||||
Test(
|
||||
/*a=*/11,
|
||||
/*b=*/90) };
|
||||
auto vec3 = Vec3{/*x=*/1.1f,
|
||||
/*y=*/2.2f,
|
||||
/*z=*/3.3f,
|
||||
/*test1=*/6.6,
|
||||
/*test2=*/Color::Green,
|
||||
/*test3=*/
|
||||
Test(
|
||||
/*a=*/11,
|
||||
/*b=*/90)};
|
||||
builder.add_pos(&vec3);
|
||||
builder.add_name(name);
|
||||
builder.add_mana(1);
|
||||
@@ -85,7 +85,7 @@ const Monster *BuildMonster(flatbuffers::FlatBufferBuilder &fbb) {
|
||||
builder.add_non_owning_reference(17);
|
||||
builder.add_inventory(inventory);
|
||||
fbb.Finish(builder.Finish());
|
||||
const Monster *monster =
|
||||
const Monster* monster =
|
||||
flatbuffers::GetRoot<Monster>(fbb.GetBufferPointer());
|
||||
return monster;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ void StringifyAnyFlatbuffersTypeTest() {
|
||||
flatbuffers::FlatBufferBuilder fbb;
|
||||
// We are using a Monster here, but we could have used any type, because the
|
||||
// code that follows is totally generic!
|
||||
const auto *monster = BuildMonster(fbb);
|
||||
const auto* monster = BuildMonster(fbb);
|
||||
|
||||
std::string expected = R"(MyGame.Example.Monster{
|
||||
pos = MyGame.Example.Vec3{
|
||||
@@ -179,13 +179,13 @@ void StringifyAnyFlatbuffersTypeTest() {
|
||||
** Test Traits::FieldType
|
||||
*******************************************************************************/
|
||||
using pos_type = Monster::Traits::FieldType<0>;
|
||||
static_assert(std::is_same_v<pos_type, const Vec3 *>);
|
||||
static_assert(std::is_same_v<pos_type, const Vec3*>);
|
||||
|
||||
using mana_type = Monster::Traits::FieldType<1>;
|
||||
static_assert(std::is_same_v<mana_type, int16_t>);
|
||||
|
||||
using name_type = Monster::Traits::FieldType<3>;
|
||||
static_assert(std::is_same_v<name_type, const flatbuffers::String *>);
|
||||
static_assert(std::is_same_v<name_type, const flatbuffers::String*>);
|
||||
|
||||
/*******************************************************************************
|
||||
** Generic Create Function Test.
|
||||
@@ -263,7 +263,7 @@ int FlatBufferCpp17Tests() {
|
||||
}
|
||||
} // namespace
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
int main(int /*argc*/, const char* /*argv*/[]) {
|
||||
InitTestEngine();
|
||||
|
||||
FlatBufferCpp17Tests();
|
||||
|
||||
@@ -1,31 +1,32 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string>
|
||||
#include "flatbuffers/idl.h" // For Parser and generation functions
|
||||
#include "test_init.h"
|
||||
#include <memory>
|
||||
#include <bfbs_gen_lua.h>
|
||||
#include <bfbs_gen_nim.h>
|
||||
#include <flatbuffers/flatc.h>
|
||||
#include "idl_gen_cpp.h" // For C++ generator
|
||||
#include <idl_gen_csharp.h>
|
||||
#include <iostream>
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include <idl_gen_binary.h>
|
||||
#include <idl_gen_csharp.h>
|
||||
#include <idl_gen_dart.h>
|
||||
#include <idl_gen_fbs.h>
|
||||
#include <idl_gen_go.h>
|
||||
#include <idl_gen_java.h>
|
||||
#include <idl_gen_json_schema.h>
|
||||
#include <idl_gen_kotlin.h>
|
||||
#include <idl_gen_kotlin.h>
|
||||
#include <idl_gen_lobster.h>
|
||||
#include <bfbs_gen_lua.h>
|
||||
#include <bfbs_gen_nim.h>
|
||||
#include <idl_gen_python.h>
|
||||
#include <idl_gen_php.h>
|
||||
#include <idl_gen_python.h>
|
||||
#include <idl_gen_rust.h>
|
||||
#include <idl_gen_text.h>
|
||||
#include <idl_gen_swift.h>
|
||||
#include <idl_gen_text.h>
|
||||
#include <idl_gen_ts.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "flatbuffers/code_generator.h"
|
||||
#include "flatbuffers/idl.h" // For Parser and generation functions
|
||||
#include "idl_gen_cpp.h" // For C++ generator
|
||||
#include "test_init.h"
|
||||
|
||||
static constexpr size_t kMinInputLength = 1;
|
||||
static constexpr size_t kMaxInputLength = 16384;
|
||||
@@ -98,8 +99,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
if (parser.Parse(parse_input)) {
|
||||
parser.Serialize();
|
||||
const uint8_t* buf = parser.builder_.GetBufferPointer();
|
||||
flatbuffers::Verifier verifier(buf,
|
||||
parser.builder_.GetSize());
|
||||
flatbuffers::Verifier verifier(buf, parser.builder_.GetSize());
|
||||
TEST_EQ(true, reflection::VerifySchemaBuffer(verifier));
|
||||
|
||||
auto root = flatbuffers::GetRoot<flatbuffers::Table>(buf);
|
||||
@@ -126,8 +126,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
generators.emplace_back(flatbuffers::NewKotlinCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewKotlinKMPCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewLobsterCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewLuaBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(flatbuffers::NewNimBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(
|
||||
flatbuffers::NewLuaBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(
|
||||
flatbuffers::NewNimBfbsGenerator(flatbuffers_version));
|
||||
generators.emplace_back(flatbuffers::NewPythonCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewPhpCodeGenerator());
|
||||
generators.emplace_back(flatbuffers::NewRustCodeGenerator());
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: monster_debug <path to fuzzer crash file>\n";
|
||||
return 0;
|
||||
@@ -23,7 +24,7 @@ int main(int argc, char *argv[]) {
|
||||
return -2;
|
||||
}
|
||||
auto rc = LLVMFuzzerTestOneInput(
|
||||
reinterpret_cast<const uint8_t *>(crash_file_data.data()),
|
||||
reinterpret_cast<const uint8_t*>(crash_file_data.data()),
|
||||
crash_file_data.size());
|
||||
std::cout << "LLVMFuzzerTestOneInput finished with code " << rc << "\n\n";
|
||||
return rc;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "flatbuffers/util.h"
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size);
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size);
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2) {
|
||||
std::cerr << "Usage: scalar_debug <path to fuzzer crash file>\n";
|
||||
return 0;
|
||||
@@ -21,7 +22,7 @@ int main(int argc, char *argv[]) {
|
||||
return -2;
|
||||
}
|
||||
auto rc = LLVMFuzzerTestOneInput(
|
||||
reinterpret_cast<const uint8_t *>(crash_file_data.data()),
|
||||
reinterpret_cast<const uint8_t*>(crash_file_data.data()),
|
||||
crash_file_data.size());
|
||||
std::cout << "LLVMFuzzerTestOneInput finished with code " << rc << "\n\n";
|
||||
return rc;
|
||||
|
||||
@@ -22,15 +22,19 @@ const Native::Vector3D UnPackVector3DAlt(const Geometry::Vector3DAlt& obj) {
|
||||
|
||||
namespace Geometry {
|
||||
void Matrix::UnPackTo(
|
||||
Native::Matrix *_o,
|
||||
const ::flatbuffers::resolver_function_t *_resolver) const {
|
||||
Native::Matrix* _o,
|
||||
const ::flatbuffers::resolver_function_t* _resolver) const {
|
||||
(void)_resolver;
|
||||
|
||||
auto _rows = rows();
|
||||
if (_rows) { _o->rows = _rows; }
|
||||
if (_rows) {
|
||||
_o->rows = _rows;
|
||||
}
|
||||
|
||||
auto _columns = columns();
|
||||
if (_columns) { _o->columns = _columns; }
|
||||
if (_columns) {
|
||||
_o->columns = _columns;
|
||||
}
|
||||
|
||||
auto _values = values();
|
||||
if (_values) {
|
||||
@@ -42,8 +46,8 @@ void Matrix::UnPackTo(
|
||||
}
|
||||
|
||||
::flatbuffers::Offset<Matrix> Matrix::Pack(
|
||||
::flatbuffers::FlatBufferBuilder &_fbb, const Native::Matrix *_o,
|
||||
const ::flatbuffers::rehasher_function_t *_rehasher) {
|
||||
::flatbuffers::FlatBufferBuilder& _fbb, const Native::Matrix* _o,
|
||||
const ::flatbuffers::rehasher_function_t* _rehasher) {
|
||||
(void)_rehasher;
|
||||
|
||||
return CreateMatrix(_fbb, _o->rows, _o->columns,
|
||||
|
||||
@@ -20,7 +20,7 @@ struct Vector3D {
|
||||
this->z = _z;
|
||||
}
|
||||
|
||||
bool operator==(const Vector3D &other) const {
|
||||
bool operator==(const Vector3D& other) const {
|
||||
return (x == other.x) && (y == other.y) && (z == other.z);
|
||||
}
|
||||
};
|
||||
@@ -38,7 +38,7 @@ struct Matrix {
|
||||
values.resize(_rows * _columns);
|
||||
}
|
||||
|
||||
bool operator==(const Matrix &other) const {
|
||||
bool operator==(const Matrix& other) const {
|
||||
return (rows == other.rows) && (columns == other.columns) &&
|
||||
(values == other.values);
|
||||
}
|
||||
|
||||
@@ -771,15 +771,15 @@ void FixedLengthArrayTest() {
|
||||
// set memory chunk of size ArrayStruct to 1's
|
||||
std::memset(static_cast<void*>(non_zero_memory), 1, arr_size);
|
||||
// after placement-new it should be all 0's
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
||||
defined(_MSC_VER) && defined(_DEBUG)
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && defined(_MSC_VER) && \
|
||||
defined(_DEBUG)
|
||||
#undef new
|
||||
#endif
|
||||
MyGame::Example::ArrayStruct* ap =
|
||||
new (non_zero_memory) MyGame::Example::ArrayStruct;
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && \
|
||||
defined(_MSC_VER) && defined(_DEBUG)
|
||||
#define new DEBUG_NEW
|
||||
#if defined(FLATBUFFERS_MEMORY_LEAK_TRACKING) && defined(_MSC_VER) && \
|
||||
defined(_DEBUG)
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
(void)ap;
|
||||
for (size_t i = 0; i < arr_size; ++i) {
|
||||
@@ -925,7 +925,8 @@ void NativeTypeTest() {
|
||||
src_data.matrix->values = {3, 4};
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
src_data.matrices.push_back(std::unique_ptr<Native::Matrix>(new Native::Matrix(1, i)));
|
||||
src_data.matrices.push_back(
|
||||
std::unique_ptr<Native::Matrix>(new Native::Matrix(1, i)));
|
||||
std::fill(src_data.matrices[i]->values.begin(),
|
||||
src_data.matrices[i]->values.end(), i + 0.5f);
|
||||
}
|
||||
@@ -960,7 +961,7 @@ void NativeTypeTest() {
|
||||
TEST_EQ(dstDataT->matrix->values[1], 4);
|
||||
|
||||
for (int i = 0; i < N; ++i) {
|
||||
const Native::Matrix &m = *dstDataT->matrices[i];
|
||||
const Native::Matrix& m = *dstDataT->matrices[i];
|
||||
TEST_EQ(m.rows, 1);
|
||||
TEST_EQ(m.columns, i);
|
||||
for (int j = 0; j < i; ++j) {
|
||||
|
||||
Reference in New Issue
Block a user