2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2014-08-21 13:51:22 +00:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-09-19 12:28:29 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2014-08-21 13:51:22 +00:00
|
|
|
** $QT_BEGIN_LICENSE:LGPL21$
|
2012-09-19 12:28:29 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2014-08-21 13:51:22 +00:00
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
2012-09-19 12:28:29 +00:00
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-09-19 12:28:29 +00:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-08-21 13:51:22 +00:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
2014-08-21 13:51:22 +00:00
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-04-27 10:05:43 +00:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-08-31 11:24:37 +00:00
|
|
|
#include "paintcommands.h"
|
2012-10-29 09:34:20 +00:00
|
|
|
#include <qbaselinetest.h>
|
|
|
|
#include <QDir>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QPainter>
|
|
|
|
|
|
|
|
#ifndef QT_NO_OPENGL
|
2012-10-29 09:34:20 +00:00
|
|
|
#include <QOpenGLFramebufferObjectFormat>
|
|
|
|
#include <QOpenGLContext>
|
|
|
|
#include <QOpenGLPaintDevice>
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-18 08:33:36 +00:00
|
|
|
#include <algorithm>
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
class tst_Lancelot : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
tst_Lancelot();
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum GraphicsEngine {
|
|
|
|
Raster = 0,
|
|
|
|
OpenGL = 1
|
|
|
|
};
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
void setupTestSuite(const QStringList& blacklist = QStringList());
|
2011-04-27 10:05:43 +00:00
|
|
|
void runTestSuite(GraphicsEngine engine, QImage::Format format);
|
2012-10-29 09:34:20 +00:00
|
|
|
void paint(QPaintDevice *device, GraphicsEngine engine, const QStringList &script, const QString &filePath);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QStringList qpsFiles;
|
2011-04-27 10:05:43 +00:00
|
|
|
QHash<QString, QStringList> scripts;
|
2012-10-29 09:34:20 +00:00
|
|
|
QHash<QString, quint16> scriptChecksums;
|
2011-04-27 10:05:43 +00:00
|
|
|
QString scriptsDir;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void initTestCase();
|
|
|
|
void cleanupTestCase() {}
|
|
|
|
|
|
|
|
void testRasterARGB32PM_data();
|
|
|
|
void testRasterARGB32PM();
|
|
|
|
void testRasterRGB32_data();
|
|
|
|
void testRasterRGB32();
|
|
|
|
void testRasterRGB16_data();
|
|
|
|
void testRasterRGB16();
|
|
|
|
|
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
void testOpenGL_data();
|
|
|
|
void testOpenGL();
|
2012-10-29 09:34:20 +00:00
|
|
|
private:
|
|
|
|
bool checkSystemGLSupport();
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
tst_Lancelot::tst_Lancelot()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::initTestCase()
|
|
|
|
{
|
|
|
|
// Check and setup the environment. We treat failures because of test environment
|
|
|
|
// (e.g. script files not found) as just warnings, and not QFAILs, to avoid false negatives
|
|
|
|
// caused by environment or server instability
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QByteArray msg;
|
|
|
|
if (!QBaselineTest::connectToBaselineServer(&msg))
|
|
|
|
QSKIP(msg);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-01-04 02:28:20 +00:00
|
|
|
QString baseDir = QFINDTESTDATA("scripts/text.qps");
|
|
|
|
scriptsDir = baseDir.left(baseDir.lastIndexOf('/')) + '/';
|
2011-04-27 10:05:43 +00:00
|
|
|
QDir qpsDir(scriptsDir);
|
2012-10-29 09:34:20 +00:00
|
|
|
qpsFiles = qpsDir.entryList(QStringList() << QLatin1String("*.qps"), QDir::Files | QDir::Readable);
|
|
|
|
if (qpsFiles.isEmpty()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QWARN("No qps script files found in " + qpsDir.path().toLatin1());
|
2011-10-19 02:53:13 +00:00
|
|
|
QSKIP("Aborted due to errors.");
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 08:33:36 +00:00
|
|
|
std::sort(qpsFiles.begin(), qpsFiles.end());
|
2012-10-29 09:34:20 +00:00
|
|
|
foreach (const QString& fileName, qpsFiles) {
|
2011-04-27 10:05:43 +00:00
|
|
|
QFile file(scriptsDir + fileName);
|
|
|
|
file.open(QFile::ReadOnly);
|
|
|
|
QByteArray cont = file.readAll();
|
2012-03-19 12:46:47 +00:00
|
|
|
scripts.insert(fileName, QString::fromUtf8(cont).split(QLatin1Char('\n'), QString::SkipEmptyParts));
|
2012-10-29 09:34:20 +00:00
|
|
|
scriptChecksums.insert(fileName, qChecksum(cont.constData(), cont.size()));
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB32PM_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB32PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB32_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB32()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB16_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite();
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterRGB16()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_RGB16);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef QT_NO_OPENGL
|
2012-10-29 09:34:20 +00:00
|
|
|
bool tst_Lancelot::checkSystemGLSupport()
|
|
|
|
{
|
|
|
|
QWindow win;
|
|
|
|
win.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
win.create();
|
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QOpenGLContext ctx;
|
|
|
|
if (!ctx.create() || !ctx.makeCurrent(&win))
|
|
|
|
return false;
|
|
|
|
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
|
|
|
if (!fbo.isValid() || !fbo.bind())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_Lancelot::testOpenGL_data()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
if (!checkSystemGLSupport())
|
|
|
|
QSKIP("System under test does not meet preconditions for GL testing. Skipping.");
|
2011-04-27 10:05:43 +00:00
|
|
|
QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
|
2012-10-29 09:34:20 +00:00
|
|
|
setupTestSuite(localBlacklist);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testOpenGL()
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
runTestSuite(OpenGL, QImage::Format_RGB32);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
void tst_Lancelot::setupTestSuite(const QStringList& blacklist)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
QTest::addColumn<QString>("qpsFile");
|
|
|
|
foreach (const QString &fileName, qpsFiles) {
|
|
|
|
if (blacklist.contains(fileName))
|
|
|
|
continue;
|
|
|
|
QBaselineTest::newRow(fileName.toLatin1(), scriptChecksums.value(fileName)) << fileName;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format)
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
QFETCH(QString, qpsFile);
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QString filePath = scriptsDir + qpsFile;
|
|
|
|
QStringList script = scripts.value(qpsFile);
|
|
|
|
QImage rendered;
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
if (engine == Raster) {
|
|
|
|
QImage img(800, 800, format);
|
2012-10-29 09:34:20 +00:00
|
|
|
paint(&img, engine, script, QFileInfo(filePath).absoluteFilePath());
|
|
|
|
rendered = img;
|
2011-04-27 10:05:43 +00:00
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
} else if (engine == OpenGL) {
|
2012-10-29 09:34:20 +00:00
|
|
|
QWindow win;
|
|
|
|
win.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
win.create();
|
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QOpenGLContext ctx;
|
2013-09-30 12:07:24 +00:00
|
|
|
QVERIFY(ctx.create());
|
|
|
|
QVERIFY(ctx.makeCurrent(&win));
|
2012-10-29 09:34:20 +00:00
|
|
|
QOpenGLFramebufferObject fbo(800, 800, fmt);
|
|
|
|
fbo.bind();
|
|
|
|
QOpenGLPaintDevice pdv(800, 800);
|
|
|
|
paint(&pdv, engine, script, QFileInfo(filePath).absoluteFilePath());
|
|
|
|
rendered = fbo.toImage().convertToFormat(format);
|
2011-04-27 10:05:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QBASELINE_TEST(rendered);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
void tst_Lancelot::paint(QPaintDevice *device, GraphicsEngine engine, const QStringList &script, const QString &filePath)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
QPainter p(device);
|
|
|
|
PaintCommands pcmd(script, 800, 800);
|
|
|
|
//pcmd.setShouldDrawText(false);
|
2012-10-29 09:34:20 +00:00
|
|
|
switch (engine) {
|
|
|
|
case OpenGL:
|
|
|
|
pcmd.setType(OpenGLBufferType);
|
|
|
|
break;
|
|
|
|
case Raster: // fallthrough
|
|
|
|
default:
|
|
|
|
pcmd.setType(ImageType);
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
pcmd.setPainter(&p);
|
|
|
|
pcmd.setFilePath(filePath);
|
|
|
|
pcmd.runCommands();
|
|
|
|
p.end();
|
|
|
|
}
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
#define main _realmain
|
2011-04-27 10:05:43 +00:00
|
|
|
QTEST_MAIN(tst_Lancelot)
|
|
|
|
#undef main
|
|
|
|
|
2012-10-29 09:34:20 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
extern Q_DECL_IMPORT QBasicAtomicInt qt_qhash_seed; // from qhash.cpp
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2012-10-29 09:34:20 +00:00
|
|
|
qt_qhash_seed.store(0); // Avoid rendering variations caused by QHash randomization
|
|
|
|
|
|
|
|
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
|
|
|
return _realmain(argc, argv);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "tst_lancelot.moc"
|