1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#include "htmlpage.h"
#include "baselineprotocol.h"
#include "baselineserver.h"
#include <QDir>
#include <QProcess>
#include <QUrl>
HTMLPage::HTMLPage()
: headerWritten(false)
{
}
HTMLPage::~HTMLPage()
{
end();
}
QString HTMLPage::filePath()
{
return path;
}
void HTMLPage::start(const QString &storagepath, const QString &runId, const PlatformInfo pinfo, const QString &hostAddress, const ImageItemList &itemList)
{
end();
id = runId;
plat = pinfo;
address = hostAddress;
root = storagepath;
imageItems = itemList;
QString dir = root + QLS("reports/");
QDir cwd;
if (!cwd.exists(dir))
cwd.mkpath(dir);
}
void HTMLPage::writeHeader(const ImageItem &item)
{
path = QLS("reports/") + id + QLC('_') + item.engineAsString()
+ QLC('_') + item.formatAsString() + QLS(".html");
QString pageUrl = BaselineServer::baseUrl() + path;
file.setFileName(root + path);
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
qWarning() << "Failed to open report file" << file.fileName();
out.setDevice(&file);
out << "<html><body><h1>Lancelot results from run " << id << "</h1>\n\n";
out << "<h3>Host: " << plat.hostName << " [" << address << "] OS: " << plat.osName << " [enum: " << plat.osVersion << "]</h3>\n";
out << "<h3>Qt version: " << plat.qtVersion << " [commit: " << plat.gitCommit << "] Build key: \"" << plat.buildKey << "\"</h3>\n";
out << "<h3>Engine: " << item.engineAsString() << " Format: " << item.formatAsString() << "</h3>\n\n";
out << "<h3><a href=\"/cgi-bin/server.cgi?cmd=updateAllBaselines&id="<< id << "&host=" << plat.hostName
<< "&engine=" << item.engineAsString() << "&format=" << item.formatAsString()
<< "&url=" << pageUrl
<< "\">Update all baselines</a><br>";
out << "<table border=\"2\">\n"
"<tr>\n"
"<td><b>Script</b></td>\n"
"<td><b>Baseline</b></td>\n"
"<td><b>Rendered</b></td>\n"
"<td><b>Comparison</b></td>\n"
"<td><b>Info/Action</b></td>\n"
"</b></tr><br>";
}
void HTMLPage::writeFooter()
{
out << "</table>\n</body></html>\n";
}
void HTMLPage::addItem(const QString &baseline, const QString &rendered, const ImageItem &item)
{
if (!headerWritten) {
writeHeader(item);
headerWritten = true;
}
QString compared = generateCompared(baseline, rendered);
QString pageUrl = BaselineServer::baseUrl() + path;
out << "<tr>\n";
out << "<td>" << item.scriptName << "</td>\n";
QStringList images = QStringList() << baseline << rendered << compared;
foreach(const QString& img, images)
out << "<td><a href=\"/" << img << "\"><img src=\"/" << img << "\" width=240 height=240></a></td>\n";
out << "<td><a href=\"/cgi-bin/server.cgi?cmd=updateSingleBaseline&oldBaseline=" << baseline
<< "&newBaseline=" << rendered << "&url=" << pageUrl << "\">Update baseline</a><br>"
"<a href=\"/cgi-bin/server.cgi?cmd=blacklist&scriptName=" << item.scriptName
<< "&host=" << plat.hostName << "&engine=" << item.engineAsString()
<< "&format=" << item.formatAsString()
<< "&url=" << pageUrl << "\">Blacklist test</a></td>\n";
out << "<tr>\n\n";
QMutableVectorIterator<ImageItem> it(imageItems);
while (it.hasNext()) {
it.next();
if (it.value().scriptName == item.scriptName) {
it.remove();
break;
}
}
}
void HTMLPage::end()
{
if (file.isOpen()) {
// Add the names of the scripts that passed the test, or were blacklisted
QString pageUrl = BaselineServer::baseUrl() + path;
for (int i=0; i<imageItems.count(); ++i) {
out << "<tr><td>" << imageItems.at(i).scriptName << "</td><td>N/A</td><td>N/A</td><td>N/A</td><td>";
if (imageItems.at(i).status == ImageItem::IgnoreItem) {
out << "<span style=\"background-color:yellow\">Blacklisted</span><br>"
"<a href=\"/cgi-bin/server.cgi?cmd=whitelist&scriptName="
<< imageItems.at(i).scriptName << "&host=" << plat.hostName
<< "&engine=" << imageItems.at(i).engineAsString()
<< "&format=" << imageItems.at(i).formatAsString()
<< "&url=" << pageUrl
<< "\">Whitelist test</a>";
} else {
out << "<span style=\"color:green\">Test passed</span>";
}
out << "</td><tr>";
}
writeFooter();
out.flush();
file.close();
path.clear();
headerWritten = false;
}
}
QString HTMLPage::generateCompared(const QString &baseline, const QString &rendered, bool fuzzy)
{
QString res = rendered;
QFileInfo fi(res);
res.chop(fi.suffix().length() + 1);
res += QLS(fuzzy ? "_fuzzycompared.png" : "_compared.png");
QStringList args;
if (fuzzy)
args << QLS("-fuzz") << QLS("5%");
args << root+baseline << root+rendered << root+res;
QProcess::execute(QLS("compare"), args);
return res;
}
void HTMLPage::handleCGIQuery(const QString &query)
{
QUrl cgiUrl(QLS("http://dummy/cgi-bin/dummy.cgi?") + query);
QTextStream s(stdout);
s << "Content-Type: text/html\r\n\r\n"
<< "<HTML>";
// << "Contents of QUERY_STRING:<br>"
// << "Full string = " << query << "<br>";
QString command(cgiUrl.queryItemValue("cmd"));
if (command == QLS("updateSingleBaseline")) {
s << BaselineHandler::updateSingleBaseline(cgiUrl.queryItemValue(QLS("oldBaseline")),
cgiUrl.queryItemValue(QLS("newBaseline")));
} else if (command == QLS("updateAllBaselines")) {
s << BaselineHandler::updateAllBaselines(cgiUrl.queryItemValue(QLS("host")),
cgiUrl.queryItemValue(QLS("id")),
cgiUrl.queryItemValue(QLS("engine")),
cgiUrl.queryItemValue(QLS("format")));
} else if (command == QLS("blacklist")) {
// blacklist a test
s << BaselineHandler::blacklistTest(cgiUrl.queryItemValue(QLS("scriptName")),
cgiUrl.queryItemValue(QLS("host")),
cgiUrl.queryItemValue(QLS("engine")),
cgiUrl.queryItemValue(QLS("format")));
} else if (command == QLS("whitelist")) {
// whitelist a test
s << BaselineHandler::whitelistTest(cgiUrl.queryItemValue(QLS("scriptName")),
cgiUrl.queryItemValue(QLS("host")),
cgiUrl.queryItemValue(QLS("engine")),
cgiUrl.queryItemValue(QLS("format")));
} else {
s << "Unknown query:<br>" << query << "<br>";
}
s << "<p><a href=\"" << cgiUrl.queryItemValue(QLS("url")) << "\">Back to report</a>";
s << "</HTML>";
}
|