2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the test suite of the Qt Toolkit.
|
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
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
|
2015-01-28 08:44:43 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-15 12:36:27 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2012-09-19 12:28:29 +00:00
|
|
|
**
|
2016-01-15 12:36:27 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** $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());
|
2016-07-27 13:45:31 +00:00
|
|
|
void runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat = QSurfaceFormat());
|
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();
|
2016-12-01 11:33:29 +00:00
|
|
|
void testRasterARGB32_data();
|
|
|
|
void testRasterARGB32();
|
2011-04-27 10:05:43 +00:00
|
|
|
void testRasterRGB16_data();
|
|
|
|
void testRasterRGB16();
|
2016-08-03 11:27:38 +00:00
|
|
|
void testRasterA2RGB30PM_data();
|
|
|
|
void testRasterA2RGB30PM();
|
|
|
|
void testRasterBGR30_data();
|
|
|
|
void testRasterBGR30();
|
2016-09-19 08:41:57 +00:00
|
|
|
void testRasterARGB8565PM_data();
|
|
|
|
void testRasterARGB8565PM();
|
|
|
|
void testRasterGrayscale8_data();
|
|
|
|
void testRasterGrayscale8();
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
#ifndef QT_NO_OPENGL
|
|
|
|
void testOpenGL_data();
|
|
|
|
void testOpenGL();
|
2016-07-27 13:45:31 +00:00
|
|
|
void testCoreOpenGL_data();
|
|
|
|
void testCoreOpenGL();
|
2012-10-29 09:34:20 +00:00
|
|
|
private:
|
|
|
|
bool checkSystemGLSupport();
|
2016-07-27 13:45:31 +00:00
|
|
|
bool checkSystemCoreGLSupport();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-01 11:33:29 +00:00
|
|
|
void tst_Lancelot::testRasterARGB32_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB32()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_ARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-03 11:27:38 +00:00
|
|
|
void tst_Lancelot::testRasterA2RGB30PM_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterA2RGB30PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_A2RGB30_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterBGR30_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterBGR30()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_BGR30);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-19 08:41:57 +00:00
|
|
|
void tst_Lancelot::testRasterARGB8565PM_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterARGB8565PM()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_ARGB8565_Premultiplied);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterGrayscale8_data()
|
|
|
|
{
|
|
|
|
setupTestSuite();
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testRasterGrayscale8()
|
|
|
|
{
|
|
|
|
runTestSuite(Raster, QImage::Format_Grayscale8);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2016-07-27 13:45:31 +00:00
|
|
|
bool tst_Lancelot::checkSystemCoreGLSupport()
|
|
|
|
{
|
|
|
|
if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
QSurfaceFormat coreFormat;
|
|
|
|
coreFormat.setVersion(3, 2);
|
|
|
|
coreFormat.setProfile(QSurfaceFormat::CoreProfile);
|
|
|
|
QWindow win;
|
|
|
|
win.setSurfaceType(QSurface::OpenGLSurface);
|
|
|
|
win.setFormat(coreFormat);
|
|
|
|
win.create();
|
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QOpenGLContext ctx;
|
|
|
|
ctx.setFormat(coreFormat);
|
|
|
|
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
|
|
|
}
|
2016-07-27 13:45:31 +00:00
|
|
|
|
|
|
|
void tst_Lancelot::testCoreOpenGL_data()
|
|
|
|
{
|
|
|
|
if (!checkSystemCoreGLSupport())
|
|
|
|
QSKIP("System under test does not meet preconditions for Core Profile GL testing. Skipping.");
|
|
|
|
QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
|
|
|
|
setupTestSuite(localBlacklist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tst_Lancelot::testCoreOpenGL()
|
|
|
|
{
|
|
|
|
QSurfaceFormat coreFormat;
|
|
|
|
coreFormat.setVersion(3, 2);
|
|
|
|
coreFormat.setProfile(QSurfaceFormat::CoreProfile);
|
|
|
|
runTestSuite(OpenGL, QImage::Format_RGB32, coreFormat);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-07-27 13:45:31 +00:00
|
|
|
void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
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);
|
2016-07-27 13:45:31 +00:00
|
|
|
win.setFormat(contextFormat);
|
2012-10-29 09:34:20 +00:00
|
|
|
win.create();
|
|
|
|
QOpenGLFramebufferObjectFormat fmt;
|
|
|
|
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
|
|
|
fmt.setSamples(4);
|
|
|
|
QOpenGLContext ctx;
|
2016-07-27 13:45:31 +00:00
|
|
|
ctx.setFormat(contextFormat);
|
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:
|
2016-07-27 13:45:31 +00:00
|
|
|
pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
|
2012-10-29 09:34:20 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2015-09-21 13:53:49 +00:00
|
|
|
qSetGlobalQHashSeed(0); // Avoid rendering variations caused by QHash randomization
|
2012-10-29 09:34:20 +00:00
|
|
|
|
|
|
|
QBaselineTest::handleCmdLineArgs(&argc, &argv);
|
|
|
|
return _realmain(argc, argv);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "tst_lancelot.moc"
|