summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2016-02-29 15:47:46 -0800
committerWouter van Oortmerssen <wvo@google.com>2016-03-07 12:58:36 -0800
commit958fc6ec49199ba47dd2492bef51845a53ec27e2 (patch)
tree2833a6d65dac786027ce16d473d9aa1517a4cdda /tests
parent19afcdc70483d9f1111382fee96126f3407d8b6b (diff)
downloadflatbuffers-958fc6ec49199ba47dd2492bef51845a53ec27e2.tar.gz
flatbuffers-958fc6ec49199ba47dd2492bef51845a53ec27e2.tar.bz2
flatbuffers-958fc6ec49199ba47dd2492bef51845a53ec27e2.zip
Added support for easy string pooling.
Change-Id: I790cf681c1bffff800d77afb0e2f908d1c827679 Tested: on Linux. Bug: 26186542
Diffstat (limited to 'tests')
-rw-r--r--tests/test.cpp20
1 files changed, 13 insertions, 7 deletions
diff --git a/tests/test.cpp b/tests/test.cpp
index fce249e9..52da4518 100644
--- a/tests/test.cpp
+++ b/tests/test.cpp
@@ -113,11 +113,13 @@ flatbuffers::unique_ptr_t CreateFlatBufferTest(std::string &buffer) {
mb3.add_name(wilma);
mlocs[2] = mb3.Finish();
- // Create an array of strings:
- flatbuffers::Offset<flatbuffers::String> strings[2];
- strings[0] = builder.CreateString("bob");
- strings[1] = builder.CreateString("fred");
- auto vecofstrings = builder.CreateVector(strings, 2);
+ // Create an array of strings. Also test string pooling.
+ flatbuffers::Offset<flatbuffers::String> strings[4];
+ strings[0] = builder.CreateSharedString("bob");
+ strings[1] = builder.CreateSharedString("fred");
+ strings[2] = builder.CreateSharedString("bob");
+ strings[3] = builder.CreateSharedString("fred");
+ auto vecofstrings = builder.CreateVector(strings, 4);
// Create an array of sorted tables, can be used with binary search when read:
auto vecoftables = builder.CreateVectorOfSortedTables(mlocs, 3);
@@ -188,9 +190,12 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length) {
// Example of accessing a vector of strings:
auto vecofstrings = monster->testarrayofstring();
- TEST_EQ(vecofstrings->Length(), 2U);
+ TEST_EQ(vecofstrings->Length(), 4U);
TEST_EQ_STR(vecofstrings->Get(0)->c_str(), "bob");
TEST_EQ_STR(vecofstrings->Get(1)->c_str(), "fred");
+ // These should have pointer equality because of string pooling.
+ TEST_EQ(vecofstrings->Get(0)->c_str(), vecofstrings->Get(2)->c_str());
+ TEST_EQ(vecofstrings->Get(1)->c_str(), vecofstrings->Get(3)->c_str());
// Example of accessing a vector of tables:
auto vecoftables = monster->testarrayoftables();
@@ -420,7 +425,8 @@ void ReflectionTest(uint8_t *flatbuf, size_t length) {
// either part or whole.
flatbuffers::FlatBufferBuilder fbb;
auto root_offset = flatbuffers::CopyTable(fbb, schema, *root_table,
- *flatbuffers::GetAnyRoot(flatbuf));
+ *flatbuffers::GetAnyRoot(flatbuf),
+ true);
fbb.Finish(root_offset, MonsterIdentifier());
// Test that it was copied correctly:
AccessFlatBufferTest(fbb.GetBufferPointer(), fbb.GetSize());