summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/StringUtilTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/UnitTests/Common/StringUtilTest.cpp')
-rw-r--r--Source/UnitTests/Common/StringUtilTest.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/StringUtilTest.cpp b/Source/UnitTests/Common/StringUtilTest.cpp
index 28bd150c06..59ba99a436 100644
--- a/Source/UnitTests/Common/StringUtilTest.cpp
+++ b/Source/UnitTests/Common/StringUtilTest.cpp
@@ -2,10 +2,12 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <gtest/gtest.h>
+
#include <string>
#include <vector>
#include "Common/StringUtil.h"
+#include "Common/Swap.h"
TEST(StringUtil, StringPopBackIf)
{
@@ -256,3 +258,26 @@ TEST(StringUtil, CaseInsensitiveContains_OverlappingMatches)
EXPECT_TRUE(Common::CaseInsensitiveContains("aaaaaa", "aa"));
EXPECT_TRUE(Common::CaseInsensitiveContains("ababababa", "bABa"));
}
+
+TEST(StringUtil, CharacterEncodingConversion)
+{
+ // wstring
+ EXPECT_EQ(WStringToUTF8(L"hello 🐬"), "hello 🐬");
+
+ // UTF-16
+ EXPECT_EQ(UTF16ToUTF8(u"hello 🐬"), "hello 🐬");
+ EXPECT_EQ(UTF8ToUTF16("hello 🐬"), u"hello 🐬");
+
+ // UTF-16BE
+ char16_t utf16be_str[] = u"hello 🐬";
+ for (auto& c : utf16be_str)
+ c = Common::swap16(c);
+ EXPECT_EQ(UTF16BEToUTF8(utf16be_str, 99), "hello 🐬");
+
+ // Shift JIS
+ EXPECT_EQ(SHIFTJISToUTF8("\x83\x43\x83\x8b\x83\x4a"), "イルカ");
+ EXPECT_EQ(UTF8ToSHIFTJIS("イルカ"), "\x83\x43\x83\x8b\x83\x4a");
+
+ // CP1252
+ EXPECT_EQ(CP1252ToUTF8("hello \xa5"), "hello ¥");
+}