diff --git a/tests/tests/line_iterator.cpp b/tests/tests/line_iterator.cpp index d8dd9dec1..e3901be29 100644 --- a/tests/tests/line_iterator.cpp +++ b/tests/tests/line_iterator.cpp @@ -14,68 +14,58 @@ #include +#include + #include #include #include #include #include -#include -#include - -using agi::line_iterator; - -using namespace util; - template -struct varg_type { - typedef T type; -}; -template<> struct varg_type { - typedef const char * type; -}; +void test_values(agi::line_iterator& iter) { + EXPECT_EQ(iter, end(iter)); +} -template -void expect_eq(const char (&str)[N], const char *charset, int num, ...) { - std::string string(str, N - 1); - agi::charset::IconvWrapper conv("utf-8", charset); - string = conv.Convert(string); - std::stringstream ss(string); - line_iterator iter; - EXPECT_NO_THROW(iter = line_iterator(ss, charset)); - va_list argp; - va_start(argp, num); - for (; num > 0; --num) { - EXPECT_FALSE(iter == line_iterator()); - EXPECT_EQ(*iter, va_arg(argp, typename varg_type::type)); - EXPECT_NO_THROW(++iter); - } - va_end(argp); - EXPECT_TRUE(iter == line_iterator()); +template +void test_values(agi::line_iterator& iter, First first, Values... values) { + EXPECT_FALSE(iter == end(iter)); + EXPECT_EQ(*iter, first); + EXPECT_NO_THROW(++iter); + test_values(iter, values...); +} + +template +void test(std::string const& str, const char *encoding, Values... values) { + std::stringstream ss(str); + agi::line_iterator iter; + EXPECT_NO_THROW(iter = agi::line_iterator(ss, encoding)); + test_values(iter, values...); +} + +template +void expect_eq(const char *str, Values... values) { + std::string utf8(str); + test(utf8, "utf-8", values...); + + agi::charset::IconvWrapper conv("utf-8", "utf-16"); + auto utf16 = conv.Convert(utf8); + test(utf16, "utf-16", values...); } TEST(lagi_line, int) { - std::vector charsets = agi::charset::GetEncodingsList >(); - for (auto const& charset : charsets) { - expect_eq("1\n2\n3\n4", charset.c_str(), 4, 1, 2, 3, 4); - expect_eq("1\n2\n3\n4\n", charset.c_str(), 4, 1, 2, 3, 4); - expect_eq("1\n2\nb\n3\n4", charset.c_str(), 4, 1, 2, 3, 4); - expect_eq("1.0\n2.0\n3.0\n4.0", charset.c_str(), 4, 1, 2, 3, 4); - expect_eq(" 0x16 \n 09 \n -2", charset.c_str(), 3, 0, 9, -2); - } + expect_eq("1\n2\n3\n4", 1, 2, 3, 4); + expect_eq("1\n2\n3\n4\n", 1, 2, 3, 4); + expect_eq("1\n2\nb\n3\n4", 1, 2, 3, 4); + expect_eq("1.0\n2.0\n3.0\n4.0", 1, 2, 3, 4); + expect_eq(" 0x16 \n 09 \n -2", 0, 9, -2); } TEST(lagi_line, double) { - std::vector charsets = agi::charset::GetEncodingsList >(); - for (auto const& charset : charsets) { - expect_eq("1.0\n2.0", charset.c_str(), 2, 1.0, 2.0); - expect_eq("#1.0\n\t2.5", charset.c_str(), 1, 2.5); - } + expect_eq("1.0\n2.0", 1.0, 2.0); + expect_eq("#1.0\n\t2.5", 2.5); } TEST(lagi_line, string) { - std::vector charsets = agi::charset::GetEncodingsList >(); - for (auto const& charset : charsets) { - expect_eq("line 1\nline 2\nline 3", charset.c_str(), 3, "line 1", "line 2", "line 3"); - expect_eq(" white space ", charset.c_str(), 1, " white space "); - expect_eq("blank\n\nlines\n", charset.c_str(), 4, "blank", "", "lines", ""); - } + expect_eq("line 1\nline 2\nline 3", "line 1", "line 2", "line 3"); + expect_eq(" white space ", " white space "); + expect_eq("blank\n\nlines\n", "blank", "", "lines", ""); } diff --git a/tests/tests/path.cpp b/tests/tests/path.cpp index 4955dfc09..1f942bebb 100644 --- a/tests/tests/path.cpp +++ b/tests/tests/path.cpp @@ -171,3 +171,10 @@ TEST(lagi_path, make_relative_on_dummy_url) { EXPECT_UNCHANGED("dummy-audio:silence?sr=44100&bd=16&ch=1&ln=396900000", MakeRelative); EXPECT_UNCHANGED("?dummy:23.976000:40000:1280:720:47:163:254:", MakeRelative); } + +TEST(lagi_path, encode) { + Path p; + p.SetToken("?user", "/a/b/c"); + p.SetToken("?local", "/a/b/c/d"); + EXPECT_EQ("?local/e", p.Encode("/a/b/c/d/e")); +}