summaryrefslogtreecommitdiff
path: root/test/WhiteBoxTests.cpp
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2020-02-28 14:51:22 +0100
committerMiklos Vajna <vmiklos@collabora.com>2020-02-28 18:31:37 +0100
commit547f9ea73186d274d512a9fa1f01e6edcad66bab (patch)
tree50ccbbcd9c7ae0e0d4fc6da93a667aa05c5cfbdc /test/WhiteBoxTests.cpp
parentb8bd1990aaa1b063ca21b78ffec629b5d5ae7697 (diff)
Rework StringVector to have a single underlying string
This is meant to reduce lots of small allocations and instead have pointers into the single string for the various tokens instead. This has a few requirements, though: 1) It's no longer OK to modify the tokens, changing their length would invalidate the start/length of other tokens. Rework DocumentBroker::load() to avoid such mutation. 2) The iterators no longer expose zero-terminated strings, so Poco::cat() doesn't work anymore: add an own cat() instead and use that in e.g. ChildSession. The own cat() has the benefit that it won't read past the end of the array if the begin index is out of bounds to add more safety. (This nicely works towards killing Poco usage in general.) 3) If zero-terminated strings for all individual tokens is needed, a copy has to be made, as done in spawnProcess(). (For all of these requirements, the build fails if there are problems.) Change-Id: Iea40e4400e630b2d669f5c72aea85cb40edf9a2c Reviewed-on: https://gerrit.libreoffice.org/c/online/+/89711 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'test/WhiteBoxTests.cpp')
-rw-r--r--test/WhiteBoxTests.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index 67dd8644a..5c843adea 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -41,6 +41,7 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testJson);
CPPUNIT_TEST(testAnonymization);
CPPUNIT_TEST(testTime);
+ CPPUNIT_TEST(testStringVector);
CPPUNIT_TEST_SUITE_END();
@@ -57,6 +58,7 @@ class WhiteBoxTests : public CPPUNIT_NS::TestFixture
void testJson();
void testAnonymization();
void testTime();
+ void testStringVector();
};
void WhiteBoxTests::testLOOLProtocolFunctions()
@@ -795,6 +797,28 @@ void WhiteBoxTests::testTime()
}
}
+void WhiteBoxTests::testStringVector()
+{
+ // Test push_back() and getParam().
+ StringVector vector;
+ vector.push_back("a");
+ vector.push_back("b");
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), vector.size());
+ auto it = vector.begin();
+ CPPUNIT_ASSERT_EQUAL(std::string("a"), vector.getParam(*it));
+ ++it;
+ CPPUNIT_ASSERT_EQUAL(std::string("b"), vector.getParam(*it));
+
+ // Test cat().
+ CPPUNIT_ASSERT_EQUAL(std::string("a b"), vector.cat(" ", 0));
+ CPPUNIT_ASSERT_EQUAL(std::string(), vector.cat(" ", 3));
+ CPPUNIT_ASSERT_EQUAL(std::string(), vector.cat(" ", 42));
+
+ // Test operator []().
+ CPPUNIT_ASSERT_EQUAL(std::string("a"), vector[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string(""), vector[2]);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(WhiteBoxTests);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */