WebKitTools/DumpRenderTree/qt/main.cpp
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     1 /*
       
     2  * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
       
     3  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
       
     4  *
       
     5  * Redistribution and use in source and binary forms, with or without
       
     6  * modification, are permitted provided that the following conditions
       
     7  * are met:
       
     8  *
       
     9  * 1.  Redistributions of source code must retain the above copyright
       
    10  *     notice, this list of conditions and the following disclaimer.
       
    11  * 2.  Redistributions in binary form must reproduce the above copyright
       
    12  *     notice, this list of conditions and the following disclaimer in the
       
    13  *     documentation and/or other materials provided with the distribution.
       
    14  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
       
    15  *     its contributors may be used to endorse or promote products derived
       
    16  *     from this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
       
    19  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
    20  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
       
    21  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
       
    22  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
       
    23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
       
    24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
       
    25  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
       
    27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    28  */
       
    29 
       
    30 #include "DumpRenderTreeQt.h"
       
    31 
       
    32 #include <wtf/AlwaysInline.h>
       
    33 
       
    34 #include <qstringlist.h>
       
    35 #include <qapplication.h>
       
    36 #include <qurl.h>
       
    37 #include <qdir.h>
       
    38 #include <qdebug.h>
       
    39 #include <qfont.h>
       
    40 #include <qwebdatabase.h>
       
    41 #include <qtimer.h>
       
    42 #include <qwindowsstyle.h>
       
    43 
       
    44 #ifdef Q_WS_X11
       
    45 #include <qx11info_x11.h>
       
    46 #include <fontconfig/fontconfig.h>
       
    47 #endif
       
    48 
       
    49 #ifdef Q_OS_WIN
       
    50 #include <io.h>
       
    51 #include <fcntl.h>
       
    52 #endif
       
    53 
       
    54 #include <limits.h>
       
    55 #include <signal.h>
       
    56 
       
    57 #if defined(__GLIBC__)
       
    58 #include <execinfo.h>
       
    59 #endif
       
    60 
       
    61 void messageHandler(QtMsgType type, const char *message)
       
    62 {
       
    63     if (type == QtCriticalMsg) {
       
    64         fprintf(stderr, "%s\n", message);
       
    65         return;
       
    66     }
       
    67     // do nothing
       
    68 }
       
    69 
       
    70 QString get_backtrace() {
       
    71     QString s;
       
    72 
       
    73 #if defined(__GLIBC__)
       
    74     void* array[256];
       
    75     size_t size; /* number of stack frames */
       
    76 
       
    77     size = backtrace(array, 256);
       
    78 
       
    79     if (!size)
       
    80         return s;
       
    81 
       
    82     char** strings = backtrace_symbols(array, size);
       
    83     for (int i = 0; i < int(size); ++i) {
       
    84         s += QString::number(i) +
       
    85              QLatin1String(": ") +
       
    86              QLatin1String(strings[i]) + QLatin1String("\n");
       
    87     }
       
    88 
       
    89     if (strings)
       
    90         free (strings);
       
    91 #endif
       
    92 
       
    93     return s;
       
    94 }
       
    95 
       
    96 #if HAVE(SIGNAL_H)
       
    97 static NO_RETURN void crashHandler(int sig)
       
    98 {
       
    99     fprintf(stderr, "%s\n", strsignal(sig));
       
   100     fprintf(stderr, "%s\n", get_backtrace().toLatin1().constData());
       
   101     exit(128 + sig);
       
   102 }
       
   103 #endif
       
   104 
       
   105 int main(int argc, char* argv[])
       
   106 {
       
   107 #ifdef Q_OS_WIN
       
   108     _setmode(1, _O_BINARY);
       
   109     _setmode(2, _O_BINARY);
       
   110 #endif
       
   111 
       
   112 #ifdef Q_WS_X11
       
   113     FcInit();
       
   114     WebCore::DumpRenderTree::initializeFonts();
       
   115 #endif
       
   116 
       
   117     QApplication::setGraphicsSystem("raster");
       
   118     QApplication::setStyle(new QWindowsStyle);
       
   119 
       
   120     QFont f("Sans Serif");
       
   121     f.setPointSize(9);
       
   122     f.setWeight(QFont::Normal);
       
   123     f.setStyle(QFont::StyleNormal);
       
   124     QApplication::setFont(f);
       
   125 
       
   126     QApplication app(argc, argv);
       
   127 #ifdef Q_WS_X11
       
   128     QX11Info::setAppDpiY(0, 96);
       
   129     QX11Info::setAppDpiX(0, 96);
       
   130 #endif
       
   131 
       
   132 #if HAVE(SIGNAL_H)
       
   133     signal(SIGILL, crashHandler);    /* 4:   illegal instruction (not reset when caught) */
       
   134     signal(SIGTRAP, crashHandler);   /* 5:   trace trap (not reset when caught) */
       
   135     signal(SIGFPE, crashHandler);    /* 8:   floating point exception */
       
   136     signal(SIGBUS, crashHandler);    /* 10:  bus error */
       
   137     signal(SIGSEGV, crashHandler);   /* 11:  segmentation violation */
       
   138     signal(SIGSYS, crashHandler);    /* 12:  bad argument to system call */
       
   139     signal(SIGPIPE, crashHandler);   /* 13:  write on a pipe with no reader */
       
   140     signal(SIGXCPU, crashHandler);   /* 24:  exceeded CPU time limit */
       
   141     signal(SIGXFSZ, crashHandler);   /* 25:  exceeded file size limit */
       
   142 #endif
       
   143 
       
   144     QStringList args = app.arguments();
       
   145     if (args.count() < 2) {
       
   146         qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename";
       
   147         exit(0);
       
   148     }
       
   149 
       
   150     // Suppress debug output from Qt if not started with -v
       
   151     if (!args.contains(QLatin1String("-v")))
       
   152         qInstallMsgHandler(messageHandler);
       
   153 
       
   154     WebCore::DumpRenderTree dumper;
       
   155 
       
   156     if (args.contains(QLatin1String("--pixel-tests")))
       
   157         dumper.setDumpPixels(true);
       
   158 
       
   159     QWebDatabase::removeAllDatabases();
       
   160 
       
   161     if (args.contains(QLatin1String("-"))) {
       
   162         QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection);
       
   163         QTimer::singleShot(0, &dumper, SLOT(readLine()));
       
   164     } else {
       
   165         dumper.setSingleFileMode(true);
       
   166         for (int i = 1; i < args.size(); ++i) {
       
   167             if (!args.at(i).startsWith('-')) {
       
   168                 dumper.processLine(args.at(i));
       
   169                 break;
       
   170             }
       
   171         }
       
   172     }
       
   173 
       
   174     return app.exec();
       
   175 
       
   176 #ifdef Q_WS_X11
       
   177     FcConfigSetCurrent(0);
       
   178 #endif
       
   179 }