2014-01-27 09:51:31 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for class IcyMetaDataParser.
|
|
|
|
*/
|
|
|
|
|
2017-12-20 14:54:56 +01:00
|
|
|
#include "util/ScopeExit.hxx"
|
2014-01-27 09:51:31 +01:00
|
|
|
|
|
|
|
/* include the .cxx file to get access to internal functions */
|
|
|
|
#include "IcyMetaDataParser.cxx"
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
#include <gtest/gtest.h>
|
2014-01-27 09:51:31 +01:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
2014-01-21 14:51:35 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2017-12-20 14:49:48 +01:00
|
|
|
static std::unique_ptr<Tag>
|
2014-01-21 14:51:35 +01:00
|
|
|
icy_parse_tag(const char *p)
|
|
|
|
{
|
|
|
|
char *q = strdup(p);
|
2017-12-20 14:54:56 +01:00
|
|
|
AtScopeExit(q) { free(q); };
|
|
|
|
return icy_parse_tag(q, q + strlen(q));
|
2014-01-21 14:51:35 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 09:51:31 +01:00
|
|
|
static void
|
|
|
|
CompareTagTitle(const Tag &tag, const std::string &title)
|
|
|
|
{
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(uint16_t(1), tag.num_items);
|
2014-01-27 09:51:31 +01:00
|
|
|
|
|
|
|
const TagItem &item = *tag.items[0];
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(TAG_TITLE, item.type);
|
|
|
|
EXPECT_EQ(title, std::string(item.value));
|
2014-01-27 09:51:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TestIcyParserTitle(const char *input, const char *title)
|
|
|
|
{
|
2017-12-20 14:49:48 +01:00
|
|
|
const auto tag = icy_parse_tag(input);
|
2014-01-27 09:51:31 +01:00
|
|
|
CompareTagTitle(*tag, title);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
TestIcyParserEmpty(const char *input)
|
|
|
|
{
|
2017-12-20 14:49:48 +01:00
|
|
|
const auto tag = icy_parse_tag(input);
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_EQ(uint16_t(0), tag->num_items);
|
2014-01-27 09:51:31 +01:00
|
|
|
}
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(IcyMetadataParserTest, Basic)
|
2014-01-27 09:51:31 +01:00
|
|
|
{
|
2018-10-16 19:01:13 +02:00
|
|
|
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");
|
2014-01-27 09:51:31 +01:00
|
|
|
}
|