refactor: port base/pathTest to QtTests
This commit is contained in:
parent
b51dec01ad
commit
501726d471
5 changed files with 61 additions and 31 deletions
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2014 - 2021 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "base/Path.h"
|
||||
#include <fstream>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
const std::string testDir = "tmp/test";
|
||||
const std::wstring testDirW = L"tmp/test";
|
||||
|
||||
TEST(PathTests, open_file_using_path)
|
||||
{
|
||||
std::string utf8FileName = testDir + "/тіás.txt";
|
||||
#if SYSAPI_WIN32
|
||||
// Windows uses UTF-16 for file path and names
|
||||
std::wstring fileName = testDirW + L"/\x0442\x0456\x00E1\x0073\x002E\x0074\x0078\x0074";
|
||||
#else
|
||||
std::string fileName = utf8FileName;
|
||||
#endif
|
||||
|
||||
std::fstream file(fileName, std::fstream::out);
|
||||
file << "test";
|
||||
file.close();
|
||||
|
||||
std::ifstream inFile(deskflow::filesystem::path(utf8FileName));
|
||||
EXPECT_TRUE(inFile.is_open());
|
||||
}
|
||||
|
|
@ -42,6 +42,7 @@ enable_testing()
|
|||
find_package(Qt6 ${REQUIRED_QT_VERSION} REQUIRED COMPONENTS Test)
|
||||
|
||||
add_subdirectory(arch)
|
||||
add_subdirectory(base)
|
||||
add_subdirectory(common)
|
||||
add_subdirectory(deskflow)
|
||||
add_subdirectory(gui)
|
||||
|
|
|
|||
10
src/unittests/base/CMakeLists.txt
Normal file
10
src/unittests/base/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# SPDX-FileCopyrightText: 2025 Deskflow Developers
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
create_test(
|
||||
NAME PathTests
|
||||
DEPENDS base
|
||||
LIBS arch
|
||||
SOURCE PathTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/base"
|
||||
)
|
||||
35
src/unittests/base/PathTests.cpp
Normal file
35
src/unittests/base/PathTests.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Chris Rizzitello <sithlord48@gmail.com>
|
||||
* SPDX-FileCopyrightText: (C) 2014 - 2021 Symless Ltd.
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "PathTests.h"
|
||||
|
||||
#include "../../lib/base/Path.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
void PathTests::initTestCase()
|
||||
{
|
||||
QDir dir;
|
||||
QVERIFY(dir.mkpath("tmp/test"));
|
||||
}
|
||||
|
||||
void PathTests::testOpen()
|
||||
{
|
||||
const QString filePath = QStringLiteral("tmp/test/тіás.txt");
|
||||
QFile file(filePath);
|
||||
|
||||
QVERIFY(file.open(QIODevice::WriteOnly));
|
||||
QVERIFY(file.write("test", 4));
|
||||
|
||||
file.close();
|
||||
QVERIFY(!file.isOpen());
|
||||
|
||||
std::ifstream inFile(deskflow::filesystem::path(filePath.toStdString()));
|
||||
QVERIFY(inFile.is_open());
|
||||
}
|
||||
|
||||
QTEST_MAIN(PathTests)
|
||||
15
src/unittests/base/PathTests.h
Normal file
15
src/unittests/base/PathTests.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* 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 <QTest>
|
||||
|
||||
class PathTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void testOpen();
|
||||
};
|
||||
Loading…
Reference in a new issue