summaryrefslogtreecommitdiff
path: root/Source/UnitTests/Common/StringUtilTest.cpp
diff options
context:
space:
mode:
authorJordan Woyak <jordan.woyak@gmail.com>2025-10-15 18:44:51 -0500
committerJordan Woyak <jordan.woyak@gmail.com>2025-11-02 00:36:04 -0500
commit0ebc54a0fa37bb9c9ff3969a6a025dc04f32c0b1 (patch)
treed30ad2b7b8722b2c2709353e883bec6ca877aaa1 /Source/UnitTests/Common/StringUtilTest.cpp
parentda7c813edf729276093abc039d084014ce330096 (diff)
UnitTests: Add some StringUtil character encoding conversion tests.
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 ¥");
+}