aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-04 07:23:06 +0100
committerMax Kellermann <max@duempel.org>2014-12-04 07:23:06 +0100
commit02a77f67971b1f0304be773bd69bb3fc1a12fa90 (patch)
treebd40a9a2ed1801d2657bbceada14320670318dd7
parent77b316cdfb0c437d3910778e7b5832e89be4b1db (diff)
downloadmpd-02a77f67971b1f0304be773bd69bb3fc1a12fa90.tar.gz
mpd-02a77f67971b1f0304be773bd69bb3fc1a12fa90.tar.xz
mpd-02a77f67971b1f0304be773bd69bb3fc1a12fa90.zip
test/test_util: add unit test for DivideString
Diffstat (limited to '')
-rw-r--r--Makefile.am1
-rw-r--r--test/DivideStringTest.hxx44
-rw-r--r--test/test_util.cxx2
3 files changed, 47 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index e23e15edd..a79c18172 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2001,6 +2001,7 @@ test_run_inotify_LDADD = \
endif
test_test_util_SOURCES = \
+ test/DivideStringTest.hxx \
test/UriUtilTest.hxx \
test/TestCircularBuffer.hxx \
test/test_util.cxx
diff --git a/test/DivideStringTest.hxx b/test/DivideStringTest.hxx
new file mode 100644
index 000000000..83c54dc56
--- /dev/null
+++ b/test/DivideStringTest.hxx
@@ -0,0 +1,44 @@
+/*
+ * Unit tests for src/util/
+ */
+
+#include "check.h"
+#include "util/DivideString.hxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string.h>
+
+class DivideStringTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(DivideStringTest);
+ CPPUNIT_TEST(TestBasic);
+ CPPUNIT_TEST(TestEmpty);
+ CPPUNIT_TEST(TestFail);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestBasic() {
+ constexpr char input[] = "foo.bar";
+ const DivideString ds(input, '.');
+ CPPUNIT_ASSERT(ds.IsDefined());
+ CPPUNIT_ASSERT(!ds.IsEmpty());
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), "foo"));
+ CPPUNIT_ASSERT_EQUAL(input + 4, ds.GetSecond());
+ }
+
+ void TestEmpty() {
+ constexpr char input[] = ".bar";
+ const DivideString ds(input, '.');
+ CPPUNIT_ASSERT(ds.IsDefined());
+ CPPUNIT_ASSERT(ds.IsEmpty());
+ CPPUNIT_ASSERT_EQUAL(0, strcmp(ds.GetFirst(), ""));
+ CPPUNIT_ASSERT_EQUAL(input + 1, ds.GetSecond());
+ }
+
+ void TestFail() {
+ constexpr char input[] = "foo!bar";
+ const DivideString ds(input, '.');
+ CPPUNIT_ASSERT(!ds.IsDefined());
+ }
+};
diff --git a/test/test_util.cxx b/test/test_util.cxx
index a40963918..e9b49c4da 100644
--- a/test/test_util.cxx
+++ b/test/test_util.cxx
@@ -3,6 +3,7 @@
*/
#include "config.h"
+#include "DivideStringTest.hxx"
#include "UriUtilTest.hxx"
#include "TestCircularBuffer.hxx"
@@ -13,6 +14,7 @@
#include <stdlib.h>
+CPPUNIT_TEST_SUITE_REGISTRATION(DivideStringTest);
CPPUNIT_TEST_SUITE_REGISTRATION(UriUtilTest);
CPPUNIT_TEST_SUITE_REGISTRATION(TestCircularBuffer);