From f7eb2b697ef6ac523632ad27b43b185f5901438c Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 27 Jan 2014 09:51:31 +0100 Subject: test/test_icy_parser: unit test for IcyMetaDataParser.cxx --- test/test_icy_parser.cxx | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 test/test_icy_parser.cxx (limited to 'test') 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 +#include +#include +#include + +#include + +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 ®istry = CppUnit::TestFactoryRegistry::getRegistry(); + runner.addTest(registry.makeTest()); + return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE; +} -- cgit v1.2.3 From 2b10ecfa37e273c752c3f87e2491e2a1a5f0ae58 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 21 Jan 2014 14:51:35 +0100 Subject: IcyMetadataParser: more robust tag parser Allow semicolons and single quotes in the stream title. This is not part of any specification, but found in real life. --- test/test_icy_parser.cxx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'test') diff --git a/test/test_icy_parser.cxx b/test/test_icy_parser.cxx index 83925cc99..2abf60f9e 100644 --- a/test/test_icy_parser.cxx +++ b/test/test_icy_parser.cxx @@ -14,6 +14,17 @@ #include +#include + +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) { @@ -51,10 +62,14 @@ public: 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"); } }; -- cgit v1.2.3