diff options
Diffstat (limited to 'tests/auto/gui/image/qmovie/tst_qmovie.cpp')
-rw-r--r-- | tests/auto/gui/image/qmovie/tst_qmovie.cpp | 124 |
1 files changed, 96 insertions, 28 deletions
diff --git a/tests/auto/gui/image/qmovie/tst_qmovie.cpp b/tests/auto/gui/image/qmovie/tst_qmovie.cpp index 11592ffc2a..29c3297043 100644 --- a/tests/auto/gui/image/qmovie/tst_qmovie.cpp +++ b/tests/auto/gui/image/qmovie/tst_qmovie.cpp @@ -1,35 +1,11 @@ -/**************************************************************************** -** -** 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 @@ -60,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 @@ -181,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); } @@ -201,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")); @@ -264,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" |