test/test_icy_parser: unit test for IcyMetaDataParser.cxx
This commit is contained in:
parent
da67260c95
commit
f7eb2b697e
11
Makefile.am
11
Makefile.am
@ -1061,6 +1061,7 @@ C_TESTS = \
|
||||
test/test_util \
|
||||
test/test_byte_reverse \
|
||||
test/test_mixramp \
|
||||
test/test_icy_parser \
|
||||
test/test_pcm \
|
||||
test/test_queue_priority
|
||||
|
||||
@ -1496,6 +1497,16 @@ test_test_mixramp_LDADD = \
|
||||
$(GLIB_LIBS) \
|
||||
$(CPPUNIT_LIBS)
|
||||
|
||||
test_test_icy_parser_SOURCES = \
|
||||
src/Log.cxx \
|
||||
test/test_icy_parser.cxx
|
||||
test_test_icy_parser_CPPFLAGS = $(AM_CPPFLAGS) $(CPPUNIT_CFLAGS) -DCPPUNIT_HAVE_RTTI=0
|
||||
test_test_icy_parser_CXXFLAGS = $(AM_CXXFLAGS) -Wno-error=deprecated-declarations
|
||||
test_test_icy_parser_LDADD = \
|
||||
libtag.a \
|
||||
$(GLIB_LIBS) \
|
||||
$(CPPUNIT_LIBS)
|
||||
|
||||
test_test_pcm_SOURCES = \
|
||||
test/test_pcm_util.hxx \
|
||||
test/test_pcm_dither.cxx \
|
||||
|
70
test/test_icy_parser.cxx
Normal file
70
test/test_icy_parser.cxx
Normal file
@ -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 ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest(registry.makeTest());
|
||||
return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
Loading…
Reference in New Issue
Block a user