mirror of
https://github.com/redstrate/Astra.git
synced 2025-04-20 11:47:46 +00:00
Add tests for the utility functions
This commit is contained in:
parent
29cd58e62f
commit
47f6d1035e
4 changed files with 70 additions and 7 deletions
|
@ -6,3 +6,9 @@ ecm_add_test(patchlisttest.cpp
|
|||
LINK_LIBRARIES astra_static Qt::Test
|
||||
NAME_PREFIX "astra-"
|
||||
)
|
||||
|
||||
ecm_add_test(utilitytest.cpp
|
||||
TEST_NAME utilitytest
|
||||
LINK_LIBRARIES astra_static Qt::Test
|
||||
NAME_PREFIX "astra-"
|
||||
)
|
58
autotests/utilitytest.cpp
Normal file
58
autotests/utilitytest.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
// SPDX-FileCopyrightText: 2024 Joshua Goins <josh@redstrate.com>
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include "utility.h"
|
||||
|
||||
class UtilityTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void testToWindowsPath()
|
||||
{
|
||||
QCOMPARE(Utility::toWindowsPath(QStringLiteral("/home/testuser/test.txt")), QStringLiteral("Z:\\home\\testuser\\test.txt"));
|
||||
}
|
||||
|
||||
void testCreatePathIfNeeded()
|
||||
{
|
||||
QTemporaryDir dir;
|
||||
QString testDirPath = dir.filePath(QStringLiteral("test-dir"));
|
||||
|
||||
QVERIFY(!QDir().exists(testDirPath));
|
||||
|
||||
Utility::createPathIfNeeded(testDirPath);
|
||||
|
||||
QVERIFY(QDir().exists(testDirPath));
|
||||
}
|
||||
|
||||
void testReadVersion()
|
||||
{
|
||||
QTemporaryFile verFile;
|
||||
verFile.open();
|
||||
|
||||
verFile.write(QByteArrayLiteral("2023.09.15.0000.0000"));
|
||||
verFile.flush();
|
||||
|
||||
QCOMPARE(Utility::readVersion(verFile.fileName()), QStringLiteral("2023.09.15.0000.0000"));
|
||||
|
||||
// lines should not affect the output
|
||||
verFile.write(QByteArrayLiteral("\r\n"));
|
||||
verFile.flush();
|
||||
|
||||
QCOMPARE(Utility::readVersion(verFile.fileName()), QStringLiteral("2023.09.15.0000.0000"));
|
||||
}
|
||||
|
||||
void testWriteVersion()
|
||||
{
|
||||
QTemporaryFile verFile;
|
||||
verFile.open();
|
||||
|
||||
Utility::writeVersion(verFile.fileName(), QStringLiteral("2023.09.15.0000.0000"));
|
||||
QCOMPARE(Utility::readVersion(verFile.fileName()), QStringLiteral("2023.09.15.0000.0000"));
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(UtilityTest)
|
||||
#include "utilitytest.moc"
|
|
@ -29,10 +29,13 @@ ecm_qt_declare_logging_category(astra_static
|
|||
|
||||
target_sources(astra_static PRIVATE
|
||||
include/patchlist.h
|
||||
src/patchlist.cpp)
|
||||
include/utility.h
|
||||
src/patchlist.cpp
|
||||
src/utility.cpp)
|
||||
target_include_directories(astra_static PUBLIC include)
|
||||
target_link_libraries(astra_static PUBLIC
|
||||
Qt6::Core)
|
||||
Qt6::Core
|
||||
Qt6::Network)
|
||||
|
||||
add_executable(astra)
|
||||
|
||||
|
@ -62,7 +65,6 @@ target_sources(astra PRIVATE
|
|||
include/sapphirelogin.h
|
||||
include/squareenixlogin.h
|
||||
include/steamapi.h
|
||||
include/utility.h
|
||||
|
||||
src/account.cpp
|
||||
src/accountmanager.cpp
|
||||
|
@ -86,7 +88,6 @@ target_sources(astra PRIVATE
|
|||
src/sapphirelogin.cpp
|
||||
src/squareenixlogin.cpp
|
||||
src/steamapi.cpp
|
||||
src/utility.cpp
|
||||
)
|
||||
|
||||
qt_target_qml_sources(astra
|
||||
|
@ -148,8 +149,6 @@ target_link_libraries(astra PRIVATE
|
|||
cotp
|
||||
KDAB::kdsingleapplication
|
||||
Qt6Keychain::Qt6Keychain
|
||||
Qt6::Core
|
||||
Qt6::Network
|
||||
Qt6::Widgets
|
||||
Qt6::Quick
|
||||
Qt6::QuickControls2
|
||||
|
|
|
@ -39,7 +39,7 @@ QString Utility::readVersion(const QString &path)
|
|||
QFile file(path);
|
||||
file.open(QFile::ReadOnly | QFile::Text);
|
||||
|
||||
return QString::fromUtf8(file.readAll());
|
||||
return QString::fromUtf8(file.readAll()).trimmed();
|
||||
}
|
||||
|
||||
void Utility::writeVersion(const QString &path, const QString &version)
|
||||
|
|
Loading…
Add table
Reference in a new issue