1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtAddOn.ImageFormats module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL-EXCEPT$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 as published by the Free Software
20** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
21** included in the packaging of this file. Please review the following
22** information to ensure the GNU General Public License requirements will
23** be met: https://www.gnu.org/licenses/gpl-3.0.html.
24**
25** $QT_END_LICENSE$
26**
27****************************************************************************/
28
29#include <QtTest/QtTest>
30#include <QtGui/QtGui>
31
32class tst_qtiff: public QObject
33{
34 Q_OBJECT
35
36private slots:
37 void initTestCase();
38
39 void readImage_data();
40 void readImage();
41 void readCorruptImage_data();
42 void readCorruptImage();
43
44private:
45 QString prefix;
46};
47
48void tst_qtiff::initTestCase()
49{
50 prefix = ":/tiff/";
51}
52
53void tst_qtiff::readImage_data()
54{
55 QTest::addColumn<QString>(name: "fileName");
56 QTest::addColumn<QSize>(name: "size");
57
58 QTest::newRow(dataTag: "grayscale-ref") << QString("grayscale-ref.tif") << QSize(320, 200);
59 QTest::newRow(dataTag: "grayscale") << QString("grayscale.tif") << QSize(320, 200);
60 QTest::newRow(dataTag: "image_100dpi") << QString("image_100dpi.tif") << QSize(22, 22);
61 QTest::newRow(dataTag: "image") << QString("image.tif") << QSize(22, 22);
62 QTest::newRow(dataTag: "indexed_orientation_1") << QString("indexed_orientation_1.tiff") << QSize(64, 64);
63 QTest::newRow(dataTag: "indexed_orientation_2") << QString("indexed_orientation_2.tiff") << QSize(64, 64);
64 QTest::newRow(dataTag: "indexed_orientation_3") << QString("indexed_orientation_3.tiff") << QSize(64, 64);
65 QTest::newRow(dataTag: "indexed_orientation_4") << QString("indexed_orientation_4.tiff") << QSize(64, 64);
66 QTest::newRow(dataTag: "indexed_orientation_5") << QString("indexed_orientation_5.tiff") << QSize(64, 64);
67 QTest::newRow(dataTag: "indexed_orientation_6") << QString("indexed_orientation_6.tiff") << QSize(64, 64);
68 QTest::newRow(dataTag: "indexed_orientation_7") << QString("indexed_orientation_7.tiff") << QSize(64, 64);
69 QTest::newRow(dataTag: "indexed_orientation_8") << QString("indexed_orientation_8.tiff") << QSize(64, 64);
70 QTest::newRow(dataTag: "mono_orientation_1") << QString("mono_orientation_1.tiff") << QSize(64, 64);
71 QTest::newRow(dataTag: "mono_orientation_2") << QString("mono_orientation_2.tiff") << QSize(64, 64);
72 QTest::newRow(dataTag: "mono_orientation_3") << QString("mono_orientation_3.tiff") << QSize(64, 64);
73 QTest::newRow(dataTag: "mono_orientation_4") << QString("mono_orientation_4.tiff") << QSize(64, 64);
74 QTest::newRow(dataTag: "mono_orientation_5") << QString("mono_orientation_5.tiff") << QSize(64, 64);
75 QTest::newRow(dataTag: "mono_orientation_6") << QString("mono_orientation_6.tiff") << QSize(64, 64);
76 QTest::newRow(dataTag: "mono_orientation_7") << QString("mono_orientation_7.tiff") << QSize(64, 64);
77 QTest::newRow(dataTag: "mono_orientation_8") << QString("mono_orientation_8.tiff") << QSize(64, 64);
78 QTest::newRow(dataTag: "original_indexed") << QString("original_indexed.tiff") << QSize(64, 64);
79 QTest::newRow(dataTag: "original_mono") << QString("original_mono.tiff") << QSize(64, 64);
80 QTest::newRow(dataTag: "original_rgb") << QString("original_rgb.tiff") << QSize(64, 64);
81 QTest::newRow(dataTag: "rgba_adobedeflate_littleendian") << QString("rgba_adobedeflate_littleendian.tif") << QSize(200, 200);
82 QTest::newRow(dataTag: "rgba_lzw_littleendian") << QString("rgba_lzw_littleendian.tif") << QSize(200, 200);
83 QTest::newRow(dataTag: "rgba_nocompression_bigendian") << QString("rgba_nocompression_bigendian.tif") << QSize(200, 200);
84 QTest::newRow(dataTag: "rgba_nocompression_littleendian") << QString("rgba_nocompression_littleendian.tif") << QSize(200, 200);
85 QTest::newRow(dataTag: "rgba_packbits_littleendian") << QString("rgba_packbits_littleendian.tif") << QSize(200, 200);
86 QTest::newRow(dataTag: "rgba_zipdeflate_littleendian") << QString("rgba_zipdeflate_littleendian.tif") << QSize(200, 200);
87 QTest::newRow(dataTag: "rgb_orientation_1") << QString("rgb_orientation_1.tiff") << QSize(64, 64);
88 QTest::newRow(dataTag: "rgb_orientation_2") << QString("rgb_orientation_2.tiff") << QSize(64, 64);
89 QTest::newRow(dataTag: "rgb_orientation_3") << QString("rgb_orientation_3.tiff") << QSize(64, 64);
90 QTest::newRow(dataTag: "rgb_orientation_4") << QString("rgb_orientation_4.tiff") << QSize(64, 64);
91 QTest::newRow(dataTag: "rgb_orientation_5") << QString("rgb_orientation_5.tiff") << QSize(64, 64);
92 QTest::newRow(dataTag: "rgb_orientation_6") << QString("rgb_orientation_6.tiff") << QSize(64, 64);
93 QTest::newRow(dataTag: "rgb_orientation_7") << QString("rgb_orientation_7.tiff") << QSize(64, 64);
94 QTest::newRow(dataTag: "rgb_orientation_8") << QString("rgb_orientation_8.tiff") << QSize(64, 64);
95 QTest::newRow(dataTag: "teapot") << QString("teapot.tiff") << QSize(256, 256);
96}
97
98void tst_qtiff::readImage()
99{
100 QFETCH(QString, fileName);
101 QFETCH(QSize, size);
102
103 QString path = prefix + fileName;
104 QBENCHMARK {
105 QImageReader reader(path);
106 QVERIFY(reader.canRead());
107 QImage image = reader.read();
108 QVERIFY(!image.isNull());
109 QCOMPARE(image.size(), size);
110 }
111}
112
113void tst_qtiff::readCorruptImage_data()
114{
115 QTest::addColumn<QString>(name: "fileName");
116 QTest::addColumn<QString>(name: "message");
117
118 QTest::newRow(dataTag: "corrupt-data") << QString("corrupt-data.tif") << QString();
119}
120
121void tst_qtiff::readCorruptImage()
122{
123 QFETCH(QString, fileName);
124 QFETCH(QString, message);
125
126 QString path = prefix + fileName;
127 QBENCHMARK {
128 QImageReader reader(path);
129 if (!message.isEmpty())
130 QTest::ignoreMessage(type: QtWarningMsg, message: message.toLatin1());
131 QVERIFY(reader.canRead());
132 QImage image = reader.read();
133 QVERIFY(image.isNull());
134 }
135}
136
137QTEST_MAIN(tst_qtiff)
138#include "tst_qtiff.moc"
139

source code of qtimageformats/tests/benchmarks/tiff/tst_qtiff.cpp