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
|
#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)
{
end();
id = runId;
plat = pinfo;
root = storagepath;
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 << "</h3>\n";
out << "<h3>Qt version: " << plat.qtVersion << "</h3>\n";
out << "<h3>Build key: " << plat.buildKey << "</h3>\n";
out << "<h3>Engine: " << item.engineAsString() << "</h3>\n";
out << "<h3>Format: " << item.formatAsString() << "</h3>\n\n";
out << "<h3><a href=\"/cgi-bin/server.cgi?update=all&id="<< id << "&host=" << plat.hostname
<< "&engine=" << item.engineAsString() << "&format=" << item.formatAsString()
<< "&url=" << pageUrl
<< "\">Update all baselines</a></h3>\n\n";
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>Fuzzy Comparison</b></td>\n"
"<td><b>Score</b></td>\n"
"<td><b>Update</b></td>\n"
"</b></tr>\n\n";
}
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 fuzzy = generateCompared(baseline, rendered, true);
QString pageUrl = BaselineServer::baseUrl() + path;
out << "<tr>\n";
out << "<td>" << item.scriptName << "</td>\n";
QStringList images = QStringList() << baseline << rendered << compared << fuzzy;
foreach(const QString& img, images)
out << "<td><a href=\"/" << img << "\"><img src=\"/" << img << "\" width=240 height=240></a></td>\n";
out << "<td></td><td><a href=\"/cgi-bin/server.cgi?update=single&oldBaseline=" << baseline
<< "&newBaseline=" << rendered << "&url=" << pageUrl << "\">Update baseline</a></td>\n";
out << "<tr>\n\n";
}
void HTMLPage::end()
{
if (file.isOpen()) {
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>";
if (cgiUrl.queryItemValue(QLS("update")) == QLS("single")) {
s << BaselineHandler::updateSingleBaseline(cgiUrl.queryItemValue(QLS("oldBaseline")),
cgiUrl.queryItemValue(QLS("newBaseline")));
} else {
s << BaselineHandler::updateAllBaselines(cgiUrl.queryItemValue(QLS("host")),
cgiUrl.queryItemValue(QLS("id")),
cgiUrl.queryItemValue(QLS("engine")),
cgiUrl.queryItemValue(QLS("format")));
}
s << "<p><a href=\"" << cgiUrl.queryItemValue(QLS("url")) << "\">Back to report</a>";
s << "</HTML>";
}
|