🚧 wip: ♻️ refactor: chekkupointo
This commit is contained in:
+3
-18
@@ -1,7 +1,7 @@
|
||||
|
||||
project(Tests LANGUAGES CXX)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Test)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Test)
|
||||
|
||||
add_executable(tst_configmgr
|
||||
tst_configmgr.cpp
|
||||
@@ -15,26 +15,11 @@ add_test(NAME tst_configmgr COMMAND tst_configmgr)
|
||||
add_test(NAME tst_imagemodel COMMAND tst_imagemodel)
|
||||
|
||||
target_link_libraries(tst_configmgr PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Test
|
||||
Qt6::Gui
|
||||
wallreel-core
|
||||
${CORELIB_NAME}
|
||||
)
|
||||
|
||||
target_link_libraries(tst_imagemodel PRIVATE
|
||||
Qt6::Core
|
||||
Qt6::Test
|
||||
Qt6::Gui
|
||||
Qt6::Quick
|
||||
wallreel-core
|
||||
)
|
||||
|
||||
target_include_directories(tst_configmgr PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/WallReel/Core
|
||||
${CMAKE_BINARY_DIR}/generated
|
||||
)
|
||||
|
||||
target_include_directories(tst_imagemodel PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/WallReel/Core
|
||||
${CMAKE_BINARY_DIR}/generated
|
||||
${CORELIB_NAME}
|
||||
)
|
||||
|
||||
+17
-15
@@ -8,7 +8,9 @@
|
||||
#include <QTemporaryDir>
|
||||
#include <QTest>
|
||||
|
||||
#include "configmgr.hpp"
|
||||
#include "Config/manager.hpp"
|
||||
|
||||
using namespace WallReel::Core;
|
||||
|
||||
class TestConfigMgr : public QObject {
|
||||
Q_OBJECT
|
||||
@@ -67,7 +69,7 @@ void TestConfigMgr::testDefaults() {
|
||||
// Empty config file
|
||||
writeConfig(QJsonObject());
|
||||
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
// Check Style Defaults
|
||||
QCOMPARE(config.getImageWidth(), 320);
|
||||
@@ -144,7 +146,7 @@ void TestConfigMgr::testFullConfigParsing() {
|
||||
root["sort"] = sortObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
// Assertions
|
||||
QCOMPARE(config.getWallpaperConfig().dirs.size(), 1);
|
||||
@@ -184,7 +186,7 @@ void TestConfigMgr::testInvalidConfigValues() {
|
||||
root["sort"] = sortObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
// Should retain defaults
|
||||
QCOMPARE(config.getImageWidth(), 320);
|
||||
@@ -208,7 +210,7 @@ void TestConfigMgr::testWallpaperScanRecursive() {
|
||||
root["wallpaper"] = wallpaperObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
QStringList wallpapers = config.getWallpapers();
|
||||
QCOMPARE(wallpapers.size(), 2);
|
||||
@@ -235,7 +237,7 @@ void TestConfigMgr::testWallpaperScanNonRecursive() {
|
||||
root["wallpaper"] = wallpaperObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
QStringList wallpapers = config.getWallpapers();
|
||||
QCOMPARE(wallpapers.size(), 1);
|
||||
@@ -262,7 +264,7 @@ void TestConfigMgr::testWallpaperExcludes() {
|
||||
root["wallpaper"] = wallpaperObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
QStringList wallpapers = config.getWallpapers();
|
||||
QCOMPARE(wallpapers.size(), 1);
|
||||
@@ -281,7 +283,7 @@ void TestConfigMgr::testExplicitPaths() {
|
||||
root["wallpaper"] = wallpaperObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
QStringList wallpapers = config.getWallpapers();
|
||||
QCOMPARE(wallpapers.size(), 1);
|
||||
@@ -308,7 +310,7 @@ void TestConfigMgr::testImageExtensions() {
|
||||
root["wallpaper"] = wallpaperObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
|
||||
QStringList wallpapers = config.getWallpapers();
|
||||
|
||||
@@ -332,7 +334,7 @@ void TestConfigMgr::testSortTypes() {
|
||||
root["sort"] = sortObj;
|
||||
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
QCOMPARE(config.getSortConfig().type, Config::SortType::None);
|
||||
QCOMPARE(config.getSortConfig().reverse, false);
|
||||
}
|
||||
@@ -344,7 +346,7 @@ void TestConfigMgr::testSortTypes() {
|
||||
sortObj["reverse"] = true;
|
||||
root["sort"] = sortObj;
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
QCOMPARE(config.getSortConfig().type, Config::SortType::Name);
|
||||
QCOMPARE(config.getSortConfig().reverse, true);
|
||||
}
|
||||
@@ -355,7 +357,7 @@ void TestConfigMgr::testSortTypes() {
|
||||
sortObj["type"] = "size";
|
||||
root["sort"] = sortObj;
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
QCOMPARE(config.getSortConfig().type, Config::SortType::Size);
|
||||
}
|
||||
// 4. Date sort
|
||||
@@ -365,7 +367,7 @@ void TestConfigMgr::testSortTypes() {
|
||||
sortObj["type"] = "date";
|
||||
root["sort"] = sortObj;
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
QCOMPARE(config.getSortConfig().type, Config::SortType::Date);
|
||||
}
|
||||
// 5. Invalid sort -> fallback to default (Name)
|
||||
@@ -375,7 +377,7 @@ void TestConfigMgr::testSortTypes() {
|
||||
sortObj["type"] = "invalid_blah";
|
||||
root["sort"] = sortObj;
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
// Default initialized in Config constructor is Name
|
||||
// But warning is logged
|
||||
QCOMPARE(config.getSortConfig().type, Config::SortType::Name);
|
||||
@@ -387,7 +389,7 @@ void TestConfigMgr::testSortTypes() {
|
||||
sortObj["type"] = "DaTe";
|
||||
root["sort"] = sortObj;
|
||||
writeConfig(root);
|
||||
Config config(m_tempDir.path(), {}, m_configPath);
|
||||
Config::Manager config(m_tempDir.path(), {}, m_configPath);
|
||||
QCOMPARE(config.getSortConfig().type, Config::SortType::Date);
|
||||
}
|
||||
}
|
||||
|
||||
+32
-30
@@ -3,9 +3,11 @@
|
||||
#include <QTemporaryDir>
|
||||
#include <QtTest>
|
||||
|
||||
#include "configmgr.hpp"
|
||||
#include "imagemodel.hpp"
|
||||
#include "imageprovider.hpp"
|
||||
#include "Config/manager.hpp"
|
||||
#include "Image/model.hpp"
|
||||
#include "Image/provider.hpp"
|
||||
|
||||
using namespace WallReel::Core;
|
||||
|
||||
class TestImageModel : public QObject {
|
||||
Q_OBJECT
|
||||
@@ -23,7 +25,7 @@ class TestImageModel : public QObject {
|
||||
QString m_pathC;
|
||||
|
||||
void createTestFiles();
|
||||
void waitForModel(ImageModel* model);
|
||||
void waitForModel(Image::Model* model);
|
||||
};
|
||||
|
||||
// clang-format off
|
||||
@@ -115,11 +117,11 @@ void TestImageModel::createTestFiles() {
|
||||
}
|
||||
}
|
||||
|
||||
void TestImageModel::waitForModel(ImageModel* model) {
|
||||
void TestImageModel::waitForModel(Image::Model* model) {
|
||||
if (!model->isLoading()) {
|
||||
return;
|
||||
}
|
||||
QSignalSpy spy(model, &ImageModel::isLoadingChanged);
|
||||
QSignalSpy spy(model, &Image::Model::isLoadingChanged);
|
||||
while (model->isLoading()) {
|
||||
if (!spy.wait(5000)) {
|
||||
qWarning() << "Timeout waiting for model to load";
|
||||
@@ -133,8 +135,8 @@ void TestImageModel::testSortName() {
|
||||
sortConfig.type = Config::SortType::Name;
|
||||
sortConfig.reverse = false;
|
||||
|
||||
ImageProvider provider;
|
||||
ImageModel model(provider, sortConfig, QSize(100, 100));
|
||||
Image::Provider provider;
|
||||
Image::Model model(provider, sortConfig, QSize(100, 100));
|
||||
|
||||
QStringList paths = {m_pathB, m_pathA, m_pathC}; // Unordered input
|
||||
model.loadAndProcess(paths);
|
||||
@@ -143,9 +145,9 @@ void TestImageModel::testSortName() {
|
||||
QCOMPARE(model.rowCount(), 3);
|
||||
|
||||
// Expected: a.gif, b.gif, c.gif
|
||||
QCOMPARE(model.data(model.index(0), ImageModel::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(1), ImageModel::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(2), ImageModel::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(0), Image::Model::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(1), Image::Model::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(2), Image::Model::NameRole).toString(), "c.gif");
|
||||
|
||||
// Reverse
|
||||
sortConfig.reverse = true;
|
||||
@@ -154,9 +156,9 @@ void TestImageModel::testSortName() {
|
||||
QCOMPARE(model.rowCount(), 3);
|
||||
|
||||
// Expected: c.gif, b.gif, a.gif
|
||||
QCOMPARE(model.data(model.index(0), ImageModel::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(1), ImageModel::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(2), ImageModel::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(0), Image::Model::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(1), Image::Model::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(2), Image::Model::NameRole).toString(), "a.gif");
|
||||
}
|
||||
|
||||
void TestImageModel::testSortDate() {
|
||||
@@ -164,8 +166,8 @@ void TestImageModel::testSortDate() {
|
||||
sortConfig.type = Config::SortType::Date;
|
||||
sortConfig.reverse = false;
|
||||
|
||||
ImageProvider provider;
|
||||
ImageModel model(provider, sortConfig, QSize(100, 100));
|
||||
Image::Provider provider;
|
||||
Image::Model model(provider, sortConfig, QSize(100, 100));
|
||||
|
||||
QStringList paths = {m_pathA, m_pathC, m_pathB};
|
||||
model.loadAndProcess(paths);
|
||||
@@ -174,17 +176,17 @@ void TestImageModel::testSortDate() {
|
||||
QCOMPARE(model.rowCount(), 3);
|
||||
|
||||
// Expected: c (old), a (mid), b (new)
|
||||
QCOMPARE(model.data(model.index(0), ImageModel::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(1), ImageModel::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), ImageModel::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(0), Image::Model::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(1), Image::Model::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), Image::Model::NameRole).toString(), "b.gif");
|
||||
|
||||
// Reverse (Newest first)
|
||||
sortConfig.reverse = true;
|
||||
model.sortUpdate();
|
||||
|
||||
QCOMPARE(model.data(model.index(0), ImageModel::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(1), ImageModel::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), ImageModel::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(0), Image::Model::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(1), Image::Model::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), Image::Model::NameRole).toString(), "c.gif");
|
||||
}
|
||||
|
||||
void TestImageModel::testSortSize() {
|
||||
@@ -192,8 +194,8 @@ void TestImageModel::testSortSize() {
|
||||
sortConfig.type = Config::SortType::Size;
|
||||
sortConfig.reverse = false;
|
||||
|
||||
ImageProvider provider;
|
||||
ImageModel model(provider, sortConfig, QSize(100, 100));
|
||||
Image::Provider provider;
|
||||
Image::Model model(provider, sortConfig, QSize(100, 100));
|
||||
|
||||
QStringList paths = {m_pathB, m_pathC, m_pathA};
|
||||
model.loadAndProcess(paths);
|
||||
@@ -201,17 +203,17 @@ void TestImageModel::testSortSize() {
|
||||
|
||||
QCOMPARE(model.rowCount(), 3);
|
||||
|
||||
QCOMPARE(model.data(model.index(0), ImageModel::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(1), ImageModel::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), ImageModel::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(0), Image::Model::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(1), Image::Model::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), Image::Model::NameRole).toString(), "b.gif");
|
||||
|
||||
// Reverse
|
||||
sortConfig.reverse = true;
|
||||
model.sortUpdate();
|
||||
|
||||
QCOMPARE(model.data(model.index(0), ImageModel::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(1), ImageModel::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), ImageModel::NameRole).toString(), "c.gif");
|
||||
QCOMPARE(model.data(model.index(0), Image::Model::NameRole).toString(), "b.gif");
|
||||
QCOMPARE(model.data(model.index(1), Image::Model::NameRole).toString(), "a.gif");
|
||||
QCOMPARE(model.data(model.index(2), Image::Model::NameRole).toString(), "c.gif");
|
||||
}
|
||||
|
||||
QTEST_MAIN(TestImageModel)
|
||||
|
||||
Reference in New Issue
Block a user