Debian Codegraph @

tests/benchmarks/plugins/imageformats/jpeg/jpeg.cpp

raw
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 test suite 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 <QDebug>
30 #include <qtest.h>
31 #include <QtTest/QtTest>
32 #include <QFile>
33 #include <QByteArray>
34 #include <QBuffer>
35 #include <QImageReader>
36 #include <QSize>
37
38 class tst_jpeg : public QObject
39 {
40 Q_OBJECT
41 private slots:
42 void jpegDecodingQtWebkitStyle();
43 };
44
45 void tst_jpeg::jpegDecodingQtWebkitStyle()
46 {
47 // QtWebkit currently calls size() to get the image size for layouting purposes.
48 // Then when it is in the viewport (we assume that here) it actually gets decoded.
49 QString testFile = QFINDTESTDATA("n900.jpeg");
50 QVERIFY2(!testFile.isEmpty(), "cannot find test file n900.jpeg!");
51 QFile inputJpeg(testFile);
52 QVERIFY(inputJpeg.exists());
53 inputJpeg.open(QIODevice::ReadOnly);
54 QByteArray imageData = inputJpeg.readAll();
55 QBuffer buffer;
56 buffer.setData(imageData);
57 buffer.open(QBuffer::ReadOnly);
58 QCOMPARE(buffer.size(), qint64(19016));
59
60
61 QBENCHMARK{
62 for (int i = 0; i < 50; i++) {
63 QImageReader reader(&buffer, "jpeg");
64 QSize size = reader.size();
65 QVERIFY(!size.isNull());
66 QByteArray format = reader.format();
67 QVERIFY(!format.isEmpty());
68 QImage img = reader.read();
69 QVERIFY(!img.isNull());
70 buffer.reset();
71 }
72 }
73 }
74
75 QTEST_MAIN(tst_jpeg)
76
77 #include "jpeg.moc"