aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_icy_parser.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-27 09:51:31 +0100
committerMax Kellermann <max@duempel.org>2014-01-27 09:51:31 +0100
commitf7eb2b697ef6ac523632ad27b43b185f5901438c (patch)
treea1bccc129ad823994e5e8d2e015b57ce1c1fc907 /test/test_icy_parser.cxx
parentda67260c955ebe1bc590b461e5ee8c9665f26f5b (diff)
downloadmpd-f7eb2b697ef6ac523632ad27b43b185f5901438c.tar.gz
mpd-f7eb2b697ef6ac523632ad27b43b185f5901438c.tar.xz
mpd-f7eb2b697ef6ac523632ad27b43b185f5901438c.zip
test/test_icy_parser: unit test for IcyMetaDataParser.cxx
Diffstat (limited to '')
-rw-r--r--test/test_icy_parser.cxx70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/test_icy_parser.cxx b/test/test_icy_parser.cxx
new file mode 100644
index 000000000..83925cc99
--- /dev/null
+++ b/test/test_icy_parser.cxx
@@ -0,0 +1,70 @@
+/*
+ * Unit tests for class IcyMetaDataParser.
+ */
+
+#include "config.h"
+
+/* include the .cxx file to get access to internal functions */
+#include "IcyMetaDataParser.cxx"
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <cppunit/ui/text/TestRunner.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+#include <string>
+
+static void
+CompareTagTitle(const Tag &tag, const std::string &title)
+{
+ CPPUNIT_ASSERT_EQUAL(1u, tag.num_items);
+
+ const TagItem &item = *tag.items[0];
+ CPPUNIT_ASSERT_EQUAL(TAG_TITLE, item.type);
+ CPPUNIT_ASSERT_EQUAL(title, std::string(item.value));
+}
+
+static void
+TestIcyParserTitle(const char *input, const char *title)
+{
+ Tag *tag = icy_parse_tag(input);
+ CompareTagTitle(*tag, title);
+ delete tag;
+}
+
+static void
+TestIcyParserEmpty(const char *input)
+{
+ Tag *tag = icy_parse_tag(input);
+ CPPUNIT_ASSERT_EQUAL(0u, tag->num_items);
+ delete tag;
+}
+
+class IcyTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(IcyTest);
+ CPPUNIT_TEST(TestIcyMetadataParser);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ void TestIcyMetadataParser() {
+ TestIcyParserEmpty("foo=bar;");
+ TestIcyParserTitle("StreamTitle='foo bar'", "foo bar");
+ TestIcyParserTitle("StreamTitle='foo bar';", "foo bar");
+ TestIcyParserTitle("StreamTitle='foo\"bar';", "foo\"bar");
+ TestIcyParserTitle("a=b;StreamTitle='foo';", "foo");
+ TestIcyParserTitle("a=;StreamTitle='foo';", "foo");
+ TestIcyParserTitle("a=b;StreamTitle='foo';c=d", "foo");
+ TestIcyParserTitle("a=b;StreamTitle='foo'", "foo");
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IcyTest);
+
+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;
+}