File: test_icy_parser.cxx

package info (click to toggle)
mpd 0.24.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 10,760 kB
  • sloc: cpp: 75,041; python: 1,408; xml: 628; perl: 469; java: 289; sh: 286; ansic: 235; makefile: 105
file content (62 lines) | stat: -rw-r--r-- 1,601 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * Unit tests for class IcyMetaDataParser.
 */

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

#include <gtest/gtest.h>

#include <string>

#include <string.h>

#ifdef HAVE_ICU_CONVERTER

static std::unique_ptr<Tag>
icy_parse_tag(std::string_view p) noexcept
{
	return icy_parse_tag(nullptr, p);
}

#endif

static void
CompareTagTitle(const Tag &tag, const std::string &title)
{
	EXPECT_EQ(uint16_t(1), tag.num_items);

	const TagItem &item = *tag.items[0];
	EXPECT_EQ(TAG_TITLE, item.type);
	EXPECT_EQ(title, std::string(item.value));
}

static void
TestIcyParserTitle(const char *input, const char *title)
{
	const auto tag = icy_parse_tag(input);
	CompareTagTitle(*tag, title);
}

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

TEST(IcyMetadataParserTest, Basic)
{
	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");
}