diff --git a/src/test/unittests/arch/IArchStringTests.cpp b/src/test/unittests/arch/IArchStringTests.cpp deleted file mode 100644 index ce10efeeeb..0000000000 --- a/src/test/unittests/arch/IArchStringTests.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Deskflow -- mouse and keyboard sharing utility - * SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd. - * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception - */ - -#include "lib/arch/IArchString.h" - -#include - -class SampleIArchString : public IArchString -{ -public: - EWideCharEncoding getWideCharEncoding() override - { - return kUTF16; - } -}; - -TEST(IArchStringTests, convStringWCToMB_will_work_do_simple_conversions) -{ - SampleIArchString as; - char buff[20]; - bool errors; - auto converted = as.convStringWCToMB(buff, L"Hello", 6, &errors); - EXPECT_STREQ(buff, "Hello"); - EXPECT_EQ(converted, 6); - EXPECT_EQ(errors, false); -} - -TEST(IArchStringTests, convStringWCToMB_will_work_do_simple_conversions_noresult) -{ - SampleIArchString as; - bool errors; - auto converted = as.convStringWCToMB(nullptr, L"Hello", 6, &errors); - EXPECT_EQ(converted, 6); - EXPECT_EQ(errors, false); -} - -TEST(IArchStringTests, convStringMBToWC_will_work_do_simple_conversions) -{ - SampleIArchString as; - wchar_t buff[20]; - bool errors; - auto converted = as.convStringMBToWC(buff, "Hello", 6, &errors); - EXPECT_STREQ(buff, L"Hello"); - EXPECT_EQ(converted, 6); - EXPECT_EQ(errors, false); -} diff --git a/src/unittests/CMakeLists.txt b/src/unittests/CMakeLists.txt index acb832ecf2..aacb012b0a 100644 --- a/src/unittests/CMakeLists.txt +++ b/src/unittests/CMakeLists.txt @@ -41,6 +41,7 @@ endfunction() enable_testing() find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Test) +add_subdirectory(arch) add_subdirectory(common) add_subdirectory(deskflow) add_subdirectory(gui) diff --git a/src/unittests/arch/CMakeLists.txt b/src/unittests/arch/CMakeLists.txt new file mode 100644 index 0000000000..9ba60210f7 --- /dev/null +++ b/src/unittests/arch/CMakeLists.txt @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2025 Deskflow Developers +# SPDX-License-Identifier: MIT + +if(WIN32) + set(extra_libs version) +endif() + +create_test( + NAME IArchStringTests + DEPENDS arch + LIBS base ${extra_libs} + SOURCE IArchStringTests.cpp + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/arch" +) diff --git a/src/unittests/arch/IArchStringTests.cpp b/src/unittests/arch/IArchStringTests.cpp new file mode 100644 index 0000000000..d3c172baa0 --- /dev/null +++ b/src/unittests/arch/IArchStringTests.cpp @@ -0,0 +1,58 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * SPDX-FileCopyrightText: (C) 2014 - 2016 Symless Ltd. + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#include "IArchStringTests.h" + +#include "../../lib/arch/IArchString.h" + +void IArchStringTests::initTestCase() +{ + m_arch.init(); + m_log.setFilter(kDEBUG2); +} + +void IArchStringTests::convertStringWCToMB_buffer() +{ + SampleIArchString as; + char buff[20]; + bool errors; + + auto converted = as.convStringWCToMB(buff, L"Hello", 6, &errors); + + QCOMPARE(converted, 6); + QCOMPARE(buff, "Hello"); + QVERIFY(!errors); +} + +void IArchStringTests::convertStringWCToMB_noBuffer() +{ + SampleIArchString as; + bool errors; + + auto converted = as.convStringWCToMB(nullptr, L"Hello", 6, &errors); + + QCOMPARE(converted, 6); + QVERIFY(!errors); +} + +void IArchStringTests::convertStringMBToWC() +{ + SampleIArchString as; + wchar_t buff[20]; + bool errors; + + auto converted = as.convStringMBToWC(buff, "Hello", 6, &errors); + QCOMPARE(converted, 6); + + auto actual = QString::fromStdWString(buff); + auto expected = QString::fromStdWString(L"Hello"); + + QCOMPARE(actual, expected); + QVERIFY(!errors); +} + +QTEST_MAIN(IArchStringTests) diff --git a/src/unittests/arch/IArchStringTests.h b/src/unittests/arch/IArchStringTests.h new file mode 100644 index 0000000000..512b7951a1 --- /dev/null +++ b/src/unittests/arch/IArchStringTests.h @@ -0,0 +1,33 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#include "base/Log.h" + +#include + +class SampleIArchString : public IArchString +{ +public: + EWideCharEncoding getWideCharEncoding() override + { + return kUTF16; + } +}; + +class IArchStringTests : public QObject +{ + Q_OBJECT +private slots: + void initTestCase(); + // Test are run in order top to bottom + void convertStringWCToMB_buffer(); + void convertStringWCToMB_noBuffer(); + void convertStringMBToWC(); + +private: + Arch m_arch; + Log m_log; +};