aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_protocol.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-09-04 15:15:58 +0200
committerMax Kellermann <max@duempel.org>2014-09-04 17:10:30 +0200
commit4907f610d6116949111fb6ff81c1489ec68b9d43 (patch)
tree330a1a6fa0ccf0f0440b489db88caea90ff39734 /test/test_protocol.cxx
parentf9d1bbbffb7bc068aa00d4040d8beefc1a66bad8 (diff)
downloadmpd-4907f610d6116949111fb6ff81c1489ec68b9d43.tar.gz
mpd-4907f610d6116949111fb6ff81c1489ec68b9d43.tar.xz
mpd-4907f610d6116949111fb6ff81c1489ec68b9d43.zip
test/test_protocol: unit test for protocol/ArgParser.cxx
Diffstat (limited to 'test/test_protocol.cxx')
-rw-r--r--test/test_protocol.cxx60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test_protocol.cxx b/test/test_protocol.cxx
new file mode 100644
index 000000000..d7ea7cd87
--- /dev/null
+++ b/test/test_protocol.cxx
@@ -0,0 +1,60 @@
+#include "config.h"
+#include "protocol/ArgParser.hxx"
+#include "protocol/Result.hxx"
+#include "Compiler.h"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+static enum ack last_error = ack(-1);
+
+void
+command_error(gcc_unused Client &client, enum ack error,
+ gcc_unused const char *fmt, ...)
+{
+ last_error = error;
+}
+
+class ArgParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(ArgParserTest);
+ CPPUNIT_TEST(TestRange);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestRange();
+};
+
+void
+ArgParserTest::TestRange()
+{
+ Client &client = *(Client *)nullptr;
+ unsigned a, b;
+
+ CPPUNIT_ASSERT(check_range(client, &a, &b, "1"));
+ CPPUNIT_ASSERT_EQUAL(1u, a);
+ CPPUNIT_ASSERT_EQUAL(2u, b);
+
+ CPPUNIT_ASSERT(check_range(client, &a, &b, "1:5"));
+ CPPUNIT_ASSERT_EQUAL(1u, a);
+ CPPUNIT_ASSERT_EQUAL(5u, b);
+
+ CPPUNIT_ASSERT(check_range(client, &a, &b, "1:"));
+ CPPUNIT_ASSERT_EQUAL(1u, a);
+ CPPUNIT_ASSERT(b >= 999999u);
+
+ CPPUNIT_ASSERT(!check_range(client, &a, &b, "-2"));
+ CPPUNIT_ASSERT_EQUAL(ACK_ERROR_ARG, last_error);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ArgParserTest);
+
+int
+main(gcc_unused int argc, gcc_unused char **argv)
+{
+ CppUnit::TextUi::TestRunner runner;
+ auto &registry = CppUnit::TestFactoryRegistry::getRegistry();
+ runner.addTest(registry.makeTest());
+ return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
+}