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