mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-03 02:22:26 +00:00
Cleaned up test output.
Change-Id: I4bec0e728cc162aa3f19091a0d154124ffbccdff
This commit is contained in:
130
tests/test.cpp
130
tests/test.cpp
@@ -104,19 +104,19 @@ flatbuffers::DetachedBuffer CreateFlatBufferTest(std::string &buffer) {
|
|||||||
auto testv = builder.CreateVectorOfStructs(tests, 2);
|
auto testv = builder.CreateVectorOfStructs(tests, 2);
|
||||||
|
|
||||||
|
|
||||||
#ifndef FLATBUFFERS_CPP98_STL
|
#ifndef FLATBUFFERS_CPP98_STL
|
||||||
// Create a vector of structures from a lambda.
|
// Create a vector of structures from a lambda.
|
||||||
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
||||||
2, [&](size_t i, Test* s) -> void {
|
2, [&](size_t i, Test* s) -> void {
|
||||||
*s = tests[i];
|
*s = tests[i];
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
// Create a vector of structures using a plain old C++ function.
|
// Create a vector of structures using a plain old C++ function.
|
||||||
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
auto testv2 = builder.CreateVectorOfStructs<Test>(
|
||||||
2, [](size_t i, Test* s, void *state) -> void {
|
2, [](size_t i, Test* s, void *state) -> void {
|
||||||
*s = (reinterpret_cast<Test*>(state))[i];
|
*s = (reinterpret_cast<Test*>(state))[i];
|
||||||
}, tests);
|
}, tests);
|
||||||
#endif // FLATBUFFERS_CPP98_STL
|
#endif // FLATBUFFERS_CPP98_STL
|
||||||
|
|
||||||
// create monster with very few fields set:
|
// create monster with very few fields set:
|
||||||
// (same functionality as CreateMonster below, but sets fields manually)
|
// (same functionality as CreateMonster below, but sets fields manually)
|
||||||
@@ -1071,9 +1071,11 @@ void FuzzTest2() {
|
|||||||
TEST_NOTNULL(NULL);
|
TEST_NOTNULL(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_OUTPUT_LINE("%dk schema tested with %dk of json\n",
|
#ifdef FLATBUFFERS_TEST_VERBOSE
|
||||||
static_cast<int>(schema.length() / 1024),
|
TEST_OUTPUT_LINE("%dk schema tested with %dk of json\n",
|
||||||
static_cast<int>(json.length() / 1024));
|
static_cast<int>(schema.length() / 1024),
|
||||||
|
static_cast<int>(json.length() / 1024));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that parser errors are actually generated.
|
// Test that parser errors are actually generated.
|
||||||
@@ -1594,55 +1596,57 @@ void FlexBuffersTest() {
|
|||||||
|
|
||||||
// Write the equivalent of:
|
// Write the equivalent of:
|
||||||
// { vec: [ -100, "Fred", 4.0, false ], bar: [ 1, 2, 3 ], bar3: [ 1, 2, 3 ], foo: 100, bool: true, mymap: { foo: "Fred" } }
|
// { vec: [ -100, "Fred", 4.0, false ], bar: [ 1, 2, 3 ], bar3: [ 1, 2, 3 ], foo: 100, bool: true, mymap: { foo: "Fred" } }
|
||||||
#ifndef FLATBUFFERS_CPP98_STL
|
#ifndef FLATBUFFERS_CPP98_STL
|
||||||
// It's possible to do this without std::function support as well.
|
// It's possible to do this without std::function support as well.
|
||||||
slb.Map([&]() {
|
slb.Map([&]() {
|
||||||
slb.Vector("vec", [&]() {
|
slb.Vector("vec", [&]() {
|
||||||
slb += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
slb += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
||||||
slb += "Fred";
|
slb += "Fred";
|
||||||
slb.IndirectFloat(4.0f);
|
slb.IndirectFloat(4.0f);
|
||||||
uint8_t blob[] = { 77 };
|
uint8_t blob[] = { 77 };
|
||||||
slb.Blob(blob, 1);
|
slb.Blob(blob, 1);
|
||||||
slb += false;
|
slb += false;
|
||||||
|
});
|
||||||
|
int ints[] = { 1, 2, 3 };
|
||||||
|
slb.Vector("bar", ints, 3);
|
||||||
|
slb.FixedTypedVector("bar3", ints, 3);
|
||||||
|
bool bools[] = {true, false, true, false};
|
||||||
|
slb.Vector("bools", bools, 4);
|
||||||
|
slb.Bool("bool", true);
|
||||||
|
slb.Double("foo", 100);
|
||||||
|
slb.Map("mymap", [&]() {
|
||||||
|
slb.String("foo", "Fred"); // Testing key and string reuse.
|
||||||
|
});
|
||||||
});
|
});
|
||||||
int ints[] = { 1, 2, 3 };
|
slb.Finish();
|
||||||
slb.Vector("bar", ints, 3);
|
#else
|
||||||
slb.FixedTypedVector("bar3", ints, 3);
|
// It's possible to do this without std::function support as well.
|
||||||
bool bools[] = {true, false, true, false};
|
slb.Map([](flexbuffers::Builder& slb2) {
|
||||||
slb.Vector("bools", bools, 4);
|
slb2.Vector("vec", [](flexbuffers::Builder& slb3) {
|
||||||
slb.Bool("bool", true);
|
slb3 += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
||||||
slb.Double("foo", 100);
|
slb3 += "Fred";
|
||||||
slb.Map("mymap", [&]() {
|
slb3.IndirectFloat(4.0f);
|
||||||
slb.String("foo", "Fred"); // Testing key and string reuse.
|
uint8_t blob[] = { 77 };
|
||||||
});
|
slb3.Blob(blob, 1);
|
||||||
});
|
slb3 += false;
|
||||||
slb.Finish();
|
}, slb2);
|
||||||
#else
|
int ints[] = { 1, 2, 3 };
|
||||||
// It's possible to do this without std::function support as well.
|
slb2.Vector("bar", ints, 3);
|
||||||
slb.Map([](flexbuffers::Builder& slb2) {
|
slb2.FixedTypedVector("bar3", ints, 3);
|
||||||
slb2.Vector("vec", [](flexbuffers::Builder& slb3) {
|
slb.Bool("bool", true);
|
||||||
slb3 += -100; // Equivalent to slb.Add(-100) or slb.Int(-100);
|
slb2.Double("foo", 100);
|
||||||
slb3 += "Fred";
|
slb2.Map("mymap", [](flexbuffers::Builder& slb3) {
|
||||||
slb3.IndirectFloat(4.0f);
|
slb3.String("foo", "Fred"); // Testing key and string reuse.
|
||||||
uint8_t blob[] = { 77 };
|
}, slb2);
|
||||||
slb3.Blob(blob, 1);
|
}, slb);
|
||||||
slb3 += false;
|
slb.Finish();
|
||||||
}, slb2);
|
#endif // FLATBUFFERS_CPP98_STL
|
||||||
int ints[] = { 1, 2, 3 };
|
|
||||||
slb2.Vector("bar", ints, 3);
|
|
||||||
slb2.FixedTypedVector("bar3", ints, 3);
|
|
||||||
slb.Bool("bool", true);
|
|
||||||
slb2.Double("foo", 100);
|
|
||||||
slb2.Map("mymap", [](flexbuffers::Builder& slb3) {
|
|
||||||
slb3.String("foo", "Fred"); // Testing key and string reuse.
|
|
||||||
}, slb2);
|
|
||||||
}, slb);
|
|
||||||
slb.Finish();
|
|
||||||
#endif // FLATBUFFERS_CPP98_STL
|
|
||||||
|
|
||||||
for (size_t i = 0; i < slb.GetBuffer().size(); i++)
|
#ifdef FLATBUFFERS_TEST_VERBOSE
|
||||||
printf("%d ", flatbuffers::vector_data(slb.GetBuffer())[i]);
|
for (size_t i = 0; i < slb.GetBuffer().size(); i++)
|
||||||
printf("\n");
|
printf("%d ", flatbuffers::vector_data(slb.GetBuffer())[i]);
|
||||||
|
printf("\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
auto map = flexbuffers::GetRoot(slb.GetBuffer()).AsMap();
|
auto map = flexbuffers::GetRoot(slb.GetBuffer()).AsMap();
|
||||||
TEST_EQ(map.size(), 7);
|
TEST_EQ(map.size(), 7);
|
||||||
|
|||||||
Reference in New Issue
Block a user