aboutsummaryrefslogtreecommitdiffstats
path: root/test/SplitStringTest.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-03 21:39:45 +0100
committerMax Kellermann <max@duempel.org>2014-12-04 09:14:28 +0100
commite69bef3ce389967b8239648e4b9eaec42217bc95 (patch)
tree603870b6d042017c7a93f1909afc91395cf1415b /test/SplitStringTest.hxx
parentc1c0fc79bcdc9caabe42fc3716ea2e2ea7b3eb3d (diff)
downloadmpd-e69bef3ce389967b8239648e4b9eaec42217bc95.tar.gz
mpd-e69bef3ce389967b8239648e4b9eaec42217bc95.tar.xz
mpd-e69bef3ce389967b8239648e4b9eaec42217bc95.zip
util/SplitString: new utility class
Replaces GLib's g_strsplit().
Diffstat (limited to 'test/SplitStringTest.hxx')
-rw-r--r--test/SplitStringTest.hxx65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/SplitStringTest.hxx b/test/SplitStringTest.hxx
new file mode 100644
index 000000000..87ed385ea
--- /dev/null
+++ b/test/SplitStringTest.hxx
@@ -0,0 +1,65 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "check.h"
+#include "util/SplitString.hxx"
+#include "util/Macros.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+
+class SplitStringTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(SplitStringTest);
+ CPPUNIT_TEST(TestBasic);
+ CPPUNIT_TEST(TestStrip);
+ CPPUNIT_TEST(TestNoStrip);
+ CPPUNIT_TEST(TestEmpty);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestBasic() {
+ constexpr char input[] = "foo.bar";
+ const char *const output[] = { "foo", "bar" };
+ size_t i = 0;
+ for (auto p : SplitString(input, '.')) {
+ CPPUNIT_ASSERT(i < ARRAY_SIZE(output));
+ CPPUNIT_ASSERT(p == output[i]);
+ ++i;
+ }
+
+ CPPUNIT_ASSERT_EQUAL(ARRAY_SIZE(output), i);
+ }
+
+ void TestStrip() {
+ constexpr char input[] = " foo\t.\r\nbar\r\n2";
+ const char *const output[] = { "foo", "bar\r\n2" };
+ size_t i = 0;
+ for (auto p : SplitString(input, '.')) {
+ CPPUNIT_ASSERT(i < ARRAY_SIZE(output));
+ CPPUNIT_ASSERT(p == output[i]);
+ ++i;
+ }
+
+ CPPUNIT_ASSERT_EQUAL(ARRAY_SIZE(output), i);
+ }
+
+ void TestNoStrip() {
+ constexpr char input[] = " foo\t.\r\nbar\r\n2";
+ const char *const output[] = { " foo\t", "\r\nbar\r\n2" };
+ size_t i = 0;
+ for (auto p : SplitString(input, '.', false)) {
+ CPPUNIT_ASSERT(i < ARRAY_SIZE(output));
+ CPPUNIT_ASSERT(p == output[i]);
+ ++i;
+ }
+
+ CPPUNIT_ASSERT_EQUAL(ARRAY_SIZE(output), i);
+ }
+
+ void TestEmpty() {
+ CPPUNIT_ASSERT(SplitString("", '.').empty());
+ }
+};