#include "base/strings/utf_string_conversions.h"
#include <stddef.h>
#include "base/strings/string_util.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace {
const wchar_t* const kConvertRoundtripCases[] = …;
}
TEST(UTFStringConversionsTest, ConvertUTF8AndWide) { … }
TEST(UTFStringConversionsTest, ConvertUTF8AndWideEmptyString) { … }
TEST(UTFStringConversionsTest, ConvertUTF8ToWide) { … }
#if defined(WCHAR_T_IS_16_BIT)
TEST(UTFStringConversionsTest, ConvertUTF16ToUTF8) {
struct WideToUTF8Case {
const wchar_t* utf16;
const char* utf8;
bool success;
} convert_cases[] = {
{L"\x4f60\x597d", "\xe4\xbd\xa0\xe5\xa5\xbd", true},
{L"\xd800\xdf00", "\xF0\x90\x8C\x80", true},
{L"\xffffHello", "\xEF\xBF\xBFHello", true},
{L"\xdbff\xdffeHello", "\xF4\x8F\xBF\xBEHello", true},
{L"\xd800\x597d", "\xef\xbf\xbd\xe5\xa5\xbd", false},
{L"\x597d\xd800", "\xe5\xa5\xbd\xef\xbf\xbd", false},
};
for (const auto& test : convert_cases) {
std::string converted;
EXPECT_EQ(test.success,
WideToUTF8(test.utf16, wcslen(test.utf16), &converted));
std::string expected(test.utf8);
EXPECT_EQ(expected, converted);
}
}
#elif defined(WCHAR_T_IS_32_BIT)
TEST(UTFStringConversionsTest, ConvertUTF32ToUTF8) { … }
#endif
TEST(UTFStringConversionsTest, ConvertMultiString) { … }
}