2014-12-01 20:55:05 +01:00
|
|
|
/*
|
|
|
|
* Unit tests for src/util/
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "lib/icu/Converter.hxx"
|
2015-06-25 22:43:55 +02:00
|
|
|
#include "util/AllocatedString.hxx"
|
2014-12-01 20:55:05 +01:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
#include <gtest/gtest.h>
|
2014-12-01 20:55:05 +01:00
|
|
|
|
|
|
|
#ifdef HAVE_ICU_CONVERTER
|
|
|
|
|
|
|
|
static const char *const invalid_utf8[] = {
|
|
|
|
"\xfc",
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StringPair {
|
|
|
|
const char *utf8, *other;
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr StringPair latin1_tests[] = {
|
|
|
|
{ "foo", "foo" },
|
|
|
|
{ "\xc3\xbc", "\xfc" },
|
|
|
|
};
|
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(IcuConverter, InvalidCharset)
|
|
|
|
{
|
|
|
|
EXPECT_ANY_THROW(IcuConverter::Create("doesntexist"));
|
|
|
|
}
|
2014-12-01 20:55:05 +01:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(IcuConverter, Latin1)
|
|
|
|
{
|
2019-11-04 15:44:06 +01:00
|
|
|
const auto converter = IcuConverter::Create("iso-8859-1");
|
2018-10-16 19:01:13 +02:00
|
|
|
ASSERT_NE(converter, nullptr);
|
2014-12-01 20:55:05 +01:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
for (const auto i : invalid_utf8) {
|
|
|
|
EXPECT_ANY_THROW(converter->FromUTF8(i));
|
|
|
|
}
|
2014-12-01 20:55:05 +01:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
for (const auto i : latin1_tests) {
|
|
|
|
auto f = converter->FromUTF8(i.utf8);
|
|
|
|
EXPECT_STREQ(f.c_str(), i.other);
|
2014-12-01 20:55:05 +01:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
auto t = converter->ToUTF8(i.other);
|
|
|
|
EXPECT_STREQ(t.c_str(), i.utf8);
|
2014-12-01 20:55:05 +01:00
|
|
|
}
|
2018-10-16 19:01:13 +02:00
|
|
|
}
|
2014-12-01 20:55:05 +01:00
|
|
|
|
|
|
|
#endif
|