test_icy_parser.cxx 1.66 KB
Newer Older
1 2 3 4
/*
 * Unit tests for class IcyMetaDataParser.
 */

5
#include "util/ScopeExit.hxx"
6 7 8 9

/* include the .cxx file to get access to internal functions */
#include "IcyMetaDataParser.cxx"

10
#include <gtest/gtest.h>
11 12 13

#include <string>

14 15
#include <string.h>

16
static std::unique_ptr<Tag>
17 18 19
icy_parse_tag(const char *p)
{
	char *q = strdup(p);
20
	AtScopeExit(q) { free(q); };
21 22 23 24 25
	return icy_parse_tag(
#ifdef HAVE_ICU_CONVERTER
			     nullptr,
#endif
			     q, q + strlen(q));
26 27
}

28 29 30
static void
CompareTagTitle(const Tag &tag, const std::string &title)
{
31
	EXPECT_EQ(uint16_t(1), tag.num_items);
32 33

	const TagItem &item = *tag.items[0];
34 35
	EXPECT_EQ(TAG_TITLE, item.type);
	EXPECT_EQ(title, std::string(item.value));
36 37 38 39 40
}

static void
TestIcyParserTitle(const char *input, const char *title)
{
41
	const auto tag = icy_parse_tag(input);
42 43 44 45 46 47
	CompareTagTitle(*tag, title);
}

static void
TestIcyParserEmpty(const char *input)
{
48
	const auto tag = icy_parse_tag(input);
49
	EXPECT_EQ(uint16_t(0), tag->num_items);
50 51
}

52
TEST(IcyMetadataParserTest, Basic)
53
{
54 55 56 57 58 59 60 61 62 63 64 65
	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");
66
}