diff options
author | Wouter van Oortmerssen <wvo@google.com> | 2016-07-14 10:55:22 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-14 10:55:22 -0700 |
commit | b22db6e8eb2f5d3d32927d09e71a55d7d21994ae (patch) | |
tree | 6444db71b7341d5b9b3d9310b199c5671fe9daf1 /tests | |
parent | 14e7e8260e7922e0baacea3cb1d9cb2877a264fc (diff) | |
parent | 3a1f776132cf9377e3a85a888e6ff2bc12c7248c (diff) | |
download | flatbuffers-b22db6e8eb2f5d3d32927d09e71a55d7d21994ae.tar.gz flatbuffers-b22db6e8eb2f5d3d32927d09e71a55d7d21994ae.tar.bz2 flatbuffers-b22db6e8eb2f5d3d32927d09e71a55d7d21994ae.zip |
Merge pull request #3905 from bog-dan-ro/master
Verifier computes the buffersize, useful when streaming multiple flatbuffers
Diffstat (limited to 'tests')
-rw-r--r-- | tests/monster_test_generated.h | 4 | ||||
-rw-r--r-- | tests/namespace_test/namespace_test1_generated.h | 2 | ||||
-rw-r--r-- | tests/namespace_test/namespace_test2_generated.h | 12 | ||||
-rw-r--r-- | tests/test.cpp | 18 |
4 files changed, 27 insertions, 9 deletions
diff --git a/tests/monster_test_generated.h b/tests/monster_test_generated.h index 40e7c408..9f3d4de0 100644 --- a/tests/monster_test_generated.h +++ b/tests/monster_test_generated.h @@ -510,12 +510,12 @@ inline const MyGame::Example::Monster *GetMonster(const void *buf) { return flat inline Monster *GetMutableMonster(void *buf) { return flatbuffers::GetMutableRoot<Monster>(buf); } -inline bool VerifyMonsterBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<MyGame::Example::Monster>(); } - inline const char *MonsterIdentifier() { return "MONS"; } inline bool MonsterBufferHasIdentifier(const void *buf) { return flatbuffers::BufferHasIdentifier(buf, MonsterIdentifier()); } +inline bool VerifyMonsterBuffer(flatbuffers::Verifier &verifier) { return verifier.VerifyBuffer<MyGame::Example::Monster>(MonsterIdentifier()); } + inline const char *MonsterExtension() { return "mon"; } inline void FinishMonsterBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<MyGame::Example::Monster> root) { fbb.Finish(root, MonsterIdentifier()); } diff --git a/tests/namespace_test/namespace_test1_generated.h b/tests/namespace_test/namespace_test1_generated.h index 9e10eb4c..23a0964f 100644 --- a/tests/namespace_test/namespace_test1_generated.h +++ b/tests/namespace_test/namespace_test1_generated.h @@ -69,7 +69,7 @@ struct TableInNestedNSBuilder { }; inline flatbuffers::Offset<TableInNestedNS> CreateTableInNestedNS(flatbuffers::FlatBufferBuilder &_fbb, - int32_t foo = 0) { + int32_t foo = 0) { TableInNestedNSBuilder builder_(_fbb); builder_.add_foo(foo); return builder_.Finish(); diff --git a/tests/namespace_test/namespace_test2_generated.h b/tests/namespace_test/namespace_test2_generated.h index 8e6b3ada..885eae29 100644 --- a/tests/namespace_test/namespace_test2_generated.h +++ b/tests/namespace_test/namespace_test2_generated.h @@ -60,9 +60,9 @@ struct TableInFirstNSBuilder { }; inline flatbuffers::Offset<TableInFirstNS> CreateTableInFirstNS(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset<NamespaceA::NamespaceB::TableInNestedNS> foo_table = 0, - NamespaceA::NamespaceB::EnumInNestedNS foo_enum = NamespaceA::NamespaceB::EnumInNestedNS_A, - const NamespaceA::NamespaceB::StructInNestedNS *foo_struct = 0) { + flatbuffers::Offset<NamespaceA::NamespaceB::TableInNestedNS> foo_table = 0, + NamespaceA::NamespaceB::EnumInNestedNS foo_enum = NamespaceA::NamespaceB::EnumInNestedNS_A, + const NamespaceA::NamespaceB::StructInNestedNS *foo_struct = 0) { TableInFirstNSBuilder builder_(_fbb); builder_.add_foo_struct(foo_struct); builder_.add_foo_table(foo_table); @@ -107,8 +107,8 @@ struct TableInCBuilder { }; inline flatbuffers::Offset<TableInC> CreateTableInC(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset<NamespaceA::TableInFirstNS> refer_to_a1 = 0, - flatbuffers::Offset<NamespaceA::SecondTableInA> refer_to_a2 = 0) { + flatbuffers::Offset<NamespaceA::TableInFirstNS> refer_to_a1 = 0, + flatbuffers::Offset<NamespaceA::SecondTableInA> refer_to_a2 = 0) { TableInCBuilder builder_(_fbb); builder_.add_refer_to_a2(refer_to_a2); builder_.add_refer_to_a1(refer_to_a1); @@ -146,7 +146,7 @@ struct SecondTableInABuilder { }; inline flatbuffers::Offset<SecondTableInA> CreateSecondTableInA(flatbuffers::FlatBufferBuilder &_fbb, - flatbuffers::Offset<NamespaceC::TableInC> refer_to_c = 0) { + flatbuffers::Offset<NamespaceC::TableInC> refer_to_c = 0) { SecondTableInABuilder builder_(_fbb); builder_.add_refer_to_c(refer_to_c); return builder_.Finish(); diff --git a/tests/test.cpp b/tests/test.cpp index 209ec699..402843a6 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -15,6 +15,7 @@ */ #define FLATBUFFERS_DEBUG_VERIFICATION_FAILURE 1 +#define FLATBUFFERS_TRACK_VERIFIER_BUFFER_SIZE #include "flatbuffers/flatbuffers.h" #include "flatbuffers/idl.h" @@ -160,6 +161,23 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length) { flatbuffers::Verifier verifier(flatbuf, length); TEST_EQ(VerifyMonsterBuffer(verifier), true); + std::vector<uint8_t> test_buff; + test_buff.resize(length * 2); + std::memcpy(&test_buff[0], flatbuf , length); + std::memcpy(&test_buff[length], flatbuf , length); + + flatbuffers::Verifier verifierl(&test_buff[0], length - 1); + TEST_EQ(VerifyMonsterBuffer(verifierl), false); + TEST_EQ(verifierl.GetComputedSize(), 0); + + flatbuffers::Verifier verifier1(&test_buff[0], length); + TEST_EQ(VerifyMonsterBuffer(verifier1), true); + TEST_EQ(verifier1.GetComputedSize(), length); + + flatbuffers::Verifier verifier2(&test_buff[length], length); + TEST_EQ(VerifyMonsterBuffer(verifier2), true); + TEST_EQ(verifier2.GetComputedSize(), length); + TEST_EQ(strcmp(MonsterIdentifier(), "MONS"), 0); TEST_EQ(MonsterBufferHasIdentifier(flatbuf), true); TEST_EQ(strcmp(MonsterExtension(), "mon"), 0); |