diff options
Diffstat (limited to 'tests/auto/gui/image/qmovie')
-rw-r--r-- | tests/auto/gui/image/qmovie/CMakeLists.txt | 22 | ||||
-rw-r--r-- | tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico | bin | 0 -> 25214 bytes | |||
-rw-r--r-- | tests/auto/gui/image/qmovie/tst_qmovie.cpp | 125 |
3 files changed, 110 insertions, 37 deletions
diff --git a/tests/auto/gui/image/qmovie/CMakeLists.txt b/tests/auto/gui/image/qmovie/CMakeLists.txt index 545ee481d1..52e0a347c4 100644 --- a/tests/auto/gui/image/qmovie/CMakeLists.txt +++ b/tests/auto/gui/image/qmovie/CMakeLists.txt @@ -1,20 +1,28 @@ -# Generated from qmovie.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qmovie Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qmovie LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - animations/*) + animations/* multiframe/*) list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qmovie SOURCES tst_qmovie.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui + Qt::TestPrivate TESTDATA ${test_data} ) @@ -23,6 +31,7 @@ set(resources_resource_files "animations/comicsecard.gif" "animations/corrupt.gif" "animations/trolltech.gif" + "multiframe/Obj_N2_Internal_Mem.ico" ) qt_internal_add_resource(tst_qmovie "resources" @@ -32,16 +41,11 @@ qt_internal_add_resource(tst_qmovie "resources" ${resources_resource_files} ) - -#### Keys ignored in scope 1:.:.:qmovie.pro:<TRUE>: -# MOC_DIR = "tmp" -# QT_FOR_CONFIG = "gui-private" - ## Scopes: ##################################################################### qt_internal_extend_target(tst_qmovie CONDITION TARGET Qt::Widgets - PUBLIC_LIBRARIES + LIBRARIES Qt::Widgets ) diff --git a/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico b/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico Binary files differnew file mode 100644 index 0000000000..8da119efdd --- /dev/null +++ b/tests/auto/gui/image/qmovie/multiframe/Obj_N2_Internal_Mem.ico diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp index c1abeccba5..29c3297043 100644 --- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp +++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp @@ -1,41 +1,18 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> #include <QTestEventLoop> #include <QSignalSpy> +#include <QtTest/private/qpropertytesthelper_p.h> #include <QIODevice> #ifndef QT_NO_WIDGETS #include <QLabel> #endif #include <QMovie> +#include <QProperty> class tst_QMovie : public QObject { @@ -59,12 +36,20 @@ private slots: void playMovie(); void jumpToFrame_data(); void jumpToFrame(); + void frameDelay(); void changeMovieFile(); #ifndef QT_NO_WIDGETS void infiniteLoop(); #endif void emptyMovie(); void bindings(); + void automatedBindings(); +#ifndef QT_NO_ICO + void multiFrameImage(); +#endif + + void setScaledSize_data(); + void setScaledSize(); }; // Testing get/set functions @@ -180,7 +165,7 @@ void tst_QMovie::playMovie() movie.start(); QCOMPARE(movie.state(), QMovie::Running); QTestEventLoop::instance().enterLoop(2); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(finishedSpy.size(), 0); QCOMPARE(movie.state(), QMovie::Running); QCOMPARE(movie.currentFrameNumber(), 0); } @@ -200,6 +185,17 @@ void tst_QMovie::jumpToFrame() QCOMPARE(movie.currentFrameNumber(), 0); } +void tst_QMovie::frameDelay() +{ + QMovie movie(QFINDTESTDATA("animations/comicsecard.gif")); + QList<int> frameDelays{ 200, 800, 800, 2000, 2600 }; + for (int i = 0; i < movie.frameCount(); i++) { + movie.jumpToFrame(i); + // Processing may have taken a little time, so round to nearest 100ms + QCOMPARE(100 * qRound(movie.nextFrameDelay() / 100.0f), frameDelays[i]); + } +} + void tst_QMovie::changeMovieFile() { QMovie movie(QFINDTESTDATA("animations/comicsecard.gif")); @@ -263,5 +259,78 @@ void tst_QMovie::bindings() QCOMPARE(cacheModeObserver, QMovie::CacheAll); } +void tst_QMovie::automatedBindings() +{ + QMovie movie; + + QTestPrivate::testReadWritePropertyBasics(movie, 50, 100, "speed"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QMovie::speed"); + return; + } + + QTestPrivate::testReadWritePropertyBasics(movie, QMovie::CacheAll, QMovie::CacheNone, + "cacheMode"); + if (QTest::currentTestFailed()) { + qDebug("Failed property test for QMovie::cacheMode"); + return; + } +} + +#ifndef QT_NO_ICO +/*! \internal + Test behavior of QMovie with image formats that are multi-frame, + but not normally intended as animation formats (such as tiff and ico). +*/ +void tst_QMovie::multiFrameImage() +{ + QMovie movie(QFINDTESTDATA("multiframe/Obj_N2_Internal_Mem.ico")); + const int expectedFrameCount = 9; + + QCOMPARE(movie.frameCount(), expectedFrameCount); + QVERIFY(movie.isValid()); + movie.setSpeed(1000); // speed up the test: play at 10 FPS (1000% of normal) + QElapsedTimer playTimer; + QSignalSpy frameChangedSpy(&movie, &QMovie::frameChanged); + QSignalSpy errorSpy(&movie, &QMovie::error); + QSignalSpy finishedSpy(&movie, &QMovie::finished); + playTimer.start(); + movie.start(); + QTRY_COMPARE(finishedSpy.size(), 1); + QCOMPARE_GE(playTimer.elapsed(), 100 * expectedFrameCount); + QCOMPARE(movie.nextFrameDelay(), 100); + QCOMPARE(errorSpy.size(), 0); + QCOMPARE(frameChangedSpy.size(), expectedFrameCount); +} +#endif + +void tst_QMovie::setScaledSize_data() +{ + QTest::addColumn<QString>("fileName"); + QTest::addColumn<QSize>("scaledSize"); + QTest::addColumn<QSize>("expectedSize"); + + QTest::newRow("trolltech (50, 50)") << QString("animations/trolltech.gif") << QSize(50, 50) << QSize(50, 50); + QTest::newRow("trolltech (400, 400)") << QString("animations/trolltech.gif") << QSize(400, 400) << QSize(400, 400); + QTest::newRow("trolltech (50, 0)") << QString("animations/trolltech.gif") << QSize(50, 0) << QSize(50, 25); + QTest::newRow("trolltech (50, -1)") << QString("animations/trolltech.gif") << QSize(50, -1) << QSize(50, 25); + QTest::newRow("trolltech (0, 50)") << QString("animations/trolltech.gif") << QSize(0, 50) << QSize(100, 50); + QTest::newRow("trolltech (-1, 50)") << QString("animations/trolltech.gif") << QSize(-1, 50) << QSize(100, 50); +} + +void tst_QMovie::setScaledSize() +{ + QFETCH(QString, fileName); + QFETCH(QSize, scaledSize); + QFETCH(QSize, expectedSize); + + QMovie movie(QFINDTESTDATA(fileName)); + movie.setScaledSize(scaledSize); + + movie.start(); + QCOMPARE(movie.currentFrameNumber(), 0); + QCOMPARE(movie.currentImage().size(), expectedSize); +} + QTEST_MAIN(tst_QMovie) #include "tst_qmovie.moc" |