File indexing completed on 2024-12-22 04:12:02

0001 /*
0002  * SPDX-FileCopyrightText: 2019 boud <boud@valdyas.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 #include "TestStorageFilterProxyModel.h"
0007 
0008 #include <simpletest.h>
0009 #include <QStandardPaths>
0010 #include <QDir>
0011 #include <QVersionNumber>
0012 #include <QDirIterator>
0013 #include <QSqlError>
0014 #include <QSqlQuery>
0015 #include <QAbstractItemModelTester>
0016 
0017 #include <kconfig.h>
0018 #include <kconfiggroup.h>
0019 #include <ksharedconfig.h>
0020 
0021 #include <KisResourceCacheDb.h>
0022 #include <KisResourceLocator.h>
0023 #include <KisResourceModel.h>
0024 
0025 #include <DummyResource.h>
0026 #include <ResourceTestHelper.h>
0027 
0028 #include <KisStorageFilterProxyModel.h>
0029 
0030 
0031 #ifndef FILES_DATA_DIR
0032 #error "FILES_DATA_DIR not set. A directory with the data used for testing installing resources"
0033 #endif
0034 
0035 
0036 void TestStorageFilterProxyModel::initTestCase()
0037 {
0038     ResourceTestHelper::initTestDb();
0039     ResourceTestHelper::createDummyLoaderRegistry();
0040 
0041     m_srcLocation = QString(FILES_DATA_DIR);
0042     QVERIFY2(QDir(m_srcLocation).exists(), m_srcLocation.toUtf8());
0043 
0044     m_dstLocation = ResourceTestHelper::filesDestDir();
0045     ResourceTestHelper::cleanDstLocation(m_dstLocation);
0046 
0047     KConfigGroup cfg(KSharedConfig::openConfig(), "");
0048     cfg.writeEntry(KisResourceLocator::resourceLocationKey, m_dstLocation);
0049 
0050     m_locator = KisResourceLocator::instance();
0051 
0052     if (!KisResourceCacheDb::initialize(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation))) {
0053         qDebug() << "Could not initialize KisResourceCacheDb on" << QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
0054     }
0055     QVERIFY(KisResourceCacheDb::isValid());
0056 
0057     KisResourceLocator::LocatorError r = m_locator->initialize(m_srcLocation);
0058     if (!m_locator->errorMessages().isEmpty()) qDebug() << m_locator->errorMessages();
0059 
0060     QVERIFY(r == KisResourceLocator::LocatorError::Ok);
0061     QVERIFY(QDir(m_dstLocation).exists());
0062 }
0063 
0064 void TestStorageFilterProxyModel::testWithTagModelTester()
0065 {
0066     KisStorageFilterProxyModel model;
0067     model.setSourceModel(KisStorageModel::instance());
0068     auto tester = new QAbstractItemModelTester(&model);
0069     Q_UNUSED(tester);
0070 }
0071 
0072 
0073 void TestStorageFilterProxyModel::testFilterByName()
0074 {
0075     QScopedPointer<KisStorageFilterProxyModel> proxyModel(new KisStorageFilterProxyModel());
0076     proxyModel->setSourceModel(KisStorageModel::instance());
0077 
0078     QString fileName = "test1";
0079 
0080     proxyModel->setFilter(KisStorageFilterProxyModel::ByStorageType, fileName);
0081 
0082 }
0083 
0084 void TestStorageFilterProxyModel::testFilterByType()
0085 {
0086     QScopedPointer<KisStorageFilterProxyModel> proxyModel(new KisStorageFilterProxyModel());
0087     proxyModel->setSourceModel(KisStorageModel::instance());
0088     proxyModel->setFilter(KisStorageFilterProxyModel::ByStorageType,
0089                           QStringList()
0090                           << KisResourceStorage::storageTypeToUntranslatedString(KisResourceStorage::StorageType::Bundle)
0091                           << KisResourceStorage::storageTypeToUntranslatedString(KisResourceStorage::StorageType::Folder));
0092 
0093 }
0094 
0095 void TestStorageFilterProxyModel::testFilterByActive()
0096 {
0097     QScopedPointer<KisStorageFilterProxyModel> proxyModel(new KisStorageFilterProxyModel());
0098     proxyModel->setSourceModel(KisStorageModel::instance());
0099     proxyModel->setFilter(KisStorageFilterProxyModel::ByStorageType, true);
0100 }
0101 
0102 
0103 void TestStorageFilterProxyModel::cleanupTestCase()
0104 {
0105     ResourceTestHelper::rmTestDb();
0106     ResourceTestHelper::cleanDstLocation(m_dstLocation);
0107 }
0108 
0109 
0110 SIMPLE_TEST_MAIN(TestStorageFilterProxyModel)
0111