deskflow/src/unittests/base/UnicodeTests.cpp

64 lines
1.5 KiB
C++
Raw Normal View History

/*
* 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"
#include "arch/ArchString.h"
2025-05-10 03:23:46 +00:00
#include "base/Unicode.h"
void UnicodeTests::initTestCase()
{
m_arch.init();
m_log.setFilter(LogLevel::Debug2);
}
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;
auto result = Unicode::textToUTF8("hello", &errors, ArchString::EWideCharEncoding::kUCS2);
QVERIFY(!errors);
#ifdef _WIN32
QCOMPARE(result, std::string("hello", 5)); // mixed-platform expected result
#else
#ifdef WORDS_BIGENDIAN
QCOMPARE(result, std::string("\0h\0e\0", 5)); // mixed-platform expected result
#else
QCOMPARE(result, std::string("h\0e\0l", 5)); // mixed-platform expected result
#endif // WORDS_BIGENDIAN
#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)