-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanualtester.cpp
More file actions
149 lines (137 loc) · 4.72 KB
/
manualtester.cpp
File metadata and controls
149 lines (137 loc) · 4.72 KB
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
#include "manualtester.h"
#include <QFileInfo>
#include <QCryptographicHash>
ManualTester::ManualTester(QApplication *a)
: QWidget()
{
app = a;
qsrand(10);
tempFile = QDir::tempPath()+"/tmp.tests"+QString::number(qrand()+1,16);
QDir::temp().mkdir(tempFile);
fprintf(stderr, "hash=%s\n", tempFile.toAscii().data());
launcher = new QProcess(this);
runtest = new QProcess(this);
showpng = new QProcess(this);
timer = new QTimer(this);
message = new QMessageBox(this);
actual = -1;
message->setText("Inspect if the shown page is correct!");
message->setInformativeText("Do you want to save the actual file as expected?");
message->setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Abort);
message->setDefaultButton(QMessageBox::Discard);
message->move(0,0);
log.setFileName("log.txt");
logging = log.open(QIODevice::WriteOnly | QIODevice::Text);
logger.setDevice(&log);
connect( this, SIGNAL( optionSignal(Option) ), SLOT( handleOption(Option) ) );
connect( this, SIGNAL( continueSignal() ), SLOT( start() ) );
connect( timer, SIGNAL( timeout() ), this, SLOT( requestOption() ) );
connect( timer, SIGNAL( timeout() ), message, SLOT( show() ) );
}
void ManualTester::start(){
actual++;
if (!QFile::exists(program.split(" ").first())){
qDebug()<< "\n" << program <<":\tProgram does not exist!" << "\n";
exit(1);
}
if (actual < fileList.size()) {
run( fileList[actual] );
} else {
handleOption(Abort);
}
}
void ManualTester::copy() {
QFileInfo info(fileList[actual]);
QStringList path = info.absoluteDir().absolutePath().split("LayoutTests");
QString actual(testDir.absolutePath()+path.last()+"/"
+info.fileName().split(".").first()+"-actual.txt");
QString expected(path.first()+"LayoutTests/platform/qt"+path.last()+"/"
+info.fileName().split(".").first()+"-expected.txt");
QFileInfo expInfo(expected);
QDir dir(expInfo.absoluteDir().absolutePath());
if ( !dir.exists() )
dir.mkpath(expInfo.absoluteDir().absolutePath());
if(QFile::remove(expected) && logging) logger<<"rm "<<expected<<"\n";
if(QFile::copy(actual,expected) && logging) logger<<"cp "<<actual<<" "<<expected<<"\n";
else qDebug()<< actual;
}
void ManualTester::run(const QString &arg) {
QFileInfo info(fileList[actual]);
QStringList path = info.absoluteDir().absolutePath().split("LayoutTests");
QString macpng(path.first()+"LayoutTests/platform/mac"+path.last()+"/"
+info.fileName().split(".").first()+"-expected.png");
fprintf(stderr,"macpng=%s\n",macpng.toAscii().data());
QStringList mainArgs = program.split(" ");
QString pgName = mainArgs.first();
mainArgs.removeFirst();
runtest->execute(tester, QStringList()<< "--no-launch-safari" <<"--platform" << "mac" << "-o" << tempFile << arg);
runtest->start(pgName, QStringList(mainArgs)<<tempFile+"/results.html");
showpng->start(pgName, QStringList(mainArgs)<< macpng);
launcher->start(pgName, QStringList(mainArgs)<<arg);
if ( !launcher->waitForStarted() )
return;
timer->start(500);
}
void ManualTester::requestOption(){
int opt = message->exec();
switch (opt) {
case QMessageBox::Save:
emit optionSignal(Save);
break;
case QMessageBox::Discard:
emit optionSignal(Discard);
break;
case QMessageBox::Abort:
emit optionSignal(Abort);
break;
default:
// should never be reached
break;
}
}
void ManualTester::setup(const QString& tstr, const QString& pgrm, const QString& tstDir, const QStringList& files) {
tester = tstr;
program = pgrm;
fileList = files;
testDir.setPath(tstDir);
}
void ManualTester::handleOption(Option opt){
launcher-> close();
runtest->close();
showpng->close();
switch (opt){
case Save:
if (actual < fileList.size()) {
copy();
} else {
handleOption(Abort);
}
break;
case Discard:
if (actual < fileList.size()) {
if (logging) logger<<"Skipped: "<<fileList[actual]<<"\n";
}
break;
case Abort:
app->setQuitOnLastWindowClosed(true);
if (actual < fileList.size()) {
if (logging) logger<<"Aborted at: "<<fileList[actual]<<"\n";
}
logger.flush();
log.close();
runtest->execute("rm", QStringList()<<"-rv"<<tempFile);
exit(0);
break;
default:
// should never be reached
break;
}
emit continueSignal();
}
ManualTester::~ManualTester()
{
delete runtest;
delete launcher;
delete timer;
delete message;
}