| 20 | namespace butil { |
| 21 | |
| 22 | TEST(SysStrings, SysWideToUTF8) { |
| 23 | EXPECT_EQ("Hello, world", SysWideToUTF8(L"Hello, world")); |
| 24 | EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToUTF8(L"\x4f60\x597d")); |
| 25 | |
| 26 | // >16 bits |
| 27 | EXPECT_EQ("\xF0\x90\x8C\x80", SysWideToUTF8(kSysWideOldItalicLetterA)); |
| 28 | |
| 29 | // Error case. When Windows finds a UTF-16 character going off the end of |
| 30 | // a string, it just converts that literal value to UTF-8, even though this |
| 31 | // is invalid. |
| 32 | // |
| 33 | // This is what XP does, but Vista has different behavior, so we don't bother |
| 34 | // verifying it: |
| 35 | // EXPECT_EQ("\xE4\xBD\xA0\xED\xA0\x80zyxw", |
| 36 | // SysWideToUTF8(L"\x4f60\xd800zyxw")); |
| 37 | |
| 38 | // Test embedded NULLs. |
| 39 | std::wstring wide_null(L"a"); |
| 40 | wide_null.push_back(0); |
| 41 | wide_null.push_back('b'); |
| 42 | |
| 43 | std::string expected_null("a"); |
| 44 | expected_null.push_back(0); |
| 45 | expected_null.push_back('b'); |
| 46 | |
| 47 | EXPECT_EQ(expected_null, SysWideToUTF8(wide_null)); |
| 48 | } |
| 49 | |
| 50 | TEST(SysStrings, SysUTF8ToWide) { |
| 51 | EXPECT_EQ(L"Hello, world", SysUTF8ToWide("Hello, world")); |
nothing calls this directly
no test coverage detected