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$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
#include "baselineprotocol.h"
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QBuffer>
|
|
|
|
#include <QHostInfo>
|
|
|
|
#include <QSysInfo>
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
|
|
|
# include <QProcess>
|
|
|
|
#endif
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QTime>
|
|
|
|
#include <QPointer>
|
2018-09-26 22:19:49 +00:00
|
|
|
#include <QRegExp>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2012-08-13 12:13:40 +00:00
|
|
|
const QString PI_Project(QLS("Project"));
|
2011-04-27 10:05:43 +00:00
|
|
|
const QString PI_TestCase(QLS("TestCase"));
|
|
|
|
const QString PI_HostName(QLS("HostName"));
|
|
|
|
const QString PI_HostAddress(QLS("HostAddress"));
|
|
|
|
const QString PI_OSName(QLS("OSName"));
|
|
|
|
const QString PI_OSVersion(QLS("OSVersion"));
|
|
|
|
const QString PI_QtVersion(QLS("QtVersion"));
|
2011-11-11 11:46:24 +00:00
|
|
|
const QString PI_QtBuildMode(QLS("QtBuildMode"));
|
2011-04-27 10:05:43 +00:00
|
|
|
const QString PI_GitCommit(QLS("GitCommit"));
|
|
|
|
const QString PI_QMakeSpec(QLS("QMakeSpec"));
|
|
|
|
const QString PI_PulseGitBranch(QLS("PulseGitBranch"));
|
|
|
|
const QString PI_PulseTestrBranch(QLS("PulseTestrBranch"));
|
|
|
|
|
|
|
|
#ifndef QMAKESPEC
|
|
|
|
#define QMAKESPEC "Unknown"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <QtCore/qt_windows.h>
|
|
|
|
#endif
|
|
|
|
#if defined(Q_OS_UNIX)
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
void BaselineProtocol::sysSleep(int ms)
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN)
|
2013-09-01 16:05:46 +00:00
|
|
|
# ifndef Q_OS_WINRT
|
2011-04-27 10:05:43 +00:00
|
|
|
Sleep(DWORD(ms));
|
2013-09-01 16:05:46 +00:00
|
|
|
# else
|
|
|
|
WaitForSingleObjectEx(GetCurrentThread(), ms, false);
|
|
|
|
# endif
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
|
|
|
struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 };
|
|
|
|
nanosleep(&ts, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
PlatformInfo::PlatformInfo()
|
2011-09-01 12:50:59 +00:00
|
|
|
: QMap<QString, QString>(), adHoc(true)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
PlatformInfo PlatformInfo::localHostInfo()
|
|
|
|
{
|
|
|
|
PlatformInfo pi;
|
|
|
|
pi.insert(PI_HostName, QHostInfo::localHostName());
|
|
|
|
pi.insert(PI_QtVersion, QLS(qVersion()));
|
|
|
|
pi.insert(PI_QMakeSpec, QString(QLS(QMAKESPEC)).remove(QRegExp(QLS("^.*mkspecs/"))));
|
2011-11-11 11:46:24 +00:00
|
|
|
#if QT_VERSION >= 0x050000
|
|
|
|
pi.insert(PI_QtBuildMode, QLibraryInfo::isDebugBuild() ? QLS("QtDebug") : QLS("QtRelease"));
|
|
|
|
#endif
|
2016-11-23 11:25:17 +00:00
|
|
|
#if defined(Q_OS_LINUX) && QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
pi.insert(PI_OSName, QLS("Linux"));
|
|
|
|
#elif defined(Q_OS_WIN)
|
|
|
|
pi.insert(PI_OSName, QLS("Windows"));
|
2016-09-09 18:21:29 +00:00
|
|
|
#elif defined(Q_OS_DARWIN)
|
|
|
|
pi.insert(PI_OSName, QLS("Darwin"));
|
2011-04-27 10:05:43 +00:00
|
|
|
#else
|
|
|
|
pi.insert(PI_OSName, QLS("Other"));
|
|
|
|
#endif
|
2016-09-09 18:21:29 +00:00
|
|
|
pi.insert(PI_OSVersion, QSysInfo::kernelVersion());
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2016-11-23 11:25:17 +00:00
|
|
|
#if QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
QProcess git;
|
|
|
|
QString cmd;
|
|
|
|
QStringList args;
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
cmd = QLS("cmd.exe");
|
|
|
|
args << QLS("/c") << QLS("git");
|
|
|
|
#else
|
|
|
|
cmd = QLS("git");
|
|
|
|
#endif
|
|
|
|
args << QLS("log") << QLS("--max-count=1") << QLS("--pretty=%H [%an] [%ad] %s");
|
|
|
|
git.start(cmd, args);
|
|
|
|
git.waitForFinished(3000);
|
|
|
|
if (!git.exitCode())
|
|
|
|
pi.insert(PI_GitCommit, QString::fromLocal8Bit(git.readAllStandardOutput().constData()).simplified());
|
|
|
|
else
|
|
|
|
pi.insert(PI_GitCommit, QLS("Unknown"));
|
|
|
|
|
|
|
|
QByteArray gb = qgetenv("PULSE_GIT_BRANCH");
|
2011-09-01 12:50:59 +00:00
|
|
|
if (!gb.isEmpty()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
pi.insert(PI_PulseGitBranch, QString::fromLatin1(gb));
|
2011-09-01 12:50:59 +00:00
|
|
|
pi.setAdHocRun(false);
|
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
QByteArray tb = qgetenv("PULSE_TESTR_BRANCH");
|
2011-09-01 12:50:59 +00:00
|
|
|
if (!tb.isEmpty()) {
|
2011-04-27 10:05:43 +00:00
|
|
|
pi.insert(PI_PulseTestrBranch, QString::fromLatin1(tb));
|
2011-09-01 12:50:59 +00:00
|
|
|
pi.setAdHocRun(false);
|
|
|
|
}
|
2012-08-06 04:19:25 +00:00
|
|
|
if (!qgetenv("JENKINS_HOME").isEmpty()) {
|
|
|
|
pi.setAdHocRun(false);
|
|
|
|
gb = qgetenv("GIT_BRANCH");
|
|
|
|
if (!gb.isEmpty()) {
|
|
|
|
// FIXME: the string "Pulse" should be eliminated, since that is not the used tool.
|
|
|
|
pi.insert(PI_PulseGitBranch, QString::fromLatin1(gb));
|
|
|
|
}
|
|
|
|
}
|
2016-11-23 11:25:17 +00:00
|
|
|
#endif // QT_CONFIG(process)
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PlatformInfo::PlatformInfo(const PlatformInfo &other)
|
|
|
|
: QMap<QString, QString>(other)
|
|
|
|
{
|
2011-09-01 12:50:59 +00:00
|
|
|
orides = other.orides;
|
|
|
|
adHoc = other.adHoc;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PlatformInfo &PlatformInfo::operator=(const PlatformInfo &other)
|
|
|
|
{
|
|
|
|
QMap<QString, QString>::operator=(other);
|
2011-09-01 12:50:59 +00:00
|
|
|
orides = other.orides;
|
|
|
|
adHoc = other.adHoc;
|
2011-04-27 10:05:43 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 12:50:59 +00:00
|
|
|
void PlatformInfo::addOverride(const QString& key, const QString& value)
|
|
|
|
{
|
|
|
|
orides.append(key);
|
|
|
|
orides.append(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QStringList PlatformInfo::overrides() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-09-01 12:50:59 +00:00
|
|
|
return orides;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 12:50:59 +00:00
|
|
|
void PlatformInfo::setAdHocRun(bool isAdHoc)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-09-01 12:50:59 +00:00
|
|
|
adHoc = isAdHoc;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 12:50:59 +00:00
|
|
|
bool PlatformInfo::isAdHocRun() const
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
2011-09-01 12:50:59 +00:00
|
|
|
return adHoc;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QDataStream & operator<< (QDataStream &stream, const PlatformInfo &pi)
|
|
|
|
{
|
|
|
|
stream << static_cast<const QMap<QString, QString>&>(pi);
|
2011-09-01 12:50:59 +00:00
|
|
|
stream << pi.orides << pi.adHoc;
|
2011-04-27 10:05:43 +00:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QDataStream & operator>> (QDataStream &stream, PlatformInfo &pi)
|
|
|
|
{
|
|
|
|
stream >> static_cast<QMap<QString, QString>&>(pi);
|
2011-09-01 12:50:59 +00:00
|
|
|
stream >> pi.orides >> pi.adHoc;
|
2011-04-27 10:05:43 +00:00
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ImageItem &ImageItem::operator=(const ImageItem &other)
|
|
|
|
{
|
|
|
|
testFunction = other.testFunction;
|
|
|
|
itemName = other.itemName;
|
|
|
|
itemChecksum = other.itemChecksum;
|
|
|
|
status = other.status;
|
|
|
|
image = other.image;
|
|
|
|
imageChecksums = other.imageChecksums;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Defined in lookup3.c:
|
|
|
|
void hashword2 (
|
|
|
|
const quint32 *k, /* the key, an array of quint32 values */
|
|
|
|
size_t length, /* the length of the key, in quint32s */
|
|
|
|
quint32 *pc, /* IN: seed OUT: primary hash value */
|
|
|
|
quint32 *pb); /* IN: more seed OUT: secondary hash value */
|
|
|
|
|
|
|
|
quint64 ImageItem::computeChecksum(const QImage &image)
|
|
|
|
{
|
|
|
|
QImage img(image);
|
|
|
|
const int bpl = img.bytesPerLine();
|
|
|
|
const int padBytes = bpl - (img.width() * img.depth() / 8);
|
|
|
|
if (padBytes) {
|
|
|
|
uchar *p = img.bits() + bpl - padBytes;
|
|
|
|
const int h = img.height();
|
|
|
|
for (int y = 0; y < h; ++y) {
|
2012-04-06 14:34:19 +00:00
|
|
|
memset(p, 0, padBytes);
|
2011-04-27 10:05:43 +00:00
|
|
|
p += bpl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
quint32 h1 = 0xfeedbacc;
|
|
|
|
quint32 h2 = 0x21604894;
|
2016-11-11 12:05:13 +00:00
|
|
|
hashword2((const quint32 *)img.constBits(), img.sizeInBytes()/4, &h1, &h2);
|
2011-04-27 10:05:43 +00:00
|
|
|
return (quint64(h1) << 32) | h2;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
QString ImageItem::engineAsString() const
|
|
|
|
{
|
|
|
|
switch (engine) {
|
|
|
|
case Raster:
|
|
|
|
return QLS("Raster");
|
|
|
|
break;
|
|
|
|
case OpenGL:
|
|
|
|
return QLS("OpenGL");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QLS("Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ImageItem::formatAsString() const
|
|
|
|
{
|
|
|
|
static const int numFormats = 16;
|
|
|
|
static const char *formatNames[numFormats] = {
|
|
|
|
"Invalid",
|
|
|
|
"Mono",
|
|
|
|
"MonoLSB",
|
|
|
|
"Indexed8",
|
|
|
|
"RGB32",
|
|
|
|
"ARGB32",
|
|
|
|
"ARGB32-Premult",
|
|
|
|
"RGB16",
|
|
|
|
"ARGB8565-Premult",
|
|
|
|
"RGB666",
|
|
|
|
"ARGB6666-Premult",
|
|
|
|
"RGB555",
|
|
|
|
"ARGB8555-Premult",
|
|
|
|
"RGB888",
|
|
|
|
"RGB444",
|
|
|
|
"ARGB4444-Premult"
|
|
|
|
};
|
|
|
|
if (renderFormat < 0 || renderFormat >= numFormats)
|
|
|
|
return QLS("UnknownFormat");
|
|
|
|
return QLS(formatNames[renderFormat]);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void ImageItem::writeImageToStream(QDataStream &out) const
|
|
|
|
{
|
|
|
|
if (image.isNull() || image.format() == QImage::Format_Invalid) {
|
|
|
|
out << quint8(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
out << quint8('Q') << quint8(image.format());
|
|
|
|
out << quint8(QSysInfo::ByteOrder) << quint8(0); // pad to multiple of 4 bytes
|
|
|
|
out << quint32(image.width()) << quint32(image.height()) << quint32(image.bytesPerLine());
|
Tests: Fix some warnings about deprecated functions not under test
Fix warnings like:
baselineserver/shared/baselineprotocol.cpp:295:72: warning: ‘int QImage::byteCount() const’ is deprecated: Use sizeInBytes [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:1560:17: warning: ‘static QList<QSslCertificate> QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:1560:39: warning: ‘static QList<QSslCertificate> QSslSocket::defaultCaCertificates()’ is deprecated [-Wdeprecated-declarations]
tst_qnetworkreply.cpp:8153:60: warning: ‘T* QWeakPointer<T>::data() const [with T = const QNetworkSession]’ is deprecated: Use toStrongRef() instead, and data() on the returned QSharedPointer [-Wdeprecated-declarations].
...
st_qprinter.cpp:1318:74: warning: ‘QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations]
tst_qprinter.cpp:1362:74: warning: ‘QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const’ is deprecated [-Wdeprecated-declarations]
tst_largefile.cpp:492:85: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations]
tst_largefile.cpp:498:91: warning: ‘bool qEqual(InputIterator1, InputIterator1, InputIterator2) [with InputIterator1 = char*; InputIterator2 = char*]’ is deprecated: Use std::equal [-Wdeprecated-declarations]
tst_qabstractitemmodel.cpp:312:25: warning: ‘void QAbstractItemModel::reset()’ is deprecated [-Wdeprecated-declarations]
...
tst_qabstractitemmodel.cpp:1793:28: warning: ‘void QAbstractItemModel::setRoleNames(const QHash<int, QByteArray>&)’ is deprecated [-Wdeprecated-declarations]
...
tst_qcolor.cpp:1425:33: warning: ‘QColor QColor::light(int) const’ is deprecated: Use QColor::lighter() instead [-Wdeprecated-declarations]
tst_qcolor.cpp:1432:31: warning: ‘QColor QColor::dark(int) const’ is deprecated: Use QColor::darker() instead [-Wdeprecated-declarations]
tst_qprinterinfo.cpp:303:61: warning: 'QList<QPagedPaintDevice::PageSize> QPrinterInfo::supportedPaperSizes() const' is deprecated [-Wdeprecated-declarations]
tst_qprinterinfo.cpp:304:65: warning: 'QList<QPair<QString, QSizeF> > QPrinterInfo::supportedSizesWithNames() const' is deprecated [-Wdeprecated-declarations]
tst_qtextdocumentfragment.cpp:947:52: warning: ‘QString QTextCharFormat::anchorName() const’ is deprecated: Use anchorNames() instead [-Wdeprecated-declarations]
tst_qtextlayout.cpp:2261:61: warning: ‘void QTextLayout::setAdditionalFormats(const QList<QTextLayout::FormatRange>&)’ is deprecated: Use setFormats() [-Wdeprecated-declarations]
tst_qtextlayout.cpp:2330:42: warning: ‘int QFontMetrics::width(const QString&, int) const’ is deprecated: Use QFontMetrics::horizontalAdvance [-Wdeprecated-declarations]
tst_qitemselectionmodel.cpp:2214:37: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations]
...
tst_qtextlist.cpp:317:68: warning: 'bool QTextList::isEmpty() const' is deprecated: Use count() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:373:32: warning: ‘void QPainter::setMatrixEnabled(bool)’ is deprecated: Use setWorldMatrixEnabled() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:374:40: warning: ‘bool QPainter::matrixEnabled() const’ is deprecated: Use worldMatrixEnabled() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:702:45: warning: ‘const QBrush& QPalette::background() const’ is deprecated: Use QPalette::window() instead [-Wdeprecated-declarations]
tst_qpainter.cpp:1573:29: warning: ‘void QPainter::drawRoundRect(const QRect&, int, int)’ is deprecated: Use drawRoundedRect(..., Qt::RelativeSize) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:76:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:81:41: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:105:30: warning: ‘virtual void QPdfWriter::setMargins(const QPagedPaintDevice::Margins&)’ is deprecated: Use setPageMargins(QMarginsF(l, t, r, b), QPageLayout::Millimeter) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:172:37: warning: ‘virtual void QPdfWriter::setPageSizeMM(const QSizeF&)’ is deprecated: Use setPageSize(QPageSize(size, QPageSize::Millimeter)) instead [-Wdeprecated-declarations]
tst_qpdfwriter.cpp:258:38: warning: ‘virtual void QPdfWriter::setPageSize(QPagedPaintDevice::PageSize)’ is deprecated: Use setPageSize(QPageSize(id)) instead [-Wdeprecated-declarations]
qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp:3980:54: warning: ‘QModelIndex QModelIndex::child(int, int) const’ is deprecated: Use QAbstractItemModel::index [-Wdeprecated-declarations]
tst_qlocale.cpp:434:26: warning: 'QString::null' is deprecated: use QString() [-Wdeprecated-declarations]
...
Change-Id: I77c1a934b27119eedeb26a77c913686314a2a5c7
Reviewed-by: David Faure <david.faure@kdab.com>
2019-05-23 11:55:23 +00:00
|
|
|
out << qCompress(reinterpret_cast<const uchar *>(image.constBits()),
|
|
|
|
int(image.sizeInBytes()));
|
2011-04-27 10:05:43 +00:00
|
|
|
//# can be followed by colormap for formats that use it
|
|
|
|
}
|
|
|
|
|
|
|
|
void ImageItem::readImageFromStream(QDataStream &in)
|
|
|
|
{
|
|
|
|
quint8 hdr, fmt, endian, pad;
|
|
|
|
quint32 width, height, bpl;
|
|
|
|
QByteArray data;
|
|
|
|
|
|
|
|
in >> hdr;
|
|
|
|
if (hdr != 'Q') {
|
|
|
|
image = QImage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in >> fmt >> endian >> pad;
|
|
|
|
if (!fmt || fmt >= QImage::NImageFormats) {
|
|
|
|
image = QImage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (endian != QSysInfo::ByteOrder) {
|
|
|
|
qWarning("ImageItem cannot read streamed image with different endianness");
|
|
|
|
image = QImage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in >> width >> height >> bpl;
|
|
|
|
in >> data;
|
|
|
|
data = qUncompress(data);
|
|
|
|
QImage res((const uchar *)data.constData(), width, height, bpl, QImage::Format(fmt));
|
|
|
|
image = res.copy(); //# yuck, seems there is currently no way to avoid data copy
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream & operator<< (QDataStream &stream, const ImageItem &ii)
|
|
|
|
{
|
|
|
|
stream << ii.testFunction << ii.itemName << ii.itemChecksum << quint8(ii.status) << ii.imageChecksums << ii.misc;
|
|
|
|
ii.writeImageToStream(stream);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDataStream & operator>> (QDataStream &stream, ImageItem &ii)
|
|
|
|
{
|
|
|
|
quint8 encStatus;
|
|
|
|
stream >> ii.testFunction >> ii.itemName >> ii.itemChecksum >> encStatus >> ii.imageChecksums >> ii.misc;
|
|
|
|
ii.status = ImageItem::ItemStatus(encStatus);
|
|
|
|
ii.readImageFromStream(stream);
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaselineProtocol::BaselineProtocol()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
BaselineProtocol::~BaselineProtocol()
|
2012-08-13 12:13:40 +00:00
|
|
|
{
|
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BaselineProtocol::disconnect()
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
socket.close();
|
2012-08-13 12:13:40 +00:00
|
|
|
return (socket.state() == QTcpSocket::UnconnectedState) ? true : socket.waitForDisconnected(Timeout);
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-01 12:50:59 +00:00
|
|
|
bool BaselineProtocol::connect(const QString &testCase, bool *dryrun, const PlatformInfo& clientInfo)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
errMsg.clear();
|
|
|
|
QByteArray serverName(qgetenv("QT_LANCELOT_SERVER"));
|
|
|
|
if (serverName.isNull())
|
2013-01-29 23:58:55 +00:00
|
|
|
serverName = "lancelot.test.qt-project.org";
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
socket.connectToHost(serverName, ServerPort);
|
|
|
|
if (!socket.waitForConnected(Timeout)) {
|
2012-08-13 12:13:40 +00:00
|
|
|
sysSleep(3000); // Wait a bit and try again, the server might just be restarting
|
2011-04-27 10:05:43 +00:00
|
|
|
if (!socket.waitForConnected(Timeout)) {
|
2019-03-06 10:27:17 +00:00
|
|
|
errMsg += QLS("TCP connectToHost failed. Host:") + QLS(serverName) + QLS(" port:") + QString::number(ServerPort);
|
2011-04-27 10:05:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-01 12:50:59 +00:00
|
|
|
PlatformInfo pi = clientInfo.isEmpty() ? PlatformInfo::localHostInfo() : clientInfo;
|
2011-04-27 10:05:43 +00:00
|
|
|
pi.insert(PI_TestCase, testCase);
|
|
|
|
QByteArray block;
|
|
|
|
QDataStream ds(&block, QIODevice::ReadWrite);
|
|
|
|
ds << pi;
|
|
|
|
if (!sendBlock(AcceptPlatformInfo, block)) {
|
|
|
|
errMsg += QLS("Failed to send data to server.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command cmd = UnknownError;
|
|
|
|
if (!receiveBlock(&cmd, &block)) {
|
2011-04-11 13:34:06 +00:00
|
|
|
errMsg.prepend(QLS("Failed to get response from server. "));
|
2011-04-27 10:05:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmd == Abort) {
|
|
|
|
errMsg += QLS("Server rejected connection. Reason: ") + QString::fromLatin1(block);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dryrun)
|
|
|
|
*dryrun = (cmd == DoDryRun);
|
|
|
|
|
|
|
|
if (cmd != Ack && cmd != DoDryRun) {
|
|
|
|
errMsg += QLS("Unexpected response from server.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BaselineProtocol::acceptConnection(PlatformInfo *pi)
|
|
|
|
{
|
|
|
|
errMsg.clear();
|
|
|
|
|
|
|
|
QByteArray block;
|
|
|
|
Command cmd = AcceptPlatformInfo;
|
|
|
|
if (!receiveBlock(&cmd, &block) || cmd != AcceptPlatformInfo)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (pi) {
|
|
|
|
QDataStream ds(block);
|
|
|
|
ds >> *pi;
|
|
|
|
pi->insert(PI_HostAddress, socket.peerAddress().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BaselineProtocol::requestBaselineChecksums(const QString &testFunction, ImageItemList *itemList)
|
|
|
|
{
|
|
|
|
errMsg.clear();
|
|
|
|
if (!itemList)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(ImageItemList::iterator it = itemList->begin(); it != itemList->end(); it++)
|
|
|
|
it->testFunction = testFunction;
|
|
|
|
|
|
|
|
QByteArray block;
|
2011-05-03 11:32:23 +00:00
|
|
|
QDataStream ds(&block, QIODevice::WriteOnly);
|
2011-04-27 10:05:43 +00:00
|
|
|
ds << *itemList;
|
|
|
|
if (!sendBlock(RequestBaselineChecksums, block))
|
|
|
|
return false;
|
2011-05-03 11:32:23 +00:00
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
Command cmd;
|
2011-05-03 11:32:23 +00:00
|
|
|
QByteArray rcvBlock;
|
|
|
|
if (!receiveBlock(&cmd, &rcvBlock) || cmd != BaselineProtocol::Ack)
|
2011-04-27 10:05:43 +00:00
|
|
|
return false;
|
2011-05-03 11:32:23 +00:00
|
|
|
QDataStream rds(&rcvBlock, QIODevice::ReadOnly);
|
|
|
|
rds >> *itemList;
|
2011-04-27 10:05:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-13 12:13:40 +00:00
|
|
|
bool BaselineProtocol::submitMatch(const ImageItem &item, QByteArray *serverMsg)
|
|
|
|
{
|
|
|
|
Command cmd;
|
|
|
|
ImageItem smallItem = item;
|
|
|
|
smallItem.image = QImage(); // No need to waste bandwith sending image (identical to baseline) to server
|
|
|
|
return (sendItem(AcceptMatch, smallItem) && receiveBlock(&cmd, serverMsg) && cmd == Ack);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
bool BaselineProtocol::submitNewBaseline(const ImageItem &item, QByteArray *serverMsg)
|
|
|
|
{
|
|
|
|
Command cmd;
|
|
|
|
return (sendItem(AcceptNewBaseline, item) && receiveBlock(&cmd, serverMsg) && cmd == Ack);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-13 12:13:40 +00:00
|
|
|
bool BaselineProtocol::submitMismatch(const ImageItem &item, QByteArray *serverMsg, bool *fuzzyMatch)
|
2011-04-27 10:05:43 +00:00
|
|
|
{
|
|
|
|
Command cmd;
|
2012-08-13 12:13:40 +00:00
|
|
|
if (sendItem(AcceptMismatch, item) && receiveBlock(&cmd, serverMsg) && (cmd == Ack || cmd == FuzzyMatch)) {
|
|
|
|
if (fuzzyMatch)
|
|
|
|
*fuzzyMatch = (cmd == FuzzyMatch);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BaselineProtocol::sendItem(Command cmd, const ImageItem &item)
|
|
|
|
{
|
|
|
|
errMsg.clear();
|
|
|
|
QBuffer buf;
|
|
|
|
buf.open(QIODevice::WriteOnly);
|
|
|
|
QDataStream ds(&buf);
|
|
|
|
ds << item;
|
|
|
|
if (!sendBlock(cmd, buf.data())) {
|
|
|
|
errMsg.prepend(QLS("Failed to submit image to server. "));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BaselineProtocol::sendBlock(Command cmd, const QByteArray &block)
|
|
|
|
{
|
|
|
|
QDataStream s(&socket);
|
|
|
|
// TBD: set qds version as a constant
|
|
|
|
s << quint16(ProtocolVersion) << quint16(cmd);
|
|
|
|
s.writeBytes(block.constData(), block.size());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BaselineProtocol::receiveBlock(Command *cmd, QByteArray *block)
|
|
|
|
{
|
|
|
|
while (socket.bytesAvailable() < int(2*sizeof(quint16) + sizeof(quint32))) {
|
|
|
|
if (!socket.waitForReadyRead(Timeout))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QDataStream ds(&socket);
|
|
|
|
quint16 rcvProtocolVersion, rcvCmd;
|
|
|
|
ds >> rcvProtocolVersion >> rcvCmd;
|
|
|
|
if (rcvProtocolVersion != ProtocolVersion) {
|
|
|
|
errMsg = QLS("Baseline protocol version mismatch, received:") + QString::number(rcvProtocolVersion)
|
|
|
|
+ QLS(" expected:") + QString::number(ProtocolVersion);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (cmd)
|
|
|
|
*cmd = Command(rcvCmd);
|
|
|
|
|
|
|
|
QByteArray uMsg;
|
|
|
|
quint32 remaining;
|
|
|
|
ds >> remaining;
|
|
|
|
uMsg.resize(remaining);
|
|
|
|
int got = 0;
|
|
|
|
char* uMsgBuf = uMsg.data();
|
|
|
|
do {
|
|
|
|
got = ds.readRawData(uMsgBuf, remaining);
|
|
|
|
remaining -= got;
|
|
|
|
uMsgBuf += got;
|
|
|
|
} while (remaining && got >= 0 && socket.waitForReadyRead(Timeout));
|
|
|
|
|
|
|
|
if (got < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (block)
|
|
|
|
*block = uMsg;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString BaselineProtocol::errorMessage()
|
|
|
|
{
|
|
|
|
QString ret = errMsg;
|
|
|
|
if (socket.error() >= 0)
|
|
|
|
ret += QLS(" Socket state: ") + socket.errorString();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|