Verified Commit e7e70ec5 authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

wallpapers/image: update dark wallpaper test

A KPackage wallpaper containing a dark variant is added to the test
data.

CCBUG: 207976
parent 1ce0e105
Pipeline #186851 passed with stage
in 13 minutes and 19 seconds
......@@ -11,7 +11,7 @@
namespace ImageBackendTestData
{
constexpr const int defaultImageCount = 2;
constexpr const int defaultPackageCount = 1;
constexpr const int defaultPackageCount = 2;
constexpr const int defaultTotalCount = defaultImageCount + defaultPackageCount;
constexpr const int alternateImageCount = 1;
......@@ -20,7 +20,8 @@ constexpr const int alternateTotalCount = alternateImageCount + alternatePackage
inline const QString defaultImageFileName1 = QStringLiteral("wallpaper.jpg.jpg");
inline const QString defaultImageFileName2 = QStringLiteral("# BUG454692 file name with hash char.png");
inline const QString defaultPackageFolderName1 = QStringLiteral("package");
inline const QString defaultPackageFolderName1 = QStringLiteral("FEATURE207976-dark-wallpaper");
inline const QString defaultPackageFolderName2 = QStringLiteral("package");
inline const QString alternateImageFileName1 = QStringLiteral("dummy.jpg");
inline const QString alternatePackageFolderName1 = QStringLiteral("dummy");
......
......@@ -39,7 +39,7 @@ private:
QDir m_alternateDir;
QStringList m_wallpaperPaths;
QString m_dummyWallpaperPath;
QString m_packagePath;
QStringList m_packagePaths;
QString m_dummyPackagePath;
int m_modelNum = 0;
QSize m_targetSize;
......@@ -56,7 +56,8 @@ void ImageProxyModelTest::initTestCase()
m_wallpaperPaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultImageFileName2);
m_dummyWallpaperPath = m_alternateDir.absoluteFilePath(ImageBackendTestData::alternateImageFileName1);
m_packagePath = m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1);
m_packagePaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1);
m_packagePaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName2);
m_dummyPackagePath = m_alternateDir.absoluteFilePath(ImageBackendTestData::alternatePackageFolderName1);
m_modelNum = 2;
......@@ -112,8 +113,10 @@ void ImageProxyModelTest::testImageProxyModelIndexOf()
{
QVERIFY(m_model->indexOf(m_wallpaperPaths.at(0)) >= 0);
QVERIFY(m_model->indexOf(m_wallpaperPaths.at(1)) >= 0);
QVERIFY(m_model->indexOf(m_packagePath) >= 0);
QVERIFY(m_model->indexOf(m_packagePath + QDir::separator()) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(0)) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(1)) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(0) + QDir::separator()) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(1) + QDir::separator()) >= 0);
QCOMPARE(m_model->indexOf(m_dataDir.absoluteFilePath(QStringLiteral("brokenpackage") + QDir::separator())), -1);
}
......@@ -142,9 +145,11 @@ void ImageProxyModelTest::testImageProxyModelAddBackground()
QCOMPARE(results.size(), 0);
// Case 2: add an existing package
results = m_model->addBackground(m_packagePath);
QCOMPARE(m_countSpy->size(), 0);
results = m_model->addBackground(m_packagePaths.at(0));
QCOMPARE(results.size(), 0);
results = m_model->addBackground(m_packagePaths.at(1));
QCOMPARE(results.size(), 0);
QCOMPARE(m_countSpy->size(), 0);
// Case 3: add a new wallpaper
results = m_model->addBackground(QUrl::fromLocalFile(m_dummyWallpaperPath).toString());
......@@ -213,7 +218,8 @@ void ImageProxyModelTest::testImageProxyModelDirWatch()
QVERIFY(m_model->m_dirWatch.contains(m_dataDir.absolutePath()));
QVERIFY(m_model->m_dirWatch.contains(m_wallpaperPaths.at(0)));
QVERIFY(m_model->m_dirWatch.contains(m_wallpaperPaths.at(1)));
QVERIFY(m_model->m_dirWatch.contains(m_packagePath));
QVERIFY(m_model->m_dirWatch.contains(m_packagePaths.at(0)));
QVERIFY(m_model->m_dirWatch.contains(m_packagePaths.at(1)));
m_model->deleteLater();
m_countSpy->deleteLater();
......
......@@ -73,7 +73,7 @@ void PackageFinderTest::testFindPreferredSizeInPackage()
QFETCH(QString, expected);
KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Wallpaper/Images"));
package.setPath(m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1));
package.setPath(m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName2));
QVERIFY(package.isValid());
QVERIFY(package.metadata().isValid());
......@@ -86,7 +86,7 @@ void PackageFinderTest::testFindPreferredSizeInPackage()
void PackageFinderTest::testPackageFinderCanFindPackages()
{
PackageFinder *finder =
new PackageFinder({m_dataDir.absolutePath(), m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1)}, QSize(1920, 1080));
new PackageFinder({m_dataDir.absolutePath(), m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName2)}, QSize(1920, 1080));
QSignalSpy spy(finder, &PackageFinder::packageFound);
QThreadPool::globalInstance()->start(finder);
......@@ -95,10 +95,19 @@ void PackageFinderTest::testPackageFinderCanFindPackages()
QCOMPARE(spy.size(), 1);
const auto items = spy.takeFirst().at(0).value<QList<KPackage::Package>>();
// Total 2 packages in the directory, but one package is broken and should not be added to the list.
QCOMPARE(items.size(), 1);
// Total 3 packages in the directory, but one package is broken and should not be added to the list.
QCOMPARE(items.size(), ImageBackendTestData::defaultPackageCount);
// Folders are sorted by names
// FEATURE207976-dark-wallpaper
QCOMPARE(items.at(0).filePath("preferred"),
m_dataDir.absoluteFilePath(QStringLiteral("%1/contents/images/1920x1080.jpg").arg(ImageBackendTestData::defaultPackageFolderName1)));
m_dataDir.absoluteFilePath(QStringLiteral("%1/contents/images/1024x768.png").arg(ImageBackendTestData::defaultPackageFolderName1)));
QCOMPARE(items.at(0).filePath("preferredDark"),
m_dataDir.absoluteFilePath(QStringLiteral("%1/contents/images_dark/1920x1080.jpg").arg(ImageBackendTestData::defaultPackageFolderName1)));
// package
QCOMPARE(items.at(1).filePath("preferred"),
m_dataDir.absoluteFilePath(QStringLiteral("%1/contents/images/1920x1080.jpg").arg(ImageBackendTestData::defaultPackageFolderName2)));
QCOMPARE(items.at(1).filePath("preferredDark"), QString());
}
QTEST_MAIN(PackageFinderTest)
......
......@@ -23,6 +23,7 @@ private Q_SLOTS:
void cleanupTestCase();
void testPackageListModelData();
void testPackageListModelDarkWallpaperPreview();
void testPackageListModelIndexOf();
void testPackageListModelLoad();
void testPackageListModelAddBackground();
......@@ -36,7 +37,7 @@ private:
QDir m_dataDir;
QDir m_alternateDir;
QString m_packagePath;
QStringList m_packagePaths;
QString m_dummyPackagePath;
QSize m_targetSize;
};
......@@ -48,7 +49,8 @@ void PackageListModelTest::initTestCase()
QVERIFY(!m_dataDir.isEmpty());
QVERIFY(!m_alternateDir.isEmpty());
m_packagePath = m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1);
m_packagePaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1);
m_packagePaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName2);
m_dummyPackagePath = m_alternateDir.absoluteFilePath(ImageBackendTestData::alternatePackageFolderName1);
m_targetSize = QSize(1920, 1080);
......@@ -86,7 +88,7 @@ void PackageListModelTest::cleanupTestCase()
void PackageListModelTest::testPackageListModelData()
{
QPersistentModelIndex idx = m_model->index(0, 0);
QPersistentModelIndex idx = m_model->index(m_model->indexOf(m_packagePaths.at(1)), 0);
QVERIFY(idx.isValid());
QCOMPARE(idx.data(Qt::DisplayRole).toString(), QStringLiteral("Honeywave (For test purpose, don't translate!)"));
......@@ -108,18 +110,42 @@ void PackageListModelTest::testPackageListModelData()
QCOMPARE(idx.data(ImageRoles::ResolutionRole).toString(), QStringLiteral("1920x1080"));
QCOMPARE(idx.data(ImageRoles::PathRole).toUrl().toLocalFile(),
m_packagePath + QDir::separator() + QStringLiteral("contents") + QDir::separator() + QStringLiteral("images") + QDir::separator()
m_packagePaths.at(1) + QDir::separator() + QStringLiteral("contents") + QDir::separator() + QStringLiteral("images") + QDir::separator()
+ QStringLiteral("1920x1080.jpg"));
QCOMPARE(idx.data(ImageRoles::PackageNameRole).toString(), m_packagePath + QDir::separator());
QCOMPARE(idx.data(ImageRoles::PackageNameRole).toString(), m_packagePaths.at(1) + QDir::separator());
QCOMPARE(idx.data(ImageRoles::RemovableRole).toBool(), false);
QCOMPARE(idx.data(ImageRoles::PendingDeletionRole).toBool(), false);
}
void PackageListModelTest::testPackageListModelDarkWallpaperPreview()
{
QModelIndex idx = m_model->index(m_model->indexOf(m_packagePaths.at(0)), 0);
QVERIFY(idx.isValid());
QCOMPARE(idx.data(Qt::DisplayRole).toString(), QStringLiteral("Dark Wallpaper (For test purpose, don't translate!)"));
QCOMPARE(idx.data(ImageRoles::ScreenshotRole), QVariant()); // Not cached yet
if (!KIO::PreviewJob::availablePlugins().empty()) {
m_dataSpy->wait();
QCOMPARE(m_dataSpy->size(), 1);
QCOMPARE(m_dataSpy->takeFirst().at(2).value<QVector<int>>().at(0), ImageRoles::ScreenshotRole);
m_dataSpy->clear();
const auto preview = idx.data(ImageRoles::ScreenshotRole).value<QPixmap>();
QVERIFY(!preview.isNull());
const auto previewImage = preview.toImage();
QCOMPARE(previewImage.pixelColor({0, 0}), Qt::red);
QCOMPARE(previewImage.pixelColor({previewImage.width() / 2, 0}), Qt::black);
}
}
void PackageListModelTest::testPackageListModelIndexOf()
{
QCOMPARE(m_model->indexOf(m_packagePath), 0);
QCOMPARE(m_model->indexOf(QUrl::fromLocalFile(m_packagePath).toString()), 0);
QCOMPARE(m_model->indexOf(m_packagePaths.at(0)), 0);
QCOMPARE(m_model->indexOf(m_packagePaths.at(1)), 1);
QCOMPARE(m_model->indexOf(QUrl::fromLocalFile(m_packagePaths.at(0)).toString()), 0);
QCOMPARE(m_model->indexOf(QUrl::fromLocalFile(m_packagePaths.at(1)).toString()), 1);
QCOMPARE(m_model->indexOf(m_dataDir.absoluteFilePath(QStringLiteral("brokenpackage"))), -1);
}
......
......@@ -37,7 +37,7 @@ private:
QDir m_alternateDir;
QStringList m_wallpaperPaths;
QString m_dummyWallpaperPath;
QString m_packagePath;
QStringList m_packagePaths;
QString m_dummyPackagePath;
QSize m_targetSize;
};
......@@ -53,7 +53,8 @@ void SlideModelTest::initTestCase()
m_wallpaperPaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultImageFileName2);
m_dummyWallpaperPath = m_alternateDir.absoluteFilePath(QStringLiteral("dummy.jpg"));
m_packagePath = m_dataDir.absoluteFilePath(QStringLiteral("package"));
m_packagePaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName1);
m_packagePaths << m_dataDir.absoluteFilePath(ImageBackendTestData::defaultPackageFolderName2);
m_dummyPackagePath = m_alternateDir.absoluteFilePath(QStringLiteral("dummy"));
m_targetSize = QSize(1920, 1080);
......@@ -97,7 +98,7 @@ void SlideModelTest::cleanupTestCase()
void SlideModelTest::testSlideModelData()
{
const int row = m_model->indexOf(m_packagePath);
const int row = m_model->indexOf(m_packagePaths.at(1));
QVERIFY(row >= 0);
const QPersistentModelIndex idx = m_model->index(row, 0);
......@@ -111,8 +112,10 @@ void SlideModelTest::testSlideModelIndexOf()
{
QVERIFY(m_model->indexOf(m_wallpaperPaths.at(0)) >= 0);
QVERIFY(m_model->indexOf(m_wallpaperPaths.at(1)) >= 0);
QVERIFY(m_model->indexOf(m_packagePath) >= 0);
QVERIFY(m_model->indexOf(m_packagePath + QDir::separator()) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(0)) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(1)) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(0) + QDir::separator()) >= 0);
QVERIFY(m_model->indexOf(m_packagePaths.at(1) + QDir::separator()) >= 0);
QCOMPARE(m_model->indexOf(m_dummyWallpaperPath), -1);
QCOMPARE(m_model->indexOf(m_dummyPackagePath + QDir::separator()), -1);
}
......
[Desktop Entry]
Name=Dark Wallpaper (For test purpose, don't translate!)
X-KDE-PluginInfo-Name=F36
X-KDE-PluginInfo-Author=Fedora KDE-SIG
X-KDE-PluginInfo-Email=kde@lists.fedoraproject.org
X-KDE-PluginInfo-License=CC-BY-SA
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment