refactor: port arch/IArchStringTests to QtTests
This commit is contained in:
parent
1c907991af
commit
b51dec01ad
5 changed files with 106 additions and 49 deletions
|
|
@ -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 <gtest/gtest.h>
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
@ -41,6 +41,7 @@ endfunction()
|
||||||
enable_testing()
|
enable_testing()
|
||||||
find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Test)
|
find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Test)
|
||||||
|
|
||||||
|
add_subdirectory(arch)
|
||||||
add_subdirectory(common)
|
add_subdirectory(common)
|
||||||
add_subdirectory(deskflow)
|
add_subdirectory(deskflow)
|
||||||
add_subdirectory(gui)
|
add_subdirectory(gui)
|
||||||
|
|
|
||||||
14
src/unittests/arch/CMakeLists.txt
Normal file
14
src/unittests/arch/CMakeLists.txt
Normal file
|
|
@ -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"
|
||||||
|
)
|
||||||
58
src/unittests/arch/IArchStringTests.cpp
Normal file
58
src/unittests/arch/IArchStringTests.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
/*
|
||||||
|
* 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 "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)
|
||||||
33
src/unittests/arch/IArchStringTests.h
Normal file
33
src/unittests/arch/IArchStringTests.h
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* Deskflow -- mouse and keyboard sharing utility
|
||||||
|
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||||
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "base/Log.h"
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue