| 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) 2015 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtTest module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | #include <QtTest/qtestcase.h> | - | ||||||||||||||||||||||||
| 35 | #include <QtTest/qtestassert.h> | - | ||||||||||||||||||||||||
| 36 | - | |||||||||||||||||||||||||
| 37 | #include <QtCore/qbytearray.h> | - | ||||||||||||||||||||||||
| 38 | #include <QtCore/qmetaobject.h> | - | ||||||||||||||||||||||||
| 39 | #include <QtCore/qobject.h> | - | ||||||||||||||||||||||||
| 40 | #include <QtCore/qstringlist.h> | - | ||||||||||||||||||||||||
| 41 | #include <QtCore/qvector.h> | - | ||||||||||||||||||||||||
| 42 | #include <QtCore/qvarlengtharray.h> | - | ||||||||||||||||||||||||
| 43 | #include <QtCore/qcoreapplication.h> | - | ||||||||||||||||||||||||
| 44 | #include <QtCore/qfile.h> | - | ||||||||||||||||||||||||
| 45 | #include <QtCore/qfileinfo.h> | - | ||||||||||||||||||||||||
| 46 | #include <QtCore/qdir.h> | - | ||||||||||||||||||||||||
| 47 | #include <QtCore/qprocess.h> | - | ||||||||||||||||||||||||
| 48 | #include <QtCore/qdebug.h> | - | ||||||||||||||||||||||||
| 49 | #include <QtCore/qlibraryinfo.h> | - | ||||||||||||||||||||||||
| 50 | #include <QtCore/private/qtools_p.h> | - | ||||||||||||||||||||||||
| 51 | #include <QtCore/qdiriterator.h> | - | ||||||||||||||||||||||||
| 52 | #include <QtCore/qtemporarydir.h> | - | ||||||||||||||||||||||||
| 53 | #include <QtCore/qthread.h> | - | ||||||||||||||||||||||||
| 54 | #include <QtCore/qwaitcondition.h> | - | ||||||||||||||||||||||||
| 55 | #include <QtCore/qmutex.h> | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | #include <QtTest/private/qtestlog_p.h> | - | ||||||||||||||||||||||||
| 58 | #include <QtTest/private/qtesttable_p.h> | - | ||||||||||||||||||||||||
| 59 | #include <QtTest/qtestdata.h> | - | ||||||||||||||||||||||||
| 60 | #include <QtTest/private/qtestresult_p.h> | - | ||||||||||||||||||||||||
| 61 | #include <QtTest/private/qsignaldumper_p.h> | - | ||||||||||||||||||||||||
| 62 | #include <QtTest/private/qbenchmark_p.h> | - | ||||||||||||||||||||||||
| 63 | #include <QtTest/private/cycle_p.h> | - | ||||||||||||||||||||||||
| 64 | #include <QtTest/private/qtestblacklist_p.h> | - | ||||||||||||||||||||||||
| 65 | #if defined(HAVE_XCTEST) | - | ||||||||||||||||||||||||
| 66 | #include <QtTest/private/qxctestlogger_p.h> | - | ||||||||||||||||||||||||
| 67 | #endif | - | ||||||||||||||||||||||||
| 68 | #if defined Q_OS_MACOS | - | ||||||||||||||||||||||||
| 69 | #include <QtTest/private/qtestutil_macos_p.h> | - | ||||||||||||||||||||||||
| 70 | #endif | - | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | #include <numeric> | - | ||||||||||||||||||||||||
| 73 | #include <algorithm> | - | ||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | #include <stdarg.h> | - | ||||||||||||||||||||||||
| 76 | #include <stdio.h> | - | ||||||||||||||||||||||||
| 77 | #include <stdlib.h> | - | ||||||||||||||||||||||||
| 78 | - | |||||||||||||||||||||||||
| 79 | #if defined(Q_OS_LINUX) | - | ||||||||||||||||||||||||
| 80 | #include <sys/types.h> | - | ||||||||||||||||||||||||
| 81 | #include <unistd.h> | - | ||||||||||||||||||||||||
| 82 | #include <fcntl.h> | - | ||||||||||||||||||||||||
| 83 | #endif | - | ||||||||||||||||||||||||
| 84 | - | |||||||||||||||||||||||||
| 85 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 86 | #ifndef Q_OS_WINCE | - | ||||||||||||||||||||||||
| 87 | # if !defined(Q_CC_MINGW) || (defined(Q_CC_MINGW) && defined(__MINGW64_VERSION_MAJOR)) | - | ||||||||||||||||||||||||
| 88 | # include <crtdbg.h> | - | ||||||||||||||||||||||||
| 89 | # endif | - | ||||||||||||||||||||||||
| 90 | #endif | - | ||||||||||||||||||||||||
| 91 | #include <windows.h> // for Sleep | - | ||||||||||||||||||||||||
| 92 | #endif | - | ||||||||||||||||||||||||
| 93 | #ifdef Q_OS_UNIX | - | ||||||||||||||||||||||||
| 94 | #include <errno.h> | - | ||||||||||||||||||||||||
| 95 | #include <signal.h> | - | ||||||||||||||||||||||||
| 96 | #include <time.h> | - | ||||||||||||||||||||||||
| 97 | #include <sys/resource.h> | - | ||||||||||||||||||||||||
| 98 | #endif | - | ||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
| 101 | #include <IOKit/pwr_mgt/IOPMLib.h> | - | ||||||||||||||||||||||||
| 102 | #endif | - | ||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||
| 104 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | using QtMiscUtils::toHexUpper; | - | ||||||||||||||||||||||||
| 107 | using QtMiscUtils::fromHex; | - | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | static void disableCoreDump() | - | ||||||||||||||||||||||||
| 110 | { | - | ||||||||||||||||||||||||
| 111 | bool ok = false; | - | ||||||||||||||||||||||||
| 112 | const int disableCoreDump = qEnvironmentVariableIntValue("QTEST_DISABLE_CORE_DUMP", &ok); | - | ||||||||||||||||||||||||
| 113 | if (ok && disableCoreDump == 1) {
| 0-680 | ||||||||||||||||||||||||
| 114 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 115 | struct rlimit limit; | - | ||||||||||||||||||||||||
| 116 | limit.rlim_cur = 0; | - | ||||||||||||||||||||||||
| 117 | limit.rlim_max = 0; | - | ||||||||||||||||||||||||
| 118 | if (setrlimit(RLIMIT_CORE, &limit) != 0)
| 0-69 | ||||||||||||||||||||||||
| 119 | qWarning("Failed to disable core dumps: %d", errno); never executed: QMessageLogger(__FILE__, 119, __PRETTY_FUNCTION__).warning("Failed to disable core dumps: %d", (*__errno_location ())); | 0 | ||||||||||||||||||||||||
| 120 | #endif | - | ||||||||||||||||||||||||
| 121 | } executed 69 times by 1 test: end of blockExecuted by:
| 69 | ||||||||||||||||||||||||
| 122 | } executed 749 times by 3 tests: end of blockExecuted by:
| 749 | ||||||||||||||||||||||||
| 123 | Q_CONSTRUCTOR_FUNCTION(disableCoreDump); executed 749 times by 3 tests: end of blockExecuted by:
| 749 | ||||||||||||||||||||||||
| 124 | - | |||||||||||||||||||||||||
| 125 | static void stackTrace() | - | ||||||||||||||||||||||||
| 126 | { | - | ||||||||||||||||||||||||
| 127 | bool ok = false; | - | ||||||||||||||||||||||||
| 128 | const int disableStackDump = qEnvironmentVariableIntValue("QTEST_DISABLE_STACK_DUMP", &ok); | - | ||||||||||||||||||||||||
| 129 | if (ok && disableStackDump == 1)
| 0 | ||||||||||||||||||||||||
| 130 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 131 | #ifdef Q_OS_LINUX | - | ||||||||||||||||||||||||
| 132 | fprintf(stderr, "\n========= Received signal, dumping stack ==============\n"); | - | ||||||||||||||||||||||||
| 133 | char cmd[512]; | - | ||||||||||||||||||||||||
| 134 | qsnprintf(cmd, 512, "gdb --pid %d 2>/dev/null <<EOF\n" | - | ||||||||||||||||||||||||
| 135 | "set prompt\n" | - | ||||||||||||||||||||||||
| 136 | "set height 0\n" | - | ||||||||||||||||||||||||
| 137 | "thread apply all where full\n" | - | ||||||||||||||||||||||||
| 138 | "detach\n" | - | ||||||||||||||||||||||||
| 139 | "quit\n" | - | ||||||||||||||||||||||||
| 140 | "EOF\n", | - | ||||||||||||||||||||||||
| 141 | (int)getpid()); | - | ||||||||||||||||||||||||
| 142 | if (system(cmd) == -1)
| 0 | ||||||||||||||||||||||||
| 143 | fprintf(stderr, "calling gdb failed\n"); never executed: fprintf(stderr, "calling gdb failed\n"); | 0 | ||||||||||||||||||||||||
| 144 | fprintf(stderr, "========= End of stack trace ==============\n"); | - | ||||||||||||||||||||||||
| 145 | #elif defined(Q_OS_OSX) | - | ||||||||||||||||||||||||
| 146 | fprintf(stderr, "\n========= Received signal, dumping stack ==============\n"); | - | ||||||||||||||||||||||||
| 147 | char cmd[512]; | - | ||||||||||||||||||||||||
| 148 | qsnprintf(cmd, 512, "lldb -p %d 2>/dev/null <<EOF\n" | - | ||||||||||||||||||||||||
| 149 | "bt all\n" | - | ||||||||||||||||||||||||
| 150 | "quit\n" | - | ||||||||||||||||||||||||
| 151 | "EOF\n", | - | ||||||||||||||||||||||||
| 152 | (int)getpid()); | - | ||||||||||||||||||||||||
| 153 | if (system(cmd) == -1) | - | ||||||||||||||||||||||||
| 154 | fprintf(stderr, "calling lldb failed\n"); | - | ||||||||||||||||||||||||
| 155 | fprintf(stderr, "========= End of stack trace ==============\n"); | - | ||||||||||||||||||||||||
| 156 | #endif | - | ||||||||||||||||||||||||
| 157 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||
| 159 | /*! | - | ||||||||||||||||||||||||
| 160 | \namespace QTest | - | ||||||||||||||||||||||||
| 161 | \inmodule QtTest | - | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | \brief The QTest namespace contains all the functions and | - | ||||||||||||||||||||||||
| 164 | declarations that are related to Qt Test. | - | ||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | See the \l{Qt Test Overview} for information about how to write unit tests. | - | ||||||||||||||||||||||||
| 167 | */ | - | ||||||||||||||||||||||||
| 168 | - | |||||||||||||||||||||||||
| 169 | /*! | - | ||||||||||||||||||||||||
| 170 | \namespace QTest::Internal | - | ||||||||||||||||||||||||
| 171 | \internal | - | ||||||||||||||||||||||||
| 172 | */ | - | ||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||
| 174 | /*! \macro QVERIFY(condition) | - | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | \relates QTest | - | ||||||||||||||||||||||||
| 177 | - | |||||||||||||||||||||||||
| 178 | The QVERIFY() macro checks whether the \a condition is true or not. If it is | - | ||||||||||||||||||||||||
| 179 | true, execution continues. If not, a failure is recorded in the test log | - | ||||||||||||||||||||||||
| 180 | and the test won't be executed further. | - | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | \b {Note:} This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 183 | by the test framework. | - | ||||||||||||||||||||||||
| 184 | - | |||||||||||||||||||||||||
| 185 | Example: | - | ||||||||||||||||||||||||
| 186 | \snippet code/src_qtestlib_qtestcase.cpp 0 | - | ||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||
| 188 | \sa QCOMPARE(), QTRY_VERIFY() | - | ||||||||||||||||||||||||
| 189 | */ | - | ||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||
| 191 | /*! \macro QVERIFY2(condition, message) | - | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | \relates QTest | - | ||||||||||||||||||||||||
| 194 | - | |||||||||||||||||||||||||
| 195 | The QVERIFY2() macro behaves exactly like QVERIFY(), except that it outputs | - | ||||||||||||||||||||||||
| 196 | a verbose \a message when \a condition is false. The \a message is a plain | - | ||||||||||||||||||||||||
| 197 | C string. | - | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | Example: | - | ||||||||||||||||||||||||
| 200 | \snippet code/src_qtestlib_qtestcase.cpp 1 | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | \sa QVERIFY(), QCOMPARE() | - | ||||||||||||||||||||||||
| 203 | */ | - | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | /*! \macro QCOMPARE(actual, expected) | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | \relates QTest | - | ||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||
| 209 | The QCOMPARE macro compares an \a actual value to an \a expected value using | - | ||||||||||||||||||||||||
| 210 | the equals operator. If \a actual and \a expected are identical, execution | - | ||||||||||||||||||||||||
| 211 | continues. If not, a failure is recorded in the test log and the test | - | ||||||||||||||||||||||||
| 212 | won't be executed further. | - | ||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||
| 214 | In the case of comparing floats and doubles, qFuzzyCompare() is used for | - | ||||||||||||||||||||||||
| 215 | comparing. This means that comparing to 0 will likely fail. One solution | - | ||||||||||||||||||||||||
| 216 | to this is to compare to 1, and add 1 to the produced output. | - | ||||||||||||||||||||||||
| 217 | - | |||||||||||||||||||||||||
| 218 | QCOMPARE tries to output the contents of the values if the comparison fails, | - | ||||||||||||||||||||||||
| 219 | so it is visible from the test log why the comparison failed. | - | ||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | QCOMPARE is very strict on the data types. Both \a actual and \a expected | - | ||||||||||||||||||||||||
| 222 | have to be of the same type, otherwise the test won't compile. This prohibits | - | ||||||||||||||||||||||||
| 223 | unspecified behavior from being introduced; that is behavior that usually | - | ||||||||||||||||||||||||
| 224 | occurs when the compiler implicitly casts the argument. | - | ||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | For your own classes, you can use \l QTest::toString() to format values for | - | ||||||||||||||||||||||||
| 227 | outputting into the test log. | - | ||||||||||||||||||||||||
| 228 | - | |||||||||||||||||||||||||
| 229 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 230 | by the test framework. | - | ||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||
| 232 | Example: | - | ||||||||||||||||||||||||
| 233 | \snippet code/src_qtestlib_qtestcase.cpp 2 | - | ||||||||||||||||||||||||
| 234 | - | |||||||||||||||||||||||||
| 235 | \sa QVERIFY(), QTRY_COMPARE(), QTest::toString() | - | ||||||||||||||||||||||||
| 236 | */ | - | ||||||||||||||||||||||||
| 237 | - | |||||||||||||||||||||||||
| 238 | /*! \macro QVERIFY_EXCEPTION_THROWN(expression, exceptiontype) | - | ||||||||||||||||||||||||
| 239 | \since 5.3 | - | ||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | \relates QTest | - | ||||||||||||||||||||||||
| 242 | - | |||||||||||||||||||||||||
| 243 | The QVERIFY_EXCEPTION_THROWN macro executes an \a expression and tries | - | ||||||||||||||||||||||||
| 244 | to catch an exception thrown from the \a expression. If the \a expression | - | ||||||||||||||||||||||||
| 245 | throws an exception and its type is the same as \a exceptiontype | - | ||||||||||||||||||||||||
| 246 | or \a exceptiontype is substitutable with the type of thrown exception | - | ||||||||||||||||||||||||
| 247 | (i.e. usually the type of thrown exception is publically derived | - | ||||||||||||||||||||||||
| 248 | from \a exceptiontype) then execution will be continued. If not-substitutable | - | ||||||||||||||||||||||||
| 249 | type of exception is thrown or the \a expression doesn't throw an exception | - | ||||||||||||||||||||||||
| 250 | at all, then a failure will be recorded in the test log and | - | ||||||||||||||||||||||||
| 251 | the test won't be executed further. | - | ||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||
| 253 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 254 | by the test framework. | - | ||||||||||||||||||||||||
| 255 | */ | - | ||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| 257 | /*! \macro QTRY_VERIFY_WITH_TIMEOUT(condition, timeout) | - | ||||||||||||||||||||||||
| 258 | \since 5.0 | - | ||||||||||||||||||||||||
| 259 | - | |||||||||||||||||||||||||
| 260 | \relates QTest | - | ||||||||||||||||||||||||
| 261 | - | |||||||||||||||||||||||||
| 262 | The QTRY_VERIFY_WITH_TIMEOUT() macro is similar to QVERIFY(), but checks the \a condition | - | ||||||||||||||||||||||||
| 263 | repeatedly, until either the condition becomes true or the \a timeout (in milliseconds) is | - | ||||||||||||||||||||||||
| 264 | reached. Between each evaluation, events will be processed. If the timeout | - | ||||||||||||||||||||||||
| 265 | is reached, a failure is recorded in the test log and the test won't be | - | ||||||||||||||||||||||||
| 266 | executed further. | - | ||||||||||||||||||||||||
| 267 | - | |||||||||||||||||||||||||
| 268 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 269 | by the test framework. | - | ||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||
| 271 | \sa QTRY_VERIFY(), QTRY_VERIFY2_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() | - | ||||||||||||||||||||||||
| 272 | */ | - | ||||||||||||||||||||||||
| 273 | - | |||||||||||||||||||||||||
| 274 | - | |||||||||||||||||||||||||
| 275 | /*! \macro QTRY_VERIFY(condition) | - | ||||||||||||||||||||||||
| 276 | \since 5.0 | - | ||||||||||||||||||||||||
| 277 | - | |||||||||||||||||||||||||
| 278 | \relates QTest | - | ||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||
| 280 | Checks the \a condition by invoking QTRY_VERIFY_WITH_TIMEOUT() with a timeout of five seconds. | - | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 283 | by the test framework. | - | ||||||||||||||||||||||||
| 284 | - | |||||||||||||||||||||||||
| 285 | \sa QTRY_VERIFY_WITH_TIMEOUT(), QTRY_VERIFY2(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() | - | ||||||||||||||||||||||||
| 286 | */ | - | ||||||||||||||||||||||||
| 287 | - | |||||||||||||||||||||||||
| 288 | /*! \macro QTRY_VERIFY2_WITH_TIMEOUT(condition, message, timeout) | - | ||||||||||||||||||||||||
| 289 | \since 5.6 | - | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | \relates QTest | - | ||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | The QTRY_VERIFY2_WITH_TIMEOUT macro is similar to QTRY_VERIFY_WITH_TIMEOUT() | - | ||||||||||||||||||||||||
| 294 | except that it outputs a verbose \a message when \a condition is still false | - | ||||||||||||||||||||||||
| 295 | after the specified \a timeout (in milliseconds). The \a message is a plain C string. | - | ||||||||||||||||||||||||
| 296 | - | |||||||||||||||||||||||||
| 297 | Example: | - | ||||||||||||||||||||||||
| 298 | \code | - | ||||||||||||||||||||||||
| 299 | QTRY_VERIFY2_WITH_TIMEOUT(list.size() > 2, QByteArray::number(list.size()).constData(), 10000); | - | ||||||||||||||||||||||||
| 300 | \endcode | - | ||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||
| 302 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 303 | by the test framework. | - | ||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||
| 305 | \sa QTRY_VERIFY(), QTRY_VERIFY_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() | - | ||||||||||||||||||||||||
| 306 | */ | - | ||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||
| 308 | /*! \macro QTRY_VERIFY2(condition, message) | - | ||||||||||||||||||||||||
| 309 | \since 5.6 | - | ||||||||||||||||||||||||
| 310 | - | |||||||||||||||||||||||||
| 311 | \relates QTest | - | ||||||||||||||||||||||||
| 312 | - | |||||||||||||||||||||||||
| 313 | Checks the \a condition by invoking QTRY_VERIFY2_WITH_TIMEOUT() with a timeout | - | ||||||||||||||||||||||||
| 314 | of five seconds. If \a condition is then still false, \a message is output. | - | ||||||||||||||||||||||||
| 315 | The \a message is a plain C string. | - | ||||||||||||||||||||||||
| 316 | - | |||||||||||||||||||||||||
| 317 | Example: | - | ||||||||||||||||||||||||
| 318 | \code | - | ||||||||||||||||||||||||
| 319 | QTRY_VERIFY2_WITH_TIMEOUT(list.size() > 2, QByteArray::number(list.size()).constData()); | - | ||||||||||||||||||||||||
| 320 | \endcode | - | ||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 323 | by the test framework. | - | ||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | \sa QTRY_VERIFY2_WITH_TIMEOUT(), QTRY_VERIFY2(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() | - | ||||||||||||||||||||||||
| 326 | */ | - | ||||||||||||||||||||||||
| 327 | - | |||||||||||||||||||||||||
| 328 | /*! \macro QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout) | - | ||||||||||||||||||||||||
| 329 | \since 5.0 | - | ||||||||||||||||||||||||
| 330 | - | |||||||||||||||||||||||||
| 331 | \relates QTest | - | ||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | The QTRY_COMPARE_WITH_TIMEOUT() macro is similar to QCOMPARE(), but performs the comparison | - | ||||||||||||||||||||||||
| 334 | of the \a actual and \a expected values repeatedly, until either the two values | - | ||||||||||||||||||||||||
| 335 | are equal or the \a timeout (in milliseconds) is reached. Between each comparison, events | - | ||||||||||||||||||||||||
| 336 | will be processed. If the timeout is reached, a failure is recorded in the | - | ||||||||||||||||||||||||
| 337 | test log and the test won't be executed further. | - | ||||||||||||||||||||||||
| 338 | - | |||||||||||||||||||||||||
| 339 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 340 | by the test framework. | - | ||||||||||||||||||||||||
| 341 | - | |||||||||||||||||||||||||
| 342 | \sa QTRY_COMPARE(), QCOMPARE(), QVERIFY(), QTRY_VERIFY() | - | ||||||||||||||||||||||||
| 343 | */ | - | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | /*! \macro QTRY_COMPARE(actual, expected) | - | ||||||||||||||||||||||||
| 346 | \since 5.0 | - | ||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | \relates QTest | - | ||||||||||||||||||||||||
| 349 | - | |||||||||||||||||||||||||
| 350 | Performs a comparison of the \a actual and \a expected values by | - | ||||||||||||||||||||||||
| 351 | invoking QTRY_COMPARE_WITH_TIMEOUT() with a timeout of five seconds. | - | ||||||||||||||||||||||||
| 352 | - | |||||||||||||||||||||||||
| 353 | \note This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 354 | by the test framework. | - | ||||||||||||||||||||||||
| 355 | - | |||||||||||||||||||||||||
| 356 | \sa QTRY_COMPARE_WITH_TIMEOUT(), QCOMPARE(), QVERIFY(), QTRY_VERIFY() | - | ||||||||||||||||||||||||
| 357 | */ | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | /*! \macro QFETCH(type, name) | - | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | \relates QTest | - | ||||||||||||||||||||||||
| 362 | - | |||||||||||||||||||||||||
| 363 | The fetch macro creates a local variable named \a name with the type \a type | - | ||||||||||||||||||||||||
| 364 | on the stack. \a name has to match the element name from the test's data. | - | ||||||||||||||||||||||||
| 365 | If no such element exists, the test will assert. | - | ||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||
| 367 | Assuming a test has the following data: | - | ||||||||||||||||||||||||
| 368 | - | |||||||||||||||||||||||||
| 369 | \snippet code/src_qtestlib_qtestcase.cpp 3 | - | ||||||||||||||||||||||||
| 370 | - | |||||||||||||||||||||||||
| 371 | The test data has two elements, a QString called \c aString and an integer | - | ||||||||||||||||||||||||
| 372 | called \c expected. To fetch these values in the actual test: | - | ||||||||||||||||||||||||
| 373 | - | |||||||||||||||||||||||||
| 374 | \snippet code/src_qtestlib_qtestcase.cpp 4 | - | ||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||
| 376 | \c aString and \c expected are variables on the stack that are initialized with | - | ||||||||||||||||||||||||
| 377 | the current test data. | - | ||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||
| 379 | \b {Note:} This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 380 | by the test framework. The test function must have a _data function. | - | ||||||||||||||||||||||||
| 381 | */ | - | ||||||||||||||||||||||||
| 382 | - | |||||||||||||||||||||||||
| 383 | /*! \macro QWARN(message) | - | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | \relates QTest | - | ||||||||||||||||||||||||
| 386 | \threadsafe | - | ||||||||||||||||||||||||
| 387 | - | |||||||||||||||||||||||||
| 388 | Appends \a message as a warning to the test log. This macro can be used anywhere | - | ||||||||||||||||||||||||
| 389 | in your tests. | - | ||||||||||||||||||||||||
| 390 | */ | - | ||||||||||||||||||||||||
| 391 | - | |||||||||||||||||||||||||
| 392 | /*! \macro QFAIL(message) | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | \relates QTest | - | ||||||||||||||||||||||||
| 395 | - | |||||||||||||||||||||||||
| 396 | This macro can be used to force a test failure. The test stops | - | ||||||||||||||||||||||||
| 397 | executing and the failure \a message is appended to the test log. | - | ||||||||||||||||||||||||
| 398 | - | |||||||||||||||||||||||||
| 399 | \b {Note:} This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 400 | by the test framework. | - | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | Example: | - | ||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||
| 404 | \snippet code/src_qtestlib_qtestcase.cpp 5 | - | ||||||||||||||||||||||||
| 405 | */ | - | ||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | /*! \macro QTEST(actual, testElement) | - | ||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | \relates QTest | - | ||||||||||||||||||||||||
| 410 | - | |||||||||||||||||||||||||
| 411 | QTEST() is a convenience macro for \l QCOMPARE() that compares | - | ||||||||||||||||||||||||
| 412 | the value \a actual with the element \a testElement from the test's data. | - | ||||||||||||||||||||||||
| 413 | If there is no such element, the test asserts. | - | ||||||||||||||||||||||||
| 414 | - | |||||||||||||||||||||||||
| 415 | Apart from that, QTEST() behaves exactly as \l QCOMPARE(). | - | ||||||||||||||||||||||||
| 416 | - | |||||||||||||||||||||||||
| 417 | Instead of writing: | - | ||||||||||||||||||||||||
| 418 | - | |||||||||||||||||||||||||
| 419 | \snippet code/src_qtestlib_qtestcase.cpp 6 | - | ||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| 421 | you can write: | - | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | \snippet code/src_qtestlib_qtestcase.cpp 7 | - | ||||||||||||||||||||||||
| 424 | - | |||||||||||||||||||||||||
| 425 | \sa QCOMPARE() | - | ||||||||||||||||||||||||
| 426 | */ | - | ||||||||||||||||||||||||
| 427 | - | |||||||||||||||||||||||||
| 428 | /*! \macro QSKIP(description) | - | ||||||||||||||||||||||||
| 429 | - | |||||||||||||||||||||||||
| 430 | \relates QTest | - | ||||||||||||||||||||||||
| 431 | - | |||||||||||||||||||||||||
| 432 | If called from a test function, the QSKIP() macro stops execution of the test | - | ||||||||||||||||||||||||
| 433 | without adding a failure to the test log. You can use it to skip tests that | - | ||||||||||||||||||||||||
| 434 | wouldn't make sense in the current configuration. The text \a description is | - | ||||||||||||||||||||||||
| 435 | appended to the test log and should contain an explanation of why the test | - | ||||||||||||||||||||||||
| 436 | couldn't be executed. | - | ||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | If the test is data-driven, each call to QSKIP() will skip only the current | - | ||||||||||||||||||||||||
| 439 | row of test data, so an unconditional call to QSKIP will produce one skip | - | ||||||||||||||||||||||||
| 440 | message in the test log for each row of test data. | - | ||||||||||||||||||||||||
| 441 | - | |||||||||||||||||||||||||
| 442 | If called from a _data function, the QSKIP() macro will stop execution of | - | ||||||||||||||||||||||||
| 443 | the _data function and will prevent execution of the associated test | - | ||||||||||||||||||||||||
| 444 | function. | - | ||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||
| 446 | If called from initTestCase() or initTestCase_data(), the QSKIP() macro will | - | ||||||||||||||||||||||||
| 447 | skip all test and _data functions. | - | ||||||||||||||||||||||||
| 448 | - | |||||||||||||||||||||||||
| 449 | \b {Note:} This macro can only be used in a test function or _data | - | ||||||||||||||||||||||||
| 450 | function that is invoked by the test framework. | - | ||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||
| 452 | Example: | - | ||||||||||||||||||||||||
| 453 | \snippet code/src_qtestlib_qtestcase.cpp 8 | - | ||||||||||||||||||||||||
| 454 | */ | - | ||||||||||||||||||||||||
| 455 | - | |||||||||||||||||||||||||
| 456 | /*! \macro QEXPECT_FAIL(dataIndex, comment, mode) | - | ||||||||||||||||||||||||
| 457 | - | |||||||||||||||||||||||||
| 458 | \relates QTest | - | ||||||||||||||||||||||||
| 459 | - | |||||||||||||||||||||||||
| 460 | The QEXPECT_FAIL() macro marks the next \l QCOMPARE() or \l QVERIFY() as an | - | ||||||||||||||||||||||||
| 461 | expected failure. Instead of adding a failure to the test log, an expected | - | ||||||||||||||||||||||||
| 462 | failure will be reported. | - | ||||||||||||||||||||||||
| 463 | - | |||||||||||||||||||||||||
| 464 | If a \l QVERIFY() or \l QCOMPARE() is marked as an expected failure, | - | ||||||||||||||||||||||||
| 465 | but passes instead, an unexpected pass (XPASS) is written to the test log. | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | The parameter \a dataIndex describes for which entry in the test data the | - | ||||||||||||||||||||||||
| 468 | failure is expected. Pass an empty string (\c{""}) if the failure | - | ||||||||||||||||||||||||
| 469 | is expected for all entries or if no test data exists. | - | ||||||||||||||||||||||||
| 470 | - | |||||||||||||||||||||||||
| 471 | \a comment will be appended to the test log for the expected failure. | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | \a mode is a \l QTest::TestFailMode and sets whether the test should | - | ||||||||||||||||||||||||
| 474 | continue to execute or not. | - | ||||||||||||||||||||||||
| 475 | - | |||||||||||||||||||||||||
| 476 | \b {Note:} This macro can only be used in a test function that is invoked | - | ||||||||||||||||||||||||
| 477 | by the test framework. | - | ||||||||||||||||||||||||
| 478 | - | |||||||||||||||||||||||||
| 479 | Example 1: | - | ||||||||||||||||||||||||
| 480 | \snippet code/src_qtestlib_qtestcase.cpp 9 | - | ||||||||||||||||||||||||
| 481 | - | |||||||||||||||||||||||||
| 482 | In the example above, an expected fail will be written into the test output | - | ||||||||||||||||||||||||
| 483 | if the variable \c i is not 42. If the variable \c i is 42, an unexpected pass | - | ||||||||||||||||||||||||
| 484 | is written instead. The QEXPECT_FAIL() has no influence on the second QCOMPARE() | - | ||||||||||||||||||||||||
| 485 | statement in the example. | - | ||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | Example 2: | - | ||||||||||||||||||||||||
| 488 | \snippet code/src_qtestlib_qtestcase.cpp 10 | - | ||||||||||||||||||||||||
| 489 | - | |||||||||||||||||||||||||
| 490 | The above testfunction will not continue executing for the test data | - | ||||||||||||||||||||||||
| 491 | entry \c{data27}. | - | ||||||||||||||||||||||||
| 492 | - | |||||||||||||||||||||||||
| 493 | \sa QTest::TestFailMode, QVERIFY(), QCOMPARE() | - | ||||||||||||||||||||||||
| 494 | */ | - | ||||||||||||||||||||||||
| 495 | - | |||||||||||||||||||||||||
| 496 | /*! \macro QFINDTESTDATA(filename) | - | ||||||||||||||||||||||||
| 497 | \since 5.0 | - | ||||||||||||||||||||||||
| 498 | - | |||||||||||||||||||||||||
| 499 | \relates QTest | - | ||||||||||||||||||||||||
| 500 | - | |||||||||||||||||||||||||
| 501 | Returns a QString for the testdata file referred to by \a filename, or an | - | ||||||||||||||||||||||||
| 502 | empty QString if the testdata file could not be found. | - | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | This macro allows the test to load data from an external file without | - | ||||||||||||||||||||||||
| 505 | hardcoding an absolute filename into the test, or using relative paths | - | ||||||||||||||||||||||||
| 506 | which may be error prone. | - | ||||||||||||||||||||||||
| 507 | - | |||||||||||||||||||||||||
| 508 | The returned path will be the first path from the following list which | - | ||||||||||||||||||||||||
| 509 | resolves to an existing file or directory: | - | ||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | \list | - | ||||||||||||||||||||||||
| 512 | \li \a filename relative to QCoreApplication::applicationDirPath() | - | ||||||||||||||||||||||||
| 513 | (only if a QCoreApplication or QApplication object has been created). | - | ||||||||||||||||||||||||
| 514 | \li \a filename relative to the test's standard install directory | - | ||||||||||||||||||||||||
| 515 | (QLibraryInfo::TestsPath with the lowercased testcase name appended). | - | ||||||||||||||||||||||||
| 516 | \li \a filename relative to the directory containing the source file from which | - | ||||||||||||||||||||||||
| 517 | QFINDTESTDATA is invoked. | - | ||||||||||||||||||||||||
| 518 | \endlist | - | ||||||||||||||||||||||||
| 519 | - | |||||||||||||||||||||||||
| 520 | If the named file/directory does not exist at any of these locations, | - | ||||||||||||||||||||||||
| 521 | a warning is printed to the test log. | - | ||||||||||||||||||||||||
| 522 | - | |||||||||||||||||||||||||
| 523 | For example, in this code: | - | ||||||||||||||||||||||||
| 524 | \snippet code/src_qtestlib_qtestcase.cpp 26 | - | ||||||||||||||||||||||||
| 525 | - | |||||||||||||||||||||||||
| 526 | The testdata file will be resolved as the first existing file from: | - | ||||||||||||||||||||||||
| 527 | - | |||||||||||||||||||||||||
| 528 | \list | - | ||||||||||||||||||||||||
| 529 | \li \c{/home/user/build/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml} | - | ||||||||||||||||||||||||
| 530 | \li \c{/usr/local/Qt-5.0.0/tests/tst_myxmlparser/testxml/simple1.xml} | - | ||||||||||||||||||||||||
| 531 | \li \c{/home/user/sources/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml} | - | ||||||||||||||||||||||||
| 532 | \endlist | - | ||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||
| 534 | This allows the test to find its testdata regardless of whether the | - | ||||||||||||||||||||||||
| 535 | test has been installed, and regardless of whether the test's build tree | - | ||||||||||||||||||||||||
| 536 | is equal to the test's source tree. | - | ||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||
| 538 | \b {Note:} reliable detection of testdata from the source directory requires | - | ||||||||||||||||||||||||
| 539 | either that qmake is used, or the \c{QT_TESTCASE_BUILDDIR} macro is defined to | - | ||||||||||||||||||||||||
| 540 | point to the working directory from which the compiler is invoked, or only | - | ||||||||||||||||||||||||
| 541 | absolute paths to the source files are passed to the compiler. Otherwise, the | - | ||||||||||||||||||||||||
| 542 | absolute path of the source directory cannot be determined. | - | ||||||||||||||||||||||||
| 543 | - | |||||||||||||||||||||||||
| 544 | \b {Note:} For tests that use the \l QTEST_APPLESS_MAIN() macro to generate a | - | ||||||||||||||||||||||||
| 545 | \c{main()} function, \c{QFINDTESTDATA} will not attempt to find test data | - | ||||||||||||||||||||||||
| 546 | relative to QCoreApplication::applicationDirPath(). In practice, this means that | - | ||||||||||||||||||||||||
| 547 | tests using \c{QTEST_APPLESS_MAIN()} will fail to find their test data | - | ||||||||||||||||||||||||
| 548 | if run from a shadow build tree. | - | ||||||||||||||||||||||||
| 549 | */ | - | ||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||
| 551 | /*! \macro QTEST_MAIN(TestClass) | - | ||||||||||||||||||||||||
| 552 | - | |||||||||||||||||||||||||
| 553 | \relates QTest | - | ||||||||||||||||||||||||
| 554 | - | |||||||||||||||||||||||||
| 555 | Implements a main() function that instantiates an application object and | - | ||||||||||||||||||||||||
| 556 | the \a TestClass, and executes all tests in the order they were defined. | - | ||||||||||||||||||||||||
| 557 | Use this macro to build stand-alone executables. | - | ||||||||||||||||||||||||
| 558 | - | |||||||||||||||||||||||||
| 559 | If \c QT_WIDGETS_LIB is defined, the application object will be a QApplication, | - | ||||||||||||||||||||||||
| 560 | if \c QT_GUI_LIB is defined, the application object will be a QGuiApplication, | - | ||||||||||||||||||||||||
| 561 | otherwise it will be a QCoreApplication. If qmake is used and the configuration | - | ||||||||||||||||||||||||
| 562 | includes \c{QT += widgets}, then \c QT_WIDGETS_LIB will be defined automatically. | - | ||||||||||||||||||||||||
| 563 | Similarly, if qmake is used and the configuration includes \c{QT += gui}, then | - | ||||||||||||||||||||||||
| 564 | \c QT_GUI_LIB will be defined automatically. | - | ||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||
| 566 | \b {Note:} On platforms that have keypad navigation enabled by default, | - | ||||||||||||||||||||||||
| 567 | this macro will forcefully disable it if \c QT_WIDGETS_LIB is defined. This is done | - | ||||||||||||||||||||||||
| 568 | to simplify the usage of key events when writing autotests. If you wish to write a | - | ||||||||||||||||||||||||
| 569 | test case that uses keypad navigation, you should enable it either in the | - | ||||||||||||||||||||||||
| 570 | \c {initTestCase()} or \c {init()} functions of your test case by calling | - | ||||||||||||||||||||||||
| 571 | \l {QApplication::setNavigationMode()}. | - | ||||||||||||||||||||||||
| 572 | - | |||||||||||||||||||||||||
| 573 | Example: | - | ||||||||||||||||||||||||
| 574 | \snippet code/src_qtestlib_qtestcase.cpp 11 | - | ||||||||||||||||||||||||
| 575 | - | |||||||||||||||||||||||||
| 576 | \sa QTEST_APPLESS_MAIN(), QTEST_GUILESS_MAIN(), QTest::qExec(), | - | ||||||||||||||||||||||||
| 577 | QApplication::setNavigationMode() | - | ||||||||||||||||||||||||
| 578 | */ | - | ||||||||||||||||||||||||
| 579 | - | |||||||||||||||||||||||||
| 580 | /*! \macro QTEST_APPLESS_MAIN(TestClass) | - | ||||||||||||||||||||||||
| 581 | - | |||||||||||||||||||||||||
| 582 | \relates QTest | - | ||||||||||||||||||||||||
| 583 | - | |||||||||||||||||||||||||
| 584 | Implements a main() function that executes all tests in \a TestClass. | - | ||||||||||||||||||||||||
| 585 | - | |||||||||||||||||||||||||
| 586 | Behaves like \l QTEST_MAIN(), but doesn't instantiate a QApplication | - | ||||||||||||||||||||||||
| 587 | object. Use this macro for really simple stand-alone non-GUI tests. | - | ||||||||||||||||||||||||
| 588 | - | |||||||||||||||||||||||||
| 589 | \sa QTEST_MAIN() | - | ||||||||||||||||||||||||
| 590 | */ | - | ||||||||||||||||||||||||
| 591 | - | |||||||||||||||||||||||||
| 592 | /*! \macro QTEST_GUILESS_MAIN(TestClass) | - | ||||||||||||||||||||||||
| 593 | \since 5.0 | - | ||||||||||||||||||||||||
| 594 | - | |||||||||||||||||||||||||
| 595 | \relates QTest | - | ||||||||||||||||||||||||
| 596 | - | |||||||||||||||||||||||||
| 597 | Implements a main() function that instantiates a QCoreApplication object | - | ||||||||||||||||||||||||
| 598 | and the \a TestClass, and executes all tests in the order they were | - | ||||||||||||||||||||||||
| 599 | defined. Use this macro to build stand-alone executables. | - | ||||||||||||||||||||||||
| 600 | - | |||||||||||||||||||||||||
| 601 | Behaves like \l QTEST_MAIN(), but instantiates a QCoreApplication instead | - | ||||||||||||||||||||||||
| 602 | of the QApplication object. Use this macro if your test case doesn't need | - | ||||||||||||||||||||||||
| 603 | functionality offered by QApplication, but the event loop is still necessary. | - | ||||||||||||||||||||||||
| 604 | - | |||||||||||||||||||||||||
| 605 | \sa QTEST_MAIN() | - | ||||||||||||||||||||||||
| 606 | */ | - | ||||||||||||||||||||||||
| 607 | - | |||||||||||||||||||||||||
| 608 | /*! | - | ||||||||||||||||||||||||
| 609 | \macro QBENCHMARK | - | ||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||
| 611 | \relates QTest | - | ||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||
| 613 | This macro is used to measure the performance of code within a test. | - | ||||||||||||||||||||||||
| 614 | The code to be benchmarked is contained within a code block following | - | ||||||||||||||||||||||||
| 615 | this macro. | - | ||||||||||||||||||||||||
| 616 | - | |||||||||||||||||||||||||
| 617 | For example: | - | ||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||
| 619 | \snippet code/src_qtestlib_qtestcase.cpp 27 | - | ||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||
| 621 | \sa {Qt Test Overview#Creating a Benchmark}{Creating a Benchmark}, | - | ||||||||||||||||||||||||
| 622 | {Chapter 5: Writing a Benchmark}{Writing a Benchmark} | - | ||||||||||||||||||||||||
| 623 | */ | - | ||||||||||||||||||||||||
| 624 | - | |||||||||||||||||||||||||
| 625 | /*! | - | ||||||||||||||||||||||||
| 626 | \macro QBENCHMARK_ONCE | - | ||||||||||||||||||||||||
| 627 | \since 4.6 | - | ||||||||||||||||||||||||
| 628 | - | |||||||||||||||||||||||||
| 629 | \relates QTest | - | ||||||||||||||||||||||||
| 630 | - | |||||||||||||||||||||||||
| 631 | \brief The QBENCHMARK_ONCE macro is for measuring performance of a | - | ||||||||||||||||||||||||
| 632 | code block by running it once. | - | ||||||||||||||||||||||||
| 633 | - | |||||||||||||||||||||||||
| 634 | This macro is used to measure the performance of code within a test. | - | ||||||||||||||||||||||||
| 635 | The code to be benchmarked is contained within a code block following | - | ||||||||||||||||||||||||
| 636 | this macro. | - | ||||||||||||||||||||||||
| 637 | - | |||||||||||||||||||||||||
| 638 | Unlike QBENCHMARK, the contents of the contained code block is only run | - | ||||||||||||||||||||||||
| 639 | once. The elapsed time will be reported as "0" if it's to short to | - | ||||||||||||||||||||||||
| 640 | be measured by the selected backend. (Use) | - | ||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||
| 642 | \sa {Qt Test Overview#Creating a Benchmark}{Creating a Benchmark}, | - | ||||||||||||||||||||||||
| 643 | {Chapter 5: Writing a Benchmark}{Writing a Benchmark} | - | ||||||||||||||||||||||||
| 644 | */ | - | ||||||||||||||||||||||||
| 645 | - | |||||||||||||||||||||||||
| 646 | /*! \enum QTest::TestFailMode | - | ||||||||||||||||||||||||
| 647 | - | |||||||||||||||||||||||||
| 648 | This enum describes the modes for handling an expected failure of the | - | ||||||||||||||||||||||||
| 649 | \l QVERIFY() or \l QCOMPARE() macros. | - | ||||||||||||||||||||||||
| 650 | - | |||||||||||||||||||||||||
| 651 | \value Abort Aborts the execution of the test. Use this mode when it | - | ||||||||||||||||||||||||
| 652 | doesn't make sense to execute the test any further after the | - | ||||||||||||||||||||||||
| 653 | expected failure. | - | ||||||||||||||||||||||||
| 654 | - | |||||||||||||||||||||||||
| 655 | \value Continue Continues execution of the test after the expected failure. | - | ||||||||||||||||||||||||
| 656 | - | |||||||||||||||||||||||||
| 657 | \sa QEXPECT_FAIL() | - | ||||||||||||||||||||||||
| 658 | */ | - | ||||||||||||||||||||||||
| 659 | - | |||||||||||||||||||||||||
| 660 | /*! \enum QTest::KeyAction | - | ||||||||||||||||||||||||
| 661 | - | |||||||||||||||||||||||||
| 662 | This enum describes possible actions for key handling. | - | ||||||||||||||||||||||||
| 663 | - | |||||||||||||||||||||||||
| 664 | \value Press The key is pressed. | - | ||||||||||||||||||||||||
| 665 | \value Release The key is released. | - | ||||||||||||||||||||||||
| 666 | \value Click The key is clicked (pressed and released). | - | ||||||||||||||||||||||||
| 667 | \value Shortcut A shortcut is activated. This value has been added in Qt 5.6. | - | ||||||||||||||||||||||||
| 668 | */ | - | ||||||||||||||||||||||||
| 669 | - | |||||||||||||||||||||||||
| 670 | /*! \enum QTest::MouseAction | - | ||||||||||||||||||||||||
| 671 | - | |||||||||||||||||||||||||
| 672 | This enum describes possible actions for mouse handling. | - | ||||||||||||||||||||||||
| 673 | - | |||||||||||||||||||||||||
| 674 | \value MousePress A mouse button is pressed. | - | ||||||||||||||||||||||||
| 675 | \value MouseRelease A mouse button is released. | - | ||||||||||||||||||||||||
| 676 | \value MouseClick A mouse button is clicked (pressed and released). | - | ||||||||||||||||||||||||
| 677 | \value MouseDClick A mouse button is double clicked (pressed and released twice). | - | ||||||||||||||||||||||||
| 678 | \value MouseMove The mouse pointer has moved. | - | ||||||||||||||||||||||||
| 679 | */ | - | ||||||||||||||||||||||||
| 680 | - | |||||||||||||||||||||||||
| 681 | /*! \fn void QTest::keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 682 | - | |||||||||||||||||||||||||
| 683 | Simulates clicking of \a key with an optional \a modifier on a \a widget. | - | ||||||||||||||||||||||||
| 684 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 685 | before clicking the key. | - | ||||||||||||||||||||||||
| 686 | - | |||||||||||||||||||||||||
| 687 | Examples: | - | ||||||||||||||||||||||||
| 688 | \snippet code/src_qtestlib_qtestcase.cpp 14 | - | ||||||||||||||||||||||||
| 689 | - | |||||||||||||||||||||||||
| 690 | The first example above simulates clicking the \c escape key on \c | - | ||||||||||||||||||||||||
| 691 | myWidget without any keyboard modifiers and without delay. The | - | ||||||||||||||||||||||||
| 692 | second example simulates clicking \c shift-escape on \c myWidget | - | ||||||||||||||||||||||||
| 693 | following a 200 ms delay of the test. | - | ||||||||||||||||||||||||
| 694 | - | |||||||||||||||||||||||||
| 695 | \sa QTest::keyClicks() | - | ||||||||||||||||||||||||
| 696 | */ | - | ||||||||||||||||||||||||
| 697 | - | |||||||||||||||||||||||||
| 698 | /*! \fn void QTest::keyClick(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 699 | \overload | - | ||||||||||||||||||||||||
| 700 | - | |||||||||||||||||||||||||
| 701 | Simulates clicking of \a key with an optional \a modifier on a \a widget. | - | ||||||||||||||||||||||||
| 702 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 703 | before clicking the key. | - | ||||||||||||||||||||||||
| 704 | - | |||||||||||||||||||||||||
| 705 | Example: | - | ||||||||||||||||||||||||
| 706 | \snippet code/src_qtestlib_qtestcase.cpp 13 | - | ||||||||||||||||||||||||
| 707 | - | |||||||||||||||||||||||||
| 708 | The example above simulates clicking \c a on \c myWidget without | - | ||||||||||||||||||||||||
| 709 | any keyboard modifiers and without delay of the test. | - | ||||||||||||||||||||||||
| 710 | - | |||||||||||||||||||||||||
| 711 | \sa QTest::keyClicks() | - | ||||||||||||||||||||||||
| 712 | */ | - | ||||||||||||||||||||||||
| 713 | - | |||||||||||||||||||||||||
| 714 | /*! \fn void QTest::keyClick(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 715 | \overload | - | ||||||||||||||||||||||||
| 716 | \since 5.0 | - | ||||||||||||||||||||||||
| 717 | - | |||||||||||||||||||||||||
| 718 | Simulates clicking of \a key with an optional \a modifier on a \a window. | - | ||||||||||||||||||||||||
| 719 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 720 | before clicking the key. | - | ||||||||||||||||||||||||
| 721 | - | |||||||||||||||||||||||||
| 722 | Examples: | - | ||||||||||||||||||||||||
| 723 | \snippet code/src_qtestlib_qtestcase.cpp 29 | - | ||||||||||||||||||||||||
| 724 | - | |||||||||||||||||||||||||
| 725 | The first example above simulates clicking the \c escape key on \c | - | ||||||||||||||||||||||||
| 726 | myWindow without any keyboard modifiers and without delay. The | - | ||||||||||||||||||||||||
| 727 | second example simulates clicking \c shift-escape on \c myWindow | - | ||||||||||||||||||||||||
| 728 | following a 200 ms delay of the test. | - | ||||||||||||||||||||||||
| 729 | - | |||||||||||||||||||||||||
| 730 | \sa QTest::keyClicks() | - | ||||||||||||||||||||||||
| 731 | */ | - | ||||||||||||||||||||||||
| 732 | - | |||||||||||||||||||||||||
| 733 | /*! \fn void QTest::keyClick(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 734 | \overload | - | ||||||||||||||||||||||||
| 735 | \since 5.0 | - | ||||||||||||||||||||||||
| 736 | - | |||||||||||||||||||||||||
| 737 | Simulates clicking of \a key with an optional \a modifier on a \a window. | - | ||||||||||||||||||||||||
| 738 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 739 | before clicking the key. | - | ||||||||||||||||||||||||
| 740 | - | |||||||||||||||||||||||||
| 741 | Example: | - | ||||||||||||||||||||||||
| 742 | \snippet code/src_qtestlib_qtestcase.cpp 28 | - | ||||||||||||||||||||||||
| 743 | - | |||||||||||||||||||||||||
| 744 | The example above simulates clicking \c a on \c myWindow without | - | ||||||||||||||||||||||||
| 745 | any keyboard modifiers and without delay of the test. | - | ||||||||||||||||||||||||
| 746 | - | |||||||||||||||||||||||||
| 747 | \sa QTest::keyClicks() | - | ||||||||||||||||||||||||
| 748 | */ | - | ||||||||||||||||||||||||
| 749 | - | |||||||||||||||||||||||||
| 750 | /*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 751 | - | |||||||||||||||||||||||||
| 752 | Sends a Qt key event to \a widget with the given \a key and an associated \a action. | - | ||||||||||||||||||||||||
| 753 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay | - | ||||||||||||||||||||||||
| 754 | (in milliseconds) of the test before sending the event. | - | ||||||||||||||||||||||||
| 755 | */ | - | ||||||||||||||||||||||||
| 756 | - | |||||||||||||||||||||||||
| 757 | /*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 758 | \overload | - | ||||||||||||||||||||||||
| 759 | - | |||||||||||||||||||||||||
| 760 | Sends a Qt key event to \a widget with the given key \a ascii and an associated \a action. | - | ||||||||||||||||||||||||
| 761 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay | - | ||||||||||||||||||||||||
| 762 | (in milliseconds) of the test before sending the event. | - | ||||||||||||||||||||||||
| 763 | */ | - | ||||||||||||||||||||||||
| 764 | - | |||||||||||||||||||||||||
| 765 | /*! \fn void QTest::keyEvent(KeyAction action, QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 766 | \overload | - | ||||||||||||||||||||||||
| 767 | \since 5.0 | - | ||||||||||||||||||||||||
| 768 | - | |||||||||||||||||||||||||
| 769 | Sends a Qt key event to \a window with the given \a key and an associated \a action. | - | ||||||||||||||||||||||||
| 770 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay | - | ||||||||||||||||||||||||
| 771 | (in milliseconds) of the test before sending the event. | - | ||||||||||||||||||||||||
| 772 | */ | - | ||||||||||||||||||||||||
| 773 | - | |||||||||||||||||||||||||
| 774 | /*! \fn void QTest::keyEvent(KeyAction action, QWindow *window, char ascii, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 775 | \overload | - | ||||||||||||||||||||||||
| 776 | \since 5.0 | - | ||||||||||||||||||||||||
| 777 | - | |||||||||||||||||||||||||
| 778 | Sends a Qt key event to \a window with the given key \a ascii and an associated \a action. | - | ||||||||||||||||||||||||
| 779 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay | - | ||||||||||||||||||||||||
| 780 | (in milliseconds) of the test before sending the event. | - | ||||||||||||||||||||||||
| 781 | */ | - | ||||||||||||||||||||||||
| 782 | - | |||||||||||||||||||||||||
| 783 | /*! \fn void QTest::keyPress(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 784 | - | |||||||||||||||||||||||||
| 785 | Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay | - | ||||||||||||||||||||||||
| 786 | is larger than 0, the test will wait for \a delay milliseconds before pressing the key. | - | ||||||||||||||||||||||||
| 787 | - | |||||||||||||||||||||||||
| 788 | \b {Note:} At some point you should release the key using \l keyRelease(). | - | ||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||
| 790 | \sa QTest::keyRelease(), QTest::keyClick() | - | ||||||||||||||||||||||||
| 791 | */ | - | ||||||||||||||||||||||||
| 792 | - | |||||||||||||||||||||||||
| 793 | /*! \fn void QTest::keyPress(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 794 | \overload | - | ||||||||||||||||||||||||
| 795 | - | |||||||||||||||||||||||||
| 796 | Simulates pressing a \a key with an optional \a modifier on a \a widget. | - | ||||||||||||||||||||||||
| 797 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 798 | before pressing the key. | - | ||||||||||||||||||||||||
| 799 | - | |||||||||||||||||||||||||
| 800 | \b {Note:} At some point you should release the key using \l keyRelease(). | - | ||||||||||||||||||||||||
| 801 | - | |||||||||||||||||||||||||
| 802 | \sa QTest::keyRelease(), QTest::keyClick() | - | ||||||||||||||||||||||||
| 803 | */ | - | ||||||||||||||||||||||||
| 804 | - | |||||||||||||||||||||||||
| 805 | /*! \fn void QTest::keyPress(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 806 | \overload | - | ||||||||||||||||||||||||
| 807 | \since 5.0 | - | ||||||||||||||||||||||||
| 808 | - | |||||||||||||||||||||||||
| 809 | Simulates pressing a \a key with an optional \a modifier on a \a window. If \a delay | - | ||||||||||||||||||||||||
| 810 | is larger than 0, the test will wait for \a delay milliseconds before pressing the key. | - | ||||||||||||||||||||||||
| 811 | - | |||||||||||||||||||||||||
| 812 | \b {Note:} At some point you should release the key using \l keyRelease(). | - | ||||||||||||||||||||||||
| 813 | - | |||||||||||||||||||||||||
| 814 | \sa QTest::keyRelease(), QTest::keyClick() | - | ||||||||||||||||||||||||
| 815 | */ | - | ||||||||||||||||||||||||
| 816 | - | |||||||||||||||||||||||||
| 817 | /*! \fn void QTest::keyPress(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 818 | \overload | - | ||||||||||||||||||||||||
| 819 | \since 5.0 | - | ||||||||||||||||||||||||
| 820 | - | |||||||||||||||||||||||||
| 821 | Simulates pressing a \a key with an optional \a modifier on a \a window. | - | ||||||||||||||||||||||||
| 822 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 823 | before pressing the key. | - | ||||||||||||||||||||||||
| 824 | - | |||||||||||||||||||||||||
| 825 | \b {Note:} At some point you should release the key using \l keyRelease(). | - | ||||||||||||||||||||||||
| 826 | - | |||||||||||||||||||||||||
| 827 | \sa QTest::keyRelease(), QTest::keyClick() | - | ||||||||||||||||||||||||
| 828 | */ | - | ||||||||||||||||||||||||
| 829 | - | |||||||||||||||||||||||||
| 830 | /*! \fn void QTest::keyRelease(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 831 | - | |||||||||||||||||||||||||
| 832 | Simulates releasing a \a key with an optional \a modifier on a \a widget. | - | ||||||||||||||||||||||||
| 833 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 834 | before releasing the key. | - | ||||||||||||||||||||||||
| 835 | - | |||||||||||||||||||||||||
| 836 | \sa QTest::keyPress(), QTest::keyClick() | - | ||||||||||||||||||||||||
| 837 | */ | - | ||||||||||||||||||||||||
| 838 | - | |||||||||||||||||||||||||
| 839 | /*! \fn void QTest::keyRelease(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 840 | \overload | - | ||||||||||||||||||||||||
| 841 | - | |||||||||||||||||||||||||
| 842 | Simulates releasing a \a key with an optional \a modifier on a \a widget. | - | ||||||||||||||||||||||||
| 843 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 844 | before releasing the key. | - | ||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||
| 846 | \sa QTest::keyClick() | - | ||||||||||||||||||||||||
| 847 | */ | - | ||||||||||||||||||||||||
| 848 | - | |||||||||||||||||||||||||
| 849 | /*! \fn void QTest::keyRelease(QWindow *window, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 850 | \overload | - | ||||||||||||||||||||||||
| 851 | \since 5.0 | - | ||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||
| 853 | Simulates releasing a \a key with an optional \a modifier on a \a window. | - | ||||||||||||||||||||||||
| 854 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 855 | before releasing the key. | - | ||||||||||||||||||||||||
| 856 | - | |||||||||||||||||||||||||
| 857 | \sa QTest::keyPress(), QTest::keyClick() | - | ||||||||||||||||||||||||
| 858 | */ | - | ||||||||||||||||||||||||
| 859 | - | |||||||||||||||||||||||||
| 860 | /*! \fn void QTest::keyRelease(QWindow *window, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 861 | \overload | - | ||||||||||||||||||||||||
| 862 | \since 5.0 | - | ||||||||||||||||||||||||
| 863 | - | |||||||||||||||||||||||||
| 864 | Simulates releasing a \a key with an optional \a modifier on a \a window. | - | ||||||||||||||||||||||||
| 865 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - | ||||||||||||||||||||||||
| 866 | before releasing the key. | - | ||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||
| 868 | \sa QTest::keyClick() | - | ||||||||||||||||||||||||
| 869 | */ | - | ||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||
| 871 | /*! \fn void QTest::keyClicks(QWidget *widget, const QString &sequence, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - | ||||||||||||||||||||||||
| 872 | - | |||||||||||||||||||||||||
| 873 | Simulates clicking a \a sequence of keys on a \a | - | ||||||||||||||||||||||||
| 874 | widget. Optionally, a keyboard \a modifier can be specified as | - | ||||||||||||||||||||||||
| 875 | well as a \a delay (in milliseconds) of the test before each key | - | ||||||||||||||||||||||||
| 876 | click. | - | ||||||||||||||||||||||||
| 877 | - | |||||||||||||||||||||||||
| 878 | Example: | - | ||||||||||||||||||||||||
| 879 | \snippet code/src_qtestlib_qtestcase.cpp 15 | - | ||||||||||||||||||||||||
| 880 | - | |||||||||||||||||||||||||
| 881 | The example above simulates clicking the sequence of keys | - | ||||||||||||||||||||||||
| 882 | representing "hello world" on \c myWidget without any keyboard | - | ||||||||||||||||||||||||
| 883 | modifiers and without delay of the test. | - | ||||||||||||||||||||||||
| 884 | - | |||||||||||||||||||||||||
| 885 | \sa QTest::keyClick() | - | ||||||||||||||||||||||||
| 886 | */ | - | ||||||||||||||||||||||||
| 887 | - | |||||||||||||||||||||||||
| 888 | /*! \fn void QTest::waitForEvents() | - | ||||||||||||||||||||||||
| 889 | \internal | - | ||||||||||||||||||||||||
| 890 | */ | - | ||||||||||||||||||||||||
| 891 | - | |||||||||||||||||||||||||
| 892 | /*! \fn void QTest::mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1) | - | ||||||||||||||||||||||||
| 893 | \internal | - | ||||||||||||||||||||||||
| 894 | */ | - | ||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||
| 896 | /*! \fn void QTest::mouseEvent(MouseAction action, QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1) | - | ||||||||||||||||||||||||
| 897 | \internal | - | ||||||||||||||||||||||||
| 898 | */ | - | ||||||||||||||||||||||||
| 899 | - | |||||||||||||||||||||||||
| 900 | /*! \fn void QTest::mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 901 | - | |||||||||||||||||||||||||
| 902 | Simulates pressing a mouse \a button with an optional \a modifier | - | ||||||||||||||||||||||||
| 903 | on a \a widget. The position is defined by \a pos; the default | - | ||||||||||||||||||||||||
| 904 | position is the center of the widget. If \a delay is specified, | - | ||||||||||||||||||||||||
| 905 | the test will wait for the specified amount of milliseconds before | - | ||||||||||||||||||||||||
| 906 | the press. | - | ||||||||||||||||||||||||
| 907 | - | |||||||||||||||||||||||||
| 908 | \sa QTest::mouseRelease(), QTest::mouseClick() | - | ||||||||||||||||||||||||
| 909 | */ | - | ||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||
| 911 | /*! \fn void QTest::mousePress(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 912 | \overload | - | ||||||||||||||||||||||||
| 913 | \since 5.0 | - | ||||||||||||||||||||||||
| 914 | - | |||||||||||||||||||||||||
| 915 | Simulates pressing a mouse \a button with an optional \a stateKey modifier | - | ||||||||||||||||||||||||
| 916 | on a \a window. The position is defined by \a pos; the default | - | ||||||||||||||||||||||||
| 917 | position is the center of the window. If \a delay is specified, | - | ||||||||||||||||||||||||
| 918 | the test will wait for the specified amount of milliseconds before | - | ||||||||||||||||||||||||
| 919 | the press. | - | ||||||||||||||||||||||||
| 920 | - | |||||||||||||||||||||||||
| 921 | \sa QTest::mouseRelease(), QTest::mouseClick() | - | ||||||||||||||||||||||||
| 922 | */ | - | ||||||||||||||||||||||||
| 923 | - | |||||||||||||||||||||||||
| 924 | /*! \fn void QTest::mouseRelease(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 925 | - | |||||||||||||||||||||||||
| 926 | Simulates releasing a mouse \a button with an optional \a modifier | - | ||||||||||||||||||||||||
| 927 | on a \a widget. The position of the release is defined by \a pos; | - | ||||||||||||||||||||||||
| 928 | the default position is the center of the widget. If \a delay is | - | ||||||||||||||||||||||||
| 929 | specified, the test will wait for the specified amount of | - | ||||||||||||||||||||||||
| 930 | milliseconds before releasing the button. | - | ||||||||||||||||||||||||
| 931 | - | |||||||||||||||||||||||||
| 932 | \sa QTest::mousePress(), QTest::mouseClick() | - | ||||||||||||||||||||||||
| 933 | */ | - | ||||||||||||||||||||||||
| 934 | - | |||||||||||||||||||||||||
| 935 | /*! \fn void QTest::mouseRelease(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 936 | \overload | - | ||||||||||||||||||||||||
| 937 | \since 5.0 | - | ||||||||||||||||||||||||
| 938 | - | |||||||||||||||||||||||||
| 939 | Simulates releasing a mouse \a button with an optional \a stateKey modifier | - | ||||||||||||||||||||||||
| 940 | on a \a window. The position of the release is defined by \a pos; | - | ||||||||||||||||||||||||
| 941 | the default position is the center of the window. If \a delay is | - | ||||||||||||||||||||||||
| 942 | specified, the test will wait for the specified amount of | - | ||||||||||||||||||||||||
| 943 | milliseconds before releasing the button. | - | ||||||||||||||||||||||||
| 944 | - | |||||||||||||||||||||||||
| 945 | \sa QTest::mousePress(), QTest::mouseClick() | - | ||||||||||||||||||||||||
| 946 | */ | - | ||||||||||||||||||||||||
| 947 | - | |||||||||||||||||||||||||
| 948 | /*! \fn void QTest::mouseClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 949 | - | |||||||||||||||||||||||||
| 950 | Simulates clicking a mouse \a button with an optional \a modifier | - | ||||||||||||||||||||||||
| 951 | on a \a widget. The position of the click is defined by \a pos; | - | ||||||||||||||||||||||||
| 952 | the default position is the center of the widget. If \a delay is | - | ||||||||||||||||||||||||
| 953 | specified, the test will wait for the specified amount of | - | ||||||||||||||||||||||||
| 954 | milliseconds before pressing and before releasing the button. | - | ||||||||||||||||||||||||
| 955 | - | |||||||||||||||||||||||||
| 956 | \sa QTest::mousePress(), QTest::mouseRelease() | - | ||||||||||||||||||||||||
| 957 | */ | - | ||||||||||||||||||||||||
| 958 | - | |||||||||||||||||||||||||
| 959 | /*! \fn void QTest::mouseClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 960 | \overload | - | ||||||||||||||||||||||||
| 961 | \since 5.0 | - | ||||||||||||||||||||||||
| 962 | - | |||||||||||||||||||||||||
| 963 | Simulates clicking a mouse \a button with an optional \a stateKey modifier | - | ||||||||||||||||||||||||
| 964 | on a \a window. The position of the click is defined by \a pos; | - | ||||||||||||||||||||||||
| 965 | the default position is the center of the window. If \a delay is | - | ||||||||||||||||||||||||
| 966 | specified, the test will wait for the specified amount of | - | ||||||||||||||||||||||||
| 967 | milliseconds before pressing and before releasing the button. | - | ||||||||||||||||||||||||
| 968 | - | |||||||||||||||||||||||||
| 969 | \sa QTest::mousePress(), QTest::mouseRelease() | - | ||||||||||||||||||||||||
| 970 | */ | - | ||||||||||||||||||||||||
| 971 | - | |||||||||||||||||||||||||
| 972 | /*! \fn void QTest::mouseDClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 973 | - | |||||||||||||||||||||||||
| 974 | Simulates double clicking a mouse \a button with an optional \a | - | ||||||||||||||||||||||||
| 975 | modifier on a \a widget. The position of the click is defined by | - | ||||||||||||||||||||||||
| 976 | \a pos; the default position is the center of the widget. If \a | - | ||||||||||||||||||||||||
| 977 | delay is specified, the test will wait for the specified amount of | - | ||||||||||||||||||||||||
| 978 | milliseconds before each press and release. | - | ||||||||||||||||||||||||
| 979 | - | |||||||||||||||||||||||||
| 980 | \sa QTest::mouseClick() | - | ||||||||||||||||||||||||
| 981 | */ | - | ||||||||||||||||||||||||
| 982 | - | |||||||||||||||||||||||||
| 983 | /*! \fn void QTest::mouseDClick(QWindow *window, Qt::MouseButton button, Qt::KeyboardModifiers stateKey = 0, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 984 | \overload | - | ||||||||||||||||||||||||
| 985 | \since 5.0 | - | ||||||||||||||||||||||||
| 986 | - | |||||||||||||||||||||||||
| 987 | Simulates double clicking a mouse \a button with an optional \a stateKey | - | ||||||||||||||||||||||||
| 988 | modifier on a \a window. The position of the click is defined by | - | ||||||||||||||||||||||||
| 989 | \a pos; the default position is the center of the window. If \a | - | ||||||||||||||||||||||||
| 990 | delay is specified, the test will wait for the specified amount of | - | ||||||||||||||||||||||||
| 991 | milliseconds before each press and release. | - | ||||||||||||||||||||||||
| 992 | - | |||||||||||||||||||||||||
| 993 | \sa QTest::mouseClick() | - | ||||||||||||||||||||||||
| 994 | */ | - | ||||||||||||||||||||||||
| 995 | - | |||||||||||||||||||||||||
| 996 | /*! \fn void QTest::mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 997 | - | |||||||||||||||||||||||||
| 998 | Moves the mouse pointer to a \a widget. If \a pos is not | - | ||||||||||||||||||||||||
| 999 | specified, the mouse pointer moves to the center of the widget. If | - | ||||||||||||||||||||||||
| 1000 | a \a delay (in milliseconds) is given, the test will wait before | - | ||||||||||||||||||||||||
| 1001 | moving the mouse pointer. | - | ||||||||||||||||||||||||
| 1002 | */ | - | ||||||||||||||||||||||||
| 1003 | - | |||||||||||||||||||||||||
| 1004 | /*! \fn void QTest::mouseMove(QWindow *window, QPoint pos = QPoint(), int delay=-1) | - | ||||||||||||||||||||||||
| 1005 | \overload | - | ||||||||||||||||||||||||
| 1006 | \since 5.0 | - | ||||||||||||||||||||||||
| 1007 | - | |||||||||||||||||||||||||
| 1008 | Moves the mouse pointer to a \a window. If \a pos is not | - | ||||||||||||||||||||||||
| 1009 | specified, the mouse pointer moves to the center of the window. If | - | ||||||||||||||||||||||||
| 1010 | a \a delay (in milliseconds) is given, the test will wait before | - | ||||||||||||||||||||||||
| 1011 | moving the mouse pointer. | - | ||||||||||||||||||||||||
| 1012 | */ | - | ||||||||||||||||||||||||
| 1013 | - | |||||||||||||||||||||||||
| 1014 | /*! | - | ||||||||||||||||||||||||
| 1015 | \fn char *QTest::toString(const T &value) | - | ||||||||||||||||||||||||
| 1016 | - | |||||||||||||||||||||||||
| 1017 | Returns a textual representation of \a value. This function is used by | - | ||||||||||||||||||||||||
| 1018 | \l QCOMPARE() to output verbose information in case of a test failure. | - | ||||||||||||||||||||||||
| 1019 | - | |||||||||||||||||||||||||
| 1020 | You can add specializations or overloads of this function to your test to enable | - | ||||||||||||||||||||||||
| 1021 | verbose output. | - | ||||||||||||||||||||||||
| 1022 | - | |||||||||||||||||||||||||
| 1023 | \b {Note:} Starting with Qt 5.5, you should prefer to provide a toString() function | - | ||||||||||||||||||||||||
| 1024 | in the type's namespace instead of specializing this template. | - | ||||||||||||||||||||||||
| 1025 | If your code needs to continue to work with the QTestLib from Qt 5.4 or | - | ||||||||||||||||||||||||
| 1026 | earlier, you need to continue to use specialization. | - | ||||||||||||||||||||||||
| 1027 | - | |||||||||||||||||||||||||
| 1028 | \b {Note:} The caller of toString() must delete the returned data | - | ||||||||||||||||||||||||
| 1029 | using \c{delete[]}. Your implementation should return a string | - | ||||||||||||||||||||||||
| 1030 | created with \c{new[]} or qstrdup(). The easiest way to do so is to | - | ||||||||||||||||||||||||
| 1031 | create a QByteArray or QString and calling QTest::toString() on it | - | ||||||||||||||||||||||||
| 1032 | (see second example below). | - | ||||||||||||||||||||||||
| 1033 | - | |||||||||||||||||||||||||
| 1034 | Example for specializing (Qt ≤ 5.4): | - | ||||||||||||||||||||||||
| 1035 | - | |||||||||||||||||||||||||
| 1036 | \snippet code/src_qtestlib_qtestcase.cpp 16 | - | ||||||||||||||||||||||||
| 1037 | - | |||||||||||||||||||||||||
| 1038 | The example above defines a toString() specialization for a class | - | ||||||||||||||||||||||||
| 1039 | called \c MyPoint. Whenever a comparison of two instances of \c | - | ||||||||||||||||||||||||
| 1040 | MyPoint fails, \l QCOMPARE() will call this function to output the | - | ||||||||||||||||||||||||
| 1041 | contents of \c MyPoint to the test log. | - | ||||||||||||||||||||||||
| 1042 | - | |||||||||||||||||||||||||
| 1043 | Same example, but with overloading (Qt ≥ 5.5): | - | ||||||||||||||||||||||||
| 1044 | - | |||||||||||||||||||||||||
| 1045 | \snippet code/src_qtestlib_qtestcase.cpp toString-overload | - | ||||||||||||||||||||||||
| 1046 | - | |||||||||||||||||||||||||
| 1047 | \sa QCOMPARE() | - | ||||||||||||||||||||||||
| 1048 | */ | - | ||||||||||||||||||||||||
| 1049 | - | |||||||||||||||||||||||||
| 1050 | /*! | - | ||||||||||||||||||||||||
| 1051 | \fn char *QTest::toString(const QLatin1String &string) | - | ||||||||||||||||||||||||
| 1052 | \overload | - | ||||||||||||||||||||||||
| 1053 | - | |||||||||||||||||||||||||
| 1054 | Returns a textual representation of the given \a string. | - | ||||||||||||||||||||||||
| 1055 | */ | - | ||||||||||||||||||||||||
| 1056 | - | |||||||||||||||||||||||||
| 1057 | /*! | - | ||||||||||||||||||||||||
| 1058 | \fn char *QTest::toString(const QString &string) | - | ||||||||||||||||||||||||
| 1059 | \overload | - | ||||||||||||||||||||||||
| 1060 | - | |||||||||||||||||||||||||
| 1061 | Returns a textual representation of the given \a string. | - | ||||||||||||||||||||||||
| 1062 | */ | - | ||||||||||||||||||||||||
| 1063 | - | |||||||||||||||||||||||||
| 1064 | /*! | - | ||||||||||||||||||||||||
| 1065 | \fn char *QTest::toString(const QByteArray &ba) | - | ||||||||||||||||||||||||
| 1066 | \overload | - | ||||||||||||||||||||||||
| 1067 | - | |||||||||||||||||||||||||
| 1068 | Returns a textual representation of the byte array \a ba. | - | ||||||||||||||||||||||||
| 1069 | - | |||||||||||||||||||||||||
| 1070 | \sa QTest::toHexRepresentation() | - | ||||||||||||||||||||||||
| 1071 | */ | - | ||||||||||||||||||||||||
| 1072 | - | |||||||||||||||||||||||||
| 1073 | /*! | - | ||||||||||||||||||||||||
| 1074 | \fn char *QTest::toString(const QTime &time) | - | ||||||||||||||||||||||||
| 1075 | \overload | - | ||||||||||||||||||||||||
| 1076 | - | |||||||||||||||||||||||||
| 1077 | Returns a textual representation of the given \a time. | - | ||||||||||||||||||||||||
| 1078 | */ | - | ||||||||||||||||||||||||
| 1079 | - | |||||||||||||||||||||||||
| 1080 | /*! | - | ||||||||||||||||||||||||
| 1081 | \fn char *QTest::toString(const QDate &date) | - | ||||||||||||||||||||||||
| 1082 | \overload | - | ||||||||||||||||||||||||
| 1083 | - | |||||||||||||||||||||||||
| 1084 | Returns a textual representation of the given \a date. | - | ||||||||||||||||||||||||
| 1085 | */ | - | ||||||||||||||||||||||||
| 1086 | - | |||||||||||||||||||||||||
| 1087 | /*! | - | ||||||||||||||||||||||||
| 1088 | \fn char *QTest::toString(const QDateTime &dateTime) | - | ||||||||||||||||||||||||
| 1089 | \overload | - | ||||||||||||||||||||||||
| 1090 | - | |||||||||||||||||||||||||
| 1091 | Returns a textual representation of the date and time specified by | - | ||||||||||||||||||||||||
| 1092 | \a dateTime. | - | ||||||||||||||||||||||||
| 1093 | */ | - | ||||||||||||||||||||||||
| 1094 | - | |||||||||||||||||||||||||
| 1095 | /*! | - | ||||||||||||||||||||||||
| 1096 | \fn char *QTest::toString(const QChar &character) | - | ||||||||||||||||||||||||
| 1097 | \overload | - | ||||||||||||||||||||||||
| 1098 | - | |||||||||||||||||||||||||
| 1099 | Returns a textual representation of the given \a character. | - | ||||||||||||||||||||||||
| 1100 | */ | - | ||||||||||||||||||||||||
| 1101 | - | |||||||||||||||||||||||||
| 1102 | /*! | - | ||||||||||||||||||||||||
| 1103 | \fn char *QTest::toString(const QPoint &point) | - | ||||||||||||||||||||||||
| 1104 | \overload | - | ||||||||||||||||||||||||
| 1105 | - | |||||||||||||||||||||||||
| 1106 | Returns a textual representation of the given \a point. | - | ||||||||||||||||||||||||
| 1107 | */ | - | ||||||||||||||||||||||||
| 1108 | - | |||||||||||||||||||||||||
| 1109 | /*! | - | ||||||||||||||||||||||||
| 1110 | \fn char *QTest::toString(const QSize &size) | - | ||||||||||||||||||||||||
| 1111 | \overload | - | ||||||||||||||||||||||||
| 1112 | - | |||||||||||||||||||||||||
| 1113 | Returns a textual representation of the given \a size. | - | ||||||||||||||||||||||||
| 1114 | */ | - | ||||||||||||||||||||||||
| 1115 | - | |||||||||||||||||||||||||
| 1116 | /*! | - | ||||||||||||||||||||||||
| 1117 | \fn char *QTest::toString(const QRect &rectangle) | - | ||||||||||||||||||||||||
| 1118 | \overload | - | ||||||||||||||||||||||||
| 1119 | - | |||||||||||||||||||||||||
| 1120 | Returns a textual representation of the given \a rectangle. | - | ||||||||||||||||||||||||
| 1121 | */ | - | ||||||||||||||||||||||||
| 1122 | - | |||||||||||||||||||||||||
| 1123 | /*! | - | ||||||||||||||||||||||||
| 1124 | \fn char *QTest::toString(const QUrl &url) | - | ||||||||||||||||||||||||
| 1125 | \since 4.4 | - | ||||||||||||||||||||||||
| 1126 | \overload | - | ||||||||||||||||||||||||
| 1127 | - | |||||||||||||||||||||||||
| 1128 | Returns a textual representation of the given \a url. | - | ||||||||||||||||||||||||
| 1129 | */ | - | ||||||||||||||||||||||||
| 1130 | - | |||||||||||||||||||||||||
| 1131 | /*! | - | ||||||||||||||||||||||||
| 1132 | \fn char *QTest::toString(const QPointF &point) | - | ||||||||||||||||||||||||
| 1133 | \overload | - | ||||||||||||||||||||||||
| 1134 | - | |||||||||||||||||||||||||
| 1135 | Returns a textual representation of the given \a point. | - | ||||||||||||||||||||||||
| 1136 | */ | - | ||||||||||||||||||||||||
| 1137 | - | |||||||||||||||||||||||||
| 1138 | /*! | - | ||||||||||||||||||||||||
| 1139 | \fn char *QTest::toString(const QSizeF &size) | - | ||||||||||||||||||||||||
| 1140 | \overload | - | ||||||||||||||||||||||||
| 1141 | - | |||||||||||||||||||||||||
| 1142 | Returns a textual representation of the given \a size. | - | ||||||||||||||||||||||||
| 1143 | */ | - | ||||||||||||||||||||||||
| 1144 | - | |||||||||||||||||||||||||
| 1145 | /*! | - | ||||||||||||||||||||||||
| 1146 | \fn char *QTest::toString(const QRectF &rectangle) | - | ||||||||||||||||||||||||
| 1147 | \overload | - | ||||||||||||||||||||||||
| 1148 | - | |||||||||||||||||||||||||
| 1149 | Returns a textual representation of the given \a rectangle. | - | ||||||||||||||||||||||||
| 1150 | */ | - | ||||||||||||||||||||||||
| 1151 | - | |||||||||||||||||||||||||
| 1152 | /*! | - | ||||||||||||||||||||||||
| 1153 | \fn char *QTest::toString(const QVariant &variant) | - | ||||||||||||||||||||||||
| 1154 | \overload | - | ||||||||||||||||||||||||
| 1155 | - | |||||||||||||||||||||||||
| 1156 | Returns a textual representation of the given \a variant. | - | ||||||||||||||||||||||||
| 1157 | */ | - | ||||||||||||||||||||||||
| 1158 | - | |||||||||||||||||||||||||
| 1159 | /*! | - | ||||||||||||||||||||||||
| 1160 | \fn char *QTest::toString(QSizePolicy::ControlType ct) | - | ||||||||||||||||||||||||
| 1161 | \overload | - | ||||||||||||||||||||||||
| 1162 | \since 5.5 | - | ||||||||||||||||||||||||
| 1163 | - | |||||||||||||||||||||||||
| 1164 | Returns a textual representation of control type \a ct. | - | ||||||||||||||||||||||||
| 1165 | */ | - | ||||||||||||||||||||||||
| 1166 | - | |||||||||||||||||||||||||
| 1167 | /*! | - | ||||||||||||||||||||||||
| 1168 | \fn char *QTest::toString(QSizePolicy::ControlTypes cts) | - | ||||||||||||||||||||||||
| 1169 | \overload | - | ||||||||||||||||||||||||
| 1170 | \since 5.5 | - | ||||||||||||||||||||||||
| 1171 | - | |||||||||||||||||||||||||
| 1172 | Returns a textual representation of control types \a cts. | - | ||||||||||||||||||||||||
| 1173 | */ | - | ||||||||||||||||||||||||
| 1174 | - | |||||||||||||||||||||||||
| 1175 | /*! | - | ||||||||||||||||||||||||
| 1176 | \fn char *QTest::toString(QSizePolicy::Policy p) | - | ||||||||||||||||||||||||
| 1177 | \overload | - | ||||||||||||||||||||||||
| 1178 | \since 5.5 | - | ||||||||||||||||||||||||
| 1179 | - | |||||||||||||||||||||||||
| 1180 | Returns a textual representation of policy \a p. | - | ||||||||||||||||||||||||
| 1181 | */ | - | ||||||||||||||||||||||||
| 1182 | - | |||||||||||||||||||||||||
| 1183 | /*! | - | ||||||||||||||||||||||||
| 1184 | \fn char *QTest::toString(QSizePolicy sp) | - | ||||||||||||||||||||||||
| 1185 | \overload | - | ||||||||||||||||||||||||
| 1186 | \since 5.5 | - | ||||||||||||||||||||||||
| 1187 | - | |||||||||||||||||||||||||
| 1188 | Returns a textual representation of size policy \a sp. | - | ||||||||||||||||||||||||
| 1189 | */ | - | ||||||||||||||||||||||||
| 1190 | - | |||||||||||||||||||||||||
| 1191 | /*! \fn void QTest::qWait(int ms) | - | ||||||||||||||||||||||||
| 1192 | - | |||||||||||||||||||||||||
| 1193 | Waits for \a ms milliseconds. While waiting, events will be processed and | - | ||||||||||||||||||||||||
| 1194 | your test will stay responsive to user interface events or network communication. | - | ||||||||||||||||||||||||
| 1195 | - | |||||||||||||||||||||||||
| 1196 | Example: | - | ||||||||||||||||||||||||
| 1197 | \snippet code/src_qtestlib_qtestcase.cpp 17 | - | ||||||||||||||||||||||||
| 1198 | - | |||||||||||||||||||||||||
| 1199 | The code above will wait until the network server is responding for a | - | ||||||||||||||||||||||||
| 1200 | maximum of about 12.5 seconds. | - | ||||||||||||||||||||||||
| 1201 | - | |||||||||||||||||||||||||
| 1202 | \sa QTest::qSleep(), QSignalSpy::wait() | - | ||||||||||||||||||||||||
| 1203 | */ | - | ||||||||||||||||||||||||
| 1204 | - | |||||||||||||||||||||||||
| 1205 | /*! \fn bool QTest::qWaitForWindowExposed(QWindow *window, int timeout) | - | ||||||||||||||||||||||||
| 1206 | \since 5.0 | - | ||||||||||||||||||||||||
| 1207 | - | |||||||||||||||||||||||||
| 1208 | Waits for \a timeout milliseconds or until the \a window is exposed. | - | ||||||||||||||||||||||||
| 1209 | Returns \c true if \c window is exposed within \a timeout milliseconds, otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1210 | - | |||||||||||||||||||||||||
| 1211 | This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some | - | ||||||||||||||||||||||||
| 1212 | time after being asked to show itself on the screen. | - | ||||||||||||||||||||||||
| 1213 | - | |||||||||||||||||||||||||
| 1214 | \sa QTest::qWaitForWindowActive(), QWindow::isExposed() | - | ||||||||||||||||||||||||
| 1215 | */ | - | ||||||||||||||||||||||||
| 1216 | - | |||||||||||||||||||||||||
| 1217 | /*! \fn bool QTest::qWaitForWindowActive(QWindow *window, int timeout) | - | ||||||||||||||||||||||||
| 1218 | \since 5.0 | - | ||||||||||||||||||||||||
| 1219 | - | |||||||||||||||||||||||||
| 1220 | Waits for \a timeout milliseconds or until the \a window is active. | - | ||||||||||||||||||||||||
| 1221 | - | |||||||||||||||||||||||||
| 1222 | Returns \c true if \c window is active within \a timeout milliseconds, otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1223 | - | |||||||||||||||||||||||||
| 1224 | \sa QTest::qWaitForWindowExposed(), QWindow::isActive() | - | ||||||||||||||||||||||||
| 1225 | */ | - | ||||||||||||||||||||||||
| 1226 | - | |||||||||||||||||||||||||
| 1227 | /*! \fn bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout) | - | ||||||||||||||||||||||||
| 1228 | \since 5.0 | - | ||||||||||||||||||||||||
| 1229 | - | |||||||||||||||||||||||||
| 1230 | Waits for \a timeout milliseconds or until the \a widget's window is exposed. | - | ||||||||||||||||||||||||
| 1231 | Returns \c true if \c widget's window is exposed within \a timeout milliseconds, otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1232 | - | |||||||||||||||||||||||||
| 1233 | This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some | - | ||||||||||||||||||||||||
| 1234 | time after being asked to show itself on the screen. | - | ||||||||||||||||||||||||
| 1235 | - | |||||||||||||||||||||||||
| 1236 | \sa QTest::qWaitForWindowActive() | - | ||||||||||||||||||||||||
| 1237 | */ | - | ||||||||||||||||||||||||
| 1238 | - | |||||||||||||||||||||||||
| 1239 | /*! \fn bool QTest::qWaitForWindowActive(QWidget *widget, int timeout) | - | ||||||||||||||||||||||||
| 1240 | \since 5.0 | - | ||||||||||||||||||||||||
| 1241 | - | |||||||||||||||||||||||||
| 1242 | Waits for \a timeout milliseconds or until the \a widget's window is active. | - | ||||||||||||||||||||||||
| 1243 | - | |||||||||||||||||||||||||
| 1244 | Returns \c true if \c widget's window is active within \a timeout milliseconds, otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1245 | - | |||||||||||||||||||||||||
| 1246 | \sa QTest::qWaitForWindowExposed(), QWidget::isActiveWindow() | - | ||||||||||||||||||||||||
| 1247 | */ | - | ||||||||||||||||||||||||
| 1248 | - | |||||||||||||||||||||||||
| 1249 | /*! \fn bool QTest::qWaitForWindowShown(QWidget *widget, int timeout) | - | ||||||||||||||||||||||||
| 1250 | \since 5.0 | - | ||||||||||||||||||||||||
| 1251 | \deprecated | - | ||||||||||||||||||||||||
| 1252 | - | |||||||||||||||||||||||||
| 1253 | Waits for \a timeout milliseconds or until the \a widget's window is exposed. | - | ||||||||||||||||||||||||
| 1254 | Returns \c true if \c widget's window is exposed within \a timeout milliseconds, otherwise returns \c false. | - | ||||||||||||||||||||||||
| 1255 | - | |||||||||||||||||||||||||
| 1256 | This function does the same as qWaitForWindowExposed(). | - | ||||||||||||||||||||||||
| 1257 | - | |||||||||||||||||||||||||
| 1258 | Example: | - | ||||||||||||||||||||||||
| 1259 | \snippet code/src_qtestlib_qtestcase.cpp 24 | - | ||||||||||||||||||||||||
| 1260 | - | |||||||||||||||||||||||||
| 1261 | \sa QTest::qWaitForWindowActive(), QTest::qWaitForWindowExposed() | - | ||||||||||||||||||||||||
| 1262 | */ | - | ||||||||||||||||||||||||
| 1263 | - | |||||||||||||||||||||||||
| 1264 | /*! | - | ||||||||||||||||||||||||
| 1265 | \class QTest::QTouchEventSequence | - | ||||||||||||||||||||||||
| 1266 | \inmodule QtTest | - | ||||||||||||||||||||||||
| 1267 | \since 4.6 | - | ||||||||||||||||||||||||
| 1268 | - | |||||||||||||||||||||||||
| 1269 | \brief The QTouchEventSequence class is used to simulate a sequence of touch events. | - | ||||||||||||||||||||||||
| 1270 | - | |||||||||||||||||||||||||
| 1271 | To simulate a sequence of touch events on a specific device for a window or widget, call | - | ||||||||||||||||||||||||
| 1272 | QTest::touchEvent to create a QTouchEventSequence instance. Add touch events to | - | ||||||||||||||||||||||||
| 1273 | the sequence by calling press(), move(), release() and stationary(), and let the | - | ||||||||||||||||||||||||
| 1274 | instance run out of scope to commit the sequence to the event system. | - | ||||||||||||||||||||||||
| 1275 | - | |||||||||||||||||||||||||
| 1276 | Example: | - | ||||||||||||||||||||||||
| 1277 | \snippet code/src_qtestlib_qtestcase.cpp 25 | - | ||||||||||||||||||||||||
| 1278 | */ | - | ||||||||||||||||||||||||
| 1279 | - | |||||||||||||||||||||||||
| 1280 | /*! | - | ||||||||||||||||||||||||
| 1281 | \fn QTest::QTouchEventSequence::~QTouchEventSequence() | - | ||||||||||||||||||||||||
| 1282 | - | |||||||||||||||||||||||||
| 1283 | Commits this sequence of touch events, unless autoCommit was disabled, and frees allocated resources. | - | ||||||||||||||||||||||||
| 1284 | */ | - | ||||||||||||||||||||||||
| 1285 | - | |||||||||||||||||||||||||
| 1286 | /*! | - | ||||||||||||||||||||||||
| 1287 | \fn void QTest::QTouchEventSequence::commit(bool processEvents) | - | ||||||||||||||||||||||||
| 1288 | - | |||||||||||||||||||||||||
| 1289 | Commits this sequence of touch events to the event system. Normally there is no need to call this | - | ||||||||||||||||||||||||
| 1290 | function because it is called from the destructor. However, if autoCommit is disabled, the events | - | ||||||||||||||||||||||||
| 1291 | only get committed upon explicitly calling this function. | - | ||||||||||||||||||||||||
| 1292 | - | |||||||||||||||||||||||||
| 1293 | In special cases tests may want to disable the processing of the events. This can be achieved by | - | ||||||||||||||||||||||||
| 1294 | setting \a processEvents to false. This results in merely queuing the events, the event loop will | - | ||||||||||||||||||||||||
| 1295 | not be forced to process them. | - | ||||||||||||||||||||||||
| 1296 | */ | - | ||||||||||||||||||||||||
| 1297 | - | |||||||||||||||||||||||||
| 1298 | /*! | - | ||||||||||||||||||||||||
| 1299 | \fn QTouchEventSequence &QTest::QTouchEventSequence::press(int touchId, const QPoint &pt, QWindow *window) | - | ||||||||||||||||||||||||
| 1300 | \since 5.0 | - | ||||||||||||||||||||||||
| 1301 | - | |||||||||||||||||||||||||
| 1302 | Adds a press event for touchpoint \a touchId at position \a pt to this sequence and returns | - | ||||||||||||||||||||||||
| 1303 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1304 | - | |||||||||||||||||||||||||
| 1305 | The position \a pt is interpreted as relative to \a window. If \a window is the null pointer, then | - | ||||||||||||||||||||||||
| 1306 | \a pt is interpreted as relative to the window provided when instantiating this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1307 | - | |||||||||||||||||||||||||
| 1308 | Simulates that the user pressed the touch screen or pad with the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1309 | */ | - | ||||||||||||||||||||||||
| 1310 | - | |||||||||||||||||||||||||
| 1311 | /*! | - | ||||||||||||||||||||||||
| 1312 | \fn QTouchEventSequence &QTest::QTouchEventSequence::press(int touchId, const QPoint &pt, QWidget *widget) | - | ||||||||||||||||||||||||
| 1313 | - | |||||||||||||||||||||||||
| 1314 | Adds a press event for touchpoint \a touchId at position \a pt to this sequence and returns | - | ||||||||||||||||||||||||
| 1315 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1316 | - | |||||||||||||||||||||||||
| 1317 | The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then | - | ||||||||||||||||||||||||
| 1318 | \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1319 | - | |||||||||||||||||||||||||
| 1320 | Simulates that the user pressed the touch screen or pad with the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1321 | */ | - | ||||||||||||||||||||||||
| 1322 | - | |||||||||||||||||||||||||
| 1323 | /*! | - | ||||||||||||||||||||||||
| 1324 | \fn QTouchEventSequence &QTest::QTouchEventSequence::move(int touchId, const QPoint &pt, QWindow *window) | - | ||||||||||||||||||||||||
| 1325 | \since 5.0 | - | ||||||||||||||||||||||||
| 1326 | - | |||||||||||||||||||||||||
| 1327 | Adds a move event for touchpoint \a touchId at position \a pt to this sequence and returns | - | ||||||||||||||||||||||||
| 1328 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1329 | - | |||||||||||||||||||||||||
| 1330 | The position \a pt is interpreted as relative to \a window. If \a window is the null pointer, then | - | ||||||||||||||||||||||||
| 1331 | \a pt is interpreted as relative to the window provided when instantiating this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1332 | - | |||||||||||||||||||||||||
| 1333 | Simulates that the user moved the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1334 | */ | - | ||||||||||||||||||||||||
| 1335 | - | |||||||||||||||||||||||||
| 1336 | /*! | - | ||||||||||||||||||||||||
| 1337 | \fn QTouchEventSequence &QTest::QTouchEventSequence::move(int touchId, const QPoint &pt, QWidget *widget) | - | ||||||||||||||||||||||||
| 1338 | - | |||||||||||||||||||||||||
| 1339 | Adds a move event for touchpoint \a touchId at position \a pt to this sequence and returns | - | ||||||||||||||||||||||||
| 1340 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1341 | - | |||||||||||||||||||||||||
| 1342 | The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then | - | ||||||||||||||||||||||||
| 1343 | \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1344 | - | |||||||||||||||||||||||||
| 1345 | Simulates that the user moved the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1346 | */ | - | ||||||||||||||||||||||||
| 1347 | - | |||||||||||||||||||||||||
| 1348 | /*! | - | ||||||||||||||||||||||||
| 1349 | \fn QTouchEventSequence &QTest::QTouchEventSequence::release(int touchId, const QPoint &pt, QWindow *window) | - | ||||||||||||||||||||||||
| 1350 | \since 5.0 | - | ||||||||||||||||||||||||
| 1351 | - | |||||||||||||||||||||||||
| 1352 | Adds a release event for touchpoint \a touchId at position \a pt to this sequence and returns | - | ||||||||||||||||||||||||
| 1353 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1354 | - | |||||||||||||||||||||||||
| 1355 | The position \a pt is interpreted as relative to \a window. If \a window is the null pointer, then | - | ||||||||||||||||||||||||
| 1356 | \a pt is interpreted as relative to the window provided when instantiating this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1357 | - | |||||||||||||||||||||||||
| 1358 | Simulates that the user lifted the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1359 | */ | - | ||||||||||||||||||||||||
| 1360 | - | |||||||||||||||||||||||||
| 1361 | /*! | - | ||||||||||||||||||||||||
| 1362 | \fn QTouchEventSequence &QTest::QTouchEventSequence::release(int touchId, const QPoint &pt, QWidget *widget) | - | ||||||||||||||||||||||||
| 1363 | - | |||||||||||||||||||||||||
| 1364 | Adds a release event for touchpoint \a touchId at position \a pt to this sequence and returns | - | ||||||||||||||||||||||||
| 1365 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1366 | - | |||||||||||||||||||||||||
| 1367 | The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then | - | ||||||||||||||||||||||||
| 1368 | \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1369 | - | |||||||||||||||||||||||||
| 1370 | Simulates that the user lifted the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1371 | */ | - | ||||||||||||||||||||||||
| 1372 | - | |||||||||||||||||||||||||
| 1373 | /*! | - | ||||||||||||||||||||||||
| 1374 | \fn QTouchEventSequence &QTest::QTouchEventSequence::stationary(int touchId) | - | ||||||||||||||||||||||||
| 1375 | - | |||||||||||||||||||||||||
| 1376 | Adds a stationary event for touchpoint \a touchId to this sequence and returns | - | ||||||||||||||||||||||||
| 1377 | a reference to this QTouchEventSequence. | - | ||||||||||||||||||||||||
| 1378 | - | |||||||||||||||||||||||||
| 1379 | Simulates that the user did not move the finger identified by \a touchId. | - | ||||||||||||||||||||||||
| 1380 | */ | - | ||||||||||||||||||||||||
| 1381 | - | |||||||||||||||||||||||||
| 1382 | /*! | - | ||||||||||||||||||||||||
| 1383 | \fn QTouchEventSequence QTest::touchEvent(QWindow *window, QTouchDevice *device, bool autoCommit) | - | ||||||||||||||||||||||||
| 1384 | \since 5.0 | - | ||||||||||||||||||||||||
| 1385 | - | |||||||||||||||||||||||||
| 1386 | Creates and returns a QTouchEventSequence for the \a device to | - | ||||||||||||||||||||||||
| 1387 | simulate events for \a window. | - | ||||||||||||||||||||||||
| 1388 | - | |||||||||||||||||||||||||
| 1389 | When adding touch events to the sequence, \a window will also be used to translate | - | ||||||||||||||||||||||||
| 1390 | the position provided to screen coordinates, unless another window is provided in the | - | ||||||||||||||||||||||||
| 1391 | respective calls to press(), move() etc. | - | ||||||||||||||||||||||||
| 1392 | - | |||||||||||||||||||||||||
| 1393 | The touch events are committed to the event system when the destructor of the | - | ||||||||||||||||||||||||
| 1394 | QTouchEventSequence is called (ie when the object returned runs out of scope), unless | - | ||||||||||||||||||||||||
| 1395 | \a autoCommit is set to false. When \a autoCommit is false, commit() has to be called | - | ||||||||||||||||||||||||
| 1396 | manually. | - | ||||||||||||||||||||||||
| 1397 | */ | - | ||||||||||||||||||||||||
| 1398 | - | |||||||||||||||||||||||||
| 1399 | /*! | - | ||||||||||||||||||||||||
| 1400 | \fn QTouchEventSequence QTest::touchEvent(QWidget *widget, QTouchDevice *device, bool autoCommit) | - | ||||||||||||||||||||||||
| 1401 | - | |||||||||||||||||||||||||
| 1402 | Creates and returns a QTouchEventSequence for the \a device to | - | ||||||||||||||||||||||||
| 1403 | simulate events for \a widget. | - | ||||||||||||||||||||||||
| 1404 | - | |||||||||||||||||||||||||
| 1405 | When adding touch events to the sequence, \a widget will also be used to translate | - | ||||||||||||||||||||||||
| 1406 | the position provided to screen coordinates, unless another widget is provided in the | - | ||||||||||||||||||||||||
| 1407 | respective calls to press(), move() etc. | - | ||||||||||||||||||||||||
| 1408 | - | |||||||||||||||||||||||||
| 1409 | The touch events are committed to the event system when the destructor of the | - | ||||||||||||||||||||||||
| 1410 | QTouchEventSequence is called (ie when the object returned runs out of scope), unless | - | ||||||||||||||||||||||||
| 1411 | \a autoCommit is set to false. When \a autoCommit is false, commit() has to be called | - | ||||||||||||||||||||||||
| 1412 | manually. | - | ||||||||||||||||||||||||
| 1413 | */ | - | ||||||||||||||||||||||||
| 1414 | - | |||||||||||||||||||||||||
| 1415 | static bool installCoverageTool(const char * appname, const char * testname) | - | ||||||||||||||||||||||||
| 1416 | { | - | ||||||||||||||||||||||||
| 1417 | #ifdef __COVERAGESCANNER__ | - | ||||||||||||||||||||||||
| 1418 | if (!qEnvironmentVariableIsEmpty("QT_TESTCOCOON_ACTIVE"))
| 0-695 | ||||||||||||||||||||||||
| 1419 | return false; executed 695 times by 1 test: return false;Executed by:
| 695 | ||||||||||||||||||||||||
| 1420 | // Set environment variable QT_TESTCOCOON_ACTIVE to prevent an eventual subtest from | - | ||||||||||||||||||||||||
| 1421 | // being considered as a stand-alone test regarding the coverage analysis. | - | ||||||||||||||||||||||||
| 1422 | qputenv("QT_TESTCOCOON_ACTIVE", "1"); | - | ||||||||||||||||||||||||
| 1423 | - | |||||||||||||||||||||||||
| 1424 | // Install Coverage Tool | - | ||||||||||||||||||||||||
| 1425 | __coveragescanner_install(appname); | - | ||||||||||||||||||||||||
| 1426 | __coveragescanner_testname(testname); | - | ||||||||||||||||||||||||
| 1427 | __coveragescanner_clear(); | - | ||||||||||||||||||||||||
| 1428 | return true; executed 542 times by 538 tests: return true;Executed by:
| 542 | ||||||||||||||||||||||||
| 1429 | #else | - | ||||||||||||||||||||||||
| 1430 | Q_UNUSED(appname); | - | ||||||||||||||||||||||||
| 1431 | Q_UNUSED(testname); | - | ||||||||||||||||||||||||
| 1432 | return false; | - | ||||||||||||||||||||||||
| 1433 | #endif | - | ||||||||||||||||||||||||
| 1434 | } | - | ||||||||||||||||||||||||
| 1435 | - | |||||||||||||||||||||||||
| 1436 | namespace QTest | - | ||||||||||||||||||||||||
| 1437 | { | - | ||||||||||||||||||||||||
| 1438 | static QObject *currentTestObject = 0; | - | ||||||||||||||||||||||||
| 1439 | static QString mainSourcePath; | - | ||||||||||||||||||||||||
| 1440 | - | |||||||||||||||||||||||||
| 1441 | class TestFunction { | - | ||||||||||||||||||||||||
| 1442 | public: | - | ||||||||||||||||||||||||
| 1443 | TestFunction() : function_(-1), data_(0) {} executed 17920 times by 1 test: end of blockExecuted by:
| 17920 | ||||||||||||||||||||||||
| 1444 | void set(int function, char *data) { function_ = function; data_ = data; } executed 56 times by 1 test: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 1445 | char *data() const { return data_; } executed 56 times by 1 test: return data_;Executed by:
| 56 | ||||||||||||||||||||||||
| 1446 | int function() const { return function_; } executed 56 times by 1 test: return function_;Executed by:
| 56 | ||||||||||||||||||||||||
| 1447 | ~TestFunction() { delete[] data_; } executed 17920 times by 1 test: end of blockExecuted by:
| 17920 | ||||||||||||||||||||||||
| 1448 | private: | - | ||||||||||||||||||||||||
| 1449 | int function_; | - | ||||||||||||||||||||||||
| 1450 | char *data_; | - | ||||||||||||||||||||||||
| 1451 | }; | - | ||||||||||||||||||||||||
| 1452 | /** | - | ||||||||||||||||||||||||
| 1453 | * Contains the list of test functions that was supplied | - | ||||||||||||||||||||||||
| 1454 | * on the command line, if any. Hence, if not empty, | - | ||||||||||||||||||||||||
| 1455 | * those functions should be run instead of | - | ||||||||||||||||||||||||
| 1456 | * all appearing in the test case. | - | ||||||||||||||||||||||||
| 1457 | */ | - | ||||||||||||||||||||||||
| 1458 | static TestFunction * testFuncs = 0; | - | ||||||||||||||||||||||||
| 1459 | static int testFuncCount = 0; | - | ||||||||||||||||||||||||
| 1460 | - | |||||||||||||||||||||||||
| 1461 | /** Don't leak testFuncs on exit even on error */ | - | ||||||||||||||||||||||||
| 1462 | static struct TestFuncCleanup | - | ||||||||||||||||||||||||
| 1463 | { | - | ||||||||||||||||||||||||
| 1464 | void cleanup() | - | ||||||||||||||||||||||||
| 1465 | { | - | ||||||||||||||||||||||||
| 1466 | delete[] testFuncs; | - | ||||||||||||||||||||||||
| 1467 | testFuncCount = 0; | - | ||||||||||||||||||||||||
| 1468 | testFuncs = 0; | - | ||||||||||||||||||||||||
| 1469 | } executed 597 times by 541 tests: end of blockExecuted by:
| 597 | ||||||||||||||||||||||||
| 1470 | - | |||||||||||||||||||||||||
| 1471 | ~TestFuncCleanup() { cleanup(); } executed 562 times by 541 tests: end of blockExecuted by:
| 562 | ||||||||||||||||||||||||
| 1472 | } testFuncCleaner; | - | ||||||||||||||||||||||||
| 1473 | - | |||||||||||||||||||||||||
| 1474 | static int keyDelay = -1; | - | ||||||||||||||||||||||||
| 1475 | static int mouseDelay = -1; | - | ||||||||||||||||||||||||
| 1476 | static int eventDelay = -1; | - | ||||||||||||||||||||||||
| 1477 | static int timeout = -1; | - | ||||||||||||||||||||||||
| 1478 | static bool noCrashHandler = false; | - | ||||||||||||||||||||||||
| 1479 | - | |||||||||||||||||||||||||
| 1480 | /*! \internal | - | ||||||||||||||||||||||||
| 1481 | Invoke a method of the object without generating warning if the method does not exist | - | ||||||||||||||||||||||||
| 1482 | */ | - | ||||||||||||||||||||||||
| 1483 | static void invokeMethod(QObject *obj, const char *methodName) | - | ||||||||||||||||||||||||
| 1484 | { | - | ||||||||||||||||||||||||
| 1485 | const QMetaObject *metaObject = obj->metaObject(); | - | ||||||||||||||||||||||||
| 1486 | int funcIndex = metaObject->indexOfMethod(methodName); | - | ||||||||||||||||||||||||
| 1487 | if (funcIndex >= 0) {
| 110923-166568 | ||||||||||||||||||||||||
| 1488 | QMetaMethod method = metaObject->method(funcIndex); | - | ||||||||||||||||||||||||
| 1489 | method.invoke(obj, Qt::DirectConnection); | - | ||||||||||||||||||||||||
| 1490 | } executed 110923 times by 428 tests: end of blockExecuted by:
| 110923 | ||||||||||||||||||||||||
| 1491 | } executed 277491 times by 540 tests: end of blockExecuted by:
| 277491 | ||||||||||||||||||||||||
| 1492 | - | |||||||||||||||||||||||||
| 1493 | int defaultEventDelay() | - | ||||||||||||||||||||||||
| 1494 | { | - | ||||||||||||||||||||||||
| 1495 | if (eventDelay == -1) {
| 36-72 | ||||||||||||||||||||||||
| 1496 | const QByteArray env = qgetenv("QTEST_EVENT_DELAY"); | - | ||||||||||||||||||||||||
| 1497 | if (!env.isEmpty())
| 0-72 | ||||||||||||||||||||||||
| 1498 | eventDelay = atoi(env.constData()); never executed: eventDelay = atoi(env.constData()); | 0 | ||||||||||||||||||||||||
| 1499 | else | - | ||||||||||||||||||||||||
| 1500 | eventDelay = 0; executed 72 times by 72 tests: eventDelay = 0;Executed by:
| 72 | ||||||||||||||||||||||||
| 1501 | } | - | ||||||||||||||||||||||||
| 1502 | return eventDelay; executed 108 times by 72 tests: return eventDelay;Executed by:
| 108 | ||||||||||||||||||||||||
| 1503 | } | - | ||||||||||||||||||||||||
| 1504 | - | |||||||||||||||||||||||||
| 1505 | int Q_TESTLIB_EXPORT defaultMouseDelay() | - | ||||||||||||||||||||||||
| 1506 | { | - | ||||||||||||||||||||||||
| 1507 | if (mouseDelay == -1) {
| 50-8829 | ||||||||||||||||||||||||
| 1508 | const QByteArray env = qgetenv("QTEST_MOUSEEVENT_DELAY"); | - | ||||||||||||||||||||||||
| 1509 | if (!env.isEmpty())
| 0-50 | ||||||||||||||||||||||||
| 1510 | mouseDelay = atoi(env.constData()); never executed: mouseDelay = atoi(env.constData()); | 0 | ||||||||||||||||||||||||
| 1511 | else | - | ||||||||||||||||||||||||
| 1512 | mouseDelay = defaultEventDelay(); executed 50 times by 50 tests: mouseDelay = defaultEventDelay();Executed by:
| 50 | ||||||||||||||||||||||||
| 1513 | } | - | ||||||||||||||||||||||||
| 1514 | return mouseDelay; executed 8879 times by 50 tests: return mouseDelay;Executed by:
| 8879 | ||||||||||||||||||||||||
| 1515 | } | - | ||||||||||||||||||||||||
| 1516 | - | |||||||||||||||||||||||||
| 1517 | int Q_TESTLIB_EXPORT defaultKeyDelay() | - | ||||||||||||||||||||||||
| 1518 | { | - | ||||||||||||||||||||||||
| 1519 | if (keyDelay == -1) {
| 58-14498 | ||||||||||||||||||||||||
| 1520 | const QByteArray env = qgetenv("QTEST_KEYEVENT_DELAY"); | - | ||||||||||||||||||||||||
| 1521 | if (!env.isEmpty())
| 0-58 | ||||||||||||||||||||||||
| 1522 | keyDelay = atoi(env.constData()); never executed: keyDelay = atoi(env.constData()); | 0 | ||||||||||||||||||||||||
| 1523 | else | - | ||||||||||||||||||||||||
| 1524 | keyDelay = defaultEventDelay(); executed 58 times by 58 tests: keyDelay = defaultEventDelay();Executed by:
| 58 | ||||||||||||||||||||||||
| 1525 | } | - | ||||||||||||||||||||||||
| 1526 | return keyDelay; executed 14556 times by 58 tests: return keyDelay;Executed by:
| 14556 | ||||||||||||||||||||||||
| 1527 | } | - | ||||||||||||||||||||||||
| 1528 | - | |||||||||||||||||||||||||
| 1529 | static int defaultTimeout() | - | ||||||||||||||||||||||||
| 1530 | { | - | ||||||||||||||||||||||||
| 1531 | if (timeout == -1) {
| 1122-129359 | ||||||||||||||||||||||||
| 1532 | bool ok = false; | - | ||||||||||||||||||||||||
| 1533 | timeout = qEnvironmentVariableIntValue("QTEST_FUNCTION_TIMEOUT", &ok); | - | ||||||||||||||||||||||||
| 1534 | - | |||||||||||||||||||||||||
| 1535 | if (!ok || timeout <= 0)
| 0-1122 | ||||||||||||||||||||||||
| 1536 | timeout = 5*60*1000; executed 1122 times by 534 tests: timeout = 5*60*1000;Executed by:
| 1122 | ||||||||||||||||||||||||
| 1537 | } executed 1122 times by 534 tests: end of blockExecuted by:
| 1122 | ||||||||||||||||||||||||
| 1538 | return timeout; executed 130481 times by 535 tests: return timeout;Executed by:
| 130481 | ||||||||||||||||||||||||
| 1539 | } | - | ||||||||||||||||||||||||
| 1540 | - | |||||||||||||||||||||||||
| 1541 | static bool isValidSlot(const QMetaMethod &sl) | - | ||||||||||||||||||||||||
| 1542 | { | - | ||||||||||||||||||||||||
| 1543 | if (sl.access() != QMetaMethod::Private || sl.parameterCount() != 0
| 1123-19343 | ||||||||||||||||||||||||
| 1544 | || sl.returnType() != QMetaType::Void || sl.methodType() != QMetaMethod::Slot)
| 0-18220 | ||||||||||||||||||||||||
| 1545 | return false; executed 6506 times by 536 tests: return false;Executed by:
| 6506 | ||||||||||||||||||||||||
| 1546 | QByteArray name = sl.name(); | - | ||||||||||||||||||||||||
| 1547 | if (name.isEmpty())
| 0-18220 | ||||||||||||||||||||||||
| 1548 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 1549 | if (name.endsWith("_data"))
| 4685-13535 | ||||||||||||||||||||||||
| 1550 | return false; executed 4685 times by 361 tests: return false;Executed by:
| 4685 | ||||||||||||||||||||||||
| 1551 | if (name == "initTestCase" || name == "cleanupTestCase"
| 90-13392 | ||||||||||||||||||||||||
| 1552 | || name == "cleanup" || name == "init")
| 83-13207 | ||||||||||||||||||||||||
| 1553 | return false; executed 411 times by 136 tests: return false;Executed by:
| 411 | ||||||||||||||||||||||||
| 1554 | return true; executed 13124 times by 535 tests: return true;Executed by:
| 13124 | ||||||||||||||||||||||||
| 1555 | } | - | ||||||||||||||||||||||||
| 1556 | - | |||||||||||||||||||||||||
| 1557 | Q_TESTLIB_EXPORT bool printAvailableFunctions = false; | - | ||||||||||||||||||||||||
| 1558 | Q_TESTLIB_EXPORT QStringList testFunctions; | - | ||||||||||||||||||||||||
| 1559 | Q_TESTLIB_EXPORT QStringList testTags; | - | ||||||||||||||||||||||||
| 1560 | - | |||||||||||||||||||||||||
| 1561 | static void qPrintTestSlots(FILE *stream, const char *filter = 0) | - | ||||||||||||||||||||||||
| 1562 | { | - | ||||||||||||||||||||||||
| 1563 | for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
| 0 | ||||||||||||||||||||||||
| 1564 | QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); | - | ||||||||||||||||||||||||
| 1565 | if (isValidSlot(sl)) {
| 0 | ||||||||||||||||||||||||
| 1566 | const QByteArray signature = sl.methodSignature(); | - | ||||||||||||||||||||||||
| 1567 | if (!filter || QString::fromLatin1(signature).contains(QLatin1String(filter), Qt::CaseInsensitive))
| 0 | ||||||||||||||||||||||||
| 1568 | fprintf(stream, "%s\n", signature.constData()); never executed: fprintf(stream, "%s\n", signature.constData()); | 0 | ||||||||||||||||||||||||
| 1569 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1570 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1571 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1572 | - | |||||||||||||||||||||||||
| 1573 | static void qPrintDataTags(FILE *stream) | - | ||||||||||||||||||||||||
| 1574 | { | - | ||||||||||||||||||||||||
| 1575 | // Avoid invoking the actual test functions, and also avoid printing irrelevant output: | - | ||||||||||||||||||||||||
| 1576 | QTestLog::setPrintAvailableTagsMode(); | - | ||||||||||||||||||||||||
| 1577 | - | |||||||||||||||||||||||||
| 1578 | // Get global data tags: | - | ||||||||||||||||||||||||
| 1579 | QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
| 1580 | invokeMethod(QTest::currentTestObject, "initTestCase_data()"); | - | ||||||||||||||||||||||||
| 1581 | const QTestTable *gTable = QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
| 1582 | - | |||||||||||||||||||||||||
| 1583 | const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject(); | - | ||||||||||||||||||||||||
| 1584 | - | |||||||||||||||||||||||||
| 1585 | // Process test functions: | - | ||||||||||||||||||||||||
| 1586 | for (int i = 0; i < currTestMetaObj->methodCount(); ++i) {
| 4-44 | ||||||||||||||||||||||||
| 1587 | QMetaMethod tf = currTestMetaObj->method(i); | - | ||||||||||||||||||||||||
| 1588 | - | |||||||||||||||||||||||||
| 1589 | if (isValidSlot(tf)) {
| 12-32 | ||||||||||||||||||||||||
| 1590 | - | |||||||||||||||||||||||||
| 1591 | // Retrieve local tags: | - | ||||||||||||||||||||||||
| 1592 | QStringList localTags; | - | ||||||||||||||||||||||||
| 1593 | QTestTable table; | - | ||||||||||||||||||||||||
| 1594 | char *slot = qstrdup(tf.methodSignature().constData()); | - | ||||||||||||||||||||||||
| 1595 | slot[strlen(slot) - 2] = '\0'; | - | ||||||||||||||||||||||||
| 1596 | QByteArray member; | - | ||||||||||||||||||||||||
| 1597 | member.resize(qstrlen(slot) + qstrlen("_data()") + 1); | - | ||||||||||||||||||||||||
| 1598 | qsnprintf(member.data(), member.size(), "%s_data()", slot); | - | ||||||||||||||||||||||||
| 1599 | invokeMethod(QTest::currentTestObject, member.constData()); | - | ||||||||||||||||||||||||
| 1600 | const int dataCount = table.dataCount(); | - | ||||||||||||||||||||||||
| 1601 | localTags.reserve(dataCount); | - | ||||||||||||||||||||||||
| 1602 | for (int j = 0; j < dataCount; ++j)
| 12-20 | ||||||||||||||||||||||||
| 1603 | localTags << QLatin1String(table.testData(j)->dataTag()); executed 20 times by 1 test: localTags << QLatin1String(table.testData(j)->dataTag());Executed by:
| 20 | ||||||||||||||||||||||||
| 1604 | - | |||||||||||||||||||||||||
| 1605 | // Print all tag combinations: | - | ||||||||||||||||||||||||
| 1606 | if (gTable->dataCount() == 0) {
| 6 | ||||||||||||||||||||||||
| 1607 | if (localTags.count() == 0) {
| 2-4 | ||||||||||||||||||||||||
| 1608 | // No tags at all, so just print the test function: | - | ||||||||||||||||||||||||
| 1609 | fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot); | - | ||||||||||||||||||||||||
| 1610 | } else { executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1611 | // Only local tags, so print each of them: | - | ||||||||||||||||||||||||
| 1612 | for (int k = 0; k < localTags.size(); ++k)
| 4-10 | ||||||||||||||||||||||||
| 1613 | fprintf( executed 10 times by 1 test: fprintf( stream, "%s %s %s\n", currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());Executed by:
| 10 | ||||||||||||||||||||||||
| 1614 | stream, "%s %s %s\n", executed 10 times by 1 test: fprintf( stream, "%s %s %s\n", currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());Executed by:
| 10 | ||||||||||||||||||||||||
| 1615 | currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data()); executed 10 times by 1 test: fprintf( stream, "%s %s %s\n", currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data());Executed by:
| 10 | ||||||||||||||||||||||||
| 1616 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1617 | } else { | - | ||||||||||||||||||||||||
| 1618 | for (int j = 0; j < gTable->dataCount(); ++j) {
| 6-12 | ||||||||||||||||||||||||
| 1619 | if (localTags.count() == 0) {
| 4-8 | ||||||||||||||||||||||||
| 1620 | // Only global tags, so print the current one: | - | ||||||||||||||||||||||||
| 1621 | fprintf( | - | ||||||||||||||||||||||||
| 1622 | stream, "%s %s __global__ %s\n", | - | ||||||||||||||||||||||||
| 1623 | currTestMetaObj->className(), slot, gTable->testData(j)->dataTag()); | - | ||||||||||||||||||||||||
| 1624 | } else { executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1625 | // Local and global tags, so print each of the local ones and | - | ||||||||||||||||||||||||
| 1626 | // the current global one: | - | ||||||||||||||||||||||||
| 1627 | for (int k = 0; k < localTags.size(); ++k)
| 8-20 | ||||||||||||||||||||||||
| 1628 | fprintf( executed 20 times by 1 test: fprintf( stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());Executed by:
| 20 | ||||||||||||||||||||||||
| 1629 | stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, executed 20 times by 1 test: fprintf( stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());Executed by:
| 20 | ||||||||||||||||||||||||
| 1630 | localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag()); executed 20 times by 1 test: fprintf( stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag());Executed by:
| 20 | ||||||||||||||||||||||||
| 1631 | } executed 8 times by 1 test: end of blockExecuted by:
| 8 | ||||||||||||||||||||||||
| 1632 | } | - | ||||||||||||||||||||||||
| 1633 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||||||||||||||
| 1634 | - | |||||||||||||||||||||||||
| 1635 | delete[] slot; | - | ||||||||||||||||||||||||
| 1636 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||
| 1637 | } executed 44 times by 1 test: end of blockExecuted by:
| 44 | ||||||||||||||||||||||||
| 1638 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 1639 | - | |||||||||||||||||||||||||
| 1640 | static int qToInt(char *str) | - | ||||||||||||||||||||||||
| 1641 | { | - | ||||||||||||||||||||||||
| 1642 | char *pEnd; | - | ||||||||||||||||||||||||
| 1643 | int l = (int)strtol(str, &pEnd, 10); | - | ||||||||||||||||||||||||
| 1644 | if (*pEnd != 0) {
| 0-17 | ||||||||||||||||||||||||
| 1645 | fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); | - | ||||||||||||||||||||||||
| 1646 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1647 | } | - | ||||||||||||||||||||||||
| 1648 | return l; executed 17 times by 1 test: return l;Executed by:
| 17 | ||||||||||||||||||||||||
| 1649 | } | - | ||||||||||||||||||||||||
| 1650 | - | |||||||||||||||||||||||||
| 1651 | Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) | - | ||||||||||||||||||||||||
| 1652 | { | - | ||||||||||||||||||||||||
| 1653 | QTestLog::LogMode logFormat = QTestLog::Plain; | - | ||||||||||||||||||||||||
| 1654 | const char *logFilename = 0; | - | ||||||||||||||||||||||||
| 1655 | - | |||||||||||||||||||||||||
| 1656 | #if defined(Q_OS_MAC) && defined(HAVE_XCTEST) | - | ||||||||||||||||||||||||
| 1657 | if (QXcodeTestLogger::canLogTestProgress()) | - | ||||||||||||||||||||||||
| 1658 | logFormat = QTestLog::XCTest; | - | ||||||||||||||||||||||||
| 1659 | #endif | - | ||||||||||||||||||||||||
| 1660 | - | |||||||||||||||||||||||||
| 1661 | const char *testOptions = | - | ||||||||||||||||||||||||
| 1662 | " New-style logging options:\n" | - | ||||||||||||||||||||||||
| 1663 | " -o filename,format : Output results to file in the specified format\n" | - | ||||||||||||||||||||||||
| 1664 | " Use - to output to stdout\n" | - | ||||||||||||||||||||||||
| 1665 | " Valid formats are:\n" | - | ||||||||||||||||||||||||
| 1666 | " txt : Plain text\n" | - | ||||||||||||||||||||||||
| 1667 | " csv : CSV format (suitable for benchmarks)\n" | - | ||||||||||||||||||||||||
| 1668 | " xunitxml : XML XUnit document\n" | - | ||||||||||||||||||||||||
| 1669 | " xml : XML document\n" | - | ||||||||||||||||||||||||
| 1670 | " lightxml : A stream of XML tags\n" | - | ||||||||||||||||||||||||
| 1671 | "\n" | - | ||||||||||||||||||||||||
| 1672 | " *** Multiple loggers can be specified, but at most one can log to stdout.\n" | - | ||||||||||||||||||||||||
| 1673 | "\n" | - | ||||||||||||||||||||||||
| 1674 | " Old-style logging options:\n" | - | ||||||||||||||||||||||||
| 1675 | " -o filename : Write the output into file\n" | - | ||||||||||||||||||||||||
| 1676 | " -txt : Output results in Plain Text\n" | - | ||||||||||||||||||||||||
| 1677 | " -csv : Output results in a CSV format (suitable for benchmarks)\n" | - | ||||||||||||||||||||||||
| 1678 | " -xunitxml : Output results as XML XUnit document\n" | - | ||||||||||||||||||||||||
| 1679 | " -xml : Output results as XML document\n" | - | ||||||||||||||||||||||||
| 1680 | " -lightxml : Output results as stream of XML tags\n" | - | ||||||||||||||||||||||||
| 1681 | "\n" | - | ||||||||||||||||||||||||
| 1682 | " *** If no output file is specified, stdout is assumed.\n" | - | ||||||||||||||||||||||||
| 1683 | " *** If no output format is specified, -txt is assumed.\n" | - | ||||||||||||||||||||||||
| 1684 | "\n" | - | ||||||||||||||||||||||||
| 1685 | " Test log detail options:\n" | - | ||||||||||||||||||||||||
| 1686 | " -silent : Log failures and fatal errors only\n" | - | ||||||||||||||||||||||||
| 1687 | " -v1 : Log the start of each testfunction\n" | - | ||||||||||||||||||||||||
| 1688 | " -v2 : Log each QVERIFY/QCOMPARE/QTEST (implies -v1)\n" | - | ||||||||||||||||||||||||
| 1689 | " -vs : Log every signal emission and resulting slot invocations\n" | - | ||||||||||||||||||||||||
| 1690 | "\n" | - | ||||||||||||||||||||||||
| 1691 | " *** The -silent and -v1 options only affect plain text output.\n" | - | ||||||||||||||||||||||||
| 1692 | "\n" | - | ||||||||||||||||||||||||
| 1693 | " Testing options:\n" | - | ||||||||||||||||||||||||
| 1694 | " -functions : Returns a list of current testfunctions\n" | - | ||||||||||||||||||||||||
| 1695 | " -datatags : Returns a list of current data tags.\n" | - | ||||||||||||||||||||||||
| 1696 | " A global data tag is preceded by ' __global__ '.\n" | - | ||||||||||||||||||||||||
| 1697 | " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n" | - | ||||||||||||||||||||||||
| 1698 | " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n" | - | ||||||||||||||||||||||||
| 1699 | " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" | - | ||||||||||||||||||||||||
| 1700 | " -maxwarnings n : Sets the maximum amount of messages to output.\n" | - | ||||||||||||||||||||||||
| 1701 | " 0 means unlimited, default: 2000\n" | - | ||||||||||||||||||||||||
| 1702 | " -nocrashhandler : Disables the crash handler. Useful for debugging crashes.\n" | - | ||||||||||||||||||||||||
| 1703 | "\n" | - | ||||||||||||||||||||||||
| 1704 | " Benchmarking options:\n" | - | ||||||||||||||||||||||||
| 1705 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
| 1706 | " -callgrind : Use callgrind to time benchmarks\n" | - | ||||||||||||||||||||||||
| 1707 | #endif | - | ||||||||||||||||||||||||
| 1708 | #ifdef QTESTLIB_USE_PERF_EVENTS | - | ||||||||||||||||||||||||
| 1709 | " -perf : Use Linux perf events to time benchmarks\n" | - | ||||||||||||||||||||||||
| 1710 | " -perfcounter name : Use the counter named 'name'\n" | - | ||||||||||||||||||||||||
| 1711 | " -perfcounterlist : Lists the counters available\n" | - | ||||||||||||||||||||||||
| 1712 | #endif | - | ||||||||||||||||||||||||
| 1713 | #ifdef HAVE_TICK_COUNTER | - | ||||||||||||||||||||||||
| 1714 | " -tickcounter : Use CPU tick counters to time benchmarks\n" | - | ||||||||||||||||||||||||
| 1715 | #endif | - | ||||||||||||||||||||||||
| 1716 | " -eventcounter : Counts events received during benchmarks\n" | - | ||||||||||||||||||||||||
| 1717 | " -minimumvalue n : Sets the minimum acceptable measurement value\n" | - | ||||||||||||||||||||||||
| 1718 | " -minimumtotal n : Sets the minimum acceptable total for repeated executions of a test function\n" | - | ||||||||||||||||||||||||
| 1719 | " -iterations n : Sets the number of accumulation iterations.\n" | - | ||||||||||||||||||||||||
| 1720 | " -median n : Sets the number of median iterations.\n" | - | ||||||||||||||||||||||||
| 1721 | " -vb : Print out verbose benchmarking information.\n"; | - | ||||||||||||||||||||||||
| 1722 | - | |||||||||||||||||||||||||
| 1723 | for (int i = 1; i < argc; ++i) {
| 695-1184 | ||||||||||||||||||||||||
| 1724 | if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0
| 0-1184 | ||||||||||||||||||||||||
| 1725 | || strcmp(argv[i], "/?") == 0) {
| 0-1184 | ||||||||||||||||||||||||
| 1726 | printf(" Usage: %s [options] [testfunction[:testdata]]...\n" | - | ||||||||||||||||||||||||
| 1727 | " By default, all testfunctions will be run.\n\n" | - | ||||||||||||||||||||||||
| 1728 | "%s", argv[0], testOptions); | - | ||||||||||||||||||||||||
| 1729 | - | |||||||||||||||||||||||||
| 1730 | if (qml) {
| 0 | ||||||||||||||||||||||||
| 1731 | printf ("\n" | - | ||||||||||||||||||||||||
| 1732 | " QmlTest options:\n" | - | ||||||||||||||||||||||||
| 1733 | " -import dir : Specify an import directory.\n" | - | ||||||||||||||||||||||||
| 1734 | " -plugins dir : Specify a directory where to search for plugins.\n" | - | ||||||||||||||||||||||||
| 1735 | " -input dir/file : Specify the root directory for test cases or a single test case file.\n" | - | ||||||||||||||||||||||||
| 1736 | " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" | - | ||||||||||||||||||||||||
| 1737 | " -translation file : Specify the translation file.\n" | - | ||||||||||||||||||||||||
| 1738 | ); | - | ||||||||||||||||||||||||
| 1739 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1740 | - | |||||||||||||||||||||||||
| 1741 | printf("\n" | - | ||||||||||||||||||||||||
| 1742 | " -help : This help\n"); | - | ||||||||||||||||||||||||
| 1743 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||||||||
| 1744 | } else if (strcmp(argv[i], "-functions") == 0) {
| 0-1184 | ||||||||||||||||||||||||
| 1745 | if (qml) {
| 0 | ||||||||||||||||||||||||
| 1746 | QTest::printAvailableFunctions = true; | - | ||||||||||||||||||||||||
| 1747 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1748 | qPrintTestSlots(stdout); | - | ||||||||||||||||||||||||
| 1749 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||||||||
| 1750 | } | - | ||||||||||||||||||||||||
| 1751 | } else if (strcmp(argv[i], "-datatags") == 0) {
| 4-1180 | ||||||||||||||||||||||||
| 1752 | if (!qml) {
| 0-4 | ||||||||||||||||||||||||
| 1753 | qPrintDataTags(stdout); | - | ||||||||||||||||||||||||
| 1754 | exit(0); executed 4 times by 1 test: exit(0);Executed by:
| 4 | ||||||||||||||||||||||||
| 1755 | } | - | ||||||||||||||||||||||||
| 1756 | } else if (strcmp(argv[i], "-txt") == 0) { never executed: end of block
| 0-1180 | ||||||||||||||||||||||||
| 1757 | logFormat = QTestLog::Plain; | - | ||||||||||||||||||||||||
| 1758 | } else if (strcmp(argv[i], "-csv") == 0) { never executed: end of block
| 0-1176 | ||||||||||||||||||||||||
| 1759 | logFormat = QTestLog::CSV; | - | ||||||||||||||||||||||||
| 1760 | } else if (strcmp(argv[i], "-xunitxml") == 0) { executed 4 times by 1 test: end of blockExecuted by:
| 4-1114 | ||||||||||||||||||||||||
| 1761 | logFormat = QTestLog::XunitXML; | - | ||||||||||||||||||||||||
| 1762 | } else if (strcmp(argv[i], "-xml") == 0) { executed 62 times by 1 test: end of blockExecuted by:
| 62-1052 | ||||||||||||||||||||||||
| 1763 | logFormat = QTestLog::XML; | - | ||||||||||||||||||||||||
| 1764 | } else if (strcmp(argv[i], "-lightxml") == 0) { executed 62 times by 1 test: end of blockExecuted by:
| 62-990 | ||||||||||||||||||||||||
| 1765 | logFormat = QTestLog::LightXML; | - | ||||||||||||||||||||||||
| 1766 | } else if (strcmp(argv[i], "-silent") == 0) { executed 62 times by 1 test: end of blockExecuted by:
| 2-988 | ||||||||||||||||||||||||
| 1767 | QTestLog::setVerboseLevel(-1); | - | ||||||||||||||||||||||||
| 1768 | } else if (strcmp(argv[i], "-v1") == 0) { executed 2 times by 1 test: end of blockExecuted by:
| 2-967 | ||||||||||||||||||||||||
| 1769 | QTestLog::setVerboseLevel(1); | - | ||||||||||||||||||||||||
| 1770 | } else if (strcmp(argv[i], "-v2") == 0) { executed 21 times by 1 test: end of blockExecuted by:
| 21-925 | ||||||||||||||||||||||||
| 1771 | QTestLog::setVerboseLevel(2); | - | ||||||||||||||||||||||||
| 1772 | } else if (strcmp(argv[i], "-vs") == 0) { executed 42 times by 1 test: end of blockExecuted by:
| 0-925 | ||||||||||||||||||||||||
| 1773 | QSignalDumper::startDump(); | - | ||||||||||||||||||||||||
| 1774 | } else if (strcmp(argv[i], "-o") == 0) { never executed: end of block
| 0-783 | ||||||||||||||||||||||||
| 1775 | if (i + 1 >= argc) {
| 0-783 | ||||||||||||||||||||||||
| 1776 | fprintf(stderr, "-o needs an extra parameter specifying the filename and optional format\n"); | - | ||||||||||||||||||||||||
| 1777 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1778 | } | - | ||||||||||||||||||||||||
| 1779 | ++i; | - | ||||||||||||||||||||||||
| 1780 | // Do we have the old or new style -o option? | - | ||||||||||||||||||||||||
| 1781 | char *filename = new char[strlen(argv[i])+1]; | - | ||||||||||||||||||||||||
| 1782 | char *format = new char[strlen(argv[i])+1]; | - | ||||||||||||||||||||||||
| 1783 | if (sscanf(argv[i], "%[^,],%s", filename, format) == 1) {
| 125-658 | ||||||||||||||||||||||||
| 1784 | // Old-style | - | ||||||||||||||||||||||||
| 1785 | logFilename = argv[i]; | - | ||||||||||||||||||||||||
| 1786 | } else { executed 125 times by 1 test: end of blockExecuted by:
| 125 | ||||||||||||||||||||||||
| 1787 | // New-style | - | ||||||||||||||||||||||||
| 1788 | if (strcmp(format, "txt") == 0)
| 256-402 | ||||||||||||||||||||||||
| 1789 | logFormat = QTestLog::Plain; executed 256 times by 1 test: logFormat = QTestLog::Plain;Executed by:
| 256 | ||||||||||||||||||||||||
| 1790 | else if (strcmp(format, "csv") == 0)
| 4-398 | ||||||||||||||||||||||||
| 1791 | logFormat = QTestLog::CSV; executed 4 times by 1 test: logFormat = QTestLog::CSV;Executed by:
| 4 | ||||||||||||||||||||||||
| 1792 | else if (strcmp(format, "lightxml") == 0)
| 123-275 | ||||||||||||||||||||||||
| 1793 | logFormat = QTestLog::LightXML; executed 123 times by 1 test: logFormat = QTestLog::LightXML;Executed by:
| 123 | ||||||||||||||||||||||||
| 1794 | else if (strcmp(format, "xml") == 0)
| 122-153 | ||||||||||||||||||||||||
| 1795 | logFormat = QTestLog::XML; executed 122 times by 1 test: logFormat = QTestLog::XML;Executed by:
| 122 | ||||||||||||||||||||||||
| 1796 | else if (strcmp(format, "xunitxml") == 0)
| 0-153 | ||||||||||||||||||||||||
| 1797 | logFormat = QTestLog::XunitXML; executed 153 times by 1 test: logFormat = QTestLog::XunitXML;Executed by:
| 153 | ||||||||||||||||||||||||
| 1798 | else { | - | ||||||||||||||||||||||||
| 1799 | fprintf(stderr, "output format must be one of txt, csv, lightxml, xml or xunitxml\n"); | - | ||||||||||||||||||||||||
| 1800 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1801 | } | - | ||||||||||||||||||||||||
| 1802 | if (strcmp(filename, "-") == 0 && QTestLog::loggerUsingStdout()) {
| 0-396 | ||||||||||||||||||||||||
| 1803 | fprintf(stderr, "only one logger can log to stdout\n"); | - | ||||||||||||||||||||||||
| 1804 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1805 | } | - | ||||||||||||||||||||||||
| 1806 | QTestLog::addLogger(logFormat, filename); | - | ||||||||||||||||||||||||
| 1807 | } executed 658 times by 1 test: end of blockExecuted by:
| 658 | ||||||||||||||||||||||||
| 1808 | delete [] filename; | - | ||||||||||||||||||||||||
| 1809 | delete [] format; | - | ||||||||||||||||||||||||
| 1810 | } else if (strcmp(argv[i], "-eventdelay") == 0) { executed 783 times by 1 test: end of blockExecuted by:
| 0-783 | ||||||||||||||||||||||||
| 1811 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1812 | fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); | - | ||||||||||||||||||||||||
| 1813 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1814 | } else { | - | ||||||||||||||||||||||||
| 1815 | QTest::eventDelay = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1816 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1817 | } else if (strcmp(argv[i], "-keydelay") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1818 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1819 | fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); | - | ||||||||||||||||||||||||
| 1820 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1821 | } else { | - | ||||||||||||||||||||||||
| 1822 | QTest::keyDelay = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1823 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1824 | } else if (strcmp(argv[i], "-mousedelay") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1825 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1826 | fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); | - | ||||||||||||||||||||||||
| 1827 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1828 | } else { | - | ||||||||||||||||||||||||
| 1829 | QTest::mouseDelay = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1830 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1831 | } else if (strcmp(argv[i], "-maxwarnings") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1832 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1833 | fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); | - | ||||||||||||||||||||||||
| 1834 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1835 | } else { | - | ||||||||||||||||||||||||
| 1836 | QTestLog::setMaxWarnings(qToInt(argv[++i])); | - | ||||||||||||||||||||||||
| 1837 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1838 | } else if (strcmp(argv[i], "-nocrashhandler") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1839 | QTest::noCrashHandler = true; | - | ||||||||||||||||||||||||
| 1840 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
| 1841 | } else if (strcmp(argv[i], "-callgrind") == 0) { never executed: end of block
| 0-142 | ||||||||||||||||||||||||
| 1842 | if (QBenchmarkValgrindUtils::haveValgrind())
| 0 | ||||||||||||||||||||||||
| 1843 | if (QFileInfo(QDir::currentPath()).isWritable()) {
| 0 | ||||||||||||||||||||||||
| 1844 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); | - | ||||||||||||||||||||||||
| 1845 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1846 | fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); | - | ||||||||||||||||||||||||
| 1847 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1848 | else { | - | ||||||||||||||||||||||||
| 1849 | fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " | - | ||||||||||||||||||||||||
| 1850 | "Using the walltime measurer.\n"); | - | ||||||||||||||||||||||||
| 1851 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1852 | } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option
| 0-142 | ||||||||||||||||||||||||
| 1853 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindChildProcess); | - | ||||||||||||||||||||||||
| 1854 | QBenchmarkGlobalData::current->callgrindOutFileBase = | - | ||||||||||||||||||||||||
| 1855 | QBenchmarkValgrindUtils::outFileBase(); | - | ||||||||||||||||||||||||
| 1856 | #endif | - | ||||||||||||||||||||||||
| 1857 | #ifdef QTESTLIB_USE_PERF_EVENTS | - | ||||||||||||||||||||||||
| 1858 | } else if (strcmp(argv[i], "-perf") == 0) { never executed: end of block
| 0-142 | ||||||||||||||||||||||||
| 1859 | if (QBenchmarkPerfEventsMeasurer::isAvailable()) {
| 0 | ||||||||||||||||||||||||
| 1860 | // perf available | - | ||||||||||||||||||||||||
| 1861 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::PerfCounter); | - | ||||||||||||||||||||||||
| 1862 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1863 | fprintf(stderr, "WARNING: Linux perf events not available. Using the walltime measurer.\n"); | - | ||||||||||||||||||||||||
| 1864 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1865 | } else if (strcmp(argv[i], "-perfcounter") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1866 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1867 | fprintf(stderr, "-perfcounter needs an extra parameter with the name of the counter\n"); | - | ||||||||||||||||||||||||
| 1868 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1869 | } else { | - | ||||||||||||||||||||||||
| 1870 | QBenchmarkPerfEventsMeasurer::setCounter(argv[++i]); | - | ||||||||||||||||||||||||
| 1871 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1872 | } else if (strcmp(argv[i], "-perfcounterlist") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1873 | QBenchmarkPerfEventsMeasurer::listCounters(); | - | ||||||||||||||||||||||||
| 1874 | exit(0); never executed: exit(0); | 0 | ||||||||||||||||||||||||
| 1875 | #endif | - | ||||||||||||||||||||||||
| 1876 | #ifdef HAVE_TICK_COUNTER | - | ||||||||||||||||||||||||
| 1877 | } else if (strcmp(argv[i], "-tickcounter") == 0) {
| 0-142 | ||||||||||||||||||||||||
| 1878 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::TickCounter); | - | ||||||||||||||||||||||||
| 1879 | #endif | - | ||||||||||||||||||||||||
| 1880 | } else if (strcmp(argv[i], "-eventcounter") == 0) { never executed: end of block
| 0-73 | ||||||||||||||||||||||||
| 1881 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::EventCounter); | - | ||||||||||||||||||||||||
| 1882 | } else if (strcmp(argv[i], "-minimumvalue") == 0) { executed 69 times by 1 test: end of blockExecuted by:
| 2-71 | ||||||||||||||||||||||||
| 1883 | if (i + 1 >= argc) {
| 0-2 | ||||||||||||||||||||||||
| 1884 | fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); | - | ||||||||||||||||||||||||
| 1885 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1886 | } else { | - | ||||||||||||||||||||||||
| 1887 | QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1888 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 1889 | } else if (strcmp(argv[i], "-minimumtotal") == 0) {
| 0-71 | ||||||||||||||||||||||||
| 1890 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1891 | fprintf(stderr, "-minimumtotal needs an extra parameter to indicate the minimum total measurement\n"); | - | ||||||||||||||||||||||||
| 1892 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1893 | } else { | - | ||||||||||||||||||||||||
| 1894 | QBenchmarkGlobalData::current->minimumTotal = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1895 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1896 | } else if (strcmp(argv[i], "-iterations") == 0) {
| 15-56 | ||||||||||||||||||||||||
| 1897 | if (i + 1 >= argc) {
| 0-15 | ||||||||||||||||||||||||
| 1898 | fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); | - | ||||||||||||||||||||||||
| 1899 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1900 | } else { | - | ||||||||||||||||||||||||
| 1901 | QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1902 | } executed 15 times by 1 test: end of blockExecuted by:
| 15 | ||||||||||||||||||||||||
| 1903 | } else if (strcmp(argv[i], "-median") == 0) {
| 0-56 | ||||||||||||||||||||||||
| 1904 | if (i + 1 >= argc) {
| 0 | ||||||||||||||||||||||||
| 1905 | fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); | - | ||||||||||||||||||||||||
| 1906 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1907 | } else { | - | ||||||||||||||||||||||||
| 1908 | QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); | - | ||||||||||||||||||||||||
| 1909 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1910 | - | |||||||||||||||||||||||||
| 1911 | } else if (strcmp(argv[i], "-vb") == 0) {
| 0-56 | ||||||||||||||||||||||||
| 1912 | QBenchmarkGlobalData::current->verboseOutput = true; | - | ||||||||||||||||||||||||
| 1913 | #if defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 1914 | } else if (strncmp(argv[i], "-ServerName:", 12) == 0 || | - | ||||||||||||||||||||||||
| 1915 | strncmp(argv[i], "-qdevel", 7) == 0) { | - | ||||||||||||||||||||||||
| 1916 | continue; | - | ||||||||||||||||||||||||
| 1917 | #elif defined(Q_OS_MAC) && defined(HAVE_XCTEST) | - | ||||||||||||||||||||||||
| 1918 | } else if (int skip = QXcodeTestLogger::parseCommandLineArgument(argv[i])) { | - | ||||||||||||||||||||||||
| 1919 | i += (skip - 1); // Eating argv[i] with a continue counts towards skips | - | ||||||||||||||||||||||||
| 1920 | continue; | - | ||||||||||||||||||||||||
| 1921 | #endif | - | ||||||||||||||||||||||||
| 1922 | } else if (argv[i][0] == '-') { never executed: end of block
| 0-56 | ||||||||||||||||||||||||
| 1923 | fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); | - | ||||||||||||||||||||||||
| 1924 | if (qml) {
| 0 | ||||||||||||||||||||||||
| 1925 | fprintf(stderr, "\nqmltest related options:\n" | - | ||||||||||||||||||||||||
| 1926 | " -import : Specify an import directory.\n" | - | ||||||||||||||||||||||||
| 1927 | " -plugins : Specify a directory where to search for plugins.\n" | - | ||||||||||||||||||||||||
| 1928 | " -input : Specify the root directory for test cases.\n" | - | ||||||||||||||||||||||||
| 1929 | " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" | - | ||||||||||||||||||||||||
| 1930 | ); | - | ||||||||||||||||||||||||
| 1931 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1932 | - | |||||||||||||||||||||||||
| 1933 | fprintf(stderr, "\n" | - | ||||||||||||||||||||||||
| 1934 | " -help : This help\n"); | - | ||||||||||||||||||||||||
| 1935 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1936 | } else if (qml) {
| 0-56 | ||||||||||||||||||||||||
| 1937 | // We can't check the availability of test functions until | - | ||||||||||||||||||||||||
| 1938 | // we load the QML files. So just store the data for now. | - | ||||||||||||||||||||||||
| 1939 | int colon = -1; | - | ||||||||||||||||||||||||
| 1940 | int offset; | - | ||||||||||||||||||||||||
| 1941 | for (offset = 0; *(argv[i]+offset); ++offset) {
| 0 | ||||||||||||||||||||||||
| 1942 | if (*(argv[i]+offset) == ':') {
| 0 | ||||||||||||||||||||||||
| 1943 | if (*(argv[i]+offset+1) == ':') {
| 0 | ||||||||||||||||||||||||
| 1944 | // "::" is used as a test name separator. | - | ||||||||||||||||||||||||
| 1945 | // e.g. "ClickTests::test_click:row1". | - | ||||||||||||||||||||||||
| 1946 | ++offset; | - | ||||||||||||||||||||||||
| 1947 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1948 | colon = offset; | - | ||||||||||||||||||||||||
| 1949 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 1950 | } | - | ||||||||||||||||||||||||
| 1951 | } | - | ||||||||||||||||||||||||
| 1952 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1953 | if (colon == -1) {
| 0 | ||||||||||||||||||||||||
| 1954 | QTest::testFunctions += QString::fromLatin1(argv[i]); | - | ||||||||||||||||||||||||
| 1955 | QTest::testTags += QString(); | - | ||||||||||||||||||||||||
| 1956 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 1957 | QTest::testFunctions += | - | ||||||||||||||||||||||||
| 1958 | QString::fromLatin1(argv[i], colon); | - | ||||||||||||||||||||||||
| 1959 | QTest::testTags += | - | ||||||||||||||||||||||||
| 1960 | QString::fromLatin1(argv[i] + colon + 1); | - | ||||||||||||||||||||||||
| 1961 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 1962 | } else { | - | ||||||||||||||||||||||||
| 1963 | if (!QTest::testFuncs) {
| 21-35 | ||||||||||||||||||||||||
| 1964 | QTest::testFuncs = new QTest::TestFunction[512]; | - | ||||||||||||||||||||||||
| 1965 | } executed 35 times by 1 test: end of blockExecuted by:
| 35 | ||||||||||||||||||||||||
| 1966 | - | |||||||||||||||||||||||||
| 1967 | int colon = -1; | - | ||||||||||||||||||||||||
| 1968 | char buf[512], *data=0; | - | ||||||||||||||||||||||||
| 1969 | int off; | - | ||||||||||||||||||||||||
| 1970 | for (off = 0; *(argv[i]+off); ++off) {
| 33-741 | ||||||||||||||||||||||||
| 1971 | if (*(argv[i]+off) == ':') {
| 23-718 | ||||||||||||||||||||||||
| 1972 | colon = off; | - | ||||||||||||||||||||||||
| 1973 | break; executed 23 times by 1 test: break;Executed by:
| 23 | ||||||||||||||||||||||||
| 1974 | } | - | ||||||||||||||||||||||||
| 1975 | } executed 718 times by 1 test: end of blockExecuted by:
| 718 | ||||||||||||||||||||||||
| 1976 | if (colon != -1) {
| 23-33 | ||||||||||||||||||||||||
| 1977 | data = qstrdup(argv[i]+colon+1); | - | ||||||||||||||||||||||||
| 1978 | } executed 23 times by 1 test: end of blockExecuted by:
| 23 | ||||||||||||||||||||||||
| 1979 | qsnprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf | - | ||||||||||||||||||||||||
| 1980 | qsnprintf(buf + off, qMin(512 - off, 3), "()"); // append "()" | - | ||||||||||||||||||||||||
| 1981 | int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); | - | ||||||||||||||||||||||||
| 1982 | if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) {
| 0-56 | ||||||||||||||||||||||||
| 1983 | fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n", buf); | - | ||||||||||||||||||||||||
| 1984 | buf[off] = 0; | - | ||||||||||||||||||||||||
| 1985 | qPrintTestSlots(stderr, buf); | - | ||||||||||||||||||||||||
| 1986 | fprintf(stderr, "\n%s -functions\nlists all available test functions.\n", argv[0]); | - | ||||||||||||||||||||||||
| 1987 | exit(1); never executed: exit(1); | 0 | ||||||||||||||||||||||||
| 1988 | } | - | ||||||||||||||||||||||||
| 1989 | testFuncs[testFuncCount].set(idx, data); | - | ||||||||||||||||||||||||
| 1990 | testFuncCount++; | - | ||||||||||||||||||||||||
| 1991 | QTEST_ASSERT(QTest::testFuncCount < 512); never executed: qt_assert("QTest::testFuncCount < 512",__FILE__,1991);
| 0-56 | ||||||||||||||||||||||||
| 1992 | } executed 56 times by 1 test: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 1993 | } | - | ||||||||||||||||||||||||
| 1994 | - | |||||||||||||||||||||||||
| 1995 | bool installedTestCoverage = installCoverageTool(QTestResult::currentAppName(), QTestResult::currentTestObjectName()); | - | ||||||||||||||||||||||||
| 1996 | QTestLog::setInstalledTestCoverage(installedTestCoverage); | - | ||||||||||||||||||||||||
| 1997 | - | |||||||||||||||||||||||||
| 1998 | // If no loggers were created by the long version of the -o command-line | - | ||||||||||||||||||||||||
| 1999 | // option, create a logger using whatever filename and format were | - | ||||||||||||||||||||||||
| 2000 | // set using the old-style command-line options. | - | ||||||||||||||||||||||||
| 2001 | if (QTestLog::loggerCount() == 0)
| 415-822 | ||||||||||||||||||||||||
| 2002 | QTestLog::addLogger(logFormat, logFilename); executed 822 times by 539 tests: QTestLog::addLogger(logFormat, logFilename);Executed by:
| 822 | ||||||||||||||||||||||||
| 2003 | } executed 1237 times by 539 tests: end of blockExecuted by:
| 1237 | ||||||||||||||||||||||||
| 2004 | - | |||||||||||||||||||||||||
| 2005 | QBenchmarkResult qMedian(const QVector<QBenchmarkResult> &container) | - | ||||||||||||||||||||||||
| 2006 | { | - | ||||||||||||||||||||||||
| 2007 | const int count = container.count(); | - | ||||||||||||||||||||||||
| 2008 | if (count == 0)
| 0-266 | ||||||||||||||||||||||||
| 2009 | return QBenchmarkResult(); never executed: return QBenchmarkResult(); | 0 | ||||||||||||||||||||||||
| 2010 | - | |||||||||||||||||||||||||
| 2011 | if (count == 1)
| 0-266 | ||||||||||||||||||||||||
| 2012 | return container.front(); executed 266 times by 2 tests: return container.front();Executed by:
| 266 | ||||||||||||||||||||||||
| 2013 | - | |||||||||||||||||||||||||
| 2014 | QVector<QBenchmarkResult> containerCopy = container; | - | ||||||||||||||||||||||||
| 2015 | std::sort(containerCopy.begin(), containerCopy.end()); | - | ||||||||||||||||||||||||
| 2016 | - | |||||||||||||||||||||||||
| 2017 | const int middle = count / 2; | - | ||||||||||||||||||||||||
| 2018 | - | |||||||||||||||||||||||||
| 2019 | // ### handle even-sized containers here by doing an aritmetic mean of the two middle items. | - | ||||||||||||||||||||||||
| 2020 | return containerCopy.at(middle); never executed: return containerCopy.at(middle); | 0 | ||||||||||||||||||||||||
| 2021 | } | - | ||||||||||||||||||||||||
| 2022 | - | |||||||||||||||||||||||||
| 2023 | struct QTestDataSetter | - | ||||||||||||||||||||||||
| 2024 | { | - | ||||||||||||||||||||||||
| 2025 | QTestDataSetter(QTestData *data) | - | ||||||||||||||||||||||||
| 2026 | { | - | ||||||||||||||||||||||||
| 2027 | QTestResult::setCurrentTestData(data); | - | ||||||||||||||||||||||||
| 2028 | } executed 130481 times by 535 tests: end of blockExecuted by:
| 130481 | ||||||||||||||||||||||||
| 2029 | ~QTestDataSetter() | - | ||||||||||||||||||||||||
| 2030 | { | - | ||||||||||||||||||||||||
| 2031 | QTestResult::setCurrentTestData(0); | - | ||||||||||||||||||||||||
| 2032 | } executed 130432 times by 535 tests: end of blockExecuted by:
| 130432 | ||||||||||||||||||||||||
| 2033 | }; | - | ||||||||||||||||||||||||
| 2034 | - | |||||||||||||||||||||||||
| 2035 | namespace { | - | ||||||||||||||||||||||||
| 2036 | - | |||||||||||||||||||||||||
| 2037 | qreal addResult(qreal current, const QBenchmarkResult& r) | - | ||||||||||||||||||||||||
| 2038 | { | - | ||||||||||||||||||||||||
| 2039 | return current + r.value; never executed: return current + r.value; | 0 | ||||||||||||||||||||||||
| 2040 | } | - | ||||||||||||||||||||||||
| 2041 | - | |||||||||||||||||||||||||
| 2042 | } | - | ||||||||||||||||||||||||
| 2043 | - | |||||||||||||||||||||||||
| 2044 | static void qInvokeTestMethodDataEntry(char *slot) | - | ||||||||||||||||||||||||
| 2045 | { | - | ||||||||||||||||||||||||
| 2046 | /* Benchmarking: for each median iteration*/ | - | ||||||||||||||||||||||||
| 2047 | - | |||||||||||||||||||||||||
| 2048 | bool isBenchmark = false; | - | ||||||||||||||||||||||||
| 2049 | int i = (QBenchmarkGlobalData::current->measurer->needsWarmupIteration()) ? -1 : 0;
| 438-130043 | ||||||||||||||||||||||||
| 2050 | - | |||||||||||||||||||||||||
| 2051 | QVector<QBenchmarkResult> results; | - | ||||||||||||||||||||||||
| 2052 | bool minimumTotalReached = false; | - | ||||||||||||||||||||||||
| 2053 | do { | - | ||||||||||||||||||||||||
| 2054 | QBenchmarkTestMethodData::current->beginDataRun(); | - | ||||||||||||||||||||||||
| 2055 | - | |||||||||||||||||||||||||
| 2056 | /* Benchmarking: for each accumulation iteration*/ | - | ||||||||||||||||||||||||
| 2057 | bool invokeOk; | - | ||||||||||||||||||||||||
| 2058 | do { | - | ||||||||||||||||||||||||
| 2059 | invokeMethod(QTest::currentTestObject, "init()"); | - | ||||||||||||||||||||||||
| 2060 | if (QTestResult::skipCurrentTest() || QTestResult::currentTestFailed())
| 63-130438 | ||||||||||||||||||||||||
| 2061 | break; executed 126 times by 1 test: break;Executed by:
| 126 | ||||||||||||||||||||||||
| 2062 | - | |||||||||||||||||||||||||
| 2063 | QBenchmarkTestMethodData::current->result = QBenchmarkResult(); | - | ||||||||||||||||||||||||
| 2064 | QBenchmarkTestMethodData::current->resultAccepted = false; | - | ||||||||||||||||||||||||
| 2065 | - | |||||||||||||||||||||||||
| 2066 | QBenchmarkGlobalData::current->context.tag = | - | ||||||||||||||||||||||||
| 2067 | QLatin1String( | - | ||||||||||||||||||||||||
| 2068 | QTestResult::currentDataTag() | - | ||||||||||||||||||||||||
| 2069 | ? QTestResult::currentDataTag() : ""); | - | ||||||||||||||||||||||||
| 2070 | - | |||||||||||||||||||||||||
| 2071 | invokeOk = QMetaObject::invokeMethod(QTest::currentTestObject, slot, | - | ||||||||||||||||||||||||
| 2072 | Qt::DirectConnection); | - | ||||||||||||||||||||||||
| 2073 | if (!invokeOk)
| 0-130305 | ||||||||||||||||||||||||
| 2074 | QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__); never executed: QTestResult::addFailure("Unable to execute slot", __FILE__, 2074); | 0 | ||||||||||||||||||||||||
| 2075 | - | |||||||||||||||||||||||||
| 2076 | isBenchmark = QBenchmarkTestMethodData::current->isBenchmark(); | - | ||||||||||||||||||||||||
| 2077 | - | |||||||||||||||||||||||||
| 2078 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||||||||||||||
| 2079 | - | |||||||||||||||||||||||||
| 2080 | invokeMethod(QTest::currentTestObject, "cleanup()"); | - | ||||||||||||||||||||||||
| 2081 | - | |||||||||||||||||||||||||
| 2082 | // If the test isn't a benchmark, finalize the result after cleanup() has finished. | - | ||||||||||||||||||||||||
| 2083 | if (!isBenchmark)
| 388-129917 | ||||||||||||||||||||||||
| 2084 | QTestResult::finishedCurrentTestDataCleanup(); executed 129917 times by 535 tests: QTestResult::finishedCurrentTestDataCleanup();Executed by:
| 129917 | ||||||||||||||||||||||||
| 2085 | - | |||||||||||||||||||||||||
| 2086 | // If this test method has a benchmark, repeat until all measurements are | - | ||||||||||||||||||||||||
| 2087 | // acceptable. | - | ||||||||||||||||||||||||
| 2088 | // The QBENCHMARK macro increases the number of iterations for each run until | - | ||||||||||||||||||||||||
| 2089 | // this happens. | - | ||||||||||||||||||||||||
| 2090 | } while (invokeOk && isBenchmark executed 130305 times by 535 tests: end of blockExecuted by:
| 0-130305 | ||||||||||||||||||||||||
| 2091 | && QBenchmarkTestMethodData::current->resultsAccepted() == false
| 12-376 | ||||||||||||||||||||||||
| 2092 | && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed());
| 0-12 | ||||||||||||||||||||||||
| 2093 | - | |||||||||||||||||||||||||
| 2094 | QBenchmarkTestMethodData::current->endDataRun(); | - | ||||||||||||||||||||||||
| 2095 | if (!QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed()) {
| 140-129280 | ||||||||||||||||||||||||
| 2096 | if (i > -1) // iteration -1 is the warmup iteration.
| 344-128796 | ||||||||||||||||||||||||
| 2097 | results.append(QBenchmarkTestMethodData::current->result); executed 344 times by 2 tests: results.append(QBenchmarkTestMethodData::current->result);Executed by:
| 344 | ||||||||||||||||||||||||
| 2098 | - | |||||||||||||||||||||||||
| 2099 | if (isBenchmark && QBenchmarkGlobalData::current->verboseOutput) {
| 0-128866 | ||||||||||||||||||||||||
| 2100 | if (i == -1) {
| 0 | ||||||||||||||||||||||||
| 2101 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
| 2102 | QString::fromLatin1("warmup stage result : %1") | - | ||||||||||||||||||||||||
| 2103 | .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0); | - | ||||||||||||||||||||||||
| 2104 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 2105 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
| 2106 | QString::fromLatin1("accumulation stage result: %1") | - | ||||||||||||||||||||||||
| 2107 | .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0); | - | ||||||||||||||||||||||||
| 2108 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2109 | } | - | ||||||||||||||||||||||||
| 2110 | } executed 129140 times by 534 tests: end of blockExecuted by:
| 129140 | ||||||||||||||||||||||||
| 2111 | - | |||||||||||||||||||||||||
| 2112 | // Verify if the minimum total measurement is reached, if it was specified: | - | ||||||||||||||||||||||||
| 2113 | if (QBenchmarkGlobalData::current->minimumTotal == -1) {
| 0-130419 | ||||||||||||||||||||||||
| 2114 | minimumTotalReached = true; | - | ||||||||||||||||||||||||
| 2115 | } else { executed 130419 times by 535 tests: end of blockExecuted by:
| 130419 | ||||||||||||||||||||||||
| 2116 | const qreal total = std::accumulate(results.begin(), results.end(), 0.0, addResult); | - | ||||||||||||||||||||||||
| 2117 | minimumTotalReached = (total >= QBenchmarkGlobalData::current->minimumTotal); | - | ||||||||||||||||||||||||
| 2118 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2119 | } while (isBenchmark
| 376-130043 | ||||||||||||||||||||||||
| 2120 | && ((++i < QBenchmarkGlobalData::current->adjustMedianIterationCount()) || !minimumTotalReached)
| 0-368 | ||||||||||||||||||||||||
| 2121 | && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed());
| 0-8 | ||||||||||||||||||||||||
| 2122 | - | |||||||||||||||||||||||||
| 2123 | // If the test is a benchmark, finalize the result after all iterations have finished. | - | ||||||||||||||||||||||||
| 2124 | if (isBenchmark) {
| 368-130043 | ||||||||||||||||||||||||
| 2125 | bool testPassed = !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed();
| 25-343 | ||||||||||||||||||||||||
| 2126 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||||||||||||||
| 2127 | // Only report benchmark figures if the test passed | - | ||||||||||||||||||||||||
| 2128 | if (testPassed && QBenchmarkTestMethodData::current->resultsAccepted())
| 0-266 | ||||||||||||||||||||||||
| 2129 | QTestLog::addBenchmarkResult(qMedian(results)); executed 266 times by 2 tests: QTestLog::addBenchmarkResult(qMedian(results));Executed by:
| 266 | ||||||||||||||||||||||||
| 2130 | } executed 368 times by 2 tests: end of blockExecuted by:
| 368 | ||||||||||||||||||||||||
| 2131 | } executed 130411 times by 535 tests: end of blockExecuted by:
| 130411 | ||||||||||||||||||||||||
| 2132 | - | |||||||||||||||||||||||||
| 2133 | class WatchDog : public QThread | - | ||||||||||||||||||||||||
| 2134 | { | - | ||||||||||||||||||||||||
| 2135 | public: | - | ||||||||||||||||||||||||
| 2136 | WatchDog() | - | ||||||||||||||||||||||||
| 2137 | { | - | ||||||||||||||||||||||||
| 2138 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
| 2139 | timeout.store(-1); | - | ||||||||||||||||||||||||
| 2140 | start(); | - | ||||||||||||||||||||||||
| 2141 | waitCondition.wait(&mutex); | - | ||||||||||||||||||||||||
| 2142 | } executed 1237 times by 539 tests: end of blockExecuted by:
| 1237 | ||||||||||||||||||||||||
| 2143 | ~WatchDog() { | - | ||||||||||||||||||||||||
| 2144 | { | - | ||||||||||||||||||||||||
| 2145 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
| 2146 | timeout.store(0); | - | ||||||||||||||||||||||||
| 2147 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
| 2148 | } | - | ||||||||||||||||||||||||
| 2149 | wait(); | - | ||||||||||||||||||||||||
| 2150 | } executed 1188 times by 541 tests: end of blockExecuted by:
| 1188 | ||||||||||||||||||||||||
| 2151 | - | |||||||||||||||||||||||||
| 2152 | void beginTest() { | - | ||||||||||||||||||||||||
| 2153 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
| 2154 | timeout.store(defaultTimeout()); | - | ||||||||||||||||||||||||
| 2155 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
| 2156 | } executed 130481 times by 535 tests: end of blockExecuted by:
| 130481 | ||||||||||||||||||||||||
| 2157 | - | |||||||||||||||||||||||||
| 2158 | void testFinished() { | - | ||||||||||||||||||||||||
| 2159 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
| 2160 | timeout.store(-1); | - | ||||||||||||||||||||||||
| 2161 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
| 2162 | } executed 130411 times by 535 tests: end of blockExecuted by:
| 130411 | ||||||||||||||||||||||||
| 2163 | - | |||||||||||||||||||||||||
| 2164 | void run() { | - | ||||||||||||||||||||||||
| 2165 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||||||||
| 2166 | waitCondition.wakeAll(); | - | ||||||||||||||||||||||||
| 2167 | while (1) { | - | ||||||||||||||||||||||||
| 2168 | int t = timeout.load(); | - | ||||||||||||||||||||||||
| 2169 | if (!t)
| 1188-229499 | ||||||||||||||||||||||||
| 2170 | break; executed 1188 times by 541 tests: break;Executed by:
| 1188 | ||||||||||||||||||||||||
| 2171 | if (!waitCondition.wait(&mutex, t)) {
| 0-229450 | ||||||||||||||||||||||||
| 2172 | stackTrace(); | - | ||||||||||||||||||||||||
| 2173 | qFatal("Test function timed out"); | - | ||||||||||||||||||||||||
| 2174 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2175 | } executed 229450 times by 977 tests: end of blockExecuted by:
| 229450 | ||||||||||||||||||||||||
| 2176 | } executed 1188 times by 541 tests: end of blockExecuted by:
| 1188 | ||||||||||||||||||||||||
| 2177 | - | |||||||||||||||||||||||||
| 2178 | private: | - | ||||||||||||||||||||||||
| 2179 | QBasicAtomicInt timeout; | - | ||||||||||||||||||||||||
| 2180 | QMutex mutex; | - | ||||||||||||||||||||||||
| 2181 | QWaitCondition waitCondition; | - | ||||||||||||||||||||||||
| 2182 | }; | - | ||||||||||||||||||||||||
| 2183 | - | |||||||||||||||||||||||||
| 2184 | - | |||||||||||||||||||||||||
| 2185 | /*! | - | ||||||||||||||||||||||||
| 2186 | \internal | - | ||||||||||||||||||||||||
| 2187 | - | |||||||||||||||||||||||||
| 2188 | Call slot_data(), init(), slot(), cleanup(), init(), slot(), cleanup(), ... | - | ||||||||||||||||||||||||
| 2189 | If data is set then it is the only test that is performed | - | ||||||||||||||||||||||||
| 2190 | - | |||||||||||||||||||||||||
| 2191 | If the function was successfully called, true is returned, otherwise | - | ||||||||||||||||||||||||
| 2192 | false. | - | ||||||||||||||||||||||||
| 2193 | */ | - | ||||||||||||||||||||||||
| 2194 | static bool qInvokeTestMethod(const char *slotName, const char *data, WatchDog *watchDog) | - | ||||||||||||||||||||||||
| 2195 | { | - | ||||||||||||||||||||||||
| 2196 | QTEST_ASSERT(slotName); never executed: qt_assert("slotName",__FILE__,2196);
| 0-13112 | ||||||||||||||||||||||||
| 2197 | - | |||||||||||||||||||||||||
| 2198 | QBenchmarkTestMethodData benchmarkData; | - | ||||||||||||||||||||||||
| 2199 | QBenchmarkTestMethodData::current = &benchmarkData; | - | ||||||||||||||||||||||||
| 2200 | - | |||||||||||||||||||||||||
| 2201 | QBenchmarkGlobalData::current->context.slotName = QLatin1String(slotName); | - | ||||||||||||||||||||||||
| 2202 | - | |||||||||||||||||||||||||
| 2203 | char member[512]; | - | ||||||||||||||||||||||||
| 2204 | QTestTable table; | - | ||||||||||||||||||||||||
| 2205 | - | |||||||||||||||||||||||||
| 2206 | char *slot = qstrdup(slotName); | - | ||||||||||||||||||||||||
| 2207 | slot[strlen(slot) - 2] = '\0'; | - | ||||||||||||||||||||||||
| 2208 | QTestResult::setCurrentTestFunction(slot); | - | ||||||||||||||||||||||||
| 2209 | - | |||||||||||||||||||||||||
| 2210 | const QTestTable *gTable = QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
| 2211 | const int globalDataCount = gTable->dataCount(); | - | ||||||||||||||||||||||||
| 2212 | int curGlobalDataIndex = 0; | - | ||||||||||||||||||||||||
| 2213 | - | |||||||||||||||||||||||||
| 2214 | /* For each test function that has a *_data() table/function, do: */ | - | ||||||||||||||||||||||||
| 2215 | do { | - | ||||||||||||||||||||||||
| 2216 | if (!gTable->isEmpty())
| 1153-12765 | ||||||||||||||||||||||||
| 2217 | QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex)); executed 1153 times by 15 tests: QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex));Executed by:
| 1153 | ||||||||||||||||||||||||
| 2218 | - | |||||||||||||||||||||||||
| 2219 | if (curGlobalDataIndex == 0) {
| 806-13112 | ||||||||||||||||||||||||
| 2220 | qsnprintf(member, 512, "%s_data()", slot); | - | ||||||||||||||||||||||||
| 2221 | invokeMethod(QTest::currentTestObject, member); | - | ||||||||||||||||||||||||
| 2222 | } executed 13112 times by 535 tests: end of blockExecuted by:
| 13112 | ||||||||||||||||||||||||
| 2223 | - | |||||||||||||||||||||||||
| 2224 | bool foundFunction = false; | - | ||||||||||||||||||||||||
| 2225 | if (!QTestResult::skipCurrentTest()) {
| 217-13701 | ||||||||||||||||||||||||
| 2226 | int curDataIndex = 0; | - | ||||||||||||||||||||||||
| 2227 | const int dataCount = table.dataCount(); | - | ||||||||||||||||||||||||
| 2228 | - | |||||||||||||||||||||||||
| 2229 | // Data tag requested but none available? | - | ||||||||||||||||||||||||
| 2230 | if (data && !dataCount) {
| 0-13678 | ||||||||||||||||||||||||
| 2231 | // Let empty data tag through. | - | ||||||||||||||||||||||||
| 2232 | if (!*data)
| 0 | ||||||||||||||||||||||||
| 2233 | data = 0; never executed: data = 0; | 0 | ||||||||||||||||||||||||
| 2234 | else { | - | ||||||||||||||||||||||||
| 2235 | fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); | - | ||||||||||||||||||||||||
| 2236 | fprintf(stderr, "Function has no testdata.\n"); | - | ||||||||||||||||||||||||
| 2237 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2238 | } | - | ||||||||||||||||||||||||
| 2239 | } | - | ||||||||||||||||||||||||
| 2240 | - | |||||||||||||||||||||||||
| 2241 | /* For each entry in the data table, do: */ | - | ||||||||||||||||||||||||
| 2242 | do { | - | ||||||||||||||||||||||||
| 2243 | QTestResult::setSkipCurrentTest(false); | - | ||||||||||||||||||||||||
| 2244 | QTestResult::setBlacklistCurrentTest(false); | - | ||||||||||||||||||||||||
| 2245 | if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
| 2-130458 | ||||||||||||||||||||||||
| 2246 | foundFunction = true; | - | ||||||||||||||||||||||||
| 2247 | - | |||||||||||||||||||||||||
| 2248 | QTestPrivate::checkBlackLists(slot, dataCount ? table.testData(curDataIndex)->dataTag() : 0); | - | ||||||||||||||||||||||||
| 2249 | - | |||||||||||||||||||||||||
| 2250 | QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0) | - | ||||||||||||||||||||||||
| 2251 | : table.testData(curDataIndex)); | - | ||||||||||||||||||||||||
| 2252 | - | |||||||||||||||||||||||||
| 2253 | if (watchDog)
| 0-130481 | ||||||||||||||||||||||||
| 2254 | watchDog->beginTest(); executed 130481 times by 535 tests: watchDog->beginTest();Executed by:
| 130481 | ||||||||||||||||||||||||
| 2255 | qInvokeTestMethodDataEntry(slot); | - | ||||||||||||||||||||||||
| 2256 | if (watchDog)
| 0-130411 | ||||||||||||||||||||||||
| 2257 | watchDog->testFinished(); executed 130411 times by 535 tests: watchDog->testFinished();Executed by:
| 130411 | ||||||||||||||||||||||||
| 2258 | - | |||||||||||||||||||||||||
| 2259 | if (data)
| 23-130388 | ||||||||||||||||||||||||
| 2260 | break; executed 23 times by 1 test: break;Executed by:
| 23 | ||||||||||||||||||||||||
| 2261 | } executed 130388 times by 535 tests: end of blockExecuted by:
| 130388 | ||||||||||||||||||||||||
| 2262 | ++curDataIndex; | - | ||||||||||||||||||||||||
| 2263 | } while (curDataIndex < dataCount); executed 130390 times by 535 tests: end of blockExecuted by:
| 13608-130390 | ||||||||||||||||||||||||
| 2264 | } executed 13631 times by 535 tests: end of blockExecuted by:
| 13631 | ||||||||||||||||||||||||
| 2265 | - | |||||||||||||||||||||||||
| 2266 | if (data && !foundFunction) {
| 0-13825 | ||||||||||||||||||||||||
| 2267 | fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); | - | ||||||||||||||||||||||||
| 2268 | fprintf(stderr, "Available testdata:\n"); | - | ||||||||||||||||||||||||
| 2269 | for (int i = 0; i < table.dataCount(); ++i)
| 0 | ||||||||||||||||||||||||
| 2270 | fprintf(stderr, "%s\n", table.testData(i)->dataTag()); never executed: fprintf(stderr, "%s\n", table.testData(i)->dataTag()); | 0 | ||||||||||||||||||||||||
| 2271 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2272 | } | - | ||||||||||||||||||||||||
| 2273 | - | |||||||||||||||||||||||||
| 2274 | QTestResult::setCurrentGlobalTestData(0); | - | ||||||||||||||||||||||||
| 2275 | ++curGlobalDataIndex; | - | ||||||||||||||||||||||||
| 2276 | } while (curGlobalDataIndex < globalDataCount); executed 13848 times by 535 tests: end of blockExecuted by:
| 806-13848 | ||||||||||||||||||||||||
| 2277 | - | |||||||||||||||||||||||||
| 2278 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
| 2279 | QTestResult::setSkipCurrentTest(false); | - | ||||||||||||||||||||||||
| 2280 | QTestResult::setBlacklistCurrentTest(false); | - | ||||||||||||||||||||||||
| 2281 | QTestResult::setCurrentTestData(0); | - | ||||||||||||||||||||||||
| 2282 | delete[] slot; | - | ||||||||||||||||||||||||
| 2283 | - | |||||||||||||||||||||||||
| 2284 | return true; executed 13042 times by 535 tests: return true;Executed by:
| 13042 | ||||||||||||||||||||||||
| 2285 | } | - | ||||||||||||||||||||||||
| 2286 | - | |||||||||||||||||||||||||
| 2287 | void *fetchData(QTestData *data, const char *tagName, int typeId) | - | ||||||||||||||||||||||||
| 2288 | { | - | ||||||||||||||||||||||||
| 2289 | QTEST_ASSERT(typeId); never executed: qt_assert("typeId",__FILE__,2289);
| 0-437275 | ||||||||||||||||||||||||
| 2290 | 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__,2290);
| 0-437275 | ||||||||||||||||||||||||
| 2291 | QTEST_ASSERT(data->parent()); never executed: qt_assert("data->parent()",__FILE__,2291);
| 0-437275 | ||||||||||||||||||||||||
| 2292 | - | |||||||||||||||||||||||||
| 2293 | int idx = data->parent()->indexOf(tagName); | - | ||||||||||||||||||||||||
| 2294 | - | |||||||||||||||||||||||||
| 2295 | if (idx == -1 || idx >= data->dataCount()) {
| 0-437254 | ||||||||||||||||||||||||
| 2296 | qFatal("QFETCH: Requested testdata '%s' not available, check your _data function.", | - | ||||||||||||||||||||||||
| 2297 | tagName); | - | ||||||||||||||||||||||||
| 2298 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2299 | - | |||||||||||||||||||||||||
| 2300 | if (typeId != data->parent()->elementTypeId(idx)) {
| 0-437254 | ||||||||||||||||||||||||
| 2301 | qFatal("Requested type '%s' does not match available type '%s'.", | - | ||||||||||||||||||||||||
| 2302 | QMetaType::typeName(typeId), | - | ||||||||||||||||||||||||
| 2303 | QMetaType::typeName(data->parent()->elementTypeId(idx))); | - | ||||||||||||||||||||||||
| 2304 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2305 | - | |||||||||||||||||||||||||
| 2306 | return data->data(idx); executed 437254 times by 363 tests: return data->data(idx);Executed by:
| 437254 | ||||||||||||||||||||||||
| 2307 | } | - | ||||||||||||||||||||||||
| 2308 | - | |||||||||||||||||||||||||
| 2309 | /*! | - | ||||||||||||||||||||||||
| 2310 | \fn char* QTest::toHexRepresentation(const char *ba, int length) | - | ||||||||||||||||||||||||
| 2311 | - | |||||||||||||||||||||||||
| 2312 | Returns a pointer to a string that is the string \a ba represented | - | ||||||||||||||||||||||||
| 2313 | as a space-separated sequence of hex characters. If the input is | - | ||||||||||||||||||||||||
| 2314 | considered too long, it is truncated. A trucation is indicated in | - | ||||||||||||||||||||||||
| 2315 | the returned string as an ellipsis at the end. | - | ||||||||||||||||||||||||
| 2316 | - | |||||||||||||||||||||||||
| 2317 | \a length is the length of the string \a ba. | - | ||||||||||||||||||||||||
| 2318 | */ | - | ||||||||||||||||||||||||
| 2319 | char *toHexRepresentation(const char *ba, int length) | - | ||||||||||||||||||||||||
| 2320 | { | - | ||||||||||||||||||||||||
| 2321 | if (length == 0)
| 0 | ||||||||||||||||||||||||
| 2322 | return qstrdup(""); never executed: return qstrdup(""); | 0 | ||||||||||||||||||||||||
| 2323 | - | |||||||||||||||||||||||||
| 2324 | /* We output at maximum about maxLen characters in order to avoid | - | ||||||||||||||||||||||||
| 2325 | * running out of memory and flooding things when the byte array | - | ||||||||||||||||||||||||
| 2326 | * is large. | - | ||||||||||||||||||||||||
| 2327 | * | - | ||||||||||||||||||||||||
| 2328 | * maxLen can't be for example 200 because Qt Test is sprinkled with fixed | - | ||||||||||||||||||||||||
| 2329 | * size char arrays. | - | ||||||||||||||||||||||||
| 2330 | * */ | - | ||||||||||||||||||||||||
| 2331 | const int maxLen = 50; | - | ||||||||||||||||||||||||
| 2332 | const int len = qMin(maxLen, length); | - | ||||||||||||||||||||||||
| 2333 | char *result = 0; | - | ||||||||||||||||||||||||
| 2334 | - | |||||||||||||||||||||||||
| 2335 | if (length > maxLen) {
| 0 | ||||||||||||||||||||||||
| 2336 | const int size = len * 3 + 4; | - | ||||||||||||||||||||||||
| 2337 | result = new char[size]; | - | ||||||||||||||||||||||||
| 2338 | - | |||||||||||||||||||||||||
| 2339 | char *const forElipsis = result + size - 5; | - | ||||||||||||||||||||||||
| 2340 | forElipsis[0] = ' '; | - | ||||||||||||||||||||||||
| 2341 | forElipsis[1] = '.'; | - | ||||||||||||||||||||||||
| 2342 | forElipsis[2] = '.'; | - | ||||||||||||||||||||||||
| 2343 | forElipsis[3] = '.'; | - | ||||||||||||||||||||||||
| 2344 | result[size - 1] = '\0'; | - | ||||||||||||||||||||||||
| 2345 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2346 | else { | - | ||||||||||||||||||||||||
| 2347 | const int size = len * 3; | - | ||||||||||||||||||||||||
| 2348 | result = new char[size]; | - | ||||||||||||||||||||||||
| 2349 | result[size - 1] = '\0'; | - | ||||||||||||||||||||||||
| 2350 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2351 | - | |||||||||||||||||||||||||
| 2352 | int i = 0; | - | ||||||||||||||||||||||||
| 2353 | int o = 0; | - | ||||||||||||||||||||||||
| 2354 | - | |||||||||||||||||||||||||
| 2355 | while (true) { | - | ||||||||||||||||||||||||
| 2356 | const char at = ba[i]; | - | ||||||||||||||||||||||||
| 2357 | - | |||||||||||||||||||||||||
| 2358 | result[o] = toHexUpper(at >> 4); | - | ||||||||||||||||||||||||
| 2359 | ++o; | - | ||||||||||||||||||||||||
| 2360 | result[o] = toHexUpper(at); | - | ||||||||||||||||||||||||
| 2361 | - | |||||||||||||||||||||||||
| 2362 | ++i; | - | ||||||||||||||||||||||||
| 2363 | ++o; | - | ||||||||||||||||||||||||
| 2364 | if (i == len)
| 0 | ||||||||||||||||||||||||
| 2365 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2366 | else { | - | ||||||||||||||||||||||||
| 2367 | result[o] = ' '; | - | ||||||||||||||||||||||||
| 2368 | ++o; | - | ||||||||||||||||||||||||
| 2369 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2370 | } | - | ||||||||||||||||||||||||
| 2371 | - | |||||||||||||||||||||||||
| 2372 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 2373 | } | - | ||||||||||||||||||||||||
| 2374 | - | |||||||||||||||||||||||||
| 2375 | /*! | - | ||||||||||||||||||||||||
| 2376 | \internal | - | ||||||||||||||||||||||||
| 2377 | Returns the same QByteArray but with only the ASCII characters still shown; | - | ||||||||||||||||||||||||
| 2378 | everything else is replaced with \c {\xHH}. | - | ||||||||||||||||||||||||
| 2379 | */ | - | ||||||||||||||||||||||||
| 2380 | char *toPrettyCString(const char *p, int length) | - | ||||||||||||||||||||||||
| 2381 | { | - | ||||||||||||||||||||||||
| 2382 | bool trimmed = false; | - | ||||||||||||||||||||||||
| 2383 | QScopedArrayPointer<char> buffer(new char[256]); | - | ||||||||||||||||||||||||
| 2384 | const char *end = p + length; | - | ||||||||||||||||||||||||
| 2385 | char *dst = buffer.data(); | - | ||||||||||||||||||||||||
| 2386 | - | |||||||||||||||||||||||||
| 2387 | bool lastWasHexEscape = false; | - | ||||||||||||||||||||||||
| 2388 | *dst++ = '"'; | - | ||||||||||||||||||||||||
| 2389 | for ( ; p != end; ++p) {
| 9782-448076 | ||||||||||||||||||||||||
| 2390 | // we can add: | - | ||||||||||||||||||||||||
| 2391 | // 1 byte: a single character | - | ||||||||||||||||||||||||
| 2392 | // 2 bytes: a simple escape sequence (\n) | - | ||||||||||||||||||||||||
| 2393 | // 3 bytes: "" and a character | - | ||||||||||||||||||||||||
| 2394 | // 4 bytes: an hex escape sequence (\xHH) | - | ||||||||||||||||||||||||
| 2395 | if (dst - buffer.data() > 246) {
| 1692-446384 | ||||||||||||||||||||||||
| 2396 | // plus the the quote, the three dots and NUL, it's 255 in the worst case | - | ||||||||||||||||||||||||
| 2397 | trimmed = true; | - | ||||||||||||||||||||||||
| 2398 | break; executed 1692 times by 23 tests: break;Executed by:
| 1692 | ||||||||||||||||||||||||
| 2399 | } | - | ||||||||||||||||||||||||
| 2400 | - | |||||||||||||||||||||||||
| 2401 | // check if we need to insert "" to break an hex escape sequence | - | ||||||||||||||||||||||||
| 2402 | if (Q_UNLIKELY(lastWasHexEscape)) {
| 45158-401226 | ||||||||||||||||||||||||
| 2403 | if (fromHex(*p) != -1) {
| 3252-41906 | ||||||||||||||||||||||||
| 2404 | // yes, insert it | - | ||||||||||||||||||||||||
| 2405 | *dst++ = '"'; | - | ||||||||||||||||||||||||
| 2406 | *dst++ = '"'; | - | ||||||||||||||||||||||||
| 2407 | } executed 3252 times by 17 tests: end of blockExecuted by:
| 3252 | ||||||||||||||||||||||||
| 2408 | lastWasHexEscape = false; | - | ||||||||||||||||||||||||
| 2409 | } executed 45158 times by 31 tests: end of blockExecuted by:
| 45158 | ||||||||||||||||||||||||
| 2410 | - | |||||||||||||||||||||||||
| 2411 | if (*p < 0x7f && *p >= 0x20 && *p != '\\' && *p != '"') {
| 336-443394 | ||||||||||||||||||||||||
| 2412 | *dst++ = *p; | - | ||||||||||||||||||||||||
| 2413 | continue; executed 388882 times by 88 tests: continue;Executed by:
| 388882 | ||||||||||||||||||||||||
| 2414 | } | - | ||||||||||||||||||||||||
| 2415 | - | |||||||||||||||||||||||||
| 2416 | // write as an escape sequence | - | ||||||||||||||||||||||||
| 2417 | // this means we may advance dst to buffer.data() + 247 or 250 | - | ||||||||||||||||||||||||
| 2418 | *dst++ = '\\'; | - | ||||||||||||||||||||||||
| 2419 | switch (*p) { | - | ||||||||||||||||||||||||
| 2420 | case 0x5c: executed 336 times by 12 tests: case 0x5c:Executed by:
| 336 | ||||||||||||||||||||||||
| 2421 | case 0x22: executed 812 times by 16 tests: case 0x22:Executed by:
| 812 | ||||||||||||||||||||||||
| 2422 | *dst++ = uchar(*p); | - | ||||||||||||||||||||||||
| 2423 | break; executed 1148 times by 18 tests: break;Executed by:
| 1148 | ||||||||||||||||||||||||
| 2424 | case 0x8: executed 292 times by 13 tests: case 0x8:Executed by:
| 292 | ||||||||||||||||||||||||
| 2425 | *dst++ = 'b'; | - | ||||||||||||||||||||||||
| 2426 | break; executed 292 times by 13 tests: break;Executed by:
| 292 | ||||||||||||||||||||||||
| 2427 | case 0xc: executed 306 times by 12 tests: case 0xc:Executed by:
| 306 | ||||||||||||||||||||||||
| 2428 | *dst++ = 'f'; | - | ||||||||||||||||||||||||
| 2429 | break; executed 306 times by 12 tests: break;Executed by:
| 306 | ||||||||||||||||||||||||
| 2430 | case 0xa: executed 7452 times by 33 tests: case 0xa:Executed by:
| 7452 | ||||||||||||||||||||||||
| 2431 | *dst++ = 'n'; | - | ||||||||||||||||||||||||
| 2432 | break; executed 7452 times by 33 tests: break;Executed by:
| 7452 | ||||||||||||||||||||||||
| 2433 | case 0xd: executed 920 times by 14 tests: case 0xd:Executed by:
| 920 | ||||||||||||||||||||||||
| 2434 | *dst++ = 'r'; | - | ||||||||||||||||||||||||
| 2435 | break; executed 920 times by 14 tests: break;Executed by:
| 920 | ||||||||||||||||||||||||
| 2436 | case 0x9: executed 872 times by 13 tests: case 0x9:Executed by:
| 872 | ||||||||||||||||||||||||
| 2437 | *dst++ = 't'; | - | ||||||||||||||||||||||||
| 2438 | break; executed 872 times by 13 tests: break;Executed by:
| 872 | ||||||||||||||||||||||||
| 2439 | default: executed 46512 times by 32 tests: default:Executed by:
| 46512 | ||||||||||||||||||||||||
| 2440 | // print as hex escape | - | ||||||||||||||||||||||||
| 2441 | *dst++ = 'x'; | - | ||||||||||||||||||||||||
| 2442 | *dst++ = toHexUpper(uchar(*p) >> 4); | - | ||||||||||||||||||||||||
| 2443 | *dst++ = toHexUpper(uchar(*p)); | - | ||||||||||||||||||||||||
| 2444 | lastWasHexEscape = true; | - | ||||||||||||||||||||||||
| 2445 | break; executed 46512 times by 32 tests: break;Executed by:
| 46512 | ||||||||||||||||||||||||
| 2446 | } | - | ||||||||||||||||||||||||
| 2447 | } | - | ||||||||||||||||||||||||
| 2448 | - | |||||||||||||||||||||||||
| 2449 | *dst++ = '"'; | - | ||||||||||||||||||||||||
| 2450 | if (trimmed) {
| 1692-9782 | ||||||||||||||||||||||||
| 2451 | *dst++ = '.'; | - | ||||||||||||||||||||||||
| 2452 | *dst++ = '.'; | - | ||||||||||||||||||||||||
| 2453 | *dst++ = '.'; | - | ||||||||||||||||||||||||
| 2454 | } executed 1692 times by 23 tests: end of blockExecuted by:
| 1692 | ||||||||||||||||||||||||
| 2455 | *dst++ = '\0'; | - | ||||||||||||||||||||||||
| 2456 | return buffer.take(); executed 11474 times by 93 tests: return buffer.take();Executed by:
| 11474 | ||||||||||||||||||||||||
| 2457 | } | - | ||||||||||||||||||||||||
| 2458 | - | |||||||||||||||||||||||||
| 2459 | /*! | - | ||||||||||||||||||||||||
| 2460 | \internal | - | ||||||||||||||||||||||||
| 2461 | Returns the same QString but with only the ASCII characters still shown; | - | ||||||||||||||||||||||||
| 2462 | everything else is replaced with \c {\uXXXX}. | - | ||||||||||||||||||||||||
| 2463 | - | |||||||||||||||||||||||||
| 2464 | Similar to QDebug::putString(). | - | ||||||||||||||||||||||||
| 2465 | */ | - | ||||||||||||||||||||||||
| 2466 | char *toPrettyUnicode(const ushort *p, int length) | - | ||||||||||||||||||||||||
| 2467 | { | - | ||||||||||||||||||||||||
| 2468 | // keep it simple for the vast majority of cases | - | ||||||||||||||||||||||||
| 2469 | bool trimmed = false; | - | ||||||||||||||||||||||||
| 2470 | QScopedArrayPointer<char> buffer(new char[256]); | - | ||||||||||||||||||||||||
| 2471 | const ushort *end = p + length; | - | ||||||||||||||||||||||||
| 2472 | char *dst = buffer.data(); | - | ||||||||||||||||||||||||
| 2473 | - | |||||||||||||||||||||||||
| 2474 | *dst++ = '"'; | - | ||||||||||||||||||||||||
| 2475 | for ( ; p != end; ++p) {
| 193207-3515228 | ||||||||||||||||||||||||
| 2476 | if (dst - buffer.data() > 245) {
| 4397-3510831 | ||||||||||||||||||||||||
| 2477 | // plus the the quote, the three dots and NUL, it's 250, 251 or 255 | - | ||||||||||||||||||||||||
| 2478 | trimmed = true; | - | ||||||||||||||||||||||||
| 2479 | break; executed 4397 times by 19 tests: break;Executed by:
| 4397 | ||||||||||||||||||||||||
| 2480 | } | - | ||||||||||||||||||||||||
| 2481 | - | |||||||||||||||||||||||||
| 2482 | if (*p < 0x7f && *p >= 0x20 && *p != '\\' && *p != '"') {
| 932-3501567 | ||||||||||||||||||||||||
| 2483 | *dst++ = *p; | - | ||||||||||||||||||||||||
| 2484 | continue; executed 3424775 times by 246 tests: continue;Executed by:
| 3424775 | ||||||||||||||||||||||||
| 2485 | } | - | ||||||||||||||||||||||||
| 2486 | - | |||||||||||||||||||||||||
| 2487 | // write as an escape sequence | - | ||||||||||||||||||||||||
| 2488 | // this means we may advance dst to buffer.data() + 246 or 250 | - | ||||||||||||||||||||||||
| 2489 | *dst++ = '\\'; | - | ||||||||||||||||||||||||
| 2490 | switch (*p) { | - | ||||||||||||||||||||||||
| 2491 | case 0x22: executed 53012 times by 19 tests: case 0x22:Executed by:
| 53012 | ||||||||||||||||||||||||
| 2492 | case 0x5c: executed 932 times by 15 tests: case 0x5c:Executed by:
| 932 | ||||||||||||||||||||||||
| 2493 | *dst++ = uchar(*p); | - | ||||||||||||||||||||||||
| 2494 | break; executed 53944 times by 26 tests: break;Executed by:
| 53944 | ||||||||||||||||||||||||
| 2495 | case 0x8: executed 2 times by 1 test: case 0x8:Executed by:
| 2 | ||||||||||||||||||||||||
| 2496 | *dst++ = 'b'; | - | ||||||||||||||||||||||||
| 2497 | break; executed 2 times by 1 test: break;Executed by:
| 2 | ||||||||||||||||||||||||
| 2498 | case 0xc: executed 18 times by 3 tests: case 0xc:Executed by:
| 18 | ||||||||||||||||||||||||
| 2499 | *dst++ = 'f'; | - | ||||||||||||||||||||||||
| 2500 | break; executed 18 times by 3 tests: break;Executed by:
| 18 | ||||||||||||||||||||||||
| 2501 | case 0xa: executed 21824 times by 37 tests: case 0xa:Executed by:
| 21824 | ||||||||||||||||||||||||
| 2502 | *dst++ = 'n'; | - | ||||||||||||||||||||||||
| 2503 | break; executed 21824 times by 37 tests: break;Executed by:
| 21824 | ||||||||||||||||||||||||
| 2504 | case 0xd: executed 78 times by 6 tests: case 0xd:Executed by:
| 78 | ||||||||||||||||||||||||
| 2505 | *dst++ = 'r'; | - | ||||||||||||||||||||||||
| 2506 | break; executed 78 times by 6 tests: break;Executed by:
| 78 | ||||||||||||||||||||||||
| 2507 | case 0x9: executed 154 times by 7 tests: case 0x9:Executed by:
| 154 | ||||||||||||||||||||||||
| 2508 | *dst++ = 't'; | - | ||||||||||||||||||||||||
| 2509 | break; executed 154 times by 7 tests: break;Executed by:
| 154 | ||||||||||||||||||||||||
| 2510 | default: executed 10036 times by 45 tests: default:Executed by:
| 10036 | ||||||||||||||||||||||||
| 2511 | *dst++ = 'u'; | - | ||||||||||||||||||||||||
| 2512 | *dst++ = toHexUpper(*p >> 12); | - | ||||||||||||||||||||||||
| 2513 | *dst++ = toHexUpper(*p >> 8); | - | ||||||||||||||||||||||||
| 2514 | *dst++ = toHexUpper(*p >> 4); | - | ||||||||||||||||||||||||
| 2515 | *dst++ = toHexUpper(*p); | - | ||||||||||||||||||||||||
| 2516 | } executed 10036 times by 45 tests: end of blockExecuted by:
| 10036 | ||||||||||||||||||||||||
| 2517 | } | - | ||||||||||||||||||||||||
| 2518 | - | |||||||||||||||||||||||||
| 2519 | *dst++ = '"'; | - | ||||||||||||||||||||||||
| 2520 | if (trimmed) {
| 4397-193207 | ||||||||||||||||||||||||
| 2521 | *dst++ = '.'; | - | ||||||||||||||||||||||||
| 2522 | *dst++ = '.'; | - | ||||||||||||||||||||||||
| 2523 | *dst++ = '.'; | - | ||||||||||||||||||||||||
| 2524 | } executed 4397 times by 19 tests: end of blockExecuted by:
| 4397 | ||||||||||||||||||||||||
| 2525 | *dst++ = '\0'; | - | ||||||||||||||||||||||||
| 2526 | return buffer.take(); executed 197604 times by 253 tests: return buffer.take();Executed by:
| 197604 | ||||||||||||||||||||||||
| 2527 | } | - | ||||||||||||||||||||||||
| 2528 | - | |||||||||||||||||||||||||
| 2529 | static bool debuggerPresent() | - | ||||||||||||||||||||||||
| 2530 | { | - | ||||||||||||||||||||||||
| 2531 | #if defined(Q_OS_LINUX) | - | ||||||||||||||||||||||||
| 2532 | int fd = open("/proc/self/status", O_RDONLY); | - | ||||||||||||||||||||||||
| 2533 | if (fd == -1)
| 0-1237 | ||||||||||||||||||||||||
| 2534 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2535 | char buffer[2048]; | - | ||||||||||||||||||||||||
| 2536 | ssize_t size = read(fd, buffer, sizeof(buffer) - 1); | - | ||||||||||||||||||||||||
| 2537 | if (size == -1) {
| 0-1237 | ||||||||||||||||||||||||
| 2538 | close(fd); | - | ||||||||||||||||||||||||
| 2539 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2540 | } | - | ||||||||||||||||||||||||
| 2541 | buffer[size] = 0; | - | ||||||||||||||||||||||||
| 2542 | const char tracerPidToken[] = "\nTracerPid:"; | - | ||||||||||||||||||||||||
| 2543 | char *tracerPid = strstr(buffer, tracerPidToken); | - | ||||||||||||||||||||||||
| 2544 | if (!tracerPid) {
| 0-1237 | ||||||||||||||||||||||||
| 2545 | close(fd); | - | ||||||||||||||||||||||||
| 2546 | return false; never executed: return false; | 0 | ||||||||||||||||||||||||
| 2547 | } | - | ||||||||||||||||||||||||
| 2548 | tracerPid += sizeof(tracerPidToken); | - | ||||||||||||||||||||||||
| 2549 | long int pid = strtol(tracerPid, &tracerPid, 10); | - | ||||||||||||||||||||||||
| 2550 | close(fd); | - | ||||||||||||||||||||||||
| 2551 | return pid != 0; executed 1237 times by 539 tests: return pid != 0;Executed by:
| 1237 | ||||||||||||||||||||||||
| 2552 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 2553 | return IsDebuggerPresent(); | - | ||||||||||||||||||||||||
| 2554 | #else | - | ||||||||||||||||||||||||
| 2555 | // TODO | - | ||||||||||||||||||||||||
| 2556 | return false; | - | ||||||||||||||||||||||||
| 2557 | #endif | - | ||||||||||||||||||||||||
| 2558 | } | - | ||||||||||||||||||||||||
| 2559 | - | |||||||||||||||||||||||||
| 2560 | static void qInvokeTestMethods(QObject *testObject) | - | ||||||||||||||||||||||||
| 2561 | { | - | ||||||||||||||||||||||||
| 2562 | const QMetaObject *metaObject = testObject->metaObject(); | - | ||||||||||||||||||||||||
| 2563 | QTEST_ASSERT(metaObject); never executed: qt_assert("metaObject",__FILE__,2563);
| 0-1237 | ||||||||||||||||||||||||
| 2564 | QTestLog::startLogging(); | - | ||||||||||||||||||||||||
| 2565 | QTestResult::setCurrentTestFunction("initTestCase"); | - | ||||||||||||||||||||||||
| 2566 | QTestTable::globalTestTable(); | - | ||||||||||||||||||||||||
| 2567 | invokeMethod(testObject, "initTestCase_data()"); | - | ||||||||||||||||||||||||
| 2568 | - | |||||||||||||||||||||||||
| 2569 | QScopedPointer<WatchDog> watchDog; | - | ||||||||||||||||||||||||
| 2570 | if (!debuggerPresent()
| 0-1237 | ||||||||||||||||||||||||
| 2571 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
| 2572 | && QBenchmarkGlobalData::current->mode() != QBenchmarkGlobalData::CallgrindChildProcess
| 0-1237 | ||||||||||||||||||||||||
| 2573 | #endif | - | ||||||||||||||||||||||||
| 2574 | ) { | - | ||||||||||||||||||||||||
| 2575 | watchDog.reset(new WatchDog); | - | ||||||||||||||||||||||||
| 2576 | } executed 1237 times by 539 tests: end of blockExecuted by:
| 1237 | ||||||||||||||||||||||||
| 2577 | - | |||||||||||||||||||||||||
| 2578 | if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) {
| 21-1216 | ||||||||||||||||||||||||
| 2579 | invokeMethod(testObject, "initTestCase()"); | - | ||||||||||||||||||||||||
| 2580 | - | |||||||||||||||||||||||||
| 2581 | // finishedCurrentTestDataCleanup() resets QTestResult::currentTestFailed(), so use a local copy. | - | ||||||||||||||||||||||||
| 2582 | const bool previousFailed = QTestResult::currentTestFailed(); | - | ||||||||||||||||||||||||
| 2583 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||||||||||||||
| 2584 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||||||||||||||
| 2585 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
| 2586 | - | |||||||||||||||||||||||||
| 2587 | if (!QTestResult::skipCurrentTest() && !previousFailed) {
| 22-1173 | ||||||||||||||||||||||||
| 2588 | - | |||||||||||||||||||||||||
| 2589 | if (QTest::testFuncs) {
| 35-1115 | ||||||||||||||||||||||||
| 2590 | for (int i = 0; i != QTest::testFuncCount; i++) {
| 35-56 | ||||||||||||||||||||||||
| 2591 | if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i].function()).methodSignature().constData(),
| 0-56 | ||||||||||||||||||||||||
| 2592 | QTest::testFuncs[i].data(), watchDog.data())) {
| 0-56 | ||||||||||||||||||||||||
| 2593 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2594 | } | - | ||||||||||||||||||||||||
| 2595 | } executed 56 times by 1 test: end of blockExecuted by:
| 56 | ||||||||||||||||||||||||
| 2596 | testFuncCleaner.cleanup(); | - | ||||||||||||||||||||||||
| 2597 | } else { executed 35 times by 1 test: end of blockExecuted by:
| 35 | ||||||||||||||||||||||||
| 2598 | int methodCount = metaObject->methodCount(); | - | ||||||||||||||||||||||||
| 2599 | QMetaMethod *testMethods = new QMetaMethod[methodCount]; | - | ||||||||||||||||||||||||
| 2600 | for (int i = 0; i != methodCount; i++)
| 1115-24649 | ||||||||||||||||||||||||
| 2601 | testMethods[i] = metaObject->method(i); executed 24649 times by 536 tests: testMethods[i] = metaObject->method(i);Executed by:
| 24649 | ||||||||||||||||||||||||
| 2602 | for (int i = 0; i != methodCount; i++) {
| 1045-24626 | ||||||||||||||||||||||||
| 2603 | if (!isValidSlot(testMethods[i]))
| 11570-13056 | ||||||||||||||||||||||||
| 2604 | continue; executed 11570 times by 537 tests: continue;Executed by:
| 11570 | ||||||||||||||||||||||||
| 2605 | if (!qInvokeTestMethod(testMethods[i].methodSignature().constData(), 0, watchDog.data()))
| 0-12986 | ||||||||||||||||||||||||
| 2606 | break; never executed: break; | 0 | ||||||||||||||||||||||||
| 2607 | } executed 12986 times by 535 tests: end of blockExecuted by:
| 12986 | ||||||||||||||||||||||||
| 2608 | delete[] testMethods; | - | ||||||||||||||||||||||||
| 2609 | testMethods = 0; | - | ||||||||||||||||||||||||
| 2610 | } executed 1045 times by 535 tests: end of blockExecuted by:
| 1045 | ||||||||||||||||||||||||
| 2611 | } | - | ||||||||||||||||||||||||
| 2612 | - | |||||||||||||||||||||||||
| 2613 | QTestResult::setSkipCurrentTest(false); | - | ||||||||||||||||||||||||
| 2614 | QTestResult::setBlacklistCurrentTest(false); | - | ||||||||||||||||||||||||
| 2615 | QTestResult::setCurrentTestFunction("cleanupTestCase"); | - | ||||||||||||||||||||||||
| 2616 | invokeMethod(testObject, "cleanupTestCase()"); | - | ||||||||||||||||||||||||
| 2617 | QTestResult::finishedCurrentTestData(); | - | ||||||||||||||||||||||||
| 2618 | QTestResult::finishedCurrentTestDataCleanup(); | - | ||||||||||||||||||||||||
| 2619 | } executed 1125 times by 538 tests: end of blockExecuted by:
| 1125 | ||||||||||||||||||||||||
| 2620 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
| 2621 | QTestResult::setCurrentTestFunction(0); | - | ||||||||||||||||||||||||
| 2622 | QTestTable::clearGlobalTestTable(); | - | ||||||||||||||||||||||||
| 2623 | - | |||||||||||||||||||||||||
| 2624 | QTestLog::stopLogging(); | - | ||||||||||||||||||||||||
| 2625 | } executed 1167 times by 541 tests: end of blockExecuted by:
| 1167 | ||||||||||||||||||||||||
| 2626 | - | |||||||||||||||||||||||||
| 2627 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 2628 | class FatalSignalHandler | - | ||||||||||||||||||||||||
| 2629 | { | - | ||||||||||||||||||||||||
| 2630 | public: | - | ||||||||||||||||||||||||
| 2631 | FatalSignalHandler(); | - | ||||||||||||||||||||||||
| 2632 | ~FatalSignalHandler(); | - | ||||||||||||||||||||||||
| 2633 | - | |||||||||||||||||||||||||
| 2634 | private: | - | ||||||||||||||||||||||||
| 2635 | static void signal(int); | - | ||||||||||||||||||||||||
| 2636 | sigset_t handledSignals; | - | ||||||||||||||||||||||||
| 2637 | }; | - | ||||||||||||||||||||||||
| 2638 | - | |||||||||||||||||||||||||
| 2639 | void FatalSignalHandler::signal(int signum) | - | ||||||||||||||||||||||||
| 2640 | { | - | ||||||||||||||||||||||||
| 2641 | const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); | - | ||||||||||||||||||||||||
| 2642 | const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); | - | ||||||||||||||||||||||||
| 2643 | if (signum != SIGINT)
| 0 | ||||||||||||||||||||||||
| 2644 | stackTrace(); never executed: stackTrace(); | 0 | ||||||||||||||||||||||||
| 2645 | qFatal("Received signal %d\n" | - | ||||||||||||||||||||||||
| 2646 | " Function time: %dms Total time: %dms", | - | ||||||||||||||||||||||||
| 2647 | signum, msecsFunctionTime, msecsTotalTime); | - | ||||||||||||||||||||||||
| 2648 | #if defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
| 2649 | { | - | ||||||||||||||||||||||||
| 2650 | struct sigaction act; | - | ||||||||||||||||||||||||
| 2651 | memset(&act, 0, sizeof(struct sigaction)); | - | ||||||||||||||||||||||||
| 2652 | act.sa_handler = SIG_DFL; | - | ||||||||||||||||||||||||
| 2653 | sigaction(signum, &act, NULL); | - | ||||||||||||||||||||||||
| 2654 | } | - | ||||||||||||||||||||||||
| 2655 | #endif | - | ||||||||||||||||||||||||
| 2656 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 2657 | - | |||||||||||||||||||||||||
| 2658 | FatalSignalHandler::FatalSignalHandler() | - | ||||||||||||||||||||||||
| 2659 | { | - | ||||||||||||||||||||||||
| 2660 | sigemptyset(&handledSignals); | - | ||||||||||||||||||||||||
| 2661 | - | |||||||||||||||||||||||||
| 2662 | const int fatalSignals[] = { | - | ||||||||||||||||||||||||
| 2663 | SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGBUS, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 }; | - | ||||||||||||||||||||||||
| 2664 | - | |||||||||||||||||||||||||
| 2665 | struct sigaction act; | - | ||||||||||||||||||||||||
| 2666 | memset(&act, 0, sizeof(act)); | - | ||||||||||||||||||||||||
| 2667 | act.sa_handler = FatalSignalHandler::signal; | - | ||||||||||||||||||||||||
| 2668 | - | |||||||||||||||||||||||||
| 2669 | // Remove the handler after it is invoked. | - | ||||||||||||||||||||||||
| 2670 | #if !defined(Q_OS_INTEGRITY) | - | ||||||||||||||||||||||||
| 2671 | act.sa_flags = SA_RESETHAND; | - | ||||||||||||||||||||||||
| 2672 | #endif | - | ||||||||||||||||||||||||
| 2673 | - | |||||||||||||||||||||||||
| 2674 | #ifdef SA_ONSTACK | - | ||||||||||||||||||||||||
| 2675 | // Let the signal handlers use an alternate stack | - | ||||||||||||||||||||||||
| 2676 | // This is necessary if SIGSEGV is to catch a stack overflow | - | ||||||||||||||||||||||||
| 2677 | # if defined(Q_CC_GNU) && defined(Q_OF_ELF) | - | ||||||||||||||||||||||||
| 2678 | // Put the alternate stack in the .lbss (large BSS) section so that it doesn't | - | ||||||||||||||||||||||||
| 2679 | // interfere with normal .bss symbols | - | ||||||||||||||||||||||||
| 2680 | __attribute__((section(".lbss.altstack"), aligned(4096))) | - | ||||||||||||||||||||||||
| 2681 | # endif | - | ||||||||||||||||||||||||
| 2682 | static char alternate_stack[16 * 1024]; | - | ||||||||||||||||||||||||
| 2683 | stack_t stack; | - | ||||||||||||||||||||||||
| 2684 | stack.ss_flags = 0; | - | ||||||||||||||||||||||||
| 2685 | stack.ss_size = sizeof alternate_stack; | - | ||||||||||||||||||||||||
| 2686 | stack.ss_sp = alternate_stack; | - | ||||||||||||||||||||||||
| 2687 | sigaltstack(&stack, 0); | - | ||||||||||||||||||||||||
| 2688 | act.sa_flags |= SA_ONSTACK; | - | ||||||||||||||||||||||||
| 2689 | #endif | - | ||||||||||||||||||||||||
| 2690 | - | |||||||||||||||||||||||||
| 2691 | // Block all fatal signals in our signal handler so we don't try to close | - | ||||||||||||||||||||||||
| 2692 | // the testlog twice. | - | ||||||||||||||||||||||||
| 2693 | sigemptyset(&act.sa_mask); | - | ||||||||||||||||||||||||
| 2694 | for (int i = 0; fatalSignals[i]; ++i)
| 1237-11133 | ||||||||||||||||||||||||
| 2695 | sigaddset(&act.sa_mask, fatalSignals[i]); executed 11133 times by 539 tests: sigaddset(&act.sa_mask, fatalSignals[i]);Executed by:
| 11133 | ||||||||||||||||||||||||
| 2696 | - | |||||||||||||||||||||||||
| 2697 | struct sigaction oldact; | - | ||||||||||||||||||||||||
| 2698 | - | |||||||||||||||||||||||||
| 2699 | for (int i = 0; fatalSignals[i]; ++i) {
| 1237-11133 | ||||||||||||||||||||||||
| 2700 | sigaction(fatalSignals[i], &act, &oldact); | - | ||||||||||||||||||||||||
| 2701 | if ( | - | ||||||||||||||||||||||||
| 2702 | #ifdef SA_SIGINFO | - | ||||||||||||||||||||||||
| 2703 | oldact.sa_flags & SA_SIGINFO ||
| 0-11133 | ||||||||||||||||||||||||
| 2704 | #endif | - | ||||||||||||||||||||||||
| 2705 | oldact.sa_handler != SIG_DFL) {
| 4948-6185 | ||||||||||||||||||||||||
| 2706 | sigaction(fatalSignals[i], &oldact, 0); | - | ||||||||||||||||||||||||
| 2707 | } else executed 6185 times by 539 tests: end of blockExecuted by:
| 6185 | ||||||||||||||||||||||||
| 2708 | { | - | ||||||||||||||||||||||||
| 2709 | sigaddset(&handledSignals, fatalSignals[i]); | - | ||||||||||||||||||||||||
| 2710 | } executed 4948 times by 539 tests: end of blockExecuted by:
| 4948 | ||||||||||||||||||||||||
| 2711 | } | - | ||||||||||||||||||||||||
| 2712 | } executed 1237 times by 539 tests: end of blockExecuted by:
| 1237 | ||||||||||||||||||||||||
| 2713 | - | |||||||||||||||||||||||||
| 2714 | - | |||||||||||||||||||||||||
| 2715 | FatalSignalHandler::~FatalSignalHandler() | - | ||||||||||||||||||||||||
| 2716 | { | - | ||||||||||||||||||||||||
| 2717 | // Unregister any of our remaining signal handlers | - | ||||||||||||||||||||||||
| 2718 | struct sigaction act; | - | ||||||||||||||||||||||||
| 2719 | memset(&act, 0, sizeof(act)); | - | ||||||||||||||||||||||||
| 2720 | act.sa_handler = SIG_DFL; | - | ||||||||||||||||||||||||
| 2721 | - | |||||||||||||||||||||||||
| 2722 | struct sigaction oldact; | - | ||||||||||||||||||||||||
| 2723 | - | |||||||||||||||||||||||||
| 2724 | for (int i = 1; i < 32; ++i) {
| 1188-36828 | ||||||||||||||||||||||||
| 2725 | if (!sigismember(&handledSignals, i))
| 4752-32076 | ||||||||||||||||||||||||
| 2726 | continue; executed 32076 times by 541 tests: continue;Executed by:
| 32076 | ||||||||||||||||||||||||
| 2727 | sigaction(i, &act, &oldact); | - | ||||||||||||||||||||||||
| 2728 | - | |||||||||||||||||||||||||
| 2729 | // If someone overwrote it in the mean time, put it back | - | ||||||||||||||||||||||||
| 2730 | if (oldact.sa_handler != FatalSignalHandler::signal)
| 69-4683 | ||||||||||||||||||||||||
| 2731 | sigaction(i, &oldact, 0); executed 69 times by 69 tests: sigaction(i, &oldact, 0);Executed by:
| 69 | ||||||||||||||||||||||||
| 2732 | } executed 4752 times by 541 tests: end of blockExecuted by:
| 4752 | ||||||||||||||||||||||||
| 2733 | } executed 1188 times by 541 tests: end of blockExecuted by:
| 1188 | ||||||||||||||||||||||||
| 2734 | - | |||||||||||||||||||||||||
| 2735 | #endif | - | ||||||||||||||||||||||||
| 2736 | - | |||||||||||||||||||||||||
| 2737 | - | |||||||||||||||||||||||||
| 2738 | } // namespace | - | ||||||||||||||||||||||||
| 2739 | - | |||||||||||||||||||||||||
| 2740 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 2741 | - | |||||||||||||||||||||||||
| 2742 | // Helper class for resolving symbol names by dynamically loading "dbghelp.dll". | - | ||||||||||||||||||||||||
| 2743 | class DebugSymbolResolver | - | ||||||||||||||||||||||||
| 2744 | { | - | ||||||||||||||||||||||||
| 2745 | Q_DISABLE_COPY(DebugSymbolResolver) | - | ||||||||||||||||||||||||
| 2746 | public: | - | ||||||||||||||||||||||||
| 2747 | struct Symbol { | - | ||||||||||||||||||||||||
| 2748 | Symbol() : name(Q_NULLPTR), address(0) {} | - | ||||||||||||||||||||||||
| 2749 | - | |||||||||||||||||||||||||
| 2750 | const char *name; // Must be freed by caller. | - | ||||||||||||||||||||||||
| 2751 | DWORD64 address; | - | ||||||||||||||||||||||||
| 2752 | }; | - | ||||||||||||||||||||||||
| 2753 | - | |||||||||||||||||||||||||
| 2754 | explicit DebugSymbolResolver(HANDLE process); | - | ||||||||||||||||||||||||
| 2755 | ~DebugSymbolResolver() { cleanup(); } | - | ||||||||||||||||||||||||
| 2756 | - | |||||||||||||||||||||||||
| 2757 | bool isValid() const { return m_symFromAddr; } | - | ||||||||||||||||||||||||
| 2758 | - | |||||||||||||||||||||||||
| 2759 | Symbol resolveSymbol(DWORD64 address) const; | - | ||||||||||||||||||||||||
| 2760 | - | |||||||||||||||||||||||||
| 2761 | private: | - | ||||||||||||||||||||||||
| 2762 | // typedefs from DbgHelp.h/.dll | - | ||||||||||||||||||||||||
| 2763 | struct DBGHELP_SYMBOL_INFO { // SYMBOL_INFO | - | ||||||||||||||||||||||||
| 2764 | ULONG SizeOfStruct; | - | ||||||||||||||||||||||||
| 2765 | ULONG TypeIndex; // Type Index of symbol | - | ||||||||||||||||||||||||
| 2766 | ULONG64 Reserved[2]; | - | ||||||||||||||||||||||||
| 2767 | ULONG Index; | - | ||||||||||||||||||||||||
| 2768 | ULONG Size; | - | ||||||||||||||||||||||||
| 2769 | ULONG64 ModBase; // Base Address of module comtaining this symbol | - | ||||||||||||||||||||||||
| 2770 | ULONG Flags; | - | ||||||||||||||||||||||||
| 2771 | ULONG64 Value; // Value of symbol, ValuePresent should be 1 | - | ||||||||||||||||||||||||
| 2772 | ULONG64 Address; // Address of symbol including base address of module | - | ||||||||||||||||||||||||
| 2773 | ULONG Register; // register holding value or pointer to value | - | ||||||||||||||||||||||||
| 2774 | ULONG Scope; // scope of the symbol | - | ||||||||||||||||||||||||
| 2775 | ULONG Tag; // pdb classification | - | ||||||||||||||||||||||||
| 2776 | ULONG NameLen; // Actual length of name | - | ||||||||||||||||||||||||
| 2777 | ULONG MaxNameLen; | - | ||||||||||||||||||||||||
| 2778 | CHAR Name[1]; // Name of symbol | - | ||||||||||||||||||||||||
| 2779 | }; | - | ||||||||||||||||||||||||
| 2780 | - | |||||||||||||||||||||||||
| 2781 | typedef BOOL (__stdcall *SymInitializeType)(HANDLE, PCSTR, BOOL); | - | ||||||||||||||||||||||||
| 2782 | typedef BOOL (__stdcall *SymFromAddrType)(HANDLE, DWORD64, PDWORD64, DBGHELP_SYMBOL_INFO *); | - | ||||||||||||||||||||||||
| 2783 | - | |||||||||||||||||||||||||
| 2784 | void cleanup(); | - | ||||||||||||||||||||||||
| 2785 | - | |||||||||||||||||||||||||
| 2786 | const HANDLE m_process; | - | ||||||||||||||||||||||||
| 2787 | HMODULE m_dbgHelpLib; | - | ||||||||||||||||||||||||
| 2788 | SymFromAddrType m_symFromAddr; | - | ||||||||||||||||||||||||
| 2789 | }; | - | ||||||||||||||||||||||||
| 2790 | - | |||||||||||||||||||||||||
| 2791 | void DebugSymbolResolver::cleanup() | - | ||||||||||||||||||||||||
| 2792 | { | - | ||||||||||||||||||||||||
| 2793 | if (m_dbgHelpLib) | - | ||||||||||||||||||||||||
| 2794 | FreeLibrary(m_dbgHelpLib); | - | ||||||||||||||||||||||||
| 2795 | m_dbgHelpLib = 0; | - | ||||||||||||||||||||||||
| 2796 | m_symFromAddr = Q_NULLPTR; | - | ||||||||||||||||||||||||
| 2797 | } | - | ||||||||||||||||||||||||
| 2798 | - | |||||||||||||||||||||||||
| 2799 | DebugSymbolResolver::DebugSymbolResolver(HANDLE process) | - | ||||||||||||||||||||||||
| 2800 | : m_process(process), m_dbgHelpLib(0), m_symFromAddr(Q_NULLPTR) | - | ||||||||||||||||||||||||
| 2801 | { | - | ||||||||||||||||||||||||
| 2802 | bool success = false; | - | ||||||||||||||||||||||||
| 2803 | m_dbgHelpLib = LoadLibraryW(L"dbghelp.dll"); | - | ||||||||||||||||||||||||
| 2804 | if (m_dbgHelpLib) { | - | ||||||||||||||||||||||||
| 2805 | SymInitializeType symInitialize = (SymInitializeType)(GetProcAddress(m_dbgHelpLib, "SymInitialize")); | - | ||||||||||||||||||||||||
| 2806 | m_symFromAddr = (SymFromAddrType)(GetProcAddress(m_dbgHelpLib, "SymFromAddr")); | - | ||||||||||||||||||||||||
| 2807 | success = symInitialize && m_symFromAddr && symInitialize(process, NULL, TRUE); | - | ||||||||||||||||||||||||
| 2808 | } | - | ||||||||||||||||||||||||
| 2809 | if (!success) | - | ||||||||||||||||||||||||
| 2810 | cleanup(); | - | ||||||||||||||||||||||||
| 2811 | } | - | ||||||||||||||||||||||||
| 2812 | - | |||||||||||||||||||||||||
| 2813 | DebugSymbolResolver::Symbol DebugSymbolResolver::resolveSymbol(DWORD64 address) const | - | ||||||||||||||||||||||||
| 2814 | { | - | ||||||||||||||||||||||||
| 2815 | // reserve additional buffer where SymFromAddr() will store the name | - | ||||||||||||||||||||||||
| 2816 | struct NamedSymbolInfo : public DBGHELP_SYMBOL_INFO { | - | ||||||||||||||||||||||||
| 2817 | enum { symbolNameLength = 255 }; | - | ||||||||||||||||||||||||
| 2818 | - | |||||||||||||||||||||||||
| 2819 | char name[symbolNameLength + 1]; | - | ||||||||||||||||||||||||
| 2820 | }; | - | ||||||||||||||||||||||||
| 2821 | - | |||||||||||||||||||||||||
| 2822 | Symbol result; | - | ||||||||||||||||||||||||
| 2823 | if (!isValid()) | - | ||||||||||||||||||||||||
| 2824 | return result; | - | ||||||||||||||||||||||||
| 2825 | NamedSymbolInfo symbolBuffer; | - | ||||||||||||||||||||||||
| 2826 | memset(&symbolBuffer, 0, sizeof(NamedSymbolInfo)); | - | ||||||||||||||||||||||||
| 2827 | symbolBuffer.MaxNameLen = NamedSymbolInfo::symbolNameLength; | - | ||||||||||||||||||||||||
| 2828 | symbolBuffer.SizeOfStruct = sizeof(DBGHELP_SYMBOL_INFO); | - | ||||||||||||||||||||||||
| 2829 | if (!m_symFromAddr(m_process, address, 0, &symbolBuffer)) | - | ||||||||||||||||||||||||
| 2830 | return result; | - | ||||||||||||||||||||||||
| 2831 | result.name = qstrdup(symbolBuffer.Name); | - | ||||||||||||||||||||||||
| 2832 | result.address = symbolBuffer.Address; | - | ||||||||||||||||||||||||
| 2833 | return result; | - | ||||||||||||||||||||||||
| 2834 | } | - | ||||||||||||||||||||||||
| 2835 | - | |||||||||||||||||||||||||
| 2836 | static LONG WINAPI windowsFaultHandler(struct _EXCEPTION_POINTERS *exInfo) | - | ||||||||||||||||||||||||
| 2837 | { | - | ||||||||||||||||||||||||
| 2838 | enum { maxStackFrames = 100 }; | - | ||||||||||||||||||||||||
| 2839 | char appName[MAX_PATH]; | - | ||||||||||||||||||||||||
| 2840 | if (!GetModuleFileNameA(NULL, appName, MAX_PATH)) | - | ||||||||||||||||||||||||
| 2841 | appName[0] = 0; | - | ||||||||||||||||||||||||
| 2842 | const int msecsFunctionTime = qRound(QTestLog::msecsFunctionTime()); | - | ||||||||||||||||||||||||
| 2843 | const int msecsTotalTime = qRound(QTestLog::msecsTotalTime()); | - | ||||||||||||||||||||||||
| 2844 | const void *exceptionAddress = exInfo->ExceptionRecord->ExceptionAddress; | - | ||||||||||||||||||||||||
| 2845 | printf("A crash occurred in %s.\n" | - | ||||||||||||||||||||||||
| 2846 | "Function time: %dms Total time: %dms\n\n" | - | ||||||||||||||||||||||||
| 2847 | "Exception address: 0x%p\n" | - | ||||||||||||||||||||||||
| 2848 | "Exception code : 0x%lx\n", | - | ||||||||||||||||||||||||
| 2849 | appName, msecsFunctionTime, msecsTotalTime, | - | ||||||||||||||||||||||||
| 2850 | exceptionAddress, exInfo->ExceptionRecord->ExceptionCode); | - | ||||||||||||||||||||||||
| 2851 | - | |||||||||||||||||||||||||
| 2852 | DebugSymbolResolver resolver(GetCurrentProcess()); | - | ||||||||||||||||||||||||
| 2853 | if (resolver.isValid()) { | - | ||||||||||||||||||||||||
| 2854 | DebugSymbolResolver::Symbol exceptionSymbol = resolver.resolveSymbol(DWORD64(exceptionAddress)); | - | ||||||||||||||||||||||||
| 2855 | if (exceptionSymbol.name) { | - | ||||||||||||||||||||||||
| 2856 | printf("Nearby symbol : %s\n", exceptionSymbol.name); | - | ||||||||||||||||||||||||
| 2857 | delete [] exceptionSymbol.name; | - | ||||||||||||||||||||||||
| 2858 | } | - | ||||||||||||||||||||||||
| 2859 | void *stack[maxStackFrames]; | - | ||||||||||||||||||||||||
| 2860 | fputs("\nStack:\n", stdout); | - | ||||||||||||||||||||||||
| 2861 | const unsigned frameCount = CaptureStackBackTrace(0, DWORD(maxStackFrames), stack, NULL); | - | ||||||||||||||||||||||||
| 2862 | for (unsigned f = 0; f < frameCount; ++f) { | - | ||||||||||||||||||||||||
| 2863 | DebugSymbolResolver::Symbol symbol = resolver.resolveSymbol(DWORD64(stack[f])); | - | ||||||||||||||||||||||||
| 2864 | if (symbol.name) { | - | ||||||||||||||||||||||||
| 2865 | printf("#%3u: %s() - 0x%p\n", f + 1, symbol.name, (const void *)symbol.address); | - | ||||||||||||||||||||||||
| 2866 | delete [] symbol.name; | - | ||||||||||||||||||||||||
| 2867 | } else { | - | ||||||||||||||||||||||||
| 2868 | printf("#%3u: Unable to obtain symbol\n", f + 1); | - | ||||||||||||||||||||||||
| 2869 | } | - | ||||||||||||||||||||||||
| 2870 | } | - | ||||||||||||||||||||||||
| 2871 | } | - | ||||||||||||||||||||||||
| 2872 | - | |||||||||||||||||||||||||
| 2873 | fputc('\n', stdout); | - | ||||||||||||||||||||||||
| 2874 | fflush(stdout); | - | ||||||||||||||||||||||||
| 2875 | - | |||||||||||||||||||||||||
| 2876 | return EXCEPTION_EXECUTE_HANDLER; | - | ||||||||||||||||||||||||
| 2877 | } | - | ||||||||||||||||||||||||
| 2878 | #endif // Q_OS_WIN) && !Q_OS_WINCE && !Q_OS_WINRT | - | ||||||||||||||||||||||||
| 2879 | - | |||||||||||||||||||||||||
| 2880 | static void initEnvironment() | - | ||||||||||||||||||||||||
| 2881 | { | - | ||||||||||||||||||||||||
| 2882 | qputenv("QT_LOGGING_TO_CONSOLE", "1"); | - | ||||||||||||||||||||||||
| 2883 | qputenv("QT_QTESTLIB_RUNNING", "1"); | - | ||||||||||||||||||||||||
| 2884 | } executed 699 times by 1 test: end of blockExecuted by:
| 699 | ||||||||||||||||||||||||
| 2885 | - | |||||||||||||||||||||||||
| 2886 | /*! | - | ||||||||||||||||||||||||
| 2887 | Executes tests declared in \a testObject. In addition, the private slots | - | ||||||||||||||||||||||||
| 2888 | \c{initTestCase()}, \c{cleanupTestCase()}, \c{init()} and \c{cleanup()} | - | ||||||||||||||||||||||||
| 2889 | are executed if they exist. See \l{Creating a Test} for more details. | - | ||||||||||||||||||||||||
| 2890 | - | |||||||||||||||||||||||||
| 2891 | Optionally, the command line arguments \a argc and \a argv can be provided. | - | ||||||||||||||||||||||||
| 2892 | For a list of recognized arguments, read \l {Qt Test Command Line Arguments}. | - | ||||||||||||||||||||||||
| 2893 | - | |||||||||||||||||||||||||
| 2894 | The following example will run all tests in \c MyTestObject: | - | ||||||||||||||||||||||||
| 2895 | - | |||||||||||||||||||||||||
| 2896 | \snippet code/src_qtestlib_qtestcase.cpp 18 | - | ||||||||||||||||||||||||
| 2897 | - | |||||||||||||||||||||||||
| 2898 | This function returns 0 if no tests failed, or a value other than 0 if one | - | ||||||||||||||||||||||||
| 2899 | or more tests failed or in case of unhandled exceptions. (Skipped tests do | - | ||||||||||||||||||||||||
| 2900 | not influence the return value.) | - | ||||||||||||||||||||||||
| 2901 | - | |||||||||||||||||||||||||
| 2902 | For stand-alone test applications, the convenience macro \l QTEST_MAIN() can | - | ||||||||||||||||||||||||
| 2903 | be used to declare a main() function that parses the command line arguments | - | ||||||||||||||||||||||||
| 2904 | and executes the tests, avoiding the need to call this function explicitly. | - | ||||||||||||||||||||||||
| 2905 | - | |||||||||||||||||||||||||
| 2906 | The return value from this function is also the exit code of the test | - | ||||||||||||||||||||||||
| 2907 | application when the \l QTEST_MAIN() macro is used. | - | ||||||||||||||||||||||||
| 2908 | - | |||||||||||||||||||||||||
| 2909 | For stand-alone test applications, this function should not be called more | - | ||||||||||||||||||||||||
| 2910 | than once, as command-line options for logging test output to files and | - | ||||||||||||||||||||||||
| 2911 | executing individual test functions will not behave correctly. | - | ||||||||||||||||||||||||
| 2912 | - | |||||||||||||||||||||||||
| 2913 | Note: This function is not reentrant, only one test can run at a time. A | - | ||||||||||||||||||||||||
| 2914 | test that was executed with qExec() can't run another test via qExec() and | - | ||||||||||||||||||||||||
| 2915 | threads are not allowed to call qExec() simultaneously. | - | ||||||||||||||||||||||||
| 2916 | - | |||||||||||||||||||||||||
| 2917 | If you have programatically created the arguments, as opposed to getting them | - | ||||||||||||||||||||||||
| 2918 | from the arguments in \c main(), it is likely of interest to use | - | ||||||||||||||||||||||||
| 2919 | QTest::qExec(QObject *, const QStringList &) since it is Unicode safe. | - | ||||||||||||||||||||||||
| 2920 | - | |||||||||||||||||||||||||
| 2921 | \sa QTEST_MAIN() | - | ||||||||||||||||||||||||
| 2922 | */ | - | ||||||||||||||||||||||||
| 2923 | - | |||||||||||||||||||||||||
| 2924 | int QTest::qExec(QObject *testObject, int argc, char **argv) | - | ||||||||||||||||||||||||
| 2925 | { | - | ||||||||||||||||||||||||
| 2926 | initEnvironment(); | - | ||||||||||||||||||||||||
| 2927 | QBenchmarkGlobalData benchmarkData; | - | ||||||||||||||||||||||||
| 2928 | QBenchmarkGlobalData::current = &benchmarkData; | - | ||||||||||||||||||||||||
| 2929 | - | |||||||||||||||||||||||||
| 2930 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
| 2931 | int callgrindChildExitCode = 0; | - | ||||||||||||||||||||||||
| 2932 | #endif | - | ||||||||||||||||||||||||
| 2933 | - | |||||||||||||||||||||||||
| 2934 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
| 2935 | bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0); | - | ||||||||||||||||||||||||
| 2936 | IOPMAssertionID powerID; | - | ||||||||||||||||||||||||
| 2937 | - | |||||||||||||||||||||||||
| 2938 | // Don't restore saved window state for auto tests. | - | ||||||||||||||||||||||||
| 2939 | QTestPrivate::disableWindowRestore(); | - | ||||||||||||||||||||||||
| 2940 | #endif | - | ||||||||||||||||||||||||
| 2941 | #ifndef QT_NO_EXCEPTIONS | - | ||||||||||||||||||||||||
| 2942 | try { | - | ||||||||||||||||||||||||
| 2943 | #endif | - | ||||||||||||||||||||||||
| 2944 | - | |||||||||||||||||||||||||
| 2945 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
| 2946 | if (macNeedsActivate) { | - | ||||||||||||||||||||||||
| 2947 | CFStringRef reasonForActivity= CFSTR("No Display Sleep"); | - | ||||||||||||||||||||||||
| 2948 | IOReturn ok = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &powerID); | - | ||||||||||||||||||||||||
| 2949 | - | |||||||||||||||||||||||||
| 2950 | if (ok != kIOReturnSuccess) | - | ||||||||||||||||||||||||
| 2951 | macNeedsActivate = false; // no need to release the assertion on exit. | - | ||||||||||||||||||||||||
| 2952 | } | - | ||||||||||||||||||||||||
| 2953 | #endif | - | ||||||||||||||||||||||||
| 2954 | - | |||||||||||||||||||||||||
| 2955 | QTestPrivate::parseBlackList(); | - | ||||||||||||||||||||||||
| 2956 | QTestPrivate::parseGpuBlackList(); | - | ||||||||||||||||||||||||
| 2957 | - | |||||||||||||||||||||||||
| 2958 | QTestResult::reset(); | - | ||||||||||||||||||||||||
| 2959 | - | |||||||||||||||||||||||||
| 2960 | QTEST_ASSERT(testObject); never executed: qt_assert("testObject",__FILE__,2960);
| 0-699 | ||||||||||||||||||||||||
| 2961 | QTEST_ASSERT(!currentTestObject); never executed: qt_assert("!currentTestObject",__FILE__,2961);
| 0-699 | ||||||||||||||||||||||||
| 2962 | currentTestObject = testObject; | - | ||||||||||||||||||||||||
| 2963 | - | |||||||||||||||||||||||||
| 2964 | const QMetaObject *metaObject = testObject->metaObject(); | - | ||||||||||||||||||||||||
| 2965 | QTEST_ASSERT(metaObject); never executed: qt_assert("metaObject",__FILE__,2965);
| 0-699 | ||||||||||||||||||||||||
| 2966 | - | |||||||||||||||||||||||||
| 2967 | QTestResult::setCurrentTestObject(metaObject->className()); | - | ||||||||||||||||||||||||
| 2968 | if (argc > 0)
| 0-699 | ||||||||||||||||||||||||
| 2969 | QTestResult::setCurrentAppName(argv[0]); executed 699 times by 1 test: QTestResult::setCurrentAppName(argv[0]);Executed by:
| 699 | ||||||||||||||||||||||||
| 2970 | - | |||||||||||||||||||||||||
| 2971 | qtest_qParseArgs(argc, argv, false); | - | ||||||||||||||||||||||||
| 2972 | - | |||||||||||||||||||||||||
| 2973 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - | ||||||||||||||||||||||||
| 2974 | if (!noCrashHandler) { | - | ||||||||||||||||||||||||
| 2975 | # ifndef Q_CC_MINGW | - | ||||||||||||||||||||||||
| 2976 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); | - | ||||||||||||||||||||||||
| 2977 | # endif | - | ||||||||||||||||||||||||
| 2978 | # ifndef Q_OS_WINRT | - | ||||||||||||||||||||||||
| 2979 | SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); | - | ||||||||||||||||||||||||
| 2980 | SetUnhandledExceptionFilter(windowsFaultHandler); | - | ||||||||||||||||||||||||
| 2981 | # endif | - | ||||||||||||||||||||||||
| 2982 | } // !noCrashHandler | - | ||||||||||||||||||||||||
| 2983 | #endif // Q_OS_WIN) && !Q_OS_WINCE && !Q_OS_WINRT | - | ||||||||||||||||||||||||
| 2984 | - | |||||||||||||||||||||||||
| 2985 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
| 2986 | if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) {
| 0-1237 | ||||||||||||||||||||||||
| 2987 | if (!qApp)
| 0 | ||||||||||||||||||||||||
| 2988 | qFatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN"); never executed: QMessageLogger(__FILE__, 2988, __PRETTY_FUNCTION__).fatal("QtTest: -callgrind option is not available with QTEST_APPLESS_MAIN"); | 0 | ||||||||||||||||||||||||
| 2989 | - | |||||||||||||||||||||||||
| 2990 | const QStringList origAppArgs(QCoreApplication::arguments()); | - | ||||||||||||||||||||||||
| 2991 | if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode))
| 0 | ||||||||||||||||||||||||
| 2992 | return -1; never executed: return -1; | 0 | ||||||||||||||||||||||||
| 2993 | - | |||||||||||||||||||||||||
| 2994 | QBenchmarkValgrindUtils::cleanup(); | - | ||||||||||||||||||||||||
| 2995 | - | |||||||||||||||||||||||||
| 2996 | } else never executed: end of block | 0 | ||||||||||||||||||||||||
| 2997 | #endif | - | ||||||||||||||||||||||||
| 2998 | { | - | ||||||||||||||||||||||||
| 2999 | #if defined(Q_OS_UNIX) | - | ||||||||||||||||||||||||
| 3000 | QScopedPointer<FatalSignalHandler> handler; | - | ||||||||||||||||||||||||
| 3001 | if (!noCrashHandler)
| 0-1237 | ||||||||||||||||||||||||
| 3002 | handler.reset(new FatalSignalHandler); executed 1237 times by 539 tests: handler.reset(new FatalSignalHandler);Executed by:
| 1237 | ||||||||||||||||||||||||
| 3003 | #endif | - | ||||||||||||||||||||||||
| 3004 | qInvokeTestMethods(testObject); | - | ||||||||||||||||||||||||
| 3005 | } executed 1167 times by 541 tests: end of blockExecuted by:
| 1167 | ||||||||||||||||||||||||
| 3006 | - | |||||||||||||||||||||||||
| 3007 | #ifndef QT_NO_EXCEPTIONS | - | ||||||||||||||||||||||||
| 3008 | } catch (...) { | - | ||||||||||||||||||||||||
| 3009 | QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__); | - | ||||||||||||||||||||||||
| 3010 | if (QTestResult::currentTestFunction()) {
| 0-21 | ||||||||||||||||||||||||
| 3011 | QTestResult::finishedCurrentTestFunction(); | - | ||||||||||||||||||||||||
| 3012 | QTestResult::setCurrentTestFunction(0); | - | ||||||||||||||||||||||||
| 3013 | } executed 21 times by 1 test: end of blockExecuted by:
| 21 | ||||||||||||||||||||||||
| 3014 | - | |||||||||||||||||||||||||
| 3015 | QTestLog::stopLogging(); | - | ||||||||||||||||||||||||
| 3016 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
| 3017 | if (macNeedsActivate) { | - | ||||||||||||||||||||||||
| 3018 | IOPMAssertionRelease(powerID); | - | ||||||||||||||||||||||||
| 3019 | } | - | ||||||||||||||||||||||||
| 3020 | #endif | - | ||||||||||||||||||||||||
| 3021 | currentTestObject = 0; | - | ||||||||||||||||||||||||
| 3022 | - | |||||||||||||||||||||||||
| 3023 | // Rethrow exception to make debugging easier. | - | ||||||||||||||||||||||||
| 3024 | throw; executed 21 times by 1 test: throw;Executed by:
| 21 | ||||||||||||||||||||||||
| 3025 | return 1; dead code: return 1; | - | ||||||||||||||||||||||||
| 3026 | } | - | ||||||||||||||||||||||||
| 3027 | #endif | - | ||||||||||||||||||||||||
| 3028 | - | |||||||||||||||||||||||||
| 3029 | currentTestObject = 0; | - | ||||||||||||||||||||||||
| 3030 | - | |||||||||||||||||||||||||
| 3031 | QSignalDumper::endDump(); | - | ||||||||||||||||||||||||
| 3032 | - | |||||||||||||||||||||||||
| 3033 | #if defined(Q_OS_MACX) | - | ||||||||||||||||||||||||
| 3034 | if (macNeedsActivate) { | - | ||||||||||||||||||||||||
| 3035 | IOPMAssertionRelease(powerID); | - | ||||||||||||||||||||||||
| 3036 | } | - | ||||||||||||||||||||||||
| 3037 | #endif | - | ||||||||||||||||||||||||
| 3038 | - | |||||||||||||||||||||||||
| 3039 | #ifdef QTESTLIB_USE_VALGRIND | - | ||||||||||||||||||||||||
| 3040 | if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess)
| 0-1167 | ||||||||||||||||||||||||
| 3041 | return callgrindChildExitCode; never executed: return callgrindChildExitCode; | 0 | ||||||||||||||||||||||||
| 3042 | #endif | - | ||||||||||||||||||||||||
| 3043 | // make sure our exit code is never going above 127 | - | ||||||||||||||||||||||||
| 3044 | // since that could wrap and indicate 0 test fails | - | ||||||||||||||||||||||||
| 3045 | return qMin(QTestLog::failCount(), 127); executed 1167 times by 541 tests: return qMin(QTestLog::failCount(), 127);Executed by:
| 1167 | ||||||||||||||||||||||||
| 3046 | } | - | ||||||||||||||||||||||||
| 3047 | - | |||||||||||||||||||||||||
| 3048 | /*! | - | ||||||||||||||||||||||||
| 3049 | \overload | - | ||||||||||||||||||||||||
| 3050 | \since 4.4 | - | ||||||||||||||||||||||||
| 3051 | - | |||||||||||||||||||||||||
| 3052 | Behaves identically to qExec(QObject *, int, char**) but takes a | - | ||||||||||||||||||||||||
| 3053 | QStringList of \a arguments instead of a \c char** list. | - | ||||||||||||||||||||||||
| 3054 | */ | - | ||||||||||||||||||||||||
| 3055 | int QTest::qExec(QObject *testObject, const QStringList &arguments) | - | ||||||||||||||||||||||||
| 3056 | { | - | ||||||||||||||||||||||||
| 3057 | const int argc = arguments.count(); | - | ||||||||||||||||||||||||
| 3058 | QVarLengthArray<char *> argv(argc); | - | ||||||||||||||||||||||||
| 3059 | - | |||||||||||||||||||||||||
| 3060 | QVector<QByteArray> args; | - | ||||||||||||||||||||||||
| 3061 | args.reserve(argc); | - | ||||||||||||||||||||||||
| 3062 | - | |||||||||||||||||||||||||
| 3063 | for (int i = 0; i < argc; ++i)
| 12-22 | ||||||||||||||||||||||||
| 3064 | { | - | ||||||||||||||||||||||||
| 3065 | args.append(arguments.at(i).toLocal8Bit().constData()); | - | ||||||||||||||||||||||||
| 3066 | argv[i] = args.last().data(); | - | ||||||||||||||||||||||||
| 3067 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 3068 | - | |||||||||||||||||||||||||
| 3069 | return qExec(testObject, argc, argv.data()); executed 12 times by 1 test: return qExec(testObject, argc, argv.data());Executed by:
| 12 | ||||||||||||||||||||||||
| 3070 | } | - | ||||||||||||||||||||||||
| 3071 | - | |||||||||||||||||||||||||
| 3072 | /*! \internal | - | ||||||||||||||||||||||||
| 3073 | */ | - | ||||||||||||||||||||||||
| 3074 | void QTest::qFail(const char *statementStr, const char *file, int line) | - | ||||||||||||||||||||||||
| 3075 | { | - | ||||||||||||||||||||||||
| 3076 | QTestResult::addFailure(statementStr, file, line); | - | ||||||||||||||||||||||||
| 3077 | } executed 386 times by 2 tests: end of blockExecuted by:
| 386 | ||||||||||||||||||||||||
| 3078 | - | |||||||||||||||||||||||||
| 3079 | /*! \internal | - | ||||||||||||||||||||||||
| 3080 | */ | - | ||||||||||||||||||||||||
| 3081 | bool QTest::qVerify(bool statement, const char *statementStr, const char *description, | - | ||||||||||||||||||||||||
| 3082 | const char *file, int line) | - | ||||||||||||||||||||||||
| 3083 | { | - | ||||||||||||||||||||||||
| 3084 | return QTestResult::verify(statement, statementStr, description, file, line); executed 13100488 times by 485 tests: return QTestResult::verify(statement, statementStr, description, file, line);Executed by:
| 13100488 | ||||||||||||||||||||||||
| 3085 | } | - | ||||||||||||||||||||||||
| 3086 | - | |||||||||||||||||||||||||
| 3087 | /*! \fn void QTest::qSkip(const char *message, const char *file, int line) | - | ||||||||||||||||||||||||
| 3088 | \internal | - | ||||||||||||||||||||||||
| 3089 | */ | - | ||||||||||||||||||||||||
| 3090 | void QTest::qSkip(const char *message, const char *file, int line) | - | ||||||||||||||||||||||||
| 3091 | { | - | ||||||||||||||||||||||||
| 3092 | QTestResult::addSkip(message, file, line); | - | ||||||||||||||||||||||||
| 3093 | QTestResult::setSkipCurrentTest(true); | - | ||||||||||||||||||||||||
| 3094 | } executed 1348 times by 56 tests: end of blockExecuted by:
| 1348 | ||||||||||||||||||||||||
| 3095 | - | |||||||||||||||||||||||||
| 3096 | /*! \fn bool QTest::qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line) | - | ||||||||||||||||||||||||
| 3097 | \internal | - | ||||||||||||||||||||||||
| 3098 | */ | - | ||||||||||||||||||||||||
| 3099 | bool QTest::qExpectFail(const char *dataIndex, const char *comment, | - | ||||||||||||||||||||||||
| 3100 | QTest::TestFailMode mode, const char *file, int line) | - | ||||||||||||||||||||||||
| 3101 | { | - | ||||||||||||||||||||||||
| 3102 | return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line); executed 8370 times by 39 tests: return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line);Executed by:
| 8370 | ||||||||||||||||||||||||
| 3103 | } | - | ||||||||||||||||||||||||
| 3104 | - | |||||||||||||||||||||||||
| 3105 | /*! \internal | - | ||||||||||||||||||||||||
| 3106 | */ | - | ||||||||||||||||||||||||
| 3107 | void QTest::qWarn(const char *message, const char *file, int line) | - | ||||||||||||||||||||||||
| 3108 | { | - | ||||||||||||||||||||||||
| 3109 | QTestLog::warn(message, file, line); | - | ||||||||||||||||||||||||
| 3110 | } executed 850 times by 13 tests: end of blockExecuted by:
| 850 | ||||||||||||||||||||||||
| 3111 | - | |||||||||||||||||||||||||
| 3112 | /*! | - | ||||||||||||||||||||||||
| 3113 | Ignores messages created by qDebug(), qInfo() or qWarning(). If the \a message | - | ||||||||||||||||||||||||
| 3114 | with the corresponding \a type is outputted, it will be removed from the | - | ||||||||||||||||||||||||
| 3115 | test log. If the test finished and the \a message was not outputted, | - | ||||||||||||||||||||||||
| 3116 | a test failure is appended to the test log. | - | ||||||||||||||||||||||||
| 3117 | - | |||||||||||||||||||||||||
| 3118 | \b {Note:} Invoking this function will only ignore one message. | - | ||||||||||||||||||||||||
| 3119 | If the message you want to ignore is outputted twice, you have to | - | ||||||||||||||||||||||||
| 3120 | call ignoreMessage() twice, too. | - | ||||||||||||||||||||||||
| 3121 | - | |||||||||||||||||||||||||
| 3122 | Example: | - | ||||||||||||||||||||||||
| 3123 | \snippet code/src_qtestlib_qtestcase.cpp 19 | - | ||||||||||||||||||||||||
| 3124 | - | |||||||||||||||||||||||||
| 3125 | The example above tests that QDir::mkdir() outputs the right warning when invoked | - | ||||||||||||||||||||||||
| 3126 | with an invalid file name. | - | ||||||||||||||||||||||||
| 3127 | */ | - | ||||||||||||||||||||||||
| 3128 | void QTest::ignoreMessage(QtMsgType type, const char *message) | - | ||||||||||||||||||||||||
| 3129 | { | - | ||||||||||||||||||||||||
| 3130 | QTestLog::ignoreMessage(type, message); | - | ||||||||||||||||||||||||
| 3131 | } executed 1015 times by 82 tests: end of blockExecuted by:
| 1015 | ||||||||||||||||||||||||
| 3132 | - | |||||||||||||||||||||||||
| 3133 | #ifndef QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
| 3134 | /*! | - | ||||||||||||||||||||||||
| 3135 | \overload | - | ||||||||||||||||||||||||
| 3136 | - | |||||||||||||||||||||||||
| 3137 | Ignores messages created by qDebug(), qInfo() or qWarning(). If the message | - | ||||||||||||||||||||||||
| 3138 | matching \a messagePattern | - | ||||||||||||||||||||||||
| 3139 | with the corresponding \a type is outputted, it will be removed from the | - | ||||||||||||||||||||||||
| 3140 | test log. If the test finished and the message was not outputted, | - | ||||||||||||||||||||||||
| 3141 | a test failure is appended to the test log. | - | ||||||||||||||||||||||||
| 3142 | - | |||||||||||||||||||||||||
| 3143 | \b {Note:} Invoking this function will only ignore one message. | - | ||||||||||||||||||||||||
| 3144 | If the message you want to ignore is outputted twice, you have to | - | ||||||||||||||||||||||||
| 3145 | call ignoreMessage() twice, too. | - | ||||||||||||||||||||||||
| 3146 | - | |||||||||||||||||||||||||
| 3147 | \since 5.3 | - | ||||||||||||||||||||||||
| 3148 | */ | - | ||||||||||||||||||||||||
| 3149 | void QTest::ignoreMessage(QtMsgType type, const QRegularExpression &messagePattern) | - | ||||||||||||||||||||||||
| 3150 | { | - | ||||||||||||||||||||||||
| 3151 | QTestLog::ignoreMessage(type, messagePattern); | - | ||||||||||||||||||||||||
| 3152 | } executed 100 times by 4 tests: end of blockExecuted by:
| 100 | ||||||||||||||||||||||||
| 3153 | #endif // QT_NO_REGULAREXPRESSION | - | ||||||||||||||||||||||||
| 3154 | - | |||||||||||||||||||||||||
| 3155 | /*! \internal | - | ||||||||||||||||||||||||
| 3156 | */ | - | ||||||||||||||||||||||||
| 3157 | - | |||||||||||||||||||||||||
| 3158 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 3159 | static inline bool isWindowsBuildDirectory(const QString &dirName) | - | ||||||||||||||||||||||||
| 3160 | { | - | ||||||||||||||||||||||||
| 3161 | return dirName.compare(QLatin1String("Debug"), Qt::CaseInsensitive) == 0 | - | ||||||||||||||||||||||||
| 3162 | || dirName.compare(QLatin1String("Release"), Qt::CaseInsensitive) == 0; | - | ||||||||||||||||||||||||
| 3163 | } | - | ||||||||||||||||||||||||
| 3164 | #endif | - | ||||||||||||||||||||||||
| 3165 | - | |||||||||||||||||||||||||
| 3166 | /*! | - | ||||||||||||||||||||||||
| 3167 | Extracts a directory from resources to disk. The content is extracted | - | ||||||||||||||||||||||||
| 3168 | recursively to a temporary folder. The extracted content is removed | - | ||||||||||||||||||||||||
| 3169 | automatically once the last reference to the return value goes out of scope. | - | ||||||||||||||||||||||||
| 3170 | - | |||||||||||||||||||||||||
| 3171 | \a dirName is the name of the directory to extract from resources. | - | ||||||||||||||||||||||||
| 3172 | - | |||||||||||||||||||||||||
| 3173 | Returns the temporary directory where the data was extracted or null in case of | - | ||||||||||||||||||||||||
| 3174 | errors. | - | ||||||||||||||||||||||||
| 3175 | */ | - | ||||||||||||||||||||||||
| 3176 | QSharedPointer<QTemporaryDir> QTest::qExtractTestData(const QString &dirName) | - | ||||||||||||||||||||||||
| 3177 | { | - | ||||||||||||||||||||||||
| 3178 | QSharedPointer<QTemporaryDir> result; // null until success, then == tempDir | - | ||||||||||||||||||||||||
| 3179 | - | |||||||||||||||||||||||||
| 3180 | QSharedPointer<QTemporaryDir> tempDir = QSharedPointer<QTemporaryDir>::create(); | - | ||||||||||||||||||||||||
| 3181 | - | |||||||||||||||||||||||||
| 3182 | tempDir->setAutoRemove(true); | - | ||||||||||||||||||||||||
| 3183 | - | |||||||||||||||||||||||||
| 3184 | if (!tempDir->isValid())
| 0-1 | ||||||||||||||||||||||||
| 3185 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 3186 | - | |||||||||||||||||||||||||
| 3187 | const QString dataPath = tempDir->path(); | - | ||||||||||||||||||||||||
| 3188 | const QString resourcePath = QLatin1Char(':') + dirName; | - | ||||||||||||||||||||||||
| 3189 | const QFileInfo fileInfo(resourcePath); | - | ||||||||||||||||||||||||
| 3190 | - | |||||||||||||||||||||||||
| 3191 | if (!fileInfo.isDir()) {
| 0-1 | ||||||||||||||||||||||||
| 3192 | qWarning("Resource path '%s' is not a directory.", qPrintable(resourcePath)); | - | ||||||||||||||||||||||||
| 3193 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 3194 | } | - | ||||||||||||||||||||||||
| 3195 | - | |||||||||||||||||||||||||
| 3196 | QDirIterator it(resourcePath, QDirIterator::Subdirectories); | - | ||||||||||||||||||||||||
| 3197 | if (!it.hasNext()) {
| 0-1 | ||||||||||||||||||||||||
| 3198 | qWarning("Resource directory '%s' is empty.", qPrintable(resourcePath)); | - | ||||||||||||||||||||||||
| 3199 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 3200 | } | - | ||||||||||||||||||||||||
| 3201 | - | |||||||||||||||||||||||||
| 3202 | while (it.hasNext()) {
| 1-5 | ||||||||||||||||||||||||
| 3203 | it.next(); | - | ||||||||||||||||||||||||
| 3204 | - | |||||||||||||||||||||||||
| 3205 | QFileInfo fileInfo = it.fileInfo(); | - | ||||||||||||||||||||||||
| 3206 | - | |||||||||||||||||||||||||
| 3207 | if (!fileInfo.isDir()) {
| 1-4 | ||||||||||||||||||||||||
| 3208 | const QString destination = dataPath + QLatin1Char('/') + fileInfo.filePath().midRef(resourcePath.length()); | - | ||||||||||||||||||||||||
| 3209 | QFileInfo destinationFileInfo(destination); | - | ||||||||||||||||||||||||
| 3210 | QDir().mkpath(destinationFileInfo.path()); | - | ||||||||||||||||||||||||
| 3211 | if (!QFile::copy(fileInfo.filePath(), destination)) {
| 0-4 | ||||||||||||||||||||||||
| 3212 | qWarning("Failed to copy '%s'.", qPrintable(fileInfo.filePath())); | - | ||||||||||||||||||||||||
| 3213 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 3214 | } | - | ||||||||||||||||||||||||
| 3215 | if (!QFile::setPermissions(destination, QFile::ReadUser | QFile::WriteUser | QFile::ReadGroup)) {
| 0-4 | ||||||||||||||||||||||||
| 3216 | qWarning("Failed to set permissions on '%s'.", qPrintable(destination)); | - | ||||||||||||||||||||||||
| 3217 | return result; never executed: return result; | 0 | ||||||||||||||||||||||||
| 3218 | } | - | ||||||||||||||||||||||||
| 3219 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 3220 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||
| 3221 | - | |||||||||||||||||||||||||
| 3222 | result = qMove(tempDir); | - | ||||||||||||||||||||||||
| 3223 | - | |||||||||||||||||||||||||
| 3224 | return result; executed 1 time by 1 test: return result;Executed by:
| 1 | ||||||||||||||||||||||||
| 3225 | } | - | ||||||||||||||||||||||||
| 3226 | - | |||||||||||||||||||||||||
| 3227 | /*! \internal | - | ||||||||||||||||||||||||
| 3228 | */ | - | ||||||||||||||||||||||||
| 3229 | - | |||||||||||||||||||||||||
| 3230 | QString QTest::qFindTestData(const QString& base, const char *file, int line, const char *builddir) | - | ||||||||||||||||||||||||
| 3231 | { | - | ||||||||||||||||||||||||
| 3232 | QString found; | - | ||||||||||||||||||||||||
| 3233 | - | |||||||||||||||||||||||||
| 3234 | // Testdata priorities: | - | ||||||||||||||||||||||||
| 3235 | - | |||||||||||||||||||||||||
| 3236 | // 1. relative to test binary. | - | ||||||||||||||||||||||||
| 3237 | if (qApp) {
| 245-975 | ||||||||||||||||||||||||
| 3238 | QDir binDirectory(QCoreApplication::applicationDirPath()); | - | ||||||||||||||||||||||||
| 3239 | if (binDirectory.exists(base)) {
| 320-655 | ||||||||||||||||||||||||
| 3240 | found = binDirectory.absoluteFilePath(base); | - | ||||||||||||||||||||||||
| 3241 | } executed 320 times by 64 tests: end of blockExecuted by:
| 320 | ||||||||||||||||||||||||
| 3242 | #ifdef Q_OS_WIN | - | ||||||||||||||||||||||||
| 3243 | // Windows: The executable is typically located in one of the | - | ||||||||||||||||||||||||
| 3244 | // 'Release' or 'Debug' directories. | - | ||||||||||||||||||||||||
| 3245 | else if (isWindowsBuildDirectory(binDirectory.dirName()) | - | ||||||||||||||||||||||||
| 3246 | && binDirectory.cdUp() && binDirectory.exists(base)) { | - | ||||||||||||||||||||||||
| 3247 | found = binDirectory.absoluteFilePath(base); | - | ||||||||||||||||||||||||
| 3248 | } | - | ||||||||||||||||||||||||
| 3249 | #endif // Q_OS_WIN | - | ||||||||||||||||||||||||
| 3250 | else if (QTestLog::verboseLevel() >= 2) {
| 0-655 | ||||||||||||||||||||||||
| 3251 | const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QLatin1Char('/') + base); | - | ||||||||||||||||||||||||
| 3252 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
| 3253 | QString::fromLatin1("testdata %1 not found relative to test binary [%2]; " | - | ||||||||||||||||||||||||
| 3254 | "checking next location").arg(base, candidate)), | - | ||||||||||||||||||||||||
| 3255 | file, line); | - | ||||||||||||||||||||||||
| 3256 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3257 | } executed 975 times by 68 tests: end of blockExecuted by:
| 975 | ||||||||||||||||||||||||
| 3258 | - | |||||||||||||||||||||||||
| 3259 | // 2. installed path. | - | ||||||||||||||||||||||||
| 3260 | if (found.isEmpty()) {
| 320-900 | ||||||||||||||||||||||||
| 3261 | const char *testObjectName = QTestResult::currentTestObjectName(); | - | ||||||||||||||||||||||||
| 3262 | if (testObjectName) {
| 0-900 | ||||||||||||||||||||||||
| 3263 | QString testsPath = QLibraryInfo::location(QLibraryInfo::TestsPath); | - | ||||||||||||||||||||||||
| 3264 | QString candidate = QString::fromLatin1("%1/%2/%3") | - | ||||||||||||||||||||||||
| 3265 | .arg(testsPath, QFile::decodeName(testObjectName).toLower(), base); | - | ||||||||||||||||||||||||
| 3266 | if (QFileInfo::exists(candidate)) {
| 21-879 | ||||||||||||||||||||||||
| 3267 | found = candidate; | - | ||||||||||||||||||||||||
| 3268 | } executed 21 times by 1 test: end of blockExecuted by:
| 21 | ||||||||||||||||||||||||
| 3269 | else if (QTestLog::verboseLevel() >= 2) {
| 0-879 | ||||||||||||||||||||||||
| 3270 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
| 3271 | QString::fromLatin1("testdata %1 not found in tests install path [%2]; " | - | ||||||||||||||||||||||||
| 3272 | "checking next location") | - | ||||||||||||||||||||||||
| 3273 | .arg(base, QDir::toNativeSeparators(candidate))), | - | ||||||||||||||||||||||||
| 3274 | file, line); | - | ||||||||||||||||||||||||
| 3275 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3276 | } executed 900 times by 10 tests: end of blockExecuted by:
| 900 | ||||||||||||||||||||||||
| 3277 | } executed 900 times by 10 tests: end of blockExecuted by:
| 900 | ||||||||||||||||||||||||
| 3278 | - | |||||||||||||||||||||||||
| 3279 | // 3. relative to test source. | - | ||||||||||||||||||||||||
| 3280 | if (found.isEmpty()) {
| 341-879 | ||||||||||||||||||||||||
| 3281 | // srcdir is the directory containing the calling source file. | - | ||||||||||||||||||||||||
| 3282 | QFileInfo srcdir = QFileInfo(QFile::decodeName(file)).path(); | - | ||||||||||||||||||||||||
| 3283 | - | |||||||||||||||||||||||||
| 3284 | // If the srcdir is relative, that means it is relative to the current working | - | ||||||||||||||||||||||||
| 3285 | // directory of the compiler at compile time, which should be passed in as `builddir'. | - | ||||||||||||||||||||||||
| 3286 | if (!srcdir.isAbsolute() && builddir) {
| 21-858 | ||||||||||||||||||||||||
| 3287 | srcdir.setFile(QFile::decodeName(builddir) + QLatin1String("/") + srcdir.filePath()); | - | ||||||||||||||||||||||||
| 3288 | } executed 140 times by 10 tests: end of blockExecuted by:
| 140 | ||||||||||||||||||||||||
| 3289 | - | |||||||||||||||||||||||||
| 3290 | QString candidate = QString::fromLatin1("%1/%2").arg(srcdir.canonicalFilePath(), base); | - | ||||||||||||||||||||||||
| 3291 | if (QFileInfo::exists(candidate)) {
| 124-755 | ||||||||||||||||||||||||
| 3292 | found = candidate; | - | ||||||||||||||||||||||||
| 3293 | } executed 124 times by 4 tests: end of blockExecuted by:
| 124 | ||||||||||||||||||||||||
| 3294 | else if (QTestLog::verboseLevel() >= 2) {
| 0-755 | ||||||||||||||||||||||||
| 3295 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
| 3296 | QString::fromLatin1("testdata %1 not found relative to source path [%2]") | - | ||||||||||||||||||||||||
| 3297 | .arg(base, QDir::toNativeSeparators(candidate))), | - | ||||||||||||||||||||||||
| 3298 | file, line); | - | ||||||||||||||||||||||||
| 3299 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3300 | } executed 879 times by 10 tests: end of blockExecuted by:
| 879 | ||||||||||||||||||||||||
| 3301 | - | |||||||||||||||||||||||||
| 3302 | // 4. Try resources | - | ||||||||||||||||||||||||
| 3303 | if (found.isEmpty()) {
| 465-755 | ||||||||||||||||||||||||
| 3304 | QString candidate = QString::fromLatin1(":/%1").arg(base); | - | ||||||||||||||||||||||||
| 3305 | if (QFileInfo::exists(candidate))
| 8-747 | ||||||||||||||||||||||||
| 3306 | found = candidate; executed 8 times by 3 tests: found = candidate;Executed by:
| 8 | ||||||||||||||||||||||||
| 3307 | } executed 755 times by 7 tests: end of blockExecuted by:
| 755 | ||||||||||||||||||||||||
| 3308 | - | |||||||||||||||||||||||||
| 3309 | // 5. Try current directory | - | ||||||||||||||||||||||||
| 3310 | if (found.isEmpty()) {
| 473-747 | ||||||||||||||||||||||||
| 3311 | QString candidate = QString::fromLatin1("%1/%2").arg(QDir::currentPath()).arg(base); | - | ||||||||||||||||||||||||
| 3312 | if (QFileInfo::exists(candidate))
| 0-747 | ||||||||||||||||||||||||
| 3313 | found = candidate; never executed: found = candidate; | 0 | ||||||||||||||||||||||||
| 3314 | } executed 747 times by 4 tests: end of blockExecuted by:
| 747 | ||||||||||||||||||||||||
| 3315 | - | |||||||||||||||||||||||||
| 3316 | // 6. Try main source directory | - | ||||||||||||||||||||||||
| 3317 | if (found.isEmpty()) {
| 473-747 | ||||||||||||||||||||||||
| 3318 | QString candidate = QTest::mainSourcePath % QLatin1Char('/') % base; | - | ||||||||||||||||||||||||
| 3319 | if (QFileInfo::exists(candidate))
| 0-747 | ||||||||||||||||||||||||
| 3320 | found = candidate; never executed: found = candidate; | 0 | ||||||||||||||||||||||||
| 3321 | } executed 747 times by 4 tests: end of blockExecuted by:
| 747 | ||||||||||||||||||||||||
| 3322 | - | |||||||||||||||||||||||||
| 3323 | if (found.isEmpty()) {
| 473-747 | ||||||||||||||||||||||||
| 3324 | QTest::qWarn(qPrintable( | - | ||||||||||||||||||||||||
| 3325 | QString::fromLatin1("testdata %1 could not be located!").arg(base)), | - | ||||||||||||||||||||||||
| 3326 | file, line); | - | ||||||||||||||||||||||||
| 3327 | } executed 747 times by 4 tests: end of blockExecuted by:
| 747 | ||||||||||||||||||||||||
| 3328 | else if (QTestLog::verboseLevel() >= 1) {
| 0-473 | ||||||||||||||||||||||||
| 3329 | QTestLog::info(qPrintable( | - | ||||||||||||||||||||||||
| 3330 | QString::fromLatin1("testdata %1 was located at %2").arg(base, QDir::toNativeSeparators(found))), | - | ||||||||||||||||||||||||
| 3331 | file, line); | - | ||||||||||||||||||||||||
| 3332 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 3333 | - | |||||||||||||||||||||||||
| 3334 | return found; executed 1220 times by 70 tests: return found;Executed by:
| 1220 | ||||||||||||||||||||||||
| 3335 | } | - | ||||||||||||||||||||||||
| 3336 | - | |||||||||||||||||||||||||
| 3337 | /*! \internal | - | ||||||||||||||||||||||||
| 3338 | */ | - | ||||||||||||||||||||||||
| 3339 | QString QTest::qFindTestData(const char *base, const char *file, int line, const char *builddir) | - | ||||||||||||||||||||||||
| 3340 | { | - | ||||||||||||||||||||||||
| 3341 | return qFindTestData(QFile::decodeName(base), file, line, builddir); executed 295 times by 63 tests: return qFindTestData(QFile::decodeName(base), file, line, builddir);Executed by:
| 295 | ||||||||||||||||||||||||
| 3342 | } | - | ||||||||||||||||||||||||
| 3343 | - | |||||||||||||||||||||||||
| 3344 | /*! \internal | - | ||||||||||||||||||||||||
| 3345 | */ | - | ||||||||||||||||||||||||
| 3346 | void *QTest::qData(const char *tagName, int typeId) | - | ||||||||||||||||||||||||
| 3347 | { | - | ||||||||||||||||||||||||
| 3348 | return fetchData(QTestResult::currentTestData(), tagName, typeId); executed 429735 times by 359 tests: return fetchData(QTestResult::currentTestData(), tagName, typeId);Executed by:
| 429735 | ||||||||||||||||||||||||
| 3349 | } | - | ||||||||||||||||||||||||
| 3350 | - | |||||||||||||||||||||||||
| 3351 | /*! \internal | - | ||||||||||||||||||||||||
| 3352 | */ | - | ||||||||||||||||||||||||
| 3353 | void *QTest::qGlobalData(const char *tagName, int typeId) | - | ||||||||||||||||||||||||
| 3354 | { | - | ||||||||||||||||||||||||
| 3355 | return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId); executed 7540 times by 15 tests: return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId);Executed by:
| 7540 | ||||||||||||||||||||||||
| 3356 | } | - | ||||||||||||||||||||||||
| 3357 | - | |||||||||||||||||||||||||
| 3358 | /*! \internal | - | ||||||||||||||||||||||||
| 3359 | */ | - | ||||||||||||||||||||||||
| 3360 | void *QTest::qElementData(const char *tagName, int metaTypeId) | - | ||||||||||||||||||||||||
| 3361 | { | - | ||||||||||||||||||||||||
| 3362 | QTEST_ASSERT(tagName); never executed: qt_assert("tagName",__FILE__,3362);
| 0-3248 | ||||||||||||||||||||||||
| 3363 | QTestData *data = QTestResult::currentTestData(); | - | ||||||||||||||||||||||||
| 3364 | QTEST_ASSERT(data); never executed: qt_assert("data",__FILE__,3364);
| 0-3248 | ||||||||||||||||||||||||
| 3365 | QTEST_ASSERT(data->parent()); never executed: qt_assert("data->parent()",__FILE__,3365);
| 0-3248 | ||||||||||||||||||||||||
| 3366 | - | |||||||||||||||||||||||||
| 3367 | int idx = data->parent()->indexOf(tagName); | - | ||||||||||||||||||||||||
| 3368 | QTEST_ASSERT(idx != -1); never executed: qt_assert("idx != -1",__FILE__,3368);
| 0-3248 | ||||||||||||||||||||||||
| 3369 | QTEST_ASSERT(data->parent()->elementTypeId(idx) == metaTypeId); never executed: qt_assert("data->parent()->elementTypeId(idx) == metaTypeId",__FILE__,3369);
| 0-3248 | ||||||||||||||||||||||||
| 3370 | - | |||||||||||||||||||||||||
| 3371 | return data->data(data->parent()->indexOf(tagName)); executed 3248 times by 38 tests: return data->data(data->parent()->indexOf(tagName));Executed by:
| 3248 | ||||||||||||||||||||||||
| 3372 | } | - | ||||||||||||||||||||||||
| 3373 | - | |||||||||||||||||||||||||
| 3374 | /*! \internal | - | ||||||||||||||||||||||||
| 3375 | */ | - | ||||||||||||||||||||||||
| 3376 | void QTest::addColumnInternal(int id, const char *name) | - | ||||||||||||||||||||||||
| 3377 | { | - | ||||||||||||||||||||||||
| 3378 | QTestTable *tbl = QTestTable::currentTestTable(); | - | ||||||||||||||||||||||||
| 3379 | QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot."); never executed: qt_assert_x("QTest::addColumn()", "Cannot add testdata outside of a _data slot.",__FILE__,3379);
| 0-9908 | ||||||||||||||||||||||||
| 3380 | - | |||||||||||||||||||||||||
| 3381 | tbl->addColumn(id, name); | - | ||||||||||||||||||||||||
| 3382 | } executed 9908 times by 365 tests: end of blockExecuted by:
| 9908 | ||||||||||||||||||||||||
| 3383 | - | |||||||||||||||||||||||||
| 3384 | /*! | - | ||||||||||||||||||||||||
| 3385 | Appends a new row to the current test data. \a dataTag is the name of | - | ||||||||||||||||||||||||
| 3386 | the testdata that will appear in the test output. Returns a QTestData reference | - | ||||||||||||||||||||||||
| 3387 | that can be used to stream in data. | - | ||||||||||||||||||||||||
| 3388 | - | |||||||||||||||||||||||||
| 3389 | Example: | - | ||||||||||||||||||||||||
| 3390 | \snippet code/src_qtestlib_qtestcase.cpp 20 | - | ||||||||||||||||||||||||
| 3391 | - | |||||||||||||||||||||||||
| 3392 | \b {Note:} This macro can only be used in a test's data function | - | ||||||||||||||||||||||||
| 3393 | that is invoked by the test framework. | - | ||||||||||||||||||||||||
| 3394 | - | |||||||||||||||||||||||||
| 3395 | See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for | - | ||||||||||||||||||||||||
| 3396 | a more extensive example. | - | ||||||||||||||||||||||||
| 3397 | - | |||||||||||||||||||||||||
| 3398 | \sa addColumn(), QFETCH() | - | ||||||||||||||||||||||||
| 3399 | */ | - | ||||||||||||||||||||||||
| 3400 | QTestData &QTest::newRow(const char *dataTag) | - | ||||||||||||||||||||||||
| 3401 | { | - | ||||||||||||||||||||||||
| 3402 | QTEST_ASSERT_X(dataTag, "QTest::newRow()", "Data tag can not be null"); never executed: qt_assert_x("QTest::newRow()", "Data tag can not be null",__FILE__,3402);
| 0-120645 | ||||||||||||||||||||||||
| 3403 | QTestTable *tbl = QTestTable::currentTestTable(); | - | ||||||||||||||||||||||||
| 3404 | QTEST_ASSERT_X(tbl, "QTest::newRow()", "Cannot add testdata outside of a _data slot."); never executed: qt_assert_x("QTest::newRow()", "Cannot add testdata outside of a _data slot.",__FILE__,3404);
| 0-120645 | ||||||||||||||||||||||||
| 3405 | QTEST_ASSERT_X(tbl->elementCount(), "QTest::newRow()", "Must add columns before attempting to add rows."); never executed: qt_assert_x("QTest::newRow()", "Must add columns before attempting to add rows.",__FILE__,3405);
| 0-120645 | ||||||||||||||||||||||||
| 3406 | - | |||||||||||||||||||||||||
| 3407 | return *tbl->newData(dataTag); executed 120645 times by 365 tests: return *tbl->newData(dataTag);Executed by:
| 120645 | ||||||||||||||||||||||||
| 3408 | } | - | ||||||||||||||||||||||||
| 3409 | - | |||||||||||||||||||||||||
| 3410 | /*! \fn void QTest::addColumn(const char *name, T *dummy = 0) | - | ||||||||||||||||||||||||
| 3411 | - | |||||||||||||||||||||||||
| 3412 | Adds a column with type \c{T} to the current test data. | - | ||||||||||||||||||||||||
| 3413 | \a name is the name of the column. \a dummy is a workaround | - | ||||||||||||||||||||||||
| 3414 | for buggy compilers and can be ignored. | - | ||||||||||||||||||||||||
| 3415 | - | |||||||||||||||||||||||||
| 3416 | To populate the column with values, newRow() can be used. Use | - | ||||||||||||||||||||||||
| 3417 | \l QFETCH() to fetch the data in the actual test. | - | ||||||||||||||||||||||||
| 3418 | - | |||||||||||||||||||||||||
| 3419 | Example: | - | ||||||||||||||||||||||||
| 3420 | \snippet code/src_qtestlib_qtestcase.cpp 21 | - | ||||||||||||||||||||||||
| 3421 | - | |||||||||||||||||||||||||
| 3422 | To add custom types to the testdata, the type must be registered with | - | ||||||||||||||||||||||||
| 3423 | QMetaType via \l Q_DECLARE_METATYPE(). | - | ||||||||||||||||||||||||
| 3424 | - | |||||||||||||||||||||||||
| 3425 | \b {Note:} This macro can only be used in a test's data function | - | ||||||||||||||||||||||||
| 3426 | that is invoked by the test framework. | - | ||||||||||||||||||||||||
| 3427 | - | |||||||||||||||||||||||||
| 3428 | See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for | - | ||||||||||||||||||||||||
| 3429 | a more extensive example. | - | ||||||||||||||||||||||||
| 3430 | - | |||||||||||||||||||||||||
| 3431 | \sa QTest::newRow(), QFETCH(), QMetaType | - | ||||||||||||||||||||||||
| 3432 | */ | - | ||||||||||||||||||||||||
| 3433 | - | |||||||||||||||||||||||||
| 3434 | /*! | - | ||||||||||||||||||||||||
| 3435 | Returns the name of the binary that is currently executed. | - | ||||||||||||||||||||||||
| 3436 | */ | - | ||||||||||||||||||||||||
| 3437 | const char *QTest::currentAppName() | - | ||||||||||||||||||||||||
| 3438 | { | - | ||||||||||||||||||||||||
| 3439 | return QTestResult::currentAppName(); executed 54 times by 5 tests: return QTestResult::currentAppName();Executed by:
| 54 | ||||||||||||||||||||||||
| 3440 | } | - | ||||||||||||||||||||||||
| 3441 | - | |||||||||||||||||||||||||
| 3442 | /*! | - | ||||||||||||||||||||||||
| 3443 | Returns the name of the test function that is currently executed. | - | ||||||||||||||||||||||||
| 3444 | - | |||||||||||||||||||||||||
| 3445 | Example: | - | ||||||||||||||||||||||||
| 3446 | - | |||||||||||||||||||||||||
| 3447 | \snippet code/src_qtestlib_qtestcase.cpp 22 | - | ||||||||||||||||||||||||
| 3448 | */ | - | ||||||||||||||||||||||||
| 3449 | const char *QTest::currentTestFunction() | - | ||||||||||||||||||||||||
| 3450 | { | - | ||||||||||||||||||||||||
| 3451 | return QTestResult::currentTestFunction(); executed 23639 times by 25 tests: return QTestResult::currentTestFunction();Executed by:
| 23639 | ||||||||||||||||||||||||
| 3452 | } | - | ||||||||||||||||||||||||
| 3453 | - | |||||||||||||||||||||||||
| 3454 | /*! | - | ||||||||||||||||||||||||
| 3455 | Returns the name of the current test data. If the test doesn't | - | ||||||||||||||||||||||||
| 3456 | have any assigned testdata, the function returns 0. | - | ||||||||||||||||||||||||
| 3457 | */ | - | ||||||||||||||||||||||||
| 3458 | const char *QTest::currentDataTag() | - | ||||||||||||||||||||||||
| 3459 | { | - | ||||||||||||||||||||||||
| 3460 | return QTestResult::currentDataTag(); executed 7839 times by 26 tests: return QTestResult::currentDataTag();Executed by:
| 7839 | ||||||||||||||||||||||||
| 3461 | } | - | ||||||||||||||||||||||||
| 3462 | - | |||||||||||||||||||||||||
| 3463 | /*! | - | ||||||||||||||||||||||||
| 3464 | Returns \c true if the current test function failed, otherwise false. | - | ||||||||||||||||||||||||
| 3465 | */ | - | ||||||||||||||||||||||||
| 3466 | bool QTest::currentTestFailed() | - | ||||||||||||||||||||||||
| 3467 | { | - | ||||||||||||||||||||||||
| 3468 | return QTestResult::currentTestFailed(); executed 1366 times by 539 tests: return QTestResult::currentTestFailed();Executed by:
| 1366 | ||||||||||||||||||||||||
| 3469 | } | - | ||||||||||||||||||||||||
| 3470 | - | |||||||||||||||||||||||||
| 3471 | /*! | - | ||||||||||||||||||||||||
| 3472 | Sleeps for \a ms milliseconds, blocking execution of the | - | ||||||||||||||||||||||||
| 3473 | test. qSleep() will not do any event processing and leave your test | - | ||||||||||||||||||||||||
| 3474 | unresponsive. Network communication might time out while | - | ||||||||||||||||||||||||
| 3475 | sleeping. Use \l qWait() to do non-blocking sleeping. | - | ||||||||||||||||||||||||
| 3476 | - | |||||||||||||||||||||||||
| 3477 | \a ms must be greater than 0. | - | ||||||||||||||||||||||||
| 3478 | - | |||||||||||||||||||||||||
| 3479 | \b {Note:} The qSleep() function calls either \c nanosleep() on | - | ||||||||||||||||||||||||
| 3480 | unix or \c Sleep() on windows, so the accuracy of time spent in | - | ||||||||||||||||||||||||
| 3481 | qSleep() depends on the operating system. | - | ||||||||||||||||||||||||
| 3482 | - | |||||||||||||||||||||||||
| 3483 | Example: | - | ||||||||||||||||||||||||
| 3484 | \snippet code/src_qtestlib_qtestcase.cpp 23 | - | ||||||||||||||||||||||||
| 3485 | - | |||||||||||||||||||||||||
| 3486 | \sa qWait() | - | ||||||||||||||||||||||||
| 3487 | */ | - | ||||||||||||||||||||||||
| 3488 | void QTest::qSleep(int ms) | - | ||||||||||||||||||||||||
| 3489 | { | - | ||||||||||||||||||||||||
| 3490 | QTEST_ASSERT(ms > 0); never executed: qt_assert("ms > 0",__FILE__,3490);
| 0-61502 | ||||||||||||||||||||||||
| 3491 | - | |||||||||||||||||||||||||
| 3492 | #if defined(Q_OS_WINRT) | - | ||||||||||||||||||||||||
| 3493 | WaitForSingleObjectEx(GetCurrentThread(), ms, true); | - | ||||||||||||||||||||||||
| 3494 | #elif defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 3495 | Sleep(uint(ms)); | - | ||||||||||||||||||||||||
| 3496 | #else | - | ||||||||||||||||||||||||
| 3497 | struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; | - | ||||||||||||||||||||||||
| 3498 | nanosleep(&ts, NULL); | - | ||||||||||||||||||||||||
| 3499 | #endif | - | ||||||||||||||||||||||||
| 3500 | } executed 61502 times by 153 tests: end of blockExecuted by:
| 61502 | ||||||||||||||||||||||||
| 3501 | - | |||||||||||||||||||||||||
| 3502 | /*! \internal | - | ||||||||||||||||||||||||
| 3503 | */ | - | ||||||||||||||||||||||||
| 3504 | QObject *QTest::testObject() | - | ||||||||||||||||||||||||
| 3505 | { | - | ||||||||||||||||||||||||
| 3506 | return currentTestObject; executed 3 times by 1 test: return currentTestObject;Executed by:
| 3 | ||||||||||||||||||||||||
| 3507 | } | - | ||||||||||||||||||||||||
| 3508 | - | |||||||||||||||||||||||||
| 3509 | /*! \internal | - | ||||||||||||||||||||||||
| 3510 | */ | - | ||||||||||||||||||||||||
| 3511 | void QTest::setMainSourcePath(const char *file, const char *builddir) | - | ||||||||||||||||||||||||
| 3512 | { | - | ||||||||||||||||||||||||
| 3513 | QString mainSourceFile = QFile::decodeName(file); | - | ||||||||||||||||||||||||
| 3514 | QFileInfo fi; | - | ||||||||||||||||||||||||
| 3515 | if (builddir)
| 0-627 | ||||||||||||||||||||||||
| 3516 | fi.setFile(QDir(QFile::decodeName(builddir)), mainSourceFile); executed 627 times by 1 test: fi.setFile(QDir(QFile::decodeName(builddir)), mainSourceFile);Executed by:
| 627 | ||||||||||||||||||||||||
| 3517 | else | - | ||||||||||||||||||||||||
| 3518 | fi.setFile(mainSourceFile); never executed: fi.setFile(mainSourceFile); | 0 | ||||||||||||||||||||||||
| 3519 | QTest::mainSourcePath = fi.absolutePath(); | - | ||||||||||||||||||||||||
| 3520 | } executed 627 times by 1 test: end of blockExecuted by:
| 627 | ||||||||||||||||||||||||
| 3521 | - | |||||||||||||||||||||||||
| 3522 | /*! \internal | - | ||||||||||||||||||||||||
| 3523 | This function is called by various specializations of QTest::qCompare | - | ||||||||||||||||||||||||
| 3524 | to decide whether to report a failure and to produce verbose test output. | - | ||||||||||||||||||||||||
| 3525 | - | |||||||||||||||||||||||||
| 3526 | The failureMsg parameter can be null, in which case a default message | - | ||||||||||||||||||||||||
| 3527 | will be output if the compare fails. If the compare succeeds, failureMsg | - | ||||||||||||||||||||||||
| 3528 | will not be output. | - | ||||||||||||||||||||||||
| 3529 | - | |||||||||||||||||||||||||
| 3530 | If the caller has already passed a failure message showing the compared | - | ||||||||||||||||||||||||
| 3531 | values, or if those values cannot be stringified, val1 and val2 can be null. | - | ||||||||||||||||||||||||
| 3532 | */ | - | ||||||||||||||||||||||||
| 3533 | bool QTest::compare_helper(bool success, const char *failureMsg, | - | ||||||||||||||||||||||||
| 3534 | char *val1, char *val2, | - | ||||||||||||||||||||||||
| 3535 | const char *actual, const char *expected, | - | ||||||||||||||||||||||||
| 3536 | const char *file, int line) | - | ||||||||||||||||||||||||
| 3537 | { | - | ||||||||||||||||||||||||
| 3538 | return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line); executed 38186306 times by 513 tests: return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line);Executed by:
| 38186306 | ||||||||||||||||||||||||
| 3539 | } | - | ||||||||||||||||||||||||
| 3540 | - | |||||||||||||||||||||||||
| 3541 | /*! \fn bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3542 | \internal | - | ||||||||||||||||||||||||
| 3543 | */ | - | ||||||||||||||||||||||||
| 3544 | bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, | - | ||||||||||||||||||||||||
| 3545 | const char *file, int line) | - | ||||||||||||||||||||||||
| 3546 | { | - | ||||||||||||||||||||||||
| 3547 | return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", executed 1570 times by 15 tests: return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", toString(t1), toString(t2), actual, expected, file, line);Executed by:
| 1570 | ||||||||||||||||||||||||
| 3548 | toString(t1), toString(t2), actual, expected, file, line); executed 1570 times by 15 tests: return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", toString(t1), toString(t2), actual, expected, file, line);Executed by:
| 1570 | ||||||||||||||||||||||||
| 3549 | } | - | ||||||||||||||||||||||||
| 3550 | - | |||||||||||||||||||||||||
| 3551 | /*! \fn bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3552 | \internal | - | ||||||||||||||||||||||||
| 3553 | */ | - | ||||||||||||||||||||||||
| 3554 | bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, | - | ||||||||||||||||||||||||
| 3555 | const char *file, int line) | - | ||||||||||||||||||||||||
| 3556 | { | - | ||||||||||||||||||||||||
| 3557 | return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", executed 2182204 times by 77 tests: return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", toString(t1), toString(t2), actual, expected, file, line);Executed by:
| 2182204 | ||||||||||||||||||||||||
| 3558 | toString(t1), toString(t2), actual, expected, file, line); executed 2182204 times by 77 tests: return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", toString(t1), toString(t2), actual, expected, file, line);Executed by:
| 2182204 | ||||||||||||||||||||||||
| 3559 | } | - | ||||||||||||||||||||||||
| 3560 | - | |||||||||||||||||||||||||
| 3561 | /*! \fn bool QTest::qCompare(double const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3562 | \internal | - | ||||||||||||||||||||||||
| 3563 | */ | - | ||||||||||||||||||||||||
| 3564 | - | |||||||||||||||||||||||||
| 3565 | /*! \fn bool QTest::qCompare(float const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3566 | \internal | - | ||||||||||||||||||||||||
| 3567 | */ | - | ||||||||||||||||||||||||
| 3568 | - | |||||||||||||||||||||||||
| 3569 | #define TO_STRING_IMPL(TYPE, FORMAT) \ | - | ||||||||||||||||||||||||
| 3570 | template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ | - | ||||||||||||||||||||||||
| 3571 | { \ | - | ||||||||||||||||||||||||
| 3572 | char *msg = new char[128]; \ | - | ||||||||||||||||||||||||
| 3573 | qsnprintf(msg, 128, #FORMAT, t); \ | - | ||||||||||||||||||||||||
| 3574 | return msg; \ | - | ||||||||||||||||||||||||
| 3575 | } | - | ||||||||||||||||||||||||
| 3576 | - | |||||||||||||||||||||||||
| 3577 | TO_STRING_IMPL(short, %hd) executed 15398 times by 13 tests: return msg;Executed by:
| 15398 | ||||||||||||||||||||||||
| 3578 | TO_STRING_IMPL(ushort, %hu) executed 11230 times by 30 tests: return msg;Executed by:
| 11230 | ||||||||||||||||||||||||
| 3579 | TO_STRING_IMPL(int, %d) executed 31500102 times by 391 tests: return msg;Executed by:
| 31500102 | ||||||||||||||||||||||||
| 3580 | TO_STRING_IMPL(uint, %u) executed 4871340 times by 71 tests: return msg;Executed by:
| 4871340 | ||||||||||||||||||||||||
| 3581 | TO_STRING_IMPL(long, %ld) executed 26344 times by 12 tests: return msg;Executed by:
| 26344 | ||||||||||||||||||||||||
| 3582 | TO_STRING_IMPL(ulong, %lu) executed 18108 times by 20 tests: return msg;Executed by:
| 18108 | ||||||||||||||||||||||||
| 3583 | #if defined(Q_OS_WIN) | - | ||||||||||||||||||||||||
| 3584 | TO_STRING_IMPL(qint64, %I64d) | - | ||||||||||||||||||||||||
| 3585 | TO_STRING_IMPL(quint64, %I64u) | - | ||||||||||||||||||||||||
| 3586 | #else | - | ||||||||||||||||||||||||
| 3587 | TO_STRING_IMPL(qint64, %lld) executed 1630264 times by 65 tests: return msg;Executed by:
| 1630264 | ||||||||||||||||||||||||
| 3588 | TO_STRING_IMPL(quint64, %llu) executed 42624 times by 23 tests: return msg;Executed by:
| 42624 | ||||||||||||||||||||||||
| 3589 | #endif | - | ||||||||||||||||||||||||
| 3590 | TO_STRING_IMPL(bool, %d) executed 336360 times by 265 tests: return msg;Executed by:
| 336360 | ||||||||||||||||||||||||
| 3591 | TO_STRING_IMPL(char, %c) executed 3527592 times by 28 tests: return msg;Executed by:
| 3527592 | ||||||||||||||||||||||||
| 3592 | TO_STRING_IMPL(signed char, %hhd) executed 9460 times by 8 tests: return msg;Executed by:
| 9460 | ||||||||||||||||||||||||
| 3593 | TO_STRING_IMPL(unsigned char, %hhu) executed 21834 times by 16 tests: return msg;Executed by:
| 21834 | ||||||||||||||||||||||||
| 3594 | TO_STRING_IMPL(float, %g) executed 3140 times by 15 tests: return msg;Executed by:
| 3140 | ||||||||||||||||||||||||
| 3595 | TO_STRING_IMPL(double, %lg) executed 4364450 times by 78 tests: return msg;Executed by:
| 4364450 | ||||||||||||||||||||||||
| 3596 | - | |||||||||||||||||||||||||
| 3597 | /*! \internal | - | ||||||||||||||||||||||||
| 3598 | */ | - | ||||||||||||||||||||||||
| 3599 | char *QTest::toString(const char *str) | - | ||||||||||||||||||||||||
| 3600 | { | - | ||||||||||||||||||||||||
| 3601 | if (!str)
| 20-2738 | ||||||||||||||||||||||||
| 3602 | return 0; executed 20 times by 3 tests: return 0;Executed by:
| 20 | ||||||||||||||||||||||||
| 3603 | char *msg = new char[strlen(str) + 1]; | - | ||||||||||||||||||||||||
| 3604 | return qstrcpy(msg, str); executed 2738 times by 45 tests: return qstrcpy(msg, str);Executed by:
| 2738 | ||||||||||||||||||||||||
| 3605 | } | - | ||||||||||||||||||||||||
| 3606 | - | |||||||||||||||||||||||||
| 3607 | /*! \internal | - | ||||||||||||||||||||||||
| 3608 | */ | - | ||||||||||||||||||||||||
| 3609 | char *QTest::toString(const void *p) | - | ||||||||||||||||||||||||
| 3610 | { | - | ||||||||||||||||||||||||
| 3611 | char *msg = new char[128]; | - | ||||||||||||||||||||||||
| 3612 | qsnprintf(msg, 128, "%p", p); | - | ||||||||||||||||||||||||
| 3613 | return msg; executed 3240790 times by 171 tests: return msg;Executed by:
| 3240790 | ||||||||||||||||||||||||
| 3614 | } | - | ||||||||||||||||||||||||
| 3615 | - | |||||||||||||||||||||||||
| 3616 | /*! \internal | - | ||||||||||||||||||||||||
| 3617 | */ | - | ||||||||||||||||||||||||
| 3618 | bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual, | - | ||||||||||||||||||||||||
| 3619 | const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3620 | { | - | ||||||||||||||||||||||||
| 3621 | return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", executed 1379 times by 45 tests: return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", toString(t1), toString(t2), actual, expected, file, line);Executed by:
| 1379 | ||||||||||||||||||||||||
| 3622 | toString(t1), toString(t2), actual, expected, file, line); executed 1379 times by 45 tests: return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", toString(t1), toString(t2), actual, expected, file, line);Executed by:
| 1379 | ||||||||||||||||||||||||
| 3623 | } | - | ||||||||||||||||||||||||
| 3624 | - | |||||||||||||||||||||||||
| 3625 | /*! \fn bool QTest::compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line); | - | ||||||||||||||||||||||||
| 3626 | \internal | - | ||||||||||||||||||||||||
| 3627 | */ | - | ||||||||||||||||||||||||
| 3628 | - | |||||||||||||||||||||||||
| 3629 | /*! \fn bool QTest::qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int); | - | ||||||||||||||||||||||||
| 3630 | \internal | - | ||||||||||||||||||||||||
| 3631 | */ | - | ||||||||||||||||||||||||
| 3632 | - | |||||||||||||||||||||||||
| 3633 | /*! \fn bool QTest::qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3634 | \internal | - | ||||||||||||||||||||||||
| 3635 | */ | - | ||||||||||||||||||||||||
| 3636 | - | |||||||||||||||||||||||||
| 3637 | /*! \fn bool QTest::qCompare(QImage const &t1, QImage const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3638 | \internal | - | ||||||||||||||||||||||||
| 3639 | */ | - | ||||||||||||||||||||||||
| 3640 | - | |||||||||||||||||||||||||
| 3641 | /*! \fn bool QTest::qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3642 | \internal | - | ||||||||||||||||||||||||
| 3643 | */ | - | ||||||||||||||||||||||||
| 3644 | - | |||||||||||||||||||||||||
| 3645 | /*! \fn bool QTest::qCompare(T const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3646 | \internal | - | ||||||||||||||||||||||||
| 3647 | */ | - | ||||||||||||||||||||||||
| 3648 | - | |||||||||||||||||||||||||
| 3649 | /*! \fn bool QTest::qCompare(const T *t1, const T *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3650 | \internal | - | ||||||||||||||||||||||||
| 3651 | */ | - | ||||||||||||||||||||||||
| 3652 | - | |||||||||||||||||||||||||
| 3653 | /*! \fn bool QTest::qCompare(T *t1, T *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3654 | \internal | - | ||||||||||||||||||||||||
| 3655 | */ | - | ||||||||||||||||||||||||
| 3656 | - | |||||||||||||||||||||||||
| 3657 | /*! \fn bool QTest::qCompare(const T1 *t1, const T2 *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3658 | \internal | - | ||||||||||||||||||||||||
| 3659 | */ | - | ||||||||||||||||||||||||
| 3660 | - | |||||||||||||||||||||||||
| 3661 | /*! \fn bool QTest::qCompare(T1 *t1, T2 *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3662 | \internal | - | ||||||||||||||||||||||||
| 3663 | */ | - | ||||||||||||||||||||||||
| 3664 | - | |||||||||||||||||||||||||
| 3665 | /*! \fn bool QTest::qCompare(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3666 | \internal | - | ||||||||||||||||||||||||
| 3667 | */ | - | ||||||||||||||||||||||||
| 3668 | - | |||||||||||||||||||||||||
| 3669 | /*! \fn bool QTest::qCompare(char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3670 | \internal | - | ||||||||||||||||||||||||
| 3671 | */ | - | ||||||||||||||||||||||||
| 3672 | - | |||||||||||||||||||||||||
| 3673 | /*! \fn bool QTest::qCompare(char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3674 | \internal | - | ||||||||||||||||||||||||
| 3675 | */ | - | ||||||||||||||||||||||||
| 3676 | - | |||||||||||||||||||||||||
| 3677 | /*! \fn bool QTest::qCompare(const char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3678 | \internal | - | ||||||||||||||||||||||||
| 3679 | */ | - | ||||||||||||||||||||||||
| 3680 | - | |||||||||||||||||||||||||
| 3681 | /*! \fn bool QTest::qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3682 | \internal | - | ||||||||||||||||||||||||
| 3683 | */ | - | ||||||||||||||||||||||||
| 3684 | - | |||||||||||||||||||||||||
| 3685 | /*! \fn bool QTest::qCompare(QLatin1String const &t1, QString const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3686 | \internal | - | ||||||||||||||||||||||||
| 3687 | */ | - | ||||||||||||||||||||||||
| 3688 | - | |||||||||||||||||||||||||
| 3689 | /*! \fn bool QTest::qCompare(QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3690 | \internal | - | ||||||||||||||||||||||||
| 3691 | */ | - | ||||||||||||||||||||||||
| 3692 | - | |||||||||||||||||||||||||
| 3693 | /*! \fn bool QTest::qCompare(QList<T> const &t1, QList<T> const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3694 | \internal | - | ||||||||||||||||||||||||
| 3695 | */ | - | ||||||||||||||||||||||||
| 3696 | - | |||||||||||||||||||||||||
| 3697 | /*! \fn bool QTest::qCompare(QFlags<T> const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3698 | \internal | - | ||||||||||||||||||||||||
| 3699 | */ | - | ||||||||||||||||||||||||
| 3700 | - | |||||||||||||||||||||||||
| 3701 | /*! \fn bool QTest::qCompare(QFlags<T> const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3702 | \internal | - | ||||||||||||||||||||||||
| 3703 | */ | - | ||||||||||||||||||||||||
| 3704 | - | |||||||||||||||||||||||||
| 3705 | /*! \fn bool QTest::qCompare(qint64 const &t1, qint32 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3706 | \internal | - | ||||||||||||||||||||||||
| 3707 | */ | - | ||||||||||||||||||||||||
| 3708 | - | |||||||||||||||||||||||||
| 3709 | /*! \fn bool QTest::qCompare(qint64 const &t1, quint32 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3710 | \internal | - | ||||||||||||||||||||||||
| 3711 | */ | - | ||||||||||||||||||||||||
| 3712 | - | |||||||||||||||||||||||||
| 3713 | /*! \fn bool QTest::qCompare(quint64 const &t1, quint32 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3714 | \internal | - | ||||||||||||||||||||||||
| 3715 | */ | - | ||||||||||||||||||||||||
| 3716 | - | |||||||||||||||||||||||||
| 3717 | /*! \fn bool QTest::qCompare(qint32 const &t1, qint64 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3718 | \internal | - | ||||||||||||||||||||||||
| 3719 | */ | - | ||||||||||||||||||||||||
| 3720 | - | |||||||||||||||||||||||||
| 3721 | /*! \fn bool QTest::qCompare(quint32 const &t1, qint64 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3722 | \internal | - | ||||||||||||||||||||||||
| 3723 | */ | - | ||||||||||||||||||||||||
| 3724 | - | |||||||||||||||||||||||||
| 3725 | /*! \fn bool QTest::qCompare(quint32 const &t1, quint64 const &t2, const char *actual, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3726 | \internal | - | ||||||||||||||||||||||||
| 3727 | */ | - | ||||||||||||||||||||||||
| 3728 | - | |||||||||||||||||||||||||
| 3729 | /*! \fn bool QTest::qTest(const T& actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line) | - | ||||||||||||||||||||||||
| 3730 | \internal | - | ||||||||||||||||||||||||
| 3731 | */ | - | ||||||||||||||||||||||||
| 3732 | - | |||||||||||||||||||||||||
| 3733 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
| 3734 | \internal | - | ||||||||||||||||||||||||
| 3735 | */ | - | ||||||||||||||||||||||||
| 3736 | - | |||||||||||||||||||||||||
| 3737 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
| 3738 | \internal | - | ||||||||||||||||||||||||
| 3739 | */ | - | ||||||||||||||||||||||||
| 3740 | - | |||||||||||||||||||||||||
| 3741 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
| 3742 | \internal | - | ||||||||||||||||||||||||
| 3743 | */ | - | ||||||||||||||||||||||||
| 3744 | - | |||||||||||||||||||||||||
| 3745 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWindow *window, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) | - | ||||||||||||||||||||||||
| 3746 | \internal | - | ||||||||||||||||||||||||
| 3747 | */ | - | ||||||||||||||||||||||||
| 3748 | - | |||||||||||||||||||||||||
| 3749 | /*! \fn void QTest::simulateEvent(QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) | - | ||||||||||||||||||||||||
| 3750 | \internal | - | ||||||||||||||||||||||||
| 3751 | */ | - | ||||||||||||||||||||||||
| 3752 | - | |||||||||||||||||||||||||
| 3753 | /*! \fn void QTest::simulateEvent(QWindow *window, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) | - | ||||||||||||||||||||||||
| 3754 | \internal | - | ||||||||||||||||||||||||
| 3755 | */ | - | ||||||||||||||||||||||||
| 3756 | - | |||||||||||||||||||||||||
| 3757 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |