Esempio n. 1
0
int main(int argc, char* argv[])
{
#ifdef Q_OS_WIN
    _setmode(1, _O_BINARY);
    _setmode(2, _O_BINARY);
#endif

    // Suppress debug output from Qt if not started with -v
    bool suppressQtDebugOutput = true;
    for (int i = 1; i < argc; ++i) {
        if (!qstrcmp(argv[i], "-v")) {
            suppressQtDebugOutput = false;
            break;
        }
    }

    // Has to be done before QApplication is constructed in case
    // QApplication itself produces debug output.
    if (suppressQtDebugOutput)
        qInstallMsgHandler(messageHandler);

    WebKit::initializeTestFonts();

    QApplication::setGraphicsSystem("raster");
    QApplication::setStyle(new QWindowsStyle);

    QApplication app(argc, argv);
    app.setQuitOnLastWindowClosed(false);

#if HAVE(QT5)
    QCoreApplication::setAttribute(Qt::AA_Use96Dpi, true);
#else
#ifdef Q_WS_X11
    QX11Info::setAppDpiY(0, 96);
    QX11Info::setAppDpiX(0, 96);
#endif

   /*
    * QApplication will initialize the default application font based
    * on the application DPI at construction time, which might be
    * different from the DPI we explicitly set using QX11Info above.
    * See: https://bugreports.qt.nokia.com/browse/QTBUG-21603
    *
    * To ensure that the application font DPI matches the application
    * DPI, we override the application font using the font we get from
    * a QWidget, which has already been resolved against the existing
    * default font, but with the correct paint-device DPI.
   */
    QApplication::setFont(QWidget().font());
#endif

    WTFInstallReportBacktraceOnCrashHook();

    QStringList args = app.arguments();
    if (args.count() < (!suppressQtDebugOutput ? 3 : 2)) {
        printUsage();
        exit(1);
    }

    // Remove the first arguments, it is application name itself
    args.removeAt(0);

    WebCore::DumpRenderTree dumper;

    int 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();

    index = args.indexOf(QLatin1String("--timeout"));
    if (index != -1) {
        int timeout = takeOptionValue(args, index).toInt();
        dumper.setTimeout(timeout);
    }

    index = args.indexOf(QLatin1String("--no-timeout"));
    if (index != -1) {
        dumper.setShouldTimeout(false);
        args.removeAt(index);
    }

    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();
}
Esempio n. 2
0
int main(int argc, char* argv[])
{
#ifdef Q_OS_WIN
    _setmode(1, _O_BINARY);
    _setmode(2, _O_BINARY);
#endif

#ifdef Q_WS_X11
    FcInit();
    WebCore::DumpRenderTree::initializeFonts();
#endif

    QApplication::setGraphicsSystem("raster");
    QApplication::setStyle(new QWindowsStyle);

    QFont f("Sans Serif");
    f.setPointSize(9);
    f.setWeight(QFont::Normal);
    f.setStyle(QFont::StyleNormal);
    QApplication::setFont(f);

    QApplication app(argc, argv);
#ifdef Q_WS_X11
    QX11Info::setAppDpiY(0, 96);
    QX11Info::setAppDpiX(0, 96);
#endif

#if HAVE(SIGNAL_H)
    signal(SIGILL, crashHandler);    /* 4:   illegal instruction (not reset when caught) */
    signal(SIGTRAP, crashHandler);   /* 5:   trace trap (not reset when caught) */
    signal(SIGFPE, crashHandler);    /* 8:   floating point exception */
    signal(SIGBUS, crashHandler);    /* 10:  bus error */
    signal(SIGSEGV, crashHandler);   /* 11:  segmentation violation */
    signal(SIGSYS, crashHandler);    /* 12:  bad argument to system call */
    signal(SIGPIPE, crashHandler);   /* 13:  write on a pipe with no reader */
    signal(SIGXCPU, crashHandler);   /* 24:  exceeded CPU time limit */
    signal(SIGXFSZ, crashHandler);   /* 25:  exceeded file size limit */
#endif

    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);
    }

    // Suppress debug output from Qt if not started with -v
    if (!args.contains(QLatin1String("-v")))
        qInstallMsgHandler(messageHandler);

    WebCore::DumpRenderTree dumper;

    if (args.contains(QLatin1String("--pixel-tests")))
        dumper.setDumpPixels(true);

    QWebDatabase::removeAllDatabases();

    if (args.contains(QLatin1String("-"))) {
        QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
        QTimer::singleShot(0, &dumper, SLOT(readLine()));
    } else
        dumper.processArgsLine(args);

    return app.exec();

#ifdef Q_WS_X11
    FcConfigSetCurrent(0);
#endif
}