1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the test suite of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 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 http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 38 ** $QT_END_LICENSE$ 39 ** 40 ****************************************************************************/ 41 42 #ifndef BASELINEPROTOCOL_H 43 #define BASELINEPROTOCOL_H 44 45 #include <QDataStream> 46 #include <QTcpSocket> 47 #include <QImage> 48 #include <QVector> 49 #include <QMap> 50 #include <QPointer> 51 #include <QStringList> 52 53 #define QLS QLatin1String 54 #define QLC QLatin1Char 55 56 #define FileFormat "png" 57 58 extern const QString PI_TestCase; 59 extern const QString PI_HostName; 60 extern const QString PI_HostAddress; 61 extern const QString PI_OSName; 62 extern const QString PI_OSVersion; 63 extern const QString PI_QtVersion; 64 extern const QString PI_BuildKey; 65 extern const QString PI_GitCommit; 66 extern const QString PI_QMakeSpec; 67 extern const QString PI_PulseGitBranch; 68 extern const QString PI_PulseTestrBranch; 69 70 class PlatformInfo : public QMap<QString, QString> 71 { 72 public: 73 PlatformInfo(); 74 PlatformInfo(const PlatformInfo &other); ~PlatformInfo()75 ~PlatformInfo() 76 {} 77 PlatformInfo &operator=(const PlatformInfo &other); 78 79 static PlatformInfo localHostInfo(); 80 81 void addOverride(const QString& key, const QString& value); 82 QStringList overrides() const; 83 bool isAdHocRun() const; 84 void setAdHocRun(bool isAdHoc); 85 86 private: 87 QStringList orides; 88 bool adHoc; 89 friend QDataStream & operator<< (QDataStream &stream, const PlatformInfo &pi); 90 friend QDataStream & operator>> (QDataStream &stream, PlatformInfo& pi); 91 }; 92 QDataStream & operator<< (QDataStream &stream, const PlatformInfo &pi); 93 QDataStream & operator>> (QDataStream &stream, PlatformInfo& pi); 94 95 96 struct ImageItem 97 { 98 public: ImageItemImageItem99 ImageItem() 100 : status(Ok), itemChecksum(0) 101 {} ImageItemImageItem102 ImageItem(const ImageItem &other) 103 { *this = other; } ~ImageItemImageItem104 ~ImageItem() 105 {} 106 ImageItem &operator=(const ImageItem &other); 107 108 static quint64 computeChecksum(const QImage& image); 109 110 enum ItemStatus { 111 Ok = 0, 112 BaselineNotFound = 1, 113 IgnoreItem = 2, 114 Mismatch = 3 115 }; 116 117 QString testFunction; 118 QString itemName; 119 ItemStatus status; 120 QImage image; 121 QList<quint64> imageChecksums; 122 quint16 itemChecksum; 123 QByteArray misc; 124 125 void writeImageToStream(QDataStream &stream) const; 126 void readImageFromStream(QDataStream &stream); 127 }; 128 QDataStream & operator<< (QDataStream &stream, const ImageItem &ii); 129 QDataStream & operator>> (QDataStream &stream, ImageItem& ii); 130 131 Q_DECLARE_METATYPE(ImageItem); 132 133 typedef QVector<ImageItem> ImageItemList; 134 135 136 class BaselineProtocol 137 { 138 public: 139 BaselineProtocol(); 140 ~BaselineProtocol(); 141 142 static BaselineProtocol *instance(QObject *parent = 0); 143 144 // **************************************************** 145 // Important constants here 146 // **************************************************** 147 enum Constant { 148 ProtocolVersion = 5, 149 ServerPort = 54129, 150 Timeout = 15000 151 }; 152 153 enum Command { 154 UnknownError = 0, 155 // Queries 156 AcceptPlatformInfo = 1, 157 RequestBaselineChecksums = 2, 158 AcceptNewBaseline = 4, 159 AcceptMismatch = 5, 160 // Responses 161 Ack = 128, 162 Abort = 129, 163 DoDryRun = 130 164 }; 165 166 // For client: 167 168 // For advanced client: 169 bool connect(const QString &testCase, bool *dryrun = 0, const PlatformInfo& clientInfo = PlatformInfo()); 170 bool requestBaselineChecksums(const QString &testFunction, ImageItemList *itemList); 171 bool submitNewBaseline(const ImageItem &item, QByteArray *serverMsg); 172 bool submitMismatch(const ImageItem &item, QByteArray *serverMsg); 173 174 // For server: 175 bool acceptConnection(PlatformInfo *pi); 176 177 QString errorMessage(); 178 179 private: 180 bool sendItem(Command cmd, const ImageItem &item); 181 182 bool sendBlock(Command cmd, const QByteArray &block); 183 bool receiveBlock(Command *cmd, QByteArray *block); 184 void sysSleep(int ms); 185 186 QString errMsg; 187 QTcpSocket socket; 188 189 friend class BaselineThread; 190 friend class BaselineHandler; 191 }; 192 193 194 #endif // BASELINEPROTOCOL_H 195