Changeset View
Changeset View
Standalone View
Standalone View
src/tests/crashtest/crashtest.cpp
Show All 30 Lines | |||||
31 | #include <kaboutdata.h> | 31 | #include <kaboutdata.h> | ||
32 | #include <assert.h> | 32 | #include <assert.h> | ||
33 | #include <QtConcurrentMap> | 33 | #include <QtConcurrentMap> | ||
34 | #include <KLocalizedString> | 34 | #include <KLocalizedString> | ||
35 | #include <QCommandLineParser> | 35 | #include <QCommandLineParser> | ||
36 | #include <QApplication> | 36 | #include <QApplication> | ||
37 | #include <KAboutData> | 37 | #include <KAboutData> | ||
38 | 38 | | |||
39 | enum CrashType { Crash, Malloc, Div0, Assert, QAssert, Threads }; | 39 | enum CrashType { Crash, Malloc, Div0, Assert, QAssert, Threads, FatalErrorMessage }; | ||
40 | 40 | | |||
41 | struct SomeStruct | 41 | struct SomeStruct | ||
42 | { | 42 | { | ||
43 | int foo() { return ret; } | 43 | int foo() { return ret; } | ||
44 | int ret; | 44 | int ret; | ||
45 | }; | 45 | }; | ||
46 | 46 | | |||
47 | void do_crash() | 47 | void do_crash() | ||
Show All 35 Lines | |||||
83 | void do_threads() | 83 | void do_threads() | ||
84 | { | 84 | { | ||
85 | QStringList foo; | 85 | QStringList foo; | ||
86 | foo << QStringLiteral("thread 1") << QStringLiteral("thread 2") << QStringLiteral("thread 3") << QStringLiteral("thread 4") << QStringLiteral("thread 5"); | 86 | foo << QStringLiteral("thread 1") << QStringLiteral("thread 2") << QStringLiteral("thread 3") << QStringLiteral("thread 4") << QStringLiteral("thread 5"); | ||
87 | QThreadPool::globalInstance()->setMaxThreadCount(5); | 87 | QThreadPool::globalInstance()->setMaxThreadCount(5); | ||
88 | QtConcurrent::blockingMap(foo, map_function); | 88 | QtConcurrent::blockingMap(foo, map_function); | ||
89 | } | 89 | } | ||
90 | 90 | | |||
91 | void do_fatalErrorMessage() | ||||
92 | { | ||||
93 | KCrash::setErrorMessage(QStringLiteral("So long, my friends...")); | ||||
94 | qFatal("So long!\n"); | ||||
95 | } | ||||
96 | | ||||
91 | void level4(int t) | 97 | void level4(int t) | ||
92 | { | 98 | { | ||
93 | if (t == Malloc) | 99 | if (t == Malloc) | ||
94 | do_malloc(); | 100 | do_malloc(); | ||
95 | else if (t == Div0) | 101 | else if (t == Div0) | ||
96 | do_div0(); | 102 | do_div0(); | ||
97 | else if (t == Assert) | 103 | else if (t == Assert) | ||
98 | do_assert(); | 104 | do_assert(); | ||
99 | else if (t == QAssert) | 105 | else if (t == QAssert) | ||
100 | do_qassert(); | 106 | do_qassert(); | ||
101 | else if (t == Threads) | 107 | else if (t == Threads) | ||
102 | do_threads(); | 108 | do_threads(); | ||
109 | else if (t == FatalErrorMessage) | ||||
110 | do_fatalErrorMessage(); | ||||
103 | else | 111 | else | ||
104 | do_crash(); | 112 | do_crash(); | ||
105 | } | 113 | } | ||
106 | 114 | | |||
107 | void level3(int t) | 115 | void level3(int t) | ||
108 | { | 116 | { | ||
109 | level4(t); | 117 | level4(t); | ||
110 | } | 118 | } | ||
Show All 15 Lines | 133 | KAboutData aboutData(QStringLiteral("crashtext"), i18n("Crash Test for DrKonqi"), | |||
126 | QStringLiteral("1.1"), | 134 | QStringLiteral("1.1"), | ||
127 | i18n("Crash Test for DrKonqi"), | 135 | i18n("Crash Test for DrKonqi"), | ||
128 | KAboutLicense::GPL, | 136 | KAboutLicense::GPL, | ||
129 | i18n("(c) 2000-2002 David Faure, Waldo Bastian")); | 137 | i18n("(c) 2000-2002 David Faure, Waldo Bastian")); | ||
130 | 138 | | |||
131 | QCommandLineParser parser; | 139 | QCommandLineParser parser; | ||
132 | parser.addOption(QCommandLineOption(QStringLiteral("autorestart"), i18n("Automatically restart"))); | 140 | parser.addOption(QCommandLineOption(QStringLiteral("autorestart"), i18n("Automatically restart"))); | ||
133 | parser.addOption(QCommandLineOption(QStringLiteral("kdeinit"), i18n("Start DrKonqi using kdeinit"))); | 141 | parser.addOption(QCommandLineOption(QStringLiteral("kdeinit"), i18n("Start DrKonqi using kdeinit"))); | ||
134 | parser.addPositionalArgument(QStringLiteral("type"), i18n("Type of crash."), QStringLiteral("crash|malloc|div0|assert|threads")); | 142 | parser.addPositionalArgument(QStringLiteral("type"), i18n("Type of crash."), QStringLiteral("crash|malloc|div0|assert|threads|fatal")); | ||
135 | aboutData.setupCommandLine(&parser); | 143 | aboutData.setupCommandLine(&parser); | ||
136 | parser.process(app); | 144 | parser.process(app); | ||
137 | aboutData.processCommandLine(&parser); | 145 | aboutData.processCommandLine(&parser); | ||
138 | 146 | | |||
139 | // Start drkonqi directly by default so that drkonqi's output goes to the console. | 147 | // Start drkonqi directly by default so that drkonqi's output goes to the console. | ||
140 | KCrash::CrashFlags flags = KCrash::AlwaysDirectly; | 148 | KCrash::CrashFlags flags = KCrash::AlwaysDirectly; | ||
141 | // This can be disabled to be able to test kcrash's real default behavior. | 149 | // This can be disabled to be able to test kcrash's real default behavior. | ||
142 | if (parser.isSet(QStringLiteral("kdeinit"))) | 150 | if (parser.isSet(QStringLiteral("kdeinit"))) | ||
Show All 9 Lines | |||||
152 | else if (type == "div0") | 160 | else if (type == "div0") | ||
153 | crashtype = Div0; | 161 | crashtype = Div0; | ||
154 | else if (type == "assert") | 162 | else if (type == "assert") | ||
155 | crashtype = Assert; | 163 | crashtype = Assert; | ||
156 | else if (type == "qassert") | 164 | else if (type == "qassert") | ||
157 | crashtype = QAssert; | 165 | crashtype = QAssert; | ||
158 | else if (type == "threads") | 166 | else if (type == "threads") | ||
159 | crashtype = Threads; | 167 | crashtype = Threads; | ||
168 | else if (type == "fatal") | ||||
169 | crashtype = FatalErrorMessage; | ||||
160 | level1(crashtype); | 170 | level1(crashtype); | ||
161 | return app.exec(); | 171 | return app.exec(); | ||
162 | } | 172 | } |