diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c1979c36c..55ccb60da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,10 +14,10 @@ set(testFiles testglobal.cpp testorderedset.cpp testpath.cpp - testtildeexpansion.cpp testutilsbytearray.cpp testutilscompare.cpp testutilsdatetime.cpp + testutilsfs.cpp testutilsgzip.cpp testutilsio.cpp testutilsnumber.cpp diff --git a/test/testtildeexpansion.cpp b/test/testtildeexpansion.cpp deleted file mode 100644 index 89c96f7b4..000000000 --- a/test/testtildeexpansion.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include -#include -#include -#include - -#include "base/path.h" -#include "base/utils/fs.h" - -class TestTildeExpansion : public QObject -{ - Q_OBJECT - -private slots: - void testExpandTilde_data(); - void testExpandTilde(); -}; - -void TestTildeExpansion::testExpandTilde_data() -{ - QTest::addColumn("input"); - QTest::addColumn("expected"); - - const QString homeDir = QDir::homePath(); - - QTest::newRow("tilde only") << u"~"_s << homeDir; - QTest::newRow("tilde with path") << u"~/Downloads"_s << (homeDir + u"/Downloads"_s); - QTest::newRow("tilde with nested path") << u"~/Documents/qBittorrent"_s << (homeDir + u"/Documents/qBittorrent"_s); - QTest::newRow("absolute path") << u"/absolute/path"_s << u"/absolute/path"_s; - QTest::newRow("relative path") << u"relative/path"_s << u"relative/path"_s; - QTest::newRow("empty path") << u""_s << u""_s; -} - -void TestTildeExpansion::testExpandTilde() -{ - QFETCH(QString, input); - QFETCH(QString, expected); - - const Path inputPath(input); - const Path expandedPath = Utils::Fs::expandTilde(inputPath); - - QCOMPARE(expandedPath.data(), expected); -} - -QTEST_APPLESS_MAIN(TestTildeExpansion) -#include "testtildeexpansion.moc" diff --git a/test/testutilsfs.cpp b/test/testutilsfs.cpp new file mode 100644 index 000000000..a83104ba9 --- /dev/null +++ b/test/testutilsfs.cpp @@ -0,0 +1,78 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2025 ExcitedHumvee + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include +#include +#include +#include + +#include "base/global.h" +#include "base/path.h" +#include "base/utils/fs.h" + +class TestUtilsFs final : public QObject +{ + Q_OBJECT + Q_DISABLE_COPY_MOVE(TestUtilsFs) + +public: + TestUtilsFs() = default; + +private slots: + void testExpandTilde_data() const; + void testExpandTilde() const; +}; + +void TestUtilsFs::testExpandTilde_data() const +{ + QTest::addColumn("input"); + QTest::addColumn("expected"); + + const QString homeDir = QDir::homePath(); + + QTest::newRow("tilde only") << u"~"_s << homeDir; + QTest::newRow("tilde with path") << u"~/Downloads"_s << QString(homeDir + u"/Downloads"_s); + QTest::newRow("tilde with nested path") << u"~/Documents/qBittorrent"_s << QString(homeDir + u"/Documents/qBittorrent"_s); + QTest::newRow("absolute path") << u"/absolute/path"_s << u"/absolute/path"_s; + QTest::newRow("relative path") << u"relative/path"_s << u"relative/path"_s; + QTest::newRow("empty path") << u""_s << u""_s; +} + +void TestUtilsFs::testExpandTilde() const +{ + QFETCH(QString, input); + QFETCH(QString, expected); + + const Path inputPath(input); + const Path expandedPath = Utils::Fs::expandTilde(inputPath); + + QCOMPARE(expandedPath.data(), expected); +} + +QTEST_APPLESS_MAIN(TestUtilsFs) +#include "testutilsfs.moc"