Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/testlib/qtestcase.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||||||||
2 | ** | - | ||||||||||||||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||||||||||||||
5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
6 | ** | - | ||||||||||||||||||||||||
7 | ** This file is part of the QtTest module of the Qt Toolkit. | - | ||||||||||||||||||||||||
8 | ** | - | ||||||||||||||||||||||||
9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
10 | ** Commercial License Usage | - | ||||||||||||||||||||||||
11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
17 | ** | - | ||||||||||||||||||||||||
18 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
22 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
25 | ** | - | ||||||||||||||||||||||||
26 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
36 | ** | - | ||||||||||||||||||||||||
37 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
38 | ** | - | ||||||||||||||||||||||||
39 | ****************************************************************************/ | - | ||||||||||||||||||||||||
40 | - | |||||||||||||||||||||||||
41 | #include <QtTest/qtestcase.h> | - | ||||||||||||||||||||||||
42 | #include <QtTest/qtestassert.h> | - | ||||||||||||||||||||||||
43 | - | |||||||||||||||||||||||||
44 | #include <QtCore/qbytearray.h> | - | ||||||||||||||||||||||||
45 | #include <QtCore/qmetaobject.h> | - | ||||||||||||||||||||||||
46 | #include <QtCore/qobject.h> | - | ||||||||||||||||||||||||
47 | #include <QtCore/qstringlist.h> | - | ||||||||||||||||||||||||
48 | #include <QtCore/qvector.h> | - | ||||||||||||||||||||||||
49 | #include <QtCore/qvarlengtharray.h> | - | ||||||||||||||||||||||||
50 | #include <QtCore/qcoreapplication.h> | - | ||||||||||||||||||||||||
51 | #include <QtCore/qfile.h> | - | ||||||||||||||||||||||||
52 | #include <QtCore/qfileinfo.h> | - | ||||||||||||||||||||||||
53 | #include <QtCore/qdir.h> | - | ||||||||||||||||||||||||
54 | #include <QtCore/qprocess.h> | - | ||||||||||||||||||||||||
55 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||||||||
56 | #include <QtCore/qlibraryinfo.h> | - | ||||||||||||||||||||||||
57 | #include <QtCore/private/qtools_p.h> | - | ||||||||||||||||||||||||
58 | #include <QtCore/qdiriterator.h> | - | ||||||||||||||||||||||||
59 | #include <QtCore/qtemporarydir.h> | - | ||||||||||||||||||||||||
60 | #include <QtCore/qthread.h> | - | ||||||||||||||||||||||||
61 | #include <QtCore/qwaitcondition.h> | - | ||||||||||||||||||||||||
62 | #include <QtCore/qmutex.h> | - | ||||||||||||||||||||||||
63 | - | |||||||||||||||||||||||||
64 | #include <QtTest/private/qtestlog_p.h> | - | ||||||||||||||||||||||||
65 | #include <QtTest/private/qtesttable_p.h> | - | ||||||||||||||||||||||||
66 | #include <QtTest/qtestdata.h> | - | ||||||||||||||||||||||||
67 | #include <QtTest/private/qtestresult_p.h> | - | ||||||||||||||||||||||||
68 | #include <QtTest/private/qsignaldumper_p.h> | - | ||||||||||||||||||||||||
69 | #include <QtTest/private/qbenchmark_p.h> | - | ||||||||||||||||||||||||
70 | #include <QtTest/private/cycle_p.h> | - | ||||||||||||||||||||||||
71 | #include <QtTest/private/qtestblacklist_p.h> | - | ||||||||||||||||||||||||
72 | #if defined(HAVE_XCTEST) | - | ||||||||||||||||||||||||
73 | #include <QtTest/private/qxctestlogger_p.h> | - | ||||||||||||||||||||||||
74 | #endif | - | ||||||||||||||||||||||||
75 | #if defined Q_OS_MACOS | - | ||||||||||||||||||||||||
76 | #include <QtTest/private/qtestutil_macos_p.h> | - | ||||||||||||||||||||||||
77 | #endif | - | ||||||||||||||||||||||||
78 | - | |||||||||||||||||||||||||
79 | #include <numeric> | - | ||||||||||||||||||||||||
80 | #include <algorithm> | - | ||||||||||||||||||||||||
81 | - | |||||||||||||||||||||||||
82 | #include <stdarg.h> | - | ||||||||||||||||||||||||
83 | #include <stdio.h> | - | ||||||||||||||||||||||||
84 | #include <stdlib.h> | - | ||||||||||||||||||||||||
85 | - | |||||||||||||||||||||||||
86 | #if defined(Q_OS_LINUX) | - | ||||||||||||||||||||||||
87 | #include <sys/types.h> | - | ||||||||||||||||||||||||
88 | #include <unistd.h> | - | ||||||||||||||||||||||||
89 | #include <fcntl.h> | - | ||||||||||||||||||||||||
90 | #endif | - | ||||||||||||||||||||||||
91 | - | |||||||||||||||||||||||||
92 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
93 | #ifndef Q_OS_WINCE | - | ||||||||||||||||||||||||
94 | # if !defined(Q_CC_MINGW) || (defined(Q_CC_MINGW) && defined(__MINGW64_VERSION_MAJOR)) | - | ||||||||||||||||||||||||
95 | # include <crtdbg.h> | - | ||||||||||||||||||||||||
96 | # endif | - | ||||||||||||||||||||||||
97 | #endif | - | ||||||||||||||||||||||||
98 | #include <windows.h> // for Sleep | - | ||||||||||||||||||||||||
99 | #endif | - | ||||||||||||||||||||||||
100 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||||||||
101 | #include <errno.h> | - | ||||||||||||||||||||||||
102 | #include <signal.h> | - | ||||||||||||||||||||||||
103 | #include <time.h> | - | ||||||||||||||||||||||||
#include <sys/resource.h> | ||||||||||||||||||||||||||
104 | #endif | - | ||||||||||||||||||||||||
105 | - | |||||||||||||||||||||||||
106 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
107 | #include <IOKit/pwr_mgt/IOPMLib.h> | - | ||||||||||||||||||||||||
108 | #endif | - | ||||||||||||||||||||||||
109 | - | |||||||||||||||||||||||||
110 | #include <vector> | - | ||||||||||||||||||||||||
111 | - | |||||||||||||||||||||||||
112 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
113 | - | |||||||||||||||||||||||||
114 | using QtMiscUtils::toHexUpper; | - | ||||||||||||||||||||||||
115 | using QtMiscUtils::fromHex; | - | ||||||||||||||||||||||||
static void disableCoreDump() | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
bool ok = false; | ||||||||||||||||||||||||||
const int disableCoreDump = qEnvironmentVariableIntValue("QTEST_DISABLE_CORE_DUMP", &ok); | ||||||||||||||||||||||||||
if (ok && disableCoreDump == 1) { | ||||||||||||||||||||||||||
#if defined(Q_OS_UNIX) | ||||||||||||||||||||||||||
struct rlimit limit; | ||||||||||||||||||||||||||
limit.rlim_cur = 0; | ||||||||||||||||||||||||||
limit.rlim_max = 0; | ||||||||||||||||||||||||||
116 | - | |||||||||||||||||||||||||
117 | - | |||||||||||||||||||||||||
if (setrlimit(RLIMIT_CORE, &limit) != 0) | ||||||||||||||||||||||||||
qWarning("Failed to disable core dumps: %d", errno); | ||||||||||||||||||||||||||
#endif | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Q_CONSTRUCTOR_FUNCTION(disableCoreDump);static void stackTrace() | ||||||||||||||||||||||||||
119 | { | - | ||||||||||||||||||||||||
120 | bool ok = false; | - | ||||||||||||||||||||||||
121 | const int disableStackDump = qEnvironmentVariableIntValue("QTEST_DISABLE_STACK_DUMP", &ok); | - | ||||||||||||||||||||||||
122 | if (ok && disableStackDump == 1) | - | ||||||||||||||||||||||||
123 | return; | - | ||||||||||||||||||||||||
124 | #ifdef Q_OS_LINUX | - | ||||||||||||||||||||||||
125 | fprintf(stderr, "\n========= Received signal, dumping stack ==============\n"); | - | ||||||||||||||||||||||||
126 | char cmd[512]; | - | ||||||||||||||||||||||||
127 | qsnprintf(cmd, 512, "gdb --pid %d 2>/dev/null <<EOF\n" | - | ||||||||||||||||||||||||
128 | "set prompt\n" | - | ||||||||||||||||||||||||
129 | "set height 0\n" | - | ||||||||||||||||||||||||
130 | "thread apply all where full\n" | - | ||||||||||||||||||||||||
131 | "detach\n" | - | ||||||||||||||||||||||||
132 | "quit\n" | - | ||||||||||||||||||||||||
133 | "EOF\n", | - | ||||||||||||||||||||||||
134 | (int)getpid()); | - | ||||||||||||||||||||||||
135 | if (system(cmd) == -1) | - | ||||||||||||||||||||||||
136 | fprintf(stderr, "calling gdb failed\n"); | - | ||||||||||||||||||||||||
137 | fprintf(stderr, "========= End of stack trace ==============\n"); | - | ||||||||||||||||||||||||
138 | #elif defined(Q_OS_OSX) | - | ||||||||||||||||||||||||
139 | fprintf(stderr, "\n========= Received signal, dumping stack ==============\n"); | - | ||||||||||||||||||||||||
140 | char cmd[512]; | - | ||||||||||||||||||||||||
141 | qsnprintf(cmd, 512, "lldb -p %d 2>/dev/null <<EOF\n" | - | ||||||||||||||||||||||||
142 | "bt all\n" | - | ||||||||||||||||||||||||
143 | "quit\n" | - | ||||||||||||||||||||||||
144 | "EOF\n", | - | ||||||||||||||||||||||||
145 | (int)getpid()); | - | ||||||||||||||||||||||||
146 | if (system(cmd) == -1) | - | ||||||||||||||||||||||||
147 | fprintf(stderr, "calling lldb failed\n"); | - | ||||||||||||||||||||||||
148 | fprintf(stderr, "========= End of stack trace ==============\n"); | - | ||||||||||||||||||||||||
149 | #endif | - | ||||||||||||||||||||||||
150 | } | - | ||||||||||||||||||||||||
151 | - | |||||||||||||||||||||||||
152 | static bool installCoverageTool(const char * appname, const char * testname) | - | ||||||||||||||||||||||||
153 | { | - | ||||||||||||||||||||||||
154 | #ifdef __COVERAGESCANNER__ | - | ||||||||||||||||||||||||
155 | if (!qEnvironmentVariableIsEmpty("QT_TESTCOCOON_ACTIVE")) | - | ||||||||||||||||||||||||
156 | return false; | - | ||||||||||||||||||||||||
157 | // Set environment variable QT_TESTCOCOON_ACTIVE to prevent an eventual subtest from | - | ||||||||||||||||||||||||
158 | // being considered as a stand-alone test regarding the coverage analysis. | - | ||||||||||||||||||||||||
159 | qputenv("QT_TESTCOCOON_ACTIVE", "1"); | - | ||||||||||||||||||||||||
160 | - | |||||||||||||||||||||||||
161 | // Install Coverage Tool | - | ||||||||||||||||||||||||
162 | __coveragescanner_install(appname); | - | ||||||||||||||||||||||||
163 | __coveragescanner_testname(testname); | - | ||||||||||||||||||||||||
164 | __coveragescanner_clear(); | - | ||||||||||||||||||||||||
165 | return true; | - | ||||||||||||||||||||||||
166 | #else | - | ||||||||||||||||||||||||
167 | Q_UNUSED(appname); | - | ||||||||||||||||||||||||
168 | Q_UNUSED(testname); | - | ||||||||||||||||||||||||
169 | return false; | - | ||||||||||||||||||||||||
170 | #endif | - | ||||||||||||||||||||||||
171 | } | - | ||||||||||||||||||||||||
172 | - | |||||||||||||||||||||||||
173 | static bool isValidSlot(const QMetaMethod &sl) | - | ||||||||||||||||||||||||
174 | { | - | ||||||||||||||||||||||||
175 | if (sl.access() != QMetaMethod::Private || sl.parameterCount() != 0
| 1289-19985 | ||||||||||||||||||||||||
176 | || sl.returnType() != QMetaType::Void || sl.methodType() != QMetaMethod::Slot)
| 0-18696 | ||||||||||||||||||||||||
177 | return false; executed 7115 times by 506 tests: return false; Executed by:
| 7115 | ||||||||||||||||||||||||
178 | const QByteArray name = sl.name(); | - | ||||||||||||||||||||||||
179 | return !(name.isEmpty() || name.endsWith("_data") executed 18696 times by 505 tests: return !(name.isEmpty() || name.endsWith("_data") || name == "initTestCase" || name == "cleanupTestCase" || name == "init" || name == "cleanup"); Executed by:
| 18696 | ||||||||||||||||||||||||
180 | || name == "initTestCase" || name == "cleanupTestCase" executed 18696 times by 505 tests: return !(name.isEmpty() || name.endsWith("_data") || name == "initTestCase" || name == "cleanupTestCase" || name == "init" || name == "cleanup"); Executed by:
| 18696 | ||||||||||||||||||||||||
181 | || name == "init" || name == "cleanup"); executed 18696 times by 505 tests: return !(name.isEmpty() || name.endsWith("_data") || name == "initTestCase" || name == "cleanupTestCase" || name == "init" || name == "cleanup"); Executed by:
| 18696 | ||||||||||||||||||||||||
182 | } | - | ||||||||||||||||||||||||
183 | - | |||||||||||||||||||||||||
184 | namespace QTest | - | ||||||||||||||||||||||||
185 | { | - | ||||||||||||||||||||||||
186 | class WatchDog; | - | ||||||||||||||||||||||||
187 | - | |||||||||||||||||||||||||
188 | static QObject *currentTestObject = 0; | - | ||||||||||||||||||||||||
189 | static QString mainSourcePath; | - | ||||||||||||||||||||||||
190 | - | |||||||||||||||||||||||||
191 | class TestFunctionTestMethods { | - | ||||||||||||||||||||||||
192 | Q_DISABLE_COPY(TestMethods) | - | ||||||||||||||||||||||||
193 | public: | - | ||||||||||||||||||||||||
TestFunction(): | ||||||||||||||||||||||||||
194 | function_(-1), data_typedef std::vector<QMetaMethod> MetaMethods; | - | ||||||||||||||||||||||||
195 | - | |||||||||||||||||||||||||
196 | explicit TestMethods(0) {}const QObject *o, const MetaMethods &m = MetaMethods()); | - | ||||||||||||||||||||||||
197 | - | |||||||||||||||||||||||||
198 | void setinvokeTests(int function, charQObject *datatestObject) { function_ = function; data_ = dataconst; | - | ||||||||||||||||||||||||
199 | - | |||||||||||||||||||||||||
200 | }static QMetaMethod findMethod(const QObject *obj, const char *signature); | - | ||||||||||||||||||||||||
201 | - | |||||||||||||||||||||||||
202 | private: | - | ||||||||||||||||||||||||
203 | bool invokeTest(int index, const char *data(), WatchDog *watchDog) const{ return data_; | - | ||||||||||||||||||||||||
204 | }void invokeTestOnData(int function()index) const{ return function_; | - | ||||||||||||||||||||||||
205 | - | |||||||||||||||||||||||||
206 | } | - | ||||||||||||||||||||||||
~TestFunction() { delete[] data_QMetaMethod m_initTestCaseMethod; } | ||||||||||||||||||||||||||
private: | ||||||||||||||||||||||||||
int function_// might not exist, check isValid(). | ||||||||||||||||||||||||||
207 | QMetaMethod m_initTestCaseDataMethod; | - | ||||||||||||||||||||||||
208 | char *data_QMetaMethod m_cleanupTestCaseMethod; | - | ||||||||||||||||||||||||
209 | QMetaMethod m_initMethod; | - | ||||||||||||||||||||||||
210 | QMetaMethod m_cleanupMethod; | - | ||||||||||||||||||||||||
211 | - | |||||||||||||||||||||||||
212 | MetaMethods m_methods; | - | ||||||||||||||||||||||||
213 | }; | - | ||||||||||||||||||||||||
214 | - | |||||||||||||||||||||||||
215 | static TestFunctionTestMethods::TestMethods(const QObject *testFuncso, const MetaMethods &m) | - | ||||||||||||||||||||||||
216 | : m_initTestCaseMethod(TestMethods::findMethod(o, "initTestCase()")) | - | ||||||||||||||||||||||||
217 | , m_initTestCaseDataMethod(TestMethods::findMethod(o, "initTestCase_data()")) | - | ||||||||||||||||||||||||
218 | , m_cleanupTestCaseMethod(TestMethods::findMethod(o, "cleanupTestCase()")) | - | ||||||||||||||||||||||||
219 | , m_initMethod(TestMethods::findMethod(o, "init()")) | - | ||||||||||||||||||||||||
220 | , m_cleanupMethod(TestMethods::findMethod(o, "cleanup()")) | - | ||||||||||||||||||||||||
221 | , m_methods(m) | - | ||||||||||||||||||||||||
222 | { | - | ||||||||||||||||||||||||
223 | if (m.empty()) {
| 39-1281 | ||||||||||||||||||||||||
224 | const QMetaObject *metaObject = 0; | - | ||||||||||||||||||||||||
statico->metaObject(); | ||||||||||||||||||||||||||
225 | const int testFuncCountcount = metaObject->methodCount(); | - | ||||||||||||||||||||||||
226 | m_methods.reserve(count); | - | ||||||||||||||||||||||||
227 | for (int i
| 1281-25703 | ||||||||||||||||||||||||
228 | void cleanup()const QMetaMethod me = metaObject->method(i); | - | ||||||||||||||||||||||||
229 | if (isValidSlot(me))
| 12327-13376 | ||||||||||||||||||||||||
230 | m_methods.push_back(me); executed 13376 times by 504 tests: m_methods.push_back(me); Executed by:
| 13376 | ||||||||||||||||||||||||
231 | } executed 25703 times by 506 tests: end of block Executed by:
| 25703 | ||||||||||||||||||||||||
232 | } executed 1281 times by 506 tests: end of block Executed by:
| 1281 | ||||||||||||||||||||||||
233 | } executed 1320 times by 506 tests: end of block Executed by:
| 1320 | ||||||||||||||||||||||||
234 | - | |||||||||||||||||||||||||
235 | QMetaMethod TestMethods::findMethod(const QObject *obj, const char *signature) | - | ||||||||||||||||||||||||
236 | { | - | ||||||||||||||||||||||||
237 | delete[] testFuncs; | - | ||||||||||||||||||||||||
testFuncCountconst QMetaObject *metaObject = 0; | ||||||||||||||||||||||||||
testFuncsobj->metaObject(); | ||||||||||||||||||||||||||
238 | const int funcIndex = metaObject->indexOfMethod(signature); | - | ||||||||||||||||||||||||
239 | return funcIndex >= executed 6664 times by 506 tests: 0 ;return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); Executed by:
executed 6664 times by 506 tests: return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); Executed by:
| 6664 | ||||||||||||||||||||||||
} executed 6664 times by 506 tests: return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); Executed by:
| ||||||||||||||||||||||||||
~TestFuncCleanup() { cleanup executed 6664 times by 506 tests: ? metaObject->method(funcIndex) : QMetaMethod();return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); Executed by:
executed 6664 times by 506 tests: return funcIndex >= 0 ? metaObject->method(funcIndex) : QMetaMethod(); Executed by:
| ||||||||||||||||||||||||||
240 | }} | - | ||||||||||||||||||||||||
241 | - | |||||||||||||||||||||||||
242 | testFuncCleaner;static int keyDelay = -1; | - | ||||||||||||||||||||||||
243 | static int mouseDelay = -1; | - | ||||||||||||||||||||||||
244 | static int eventDelay = -1; | - | ||||||||||||||||||||||||
245 | static int timeout = -1; | - | ||||||||||||||||||||||||
246 | static bool noCrashHandler = false; | - | ||||||||||||||||||||||||
247 | - | |||||||||||||||||||||||||
248 | /*! \internal | - | ||||||||||||||||||||||||
249 | Invoke a method of the object without generating warning if the method does not exist | - | ||||||||||||||||||||||||
250 | */ | - | ||||||||||||||||||||||||
251 | static void invokeMethod(QObject *obj, const char *methodName) | - | ||||||||||||||||||||||||
252 | { | - | ||||||||||||||||||||||||
253 | const QMetaObject *metaObject = obj->metaObject(); | - | ||||||||||||||||||||||||
254 | int funcIndex = metaObject->indexOfMethod(methodName); | - | ||||||||||||||||||||||||
255 | if (funcIndex >= 0) { | - | ||||||||||||||||||||||||
256 | QMetaMethod method = metaObject->method(funcIndex); | - | ||||||||||||||||||||||||
257 | method.invoke(obj, Qt::DirectConnection); | - | ||||||||||||||||||||||||
258 | } | - | ||||||||||||||||||||||||
259 | } | - | ||||||||||||||||||||||||
260 | - | |||||||||||||||||||||||||
261 | int defaultEventDelay() | - | ||||||||||||||||||||||||
262 | { | - | ||||||||||||||||||||||||
263 | if (eventDelay == -1) { | - | ||||||||||||||||||||||||
264 | const QByteArray env = qgetenv("QTEST_EVENT_DELAY"); | - | ||||||||||||||||||||||||
265 | if (!env.isEmpty()) | - | ||||||||||||||||||||||||
266 | eventDelay = atoi(env.constData()); | - | ||||||||||||||||||||||||
267 | else | - | ||||||||||||||||||||||||
268 | eventDelay = 0; | - | ||||||||||||||||||||||||
269 | } | - | ||||||||||||||||||||||||
270 | return eventDelay; | - | ||||||||||||||||||||||||
271 | } | - | ||||||||||||||||||||||||
272 | - | |||||||||||||||||||||||||
273 | int Q_TESTLIB_EXPORT defaultMouseDelay() | - | ||||||||||||||||||||||||
274 | { | - | ||||||||||||||||||||||||
275 | if (mouseDelay == -1) { | - | ||||||||||||||||||||||||
276 | const QByteArray env = qgetenv("QTEST_MOUSEEVENT_DELAY"); | - | ||||||||||||||||||||||||
277 | if (!env.isEmpty()) | - | ||||||||||||||||||||||||
278 | mouseDelay = atoi(env.constData()); | - | ||||||||||||||||||||||||
279 | else | - | ||||||||||||||||||||||||
280 | mouseDelay = defaultEventDelay(); | - | ||||||||||||||||||||||||
281 | } | - | ||||||||||||||||||||||||
282 | return mouseDelay; | - | ||||||||||||||||||||||||
283 | } | - | ||||||||||||||||||||||||
284 | - | |||||||||||||||||||||||||
285 | int Q_TESTLIB_EXPORT defaultKeyDelay() | - | ||||||||||||||||||||||||
286 | { | - | ||||||||||||||||||||||||
287 | if (keyDelay == -1) { | - | ||||||||||||||||||||||||
288 | const QByteArray env = qgetenv("QTEST_KEYEVENT_DELAY"); | - | ||||||||||||||||||||||||
289 | if (!env.isEmpty()) | - | ||||||||||||||||||||||||
290 | keyDelay = atoi(env.constData()); | - | ||||||||||||||||||||||||
291 | else | - | ||||||||||||||||||||||||
292 | keyDelay = defaultEventDelay(); | - | ||||||||||||||||||||||||
293 | } | - | ||||||||||||||||||||||||
294 | return keyDelay; | - | ||||||||||||||||||||||||
295 | } | - | ||||||||||||||||||||||||
296 | - | |||||||||||||||||||||||||
297 | static int defaultTimeout() | - | ||||||||||||||||||||||||
298 | { | - | ||||||||||||||||||||||||
299 | if (timeout == -1) { | - | ||||||||||||||||||||||||
300 | bool ok = false; | - | ||||||||||||||||||||||||
301 | timeout = qEnvironmentVariableIntValue("QTEST_FUNCTION_TIMEOUT", &ok); | - | ||||||||||||||||||||||||
302 | - | |||||||||||||||||||||||||
303 | if (!ok || timeout <= 0) | - | ||||||||||||||||||||||||
304 | timeout = 5*60*1000; | - | ||||||||||||||||||||||||
305 | } | - | ||||||||||||||||||||||||
306 | return timeout; | - | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
static bool isValidSlot(const QMetaMethod &sl) | ||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||
if (sl.access() != QMetaMethod::Private || sl.parameterCount() != 0 | ||||||||||||||||||||||||||
|| sl.returnType() != QMetaType::Void || sl.methodType() != QMetaMethod::Slot) | ||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||
QByteArray name = sl.name(); | ||||||||||||||||||||||||||
if (name.isEmpty()) | ||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||
if (name.endsWith("_data")) | ||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||
if (name == "initTestCase" || name == "cleanupTestCase" | ||||||||||||||||||||||||||
|| name == "cleanup" || name == "init") | ||||||||||||||||||||||||||
return false; | ||||||||||||||||||||||||||
return true; | ||||||||||||||||||||||||||
307 | } | - | ||||||||||||||||||||||||
308 | - | |||||||||||||||||||||||||
309 | Q_TESTLIB_EXPORT bool printAvailableFunctions = false; | - | ||||||||||||||||||||||||
310 | Q_TESTLIB_EXPORT QStringList testFunctions; | - | ||||||||||||||||||||||||
311 | Q_TESTLIB_EXPORT QStringList testTags; | - | ||||||||||||||||||||||||
312 | - | |||||||||||||||||||||||||
313 | static void qPrintTestSlots(FILE *stream, const char *filter = 0) | - | ||||||||||||||||||||||||
314 | { | - | ||||||||||||||||||||||||
315 | for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { | - | ||||||||||||||||||||||||
316 | QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); | - | ||||||||||||||||||||||||
317 | if (isValidSlot(sl)) { | - | ||||||||||||||||||||||||
318 | const QByteArray signature = sl.methodSignature(); | - | ||||||||||||||||||||||||
319 | if (!filter || QString::fromLatin1(signature).contains(QLatin1String(filter), Qt::CaseInsensitive)) | - | ||||||||||||||||||||||||
320 | fprintf(stream, "%s\n", signature.constData()); | - | ||||||||||||||||||||||||
321 | } | - | ||||||||||||||||||||||||
322 | } | - | ||||||||||||||||||||||||
323 | } | - | ||||||||||||||||||||||||
324 | - | |||||||||||||||||||||||||
325 | static void qPrintDataTags(FILE *stream) | - | ||||||||||||||||||||||||
326 | { | - | ||||||||||||||||||||||||
327 | // Avoid invoking the actual test functions, and also avoid printing irrelevant output: | - | ||||||||||||||||||||||||
328 | QTestLog::setPrintAvailableTagsMode(); | - | ||||||||||||||||||||||||
329 | - | |||||||||||||||||||||||||
330 | // Get global data tags: | - | ||||||||||||||||||||||||
331 | QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
332 | invokeMethod(QTest::currentTestObject, "initTestCase_data()"); | - | ||||||||||||||||||||||||
333 | const QTestTable *gTable = QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
334 | - | |||||||||||||||||||||||||
335 | const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject(); | - | ||||||||||||||||||||||||
336 | - | |||||||||||||||||||||||||
337 | // Process test functions: | - | ||||||||||||||||||||||||
338 | for (int i = 0; i < currTestMetaObj->methodCount(); ++i) { | - | ||||||||||||||||||||||||
339 | QMetaMethod tf = currTestMetaObj->method(i); | - | ||||||||||||||||||||||||
340 | - | |||||||||||||||||||||||||
341 | if (isValidSlot(tf)) { | - | ||||||||||||||||||||||||
342 | - | |||||||||||||||||||||||||
343 | // Retrieve local tags: | - | ||||||||||||||||||||||||
344 | QStringList localTags; | - | ||||||||||||||||||||||||
345 | QTestTable table; | - | ||||||||||||||||||||||||
346 | char *slot = qstrdup(tf.methodSignature().constData()); | - | ||||||||||||||||||||||||
347 | slot[strlen(slot) - 2] = '\0'; | - | ||||||||||||||||||||||||
348 | QByteArray member; | - | ||||||||||||||||||||||||
349 | member.resize(qstrlen(slot) + qstrlen("_data()") + 1); | - | ||||||||||||||||||||||||
350 | qsnprintf(member.data(), member.size(), "%s_data()", slot); | - | ||||||||||||||||||||||||
351 | invokeMethod(QTest::currentTestObject, member.constData()); | - | ||||||||||||||||||||||||
352 | const int dataCount = table.dataCount(); | - | ||||||||||||||||||||||||
353 | localTags.reserve(dataCount); | - | ||||||||||||||||||||||||
354 | for (int j = 0; j < dataCount; ++j) | - | ||||||||||||||||||||||||
355 | localTags << QLatin1String(table.testData(j)->dataTag()); | - | ||||||||||||||||||||||||
356 | - | |||||||||||||||||||||||||
357 | // Print all tag combinations: | - | ||||||||||||||||||||||||
358 | if (gTable->dataCount() == 0) { | - | ||||||||||||||||||||||||
359 | if (localTags.count() == 0) { | - | ||||||||||||||||||||||||
360 | // No tags at all, so just print the test function: | - | ||||||||||||||||||||||||
361 | fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot); | - | ||||||||||||||||||||||||
362 | } else { | - | ||||||||||||||||||||||||
363 | // Only local tags, so print each of them: | - | ||||||||||||||||||||||||
364 | for (int k = 0; k < localTags.size(); ++k) | - | ||||||||||||||||||||||||
365 | fprintf( | - | ||||||||||||||||||||||||
366 | stream, "%s %s %s\n", | - | ||||||||||||||||||||||||
367 | currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data()); | - | ||||||||||||||||||||||||
368 | } | - | ||||||||||||||||||||||||
369 | } else { | - | ||||||||||||||||||||||||
370 | for (int j = 0; j < gTable->dataCount(); ++j) { | - | ||||||||||||||||||||||||
371 | if (localTags.count() == 0) { | - | ||||||||||||||||||||||||
372 | // Only global tags, so print the current one: | - | ||||||||||||||||||||||||
373 | fprintf( | - | ||||||||||||||||||||||||
374 | stream, "%s %s __global__ %s\n", | - | ||||||||||||||||||||||||
375 | currTestMetaObj->className(), slot, gTable->testData(j)->dataTag()); | - | ||||||||||||||||||||||||
376 | } else { | - | ||||||||||||||||||||||||
377 | // Local and global tags, so print each of the local ones and | - | ||||||||||||||||||||||||
378 | // the current global one: | - | ||||||||||||||||||||||||
379 | for (int k = 0; k < localTags.size(); ++k) | - | ||||||||||||||||||||||||
380 | fprintf( | - | ||||||||||||||||||||||||
381 | stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, | - | ||||||||||||||||||||||||
382 | localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag()); | - | ||||||||||||||||||||||||
383 | } | - | ||||||||||||||||||||||||
384 | } | - | ||||||||||||||||||||||||
385 | } | - | ||||||||||||||||||||||||
386 | - | |||||||||||||||||||||||||
387 | delete[] slot; | - | ||||||||||||||||||||||||
388 | } | - | ||||||||||||||||||||||||
389 | } | - | ||||||||||||||||||||||||
390 | } | - | ||||||||||||||||||||||||
391 | - | |||||||||||||||||||||||||
392 | static int qToInt(char *str) | - | ||||||||||||||||||||||||
393 | { | - | ||||||||||||||||||||||||
394 | char *pEnd; | - | ||||||||||||||||||||||||
395 | int l = (int)strtol(str, &pEnd, 10); | - | ||||||||||||||||||||||||
396 | if (*pEnd != 0) { | - | ||||||||||||||||||||||||
397 | fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); | - | ||||||||||||||||||||||||
398 | exit(1); | - | ||||||||||||||||||||||||
399 | } | - | ||||||||||||||||||||||||
400 | return l; | - | ||||||||||||||||||||||||
401 | } | - | ||||||||||||||||||||||||
402 | - | |||||||||||||||||||||||||
403 | Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) | - | ||||||||||||||||||||||||
404 | { | - | ||||||||||||||||||||||||
405 | QTestLog::LogMode logFormat = QTestLog::Plain; | - | ||||||||||||||||||||||||
406 | const char *logFilename = 0; | - | ||||||||||||||||||||||||
407 | - | |||||||||||||||||||||||||
408 | QTest::testFunctions.clear(); | - | ||||||||||||||||||||||||
409 | QTest::testTags.clear(); | - | ||||||||||||||||||||||||
410 | - | |||||||||||||||||||||||||
411 | #if defined(Q_OS_MAC) && defined(HAVE_XCTEST) | - | ||||||||||||||||||||||||
412 | if (QXcodeTestLogger::canLogTestProgress()) | - | ||||||||||||||||||||||||
413 | logFormat = QTestLog::XCTest; | - | ||||||||||||||||||||||||
414 | #endif | - | ||||||||||||||||||||||||
415 | - | |||||||||||||||||||||||||
416 | const char *testOptions = | - | ||||||||||||||||||||||||
417 | " New-style logging options:\n" | - | ||||||||||||||||||||||||
418 | " -o filename,format : Output results to file in the specified format\n" | - | ||||||||||||||||||||||||
419 | " Use - to output to stdout\n" | - | ||||||||||||||||||||||||
420 | " Valid formats are:\n" | - | ||||||||||||||||||||||||
421 | " txt : Plain text\n" | - | ||||||||||||||||||||||||
422 | " csv : CSV format (suitable for benchmarks)\n" | - | ||||||||||||||||||||||||
423 | " xunitxml : XML XUnit document\n" | - | ||||||||||||||||||||||||
424 | " xml : XML document\n" | - | ||||||||||||||||||||||||
425 | " lightxml : A stream of XML tags\n" | - | ||||||||||||||||||||||||
426 | " teamcity : TeamCity format\n" | - | ||||||||||||||||||||||||
427 | "\n" | - | ||||||||||||||||||||||||
428 | " *** Multiple loggers can be specified, but at most one can log to stdout.\n" | - | ||||||||||||||||||||||||
429 | "\n" | - | ||||||||||||||||||||||||
430 | " Old-style logging options:\n" | - | ||||||||||||||||||||||||
431 | " -o filename : Write the output into file\n" | - | ||||||||||||||||||||||||
432 | " -txt : Output results in Plain Text\n" | - | ||||||||||||||||||||||||
433 | " -csv : Output results in a CSV format (suitable for benchmarks)\n" | - | ||||||||||||||||||||||||
434 | " -xunitxml : Output results as XML XUnit document\n" | - | ||||||||||||||||||||||||
435 | " -xml : Output results as XML document\n" | - | ||||||||||||||||||||||||
436 | " -lightxml : Output results as stream of XML tags\n" | - | ||||||||||||||||||||||||
437 | " -teamcity : Output results in TeamCity format\n" | - | ||||||||||||||||||||||||
438 | "\n" | - | ||||||||||||||||||||||||
439 | " *** If no output file is specified, stdout is assumed.\n" | - | ||||||||||||||||||||||||
440 | " *** If no output format is specified, -txt is assumed.\n" | - | ||||||||||||||||||||||||
441 | "\n" | - | ||||||||||||||||||||||||
442 | " Test log detail options:\n" | - | ||||||||||||||||||||||||
443 | " -silent : Log failures and fatal errors only\n" | - | ||||||||||||||||||||||||
444 | " -v1 : Log the start of each testfunction\n" | - | ||||||||||||||||||||||||
445 | " -v2 : Log each QVERIFY/QCOMPARE/QTEST (implies -v1)\n" | - | ||||||||||||||||||||||||
446 | " -vs : Log every signal emission and resulting slot invocations\n" | - | ||||||||||||||||||||||||
447 | "\n" | - | ||||||||||||||||||||||||
448 | " *** The -silent and -v1 options only affect plain text output.\n" | - | ||||||||||||||||||||||||
449 | "\n" | - | ||||||||||||||||||||||||
450 | " Testing options:\n" | - | ||||||||||||||||||||||||
451 | " -functions : Returns a list of current testfunctions\n" | - | ||||||||||||||||||||||||
452 | " -datatags : Returns a list of current data tags.\n" | - | ||||||||||||||||||||||||
453 | " A global data tag is preceded by ' __global__ '.\n" | - | ||||||||||||||||||||||||
454 | " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n" | - | ||||||||||||||||||||||||
455 | " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n" | - | ||||||||||||||||||||||||
456 | " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" | - | ||||||||||||||||||||||||
457 | " -maxwarnings n : Sets the maximum amount of messages to output.\n" | - | ||||||||||||||||||||||||
458 | " 0 means unlimited, default: 2000\n" | - | ||||||||||||||||||||||||
459 | " -nocrashhandler : Disables the crash handler. Useful for debugging crashes.\n" | - | ||||||||||||||||||||||||
460 | "\n" | - | ||||||||||||||||||||||||
461 | " Benchmarking options:\n" | - | ||||||||||||||||||||||||
462 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
463 | " -callgrind : Use callgrind to time benchmarks\n" | - | ||||||||||||||||||||||||
464 | #endif | - | ||||||||||||||||||||||||
465 | #ifdef QTESTLIB_USE_PERF_EVENTS | - | ||||||||||||||||||||||||
466 | " -perf : Use Linux perf events to time benchmarks\n" | - | ||||||||||||||||||||||||
467 | " -perfcounter name : Use the counter named 'name'\n" | - | ||||||||||||||||||||||||
468 | " -perfcounterlist : Lists the counters available\n" | - | ||||||||||||||||||||||||
469 | #endif | - | ||||||||||||||||||||||||
470 | #ifdef HAVE_TICK_COUNTER | - | ||||||||||||||||||||||||
471 | " -tickcounter : Use CPU tick counters to time benchmarks\n" | - | ||||||||||||||||||||||||
472 | #endif | - | ||||||||||||||||||||||||
473 | " -eventcounter : Counts events received during benchmarks\n" | - | ||||||||||||||||||||||||
474 | " -minimumvalue n : Sets the minimum acceptable measurement value\n" | - | ||||||||||||||||||||||||
475 | " -minimumtotal n : Sets the minimum acceptable total for repeated executions of a test function\n" | - | ||||||||||||||||||||||||
476 | " -iterations n : Sets the number of accumulation iterations.\n" | - | ||||||||||||||||||||||||
477 | " -median n : Sets the number of median iterations.\n" | - | ||||||||||||||||||||||||
478 | " -vb : Print out verbose benchmarking information.\n"; | - | ||||||||||||||||||||||||
479 | - | |||||||||||||||||||||||||
480 | for (int i = 1; i < argc; ++i) {
| 811-1387 | ||||||||||||||||||||||||
481 | if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0
| 0-1387 | ||||||||||||||||||||||||
482 | || strcmp(argv[i], "/?") == 0) {
| 0-1387 | ||||||||||||||||||||||||
483 | printf(" Usage: %s [options] [testfunction[:testdata]]...\n" | - | ||||||||||||||||||||||||
484 | " By default, all testfunctions will be run.\n\n" | - | ||||||||||||||||||||||||
485 | "%s", argv[0], testOptions); | - | ||||||||||||||||||||||||
486 | - | |||||||||||||||||||||||||
487 | if (qml) {
| 0 | ||||||||||||||||||||||||
488 | printf ("\n" | - | ||||||||||||||||||||||||
489 | " QmlTest options:\n" | - | ||||||||||||||||||||||||
490 | " -import dir : Specify an import directory.\n" | - | ||||||||||||||||||||||||
491 | " -plugins dir : Specify a directory where to search for plugins.\n" | - | ||||||||||||||||||||||||
492 | " -input dir/file : Specify the root directory for test cases or a single test case file.\n" | - | ||||||||||||||||||||||||
493 | " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" | - | ||||||||||||||||||||||||
494 | " -translation file : Specify the translation file.\n" | - | ||||||||||||||||||||||||
495 | ); | - | ||||||||||||||||||||||||
496 | } never executed: end of block | 0 | ||||||||||||||||||||||||
497 | - | |||||||||||||||||||||||||
498 | printf("\n" | - | ||||||||||||||||||||||||
499 | " -help : This help\n"); | - | ||||||||||||||||||||||||
500 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||||||||
501 | } else if (strcmp(argv[i], "-functions") == 0) {
| 0-1387 | ||||||||||||||||||||||||
502 | if (qml) {
| 0 | ||||||||||||||||||||||||
503 | QTest::printAvailableFunctions = true; | - | ||||||||||||||||||||||||
504 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
505 | qPrintTestSlots(stdout); | - | ||||||||||||||||||||||||
506 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||||||||
507 | } | - | ||||||||||||||||||||||||
508 | } else if (strcmp(argv[i], "-datatags") == 0) {
| 4-1383 | ||||||||||||||||||||||||
509 | if (!qml) {
| 0-4 | ||||||||||||||||||||||||
510 | qPrintDataTags(stdout); | - | ||||||||||||||||||||||||
511 | exit(0); executed 4 times by 1 test: exit(0); Executed by:
| 4 | ||||||||||||||||||||||||
512 | } | - | ||||||||||||||||||||||||
513 | } else if (strcmp(argv[i], "-txt") == 0) { never executed: end of block
| 0-1383 | ||||||||||||||||||||||||
514 | logFormat = QTestLog::Plain; | - | ||||||||||||||||||||||||
515 | } else if (strcmp(argv[i], "-csv") == 0) { never executed: end of block
| 0-1379 | ||||||||||||||||||||||||
516 | logFormat = QTestLog::CSV; | - | ||||||||||||||||||||||||
517 | } else if (strcmp(argv[i], "-xunitxml") == 0) { executed 4 times by 1 test: end of block Executed by:
| 4-1317 | ||||||||||||||||||||||||
518 | logFormat = QTestLog::XunitXML; | - | ||||||||||||||||||||||||
519 | } else if (strcmp(argv[i], "-xml") == 0) { executed 62 times by 1 test: end of block Executed by:
| 62-1255 | ||||||||||||||||||||||||
520 | logFormat = QTestLog::XML; | - | ||||||||||||||||||||||||
521 | } else if (strcmp(argv[i], "-lightxml") == 0) { executed 62 times by 1 test: end of block Executed by:
| 62-1193 | ||||||||||||||||||||||||
522 | logFormat = QTestLog::LightXML; | - | ||||||||||||||||||||||||
523 | } else if (strcmp(argv[i], "-teamcity") == 0) { executed 62 times by 1 test: end of block Executed by:
| 58-1135 | ||||||||||||||||||||||||
524 | logFormat = QTestLog::TeamCity; | - | ||||||||||||||||||||||||
525 | } else if (strcmp(argv[i], "-silent") == 0) { executed 58 times by 1 test: end of block Executed by:
| 2-1133 | ||||||||||||||||||||||||
526 | QTestLog::setVerboseLevel(-1); | - | ||||||||||||||||||||||||
527 | } else if (strcmp(argv[i], "-v1") == 0) { executed 2 times by 1 test: end of block Executed by:
| 2-1108 | ||||||||||||||||||||||||
528 | QTestLog::setVerboseLevel(1); | - | ||||||||||||||||||||||||
529 | } else if (strcmp(argv[i], "-v2") == 0) { executed 25 times by 1 test: end of block Executed by:
| 25-1058 | ||||||||||||||||||||||||
530 | QTestLog::setVerboseLevel(2); | - | ||||||||||||||||||||||||
531 | } else if (strcmp(argv[i], "-vs") == 0) { executed 50 times by 1 test: end of block Executed by:
| 0-1058 | ||||||||||||||||||||||||
532 | QSignalDumper::startDump(); | - | ||||||||||||||||||||||||
533 | } else if (strcmp(argv[i], "-o") == 0) { never executed: end of block
| 0-900 | ||||||||||||||||||||||||
534 | if (i + 1 >= argc) {
| 0-900 | ||||||||||||||||||||||||
535 | fprintf(stderr, "-o needs an extra parameter specifying the filename and optional format\n"); | - | ||||||||||||||||||||||||
536 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
537 | } | - | ||||||||||||||||||||||||
538 | ++i; | - | ||||||||||||||||||||||||
539 | // Do we have the old or new style -o option? | - | ||||||||||||||||||||||||
540 | char *filename = new char[strlen(argv[i])+1]; | - | ||||||||||||||||||||||||
541 | char *format = new char[strlen(argv[i])+1]; | - | ||||||||||||||||||||||||
542 | if (sscanf(argv[i], "%[^,],%s", filename, format) == 1) {
| 154-746 | ||||||||||||||||||||||||
543 | // Old-style | - | ||||||||||||||||||||||||
544 | logFilename = argv[i]; | - | ||||||||||||||||||||||||
545 | } else { executed 154 times by 1 test: end of block Executed by:
| 154 | ||||||||||||||||||||||||
546 | // New-style | - | ||||||||||||||||||||||||
547 | if (strcmp(format, "txt") == 0)
| 256-490 | ||||||||||||||||||||||||
548 | logFormat = QTestLog::Plain; executed 256 times by 1 test: logFormat = QTestLog::Plain; Executed by:
| 256 | ||||||||||||||||||||||||
549 | else if (strcmp(format, "csv") == 0)
| 4-486 | ||||||||||||||||||||||||
550 | logFormat = QTestLog::CSV; executed 4 times by 1 test: logFormat = QTestLog::CSV; Executed by:
| 4 | ||||||||||||||||||||||||
551 | else if (strcmp(format, "lightxml") == 0)
| 123-363 | ||||||||||||||||||||||||
552 | logFormat = QTestLog::LightXML; executed 123 times by 1 test: logFormat = QTestLog::LightXML; Executed by:
| 123 | ||||||||||||||||||||||||
553 | else if (strcmp(format, "xml") == 0)
| 122-241 | ||||||||||||||||||||||||
554 | logFormat = QTestLog::XML; executed 122 times by 1 test: logFormat = QTestLog::XML; Executed by:
| 122 | ||||||||||||||||||||||||
555 | else if (strcmp(format, "xunitxml") == 0)
| 88-153 | ||||||||||||||||||||||||
556 | logFormat = QTestLog::XunitXML; executed 153 times by 1 test: logFormat = QTestLog::XunitXML; Executed by:
| 153 | ||||||||||||||||||||||||
557 | else if (strcmp(format, "teamcity") == 0)
| 0-88 | ||||||||||||||||||||||||
558 | logFormat = QTestLog::TeamCity executed 88 times by 1 test: ;logFormat = QTestLog::TeamCity; Executed by:
executed 88 times by 1 test: logFormat = QTestLog::TeamCity; Executed by:
| 88 | ||||||||||||||||||||||||
559 | else { | - | ||||||||||||||||||||||||
560 | fprintf(stderr, "output format must be one of txt, csv, lightxml, xml, teamcity or xunitxml\n"); | - | ||||||||||||||||||||||||
561 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
562 | } | - | ||||||||||||||||||||||||
563 | if (strcmp(filename, "-") == 0 && QTestLog::loggerUsingStdout()) {
| 0-455 | ||||||||||||||||||||||||
564 | fprintf(stderr, "only one logger can log to stdout\n"); | - | ||||||||||||||||||||||||
565 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
566 | } | - | ||||||||||||||||||||||||
567 | QTestLog::addLogger(logFormat, filename); | - | ||||||||||||||||||||||||
568 | } executed 746 times by 1 test: end of block Executed by:
| 746 | ||||||||||||||||||||||||
569 | delete [] filename; | - | ||||||||||||||||||||||||
570 | delete [] format; | - | ||||||||||||||||||||||||
571 | } else if (strcmp(argv[i], "-eventdelay") == 0) { executed 900 times by 1 test: end of block Executed by:
| 0-900 | ||||||||||||||||||||||||
572 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
573 | fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); | - | ||||||||||||||||||||||||
574 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
575 | } else { | - | ||||||||||||||||||||||||
576 | QTest::eventDelay = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
577 | } never executed: end of block | 0 | ||||||||||||||||||||||||
578 | } else if (strcmp(argv[i], "-keydelay") == 0) {
| 0-158 | ||||||||||||||||||||||||
579 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
580 | fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); | - | ||||||||||||||||||||||||
581 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
582 | } else { | - | ||||||||||||||||||||||||
583 | QTest::keyDelay = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
584 | } never executed: end of block | 0 | ||||||||||||||||||||||||
585 | } else if (strcmp(argv[i], "-mousedelay") == 0) {
| 0-158 | ||||||||||||||||||||||||
586 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
587 | fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); | - | ||||||||||||||||||||||||
588 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
589 | } else { | - | ||||||||||||||||||||||||
590 | QTest::mouseDelay = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
591 | } never executed: end of block | 0 | ||||||||||||||||||||||||
592 | } else if (strcmp(argv[i], "-maxwarnings") == 0) {
| 0-158 | ||||||||||||||||||||||||
593 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
594 | fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); | - | ||||||||||||||||||||||||
595 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
596 | } else { | - | ||||||||||||||||||||||||
597 | QTestLog::setMaxWarnings(qToInt(argv[++i])); | - | ||||||||||||||||||||||||
598 | } never executed: end of block | 0 | ||||||||||||||||||||||||
599 | } else if (strcmp(argv[i], "-nocrashhandler") == 0) {
| 0-158 | ||||||||||||||||||||||||
600 | QTest::noCrashHandler = true; | - | ||||||||||||||||||||||||
601 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
602 | } else if (strcmp(argv[i], "-callgrind") == 0) { never executed: end of block
| 0-158 | ||||||||||||||||||||||||
603 | if (QBenchmarkValgrindUtils::haveValgrind())
| 0 | ||||||||||||||||||||||||
604 | if (QFileInfo(QDir::currentPath()).isWritable()) {
| 0 | ||||||||||||||||||||||||
605 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); | - | ||||||||||||||||||||||||
606 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
607 | fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); | - | ||||||||||||||||||||||||
608 | } never executed: end of block | 0 | ||||||||||||||||||||||||
609 | else { | - | ||||||||||||||||||||||||
610 | fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " | - | ||||||||||||||||||||||||
611 | "Using the walltime measurer.\n"); | - | ||||||||||||||||||||||||
612 | } never executed: end of block | 0 | ||||||||||||||||||||||||
613 | } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option
| 0-158 | ||||||||||||||||||||||||
614 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindChildProcess); | - | ||||||||||||||||||||||||
615 | QBenchmarkGlobalData::current->callgrindOutFileBase = | - | ||||||||||||||||||||||||
616 | QBenchmarkValgrindUtils::outFileBase(); | - | ||||||||||||||||||||||||
617 | #endif | - | ||||||||||||||||||||||||
618 | #ifdef QTESTLIB_USE_PERF_EVENTS | - | ||||||||||||||||||||||||
619 | } else if (strcmp(argv[i], "-perf") == 0) { never executed: end of block
| 0-158 | ||||||||||||||||||||||||
620 | if (QBenchmarkPerfEventsMeasurer::isAvailable()) {
| 0 | ||||||||||||||||||||||||
621 | // perf available | - | ||||||||||||||||||||||||
622 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::PerfCounter); | - | ||||||||||||||||||||||||
623 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
624 | fprintf(stderr, "WARNING: Linux perf events not available. Using the walltime measurer.\n"); | - | ||||||||||||||||||||||||
625 | } never executed: end of block | 0 | ||||||||||||||||||||||||
626 | } else if (strcmp(argv[i], "-perfcounter") == 0) {
| 0-158 | ||||||||||||||||||||||||
627 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
628 | fprintf(stderr, "-perfcounter needs an extra parameter with the name of the counter\n"); | - | ||||||||||||||||||||||||
629 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
630 | } else { | - | ||||||||||||||||||||||||
631 | QBenchmarkPerfEventsMeasurer::setCounter(argv[++i]); | - | ||||||||||||||||||||||||
632 | } never executed: end of block | 0 | ||||||||||||||||||||||||
633 | } else if (strcmp(argv[i], "-perfcounterlist") == 0) {
| 0-158 | ||||||||||||||||||||||||
634 | QBenchmarkPerfEventsMeasurer::listCounters(); | - | ||||||||||||||||||||||||
635 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||||||||
636 | #endif | - | ||||||||||||||||||||||||
637 | #ifdef HAVE_TICK_COUNTER | - | ||||||||||||||||||||||||
638 | } else if (strcmp(argv[i], "-tickcounter") == 0) {
| 0-158 | ||||||||||||||||||||||||
639 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::TickCounter); | - | ||||||||||||||||||||||||
640 | #endif | - | ||||||||||||||||||||||||
641 | } else if (strcmp(argv[i], "-eventcounter") == 0) { never executed: end of block
| 0-85 | ||||||||||||||||||||||||
642 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::EventCounter); | - | ||||||||||||||||||||||||
643 | } else if (strcmp(argv[i], "-minimumvalue") == 0) { executed 73 times by 1 test: end of block Executed by:
| 2-83 | ||||||||||||||||||||||||
644 | if (i + 1 >= argc) {
| 0-2 | ||||||||||||||||||||||||
645 | fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); | - | ||||||||||||||||||||||||
646 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
647 | } else { | - | ||||||||||||||||||||||||
648 | QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
649 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||||||||
650 | } else if (strcmp(argv[i], "-minimumtotal") == 0) {
| 0-83 | ||||||||||||||||||||||||
651 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
652 | fprintf(stderr, "-minimumtotal needs an extra parameter to indicate the minimum total measurement\n"); | - | ||||||||||||||||||||||||
653 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
654 | } else { | - | ||||||||||||||||||||||||
655 | QBenchmarkGlobalData::current->minimumTotal = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
656 | } never executed: end of block | 0 | ||||||||||||||||||||||||
657 | } else if (strcmp(argv[i], "-iterations") == 0) {
| 19-64 | ||||||||||||||||||||||||
658 | if (i + 1 >= argc) {
| 0-19 | ||||||||||||||||||||||||
659 | fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); | - | ||||||||||||||||||||||||
660 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
661 | } else { | - | ||||||||||||||||||||||||
662 | QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
663 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||||||||||||||
664 | } else if (strcmp(argv[i], "-median") == 0) {
| 0-64 | ||||||||||||||||||||||||
665 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
666 | fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); | - | ||||||||||||||||||||||||
667 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
668 | } else { | - | ||||||||||||||||||||||||
669 | QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
670 | } never executed: end of block | 0 | ||||||||||||||||||||||||
671 | - | |||||||||||||||||||||||||
672 | } else if (strcmp(argv[i], "-vb") == 0) {
| 0-64 | ||||||||||||||||||||||||
673 | QBenchmarkGlobalData::current->verboseOutput = true; | - | ||||||||||||||||||||||||
674 | #if defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
675 | } else if (strncmp(argv[i], "-ServerName:", 12) == 0 || | - | ||||||||||||||||||||||||
676 | strncmp(argv[i], "-qdevel", 7) == 0) { | - | ||||||||||||||||||||||||
677 | continue; | - | ||||||||||||||||||||||||
678 | #elif defined(Q_OS_MAC) && defined(HAVE_XCTEST) | - | ||||||||||||||||||||||||
679 | } else if (int skip = QXcodeTestLogger::parseCommandLineArgument(argv[i])) { | - | ||||||||||||||||||||||||
680 | i += (skip - 1); // Eating argv[i] with a continue counts towards skips | - | ||||||||||||||||||||||||
681 | continue; | - | ||||||||||||||||||||||||
682 | #endif | - | ||||||||||||||||||||||||
683 | } else if (argv[i][0] == '-') { never executed: end of block
| 0-64 | ||||||||||||||||||||||||
684 | fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); | - | ||||||||||||||||||||||||
685 | if (qml) {
| 0 | ||||||||||||||||||||||||
686 | fprintf(stderr, "\nqmltest related options:\n" | - | ||||||||||||||||||||||||
687 | " -import : Specify an import directory.\n" | - | ||||||||||||||||||||||||
688 | " -plugins : Specify a directory where to search for plugins.\n" | - | ||||||||||||||||||||||||
689 | " -input : Specify the root directory for test cases.\n" | - | ||||||||||||||||||||||||
690 | " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" | - | ||||||||||||||||||||||||
691 | ); | - | ||||||||||||||||||||||||
692 | } never executed: end of block | 0 | ||||||||||||||||||||||||
693 | - | |||||||||||||||||||||||||
694 | fprintf(stderr, "\n" | - | ||||||||||||||||||||||||
695 | " -help : This help\n"); | - | ||||||||||||||||||||||||
696 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
697 | } else if (qml){ | - | ||||||||||||||||||||||||
698 | // We can't check the availability of test functions until | - | ||||||||||||||||||||||||
699 | // we load the QML files. So just store the data for now. | - | ||||||||||||||||||||||||
700 | int colon = -1; | - | ||||||||||||||||||||||||
701 | int offset; | - | ||||||||||||||||||||||||
702 | for (offset = 0; *(argv[i]+offset); ++offset) {
| 37-865 | ||||||||||||||||||||||||
703 | if (*(argv[i]+offset) == ':') {
| 27-838 | ||||||||||||||||||||||||
704 | if (*(argv[i]+offset+1) == ':') {
| 0-27 | ||||||||||||||||||||||||
705 | // "::" is used as a test name separator. | - | ||||||||||||||||||||||||
706 | // e.g. "ClickTests::test_click:row1". | - | ||||||||||||||||||||||||
707 | ++offset; | - | ||||||||||||||||||||||||
708 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
709 | colon = offset; | - | ||||||||||||||||||||||||
710 | break; executed 27 times by 1 test: break; Executed by:
| 27 | ||||||||||||||||||||||||
711 | } | - | ||||||||||||||||||||||||
712 | } | - | ||||||||||||||||||||||||
713 | } executed 838 times by 1 test: end of block Executed by:
| 838 | ||||||||||||||||||||||||
714 | if (colon == -1) {
| 27-37 | ||||||||||||||||||||||||
715 | QTest::testFunctions += QString::fromLatin1(argv[i]); | - | ||||||||||||||||||||||||
716 | QTest::testTags += QString(); | - | ||||||||||||||||||||||||
717 | } else { executed 37 times by 1 test: end of block Executed by:
| 37 | ||||||||||||||||||||||||
718 | QTest::testFunctions += | - | ||||||||||||||||||||||||
719 | QString::fromLatin1(argv[i], colon); | - | ||||||||||||||||||||||||
720 | QTest::testTags += | - | ||||||||||||||||||||||||
721 | QString::fromLatin1(argv[i] + colon+ 1); | - | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||
if (!QTest::testFuncs) { | ||||||||||||||||||||||||||
QTest::testFuncs = new QTest::TestFunction[512]; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
int colon = -1; | ||||||||||||||||||||||||||
char buf[512], *data=0; | ||||||||||||||||||||||||||
int off; | ||||||||||||||||||||||||||
for (off = 0; *(argv[i]+off); ++off) { | ||||||||||||||||||||||||||
if (*(argv[i]+off) == ':') { | ||||||||||||||||||||||||||
colon = off; | ||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
if (colon != -1) { | ||||||||||||||||||||||||||
data = qstrdup(argv[i]+colon +1); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
qsnprintf(buf, qMin(512, off + 1), "%s", argv[i]); qsnprintf(buf+ off, qMin(512 - off, 3), "()"); int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); | ||||||||||||||||||||||||||
if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) { | ||||||||||||||||||||||||||
fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n", buf); | ||||||||||||||||||||||||||
buf[off] = 0; | ||||||||||||||||||||||||||
qPrintTestSlots(stderr, buf); | ||||||||||||||||||||||||||
fprintf(stderr, "\n%s -functions\nlists all available test functions.\n", argv[0]); | ||||||||||||||||||||||||||
exit(1); | ||||||||||||||||||||||||||
722 | } executed 27 times by 1 test: end of block Executed by:
| 27 | ||||||||||||||||||||||||
723 | testFuncs[testFuncCount].set(idx, data); | - | ||||||||||||||||||||||||
testFuncCount++; | ||||||||||||||||||||||||||
QTEST_ASSERT(QTest::testFuncCount < 512);} | ||||||||||||||||||||||||||
724 | } | - | ||||||||||||||||||||||||
725 | - | |||||||||||||||||||||||||
726 | bool installedTestCoverage = installCoverageTool(QTestResult::currentAppName(), QTestResult::currentTestObjectName()); | - | ||||||||||||||||||||||||
727 | QTestLog::setInstalledTestCoverage(installedTestCoverage); | - | ||||||||||||||||||||||||
728 | - | |||||||||||||||||||||||||
729 | // If no loggers were created by the long version of the -o command-line | - | ||||||||||||||||||||||||
730 | // option, create a logger using whatever filename and format were | - | ||||||||||||||||||||||||
731 | // set using the old-style command-line options. | - | ||||||||||||||||||||||||
732 | if (QTestLog::loggerCount() == 0)
| 473-847 | ||||||||||||||||||||||||
733 | QTestLog::addLogger(logFormat, logFilename); executed 847 times by 506 tests: QTestLog::addLogger(logFormat, logFilename); Executed by:
| 847 | ||||||||||||||||||||||||
734 | } executed 1320 times by 506 tests: end of block Executed by:
| 1320 | ||||||||||||||||||||||||
735 | - | |||||||||||||||||||||||||
736 | QBenchmarkResult qMedian(const QVector<QBenchmarkResult> &container) | - | ||||||||||||||||||||||||
737 | { | - | ||||||||||||||||||||||||
738 | const int count = container.count(); | - | ||||||||||||||||||||||||
739 | if (count == 0) | - | ||||||||||||||||||||||||
740 | return QBenchmarkResult(); | - | ||||||||||||||||||||||||
741 | - | |||||||||||||||||||||||||
742 | if (count == 1) | - | ||||||||||||||||||||||||
743 | return container.front(); | - | ||||||||||||||||||||||||
744 | - | |||||||||||||||||||||||||
745 | QVector<QBenchmarkResult> containerCopy = container; | - | ||||||||||||||||||||||||
746 | std::sort(containerCopy.begin(), containerCopy.end()); | - | ||||||||||||||||||||||||
747 | - | |||||||||||||||||||||||||
748 | const int middle = count / 2; | - | ||||||||||||||||||||||||
749 | - | |||||||||||||||||||||||||
750 | // ### handle even-sized containers here by doing an aritmetic mean of the two middle items. | - | ||||||||||||||||||||||||
751 | return containerCopy.at(middle); | - | ||||||||||||||||||||||||
752 | } | - | ||||||||||||||||||||||||
753 | - | |||||||||||||||||||||||||
754 | struct QTestDataSetter | - | ||||||||||||||||||||||||
755 | { | - | ||||||||||||||||||||||||
756 | QTestDataSetter(QTestData *data) | - | ||||||||||||||||||||||||
757 | { | - | ||||||||||||||||||||||||
758 | QTestResult::setCurrentTestData(data); | - | ||||||||||||||||||||||||
759 | } | - | ||||||||||||||||||||||||
760 | ~QTestDataSetter() | - | ||||||||||||||||||||||||
761 | { | - | ||||||||||||||||||||||||
762 | QTestResult::setCurrentTestData(0); | - | ||||||||||||||||||||||||
763 | } | - | ||||||||||||||||||||||||
764 | }; | - | ||||||||||||||||||||||||
765 | - | |||||||||||||||||||||||||
766 | namespace { | - | ||||||||||||||||||||||||
767 | - | |||||||||||||||||||||||||
768 | qreal addResult(qreal current, const QBenchmarkResult& r) | - | ||||||||||||||||||||||||
769 | { | - | ||||||||||||||||||||||||
770 | return current + r.value; | - | ||||||||||||||||||||||||
771 | } | - | ||||||||||||||||||||||||
772 | - | |||||||||||||||||||||||||
773 | } | - | ||||||||||||||||||||||||
774 | - | |||||||||||||||||||||||||
staticvoid qInvokeTestMethodDataEntryTestMethods::invokeTestOnData(char *slotint index) const | ||||||||||||||||||||||||||
776 | { | - | ||||||||||||||||||||||||
777 | /* Benchmarking: for each median iteration*/ | - | ||||||||||||||||||||||||
778 | - | |||||||||||||||||||||||||
779 | bool isBenchmark = false; | - | ||||||||||||||||||||||||
780 | int i = (QBenchmarkGlobalData::current->measurer->needsWarmupIteration()) ? -1 : 0;
| 494-126116 | ||||||||||||||||||||||||
781 | - | |||||||||||||||||||||||||
782 | QVector<QBenchmarkResult> results; | - | ||||||||||||||||||||||||
783 | bool minimumTotalReached = false; | - | ||||||||||||||||||||||||
784 | do { | - | ||||||||||||||||||||||||
785 | QBenchmarkTestMethodData::current->beginDataRun(); | - | ||||||||||||||||||||||||
786 | - | |||||||||||||||||||||||||
787 | /* Benchmarking: for each accumulation iteration*/ | - | ||||||||||||||||||||||||
788 | bool invokeOk; | - | ||||||||||||||||||||||||
789 | do { | - | ||||||||||||||||||||||||
790 | invokeMethodif (m_initMethod.isValid())
| 14076-112554 | ||||||||||||||||||||||||
791 | m_initMethod.invoke executed 14076 times by 100 tests: (QTest::currentTestObject, "init()"Qt::DirectConnection);m_initMethod.invoke(QTest::currentTestObject, Qt::DirectConnection); Executed by:
executed 14076 times by 100 tests: m_initMethod.invoke(QTest::currentTestObject, Qt::DirectConnection); Executed by:
| 14076 | ||||||||||||||||||||||||
792 | if (QTestResult::skipCurrentTest() || QTestResult::currentTestFailed())
| 75-126555 | ||||||||||||||||||||||||
793 | break; executed 150 times by 1 test: break; Executed by:
| 150 | ||||||||||||||||||||||||
794 | - | |||||||||||||||||||||||||
795 | QBenchmarkTestMethodData::current->result = QBenchmarkResult(); | - | ||||||||||||||||||||||||
796 | QBenchmarkTestMethodData::current->resultAccepted = false; | - | ||||||||||||||||||||||||
797 | - | |||||||||||||||||||||||||
798 | QBenchmarkGlobalData::current->context.tag = | - | ||||||||||||||||||||||||
799 | QLatin1String( | - | ||||||||||||||||||||||||
800 | QTestResult::currentDataTag() | - | ||||||||||||||||||||||||
801 | ? QTestResult::currentDataTag() : ""); | - | ||||||||||||||||||||||||
802 | - | |||||||||||||||||||||||||
803 | invokeOk = QMetaObject::invokeMethodm_methods[index].invoke(QTest::currentTestObject, slot, Qt::DirectConnection); | - | ||||||||||||||||||||||||
804 | if (!invokeOk)
| 0-126398 | ||||||||||||||||||||||||
805 | QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__); never executed: QTestResult::addFailure("Unable to execute slot", __FILE__, 805); | 0 | ||||||||||||||||||||||||
806 | - | |||||||||||||||||||||||||
807 | isBenchmark = QBenchmarkTestMethodData::current->isBenchmark(); | - | ||||||||||||||||||||||||
808 | - | |||||||||||||||||||||||||
809 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||||||||||||||
810 | - | |||||||||||||||||||||||||
811 | invokeMethodif (m_cleanupMethod.isValid())
| 32781-93617 | ||||||||||||||||||||||||
812 | m_cleanupMethod.invoke executed 32781 times by 104 tests: (QTest::currentTestObject, "cleanup()"Qt::DirectConnection);m_cleanupMethod.invoke(QTest::currentTestObject, Qt::DirectConnection); Executed by:
executed 32781 times by 104 tests: m_cleanupMethod.invoke(QTest::currentTestObject, Qt::DirectConnection); Executed by:
| 32781 | ||||||||||||||||||||||||
813 | - | |||||||||||||||||||||||||
814 | // If the test isn't a benchmark, finalize the result after cleanup() has finished. | - | ||||||||||||||||||||||||
815 | if (!isBenchmark)
| 420-125978 | ||||||||||||||||||||||||
816 | QTestResult::finishedCurrentTestDataCleanup(); executed 125978 times by 502 tests: QTestResult::finishedCurrentTestDataCleanup(); Executed by:
| 125978 | ||||||||||||||||||||||||
817 | - | |||||||||||||||||||||||||
818 | // If this test method has a benchmark, repeat until all measurements are | - | ||||||||||||||||||||||||
819 | // acceptable. | - | ||||||||||||||||||||||||
820 | // The QBENCHMARK macro increases the number of iterations for each run until | - | ||||||||||||||||||||||||
821 | // this happens. | - | ||||||||||||||||||||||||
822 | } while (invokeOk && isBenchmark executed 126398 times by 502 tests: end of block Executed by:
| 0-126398 | ||||||||||||||||||||||||
823 | && QBenchmarkTestMethodData::current->resultsAccepted() == false
| 12-408 | ||||||||||||||||||||||||
824 | && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed());
| 0-12 | ||||||||||||||||||||||||
825 | - | |||||||||||||||||||||||||
826 | QBenchmarkTestMethodData::current->endDataRun(); | - | ||||||||||||||||||||||||
827 | if (!QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed()) {
| 168-125366 | ||||||||||||||||||||||||
828 | if (i > -1) // iteration -1 is the warmup iteration.
| 380-124818 | ||||||||||||||||||||||||
829 | results.append(QBenchmarkTestMethodData::current->result); executed 380 times by 2 tests: results.append(QBenchmarkTestMethodData::current->result); Executed by:
| 380 | ||||||||||||||||||||||||
830 | - | |||||||||||||||||||||||||
831 | if (isBenchmark && QBenchmarkGlobalData::current->verboseOutput) {
| 0-124908 | ||||||||||||||||||||||||
832 | if (i == -1) {
| 0 | ||||||||||||||||||||||||
833 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
834 | QString::fromLatin1("warmup stage result : %1") | - | ||||||||||||||||||||||||
835 | .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0); | - | ||||||||||||||||||||||||
836 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
837 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
838 | QString::fromLatin1("accumulation stage result: %1") | - | ||||||||||||||||||||||||
839 | .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0); | - | ||||||||||||||||||||||||
840 | } never executed: end of block | 0 | ||||||||||||||||||||||||
841 | } | - | ||||||||||||||||||||||||
842 | } executed 125198 times by 501 tests: end of block Executed by:
| 125198 | ||||||||||||||||||||||||
843 | - | |||||||||||||||||||||||||
844 | // Verify if the minimum total measurement is reached, if it was specified: | - | ||||||||||||||||||||||||
845 | if (QBenchmarkGlobalData::current->minimumTotal == -1) {
| 0-126536 | ||||||||||||||||||||||||
846 | minimumTotalReached = true; | - | ||||||||||||||||||||||||
847 | } else { executed 126536 times by 502 tests: end of block Executed by:
| 126536 | ||||||||||||||||||||||||
848 | const qreal total = std::accumulate(results.begin(), results.end(), 0.0, addResult); | - | ||||||||||||||||||||||||
849 | minimumTotalReached = (total >= QBenchmarkGlobalData::current->minimumTotal); | - | ||||||||||||||||||||||||
850 | } never executed: end of block | 0 | ||||||||||||||||||||||||
851 | } while (isBenchmark
| 408-126128 | ||||||||||||||||||||||||
852 | && ((++i < QBenchmarkGlobalData::current->adjustMedianIterationCount()) || !minimumTotalReached)
| 0-400 | ||||||||||||||||||||||||
853 | && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed());
| 0-8 | ||||||||||||||||||||||||
854 | - | |||||||||||||||||||||||||
855 | // If the test is a benchmark, finalize the result after all iterations have finished. | - | ||||||||||||||||||||||||
856 | if (isBenchmark) {
| 400-126128 | ||||||||||||||||||||||||
857 | bool testPassed = !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed();
| 25-375 | ||||||||||||||||||||||||
858 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||||||||||||||
859 | // Only report benchmark figures if the test passed | - | ||||||||||||||||||||||||
860 | if (testPassed && QBenchmarkTestMethodData::current->resultsAccepted())
| 0-282 | ||||||||||||||||||||||||
861 | QTestLog::addBenchmarkResult(qMedian(results)); executed 282 times by 2 tests: QTestLog::addBenchmarkResult(qMedian(results)); Executed by:
| 282 | ||||||||||||||||||||||||
862 | } executed 400 times by 2 tests: end of block Executed by:
| 400 | ||||||||||||||||||||||||
863 | } executed 126528 times by 502 tests: end of block Executed by:
| 126528 | ||||||||||||||||||||||||
864 | - | |||||||||||||||||||||||||
865 | class WatchDog : public QThread | - | ||||||||||||||||||||||||
866 | { | - | ||||||||||||||||||||||||
867 | public: | - | ||||||||||||||||||||||||
868 | WatchDog() | - | ||||||||||||||||||||||||
869 | { | - | ||||||||||||||||||||||||
870 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
871 | timeout.store(-1); | - | ||||||||||||||||||||||||
872 | start(); | - | ||||||||||||||||||||||||
873 | waitCondition.wait(&mutex); | - | ||||||||||||||||||||||||
874 | } | - | ||||||||||||||||||||||||
875 | ~WatchDog() { | - | ||||||||||||||||||||||||
876 | { | - | ||||||||||||||||||||||||
877 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
878 | timeout.store(0); | - | ||||||||||||||||||||||||
879 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
880 | } | - | ||||||||||||||||||||||||
881 | wait(); | - | ||||||||||||||||||||||||
882 | } | - | ||||||||||||||||||||||||
883 | - | |||||||||||||||||||||||||
884 | void beginTest() { | - | ||||||||||||||||||||||||
885 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
886 | timeout.store(defaultTimeout()); | - | ||||||||||||||||||||||||
887 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
888 | } | - | ||||||||||||||||||||||||
889 | - | |||||||||||||||||||||||||
890 | void testFinished() { | - | ||||||||||||||||||||||||
891 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
892 | timeout.store(-1); | - | ||||||||||||||||||||||||
893 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
894 | } | - | ||||||||||||||||||||||||
895 | - | |||||||||||||||||||||||||
896 | void run() { | - | ||||||||||||||||||||||||
897 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
898 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
899 | while (1) { | - | ||||||||||||||||||||||||
900 | int t = timeout.load(); | - | ||||||||||||||||||||||||
901 | if (!t)
| 1263-221322 | ||||||||||||||||||||||||
902 | break; executed 1263 times by 508 tests: break; Executed by:
| 1263 | ||||||||||||||||||||||||
903 | if (Q_UNLIKELY(!waitCondition.wait(&mutex, t))))) {
| 0-221265 | ||||||||||||||||||||||||
904 | stackTrace(); | - | ||||||||||||||||||||||||
905 | qFatal("Test function timed out"); | - | ||||||||||||||||||||||||
906 | } never executed: end of block | 0 | ||||||||||||||||||||||||
907 | } executed 221265 times by 901 tests: end of block Executed by:
| 221265 | ||||||||||||||||||||||||
908 | } executed 1263 times by 508 tests: end of block Executed by:
| 1263 | ||||||||||||||||||||||||
909 | - | |||||||||||||||||||||||||
910 | private: | - | ||||||||||||||||||||||||
911 | QBasicAtomicInt timeout; | - | ||||||||||||||||||||||||
912 | QMutex mutex; | - | ||||||||||||||||||||||||
913 | QWaitCondition waitCondition; | - | ||||||||||||||||||||||||
914 | }; | - | ||||||||||||||||||||||||
915 | - | |||||||||||||||||||||||||
916 | - | |||||||||||||||||||||||||
917 | /*! | - | ||||||||||||||||||||||||
918 | \internal | - | ||||||||||||||||||||||||
919 | - | |||||||||||||||||||||||||
920 | Call slot_data(), init(), slot(), cleanup(), init(), slot(), cleanup(), ... | - | ||||||||||||||||||||||||
921 | If data is set then it is the only test that is performed | - | ||||||||||||||||||||||||
922 | - | |||||||||||||||||||||||||
923 | If the function was successfully called, true is returned, otherwise | - | ||||||||||||||||||||||||
924 | false. | - | ||||||||||||||||||||||||
925 | */ | - | ||||||||||||||||||||||||
staticbool qInvokeTestMethodTestMethods::invokeTest(const char *slotNameint index, const char *data, WatchDog *watchDog) const | ||||||||||||||||||||||||||
927 | { | - | ||||||||||||||||||||||||
928 | QTEST_ASSERT(slotName);QBenchmarkTestMethodData benchmarkData; | - | ||||||||||||||||||||||||
929 | QBenchmarkTestMethodData::current = &benchmarkData; | - | ||||||||||||||||||||||||
930 | - | |||||||||||||||||||||||||
931 | const QByteArray &name = m_methods[index].name(); | - | ||||||||||||||||||||||||
932 | QBenchmarkGlobalData::current->context.slotName = QLatin1String(slotNamename) + QLatin1String("()"); | - | ||||||||||||||||||||||||
933 | - | |||||||||||||||||||||||||
934 | char member[512]; | - | ||||||||||||||||||||||||
935 | QTestTable table; | - | ||||||||||||||||||||||||
char *slot = qstrdup(slotName); | ||||||||||||||||||||||||||
slot[strlen(slot) - 2] = '\0'; | ||||||||||||||||||||||||||
936 | - | |||||||||||||||||||||||||
937 | QTestResult::setCurrentTestFunction(slot);name.constData()); | - | ||||||||||||||||||||||||
938 | - | |||||||||||||||||||||||||
939 | const QTestTable *gTable = QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
940 | const int globalDataCount = gTable->dataCount(); | - | ||||||||||||||||||||||||
941 | int curGlobalDataIndex = 0; | - | ||||||||||||||||||||||||
942 | - | |||||||||||||||||||||||||
943 | /* For each test function that has a *_data() table/function, do: */ | - | ||||||||||||||||||||||||
944 | do { | - | ||||||||||||||||||||||||
945 | if (!gTable->isEmpty())
| 1197-12891 | ||||||||||||||||||||||||
946 | QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex)); executed 1197 times by 15 tests: QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex)); Executed by:
| 1197 | ||||||||||||||||||||||||
947 | - | |||||||||||||||||||||||||
948 | if (curGlobalDataIndex == 0) {
| 832-13256 | ||||||||||||||||||||||||
949 | qsnprintf(member, 512, "%s_data()", slot);name.constData()); | - | ||||||||||||||||||||||||
950 | invokeMethod(QTest::currentTestObject, member); | - | ||||||||||||||||||||||||
951 | } executed 13256 times by 502 tests: end of block Executed by:
| 13256 | ||||||||||||||||||||||||
952 | - | |||||||||||||||||||||||||
953 | bool foundFunction = false; | - | ||||||||||||||||||||||||
954 | if (!QTestResult::skipCurrentTest()) {
| 237-13851 | ||||||||||||||||||||||||
955 | int curDataIndex = 0; | - | ||||||||||||||||||||||||
956 | const int dataCount = table.dataCount(); | - | ||||||||||||||||||||||||
957 | - | |||||||||||||||||||||||||
958 | // Data tag requested but none available? | - | ||||||||||||||||||||||||
959 | if (data && !dataCount) {
| 0-13824 | ||||||||||||||||||||||||
960 | // Let empty data tag through. | - | ||||||||||||||||||||||||
961 | if (!*data)
| 0 | ||||||||||||||||||||||||
962 | data = 0; never executed: data = 0; | 0 | ||||||||||||||||||||||||
963 | else { | - | ||||||||||||||||||||||||
964 | fprintf(stderr, "Unknown testdata for function %s:(): '%s'\n", slotName, name.constData(), data); | - | ||||||||||||||||||||||||
965 | fprintf(stderr, "Function has no testdata.\n"); | - | ||||||||||||||||||||||||
966 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
967 | } | - | ||||||||||||||||||||||||
968 | } | - | ||||||||||||||||||||||||
969 | - | |||||||||||||||||||||||||
970 | /* For each entry in the data table, do: */ | - | ||||||||||||||||||||||||
971 | do { | - | ||||||||||||||||||||||||
972 | QTestResult::setSkipCurrentTest(false); | - | ||||||||||||||||||||||||
973 | QTestResult::setBlacklistCurrentTest(false); | - | ||||||||||||||||||||||||
974 | if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
| 2-126583 | ||||||||||||||||||||||||
975 | foundFunction = true; | - | ||||||||||||||||||||||||
976 | - | |||||||||||||||||||||||||
977 | QTestPrivate::checkBlackLists(slot,name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : 0); | - | ||||||||||||||||||||||||
978 | - | |||||||||||||||||||||||||
979 | QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0) | - | ||||||||||||||||||||||||
980 | : table.testData(curDataIndex)); | - | ||||||||||||||||||||||||
981 | - | |||||||||||||||||||||||||
982 | if (watchDog)
| 0-126610 | ||||||||||||||||||||||||
983 | watchDog->beginTest(); executed 126610 times by 502 tests: watchDog->beginTest(); Executed by:
| 126610 | ||||||||||||||||||||||||
984 | qInvokeTestMethodDataEntryinvokeTestOnData(slotindex); | - | ||||||||||||||||||||||||
985 | if (watchDog)
| 0-126528 | ||||||||||||||||||||||||
986 | watchDog->testFinished(); executed 126528 times by 502 tests: watchDog->testFinished(); Executed by:
| 126528 | ||||||||||||||||||||||||
987 | - | |||||||||||||||||||||||||
988 | if (data)
| 27-126501 | ||||||||||||||||||||||||
989 | break; executed 27 times by 1 test: break; Executed by:
| 27 | ||||||||||||||||||||||||
990 | } executed 126501 times by 502 tests: end of block Executed by:
| 126501 | ||||||||||||||||||||||||
991 | ++curDataIndex; | - | ||||||||||||||||||||||||
992 | } while (curDataIndex < dataCount); executed 126503 times by 502 tests: end of block Executed by:
| 13742-126503 | ||||||||||||||||||||||||
993 | } executed 13769 times by 502 tests: end of block Executed by:
| 13769 | ||||||||||||||||||||||||
994 | - | |||||||||||||||||||||||||
995 | if (data && !foundFunction) {
| 0-13979 | ||||||||||||||||||||||||
996 | fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName'%s()'\n", name.constData(), data); | - | ||||||||||||||||||||||||
997 | fprintf(stderr, "Available testdata:\n"); | - | ||||||||||||||||||||||||
998 | for (int i = 0; i < table.dataCount(); ++i)
| 0 | ||||||||||||||||||||||||
999 | fprintf(stderr, "%s\n", table.testData(i)->dataTag()); never executed: fprintf(stderr, "%s\n", table.testData(i)->dataTag()); | 0 | ||||||||||||||||||||||||
1000 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
1001 | } | - | ||||||||||||||||||||||||
1002 | - | |||||||||||||||||||||||||
1003 | QTestResult::setCurrentGlobalTestData(0); | - | ||||||||||||||||||||||||
1004 | ++curGlobalDataIndex; | - | ||||||||||||||||||||||||
1005 | } while (curGlobalDataIndex < globalDataCount); executed 14006 times by 502 tests: end of block Executed by:
| 832-14006 | ||||||||||||||||||||||||
1006 | - | |||||||||||||||||||||||||
1007 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
1008 | QTestResult::setSkipCurrentTest(false); | - | ||||||||||||||||||||||||
1009 | QTestResult::setBlacklistCurrentTest(false); | - | ||||||||||||||||||||||||
1010 | QTestResult::setCurrentTestData(0); | - | ||||||||||||||||||||||||
1011 | - | |||||||||||||||||||||||||
1012 | delete[] slot;return true; executed 13174 times by 502 tests: return true; Executed by:
| 13174 | ||||||||||||||||||||||||
1013 | } | - | ||||||||||||||||||||||||
1014 | - | |||||||||||||||||||||||||
1015 | void *fetchData(QTestData *data, const char *tagName, int typeId) | - | ||||||||||||||||||||||||
1016 | { | - | ||||||||||||||||||||||||
1017 | QTEST_ASSERT(typeId); never executed: qt_assert("typeId",__FILE__,1017);
| 0-431987 | ||||||||||||||||||||||||
1018 | QTEST_ASSERT_X(data, "QTest::fetchData()", "Test data requested, but no testdata available."); never executed: qt_assert_x("QTest::fetchData()", "Test data requested, but no testdata available.",__FILE__,1018);
| 0-431987 | ||||||||||||||||||||||||
1019 | QTEST_ASSERT(data->parent()); never executed: qt_assert("data->parent()",__FILE__,1019);
| 0-431987 | ||||||||||||||||||||||||
1020 | - | |||||||||||||||||||||||||
1021 | int idx = data->parent()->indexOf(tagName); | - | ||||||||||||||||||||||||
1022 | - | |||||||||||||||||||||||||
1023 | if (Q_UNLIKELY(idx == -1 || idx >= data->dataCount())())) {
| 25-431962 | ||||||||||||||||||||||||
1024 | qFatal("QFETCH: Requested testdata '%s' not available, check your _data function.", | - | ||||||||||||||||||||||||
1025 | tagName); | - | ||||||||||||||||||||||||
1026 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1027 | - | |||||||||||||||||||||||||
1028 | if (Q_UNLIKELY(typeId != data->parent()->elementTypeId(idx))))) {
| 0-431962 | ||||||||||||||||||||||||
1029 | qFatal("Requested type '%s' does not match available type '%s'.", | - | ||||||||||||||||||||||||
1030 | QMetaType::typeName(typeId), | - | ||||||||||||||||||||||||
1031 | QMetaType::typeName(data->parent()->elementTypeId(idx))); | - | ||||||||||||||||||||||||
1032 | } never executed: end of block | 0 | ||||||||||||||||||||||||
1033 | - | |||||||||||||||||||||||||
1034 | return data->data(idx); executed 431962 times by 330 tests: return data->data(idx); Executed by:
| 431962 | ||||||||||||||||||||||||
1035 | } | - | ||||||||||||||||||||||||
1036 | - | |||||||||||||||||||||||||
1037 | /*! | - | ||||||||||||||||||||||||
1038 | \fn char* QTest::toHexRepresentation(const char *ba, int length) | - | ||||||||||||||||||||||||
1039 | - | |||||||||||||||||||||||||
1040 | Returns a pointer to a string that is the string \a ba represented | - | ||||||||||||||||||||||||
1041 | as a space-separated sequence of hex characters. If the input is | - | ||||||||||||||||||||||||
1042 | considered too long, it is truncated. A trucation is indicated in | - | ||||||||||||||||||||||||
1043 | the returned string as an ellipsis at the end. | - | ||||||||||||||||||||||||
1044 | - | |||||||||||||||||||||||||
1045 | \a length is the length of the string \a ba. | - | ||||||||||||||||||||||||
1046 | */ | - | ||||||||||||||||||||||||
1047 | char *toHexRepresentation(const char *ba, int length) | - | ||||||||||||||||||||||||
1048 | { | - | ||||||||||||||||||||||||
1049 | if (length == 0) | - | ||||||||||||||||||||||||
1050 | return qstrdup(""); | - | ||||||||||||||||||||||||
1051 | - | |||||||||||||||||||||||||
1052 | /* We output at maximum about maxLen characters in order to avoid | - | ||||||||||||||||||||||||
1053 | * running out of memory and flooding things when the byte array | - | ||||||||||||||||||||||||
1054 | * is large. | - | ||||||||||||||||||||||||
1055 | * | - | ||||||||||||||||||||||||
1056 | * maxLen can't be for example 200 because Qt Test is sprinkled with fixed | - | ||||||||||||||||||||||||
1057 | * size char arrays. | - | ||||||||||||||||||||||||
1058 | * */ | - | ||||||||||||||||||||||||
1059 | const int maxLen = 50; | - | ||||||||||||||||||||||||
1060 | const int len = qMin(maxLen, length); | - | ||||||||||||||||||||||||
1061 | char *result = 0; | - | ||||||||||||||||||||||||
1062 | - | |||||||||||||||||||||||||
1063 | if (length > maxLen) { | - | ||||||||||||||||||||||||
1064 | const int size = len * 3 + 4; | - | ||||||||||||||||||||||||
1065 | result = new char[size]; | - | ||||||||||||||||||||||||
1066 | - | |||||||||||||||||||||||||
1067 | char *const forElipsis = result + size - 5; | - | ||||||||||||||||||||||||
1068 | forElipsis[0] = ' '; | - | ||||||||||||||||||||||||
1069 | forElipsis[1] = '.'; | - | ||||||||||||||||||||||||
1070 | forElipsis[2] = '.'; | - | ||||||||||||||||||||||||
1071 | forElipsis[3] = '.'; | - | ||||||||||||||||||||||||
1072 | result[size - 1] = '\0'; | - | ||||||||||||||||||||||||
1073 | } | - | ||||||||||||||||||||||||
1074 | else { | - | ||||||||||||||||||||||||
1075 | const int size = len * 3; | - | ||||||||||||||||||||||||
1076 | result = new char[size]; | - | ||||||||||||||||||||||||
1077 | result[size - 1] = '\0'; | - | ||||||||||||||||||||||||
1078 | } | - | ||||||||||||||||||||||||
1079 | - | |||||||||||||||||||||||||
1080 | int i = 0; | - | ||||||||||||||||||||||||
1081 | int o = 0; | - | ||||||||||||||||||||||||
1082 | - | |||||||||||||||||||||||||
1083 | while (true) { | - | ||||||||||||||||||||||||
1084 | const char at = ba[i]; | - | ||||||||||||||||||||||||
1085 | - | |||||||||||||||||||||||||
1086 | result[o] = toHexUpper(at >> 4); | - | ||||||||||||||||||||||||
1087 | ++o; | - | ||||||||||||||||||||||||
1088 | result[o] = toHexUpper(at); | - | ||||||||||||||||||||||||
1089 | - | |||||||||||||||||||||||||
1090 | ++i; | - | ||||||||||||||||||||||||
1091 | ++o; | - | ||||||||||||||||||||||||
1092 | if (i == len) | - | ||||||||||||||||||||||||
1093 | break; | - | ||||||||||||||||||||||||
1094 | else { | - | ||||||||||||||||||||||||
1095 | result[o] = ' '; | - | ||||||||||||||||||||||||
1096 | ++o; | - | ||||||||||||||||||||||||
1097 | } | - | ||||||||||||||||||||||||
1098 | } | - | ||||||||||||||||||||||||
1099 | - | |||||||||||||||||||||||||
1100 | return result; | - | ||||||||||||||||||||||||
1101 | } | - | ||||||||||||||||||||||||
1102 | - | |||||||||||||||||||||||||
1103 | /*! | - | ||||||||||||||||||||||||
1104 | \internal | - | ||||||||||||||||||||||||
1105 | Returns the same QByteArray but with only the ASCII characters still shown; | - | ||||||||||||||||||||||||
1106 | everything else is replaced with \c {\xHH}. | - | ||||||||||||||||||||||||
1107 | */ | - | ||||||||||||||||||||||||
1108 | char *toPrettyCString(const char *p, int length) | - | ||||||||||||||||||||||||
1109 | { | - | ||||||||||||||||||||||||
1110 | bool trimmed = false; | - | ||||||||||||||||||||||||
1111 | QScopedArrayPointer<char> buffer(new char[256]); | - | ||||||||||||||||||||||||
1112 | const char *end = p + length; | - | ||||||||||||||||||||||||
1113 | char *dst = buffer.data(); | - | ||||||||||||||||||||||||
1114 | - | |||||||||||||||||||||||||
1115 | bool lastWasHexEscape = false; | - | ||||||||||||||||||||||||
1116 | *dst++ = '"'; | - | ||||||||||||||||||||||||
1117 | for ( ; p != end; ++p) { | - | ||||||||||||||||||||||||
1118 | // we can add: | - | ||||||||||||||||||||||||
1119 | // 1 byte: a single character | - | ||||||||||||||||||||||||
1120 | // 2 bytes: a simple escape sequence (\n) | - | ||||||||||||||||||||||||
1121 | // 3 bytes: "" and a character | - | ||||||||||||||||||||||||
1122 | // 4 bytes: an hex escape sequence (\xHH) | - | ||||||||||||||||||||||||
1123 | if (dst - buffer.data() > 246) { | - | ||||||||||||||||||||||||
1124 | // plus the the quote, the three dots and NUL, it's 255 in the worst case | - | ||||||||||||||||||||||||
1125 | trimmed = true; | - | ||||||||||||||||||||||||
1126 | break; | - | ||||||||||||||||||||||||
1127 | } | - | ||||||||||||||||||||||||
1128 | - | |||||||||||||||||||||||||
1129 | // check if we need to insert "" to break an hex escape sequence | - | ||||||||||||||||||||||||
1130 | if (Q_UNLIKELY(lastWasHexEscape)) { | - | ||||||||||||||||||||||||
1131 | if (fromHex(*p) != -1) { | - | ||||||||||||||||||||||||
1132 | // yes, insert it | - | ||||||||||||||||||||||||
1133 | *dst++ = '"'; | - | ||||||||||||||||||||||||
1134 | *dst++ = '"'; | - | ||||||||||||||||||||||||
1135 | } | - | ||||||||||||||||||||||||
1136 | lastWasHexEscape = false; | - | ||||||||||||||||||||||||
1137 | } | - | ||||||||||||||||||||||||
1138 | - | |||||||||||||||||||||||||
1139 | if (*p < 0x7f && *p >= 0x20 && *p != '\\' && *p != '"') { | - | ||||||||||||||||||||||||
1140 | *dst++ = *p; | - | ||||||||||||||||||||||||
1141 | continue; | - | ||||||||||||||||||||||||
1142 | } | - | ||||||||||||||||||||||||
1143 | - | |||||||||||||||||||||||||
1144 | // write as an escape sequence | - | ||||||||||||||||||||||||
1145 | // this means we may advance dst to buffer.data() + 247 or 250 | - | ||||||||||||||||||||||||
1146 | *dst++ = '\\'; | - | ||||||||||||||||||||||||
1147 | switch (*p) { | - | ||||||||||||||||||||||||
1148 | case 0x5c: | - | ||||||||||||||||||||||||
1149 | case 0x22: | - | ||||||||||||||||||||||||
1150 | *dst++ = uchar(*p); | - | ||||||||||||||||||||||||
1151 | break; | - | ||||||||||||||||||||||||
1152 | case 0x8: | - | ||||||||||||||||||||||||
1153 | *dst++ = 'b'; | - | ||||||||||||||||||||||||
1154 | break; | - | ||||||||||||||||||||||||
1155 | case 0xc: | - | ||||||||||||||||||||||||
1156 | *dst++ = 'f'; | - | ||||||||||||||||||||||||
1157 | break; | - | ||||||||||||||||||||||||
1158 | case 0xa: | - | ||||||||||||||||||||||||
1159 | *dst++ = 'n'; | - | ||||||||||||||||||||||||
1160 | break; | - | ||||||||||||||||||||||||
1161 | case 0xd: | - | ||||||||||||||||||||||||
1162 | *dst++ = 'r'; | - | ||||||||||||||||||||||||
1163 | break; | - | ||||||||||||||||||||||||
1164 | case 0x9: | - | ||||||||||||||||||||||||
1165 | *dst++ = 't'; | - | ||||||||||||||||||||||||
1166 | break; | - | ||||||||||||||||||||||||
1167 | default: | - | ||||||||||||||||||||||||
1168 | // print as hex escape | - | ||||||||||||||||||||||||
1169 | *dst++ = 'x'; | - | ||||||||||||||||||||||||
1170 | *dst++ = toHexUpper(uchar(*p) >> 4); | - | ||||||||||||||||||||||||
1171 | *dst++ = toHexUpper(uchar(*p)); | - | ||||||||||||||||||||||||
1172 | lastWasHexEscape = true; | - | ||||||||||||||||||||||||
1173 | break; | - | ||||||||||||||||||||||||
1174 | } | - | ||||||||||||||||||||||||
1175 | } | - | ||||||||||||||||||||||||
1176 | - | |||||||||||||||||||||||||
1177 | *dst++ = '"'; | - | ||||||||||||||||||||||||
1178 | if (trimmed) { | - | ||||||||||||||||||||||||
1179 | *dst++ = '.'; | - | ||||||||||||||||||||||||
1180 | *dst++ = '.'; | - | ||||||||||||||||||||||||
1181 | *dst++ = '.'; | - | ||||||||||||||||||||||||
1182 | } | - | ||||||||||||||||||||||||
1183 | *dst++ = '\0'; | - | ||||||||||||||||||||||||
1184 | return buffer.take(); | - | ||||||||||||||||||||||||
1185 | } | - | ||||||||||||||||||||||||
1186 | - | |||||||||||||||||||||||||
1187 | /*! | - | ||||||||||||||||||||||||
1188 | \internal | - | ||||||||||||||||||||||||
1189 | Returns the same QString but with only the ASCII characters still shown; | - | ||||||||||||||||||||||||
1190 | everything else is replaced with \c {\uXXXX}. | - | ||||||||||||||||||||||||
1191 | - | |||||||||||||||||||||||||
1192 | Similar to QDebug::putString(). | - | ||||||||||||||||||||||||
1193 | */ | - | ||||||||||||||||||||||||
1194 | char *toPrettyUnicode(const ushort *p, int length) | - | ||||||||||||||||||||||||
1195 | { | - | ||||||||||||||||||||||||
1196 | // keep it simple for the vast majority of cases | - | ||||||||||||||||||||||||
1197 | bool trimmed = false; | - | ||||||||||||||||||||||||
1198 | QScopedArrayPointer<char> buffer(new char[256]); | - | ||||||||||||||||||||||||
1199 | const ushort *end = p + length; | - | ||||||||||||||||||||||||
1200 | char *dst = buffer.data(); | - | ||||||||||||||||||||||||
1201 | - | |||||||||||||||||||||||||
1202 | *dst++ = '"'; | - | ||||||||||||||||||||||||
1203 | for ( ; p != end; ++p) { | - | ||||||||||||||||||||||||
1204 | if (dst - buffer.data() > 245) { | - | ||||||||||||||||||||||||
1205 | // plus the the quote, the three dots and NUL, it's 250, 251 or 255 | - | ||||||||||||||||||||||||
1206 | trimmed = true; | - | ||||||||||||||||||||||||
1207 | break; | - | ||||||||||||||||||||||||
1208 | } | - | ||||||||||||||||||||||||
1209 | - | |||||||||||||||||||||||||
1210 | if (*p < 0x7f && *p >= 0x20 && *p != '\\' && *p != '"') { | - | ||||||||||||||||||||||||
1211 | *dst++ = *p; | - | ||||||||||||||||||||||||
1212 | continue; | - | ||||||||||||||||||||||||
1213 | } | - | ||||||||||||||||||||||||
1214 | - | |||||||||||||||||||||||||
1215 | // write as an escape sequence | - | ||||||||||||||||||||||||
1216 | // this means we may advance dst to buffer.data() + 246 or 250 | - | ||||||||||||||||||||||||
1217 | *dst++ = '\\'; | - | ||||||||||||||||||||||||
1218 | switch (*p) { | - | ||||||||||||||||||||||||
1219 | case 0x22: | - | ||||||||||||||||||||||||
1220 | case 0x5c: | - | ||||||||||||||||||||||||
1221 | *dst++ = uchar(*p); | - | ||||||||||||||||||||||||
1222 | break; | - | ||||||||||||||||||||||||
1223 | case 0x8: | - | ||||||||||||||||||||||||
1224 | *dst++ = 'b'; | - | ||||||||||||||||||||||||
1225 | break; | - | ||||||||||||||||||||||||
1226 | case 0xc: | - | ||||||||||||||||||||||||
1227 | *dst++ = 'f'; | - | ||||||||||||||||||||||||
1228 | break; | - | ||||||||||||||||||||||||
1229 | case 0xa: | - | ||||||||||||||||||||||||
1230 | *dst++ = 'n'; | - | ||||||||||||||||||||||||
1231 | break; | - | ||||||||||||||||||||||||
1232 | case 0xd: | - | ||||||||||||||||||||||||
1233 | *dst++ = 'r'; | - | ||||||||||||||||||||||||
1234 | break; | - | ||||||||||||||||||||||||
1235 | case 0x9: | - | ||||||||||||||||||||||||
1236 | *dst++ = 't'; | - | ||||||||||||||||||||||||
1237 | break; | - | ||||||||||||||||||||||||
1238 | default: | - | ||||||||||||||||||||||||
1239 | *dst++ = 'u'; | - | ||||||||||||||||||||||||
1240 | *dst++ = toHexUpper(*p >> 12); | - | ||||||||||||||||||||||||
1241 | *dst++ = toHexUpper(*p >> 8); | - | ||||||||||||||||||||||||
1242 | *dst++ = toHexUpper(*p >> 4); | - | ||||||||||||||||||||||||
1243 | *dst++ = toHexUpper(*p); | - | ||||||||||||||||||||||||
1244 | } | - | ||||||||||||||||||||||||
1245 | } | - | ||||||||||||||||||||||||
1246 | - | |||||||||||||||||||||||||
1247 | *dst++ = '"'; | - | ||||||||||||||||||||||||
1248 | if (trimmed) { | - | ||||||||||||||||||||||||
1249 | *dst++ = '.'; | - | ||||||||||||||||||||||||
1250 | *dst++ = '.'; | - | ||||||||||||||||||||||||
1251 | *dst++ = '.'; | - | ||||||||||||||||||||||||
1252 | } | - | ||||||||||||||||||||||||
1253 | *dst++ = '\0'; | - | ||||||||||||||||||||||||
1254 | return buffer.take(); | - | ||||||||||||||||||||||||
1255 | } | - | ||||||||||||||||||||||||
1256 | - | |||||||||||||||||||||||||
1257 | static bool debuggerPresent() | - | ||||||||||||||||||||||||
1258 | { | - | ||||||||||||||||||||||||
1259 | #if defined(Q_OS_LINUX) | - | ||||||||||||||||||||||||
1260 | int fd = open("/proc/self/status", O_RDONLY); | - | ||||||||||||||||||||||||
1261 | if (fd == -1) | - | ||||||||||||||||||||||||
1262 | return false; | - | ||||||||||||||||||||||||
1263 | char buffer[2048]; | - | ||||||||||||||||||||||||
1264 | ssize_t size = read(fd, buffer, sizeof(buffer) - 1); | - | ||||||||||||||||||||||||
1265 | if (size == -1) { | - | ||||||||||||||||||||||||
1266 | close(fd); | - | ||||||||||||||||||||||||
1267 | return false; | - | ||||||||||||||||||||||||
1268 | } | - | ||||||||||||||||||||||||
1269 | buffer[size] = 0; | - | ||||||||||||||||||||||||
1270 | const char tracerPidToken[] = "\nTracerPid:"; | - | ||||||||||||||||||||||||
1271 | char *tracerPid = strstr(buffer, tracerPidToken); | - | ||||||||||||||||||||||||
1272 | if (!tracerPid) { | - | ||||||||||||||||||||||||
1273 | close(fd); | - | ||||||||||||||||||||||||
1274 | return false; | - | ||||||||||||||||||||||||
1275 | } | - | ||||||||||||||||||||||||
1276 | tracerPid += sizeof(tracerPidToken); | - | ||||||||||||||||||||||||
1277 | long int pid = strtol(tracerPid, &tracerPid, 10); | - | ||||||||||||||||||||||||
1278 | close(fd); | - | ||||||||||||||||||||||||
1279 | return pid != 0; | - | ||||||||||||||||||||||||
1280 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
1281 | return IsDebuggerPresent(); | - | ||||||||||||||||||||||||
1282 | #else | - | ||||||||||||||||||||||||
1283 | // TODO | - | ||||||||||||||||||||||||
1284 | return false; | - | ||||||||||||||||||||||||
1285 | #endif | - | ||||||||||||||||||||||||
1286 | } | - | ||||||||||||||||||||||||
1287 | - | |||||||||||||||||||||||||
staticvoid qInvokeTestMethodsTestMethods::invokeTests(QObject *testObject) const | ||||||||||||||||||||||||||
1289 | { | - | ||||||||||||||||||||||||
1290 | const QMetaObject *metaObject = testObject->metaObject(); | - | ||||||||||||||||||||||||
1291 | QTEST_ASSERT(metaObject); never executed: qt_assert("metaObject",__FILE__,1291);
| 0-1320 | ||||||||||||||||||||||||
1292 | QTestLog::startLogging(); | - | ||||||||||||||||||||||||
1293 | QTestResult::setCurrentTestFunction("initTestCase"); | - | ||||||||||||||||||||||||
1294 | QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
1295 | invokeMethodif (m_initTestCaseDataMethod.isValid())
| 85-1235 | ||||||||||||||||||||||||
1296 | m_initTestCaseDataMethod.invoke executed 85 times by 11 tests: (testObject, "initTestCase_data()"Qt::DirectConnection);m_initTestCaseDataMethod.invoke(testObject, Qt::DirectConnection); Executed by:
executed 85 times by 11 tests: m_initTestCaseDataMethod.invoke(testObject, Qt::DirectConnection); Executed by:
| 85 | ||||||||||||||||||||||||
1297 | - | |||||||||||||||||||||||||
1298 | QScopedPointer<WatchDog> watchDog; | - | ||||||||||||||||||||||||
1299 | if (!debuggerPresent()
| 0-1320 | ||||||||||||||||||||||||
1300 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
1301 | && QBenchmarkGlobalData::current->mode() != QBenchmarkGlobalData::CallgrindChildProcess
| 0-1320 | ||||||||||||||||||||||||
1302 | #endif | - | ||||||||||||||||||||||||
1303 | ) { | - | ||||||||||||||||||||||||
1304 | watchDog.reset(new WatchDog); | - | ||||||||||||||||||||||||
1305 | } executed 1320 times by 506 tests: end of block Executed by:
| 1320 | ||||||||||||||||||||||||
1306 | - | |||||||||||||||||||||||||
1307 | if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) {
| 25-1295 | ||||||||||||||||||||||||
1308 | invokeMethodif (m_initTestCaseMethod.isValid())
| 316-954 | ||||||||||||||||||||||||
1309 | m_initTestCaseMethod.invoke executed 316 times by 190 tests: (testObject, "initTestCase()"Qt::DirectConnection);m_initTestCaseMethod.invoke(testObject, Qt::DirectConnection); Executed by:
executed 316 times by 190 tests: m_initTestCaseMethod.invoke(testObject, Qt::DirectConnection); Executed by:
| 316 | ||||||||||||||||||||||||
1310 | - | |||||||||||||||||||||||||
1311 | // finishedCurrentTestDataCleanup() resets QTestResult::currentTestFailed(), so use a local copy. | - | ||||||||||||||||||||||||
1312 | const bool previousFailed = QTestResult::currentTestFailed(); | - | ||||||||||||||||||||||||
1313 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||||||||||||||
1314 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||||||||||||||
1315 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
1316 | - | |||||||||||||||||||||||||
1317 | if (!QTestResult::skipCurrentTest() && !previousFailed) {
| 26-1244 | ||||||||||||||||||||||||
if (QTest::testFuncs
| ||||||||||||||||||||||||||
1318 | for (int i = 0;, count = int(m_methods.size()); i != QTest::testFuncCount< count; ++i++)) {
| 1135-13256 | ||||||||||||||||||||||||
1319 | const char *data = Q_NULLPTR; | - | ||||||||||||||||||||||||
1320 | if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i ].function()).methodSignature().constData(),< QTest::testFuncs[i].data(), watchDogtestTags.data())) {
| 27-13192 | ||||||||||||||||||||||||
break;
| ||||||||||||||||||||||||||
}
| ||||||||||||||||||||||||||
}
| ||||||||||||||||||||||||||
testFuncCleaner
| ||||||||||||||||||||||||||
} else {
| ||||||||||||||||||||||||||
int methodCount = metaObject->methodCount();
| ||||||||||||||||||||||||||
QMetaMethod *testMethods = new QMetaMethod[methodCount];
| ||||||||||||||||||||||||||
for
| ||||||||||||||||||||||||||
testMethods[
| ||||||||||||||||||||||||||
1321 | data executed 27 times by 1 test: = metaObject->methodqstrdup(i);data = qstrdup(QTest::testTags.at(i).toLatin1().constData()); Executed by:
executed 27 times by 1 test: data = qstrdup(QTest::testTags.at(i).toLatin1().constData()); Executed by:
| 27 | ||||||||||||||||||||||||
for executed 27 times by 1 test: QTest::testTags.at(inti).toLatin1().constData());data = qstrdup(QTest::testTags.at(i).toLatin1().constData()); Executed by:
executed 27 times by 1 test: data = qstrdup(QTest::testTags.at(i).toLatin1().constData()); Executed by:
| ||||||||||||||||||||||||||
1322 | const bool ok = 0; i != methodCount; i++) { | - | ||||||||||||||||||||||||
if (!isValidSlot(testMethods[i])) | ||||||||||||||||||||||||||
continue; | ||||||||||||||||||||||||||
if (!qInvokeTestMethodinvokeTest(testMethods[i].methodSignature().constData(), 0, data, watchDog.data())) | ||||||||||||||||||||||||||
break; | ||||||||||||||||||||||||||
}()); | ||||||||||||||||||||||||||
1323 | delete [] testMethodsdata; | - | ||||||||||||||||||||||||
1324 | testMethods = 0if (!ok)
| 0-13174 | ||||||||||||||||||||||||
1325 | break never executed: ;break; never executed: break; | 0 | ||||||||||||||||||||||||
1326 | } executed 13174 times by 502 tests: end of block Executed by:
| 13174 | ||||||||||||||||||||||||
1327 | } executed 1135 times by 502 tests: end of block Executed by:
| 1135 | ||||||||||||||||||||||||
1328 | - | |||||||||||||||||||||||||
1329 | QTestResult::setSkipCurrentTest(false); | - | ||||||||||||||||||||||||
1330 | QTestResult::setBlacklistCurrentTest(false); | - | ||||||||||||||||||||||||
1331 | QTestResult::setCurrentTestFunction("cleanupTestCase"); | - | ||||||||||||||||||||||||
1332 | invokeMethodif (m_cleanupTestCaseMethod.isValid())
| 210-978 | ||||||||||||||||||||||||
1333 | m_cleanupTestCaseMethod.invoke executed 210 times by 85 tests: (testObject, "cleanupTestCase()"Qt::DirectConnection);m_cleanupTestCaseMethod.invoke(testObject, Qt::DirectConnection); Executed by:
executed 210 times by 85 tests: m_cleanupTestCaseMethod.invoke(testObject, Qt::DirectConnection); Executed by:
| 210 | ||||||||||||||||||||||||
1334 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||||||||||||||
1335 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||||||||||||||
1336 | } executed 1188 times by 505 tests: end of block Executed by:
| 1188 | ||||||||||||||||||||||||
1337 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
1338 | QTestResult::setCurrentTestFunction(0); | - | ||||||||||||||||||||||||
1339 | QTestTable::clearGlobalTestTable(); | - | ||||||||||||||||||||||||
1340 | - | |||||||||||||||||||||||||
1341 | QTestLog::stopLogging(); | - | ||||||||||||||||||||||||
1342 | } executed 1238 times by 508 tests: end of block Executed by:
| 1238 | ||||||||||||||||||||||||
1343 | - | |||||||||||||||||||||||||
1344 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
1345 | class FatalSignalHandler | - | ||||||||||||||||||||||||
1346 | { | - | ||||||||||||||||||||||||
1347 | public: | - | ||||||||||||||||||||||||
1348 | FatalSignalHandler(); | - | ||||||||||||||||||||||||
1349 | ~FatalSignalHandler(); | - | ||||||||||||||||||||||||
1350 | - | |||||||||||||||||||||||||
1351 | private: | - | ||||||||||||||||||||||||
1352 | static void signal(int); | - | ||||||||||||||||||||||||
1353 | sigset_t handledSignals; | - | ||||||||||||||||||||||||
1354 | }; | - | ||||||||||||||||||||||||
1355 | - | |||||||||||||||||||||||||
1356 | void FatalSignalHandler::signal(int signum) | - | ||||||||||||||||||||||||
1357 | { | - | ||||||||||||||||||||||||
1358 | const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); | - | ||||||||||||||||||||||||
1359 | const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); | - | ||||||||||||||||||||||||
1360 | if (signum != SIGINT) | - | ||||||||||||||||||||||||
1361 | stackTrace(); | - | ||||||||||||||||||||||||
1362 | qFatal("Received signal %d\n" | - | ||||||||||||||||||||||||
1363 | " Function time: %dms Total time: %dms", | - | ||||||||||||||||||||||||
1364 | signum, msecsFunctionTime, msecsTotalTime); | - | ||||||||||||||||||||||||
1365 | #if defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
1366 | { | - | ||||||||||||||||||||||||
1367 | struct sigaction act; | - | ||||||||||||||||||||||||
1368 | memset(&act, 0, sizeof(struct sigaction)); | - | ||||||||||||||||||||||||
1369 | act.sa_handler = SIG_DFL; | - | ||||||||||||||||||||||||
1370 | sigaction(signum, &act, NULL); | - | ||||||||||||||||||||||||
1371 | } | - | ||||||||||||||||||||||||
1372 | #endif | - | ||||||||||||||||||||||||
1373 | } | - | ||||||||||||||||||||||||
1374 | - | |||||||||||||||||||||||||
1375 | FatalSignalHandler::FatalSignalHandler() | - | ||||||||||||||||||||||||
1376 | { | - | ||||||||||||||||||||||||
1377 | sigemptyset(&handledSignals); | - | ||||||||||||||||||||||||
1378 | - | |||||||||||||||||||||||||
1379 | const int fatalSignals[] = { | - | ||||||||||||||||||||||||
1380 | SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 }; | - | ||||||||||||||||||||||||
1381 | - | |||||||||||||||||||||||||
1382 | struct sigaction act; | - | ||||||||||||||||||||||||
1383 | memset(&act, 0, sizeof(act)); | - | ||||||||||||||||||||||||
1384 | act.sa_handler = FatalSignalHandler::signal; | - | ||||||||||||||||||||||||
1385 | - | |||||||||||||||||||||||||
1386 | // Remove the handler after it is invoked. | - | ||||||||||||||||||||||||
1387 | #if !defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
1388 | act.sa_flags = SA_RESETHAND; | - | ||||||||||||||||||||||||
1389 | #endif | - | ||||||||||||||||||||||||
1390 | - | |||||||||||||||||||||||||
1391 | #ifdef SA_ONSTACK | - | ||||||||||||||||||||||||
1392 | // Let the signal handlers use an alternate stack | - | ||||||||||||||||||||||||
1393 | // This is necessary if SIGSEGV is to catch a stack overflow | - | ||||||||||||||||||||||||
1394 | # if defined(Q_CC_GNU) && defined(Q_OF_ELF) | - | ||||||||||||||||||||||||
1395 | // Put the alternate stack in the .lbss (large BSS) section so that it doesn't | - | ||||||||||||||||||||||||
1396 | // interfere with normal .bss symbols | - | ||||||||||||||||||||||||
1397 | __attribute__((section(".lbss.altstack"), aligned(4096))) | - | ||||||||||||||||||||||||
1398 | # endif | - | ||||||||||||||||||||||||
1399 | static char alternate_stack[16 * 1024]; | - | ||||||||||||||||||||||||
1400 | stack_t stack; | - | ||||||||||||||||||||||||
1401 | stack.ss_flags = 0; | - | ||||||||||||||||||||||||
1402 | stack.ss_size = sizeof alternate_stack; | - | ||||||||||||||||||||||||
1403 | stack.ss_sp = alternate_stack; | - | ||||||||||||||||||||||||
1404 | sigaltstack(&stack, 0); | - | ||||||||||||||||||||||||
1405 | act.sa_flags |= SA_ONSTACK; | - | ||||||||||||||||||||||||
1406 | #endif | - | ||||||||||||||||||||||||
1407 | - | |||||||||||||||||||||||||
1408 | // Block all fatal signals in our signal handler so we don't try to close | - | ||||||||||||||||||||||||
1409 | // the testlog twice. | - | ||||||||||||||||||||||||
1410 | sigemptyset(&act.sa_mask); | - | ||||||||||||||||||||||||
1411 | for (int i = 0; fatalSignals[i]; ++i) | - | ||||||||||||||||||||||||
1412 | sigaddset(&act.sa_mask, fatalSignals[i]); | - | ||||||||||||||||||||||||
1413 | - | |||||||||||||||||||||||||
1414 | struct sigaction oldact; | - | ||||||||||||||||||||||||
1415 | - | |||||||||||||||||||||||||
1416 | for (int i = 0; fatalSignals[i]; ++i) { | - | ||||||||||||||||||||||||
1417 | sigaction(fatalSignals[i], &act, &oldact); | - | ||||||||||||||||||||||||
1418 | if ( | - | ||||||||||||||||||||||||
1419 | #ifdef SA_SIGINFO | - | ||||||||||||||||||||||||
1420 | oldact.sa_flags & SA_SIGINFO || | - | ||||||||||||||||||||||||
1421 | #endif | - | ||||||||||||||||||||||||
1422 | oldact.sa_handler != SIG_DFL) { | - | ||||||||||||||||||||||||
1423 | sigaction(fatalSignals[i], &oldact, 0); | - | ||||||||||||||||||||||||
1424 | } else | - | ||||||||||||||||||||||||
1425 | { | - | ||||||||||||||||||||||||
1426 | sigaddset(&handledSignals, fatalSignals[i]); | - | ||||||||||||||||||||||||
1427 | } | - | ||||||||||||||||||||||||
1428 | } | - | ||||||||||||||||||||||||
1429 | } | - | ||||||||||||||||||||||||
1430 | - | |||||||||||||||||||||||||
1431 | - | |||||||||||||||||||||||||
1432 | FatalSignalHandler::~FatalSignalHandler() | - | ||||||||||||||||||||||||
1433 | { | - | ||||||||||||||||||||||||
1434 | // Unregister any of our remaining signal handlers | - | ||||||||||||||||||||||||
1435 | struct sigaction act; | - | ||||||||||||||||||||||||
1436 | memset(&act, 0, sizeof(act)); | - | ||||||||||||||||||||||||
1437 | act.sa_handler = SIG_DFL; | - | ||||||||||||||||||||||||
1438 | - | |||||||||||||||||||||||||
1439 | struct sigaction oldact; | - | ||||||||||||||||||||||||
1440 | - | |||||||||||||||||||||||||
1441 | for (int i = 1; i < 32; ++i) { | - | ||||||||||||||||||||||||
1442 | if (!sigismember(&handledSignals, i)) | - | ||||||||||||||||||||||||
1443 | continue; | - | ||||||||||||||||||||||||
1444 | sigaction(i, &act, &oldact); | - | ||||||||||||||||||||||||
1445 | - | |||||||||||||||||||||||||
1446 | // If someone overwrote it in the mean time, put it back | - | ||||||||||||||||||||||||
1447 | if (oldact.sa_handler != FatalSignalHandler::signal) | - | ||||||||||||||||||||||||
1448 | sigaction(i, &oldact, 0); | - | ||||||||||||||||||||||||
1449 | } | - | ||||||||||||||||||||||||
1450 | } | - | ||||||||||||||||||||||||
1451 | - | |||||||||||||||||||||||||
1452 | #endif | - | ||||||||||||||||||||||||
1453 | - | |||||||||||||||||||||||||
1454 | - | |||||||||||||||||||||||||
1455 | } // namespace | - | ||||||||||||||||||||||||
1456 | - | |||||||||||||||||||||||||
1457 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
1458 | - | |||||||||||||||||||||||||
1459 | // Helper class for resolving symbol names by dynamically loading "dbghelp.dll". | - | ||||||||||||||||||||||||
1460 | class DebugSymbolResolver | - | ||||||||||||||||||||||||
1461 | { | - | ||||||||||||||||||||||||
1462 | Q_DISABLE_COPY(DebugSymbolResolver) | - | ||||||||||||||||||||||||
1463 | public: | - | ||||||||||||||||||||||||
1464 | struct Symbol { | - | ||||||||||||||||||||||||
1465 | Symbol() : name(Q_NULLPTR), address(0) {} | - | ||||||||||||||||||||||||
1466 | - | |||||||||||||||||||||||||
1467 | const char *name; // Must be freed by caller. | - | ||||||||||||||||||||||||
1468 | DWORD64 address; | - | ||||||||||||||||||||||||
1469 | }; | - | ||||||||||||||||||||||||
1470 | - | |||||||||||||||||||||||||
1471 | explicit DebugSymbolResolver(HANDLE process); | - | ||||||||||||||||||||||||
1472 | ~DebugSymbolResolver() { cleanup(); } | - | ||||||||||||||||||||||||
1473 | - | |||||||||||||||||||||||||
1474 | bool isValid() const { return m_symFromAddr; } | - | ||||||||||||||||||||||||
1475 | - | |||||||||||||||||||||||||
1476 | Symbol resolveSymbol(DWORD64 address) const; | - | ||||||||||||||||||||||||
1477 | - | |||||||||||||||||||||||||
1478 | private: | - | ||||||||||||||||||||||||
1479 | // typedefs from DbgHelp.h/.dll | - | ||||||||||||||||||||||||
1480 | struct DBGHELP_SYMBOL_INFO { // SYMBOL_INFO | - | ||||||||||||||||||||||||
1481 | ULONG SizeOfStruct; | - | ||||||||||||||||||||||||
1482 | ULONG TypeIndex; // Type Index of symbol | - | ||||||||||||||||||||||||
1483 | ULONG64 Reserved[2]; | - | ||||||||||||||||||||||||
1484 | ULONG Index; | - | ||||||||||||||||||||||||
1485 | ULONG Size; | - | ||||||||||||||||||||||||
1486 | ULONG64 ModBase; // Base Address of module comtaining this symbol | - | ||||||||||||||||||||||||
1487 | ULONG Flags; | - | ||||||||||||||||||||||||
1488 | ULONG64 Value; // Value of symbol, ValuePresent should be 1 | - | ||||||||||||||||||||||||
1489 | ULONG64 Address; // Address of symbol including base address of module | - | ||||||||||||||||||||||||
1490 | ULONG Register; // register holding value or pointer to value | - | ||||||||||||||||||||||||
1491 | ULONG Scope; // scope of the symbol | - | ||||||||||||||||||||||||
1492 | ULONG Tag; // pdb classification | - | ||||||||||||||||||||||||
1493 | ULONG NameLen; // Actual length of name | - | ||||||||||||||||||||||||
1494 | ULONG MaxNameLen; | - | ||||||||||||||||||||||||
1495 | CHAR Name[1]; // Name of symbol | - | ||||||||||||||||||||||||
1496 | }; | - | ||||||||||||||||||||||||
1497 | - | |||||||||||||||||||||||||
1498 | typedef BOOL (__stdcall *SymInitializeType)(HANDLE, PCSTR, BOOL); | - | ||||||||||||||||||||||||
1499 | typedef BOOL (__stdcall *SymFromAddrType)(HANDLE, DWORD64, PDWORD64, DBGHELP_SYMBOL_INFO *); | - | ||||||||||||||||||||||||
1500 | - | |||||||||||||||||||||||||
1501 | void cleanup(); | - | ||||||||||||||||||||||||
1502 | - | |||||||||||||||||||||||||
1503 | const HANDLE m_process; | - | ||||||||||||||||||||||||
1504 | HMODULE m_dbgHelpLib; | - | ||||||||||||||||||||||||
1505 | SymFromAddrType m_symFromAddr; | - | ||||||||||||||||||||||||
1506 | }; | - | ||||||||||||||||||||||||
1507 | - | |||||||||||||||||||||||||
1508 | void DebugSymbolResolver::cleanup() | - | ||||||||||||||||||||||||
1509 | { | - | ||||||||||||||||||||||||
1510 | if (m_dbgHelpLib) | - | ||||||||||||||||||||||||
1511 | FreeLibrary(m_dbgHelpLib); | - | ||||||||||||||||||||||||
1512 | m_dbgHelpLib = 0; | - | ||||||||||||||||||||||||
1513 | m_symFromAddr = Q_NULLPTR; | - | ||||||||||||||||||||||||
1514 | } | - | ||||||||||||||||||||||||
1515 | - | |||||||||||||||||||||||||
1516 | DebugSymbolResolver::DebugSymbolResolver(HANDLE process) | - | ||||||||||||||||||||||||
1517 | : m_process(process), m_dbgHelpLib(0), m_symFromAddr(Q_NULLPTR) | - | ||||||||||||||||||||||||
1518 | { | - | ||||||||||||||||||||||||
1519 | bool success = false; | - | ||||||||||||||||||||||||
1520 | m_dbgHelpLib = LoadLibraryW(L"dbghelp.dll"); | - | ||||||||||||||||||||||||
1521 | if (m_dbgHelpLib) { | - | ||||||||||||||||||||||||
1522 | SymInitializeType symInitialize = (SymInitializeType)(GetProcAddress(m_dbgHelpLib, "SymInitialize")); | - | ||||||||||||||||||||||||
1523 | m_symFromAddr = (SymFromAddrType)(GetProcAddress(m_dbgHelpLib, "SymFromAddr")); | - | ||||||||||||||||||||||||
1524 | success = symInitialize && m_symFromAddr && symInitialize(process, NULL, TRUE); | - | ||||||||||||||||||||||||
1525 | } | - | ||||||||||||||||||||||||
1526 | if (!success) | - | ||||||||||||||||||||||||
1527 | cleanup(); | - | ||||||||||||||||||||||||
1528 | } | - | ||||||||||||||||||||||||
1529 | - | |||||||||||||||||||||||||
1530 | DebugSymbolResolver::Symbol DebugSymbolResolver::resolveSymbol(DWORD64 address) const | - | ||||||||||||||||||||||||
1531 | { | - | ||||||||||||||||||||||||
1532 | // reserve additional buffer where SymFromAddr() will store the name | - | ||||||||||||||||||||||||
1533 | struct NamedSymbolInfo : public DBGHELP_SYMBOL_INFO { | - | ||||||||||||||||||||||||
1534 | enum { symbolNameLength = 255 }; | - | ||||||||||||||||||||||||
1535 | - | |||||||||||||||||||||||||
1536 | char name[symbolNameLength + 1]; | - | ||||||||||||||||||||||||
1537 | }; | - | ||||||||||||||||||||||||
1538 | - | |||||||||||||||||||||||||
1539 | Symbol result; | - | ||||||||||||||||||||||||
1540 | if (!isValid()) | - | ||||||||||||||||||||||||
1541 | return result; | - | ||||||||||||||||||||||||
1542 | NamedSymbolInfo symbolBuffer; | - | ||||||||||||||||||||||||
1543 | memset(&symbolBuffer, 0, sizeof(NamedSymbolInfo)); | - | ||||||||||||||||||||||||
1544 | symbolBuffer.MaxNameLen = NamedSymbolInfo::symbolNameLength; | - | ||||||||||||||||||||||||
1545 | symbolBuffer.SizeOfStruct = sizeof(DBGHELP_SYMBOL_INFO); | - | ||||||||||||||||||||||||
1546 | if (!m_symFromAddr(m_process, address, 0, &symbolBuffer)) | - | ||||||||||||||||||||||||
1547 | return result; | - | ||||||||||||||||||||||||
1548 | result.name = qstrdup(symbolBuffer.Name); | - | ||||||||||||||||||||||||
1549 | result.address = symbolBuffer.Address; | - | ||||||||||||||||||||||||
1550 | return result; | - | ||||||||||||||||||||||||
1551 | } | - | ||||||||||||||||||||||||
1552 | - | |||||||||||||||||||||||||
1553 | static LONG WINAPI windowsFaultHandler(struct _EXCEPTION_POINTERS *exInfo) | - | ||||||||||||||||||||||||
1554 | { | - | ||||||||||||||||||||||||
1555 | enum { maxStackFrames = 100 }; | - | ||||||||||||||||||||||||
1556 | char appName[MAX_PATH]; | - | ||||||||||||||||||||||||
1557 | if (!GetModuleFileNameA(NULL, appName, MAX_PATH)) | - | ||||||||||||||||||||||||
1558 | appName[0] = 0; | - | ||||||||||||||||||||||||
1559 | const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); | - | ||||||||||||||||||||||||
1560 | const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); | - | ||||||||||||||||||||||||
1561 | const void *exceptionAddress = exInfo->ExceptionRecord->ExceptionAddress; | - | ||||||||||||||||||||||||
1562 | printf("A crash occurred in %s.\n" | - | ||||||||||||||||||||||||
1563 | "Function time: %dms Total time: %dms\n\n" | - | ||||||||||||||||||||||||
1564 | "Exception address: 0x%p\n" | - | ||||||||||||||||||||||||
1565 | "Exception code : 0x%lx\n", | - | ||||||||||||||||||||||||
1566 | appName, msecsFunctionTime, msecsTotalTime, | - | ||||||||||||||||||||||||
1567 | exceptionAddress, exInfo->ExceptionRecord->ExceptionCode); | - | ||||||||||||||||||||||||
1568 | - | |||||||||||||||||||||||||
1569 | DebugSymbolResolver resolver(GetCurrentProcess()); | - | ||||||||||||||||||||||||
1570 | if (resolver.isValid()) { | - | ||||||||||||||||||||||||
1571 | DebugSymbolResolver::Symbol exceptionSymbol = resolver.resolveSymbol(DWORD64(exceptionAddress)); | - | ||||||||||||||||||||||||
1572 | if (exceptionSymbol.name) { | - | ||||||||||||||||||||||||
1573 | printf("Nearby symbol : %s\n", exceptionSymbol.name); | - | ||||||||||||||||||||||||
1574 | delete [] exceptionSymbol.name; | - | ||||||||||||||||||||||||
1575 | } | - | ||||||||||||||||||||||||
1576 | void *stack[maxStackFrames]; | - | ||||||||||||||||||||||||
1577 | fputs("\nStack:\n", stdout); | - | ||||||||||||||||||||||||
1578 | const unsigned frameCount = CaptureStackBackTrace(0, DWORD(maxStackFrames), stack, NULL); | - | ||||||||||||||||||||||||
1579 | for (unsigned f = 0; f < frameCount; ++f) { | - | ||||||||||||||||||||||||
1580 | DebugSymbolResolver::Symbol symbol = resolver.resolveSymbol(DWORD64(stack[f])); | - | ||||||||||||||||||||||||
1581 | if (symbol.name) { | - | ||||||||||||||||||||||||
1582 | printf("#%3u: %s() - 0x%p\n", f + 1, symbol.name, (const void *)symbol.address); | - | ||||||||||||||||||||||||
1583 | delete [] symbol.name; | - | ||||||||||||||||||||||||
1584 | } else { | - | ||||||||||||||||||||||||
1585 | printf("#%3u: Unable to obtain symbol\n", f + 1); | - | ||||||||||||||||||||||||
1586 | } | - | ||||||||||||||||||||||||
1587 | } | - | ||||||||||||||||||||||||
1588 | } | - | ||||||||||||||||||||||||
1589 | - | |||||||||||||||||||||||||
1590 | fputc('\n', stdout); | - | ||||||||||||||||||||||||
1591 | fflush(stdout); | - | ||||||||||||||||||||||||
1592 | - | |||||||||||||||||||||||||
1593 | return EXCEPTION_EXECUTE_HANDLER; | - | ||||||||||||||||||||||||
1594 | } | - | ||||||||||||||||||||||||
1595 | #endif // Q_OS_WIN) && !Q_OS_WINCE && !Q_OS_WINRT | - | ||||||||||||||||||||||||
1596 | - | |||||||||||||||||||||||||
1597 | static void initEnvironment() | - | ||||||||||||||||||||||||
1598 | { | - | ||||||||||||||||||||||||
1599 | qputenv("QT_LOGGING_TO_CONSOLE", "1"); | - | ||||||||||||||||||||||||
1600 | qputenv("QT_QTESTLIB_RUNNING", "1"); | - | ||||||||||||||||||||||||
1601 | } | - | ||||||||||||||||||||||||
1602 | - | |||||||||||||||||||||||||
1603 | /*! | - | ||||||||||||||||||||||||
1604 | Executes tests declared in \a testObject. In addition, the private slots | - | ||||||||||||||||||||||||
1605 | \c{initTestCase()}, \c{cleanupTestCase()}, \c{init()} and \c{cleanup()} | - | ||||||||||||||||||||||||
1606 | are executed if they exist. See \l{Creating a Test} for more details. | - | ||||||||||||||||||||||||
1607 | - | |||||||||||||||||||||||||
1608 | Optionally, the command line arguments \a argc and \a argv can be provided. | - | ||||||||||||||||||||||||
1609 | For a list of recognized arguments, read \l {Qt Test Command Line Arguments}. | - | ||||||||||||||||||||||||
1610 | - | |||||||||||||||||||||||||
1611 | The following example will run all tests in \c MyTestObject: | - | ||||||||||||||||||||||||
1612 | - | |||||||||||||||||||||||||
1613 | \snippet code/src_qtestlib_qtestcase.cpp 18 | - | ||||||||||||||||||||||||
1614 | - | |||||||||||||||||||||||||
1615 | This function returns 0 if no tests failed, or a value other than 0 if one | - | ||||||||||||||||||||||||
1616 | or more tests failed or in case of unhandled exceptions. (Skipped tests do | - | ||||||||||||||||||||||||
1617 | not influence the return value.) | - | ||||||||||||||||||||||||
1618 | - | |||||||||||||||||||||||||
1619 | For stand-alone test applications, the convenience macro \l QTEST_MAIN() can | - | ||||||||||||||||||||||||
1620 | be used to declare a main() function that parses the command line arguments | - | ||||||||||||||||||||||||
1621 | and executes the tests, avoiding the need to call this function explicitly. | - | ||||||||||||||||||||||||
1622 | - | |||||||||||||||||||||||||
1623 | The return value from this function is also the exit code of the test | - | ||||||||||||||||||||||||
1624 | application when the \l QTEST_MAIN() macro is used. | - | ||||||||||||||||||||||||
1625 | - | |||||||||||||||||||||||||
1626 | For stand-alone test applications, this function should not be called more | - | ||||||||||||||||||||||||
1627 | than once, as command-line options for logging test output to files and | - | ||||||||||||||||||||||||
1628 | executing individual test functions will not behave correctly. | - | ||||||||||||||||||||||||
1629 | - | |||||||||||||||||||||||||
1630 | Note: This function is not reentrant, only one test can run at a time. A | - | ||||||||||||||||||||||||
1631 | test that was executed with qExec() can't run another test via qExec() and | - | ||||||||||||||||||||||||
1632 | threads are not allowed to call qExec() simultaneously. | - | ||||||||||||||||||||||||
1633 | - | |||||||||||||||||||||||||
1634 | If you have programatically created the arguments, as opposed to getting them | - | ||||||||||||||||||||||||
1635 | from the arguments in \c main(), it is likely of interest to use | - | ||||||||||||||||||||||||
1636 | QTest::qExec(QObject *, const QStringList &) since it is Unicode safe. | - | ||||||||||||||||||||||||
1637 | - | |||||||||||||||||||||||||
1638 | \sa QTEST_MAIN() | - | ||||||||||||||||||||||||
1639 | */ | - | ||||||||||||||||||||||||
1640 | - | |||||||||||||||||||||||||
1641 | int QTest::qExec(QObject *testObject, int argc, char **argv) | - | ||||||||||||||||||||||||
1642 | { | - | ||||||||||||||||||||||||
1643 | initEnvironment(); | - | ||||||||||||||||||||||||
1644 | QBenchmarkGlobalData benchmarkData; | - | ||||||||||||||||||||||||
1645 | QBenchmarkGlobalData::current = &benchmarkData; | - | ||||||||||||||||||||||||
1646 | - | |||||||||||||||||||||||||
1647 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
1648 | int callgrindChildExitCode = 0; | - | ||||||||||||||||||||||||
1649 | #endif | - | ||||||||||||||||||||||||
1650 | - | |||||||||||||||||||||||||
1651 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
1652 | bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0); | - | ||||||||||||||||||||||||
1653 | IOPMAssertionID powerID; | - | ||||||||||||||||||||||||
1654 | - | |||||||||||||||||||||||||
1655 | // Don't restore saved window state for auto tests. | - | ||||||||||||||||||||||||
1656 | QTestPrivate::disableWindowRestore(); | - | ||||||||||||||||||||||||
1657 | #endif | - | ||||||||||||||||||||||||
1658 | #ifndef QT_NO_EXCEPTIONS | - | ||||||||||||||||||||||||
1659 | try { | - | ||||||||||||||||||||||||
1660 | #endif | - | ||||||||||||||||||||||||
1661 | - | |||||||||||||||||||||||||
1662 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
1663 | if (macNeedsActivate) { | - | ||||||||||||||||||||||||
1664 | CFStringRef reasonForActivity= CFSTR("No Display Sleep"); | - | ||||||||||||||||||||||||
1665 | IOReturn ok = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &powerID); | - | ||||||||||||||||||||||||
1666 | - | |||||||||||||||||||||||||
1667 | if (ok != kIOReturnSuccess) | - | ||||||||||||||||||||||||
1668 | macNeedsActivate = false; // no need to release the assertion on exit. | - | ||||||||||||||||||||||||
1669 | } | - | ||||||||||||||||||||||||
1670 | #endif | - | ||||||||||||||||||||||||
1671 | - | |||||||||||||||||||||||||
1672 | QTestPrivate::parseBlackList(); | - | ||||||||||||||||||||||||
1673 | QTestPrivate::parseGpuBlackList(); | - | ||||||||||||||||||||||||
1674 | - | |||||||||||||||||||||||||
1675 | QTestResult::reset(); | - | ||||||||||||||||||||||||
1676 | - | |||||||||||||||||||||||||
1677 | QTEST_ASSERT(testObject); never executed: qt_assert("testObject",__FILE__,1677);
| 0-815 | ||||||||||||||||||||||||
1678 | QTEST_ASSERT(!currentTestObject); never executed: qt_assert("!currentTestObject",__FILE__,1678);
| 0-815 | ||||||||||||||||||||||||
1679 | currentTestObject = testObject; | - | ||||||||||||||||||||||||
1680 | - | |||||||||||||||||||||||||
1681 | const QMetaObject *metaObject = testObject->metaObject(); | - | ||||||||||||||||||||||||
1682 | QTEST_ASSERT(metaObject); never executed: qt_assert("metaObject",__FILE__,1682);
| 0-815 | ||||||||||||||||||||||||
1683 | - | |||||||||||||||||||||||||
1684 | QTestResult::setCurrentTestObject(metaObject->className()); | - | ||||||||||||||||||||||||
1685 | if (argc > 0)
| 0-815 | ||||||||||||||||||||||||
1686 | QTestResult::setCurrentAppName(argv[0]); executed 815 times by 1 test: QTestResult::setCurrentAppName(argv[0]); Executed by:
| 815 | ||||||||||||||||||||||||
1687 | - | |||||||||||||||||||||||||
1688 | qtest_qParseArgs(argc, argv, false); | - | ||||||||||||||||||||||||
1689 | - | |||||||||||||||||||||||||
1690 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
1691 | if (!noCrashHandler) { | - | ||||||||||||||||||||||||
1692 | # ifndef Q_CC_MINGW | - | ||||||||||||||||||||||||
1693 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); | - | ||||||||||||||||||||||||
1694 | # endif | - | ||||||||||||||||||||||||
1695 | # ifndef Q_OS_WINRT | - | ||||||||||||||||||||||||
1696 | SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); | - | ||||||||||||||||||||||||
1697 | SetUnhandledExceptionFilter(windowsFaultHandler); | - | ||||||||||||||||||||||||
1698 | # endif | - | ||||||||||||||||||||||||
1699 | } // !noCrashHandler | - | ||||||||||||||||||||||||
1700 | #endif // Q_OS_WIN) && !Q_OS_WINCE && !Q_OS_WINRT | - | ||||||||||||||||||||||||
1701 | - | |||||||||||||||||||||||||
1702 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
1703 | if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
| 0-1320 | ||||||||||||||||||||||||
1704 | if (Q_UNLIKELY(!qApp)))
| 0 | ||||||||||||||||||||||||
1705 | qFatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN"); never executed: QMessageLogger(__FILE__, 1705, __PRETTY_FUNCTION__).fatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN"); | 0 | ||||||||||||||||||||||||
1706 | - | |||||||||||||||||||||||||
1707 | const QStringList origAppArgs(QCoreApplication::arguments()); | - | ||||||||||||||||||||||||
1708 | if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode))
| 0 | ||||||||||||||||||||||||
1709 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
1710 | - | |||||||||||||||||||||||||
1711 | QBenchmarkValgrindUtils::cleanup(); | - | ||||||||||||||||||||||||
1712 | - | |||||||||||||||||||||||||
1713 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
1714 | #endif | - | ||||||||||||||||||||||||
1715 | { | - | ||||||||||||||||||||||||
1716 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
1717 | QScopedPointer<FatalSignalHandler> handler; | - | ||||||||||||||||||||||||
1718 | if (!noCrashHandler)
| 0-1320 | ||||||||||||||||||||||||
1719 | handler.reset(new FatalSignalHandler); executed 1320 times by 506 tests: handler.reset(new FatalSignalHandler); Executed by:
| 1320 | ||||||||||||||||||||||||
1720 | #endif | - | ||||||||||||||||||||||||
1721 | qInvokeTestMethodsTestMethods::MetaMethods commandLineMethods; | - | ||||||||||||||||||||||||
1722 | for (const QString &tf : qAsConst(QTest::testFunctions)) { | - | ||||||||||||||||||||||||
1723 | const QByteArray tfB = tf.toLatin1(); | - | ||||||||||||||||||||||||
1724 | const QByteArray signature = tfB + QByteArrayLiteral("()"); executed 64 times by 1 test: return ba; Executed by:
| 64 | ||||||||||||||||||||||||
1725 | QMetaMethod m = TestMethods::findMethod(testObject, signature.constData()); | - | ||||||||||||||||||||||||
1726 | if (!m.isValid() || !isValidSlot(m)) {
| 0-64 | ||||||||||||||||||||||||
1727 | fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n", tfB.constData()); | - | ||||||||||||||||||||||||
1728 | qPrintTestSlots(stderr, tfB.constData()); | - | ||||||||||||||||||||||||
1729 | fprintf(stderr, "\n%s -functions\nlists all available test functions.\n", argv[0]); | - | ||||||||||||||||||||||||
1730 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
1731 | } | - | ||||||||||||||||||||||||
1732 | commandLineMethods.push_back(m); | - | ||||||||||||||||||||||||
1733 | } executed 64 times by 1 test: end of block Executed by:
| 64 | ||||||||||||||||||||||||
1734 | TestMethods test(testObject, commandLineMethods); | - | ||||||||||||||||||||||||
1735 | test.invokeTests(testObject); | - | ||||||||||||||||||||||||
1736 | } executed 1238 times by 508 tests: end of block Executed by:
| 1238 | ||||||||||||||||||||||||
1737 | - | |||||||||||||||||||||||||
1738 | #ifndef QT_NO_EXCEPTIONS | - | ||||||||||||||||||||||||
1739 | } catch (...) { | - | ||||||||||||||||||||||||
1740 | QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__); | - | ||||||||||||||||||||||||
1741 | if (QTestResult::currentTestFunction()) {
| 0-25 | ||||||||||||||||||||||||
1742 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
1743 | QTestResult::setCurrentTestFunction(0); | - | ||||||||||||||||||||||||
1744 | } executed 25 times by 1 test: end of block Executed by:
| 25 | ||||||||||||||||||||||||
1745 | - | |||||||||||||||||||||||||
1746 | QTestLog::stopLogging(); | - | ||||||||||||||||||||||||
1747 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
1748 | if (macNeedsActivate) { | - | ||||||||||||||||||||||||
1749 | IOPMAssertionRelease(powerID); | - | ||||||||||||||||||||||||
1750 | } | - | ||||||||||||||||||||||||
1751 | #endif | - | ||||||||||||||||||||||||
1752 | currentTestObject = 0; | - | ||||||||||||||||||||||||
1753 | - | |||||||||||||||||||||||||
1754 | // Rethrow exception to make debugging easier. | - | ||||||||||||||||||||||||
1755 | throw; executed 25 times by 1 test: throw; Executed by:
| 25 | ||||||||||||||||||||||||
1756 | return 1; dead code: return 1; | - | ||||||||||||||||||||||||
1757 | } | - | ||||||||||||||||||||||||
1758 | #endif | - | ||||||||||||||||||||||||
1759 | - | |||||||||||||||||||||||||
1760 | currentTestObject = 0; | - | ||||||||||||||||||||||||
1761 | - | |||||||||||||||||||||||||
1762 | QSignalDumper::endDump(); | - | ||||||||||||||||||||||||
1763 | - | |||||||||||||||||||||||||
1764 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
1765 | if (macNeedsActivate) { | - | ||||||||||||||||||||||||
1766 | IOPMAssertionRelease(powerID); | - | ||||||||||||||||||||||||
1767 | } | - | ||||||||||||||||||||||||
1768 | #endif | - | ||||||||||||||||||||||||
1769 | - | |||||||||||||||||||||||||
1770 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
1771 | if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
| 0-1238 | ||||||||||||||||||||||||
1772 | return callgrindChildExitCode; never executed: return callgrindChildExitCode; | 0 | ||||||||||||||||||||||||
1773 | #endif | - | ||||||||||||||||||||||||
1774 | // make sure our exit code is never going above 127 | - | ||||||||||||||||||||||||
1775 | // since that could wrap and indicate 0 test fails | - | ||||||||||||||||||||||||
1776 | return qMin(QTestLog::failCount(), 127); executed 1238 times by 508 tests: return qMin(QTestLog::failCount(), 127); Executed by:
| 1238 | ||||||||||||||||||||||||
1777 | } | - | ||||||||||||||||||||||||
1778 | - | |||||||||||||||||||||||||
1779 | /*! | - | ||||||||||||||||||||||||
1780 | \overload | - | ||||||||||||||||||||||||
1781 | \since 4.4 | - | ||||||||||||||||||||||||
1782 | - | |||||||||||||||||||||||||
1783 | Behaves identically to qExec(QObject *, int, char**) but takes a | - | ||||||||||||||||||||||||
1784 | QStringList of \a arguments instead of a \c char** list. | - | ||||||||||||||||||||||||
1785 | */ | - | ||||||||||||||||||||||||
1786 | int QTest::qExec(QObject *testObject, const QStringList &arguments) | - | ||||||||||||||||||||||||
1787 | { | - | ||||||||||||||||||||||||
1788 | const int argc = arguments.count(); | - | ||||||||||||||||||||||||
1789 | QVarLengthArray<char *> argv(argc); | - | ||||||||||||||||||||||||
1790 | - | |||||||||||||||||||||||||
1791 | QVector<QByteArray> args; | - | ||||||||||||||||||||||||
1792 | args.reserve(argc); | - | ||||||||||||||||||||||||
1793 | - | |||||||||||||||||||||||||
1794 | for (int i = 0; i < argc; ++i) | - | ||||||||||||||||||||||||
1795 | { | - | ||||||||||||||||||||||||
1796 | args.append(arguments.at(i).toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
1797 | argv[i] = args.last().data(); | - | ||||||||||||||||||||||||
1798 | } | - | ||||||||||||||||||||||||
1799 | - | |||||||||||||||||||||||||
1800 | return qExec(testObject, argc, argv.data()); | - | ||||||||||||||||||||||||
1801 | } | - | ||||||||||||||||||||||||
1802 | - | |||||||||||||||||||||||||
1803 | /*! \internal | - | ||||||||||||||||||||||||
1804 | */ | - | ||||||||||||||||||||||||
1805 | void QTest::qFail(const char *statementStr, const char *file, int line) | - | ||||||||||||||||||||||||
1806 | { | - | ||||||||||||||||||||||||
1807 | QTestResult::addFailure(statementStr, file, line); | - | ||||||||||||||||||||||||
1808 | } | - | ||||||||||||||||||||||||
1809 | - | |||||||||||||||||||||||||
1810 | /*! \internal | - | ||||||||||||||||||||||||
1811 | */ | - | ||||||||||||||||||||||||
1812 | bool QTest::qVerify(bool statement, const char *statementStr, const char *description, | - | ||||||||||||||||||||||||
1813 | const char *file, int line) | - | ||||||||||||||||||||||||
1814 | { | - | ||||||||||||||||||||||||
1815 | return QTestResult::verify(statement, statementStr, description, file, line); | - | ||||||||||||||||||||||||
1816 | } | - | ||||||||||||||||||||||||
1817 | - | |||||||||||||||||||||||||
1818 | /*! \fn void QTest::qSkip(const char *message, const char *file, int line) | - | ||||||||||||||||||||||||
1819 | \internal | - | ||||||||||||||||||||||||
1820 | */ | - | ||||||||||||||||||||||||
1821 | void QTest::qSkip(const char *message, const char *file, int line) | - | ||||||||||||||||||||||||
1822 | { | - | ||||||||||||||||||||||||
1823 | QTestResult::addSkip(message, file, line); | - | ||||||||||||||||||||||||
1824 | QTestResult::setSkipCurrentTest(true); | - | ||||||||||||||||||||||||
1825 | } | - | ||||||||||||||||||||||||
1826 | - | |||||||||||||||||||||||||
1827 | /*! \fn bool QTest::qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line) | - | ||||||||||||||||||||||||
1828 | \internal | - | ||||||||||||||||||||||||
1829 | */ | - | ||||||||||||||||||||||||
1830 | bool QTest::qExpectFail(const char *dataIndex, const char *comment, | - | ||||||||||||||||||||||||
1831 | QTest::TestFailMode mode, const char *file, int line) | - | ||||||||||||||||||||||||
1832 | { | - | ||||||||||||||||||||||||
1833 | return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line); | - | ||||||||||||||||||||||||
1834 | } | - | ||||||||||||||||||||||||
1835 | - | |||||||||||||||||||||||||
1836 | /*! \internal | - | ||||||||||||||||||||||||
1837 | */ | - | ||||||||||||||||||||||||
1838 | void QTest::qWarn(const char *message, const char *file, int line) | - | ||||||||||||||||||||||||
1839 | { | - | ||||||||||||||||||||||||
1840 | QTestLog::warn(message, file, line); | - | ||||||||||||||||||||||||
1841 | } | - | ||||||||||||||||||||||||
1842 | - | |||||||||||||||||||||||||
1843 | /*! | - | ||||||||||||||||||||||||
1844 | Ignores messages created by qDebug(), qInfo() or qWarning(). If the \a message | - | ||||||||||||||||||||||||
1845 | with the corresponding \a type is outputted, it will be removed from the | - | ||||||||||||||||||||||||
1846 | test log. If the test finished and the \a message was not outputted, | - | ||||||||||||||||||||||||
1847 | a test failure is appended to the test log. | - | ||||||||||||||||||||||||
1848 | - | |||||||||||||||||||||||||
1849 | \b {Note:} Invoking this function will only ignore one message. | - | ||||||||||||||||||||||||
1850 | If the message you want to ignore is outputted twice, you have to | - | ||||||||||||||||||||||||
1851 | call ignoreMessage() twice, too. | - | ||||||||||||||||||||||||
1852 | - | |||||||||||||||||||||||||
1853 | Example: | - | ||||||||||||||||||||||||
1854 | \snippet code/src_qtestlib_qtestcase.cpp 19 | - | ||||||||||||||||||||||||
1855 | - | |||||||||||||||||||||||||
1856 | The example above tests that QDir::mkdir() outputs the right warning when invoked | - | ||||||||||||||||||||||||
1857 | with an invalid file name. | - | ||||||||||||||||||||||||
1858 | */ | - | ||||||||||||||||||||||||
1859 | void QTest::ignoreMessage(QtMsgType type, const char *message) | - | ||||||||||||||||||||||||
1860 | { | - | ||||||||||||||||||||||||
1861 | QTestLog::ignoreMessage(type, message); | - | ||||||||||||||||||||||||
1862 | } | - | ||||||||||||||||||||||||
1863 | - | |||||||||||||||||||||||||
1864 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
1865 | /*! | - | ||||||||||||||||||||||||
1866 | \overload | - | ||||||||||||||||||||||||
1867 | - | |||||||||||||||||||||||||
1868 | Ignores messages created by qDebug(), qInfo() or qWarning(). If the message | - | ||||||||||||||||||||||||
1869 | matching \a messagePattern | - | ||||||||||||||||||||||||
1870 | with the corresponding \a type is outputted, it will be removed from the | - | ||||||||||||||||||||||||
1871 | test log. If the test finished and the message was not outputted, | - | ||||||||||||||||||||||||
1872 | a test failure is appended to the test log. | - | ||||||||||||||||||||||||
1873 | - | |||||||||||||||||||||||||
1874 | \b {Note:} Invoking this function will only ignore one message. | - | ||||||||||||||||||||||||
1875 | If the message you want to ignore is outputted twice, you have to | - | ||||||||||||||||||||||||
1876 | call ignoreMessage() twice, too. | - | ||||||||||||||||||||||||
1877 | - | |||||||||||||||||||||||||
1878 | \since 5.3 | - | ||||||||||||||||||||||||
1879 | */ | - | ||||||||||||||||||||||||
1880 | void QTest::ignoreMessage(QtMsgType type, const QRegularExpression &messagePattern) | - | ||||||||||||||||||||||||
1881 | { | - | ||||||||||||||||||||||||
1882 | QTestLog::ignoreMessage(type, messagePattern); | - | ||||||||||||||||||||||||
1883 | } | - | ||||||||||||||||||||||||
1884 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
1885 | - | |||||||||||||||||||||||||
1886 | /*! \internal | - | ||||||||||||||||||||||||
1887 | */ | - | ||||||||||||||||||||||||
1888 | - | |||||||||||||||||||||||||
1889 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
1890 | static inline bool isWindowsBuildDirectory(const QString &dirName) | - | ||||||||||||||||||||||||
1891 | { | - | ||||||||||||||||||||||||
1892 | return dirName.compare(QLatin1String("Debug"), Qt::CaseInsensitive) == 0 | - | ||||||||||||||||||||||||
1893 | || dirName.compare(QLatin1String("Release"), Qt::CaseInsensitive) == 0; | - | ||||||||||||||||||||||||
1894 | } | - | ||||||||||||||||||||||||
1895 | #endif | - | ||||||||||||||||||||||||
1896 | - | |||||||||||||||||||||||||
1897 | /*! | - | ||||||||||||||||||||||||
1898 | Extracts a directory from resources to disk. The content is extracted | - | ||||||||||||||||||||||||
1899 | recursively to a temporary folder. The extracted content is removed | - | ||||||||||||||||||||||||
1900 | automatically once the last reference to the return value goes out of scope. | - | ||||||||||||||||||||||||
1901 | - | |||||||||||||||||||||||||
1902 | \a dirName is the name of the directory to extract from resources. | - | ||||||||||||||||||||||||
1903 | - | |||||||||||||||||||||||||
1904 | Returns the temporary directory where the data was extracted or null in case of | - | ||||||||||||||||||||||||
1905 | errors. | - | ||||||||||||||||||||||||
1906 | */ | - | ||||||||||||||||||||||||
1907 | QSharedPointer<QTemporaryDir> QTest::qExtractTestData(const QString &dirName) | - | ||||||||||||||||||||||||
1908 | { | - | ||||||||||||||||||||||||
1909 | QSharedPointer<QTemporaryDir> result; // null until success, then == tempDir | - | ||||||||||||||||||||||||
1910 | - | |||||||||||||||||||||||||
1911 | QSharedPointer<QTemporaryDir> tempDir = QSharedPointer<QTemporaryDir>::create(); | - | ||||||||||||||||||||||||
1912 | - | |||||||||||||||||||||||||
1913 | tempDir->setAutoRemove(true); | - | ||||||||||||||||||||||||
1914 | - | |||||||||||||||||||||||||
1915 | if (!tempDir->isValid()) | - | ||||||||||||||||||||||||
1916 | return result; | - | ||||||||||||||||||||||||
1917 | - | |||||||||||||||||||||||||
1918 | const QString dataPath = tempDir->path(); | - | ||||||||||||||||||||||||
1919 | const QString resourcePath = QLatin1Char(':') + dirName; | - | ||||||||||||||||||||||||
1920 | const QFileInfo fileInfo(resourcePath); | - | ||||||||||||||||||||||||
1921 | - | |||||||||||||||||||||||||
1922 | if (!fileInfo.isDir()) { | - | ||||||||||||||||||||||||
1923 | qWarning("Resource path '%s' is not a directory.", qPrintable(resourcePath)); | - | ||||||||||||||||||||||||
1924 | return result; | - | ||||||||||||||||||||||||
1925 | } | - | ||||||||||||||||||||||||
1926 | - | |||||||||||||||||||||||||
1927 | QDirIterator it(resourcePath, QDirIterator::Subdirectories); | - | ||||||||||||||||||||||||
1928 | if (!it.hasNext()) { | - | ||||||||||||||||||||||||
1929 | qWarning("Resource directory '%s' is empty.", qPrintable(resourcePath)); | - | ||||||||||||||||||||||||
1930 | return result; | - | ||||||||||||||||||||||||
1931 | } | - | ||||||||||||||||||||||||
1932 | - | |||||||||||||||||||||||||
1933 | while (it.hasNext()) { | - | ||||||||||||||||||||||||
1934 | it.next(); | - | ||||||||||||||||||||||||
1935 | - | |||||||||||||||||||||||||
1936 | QFileInfo fileInfo = it.fileInfo(); | - | ||||||||||||||||||||||||
1937 | - | |||||||||||||||||||||||||
1938 | if (!fileInfo.isDir()) { | - | ||||||||||||||||||||||||
1939 | const QString destination = dataPath + QLatin1Char('/') + fileInfo.filePath().midRef(resourcePath.length()); | - | ||||||||||||||||||||||||
1940 | QFileInfo destinationFileInfo(destination); | - | ||||||||||||||||||||||||
1941 | QDir().mkpath(destinationFileInfo.path()); | - | ||||||||||||||||||||||||
1942 | if (!QFile::copy(fileInfo.filePath(), destination)) { | - | ||||||||||||||||||||||||
1943 | qWarning("Failed to copy '%s'.", qPrintable(fileInfo.filePath())); | - | ||||||||||||||||||||||||
1944 | return result; | - | ||||||||||||||||||||||||
1945 | } | - | ||||||||||||||||||||||||
1946 | if (!QFile::setPermissions(destination, QFile::ReadUser | QFile::WriteUser | QFile::ReadGroup)) { | - | ||||||||||||||||||||||||
1947 | qWarning("Failed to set permissions on '%s'.", qPrintable(destination)); | - | ||||||||||||||||||||||||
1948 | return result; | - | ||||||||||||||||||||||||
1949 | } | - | ||||||||||||||||||||||||
1950 | } | - | ||||||||||||||||||||||||
1951 | } | - | ||||||||||||||||||||||||
1952 | - | |||||||||||||||||||||||||
1953 | result = qMove(tempDir); | - | ||||||||||||||||||||||||
1954 | - | |||||||||||||||||||||||||
1955 | return result; | - | ||||||||||||||||||||||||
1956 | } | - | ||||||||||||||||||||||||
1957 | - | |||||||||||||||||||||||||
1958 | /*! \internal | - | ||||||||||||||||||||||||
1959 | */ | - | ||||||||||||||||||||||||
1960 | - | |||||||||||||||||||||||||
1961 | QString QTest::qFindTestData(const QString& base, const char *file, int line, const char *builddir) | - | ||||||||||||||||||||||||
1962 | { | - | ||||||||||||||||||||||||
1963 | QString found; | - | ||||||||||||||||||||||||
1964 | - | |||||||||||||||||||||||||
1965 | // Testdata priorities: | - | ||||||||||||||||||||||||
1966 | - | |||||||||||||||||||||||||
1967 | // 1. relative to test binary. | - | ||||||||||||||||||||||||
1968 | if (qApp) { | - | ||||||||||||||||||||||||
1969 | QDir binDirectory(QCoreApplication::applicationDirPath()); | - | ||||||||||||||||||||||||
1970 | if (binDirectory.exists(base)) { | - | ||||||||||||||||||||||||
1971 | found = binDirectory.absoluteFilePath(base); | - | ||||||||||||||||||||||||
1972 | } | - | ||||||||||||||||||||||||
1973 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
1974 | // Windows: The executable is typically located in one of the | - | ||||||||||||||||||||||||
1975 | // 'Release' or 'Debug' directories. | - | ||||||||||||||||||||||||
1976 | else if (isWindowsBuildDirectory(binDirectory.dirName()) | - | ||||||||||||||||||||||||
1977 | && binDirectory.cdUp() && binDirectory.exists(base)) { | - | ||||||||||||||||||||||||
1978 | found = binDirectory.absoluteFilePath(base); | - | ||||||||||||||||||||||||
1979 | } | - | ||||||||||||||||||||||||
1980 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||
1981 | else if (QTestLog::verboseLevel() >= 2) { | - | ||||||||||||||||||||||||
1982 | const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QLatin1Char('/') + base); | - | ||||||||||||||||||||||||
1983 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
1984 | QString::fromLatin1("testdata %1 not found relative to test binary [%2]; " | - | ||||||||||||||||||||||||
1985 | "checking next location").arg(base, candidate)), | - | ||||||||||||||||||||||||
1986 | file, line); | - | ||||||||||||||||||||||||
1987 | } | - | ||||||||||||||||||||||||
1988 | } | - | ||||||||||||||||||||||||
1989 | - | |||||||||||||||||||||||||
1990 | // 2. installed path. | - | ||||||||||||||||||||||||
1991 | if (found.isEmpty()) { | - | ||||||||||||||||||||||||
1992 | const char *testObjectName = QTestResult::currentTestObjectName(); | - | ||||||||||||||||||||||||
1993 | if (testObjectName) { | - | ||||||||||||||||||||||||
1994 | QString testsPath = QLibraryInfo::location(QLibraryInfo::TestsPath); | - | ||||||||||||||||||||||||
1995 | QString candidate = QString::fromLatin1("%1/%2/%3") | - | ||||||||||||||||||||||||
1996 | .arg(testsPath, QFile::decodeName(testObjectName).toLower(), base); | - | ||||||||||||||||||||||||
1997 | if (QFileInfo::exists(candidate)) { | - | ||||||||||||||||||||||||
1998 | found = candidate; | - | ||||||||||||||||||||||||
1999 | } | - | ||||||||||||||||||||||||
2000 | else if (QTestLog::verboseLevel() >= 2) { | - | ||||||||||||||||||||||||
2001 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
2002 | QString::fromLatin1("testdata %1 not found in tests install path [%2]; " | - | ||||||||||||||||||||||||
2003 | "checking next location") | - | ||||||||||||||||||||||||
2004 | .arg(base, QDir::toNativeSeparators(candidate))), | - | ||||||||||||||||||||||||
2005 | file, line); | - | ||||||||||||||||||||||||
2006 | } | - | ||||||||||||||||||||||||
2007 | } | - | ||||||||||||||||||||||||
2008 | } | - | ||||||||||||||||||||||||
2009 | - | |||||||||||||||||||||||||
2010 | // 3. relative to test source. | - | ||||||||||||||||||||||||
2011 | if (found.isEmpty()) { | - | ||||||||||||||||||||||||
2012 | // srcdir is the directory containing the calling source file. | - | ||||||||||||||||||||||||
2013 | QFileInfo srcdir = QFileInfo(QFile::decodeName(file)).path(); | - | ||||||||||||||||||||||||
2014 | - | |||||||||||||||||||||||||
2015 | // If the srcdir is relative, that means it is relative to the current working | - | ||||||||||||||||||||||||
2016 | // directory of the compiler at compile time, which should be passed in as `builddir'. | - | ||||||||||||||||||||||||
2017 | if (!srcdir.isAbsolute() && builddir) { | - | ||||||||||||||||||||||||
2018 | srcdir.setFile(QFile::decodeName(builddir) + QLatin1String("/") + srcdir.filePath()); | - | ||||||||||||||||||||||||
2019 | } | - | ||||||||||||||||||||||||
2020 | - | |||||||||||||||||||||||||
2021 | QString candidate = QString::fromLatin1("%1/%2").arg(srcdir.canonicalFilePath(), base); | - | ||||||||||||||||||||||||
2022 | if (QFileInfo::exists(candidate)) { | - | ||||||||||||||||||||||||
2023 | found = candidate; | - | ||||||||||||||||||||||||
2024 | } | - | ||||||||||||||||||||||||
2025 | else if (QTestLog::verboseLevel() >= 2) { | - | ||||||||||||||||||||||||
2026 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
2027 | QString::fromLatin1("testdata %1 not found relative to source path [%2]") | - | ||||||||||||||||||||||||
2028 | .arg(base, QDir::toNativeSeparators(candidate))), | - | ||||||||||||||||||||||||
2029 | file, line); | - | ||||||||||||||||||||||||
2030 | } | - | ||||||||||||||||||||||||
2031 | } | - | ||||||||||||||||||||||||
2032 | - | |||||||||||||||||||||||||
2033 | // 4. Try resources | - | ||||||||||||||||||||||||
2034 | if (found.isEmpty()) { | - | ||||||||||||||||||||||||
2035 | QString candidate = QString::fromLatin1(":/%1").arg(base); | - | ||||||||||||||||||||||||
2036 | if (QFileInfo::exists(candidate)) | - | ||||||||||||||||||||||||
2037 | found = candidate; | - | ||||||||||||||||||||||||
2038 | } | - | ||||||||||||||||||||||||
2039 | - | |||||||||||||||||||||||||
2040 | // 5. Try current directory | - | ||||||||||||||||||||||||
2041 | if (found.isEmpty()) { | - | ||||||||||||||||||||||||
2042 | QString candidate = QString::fromLatin1("%1/%2").arg(QDir::currentPath()).arg(base); | - | ||||||||||||||||||||||||
2043 | if (QFileInfo::exists(candidate)) | - | ||||||||||||||||||||||||
2044 | found = candidate; | - | ||||||||||||||||||||||||
2045 | } | - | ||||||||||||||||||||||||
2046 | - | |||||||||||||||||||||||||
2047 | // 6. Try main source directory | - | ||||||||||||||||||||||||
2048 | if (found.isEmpty()) { | - | ||||||||||||||||||||||||
2049 | QString candidate = QTest::mainSourcePath % QLatin1Char('/') % base; | - | ||||||||||||||||||||||||
2050 | if (QFileInfo::exists(candidate)) | - | ||||||||||||||||||||||||
2051 | found = candidate; | - | ||||||||||||||||||||||||
2052 | } | - | ||||||||||||||||||||||||
2053 | - | |||||||||||||||||||||||||
2054 | if (found.isEmpty()) { | - | ||||||||||||||||||||||||
2055 | QTest::qWarn(qPrintable( | - | ||||||||||||||||||||||||
2056 | QString::fromLatin1("testdata %1 could not be located!").arg(base)), | - | ||||||||||||||||||||||||
2057 | file, line); | - | ||||||||||||||||||||||||
2058 | } | - | ||||||||||||||||||||||||
2059 | else if (QTestLog::verboseLevel() >= 1) { | - | ||||||||||||||||||||||||
2060 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
2061 | QString::fromLatin1("testdata %1 was located at %2").arg(base, QDir::toNativeSeparators(found))), | - | ||||||||||||||||||||||||
2062 | file, line); | - | ||||||||||||||||||||||||
2063 | } | - | ||||||||||||||||||||||||
2064 | - | |||||||||||||||||||||||||
2065 | return found; | - | ||||||||||||||||||||||||
2066 | } | - | ||||||||||||||||||||||||
2067 | - | |||||||||||||||||||||||||
2068 | /*! \internal | - | ||||||||||||||||||||||||
2069 | */ | - | ||||||||||||||||||||||||
2070 | QString QTest::qFindTestData(const char *base, const char *file, int line, const char *builddir) | - | ||||||||||||||||||||||||
2071 | { | - | ||||||||||||||||||||||||
2072 | return qFindTestData(QFile::decodeName(base), file, line, builddir); | - | ||||||||||||||||||||||||
2073 | } | - | ||||||||||||||||||||||||
2074 | - | |||||||||||||||||||||||||
2075 | /*! \internal | - | ||||||||||||||||||||||||
2076 | */ | - | ||||||||||||||||||||||||
2077 | void *QTest::qData(const char *tagName, int typeId) | - | ||||||||||||||||||||||||
2078 | { | - | ||||||||||||||||||||||||
2079 | return fetchData(QTestResult::currentTestData(), tagName, typeId); | - | ||||||||||||||||||||||||
2080 | } | - | ||||||||||||||||||||||||
2081 | - | |||||||||||||||||||||||||
2082 | /*! \internal | - | ||||||||||||||||||||||||
2083 | */ | - | ||||||||||||||||||||||||
2084 | void *QTest::qGlobalData(const char *tagName, int typeId) | - | ||||||||||||||||||||||||
2085 | { | - | ||||||||||||||||||||||||
2086 | return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId); | - | ||||||||||||||||||||||||
2087 | } | - | ||||||||||||||||||||||||
2088 | - | |||||||||||||||||||||||||
2089 | /*! \internal | - | ||||||||||||||||||||||||
2090 | */ | - | ||||||||||||||||||||||||
2091 | void *QTest::qElementData(const char *tagName, int metaTypeId) | - | ||||||||||||||||||||||||
2092 | { | - | ||||||||||||||||||||||||
2093 | QTEST_ASSERT(tagName); | - | ||||||||||||||||||||||||
2094 | QTestData *data = QTestResult::currentTestData(); | - | ||||||||||||||||||||||||
2095 | QTEST_ASSERT(data); | - | ||||||||||||||||||||||||
2096 | QTEST_ASSERT(data->parent()); | - | ||||||||||||||||||||||||
2097 | - | |||||||||||||||||||||||||
2098 | int idx = data->parent()->indexOf(tagName); | - | ||||||||||||||||||||||||
2099 | QTEST_ASSERT(idx != -1); | - | ||||||||||||||||||||||||
2100 | QTEST_ASSERT(data->parent()->elementTypeId(idx) == metaTypeId); | - | ||||||||||||||||||||||||
2101 | - | |||||||||||||||||||||||||
2102 | return data->data(data->parent()->indexOf(tagName)); | - | ||||||||||||||||||||||||
2103 | } | - | ||||||||||||||||||||||||
2104 | - | |||||||||||||||||||||||||
2105 | /*! \internal | - | ||||||||||||||||||||||||
2106 | */ | - | ||||||||||||||||||||||||
2107 | void QTest::addColumnInternal(int id, const char *name) | - | ||||||||||||||||||||||||
2108 | { | - | ||||||||||||||||||||||||
2109 | QTestTable *tbl = QTestTable::currentTestTable(); | - | ||||||||||||||||||||||||
2110 | QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot."); | - | ||||||||||||||||||||||||
2111 | - | |||||||||||||||||||||||||
2112 | tbl->addColumn(id, name); | - | ||||||||||||||||||||||||
2113 | } | - | ||||||||||||||||||||||||
2114 | - | |||||||||||||||||||||||||
2115 | /*! | - | ||||||||||||||||||||||||
2116 | Appends a new row to the current test data. \a dataTag is the name of | - | ||||||||||||||||||||||||
2117 | the testdata that will appear in the test output. Returns a QTestData reference | - | ||||||||||||||||||||||||
2118 | that can be used to stream in data. | - | ||||||||||||||||||||||||
2119 | - | |||||||||||||||||||||||||
2120 | Example: | - | ||||||||||||||||||||||||
2121 | \snippet code/src_qtestlib_qtestcase.cpp 20 | - | ||||||||||||||||||||||||
2122 | - | |||||||||||||||||||||||||
2123 | \b {Note:} This macro can only be used in a test's data function | - | ||||||||||||||||||||||||
2124 | that is invoked by the test framework. | - | ||||||||||||||||||||||||
2125 | - | |||||||||||||||||||||||||
2126 | See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for | - | ||||||||||||||||||||||||
2127 | a more extensive example. | - | ||||||||||||||||||||||||
2128 | - | |||||||||||||||||||||||||
2129 | \sa addColumn(), QFETCH() | - | ||||||||||||||||||||||||
2130 | */ | - | ||||||||||||||||||||||||
2131 | QTestData &QTest::newRow(const char *dataTag) | - | ||||||||||||||||||||||||
2132 | { | - | ||||||||||||||||||||||||
2133 | QTEST_ASSERT_X(dataTag, "QTest::newRow()", "Data tag can not be null"); | - | ||||||||||||||||||||||||
2134 | QTestTable *tbl = QTestTable::currentTestTable(); | - | ||||||||||||||||||||||||
2135 | QTEST_ASSERT_X(tbl, "QTest::newRow()", "Cannot add testdata outside of a _data slot."); | - | ||||||||||||||||||||||||
2136 | QTEST_ASSERT_X(tbl->elementCount(), "QTest::newRow()", "Must add columns before attempting to add rows."); | - | ||||||||||||||||||||||||
2137 | - | |||||||||||||||||||||||||
2138 | return *tbl->newData(dataTag); | - | ||||||||||||||||||||||||
2139 | } | - | ||||||||||||||||||||||||
2140 | - | |||||||||||||||||||||||||
2141 | /*! \fn void QTest::addColumn(const char *name, T *dummy = 0) | - | ||||||||||||||||||||||||
2142 | - | |||||||||||||||||||||||||
2143 | Adds a column with type \c{T} to the current test data. | - | ||||||||||||||||||||||||
2144 | \a name is the name of the column. \a dummy is a workaround | - | ||||||||||||||||||||||||
2145 | for buggy compilers and can be ignored. | - | ||||||||||||||||||||||||
2146 | - | |||||||||||||||||||||||||
2147 | To populate the column with values, newRow() can be used. Use | - | ||||||||||||||||||||||||
2148 | \l QFETCH() to fetch the data in the actual test. | - | ||||||||||||||||||||||||
2149 | - | |||||||||||||||||||||||||
2150 | Example: | - | ||||||||||||||||||||||||
2151 | \snippet code/src_qtestlib_qtestcase.cpp 21 | - | ||||||||||||||||||||||||
2152 | - | |||||||||||||||||||||||||
2153 | To add custom types to the testdata, the type must be registered with | - | ||||||||||||||||||||||||
2154 | QMetaType via \l Q_DECLARE_METATYPE(). | - | ||||||||||||||||||||||||
2155 | - | |||||||||||||||||||||||||
2156 | \b {Note:} This macro can only be used in a test's data function | - | ||||||||||||||||||||||||
2157 | that is invoked by the test framework. | - | ||||||||||||||||||||||||
2158 | - | |||||||||||||||||||||||||
2159 | See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for | - | ||||||||||||||||||||||||
2160 | a more extensive example. | - | ||||||||||||||||||||||||
2161 | - | |||||||||||||||||||||||||
2162 | \sa QTest::newRow(), QFETCH(), QMetaType | - | ||||||||||||||||||||||||
2163 | */ | - | ||||||||||||||||||||||||
2164 | - | |||||||||||||||||||||||||
2165 | /*! | - | ||||||||||||||||||||||||
2166 | Returns the name of the binary that is currently executed. | - | ||||||||||||||||||||||||
2167 | */ | - | ||||||||||||||||||||||||
2168 | const char *QTest::currentAppName() | - | ||||||||||||||||||||||||
2169 | { | - | ||||||||||||||||||||||||
2170 | return QTestResult::currentAppName(); | - | ||||||||||||||||||||||||
2171 | } | - | ||||||||||||||||||||||||
2172 | - | |||||||||||||||||||||||||
2173 | /*! | - | ||||||||||||||||||||||||
2174 | Returns the name of the test function that is currently executed. | - | ||||||||||||||||||||||||
2175 | - | |||||||||||||||||||||||||
2176 | Example: | - | ||||||||||||||||||||||||
2177 | - | |||||||||||||||||||||||||
2178 | \snippet code/src_qtestlib_qtestcase.cpp 22 | - | ||||||||||||||||||||||||
2179 | */ | - | ||||||||||||||||||||||||
2180 | const char *QTest::currentTestFunction() | - | ||||||||||||||||||||||||
2181 | { | - | ||||||||||||||||||||||||
2182 | return QTestResult::currentTestFunction(); | - | ||||||||||||||||||||||||
2183 | } | - | ||||||||||||||||||||||||
2184 | - | |||||||||||||||||||||||||
2185 | /*! | - | ||||||||||||||||||||||||
2186 | Returns the name of the current test data. If the test doesn't | - | ||||||||||||||||||||||||
2187 | have any assigned testdata, the function returns 0. | - | ||||||||||||||||||||||||
2188 | */ | - | ||||||||||||||||||||||||
2189 | const char *QTest::currentDataTag() | - | ||||||||||||||||||||||||
2190 | { | - | ||||||||||||||||||||||||
2191 | return QTestResult::currentDataTag(); | - | ||||||||||||||||||||||||
2192 | } | - | ||||||||||||||||||||||||
2193 | - | |||||||||||||||||||||||||
2194 | /*! | - | ||||||||||||||||||||||||
2195 | Returns \c true if the current test function failed, otherwise false. | - | ||||||||||||||||||||||||
2196 | */ | - | ||||||||||||||||||||||||
2197 | bool QTest::currentTestFailed() | - | ||||||||||||||||||||||||
2198 | { | - | ||||||||||||||||||||||||
2199 | return QTestResult::currentTestFailed(); | - | ||||||||||||||||||||||||
2200 | } | - | ||||||||||||||||||||||||
2201 | - | |||||||||||||||||||||||||
2202 | /*! | - | ||||||||||||||||||||||||
2203 | Sleeps for \a ms milliseconds, blocking execution of the | - | ||||||||||||||||||||||||
2204 | test. qSleep() will not do any event processing and leave your test | - | ||||||||||||||||||||||||
2205 | unresponsive. Network communication might time out while | - | ||||||||||||||||||||||||
2206 | sleeping. Use \l qWait() to do non-blocking sleeping. | - | ||||||||||||||||||||||||
2207 | - | |||||||||||||||||||||||||
2208 | \a ms must be greater than 0. | - | ||||||||||||||||||||||||
2209 | - | |||||||||||||||||||||||||
2210 | \b {Note:} The qSleep() function calls either \c nanosleep() on | - | ||||||||||||||||||||||||
2211 | unix or \c Sleep() on windows, so the accuracy of time spent in | - | ||||||||||||||||||||||||
2212 | qSleep() depends on the operating system. | - | ||||||||||||||||||||||||
2213 | - | |||||||||||||||||||||||||
2214 | Example: | - | ||||||||||||||||||||||||
2215 | \snippet code/src_qtestlib_qtestcase.cpp 23 | - | ||||||||||||||||||||||||
2216 | - | |||||||||||||||||||||||||
2217 | \sa qWait() | - | ||||||||||||||||||||||||
2218 | */ | - | ||||||||||||||||||||||||
2219 | void QTest::qSleep(int ms) | - | ||||||||||||||||||||||||
2220 | { | - | ||||||||||||||||||||||||
2221 | QTEST_ASSERT(ms > 0); | - | ||||||||||||||||||||||||
2222 | - | |||||||||||||||||||||||||
2223 | #if defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
2224 | WaitForSingleObjectEx(GetCurrentThread(), ms, true); | - | ||||||||||||||||||||||||
2225 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
2226 | Sleep(uint(ms)); | - | ||||||||||||||||||||||||
2227 | #else | - | ||||||||||||||||||||||||
2228 | struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; | - | ||||||||||||||||||||||||
2229 | nanosleep(&ts, NULL); | - | ||||||||||||||||||||||||
2230 | #endif | - | ||||||||||||||||||||||||
2231 | } | - | ||||||||||||||||||||||||
2232 | - | |||||||||||||||||||||||||
2233 | /*! \internal | - | ||||||||||||||||||||||||
2234 | */ | - | ||||||||||||||||||||||||
2235 | QObject *QTest::testObject() | - | ||||||||||||||||||||||||
2236 | { | - | ||||||||||||||||||||||||
2237 | return currentTestObject; | - | ||||||||||||||||||||||||
2238 | } | - | ||||||||||||||||||||||||
2239 | - | |||||||||||||||||||||||||
2240 | /*! \internal | - | ||||||||||||||||||||||||
2241 | */ | - | ||||||||||||||||||||||||
2242 | void QTest::setMainSourcePath(const char *file, const char *builddir) | - | ||||||||||||||||||||||||
2243 | { | - | ||||||||||||||||||||||||
2244 | QString mainSourceFile = QFile::decodeName(file); | - | ||||||||||||||||||||||||
2245 | QFileInfo fi; | - | ||||||||||||||||||||||||
2246 | if (builddir) | - | ||||||||||||||||||||||||
2247 | fi.setFile(QDir(QFile::decodeName(builddir)), mainSourceFile); | - | ||||||||||||||||||||||||
2248 | else | - | ||||||||||||||||||||||||
2249 | fi.setFile(mainSourceFile); | - | ||||||||||||||||||||||||
2250 | QTest::mainSourcePath = fi.absolutePath(); | - | ||||||||||||||||||||||||
2251 | } | - | ||||||||||||||||||||||||
2252 | - | |||||||||||||||||||||||||
2253 | /*! \internal | - | ||||||||||||||||||||||||
2254 | This function is called by various specializations of QTest::qCompare | - | ||||||||||||||||||||||||
2255 | to decide whether to report a failure and to produce verbose test output. | - | ||||||||||||||||||||||||
2256 | - | |||||||||||||||||||||||||
2257 | The failureMsg parameter can be null, in which case a default message | - | ||||||||||||||||||||||||
2258 | will be output if the compare fails. If the compare succeeds, failureMsg | - | ||||||||||||||||||||||||
2259 | will not be output. | - | ||||||||||||||||||||||||
2260 | - | |||||||||||||||||||||||||
2261 | If the caller has already passed a failure message showing the compared | - | ||||||||||||||||||||||||
2262 | values, or if those values cannot be stringified, val1 and val2 can be null. | - | ||||||||||||||||||||||||
2263 | */ | - | ||||||||||||||||||||||||
2264 | bool QTest::compare_helper(bool success, const char *failureMsg, | - | ||||||||||||||||||||||||
2265 | char *val1, char *val2, | - | ||||||||||||||||||||||||
2266 | const char *actual, const char *expected, | - | ||||||||||||||||||||||||
2267 | const char *file, int line) | - | ||||||||||||||||||||||||
2268 | { | - | ||||||||||||||||||||||||
2269 | return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line); | - | ||||||||||||||||||||||||
2270 | } | - | ||||||||||||||||||||||||
2271 | - | |||||||||||||||||||||||||
2272 | /*! \fn bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2273 | \internal | - | ||||||||||||||||||||||||
2274 | */ | - | ||||||||||||||||||||||||
2275 | bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, | - | ||||||||||||||||||||||||
2276 | const char *file, int line) | - | ||||||||||||||||||||||||
2277 | { | - | ||||||||||||||||||||||||
2278 | return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", | - | ||||||||||||||||||||||||
2279 | toString(t1), toString(t2), actual, expected, file, line); | - | ||||||||||||||||||||||||
2280 | } | - | ||||||||||||||||||||||||
2281 | - | |||||||||||||||||||||||||
2282 | /*! \fn bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2283 | \internal | - | ||||||||||||||||||||||||
2284 | */ | - | ||||||||||||||||||||||||
2285 | bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, | - | ||||||||||||||||||||||||
2286 | const char *file, int line) | - | ||||||||||||||||||||||||
2287 | { | - | ||||||||||||||||||||||||
2288 | return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", | - | ||||||||||||||||||||||||
2289 | toString(t1), toString(t2), actual, expected, file, line); | - | ||||||||||||||||||||||||
2290 | } | - | ||||||||||||||||||||||||
2291 | - | |||||||||||||||||||||||||
2292 | /*! \fn bool QTest::qCompare(double const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2293 | \internal | - | ||||||||||||||||||||||||
2294 | */ | - | ||||||||||||||||||||||||
2295 | - | |||||||||||||||||||||||||
2296 | /*! \fn bool QTest::qCompare(float const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2297 | \internal | - | ||||||||||||||||||||||||
2298 | */ | - | ||||||||||||||||||||||||
2299 | - | |||||||||||||||||||||||||
2300 | #define TO_STRING_IMPL(TYPE, FORMAT) \ | - | ||||||||||||||||||||||||
2301 | template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ | - | ||||||||||||||||||||||||
2302 | { \ | - | ||||||||||||||||||||||||
2303 | char *msg = new char[128]; \ | - | ||||||||||||||||||||||||
2304 | qsnprintf(msg, 128, #FORMAT, t); \ | - | ||||||||||||||||||||||||
2305 | return msg; \ | - | ||||||||||||||||||||||||
2306 | } | - | ||||||||||||||||||||||||
2307 | - | |||||||||||||||||||||||||
2308 | TO_STRING_IMPL(short, %hd) | - | ||||||||||||||||||||||||
2309 | TO_STRING_IMPL(ushort, %hu) | - | ||||||||||||||||||||||||
2310 | TO_STRING_IMPL(int, %d) | - | ||||||||||||||||||||||||
2311 | TO_STRING_IMPL(uint, %u) | - | ||||||||||||||||||||||||
2312 | TO_STRING_IMPL(long, %ld) | - | ||||||||||||||||||||||||
2313 | TO_STRING_IMPL(ulong, %lu) | - | ||||||||||||||||||||||||
2314 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
2315 | TO_STRING_IMPL(qint64, %I64d) | - | ||||||||||||||||||||||||
2316 | TO_STRING_IMPL(quint64, %I64u) | - | ||||||||||||||||||||||||
2317 | #else | - | ||||||||||||||||||||||||
2318 | TO_STRING_IMPL(qint64, %lld) | - | ||||||||||||||||||||||||
2319 | TO_STRING_IMPL(quint64, %llu) | - | ||||||||||||||||||||||||
2320 | #endif | - | ||||||||||||||||||||||||
2321 | TO_STRING_IMPL(bool, %d) | - | ||||||||||||||||||||||||
TO_STRING_IMPL(char, %c) | ||||||||||||||||||||||||||
2322 | TO_STRING_IMPL(signed char, %hhd) | - | ||||||||||||||||||||||||
2323 | TO_STRING_IMPL(unsigned char, %hhu) | - | ||||||||||||||||||||||||
2324 | TO_STRING_IMPL(float, %g) | - | ||||||||||||||||||||||||
2325 | TO_STRING_IMPL(double, %lg) | - | ||||||||||||||||||||||||
2326 | - | |||||||||||||||||||||||||
2327 | template <> Q_TESTLIB_EXPORT char *QTest::toString<char>(const char &t) | - | ||||||||||||||||||||||||
2328 | { | - | ||||||||||||||||||||||||
2329 | unsigned char c = static_cast<unsigned char>(t); | - | ||||||||||||||||||||||||
2330 | char *msg = new char[16]; | - | ||||||||||||||||||||||||
2331 | switch (c) { | - | ||||||||||||||||||||||||
2332 | case 0x00: executed 2582 times by 14 tests: case 0x00: Executed by:
| 2582 | ||||||||||||||||||||||||
2333 | qstrcpy(msg, "'\\0'"); | - | ||||||||||||||||||||||||
2334 | break; executed 2582 times by 14 tests: break; Executed by:
| 2582 | ||||||||||||||||||||||||
2335 | case 0x07: executed 2 times by 1 test: case 0x07: Executed by:
| 2 | ||||||||||||||||||||||||
2336 | qstrcpy(msg, "'\\a'"); | - | ||||||||||||||||||||||||
2337 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2338 | case 0x08: executed 2 times by 1 test: case 0x08: Executed by:
| 2 | ||||||||||||||||||||||||
2339 | qstrcpy(msg, "'\\b'"); | - | ||||||||||||||||||||||||
2340 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2341 | case 0x09: executed 2 times by 1 test: case 0x09: Executed by:
| 2 | ||||||||||||||||||||||||
2342 | qstrcpy(msg, "'\\t'"); | - | ||||||||||||||||||||||||
2343 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2344 | case 0x0a: executed 4418 times by 8 tests: case 0x0a: Executed by:
| 4418 | ||||||||||||||||||||||||
2345 | qstrcpy(msg, "'\\n'"); | - | ||||||||||||||||||||||||
2346 | break; executed 4418 times by 8 tests: break; Executed by:
| 4418 | ||||||||||||||||||||||||
2347 | case 0x0b: executed 2 times by 1 test: case 0x0b: Executed by:
| 2 | ||||||||||||||||||||||||
2348 | qstrcpy(msg, "'\\v'"); | - | ||||||||||||||||||||||||
2349 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2350 | case 0x0c: executed 2 times by 1 test: case 0x0c: Executed by:
| 2 | ||||||||||||||||||||||||
2351 | qstrcpy(msg, "'\\f'"); | - | ||||||||||||||||||||||||
2352 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2353 | case 0x0d: executed 16 times by 3 tests: case 0x0d: Executed by:
| 16 | ||||||||||||||||||||||||
2354 | qstrcpy(msg, "'\\r'"); | - | ||||||||||||||||||||||||
2355 | break; executed 16 times by 3 tests: break; Executed by:
| 16 | ||||||||||||||||||||||||
2356 | case 0x22: executed 4 times by 2 tests: case 0x22: Executed by:
| 4 | ||||||||||||||||||||||||
2357 | qstrcpy(msg, "'\\\"'"); | - | ||||||||||||||||||||||||
2358 | break; executed 4 times by 2 tests: break; Executed by:
| 4 | ||||||||||||||||||||||||
2359 | case 0x27: executed 2 times by 1 test: case 0x27: Executed by:
| 2 | ||||||||||||||||||||||||
2360 | qstrcpy(msg, "'\\\''"); | - | ||||||||||||||||||||||||
2361 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2362 | case 0x5c: executed 2 times by 1 test: case 0x5c: Executed by:
| 2 | ||||||||||||||||||||||||
2363 | qstrcpy(msg, "'\\\\'"); | - | ||||||||||||||||||||||||
2364 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||||||||
2365 | default: executed 3514306 times by 24 tests: default: Executed by:
| 3514306 | ||||||||||||||||||||||||
2366 | if (c < 0x20 || c >= 0x7F
| 434-3513872 | ||||||||||||||||||||||||
2367 | qsnprintf(msg, 16, "'\\x%02x'", c); executed 9090 times by 5 tests: qsnprintf(msg, 16, "'\\x%02x'", c); Executed by:
| 9090 | ||||||||||||||||||||||||
2368 | else | - | ||||||||||||||||||||||||
2369 | qsnprintf(msg, 16, "'%c'" , c); executed 3505216 times by 23 tests: qsnprintf(msg, 16, "'%c'" , c); Executed by:
| 3505216 | ||||||||||||||||||||||||
2370 | } | - | ||||||||||||||||||||||||
2371 | return msg; executed 3521340 times by 26 tests: return msg; Executed by:
| 3521340 | ||||||||||||||||||||||||
2372 | } | - | ||||||||||||||||||||||||
2373 | - | |||||||||||||||||||||||||
2374 | /*! \internal | - | ||||||||||||||||||||||||
2375 | */ | - | ||||||||||||||||||||||||
2376 | char *QTest::toString(const char *str) | - | ||||||||||||||||||||||||
2377 | { | - | ||||||||||||||||||||||||
2378 | if (!str) | - | ||||||||||||||||||||||||
2379 | return 0; | - | ||||||||||||||||||||||||
2380 | char *msg = new char[strlen(str) + 1]; | - | ||||||||||||||||||||||||
2381 | return qstrcpy(msg, str); | - | ||||||||||||||||||||||||
2382 | } | - | ||||||||||||||||||||||||
2383 | - | |||||||||||||||||||||||||
2384 | /*! \internal | - | ||||||||||||||||||||||||
2385 | */ | - | ||||||||||||||||||||||||
2386 | char *QTest::toString(const void *p) | - | ||||||||||||||||||||||||
2387 | { | - | ||||||||||||||||||||||||
2388 | char *msg = new char[128]; | - | ||||||||||||||||||||||||
2389 | qsnprintf(msg, 128, "%p", p); | - | ||||||||||||||||||||||||
2390 | return msg; | - | ||||||||||||||||||||||||
2391 | } | - | ||||||||||||||||||||||||
2392 | - | |||||||||||||||||||||||||
2393 | /*! \internal | - | ||||||||||||||||||||||||
2394 | */ | - | ||||||||||||||||||||||||
2395 | bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual, | - | ||||||||||||||||||||||||
2396 | const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2397 | { | - | ||||||||||||||||||||||||
2398 | return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", | - | ||||||||||||||||||||||||
2399 | toString(t1), toString(t2), actual, expected, file, line); | - | ||||||||||||||||||||||||
2400 | } | - | ||||||||||||||||||||||||
2401 | - | |||||||||||||||||||||||||
2402 | /*! | - | ||||||||||||||||||||||||
2403 | \namespace QTest::Internal | - | ||||||||||||||||||||||||
2404 | \internal | - | ||||||||||||||||||||||||
2405 | */ | - | ||||||||||||||||||||||||
2406 | - | |||||||||||||||||||||||||
2407 | /*! \fn bool QTest::compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line); | - | ||||||||||||||||||||||||
2408 | \internal | - | ||||||||||||||||||||||||
2409 | */ | - | ||||||||||||||||||||||||
2410 | - | |||||||||||||||||||||||||
2411 | /*! \fn bool QTest::qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int); | - | ||||||||||||||||||||||||
2412 | \internal | - | ||||||||||||||||||||||||
2413 | */ | - | ||||||||||||||||||||||||
2414 | - | |||||||||||||||||||||||||
2415 | /*! \fn bool QTest::qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2416 | \internal | - | ||||||||||||||||||||||||
2417 | */ | - | ||||||||||||||||||||||||
2418 | - | |||||||||||||||||||||||||
2419 | /*! \fn bool QTest::qCompare(QImage const &t1, QImage const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2420 | \internal | - | ||||||||||||||||||||||||
2421 | */ | - | ||||||||||||||||||||||||
2422 | - | |||||||||||||||||||||||||
2423 | /*! \fn bool QTest::qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2424 | \internal | - | ||||||||||||||||||||||||
2425 | */ | - | ||||||||||||||||||||||||
2426 | - | |||||||||||||||||||||||||
2427 | /*! \fn bool QTest::qCompare(T const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2428 | \internal | - | ||||||||||||||||||||||||
2429 | */ | - | ||||||||||||||||||||||||
2430 | - | |||||||||||||||||||||||||
2431 | /*! \fn bool QTest::qCompare(const T *t1, const T *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2432 | \internal | - | ||||||||||||||||||||||||
2433 | */ | - | ||||||||||||||||||||||||
2434 | - | |||||||||||||||||||||||||
2435 | /*! \fn bool QTest::qCompare(T *t1, T *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2436 | \internal | - | ||||||||||||||||||||||||
2437 | */ | - | ||||||||||||||||||||||||
2438 | - | |||||||||||||||||||||||||
2439 | /*! \fn bool QTest::qCompare(const T1 *t1, const T2 *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2440 | \internal | - | ||||||||||||||||||||||||
2441 | */ | - | ||||||||||||||||||||||||
2442 | - | |||||||||||||||||||||||||
2443 | /*! \fn bool QTest::qCompare(T1 *t1, T2 *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2444 | \internal | - | ||||||||||||||||||||||||
2445 | */ | - | ||||||||||||||||||||||||
2446 | - | |||||||||||||||||||||||||
2447 | /*! \fn bool QTest::qCompare(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2448 | \internal | - | ||||||||||||||||||||||||
2449 | */ | - | ||||||||||||||||||||||||
2450 | - | |||||||||||||||||||||||||
2451 | /*! \fn bool QTest::qCompare(char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2452 | \internal | - | ||||||||||||||||||||||||
2453 | */ | - | ||||||||||||||||||||||||
2454 | - | |||||||||||||||||||||||||
2455 | /*! \fn bool QTest::qCompare(char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2456 | \internal | - | ||||||||||||||||||||||||
2457 | */ | - | ||||||||||||||||||||||||
2458 | - | |||||||||||||||||||||||||
2459 | /*! \fn bool QTest::qCompare(const char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2460 | \internal | - | ||||||||||||||||||||||||
2461 | */ | - | ||||||||||||||||||||||||
2462 | - | |||||||||||||||||||||||||
2463 | /*! \fn bool QTest::qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2464 | \internal | - | ||||||||||||||||||||||||
2465 | */ | - | ||||||||||||||||||||||||
2466 | - | |||||||||||||||||||||||||
2467 | /*! \fn bool QTest::qCompare(QLatin1String const &t1, QString const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2468 | \internal | - | ||||||||||||||||||||||||
2469 | */ | - | ||||||||||||||||||||||||
2470 | - | |||||||||||||||||||||||||
2471 | /*! \fn bool QTest::qCompare(QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2472 | \internal | - | ||||||||||||||||||||||||
2473 | */ | - | ||||||||||||||||||||||||
2474 | - | |||||||||||||||||||||||||
2475 | /*! \fn bool QTest::qCompare(QList<T> const &t1, QList<T> const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2476 | \internal | - | ||||||||||||||||||||||||
2477 | */ | - | ||||||||||||||||||||||||
2478 | - | |||||||||||||||||||||||||
2479 | /*! \fn bool QTest::qCompare(QFlags<T> const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2480 | \internal | - | ||||||||||||||||||||||||
2481 | */ | - | ||||||||||||||||||||||||
2482 | - | |||||||||||||||||||||||||
2483 | /*! \fn bool QTest::qCompare(QFlags<T> const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2484 | \internal | - | ||||||||||||||||||||||||
2485 | */ | - | ||||||||||||||||||||||||
2486 | - | |||||||||||||||||||||||||
2487 | /*! \fn bool QTest::qCompare(qint64 const &t1, qint32 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2488 | \internal | - | ||||||||||||||||||||||||
2489 | */ | - | ||||||||||||||||||||||||
2490 | - | |||||||||||||||||||||||||
2491 | /*! \fn bool QTest::qCompare(qint64 const &t1, quint32 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2492 | \internal | - | ||||||||||||||||||||||||
2493 | */ | - | ||||||||||||||||||||||||
2494 | - | |||||||||||||||||||||||||
2495 | /*! \fn bool QTest::qCompare(quint64 const &t1, quint32 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2496 | \internal | - | ||||||||||||||||||||||||
2497 | */ | - | ||||||||||||||||||||||||
2498 | - | |||||||||||||||||||||||||
2499 | /*! \fn bool QTest::qCompare(qint32 const &t1, qint64 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2500 | \internal | - | ||||||||||||||||||||||||
2501 | */ | - | ||||||||||||||||||||||||
2502 | - | |||||||||||||||||||||||||
2503 | /*! \fn bool QTest::qCompare(quint32 const &t1, qint64 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2504 | \internal | - | ||||||||||||||||||||||||
2505 | */ | - | ||||||||||||||||||||||||
2506 | - | |||||||||||||||||||||||||
2507 | /*! \fn bool QTest::qCompare(quint32 const &t1, quint64 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2508 | \internal | - | ||||||||||||||||||||||||
2509 | */ | - | ||||||||||||||||||||||||
2510 | - | |||||||||||||||||||||||||
2511 | /*! \fn bool QTest::qTest(const T& actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
2512 | \internal | - | ||||||||||||||||||||||||
2513 | */ | - | ||||||||||||||||||||||||
2514 | - | |||||||||||||||||||||||||
2515 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
2516 | \internal | - | ||||||||||||||||||||||||
2517 | */ | - | ||||||||||||||||||||||||
2518 | - | |||||||||||||||||||||||||
2519 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
2520 | \internal | - | ||||||||||||||||||||||||
2521 | */ | - | ||||||||||||||||||||||||
2522 | - | |||||||||||||||||||||||||
2523 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
2524 | \internal | - | ||||||||||||||||||||||||
2525 | */ | - | ||||||||||||||||||||||||
2526 | - | |||||||||||||||||||||||||
2527 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
2528 | \internal | - | ||||||||||||||||||||||||
2529 | */ | - | ||||||||||||||||||||||||
2530 | - | |||||||||||||||||||||||||
2531 | /*! \fn void QTest::simulateEvent(QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) | - | ||||||||||||||||||||||||
2532 | \internal | - | ||||||||||||||||||||||||
2533 | */ | - | ||||||||||||||||||||||||
2534 | - | |||||||||||||||||||||||||
2535 | /*! \fn void QTest::simulateEvent(QWindow *window, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) | - | ||||||||||||||||||||||||
2536 | \internal | - | ||||||||||||||||||||||||
2537 | */ | - | ||||||||||||||||||||||||
2538 | - | |||||||||||||||||||||||||
2539 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
Source code | Switch to Preprocessed file |