|
1 /* |
|
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
|
3 * Copyright (C) 2007 Trolltech ASA |
|
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 #include "testplugin.h" |
|
32 |
|
33 #include <qstringlist.h> |
|
34 #include <qapplication.h> |
|
35 #include <qurl.h> |
|
36 #include <qdir.h> |
|
37 #include <qdebug.h> |
|
38 #include <qfont.h> |
|
39 |
|
40 #ifdef Q_WS_X11 |
|
41 #include <qx11info_x11.h> |
|
42 #include <fontconfig/fontconfig.h> |
|
43 #endif |
|
44 |
|
45 #include <limits.h> |
|
46 #include <signal.h> |
|
47 |
|
48 Q_IMPORT_PLUGIN(testplugin) |
|
49 |
|
50 void messageHandler(QtMsgType type, const char *message) |
|
51 { |
|
52 if (type == QtCriticalMsg) { |
|
53 fprintf(stderr, "%s\n", message); |
|
54 return; |
|
55 } |
|
56 // do nothing |
|
57 } |
|
58 |
|
59 static void crashHandler(int sig) |
|
60 { |
|
61 fprintf(stderr, "%s\n", strsignal(sig)); |
|
62 exit(128 + sig); |
|
63 } |
|
64 |
|
65 int main(int argc, char* argv[]) |
|
66 { |
|
67 #ifdef Q_WS_X11 |
|
68 FcInit(); |
|
69 FcConfig *config = FcConfigCreate(); |
|
70 QByteArray fontDir = getenv("WEBKIT_TESTFONTS"); |
|
71 if (fontDir.isEmpty()) { |
|
72 fprintf(stderr, |
|
73 "\n\n" |
|
74 "--------------------------------------------------------------------\n" |
|
75 "WEBKIT_TESTFONTS environment variable is not set.\n" |
|
76 "This variable has to point to the directory containing the fonts\n" |
|
77 "you can checkout from svn://labs.trolltech.com/svn/webkit/testfonts\n" |
|
78 "--------------------------------------------------------------------\n" |
|
79 ); |
|
80 exit(1); |
|
81 } |
|
82 char currentPath[PATH_MAX+1]; |
|
83 getcwd(currentPath, PATH_MAX); |
|
84 QByteArray configFile = currentPath; |
|
85 configFile += "/WebKitTools/DumpRenderTree/qt/fonts.conf"; |
|
86 if (!FcConfigParseAndLoad (config, (FcChar8*) configFile.data(), true)) |
|
87 qFatal("Couldn't load font configuration file"); |
|
88 if (!FcConfigAppFontAddDir (config, (FcChar8*) fontDir.data())) |
|
89 qFatal("Couldn't add font dir!"); |
|
90 FcConfigSetCurrent(config); |
|
91 #endif |
|
92 QApplication app(argc, argv); |
|
93 #ifdef Q_WS_X11 |
|
94 QX11Info::setAppDpiY(0, 96); |
|
95 QX11Info::setAppDpiX(0, 96); |
|
96 #endif |
|
97 |
|
98 QFont f("Sans Serif"); |
|
99 f.setPointSize(9); |
|
100 f.setWeight(QFont::Normal); |
|
101 f.setStyle(QFont::StyleNormal); |
|
102 app.setFont(f); |
|
103 app.setStyle(QLatin1String("Plastique")); |
|
104 |
|
105 |
|
106 signal(SIGILL, crashHandler); /* 4: illegal instruction (not reset when caught) */ |
|
107 signal(SIGTRAP, crashHandler); /* 5: trace trap (not reset when caught) */ |
|
108 signal(SIGFPE, crashHandler); /* 8: floating point exception */ |
|
109 signal(SIGBUS, crashHandler); /* 10: bus error */ |
|
110 signal(SIGSEGV, crashHandler); /* 11: segmentation violation */ |
|
111 signal(SIGSYS, crashHandler); /* 12: bad argument to system call */ |
|
112 signal(SIGPIPE, crashHandler); /* 13: write on a pipe with no reader */ |
|
113 signal(SIGXCPU, crashHandler); /* 24: exceeded CPU time limit */ |
|
114 signal(SIGXFSZ, crashHandler); /* 25: exceeded file size limit */ |
|
115 |
|
116 QStringList args = app.arguments(); |
|
117 if (args.count() < 2) { |
|
118 qDebug() << "Usage: DumpRenderTree [-v] filename"; |
|
119 exit(0); |
|
120 } |
|
121 |
|
122 // supress debug output from Qt if not started with -v |
|
123 if (!args.contains(QLatin1String("-v"))) |
|
124 qInstallMsgHandler(messageHandler); |
|
125 |
|
126 WebCore::DumpRenderTree dumper; |
|
127 |
|
128 if (args.last() == QLatin1String("-")) { |
|
129 dumper.open(); |
|
130 } else { |
|
131 if (!args.last().startsWith("/") |
|
132 && !args.last().startsWith("file:")) { |
|
133 QString path = QDir::currentPath(); |
|
134 if (!path.endsWith('/')) |
|
135 path.append('/'); |
|
136 args.last().prepend(path); |
|
137 } |
|
138 dumper.open(QUrl(args.last())); |
|
139 } |
|
140 return app.exec(); |
|
141 #ifdef Q_WS_X11 |
|
142 FcConfigSetCurrent(0); |
|
143 #endif |
|
144 } |