2025-04-03 01:15:52 +00:00
|
|
|
/*
|
|
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
|
|
|
|
* SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "UnicodeTests.h"
|
|
|
|
|
|
2025-05-22 21:55:40 +00:00
|
|
|
#include "arch/ArchString.h"
|
2025-05-10 03:23:46 +00:00
|
|
|
#include "base/Unicode.h"
|
2025-04-03 01:15:52 +00:00
|
|
|
|
|
|
|
|
void UnicodeTests::initTestCase()
|
|
|
|
|
{
|
|
|
|
|
m_arch.init();
|
2025-07-07 21:44:21 +00:00
|
|
|
m_log.setFilter(LogLevel::Debug2);
|
2025-04-03 01:15:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnicodeTests::UTF32ToUTF8()
|
|
|
|
|
{
|
|
|
|
|
bool errors;
|
|
|
|
|
auto result = Unicode::UTF32ToUTF8(std::string("h\0\0\0e\0\0\0l\0\0\0l\0\0\0o\0\0\0", 20), &errors);
|
|
|
|
|
|
|
|
|
|
QVERIFY(!errors);
|
|
|
|
|
QCOMPARE(result.c_str(), "hello");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnicodeTests::UTF16ToUTF8()
|
|
|
|
|
{
|
|
|
|
|
bool errors;
|
|
|
|
|
auto result = Unicode::UTF16ToUTF8(std::string("h\0e\0l\0l\0o\0", 10), &errors);
|
|
|
|
|
|
|
|
|
|
QVERIFY(!errors);
|
|
|
|
|
QCOMPARE(result.c_str(), "hello");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnicodeTests::UCS2ToUTF8_kUCS2()
|
|
|
|
|
{
|
|
|
|
|
bool errors;
|
2025-05-22 21:55:40 +00:00
|
|
|
auto result = Unicode::textToUTF8("hello", &errors, ArchString::EWideCharEncoding::kUCS2);
|
2025-04-03 01:15:52 +00:00
|
|
|
|
|
|
|
|
QVERIFY(!errors);
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
QCOMPARE(result, std::string("hello", 5)); // mixed-platform expected result
|
2025-08-12 08:34:40 +00:00
|
|
|
#else
|
|
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
|
QCOMPARE(result, std::string("\0h\0e\0", 5)); // mixed-platform expected result
|
2025-04-03 01:15:52 +00:00
|
|
|
#else
|
|
|
|
|
QCOMPARE(result, std::string("h\0e\0l", 5)); // mixed-platform expected result
|
2025-08-12 08:34:40 +00:00
|
|
|
#endif // WORDS_BIGENDIAN
|
2025-04-03 01:15:52 +00:00
|
|
|
#endif // _WIN32
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void UnicodeTests::UCS2ToUTF8()
|
|
|
|
|
{
|
|
|
|
|
bool errors;
|
|
|
|
|
auto result = Unicode::textToUTF8("hello", &errors);
|
|
|
|
|
|
|
|
|
|
QVERIFY(!errors);
|
|
|
|
|
QCOMPARE(result, std::string("hello", 5)); // mixed-platform expected result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QTEST_MAIN(UnicodeTests)
|