1 /* 2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann (at) 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 <qwebsettings.h> 41 #include <qwebdatabase.h> 42 #include <qdesktopservices.h> 43 #include <qtimer.h> 44 #include <qwindowsstyle.h> 45 46 #ifdef Q_WS_X11 47 #include <qx11info_x11.h> 48 #include <fontconfig/fontconfig.h> 49 #endif 50 51 #ifdef Q_OS_WIN 52 #include <io.h> 53 #include <fcntl.h> 54 #endif 55 56 #include <limits.h> 57 #include <signal.h> 58 59 #if defined(__GLIBC__) 60 #include <execinfo.h> 61 #endif 62 63 void messageHandler(QtMsgType type, const char *message) 64 { 65 if (type == QtCriticalMsg) { 66 fprintf(stderr, "%s\n", message); 67 return; 68 } 69 // do nothing 70 } 71 72 QString get_backtrace() { 73 QString s; 74 75 #if defined(__GLIBC__) 76 void* array[256]; 77 size_t size; /* number of stack frames */ 78 79 size = backtrace(array, 256); 80 81 if (!size) 82 return s; 83 84 char** strings = backtrace_symbols(array, size); 85 for (int i = 0; i < int(size); ++i) { 86 s += QString::number(i) + 87 QLatin1String(": ") + 88 QLatin1String(strings[i]) + QLatin1String("\n"); 89 } 90 91 if (strings) 92 free (strings); 93 #endif 94 95 return s; 96 } 97 98 #ifndef Q_OS_WIN 99 static NO_RETURN void crashHandler(int sig) 100 { 101 fprintf(stderr, "%s\n", strsignal(sig)); 102 fprintf(stderr, "%s\n", get_backtrace().toLatin1().constData()); 103 exit(128 + sig); 104 } 105 #endif 106 107 int main(int argc, char* argv[]) 108 { 109 #ifdef Q_OS_WIN 110 _setmode(1, _O_BINARY); 111 _setmode(2, _O_BINARY); 112 #endif 113 114 #ifdef Q_WS_X11 115 FcInit(); 116 WebCore::DumpRenderTree::initializeFonts(); 117 #endif 118 119 #if QT_VERSION >= 0x040500 120 QApplication::setGraphicsSystem("raster"); 121 #endif 122 123 QApplication::setStyle(new QWindowsStyle); 124 125 QFont f("Sans Serif"); 126 f.setPointSize(9); 127 f.setWeight(QFont::Normal); 128 f.setStyle(QFont::StyleNormal); 129 QApplication::setFont(f); 130 131 QApplication app(argc, argv); 132 #ifdef Q_WS_X11 133 QX11Info::setAppDpiY(0, 96); 134 QX11Info::setAppDpiX(0, 96); 135 #endif 136 137 #ifndef Q_OS_WIN 138 signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ 139 signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ 140 signal(SIGFPE, crashHandler); /* 8: floating point exception */ 141 signal(SIGBUS, crashHandler); /* 10: bus error */ 142 signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ 143 signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ 144 signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ 145 signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ 146 signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ 147 #endif 148 149 QStringList args = app.arguments(); 150 if (args.count() < 2) { 151 qDebug() << "Usage: DumpRenderTree [-v|--pixel-tests] filename"; 152 exit(0); 153 } 154 155 // Suppress debug output from Qt if not started with -v 156 if (!args.contains(QLatin1String("-v"))) 157 qInstallMsgHandler(messageHandler); 158 159 WebCore::DumpRenderTree dumper; 160 161 if (args.contains(QLatin1String("--pixel-tests"))) 162 dumper.setDumpPixels(true); 163 164 QString dbDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + QDir::separator() + "qtwebkitdrt"; 165 QWebSettings::setOfflineStoragePath(dbDir); 166 QWebDatabase::removeAllDatabases(); 167 168 if (args.contains(QLatin1String("-"))) { 169 QObject::connect(&dumper, SIGNAL(ready()), &dumper, SLOT(readLine()), Qt::QueuedConnection); 170 QTimer::singleShot(0, &dumper, SLOT(readLine())); 171 } else { 172 dumper.setSingleFileMode(true); 173 for (int i = 1; i < args.size(); ++i) { 174 if (!args.at(i).startsWith('-')) { 175 dumper.processLine(args.at(i)); 176 break; 177 } 178 } 179 } 180 181 return app.exec(); 182 183 #ifdef Q_WS_X11 184 FcConfigSetCurrent(0); 185 #endif 186 } 187