1/****************************************************************************
2**
3** Copyright (C) 2018 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 <private/qtexturefilereader_p.h>
30#include <QtTest>
31
32class tst_qtexturefilereader : public QObject
33{
34 Q_OBJECT
35
36private slots:
37 void checkHandlers_data();
38 void checkHandlers();
39};
40
41void tst_qtexturefilereader::checkHandlers_data()
42{
43 QTest::addColumn<QString>(name: "fileName");
44 QTest::addColumn<QSize>(name: "size");
45 QTest::addColumn<quint32>(name: "glFormat");
46 QTest::addColumn<quint32>(name: "glInternalFormat");
47 QTest::addColumn<quint32>(name: "glBaseInternalFormat");
48 QTest::addColumn<int>(name: "levels");
49 QTest::addColumn<QList<int>>(name: "dataOffsets");
50 QTest::addColumn<QList<int>>(name: "dataLengths");
51
52 QTest::addRow(format: "pattern.pkm")
53 << QStringLiteral(":/texturefiles/pattern.pkm")
54 << QSize(64, 64)
55 << quint32(0x0)
56 << quint32(0x8d64)
57 << quint32(0x0)
58 << 1
59 << (QList<int>() << 16)
60 << (QList<int>() << 2048);
61
62 QTest::addRow(format: "car.ktx")
63 << QStringLiteral(":/texturefiles/car.ktx")
64 << QSize(146, 80)
65 << quint32(0x0)
66 << quint32(0x9278)
67 << quint32(0x1908)
68 << 1
69 << (QList<int>() << 68)
70 << (QList<int>() << 11840);
71
72 QTest::addRow(format: "car_mips.ktx")
73 << QStringLiteral(":/texturefiles/car_mips.ktx")
74 << QSize(146, 80)
75 << quint32(0x0)
76 << quint32(0x9274)
77 << quint32(0x1907)
78 << 8
79 << (QList<int>() << 68 << 5992 << 7516 << 7880 << 8004 << 8056 << 8068 << 8080)
80 << (QList<int>() << 5920 << 1520 << 360 << 120 << 48 << 8 << 8 << 8);
81
82 QTest::addRow(format: "newlogo.astc")
83 << QStringLiteral(":/texturefiles/newlogo.astc")
84 << QSize(111, 78)
85 << quint32(0x0)
86 << quint32(0x93b9)
87 << quint32(0x0)
88 << 1
89 << (QList<int>() << 16)
90 << (QList<int>() << 2496);
91
92 QTest::addRow(format: "newlogo_srgb.astc")
93 << QStringLiteral(":/texturefiles/newlogo_srgb.astc")
94 << QSize(111, 78)
95 << quint32(0x0)
96 << quint32(0x93d9)
97 << quint32(0x0)
98 << 1
99 << (QList<int>() << 16)
100 << (QList<int>() << 2496);
101}
102
103void tst_qtexturefilereader::checkHandlers()
104{
105 QFETCH(QString, fileName);
106 QFETCH(QSize, size);
107 QFETCH(quint32, glFormat);
108 QFETCH(quint32, glInternalFormat);
109 QFETCH(int, levels);
110 QFETCH(QList<int>, dataOffsets);
111 QFETCH(QList<int>, dataLengths);
112
113 QFile f(fileName);
114 QVERIFY(f.open(QIODevice::ReadOnly));
115 QTextureFileReader r(&f, fileName);
116 QVERIFY(r.canRead());
117
118 QTextureFileData tex = r.read();
119 QVERIFY(!tex.isNull());
120 QVERIFY(tex.isValid());
121 QCOMPARE(tex.size(), size);
122 QCOMPARE(tex.glFormat(), glFormat);
123 QCOMPARE(tex.glInternalFormat(), glInternalFormat);
124 QCOMPARE(tex.numLevels(), levels);
125 for (int i = 0; i < tex.numLevels(); i++) {
126 QCOMPARE(tex.dataOffset(i), dataOffsets.at(i));
127 QCOMPARE(tex.dataLength(i), dataLengths.at(i));
128 }
129}
130
131QTEST_MAIN(tst_qtexturefilereader)
132
133#include "tst_qtexturefilereader.moc"
134

source code of qtbase/tests/auto/gui/util/qtexturefilereader/tst_qtexturefilereader.cpp