summaryrefslogtreecommitdiffstats
path: root/Tools/DumpRenderTree/qt/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/DumpRenderTree/qt/main.cpp')
-rw-r--r--Tools/DumpRenderTree/qt/main.cpp89
1 files changed, 79 insertions, 10 deletions
diff --git a/Tools/DumpRenderTree/qt/main.cpp b/Tools/DumpRenderTree/qt/main.cpp
index 8349d73..bc762e5 100644
--- a/Tools/DumpRenderTree/qt/main.cpp
+++ b/Tools/DumpRenderTree/qt/main.cpp
@@ -67,6 +67,33 @@ void messageHandler(QtMsgType type, const char *message)
// do nothing
}
+// We only support -v or --pixel-tests or --stdout or --stderr or -, all the others will be
+// pass as test case name (even -abc.html is a valid test case name)
+bool isOption(const QString& str)
+{
+ return str == QString("-v") || str == QString("--pixel-tests")
+ || str == QString("--stdout") || str == QString("--stderr")
+ || str == QString("-");
+}
+
+QString takeOptionValue(QStringList& arguments, int index)
+{
+ QString result;
+
+ if (index + 1 < arguments.count() && !isOption(arguments.at(index + 1)))
+ result = arguments.takeAt(index + 1);
+ arguments.removeAt(index);
+
+ return result;
+}
+
+void printUsage()
+{
+ fprintf(stderr, "Usage: DumpRenderTree [-v|--pixel-tests] [--stdout output_filename] [-stderr error_filename] filename [filename2..n]\n");
+ fprintf(stderr, "Or folder containing test files: DumpRenderTree [-v|--pixel-tests] dirpath\n");
+ fflush(stderr);
+}
+
QString get_backtrace() {
QString s;
@@ -143,28 +170,70 @@ int main(int argc, char* argv[])
QStringList args = app.arguments();
if (args.count() < 2) {
- qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename [filename2..n]";
- qDebug() << "Or folder containing test files: DumpRenderTree [-v|--pixel-tests] dirpath";
- exit(0);
+ printUsage();
+ exit(1);
}
+ // Remove the first arguments, it is application name itself
+ args.removeAt(0);
+
// Suppress debug output from Qt if not started with -v
- if (!args.contains(QLatin1String("-v")))
+ int index = args.indexOf(QLatin1String("-v"));
+ if (index == -1)
qInstallMsgHandler(messageHandler);
+ else
+ args.removeAt(index);
WebCore::DumpRenderTree dumper;
- if (args.contains(QLatin1String("--pixel-tests")))
+ index = args.indexOf(QLatin1String("--pixel-tests"));
+ if (index != -1) {
dumper.setDumpPixels(true);
+ args.removeAt(index);
+ }
+ index = args.indexOf(QLatin1String("--stdout"));
+ if (index != -1) {
+ QString fileName = takeOptionValue(args, index);
+ dumper.setRedirectOutputFileName(fileName);
+ if (fileName.isEmpty() || !freopen(qPrintable(fileName), "w", stdout)) {
+ fprintf(stderr, "STDOUT redirection failed.");
+ exit(1);
+ }
+ }
+ index = args.indexOf(QLatin1String("--stderr"));
+ if (index != -1) {
+ QString fileName = takeOptionValue(args, index);
+ dumper.setRedirectErrorFileName(fileName);
+ if (!freopen(qPrintable(fileName), "w", stderr)) {
+ fprintf(stderr, "STDERR redirection failed.");
+ exit(1);
+ }
+ }
QWebDatabase::removeAllDatabases();
- if (args.contains(QLatin1String("-"))) {
- QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
- QTimer::singleShot(0, &dumper, SLOT(readLine()));
- } else
+ index = args.indexOf(QLatin1String("-"));
+ if (index != -1) {
+ args.removeAt(index);
+
+ // Continue waiting in STDIN for more test case after process one test case
+ QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
+
+ // Read and only read the first test case, ignore the others
+ if (args.size() > 0) {
+ // Process the argument first
+ dumper.processLine(args[0]);
+ } else
+ QTimer::singleShot(0, &dumper, SLOT(readLine()));
+ } else {
+ // Go into standalone mode
+ // Standalone mode need at least one test case
+ if (args.count() < 1) {
+ printUsage();
+ exit(1);
+ }
dumper.processArgsLine(args);
-
+ }
return app.exec();
#ifdef Q_WS_X11