2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2007 Trolltech ASA
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include "DumpRenderTree.h"
31 #include "testplugin.h"
33 #include <qstringlist.h>
34 #include <qapplication.h>
41 #include <qx11info_x11.h>
42 #include <fontconfig/fontconfig.h>
48 #if defined(__GLIBC__)
52 Q_IMPORT_PLUGIN(testplugin)
54 void messageHandler(QtMsgType type, const char *message)
56 if (type == QtCriticalMsg) {
57 fprintf(stderr, "%s\n", message);
63 QString get_backtrace() {
66 #if defined(__GLIBC__)
68 size_t size; /* number of stack frames */
70 size = backtrace(array, 256);
75 char** strings = backtrace_symbols(array, size);
76 for (int i = 0; i < size; ++i) {
77 s += QString::number(i) +
79 QLatin1String(strings[i]) + QLatin1String("\n");
89 static void crashHandler(int sig)
91 fprintf(stderr, "%s\n", strsignal(sig));
92 fprintf(stderr, "%s\n", get_backtrace().toLatin1().constData());
96 int main(int argc, char* argv[])
100 FcConfig *config = FcConfigCreate();
101 QByteArray fontDir = getenv("WEBKIT_TESTFONTS");
102 if (fontDir.isEmpty() || !QDir(fontDir).exists()) {
105 "--------------------------------------------------------------------\n"
106 "WEBKIT_TESTFONTS environment variable is not set correctly.\n"
107 "This variable has to point to the directory containing the fonts\n"
108 "you can checkout from svn://labs.trolltech.com/svn/webkit/testfonts\n"
109 "--------------------------------------------------------------------\n"
113 char currentPath[PATH_MAX+1];
114 getcwd(currentPath, PATH_MAX);
115 QByteArray configFile = currentPath;
116 configFile += "/WebKitTools/DumpRenderTree/qt/fonts.conf";
117 if (!FcConfigParseAndLoad (config, (FcChar8*) configFile.data(), true))
118 qFatal("Couldn't load font configuration file");
119 if (!FcConfigAppFontAddDir (config, (FcChar8*) fontDir.data()))
120 qFatal("Couldn't add font dir!");
121 FcConfigSetCurrent(config);
123 QApplication app(argc, argv);
125 QX11Info::setAppDpiY(0, 96);
126 QX11Info::setAppDpiX(0, 96);
129 QFont f("Sans Serif");
131 f.setWeight(QFont::Normal);
132 f.setStyle(QFont::StyleNormal);
134 app.setStyle(QLatin1String("Plastique"));
137 signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */
138 signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */
139 signal(SIGFPE, crashHandler); /* 8: floating point exception */
140 signal(SIGBUS, crashHandler); /* 10: bus error */
141 signal(SIGSEGV, crashHandler); /* 11: segmentation violation */
142 signal(SIGSYS, crashHandler); /* 12: bad argument to system call */
143 signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */
144 signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */
145 signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */
147 QStringList args = app.arguments();
148 if (args.count() < 2) {
149 qDebug() << "Usage: DumpRenderTree [-v] filename";
153 // supress debug output from Qt if not started with -v
154 if (!args.contains(QLatin1String("-v")))
155 qInstallMsgHandler(messageHandler);
157 WebCore::DumpRenderTree dumper;
159 if (args.last() == QLatin1String("-")) {
162 if (!args.last().startsWith("/")
163 && !args.last().startsWith("file:")) {
164 QString path = QDir::currentPath();
165 if (!path.endsWith('/'))
167 args.last().prepend(path);
169 dumper.open(QUrl(args.last()));
173 FcConfigSetCurrent(0);