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

wallpapers/image: Add autotest for ImageSizeFinder

Test the finder can return a correct image dimension.
parent 5ac90429
include(ECMMarkAsTest)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/..)
set(testfindpreferredimage_SRCS
testfindpreferredimage.cpp
../imagebackend.cpp
......@@ -9,3 +12,7 @@ add_executable(testfindpreferredimage EXCLUDE_FROM_ALL ${testfindpreferredimage_
target_link_libraries(testfindpreferredimage
plasma_wallpaper_imageplugin
Qt::Test)
# ImageSizeFinder test
ecm_add_test(test_imagesizefinder.cpp TEST_NAME testimagesizefinder
LINK_LIBRARIES Qt::Test plasma_wallpaper_imageplugin_static)
/*
SPDX-FileCopyrightText: 2022 Fushan Wen <qydwhotmail@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <QDir>
#include <QtTest>
#include "finder/imagesizefinder.h"
class ImageSizeFinderTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase();
void testImageSizeFinder();
private:
QDir m_dataDir;
};
void ImageSizeFinderTest::initTestCase()
{
m_dataDir = QDir(QFINDTESTDATA("testdata/default"));
QVERIFY(!m_dataDir.isEmpty());
}
void ImageSizeFinderTest::testImageSizeFinder()
{
const QString path = m_dataDir.absoluteFilePath(QStringLiteral("wallpaper.jpg.jpg"));
ImageSizeFinder *finder = new ImageSizeFinder(path);
QSignalSpy spy(finder, &ImageSizeFinder::sizeFound);
QThreadPool::globalInstance()->start(finder);
spy.wait(10 * 1000);
QCOMPARE(spy.size(), 1);
const auto firstSignalResult = spy.takeFirst();
QCOMPARE(firstSignalResult.size(), 2);
QCOMPARE(firstSignalResult.at(0).toString(), path);
QCOMPARE(firstSignalResult.at(1).toSize(), QSize(15, 16));
}
QTEST_MAIN(ImageSizeFinderTest)
#include "test_imagesizefinder.moc"
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