forked from rosebudai/OpenRCT2-Web
Add tests for rct2 <-> utf8 conversions
This commit is contained in:
1 parent
947a0625c8
commit
e7fb20c283
4 files changed
+93
-12
No files matched your search
@@ -4,6 +4,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <openrct2/core/String.hpp>
|
||||
#include "AssertHelpers.hpp"
|
||||
#include "helpers/StringHelpers.hpp"
|
||||
|
||||
using TCase = std::tuple<std::string, std::string, std::string>;
|
||||
|
||||
@@ -11,16 +12,6 @@ class StringTest : public testing::TestWithParam<TCase>
|
||||
{
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Test Helpers
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static std::string StringFromBytes(std::initializer_list<uint8> list)
|
||||
{
|
||||
std::vector<uint8> data(list);
|
||||
return std::string(data.begin(), data.end());
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Tests for String::Trim
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -92,7 +83,7 @@ TEST_F(StringTest, Split_ByEmpty)
|
||||
|
||||
TEST_F(StringTest, Convert_950_to_UTF8)
|
||||
{
|
||||
auto input = StringFromBytes({ 0xA7, 0xD6, 0xB3, 0x74, 0xAA, 0xBA, 0xB4, 0xC4, 0xA6, 0xE2, 0xAA, 0xB0, 0xAF, 0x57 });
|
||||
auto input = StringFromHex("a7d6b374aabab4c4a6e2aab0af57");
|
||||
auto expected = u8"快速的棕色狐狸";
|
||||
auto actual = String::Convert(input, CODE_PAGE::CP_950, CODE_PAGE::CP_UTF8);
|
||||
ASSERT_EQ(expected, actual);
|
||||
@@ -101,7 +92,7 @@ TEST_F(StringTest, Convert_950_to_UTF8)
|
||||
TEST_F(StringTest, Convert_UTF8_to_932)
|
||||
{
|
||||
auto input = u8"ファストブラウンフォックス";
|
||||
auto expected = StringFromBytes({ 0x83, 0x74, 0x83, 0x40, 0x83, 0x58, 0x83, 0x67, 0x83, 0x75, 0x83, 0x89, 0x83, 0x45, 0x83, 0x93, 0x83, 0x74, 0x83, 0x48, 0x83, 0x62, 0x83, 0x4E, 0x83, 0x58 });
|
||||
auto expected = StringFromHex("83748340835883678375838983458393837483488362834e8358");
|
||||
auto actual = String::Convert(input, CODE_PAGE::CP_UTF8, CODE_PAGE::CP_932);
|
||||
ASSERT_EQ(expected, actual);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user