|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include <qtest.h> |
|
43 #include <QBuffer> |
|
44 #include <QDebug> |
|
45 #include <QFile> |
|
46 #include <QImage> |
|
47 #include <QImageReader> |
|
48 #include <QImageWriter> |
|
49 #include <QLabel> |
|
50 #include <QPixmap> |
|
51 #include <QSet> |
|
52 #include <QTcpSocket> |
|
53 #include <QTcpServer> |
|
54 #include <QTimer> |
|
55 |
|
56 typedef QMap<QString, QString> QStringMap; |
|
57 typedef QList<int> QIntList; |
|
58 Q_DECLARE_METATYPE(QImage) |
|
59 Q_DECLARE_METATYPE(QRect) |
|
60 Q_DECLARE_METATYPE(QSize) |
|
61 Q_DECLARE_METATYPE(QColor) |
|
62 Q_DECLARE_METATYPE(QStringMap) |
|
63 Q_DECLARE_METATYPE(QIntList) |
|
64 Q_DECLARE_METATYPE(QIODevice *) |
|
65 |
|
66 //TESTED_FILES= |
|
67 |
|
68 class tst_QImageReader : public QObject |
|
69 { |
|
70 Q_OBJECT |
|
71 |
|
72 public: |
|
73 tst_QImageReader(); |
|
74 virtual ~tst_QImageReader(); |
|
75 |
|
76 public slots: |
|
77 void init(); |
|
78 void cleanup(); |
|
79 |
|
80 private slots: |
|
81 void readImage_data(); |
|
82 void readImage(); |
|
83 |
|
84 void setScaledSize_data(); |
|
85 void setScaledSize(); |
|
86 |
|
87 void setClipRect_data(); |
|
88 void setClipRect(); |
|
89 |
|
90 void setScaledClipRect_data(); |
|
91 void setScaledClipRect(); |
|
92 |
|
93 private: |
|
94 QList< QPair<QString, QByteArray> > images; // filename, format |
|
95 }; |
|
96 |
|
97 tst_QImageReader::tst_QImageReader() |
|
98 { |
|
99 images << QPair<QString, QByteArray>(QLatin1String("colorful.bmp"), QByteArray("bmp")); |
|
100 images << QPair<QString, QByteArray>(QLatin1String("font.bmp"), QByteArray("bmp")); |
|
101 images << QPair<QString, QByteArray>(QLatin1String("crash-signed-char.bmp"), QByteArray("bmp")); |
|
102 images << QPair<QString, QByteArray>(QLatin1String("4bpp-rle.bmp"), QByteArray("bmp")); |
|
103 images << QPair<QString, QByteArray>(QLatin1String("tst7.bmp"), QByteArray("bmp")); |
|
104 images << QPair<QString, QByteArray>(QLatin1String("16bpp.bmp"), QByteArray("bmp")); |
|
105 images << QPair<QString, QByteArray>(QLatin1String("negativeheight.bmp"), QByteArray("bmp")); |
|
106 images << QPair<QString, QByteArray>(QLatin1String("marble.xpm"), QByteArray("xpm")); |
|
107 images << QPair<QString, QByteArray>(QLatin1String("kollada.png"), QByteArray("png")); |
|
108 images << QPair<QString, QByteArray>(QLatin1String("teapot.ppm"), QByteArray("ppm")); |
|
109 images << QPair<QString, QByteArray>(QLatin1String("runners.ppm"), QByteArray("ppm")); |
|
110 images << QPair<QString, QByteArray>(QLatin1String("test.ppm"), QByteArray("ppm")); |
|
111 images << QPair<QString, QByteArray>(QLatin1String("gnus.xbm"), QByteArray("xbm")); |
|
112 #if defined QTEST_HAVE_JPEG |
|
113 images << QPair<QString, QByteArray>(QLatin1String("beavis.jpg"), QByteArray("jpeg")); |
|
114 images << QPair<QString, QByteArray>(QLatin1String("YCbCr_cmyk.jpg"), QByteArray("jpeg")); |
|
115 images << QPair<QString, QByteArray>(QLatin1String("YCbCr_rgb.jpg"), QByteArray("jpeg")); |
|
116 images << QPair<QString, QByteArray>(QLatin1String("task210380.jpg"), QByteArray("jpeg")); |
|
117 #endif |
|
118 #if defined QTEST_HAVE_GIF |
|
119 images << QPair<QString, QByteArray>(QLatin1String("earth.gif"), QByteArray("gif")); |
|
120 images << QPair<QString, QByteArray>(QLatin1String("trolltech.gif"), QByteArray("gif")); |
|
121 #endif |
|
122 #if defined QTEST_HAVE_MNG |
|
123 images << QPair<QString, QByteArray>(QLatin1String("ball.mng"), QByteArray("mng")); |
|
124 images << QPair<QString, QByteArray>(QLatin1String("fire.mng"), QByteArray("mng")); |
|
125 #endif |
|
126 } |
|
127 |
|
128 tst_QImageReader::~tst_QImageReader() |
|
129 { |
|
130 } |
|
131 |
|
132 void tst_QImageReader::init() |
|
133 { |
|
134 } |
|
135 |
|
136 void tst_QImageReader::cleanup() |
|
137 { |
|
138 } |
|
139 |
|
140 void tst_QImageReader::readImage_data() |
|
141 { |
|
142 QTest::addColumn<QString>("fileName"); |
|
143 QTest::addColumn<QByteArray>("format"); |
|
144 |
|
145 for (int i = 0; i < images.size(); ++i) { |
|
146 const QString file = images[i].first; |
|
147 const QByteArray format = images[i].second; |
|
148 QTest::newRow(qPrintable(file)) << file << format; |
|
149 } |
|
150 } |
|
151 |
|
152 void tst_QImageReader::readImage() |
|
153 { |
|
154 QFETCH(QString, fileName); |
|
155 QFETCH(QByteArray, format); |
|
156 |
|
157 QBENCHMARK { |
|
158 QImageReader io("images/" + fileName, format); |
|
159 QImage image = io.read(); |
|
160 QVERIFY(!image.isNull()); |
|
161 } |
|
162 } |
|
163 |
|
164 void tst_QImageReader::setScaledSize_data() |
|
165 { |
|
166 QTest::addColumn<QString>("fileName"); |
|
167 QTest::addColumn<QByteArray>("format"); |
|
168 QTest::addColumn<QSize>("newSize"); |
|
169 |
|
170 for (int i = 0; i < images.size(); ++i) { |
|
171 const QString file = images[i].first; |
|
172 const QByteArray format = images[i].second; |
|
173 QSize size(200, 200); |
|
174 if (file == QLatin1String("teapot")) |
|
175 size = QSize(400, 400); |
|
176 else if (file == QLatin1String("test.ppm")) |
|
177 size = QSize(10, 10); |
|
178 QTest::newRow(qPrintable(file)) << file << format << size; |
|
179 } |
|
180 } |
|
181 |
|
182 void tst_QImageReader::setScaledSize() |
|
183 { |
|
184 QFETCH(QString, fileName); |
|
185 QFETCH(QSize, newSize); |
|
186 QFETCH(QByteArray, format); |
|
187 |
|
188 QBENCHMARK { |
|
189 QImageReader reader("images/" + fileName, format); |
|
190 reader.setScaledSize(newSize); |
|
191 QImage image = reader.read(); |
|
192 QCOMPARE(image.size(), newSize); |
|
193 } |
|
194 } |
|
195 |
|
196 void tst_QImageReader::setClipRect_data() |
|
197 { |
|
198 QTest::addColumn<QString>("fileName"); |
|
199 QTest::addColumn<QByteArray>("format"); |
|
200 QTest::addColumn<QRect>("newRect"); |
|
201 |
|
202 for (int i = 0; i < images.size(); ++i) { |
|
203 const QString file = images[i].first; |
|
204 const QByteArray format = images[i].second; |
|
205 QTest::newRow(qPrintable(file)) << file << format << QRect(0, 0, 50, 50); |
|
206 } |
|
207 } |
|
208 |
|
209 void tst_QImageReader::setClipRect() |
|
210 { |
|
211 QFETCH(QString, fileName); |
|
212 QFETCH(QRect, newRect); |
|
213 QFETCH(QByteArray, format); |
|
214 |
|
215 QBENCHMARK { |
|
216 QImageReader reader("images/" + fileName, format); |
|
217 reader.setClipRect(newRect); |
|
218 QImage image = reader.read(); |
|
219 QCOMPARE(image.rect(), newRect); |
|
220 } |
|
221 } |
|
222 |
|
223 void tst_QImageReader::setScaledClipRect_data() |
|
224 { |
|
225 setClipRect_data(); |
|
226 } |
|
227 |
|
228 void tst_QImageReader::setScaledClipRect() |
|
229 { |
|
230 QFETCH(QString, fileName); |
|
231 QFETCH(QRect, newRect); |
|
232 QFETCH(QByteArray, format); |
|
233 |
|
234 QBENCHMARK { |
|
235 QImageReader reader("images/" + fileName, format); |
|
236 reader.setScaledSize(QSize(300, 300)); |
|
237 reader.setScaledClipRect(newRect); |
|
238 QImage image = reader.read(); |
|
239 QCOMPARE(image.rect(), newRect); |
|
240 } |
|
241 } |
|
242 |
|
243 QTEST_MAIN(tst_QImageReader) |
|
244 #include "tst_qimagereader.moc" |