diff options
author | Max Kellermann <max@duempel.org> | 2014-01-27 10:33:42 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-01-27 10:33:42 +0100 |
commit | 30fadaed7fceb242f97776f189fcce1a2214604c (patch) | |
tree | fe055d1d1c959489f0dbb484e4f45e3994c8f89c /test/test_icy_parser.cxx | |
parent | c01282a322f13055cff9f68464b3b1750e59ee4f (diff) | |
parent | 2b10ecfa37e273c752c3f87e2491e2a1a5f0ae58 (diff) | |
download | mpd-30fadaed7fceb242f97776f189fcce1a2214604c.tar.gz mpd-30fadaed7fceb242f97776f189fcce1a2214604c.tar.xz mpd-30fadaed7fceb242f97776f189fcce1a2214604c.zip |
Merge branch 'v0.18.x'
Diffstat (limited to 'test/test_icy_parser.cxx')
-rw-r--r-- | test/test_icy_parser.cxx | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/test/test_icy_parser.cxx b/test/test_icy_parser.cxx new file mode 100644 index 000000000..a996df134 --- /dev/null +++ b/test/test_icy_parser.cxx @@ -0,0 +1,85 @@ +/* + * 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> + +#include <string.h> + +static Tag * +icy_parse_tag(const char *p) +{ + char *q = strdup(p); + Tag *tag = icy_parse_tag(q, q + strlen(q)); + free(q); + return tag; +} + +static void +CompareTagTitle(const Tag &tag, const std::string &title) +{ + CPPUNIT_ASSERT_EQUAL(uint16_t(1), 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(uint16_t(0), 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("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"); + TestIcyParserTitle("a='b;c';StreamTitle='foo;bar'", "foo;bar"); + TestIcyParserTitle("a='b'c';StreamTitle='foo'bar'", "foo'bar"); + TestIcyParserTitle("StreamTitle='fo'o'b'ar';a='b'c'd'", "fo'o'b'ar"); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(IcyTest); + +int +main(gcc_unused int argc, gcc_unused char **argv) +{ + CppUnit::TextUi::TestRunner runner; + auto ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; +} |