diff options
Diffstat (limited to 'tests/auto/gui/image/qpixmap/tst_qpixmap.cpp')
-rw-r--r-- | tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 99 |
1 files changed, 58 insertions, 41 deletions
diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 24f10e559c..d8c553b521 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -1,51 +1,27 @@ -/**************************************************************************** -** -** 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$ -** -****************************************************************************/ - - -#include <QtTest/QtTest> -#include <qpixmap.h> -#include <qbitmap.h> -#include <qimage.h> -#include <qimagereader.h> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QSet> +#include <QTemporaryFile> +#include <QBuffer> +#include <QTest> +#include <QPixmap> +#include <QBitmap> +#include <QImage> +#include <QImageReader> +#include <QPaintEngine> + #ifndef QT_NO_WIDGETS -#include <qsplashscreen.h> +#include <QSplashScreen> #endif -#include <qpaintengine.h> #include <qpa/qplatformpixmap.h> #include <qpa/qplatformintegration.h> #include <private/qguiapplication_p.h> #include <private/qdrawhelper_p.h> -#include <QSet> - #ifdef Q_OS_WIN -#include <windows.h> +#include <qt_windows.h> #endif @@ -118,7 +94,9 @@ private slots: void refUnref(); void copy(); + void move(); void deepCopyPreservesDpr(); + void fillPreservesDpr(); void dprPassthrough(); void depthOfNullObjects(); @@ -159,6 +137,7 @@ private slots: void copyOnNonAlignedBoundary(); void devicePixelRatio(); + void deviceIndependentSize(); private: const QString m_prefix; @@ -1063,7 +1042,7 @@ void tst_QPixmap::onlyNullPixmapsOutsideGuiThread() class Thread : public QThread { public: - void run() + void run() override { QTest::ignoreMessage(QtWarningMsg, "QPixmap: It is not safe to use pixmaps outside the GUI thread"); @@ -1142,6 +1121,20 @@ void tst_QPixmap::copy() QCOMPARE(trans, transCopy); } +void tst_QPixmap::move() +{ + QPixmap moveFrom(32, 32); + + QPixmap moveAssigned; + moveAssigned = std::move(moveFrom); + QVERIFY(!moveAssigned.isNull()); + QVERIFY(moveFrom.isNull()); + + QPixmap moveConstructed(std::move(moveAssigned)); + QVERIFY(moveAssigned.isNull()); + QVERIFY(!moveConstructed.isNull()); +} + // QTBUG-58653: Force a deep copy of a pixmap by // having a QPainter and check whether DevicePixelRatio is preserved void tst_QPixmap::deepCopyPreservesDpr() @@ -1155,6 +1148,19 @@ void tst_QPixmap::deepCopyPreservesDpr() QCOMPARE(dest.devicePixelRatio(), dpr); } +// Check that the DPR is preserved after doing a fill after an +// assigned copy of the QPixmap +void tst_QPixmap::fillPreservesDpr() +{ + const qreal dpr = 2; + QPixmap src(32, 32); + src.setDevicePixelRatio(dpr); + src.fill(Qt::red); + QPixmap dest = src; + dest.fill(Qt::blue); + QCOMPARE(dest.devicePixelRatio(), dpr); +} + void tst_QPixmap::dprPassthrough() { const qreal dpr = 2; @@ -1170,8 +1176,10 @@ void tst_QPixmap::dprPassthrough() pm.convertFromImage(img); QCOMPARE(pm.devicePixelRatio(), dpr); +#ifndef QT_NO_IMAGE_HEURISTIC_MASK QBitmap heuristicMask = src.createHeuristicMask(); QCOMPARE(heuristicMask.devicePixelRatio(), dpr); +#endif QBitmap maskFromColor = src.createMaskFromColor(Qt::white); QCOMPARE(maskFromColor.devicePixelRatio(), dpr); @@ -1417,7 +1425,7 @@ void tst_QPixmap::loadFromDataImage() QPixmap pixmapWithCopy = QPixmap::fromImage(imageRef); QFile file(imagePath); - file.open(QIODevice::ReadOnly); + QVERIFY(file.open(QIODevice::ReadOnly)); QByteArray rawData = file.readAll(); QPixmap directLoadingPixmap; @@ -1662,5 +1670,14 @@ void tst_QPixmap::devicePixelRatio() QCOMPARE(b.devicePixelRatio(), qreal(1.0)); } +void tst_QPixmap::deviceIndependentSize() { + QPixmap a(64, 64); + a.fill(Qt::white); + a.setDevicePixelRatio(1.0); + QCOMPARE(a.deviceIndependentSize(), QSizeF(64, 64)); + a.setDevicePixelRatio(2.0); + QCOMPARE(a.deviceIndependentSize(), QSizeF(32, 32)); +} + QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" |