| 1 | /* |
| 2 | * Copyright 2012 Canonical Ltd. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation; version 3. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU Lesser General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU Lesser General Public License |
| 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | * |
| 16 | * Author: Florian Boucault <[email protected]> |
| 17 | */ |
| 18 | |
| 19 | #include <QtTest/QtTest> |
| 20 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 21 | #include <LomiriToolkit-Qt6/private/ucscalingimageprovider_p.h> |
| 22 | #else |
| 23 | #include <LomiriToolkit/private/ucscalingimageprovider_p.h> |
| 24 | #endif |
| 25 | |
| 26 | UT_USE_NAMESPACE |
| 27 | |
| 28 | class tst_UCScalingImageProvider: public QObject |
| 29 | { |
| 30 | Q_OBJECT |
| 31 | |
| 32 | private Q_SLOTS: |
| 33 | |
| 34 | void scaleToHalfSize() { |
| 35 | UCScalingImageProvider provider; |
| 36 | QImage result; |
| 37 | QSize returnedSize; |
| 38 | QImage expected; |
| 39 | |
| 40 | result = provider.requestImage("0.5/" + QDir::currentPath() + QDir::separator() + "input.png", &returnedSize, QSize()); |
| 41 | expected = QImage("scaled_half.png"); |
| 42 | |
| 43 | QCOMPARE(result, expected); |
| 44 | QCOMPARE(returnedSize, expected.size()); |
| 45 | } |
| 46 | |
| 47 | void qrcSupport() { |
| 48 | UCScalingImageProvider provider; |
| 49 | QImage result; |
| 50 | QSize returnedSize; |
| 51 | QImage expected; |
| 52 | |
| 53 | result = provider.requestImage("0.5/:/test/prefix/input.png", &returnedSize, QSize()); |
| 54 | expected = QImage("scaled_half.png"); |
| 55 | |
| 56 | QCOMPARE(result, expected); |
| 57 | QCOMPARE(returnedSize, expected.size()); |
| 58 | } |
| 59 | |
| 60 | void respectRequestedSize_data() { |
| 61 | QTest::addColumn<QString>("inputFile"); |
| 62 | QTest::addColumn<QString>("scalingFactor"); |
| 63 | QTest::addColumn<QSize>("requestedSize"); |
| 64 | QTest::addColumn<QSize>("returnedSize"); |
| 65 | QTest::addColumn<QSize>("resultSize"); |
| 66 | |
| 67 | QString inputFile(QDir::currentPath() + QDir::separator() + "input128x256.png"); |
| 68 | QTest::newRow("no scaling, bigger width and height") << inputFile << "1.0" << QSize(1000, 1000) << QSize(128, 256) << QSize(128, 256); |
| 69 | QTest::newRow("no scaling, smaller width") << inputFile << "1.0" << QSize(50, 1000) << QSize(128, 256) << QSize(50, 100); |
| 70 | QTest::newRow("no scaling, smaller height") << inputFile << "1.0" << QSize(1000, 50) << QSize(128, 256) << QSize(25, 50); |
| 71 | QTest::newRow("no scaling, smaller width and height")<< inputFile << "1.0" << QSize(50, 50) << QSize(128, 256) << QSize(25, 50); |
| 72 | QTest::newRow("downscaling, bigger width and height")<< inputFile << "0.5" << QSize(1000, 1000) << QSize(64, 128) << QSize(64, 128); |
| 73 | QTest::newRow("downscaling, smaller width") << inputFile << "0.5" << QSize(50, 1000) << QSize(64, 128) << QSize(50, 100); |
| 74 | QTest::newRow("downscaling, smaller height") << inputFile << "0.5" << QSize(1000, 50) << QSize(64, 128) << QSize(25, 50); |
| 75 | QTest::newRow("downscaling, smaller width and height")<< inputFile << "0.5" << QSize(50, 50) << QSize(64, 128) << QSize(25, 50); |
| 76 | QTest::newRow("upscaling, bigger width and height") << inputFile << "2.0" << QSize(1000, 1000) << QSize(256, 512) << QSize(256, 512); |
| 77 | QTest::newRow("upscaling, smaller width") << inputFile << "2.0" << QSize(50, 1000) << QSize(256, 512) << QSize(50, 100); |
| 78 | QTest::newRow("upscaling, smaller height") << inputFile << "2.0" << QSize(1000, 50) << QSize(256, 512) << QSize(25, 50); |
| 79 | QTest::newRow("upscaling, smaller width and height") << inputFile << "2.0" << QSize(50, 50) << QSize(256, 512) << QSize(25, 50); |
| 80 | QTest::newRow("upscaling, smaller width and no height") << inputFile << "2.0" << QSize(50, 0) << QSize(256, 512) << QSize(50, 100); |
| 81 | QTest::newRow("upscaling, smaller height and no width") << inputFile << "2.0" << QSize(0, 50) << QSize(256, 512) << QSize(25, 50); |
| 82 | } |
| 83 | |
| 84 | void respectRequestedSize() { |
| 85 | UCScalingImageProvider provider; |
| 86 | QImage result; |
| 87 | QSize size; |
| 88 | |
| 89 | QFETCH(QString, inputFile); |
| 90 | QFETCH(QString, scalingFactor); |
| 91 | QFETCH(QSize, requestedSize); |
| 92 | QFETCH(QSize, returnedSize); |
| 93 | QFETCH(QSize, resultSize); |
| 94 | |
| 95 | result = provider.requestImage(scalingFactor + "/" + inputFile, &size, requestedSize); |
| 96 | |
| 97 | QCOMPARE(size, returnedSize); |
| 98 | QCOMPARE(result.size(), resultSize); |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | QTEST_MAIN(tst_UCScalingImageProvider) |
| 103 | |
| 104 | #include "tst_scaling_image_provider.moc" |