| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| | ** | |
| | ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). | |
| | ** Contact: http://www.qt-project.org/legal | |
| | ** | |
| | ** This file is part of the QtTest module of the Qt Toolkit. | |
| | ** | |
| | ** $QT_BEGIN_LICENSE:LGPL$ | |
| | ** Commercial License Usage | |
| | ** Licensees holding valid commercial Qt licenses may use this file in | |
| | ** accordance with the commercial license agreement provided with the | |
| | ** Software or, alternatively, in accordance with the terms contained in | |
| | ** a written agreement between you and Digia. For licensing terms and | |
| | ** conditions see http://qt.digia.com/licensing. For further information | |
| | ** use the contact form at http://qt.digia.com/contact-us. | |
| | ** | |
| | ** GNU Lesser General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU Lesser | |
| | ** General Public License version 2.1 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.LGPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU Lesser General Public License version 2.1 requirements | |
| | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | |
| | ** | |
| | ** In addition, as a special exception, Digia gives you certain additional | |
| | ** rights. These rights are described in the Digia Qt LGPL Exception | |
| | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | |
| | ** | |
| | ** GNU General Public License Usage | |
| | ** Alternatively, this file may be used under the terms of the GNU | |
| | ** General Public License version 3.0 as published by the Free Software | |
| | ** Foundation and appearing in the file LICENSE.GPL included in the | |
| | ** packaging of this file. Please review the following information to | |
| | ** ensure the GNU General Public License version 3.0 requirements will be | |
| | ** met: http://www.gnu.org/copyleft/gpl.html. | |
| | ** | |
| | ** | |
| | ** $QT_END_LICENSE$ | |
| | ** | |
| | ****************************************************************************/**************************************************************************** | |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtTest module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 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 Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include <QtTest/qtestcase.h> | - |
| 43 | #include <QtTest/qtestassert.h> | - |
| 44 | | - |
| 45 | #include <QtCore/qbytearray.h> | - |
| 46 | #include <QtCore/qmetaobject.h> | - |
| 47 | #include <QtCore/qobject.h> | - |
| 48 | #include <QtCore/qstringlist.h> | - |
| 49 | #include <QtCore/qvector.h> | - |
| 50 | #include <QtCore/qvarlengtharray.h> | - |
| 51 | #include <QtCore/qcoreapplication.h> | - |
| 52 | #include <QtCore/qfile.h> | - |
| 53 | #include <QtCore/qfileinfo.h> | - |
| 54 | #include <QtCore/qdir.h> | - |
| 55 | #include <QtCore/qprocess.h> | - |
| 56 | #include <QtCore/qdebug.h> | - |
| 57 | #include <QtCore/qlibraryinfo.h> | - |
| 58 | | - |
| 59 | #include <QtTest/private/qtestlog_p.h> | - |
| 60 | #include <QtTest/private/qtesttable_p.h> | - |
| 61 | #include <QtTest/qtestdata.h> | - |
| 62 | #include <QtTest/private/qtestresult_p.h> | - |
| 63 | #include <QtTest/private/qsignaldumper_p.h> | - |
| 64 | #include <QtTest/private/qbenchmark_p.h> | - |
| 65 | #include <QtTest/private/cycle_p.h> | - |
| 66 | | - |
| 67 | #include <stdarg.h> | - |
| 68 | #include <stdio.h> | - |
| 69 | #include <stdlib.h> | - |
| 70 | | - |
| 71 | #ifdef Q_OS_WIN | - |
| 72 | #ifndef Q_OS_WINCE | - |
| 73 | # if !defined(Q_CC_MINGW) || (defined(Q_CC_MINGW) && defined(__MINGW64_VERSION_MAJOR)) | - |
| 74 | # include <crtdbg.h> | - |
| 75 | # endif | - |
| 76 | #endif | - |
| 77 | #include <windows.h> // for Sleep | - |
| 78 | #endif | - |
| 79 | #ifdef Q_OS_UNIX | - |
| 80 | #include <errno.h> | - |
| 81 | #include <signal.h> | - |
| 82 | #include <time.h> | - |
| 83 | #endif | - |
| 84 | | - |
| 85 | #ifdef Q_OS_MAC | - |
| 86 | #include <IOKit/pwr_mgt/IOPMLib.h> | - |
| 87 | #endif | - |
| 88 | | - |
| 89 | QT_BEGIN_NAMESPACE | - |
| 90 | | - |
| 91 | /*! | - |
| 92 | \namespace QTest | - |
| 93 | \inmodule QtTest | - |
| 94 | | - |
| 95 | \brief The QTest namespace contains all the functions and | - |
| 96 | declarations that are related to Qt Test. | - |
| 97 | | - |
| 98 | See the \l{Qt Test Overview} for information about how to write unit tests. | - |
| 99 | */ | - |
| 100 | | - |
| 101 | /*! \macro QVERIFY(condition) | - |
| 102 | | - |
| 103 | \relates QTest | - |
| 104 | | - |
| 105 | The QVERIFY() macro checks whether the \a condition is true or not. If it is | - |
| 106 | true, execution continues. If not, a failure is recorded in the test log | - |
| 107 | and the test won't be executed further. | - |
| 108 | | - |
| 109 | \b {Note:} This macro can only be used in a test function that is invoked | - |
| 110 | by the test framework. | - |
| 111 | | - |
| 112 | Example: | - |
| 113 | \snippet code/src_qtestlib_qtestcase.cpp 0 | - |
| 114 | | - |
| 115 | \sa QCOMPARE(), QTRY_VERIFY() | - |
| 116 | */ | - |
| 117 | | - |
| 118 | /*! \macro QVERIFY2(condition, message) | - |
| 119 | | - |
| 120 | \relates QTest | - |
| 121 | | - |
| 122 | The QVERIFY2() macro behaves exactly like QVERIFY(), except that it outputs | - |
| 123 | a verbose \a message when \a condition is false. The \a message is a plain | - |
| 124 | C string. | - |
| 125 | | - |
| 126 | Example: | - |
| 127 | \snippet code/src_qtestlib_qtestcase.cpp 1 | - |
| 128 | | - |
| 129 | \sa QVERIFY(), QCOMPARE() | - |
| 130 | */ | - |
| 131 | | - |
| 132 | /*! \macro QCOMPARE(actual, expected) | - |
| 133 | | - |
| 134 | \relates QTest | - |
| 135 | | - |
| 136 | The QCOMPARE macro compares an \a actual value to an \a expected value using | - |
| 137 | the equals operator. If \a actual and \a expected are identical, execution | - |
| 138 | continues. If not, a failure is recorded in the test log and the test | - |
| 139 | won't be executed further. | - |
| 140 | | - |
| 141 | In the case of comparing floats and doubles, qFuzzyCompare() is used for | - |
| 142 | comparing. This means that comparing to 0 will likely fail. One solution | - |
| 143 | to this is to compare to 1, and add 1 to the produced output. | - |
| 144 | | - |
| 145 | QCOMPARE tries to output the contents of the values if the comparison fails, | - |
| 146 | so it is visible from the test log why the comparison failed. | - |
| 147 | | - |
| 148 | QCOMPARE is very strict on the data types. Both \a actual and \a expected | - |
| 149 | have to be of the same type, otherwise the test won't compile. This prohibits | - |
| 150 | unspecified behavior from being introduced; that is behavior that usually | - |
| 151 | occurs when the compiler implicitly casts the argument. | - |
| 152 | | - |
| 153 | For your own classes, you can use \l QTest::toString() to format values for | - |
| 154 | outputting into the test log. | - |
| 155 | | - |
| 156 | \note This macro can only be used in a test function that is invoked | - |
| 157 | by the test framework. | - |
| 158 | | - |
| 159 | Example: | - |
| 160 | \snippet code/src_qtestlib_qtestcase.cpp 2 | - |
| 161 | | - |
| 162 | \sa QVERIFY(), QTRY_COMPARE(), QTest::toString() | - |
| 163 | */ | - |
| 164 | | - |
| 165 | /*! \macro QTRY_VERIFY_WITH_TIMEOUT(condition, timeout) | - |
| 166 | \since 5.0 | - |
| 167 | | - |
| 168 | \relates QTest | - |
| 169 | | - |
| 170 | The QTRY_VERIFY_WITH_TIMEOUT() macro is similar to QVERIFY(), but checks the \a condition | - |
| 171 | repeatedly, until either the condition becomes true or the \a timeout is | - |
| 172 | reached. Between each evaluation, events will be processed. If the timeout | - |
| 173 | is reached, a failure is recorded in the test log and the test won't be | - |
| 174 | executed further. | - |
| 175 | | - |
| 176 | \note This macro can only be used in a test function that is invoked | - |
| 177 | by the test framework. | - |
| 178 | | - |
| 179 | \sa QTRY_VERIFY(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() | - |
| 180 | */ | - |
| 181 | | - |
| 182 | | - |
| 183 | /*! \macro QTRY_VERIFY(condition) | - |
| 184 | \since 5.0 | - |
| 185 | | - |
| 186 | \relates QTest | - |
| 187 | | - |
| 188 | Checks the \a condition by invoking QTRY_VERIFY_WITH_TIMEOUT() with a timeout of five seconds. | - |
| 189 | | - |
| 190 | \note This macro can only be used in a test function that is invoked | - |
| 191 | by the test framework. | - |
| 192 | | - |
| 193 | \sa QTRY_VERIFY_WITH_TIMEOUT(), QVERIFY(), QCOMPARE(), QTRY_COMPARE() | - |
| 194 | */ | - |
| 195 | | - |
| 196 | /*! \macro QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout) | - |
| 197 | \since 5.0 | - |
| 198 | | - |
| 199 | \relates QTest | - |
| 200 | | - |
| 201 | The QTRY_COMPARE_WITH_TIMEOUT() macro is similar to QCOMPARE(), but performs the comparison | - |
| 202 | of the \a actual and \a expected values repeatedly, until either the two values | - |
| 203 | are equal or the \a timeout is reached. Between each comparison, events | - |
| 204 | will be processed. If the timeout is reached, a failure is recorded in the | - |
| 205 | test log and the test won't be executed further. | - |
| 206 | | - |
| 207 | \note This macro can only be used in a test function that is invoked | - |
| 208 | by the test framework. | - |
| 209 | | - |
| 210 | \sa QTRY_COMPARE(), QCOMPARE(), QVERIFY(), QTRY_VERIFY() | - |
| 211 | */ | - |
| 212 | | - |
| 213 | /*! \macro QTRY_COMPARE(actual, expected) | - |
| 214 | \since 5.0 | - |
| 215 | | - |
| 216 | \relates QTest | - |
| 217 | | - |
| 218 | Performs a comparison of the \a actual and \a expected values by | - |
| 219 | invoking QTRY_COMPARE_WITH_TIMEOUT() with a timeout of five seconds. | - |
| 220 | | - |
| 221 | \note This macro can only be used in a test function that is invoked | - |
| 222 | by the test framework. | - |
| 223 | | - |
| 224 | \sa QTRY_COMPARE_WITH_TIMEOUT(), QCOMPARE(), QVERIFY(), QTRY_VERIFY() | - |
| 225 | */ | - |
| 226 | | - |
| 227 | /*! \macro QFETCH(type, name) | - |
| 228 | | - |
| 229 | \relates QTest | - |
| 230 | | - |
| 231 | The fetch macro creates a local variable named \a name with the type \a type | - |
| 232 | on the stack. \a name has to match the element name from the test's data. | - |
| 233 | If no such element exists, the test will assert. | - |
| 234 | | - |
| 235 | Assuming a test has the following data: | - |
| 236 | | - |
| 237 | \snippet code/src_qtestlib_qtestcase.cpp 3 | - |
| 238 | | - |
| 239 | The test data has two elements, a QString called \c aString and an integer | - |
| 240 | called \c expected. To fetch these values in the actual test: | - |
| 241 | | - |
| 242 | \snippet code/src_qtestlib_qtestcase.cpp 4 | - |
| 243 | | - |
| 244 | \c aString and \c expected are variables on the stack that are initialized with | - |
| 245 | the current test data. | - |
| 246 | | - |
| 247 | \b {Note:} This macro can only be used in a test function that is invoked | - |
| 248 | by the test framework. The test function must have a _data function. | - |
| 249 | */ | - |
| 250 | | - |
| 251 | /*! \macro QWARN(message) | - |
| 252 | | - |
| 253 | \relates QTest | - |
| 254 | \threadsafe | - |
| 255 | | - |
| 256 | Appends \a message as a warning to the test log. This macro can be used anywhere | - |
| 257 | in your tests. | - |
| 258 | */ | - |
| 259 | | - |
| 260 | /*! \macro QFAIL(message) | - |
| 261 | | - |
| 262 | \relates QTest | - |
| 263 | | - |
| 264 | This macro can be used to force a test failure. The test stops | - |
| 265 | executing and the failure \a message is appended to the test log. | - |
| 266 | | - |
| 267 | \b {Note:} This macro can only be used in a test function that is invoked | - |
| 268 | by the test framework. | - |
| 269 | | - |
| 270 | Example: | - |
| 271 | | - |
| 272 | \snippet code/src_qtestlib_qtestcase.cpp 5 | - |
| 273 | */ | - |
| 274 | | - |
| 275 | /*! \macro QTEST(actual, testElement) | - |
| 276 | | - |
| 277 | \relates QTest | - |
| 278 | | - |
| 279 | QTEST() is a convenience macro for \l QCOMPARE() that compares | - |
| 280 | the value \a actual with the element \a testElement from the test's data. | - |
| 281 | If there is no such element, the test asserts. | - |
| 282 | | - |
| 283 | Apart from that, QTEST() behaves exactly as \l QCOMPARE(). | - |
| 284 | | - |
| 285 | Instead of writing: | - |
| 286 | | - |
| 287 | \snippet code/src_qtestlib_qtestcase.cpp 6 | - |
| 288 | | - |
| 289 | you can write: | - |
| 290 | | - |
| 291 | \snippet code/src_qtestlib_qtestcase.cpp 7 | - |
| 292 | | - |
| 293 | \sa QCOMPARE() | - |
| 294 | */ | - |
| 295 | | - |
| 296 | /*! \macro QSKIP(description) | - |
| 297 | | - |
| 298 | \relates QTest | - |
| 299 | | - |
| 300 | If called from a test function, the QSKIP() macro stops execution of the test | - |
| 301 | without adding a failure to the test log. You can use it to skip tests that | - |
| 302 | wouldn't make sense in the current configuration. The text \a description is | - |
| 303 | appended to the test log and should contain an explanation of why the test | - |
| 304 | couldn't be executed. | - |
| 305 | | - |
| 306 | If the test is data-driven, each call to QSKIP() will skip only the current | - |
| 307 | row of test data, so an unconditional call to QSKIP will produce one skip | - |
| 308 | message in the test log for each row of test data. | - |
| 309 | | - |
| 310 | If called from an _data function, the QSKIP() macro will stop execution of | - |
| 311 | the _data function and will prevent execution of the associated test | - |
| 312 | function. | - |
| 313 | | - |
| 314 | If called from initTestCase() or initTestCase_data(), the QSKIP() macro will | - |
| 315 | skip all test and _data functions. | - |
| 316 | | - |
| 317 | \b {Note:} This macro can only be used in a test function or _data | - |
| 318 | function that is invoked by the test framework. | - |
| 319 | | - |
| 320 | Example: | - |
| 321 | \snippet code/src_qtestlib_qtestcase.cpp 8 | - |
| 322 | */ | - |
| 323 | | - |
| 324 | /*! \macro QEXPECT_FAIL(dataIndex, comment, mode) | - |
| 325 | | - |
| 326 | \relates QTest | - |
| 327 | | - |
| 328 | The QEXPECT_FAIL() macro marks the next \l QCOMPARE() or \l QVERIFY() as an | - |
| 329 | expected failure. Instead of adding a failure to the test log, an expected | - |
| 330 | failure will be reported. | - |
| 331 | | - |
| 332 | If a \l QVERIFY() or \l QCOMPARE() is marked as an expected failure, | - |
| 333 | but passes instead, an unexpected pass (XPASS) is written to the test log. | - |
| 334 | | - |
| 335 | The parameter \a dataIndex describes for which entry in the test data the | - |
| 336 | failure is expected. Pass an empty string (\c{""}) if the failure | - |
| 337 | is expected for all entries or if no test data exists. | - |
| 338 | | - |
| 339 | \a comment will be appended to the test log for the expected failure. | - |
| 340 | | - |
| 341 | \a mode is a \l QTest::TestFailMode and sets whether the test should | - |
| 342 | continue to execute or not. | - |
| 343 | | - |
| 344 | \b {Note:} This macro can only be used in a test function that is invoked | - |
| 345 | by the test framework. | - |
| 346 | | - |
| 347 | Example 1: | - |
| 348 | \snippet code/src_qtestlib_qtestcase.cpp 9 | - |
| 349 | | - |
| 350 | In the example above, an expected fail will be written into the test output | - |
| 351 | if the variable \c i is not 42. If the variable \c i is 42, an unexpected pass | - |
| 352 | is written instead. The QEXPECT_FAIL() has no influence on the second QCOMPARE() | - |
| 353 | statement in the example. | - |
| 354 | | - |
| 355 | Example 2: | - |
| 356 | \snippet code/src_qtestlib_qtestcase.cpp 10 | - |
| 357 | | - |
| 358 | The above testfunction will not continue executing for the test data | - |
| 359 | entry \c{data27}. | - |
| 360 | | - |
| 361 | \sa QTest::TestFailMode, QVERIFY(), QCOMPARE() | - |
| 362 | */ | - |
| 363 | | - |
| 364 | /*! \macro QFINDTESTDATA(filename) | - |
| 365 | \since 5.0 | - |
| 366 | | - |
| 367 | \relates QTest | - |
| 368 | | - |
| 369 | Returns a QString for the testdata file referred to by \a filename, or an | - |
| 370 | empty QString if the testdata file could not be found. | - |
| 371 | | - |
| 372 | This macro allows the test to load data from an external file without | - |
| 373 | hardcoding an absolute filename into the test, or using relative paths | - |
| 374 | which may be error prone. | - |
| 375 | | - |
| 376 | The returned path will be the first path from the following list which | - |
| 377 | resolves to an existing file or directory: | - |
| 378 | | - |
| 379 | \list | - |
| 380 | \li \a filename relative to QCoreApplication::applicationDirPath() | - |
| 381 | (only if a QCoreApplication or QApplication object has been created). | - |
| 382 | \li \a filename relative to the test's standard install directory | - |
| 383 | (QLibraryInfo::TestsPath with the lowercased testcase name appended). | - |
| 384 | \li \a filename relative to the directory containing the source file from which | - |
| 385 | QFINDTESTDATA is invoked. | - |
| 386 | \endlist | - |
| 387 | | - |
| 388 | If the named file/directory does not exist at any of these locations, | - |
| 389 | a warning is printed to the test log. | - |
| 390 | | - |
| 391 | For example, in this code: | - |
| 392 | \snippet code/src_qtestlib_qtestcase.cpp 26 | - |
| 393 | | - |
| 394 | The testdata file will be resolved as the first existing file from: | - |
| 395 | | - |
| 396 | \list | - |
| 397 | \li \c{/home/user/build/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml} | - |
| 398 | \li \c{/usr/local/Qt-5.0.0/tests/tst_myxmlparser/testxml/simple1.xml} | - |
| 399 | \li \c{/home/user/sources/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml} | - |
| 400 | \endlist | - |
| 401 | | - |
| 402 | This allows the test to find its testdata regardless of whether the | - |
| 403 | test has been installed, and regardless of whether the test's build tree | - |
| 404 | is equal to the test's source tree. | - |
| 405 | | - |
| 406 | \b {Note:} reliable detection of testdata from the source directory requires | - |
| 407 | either that qmake is used, or the \c{QT_TESTCASE_BUILDDIR} macro is defined to | - |
| 408 | point to the working directory from which the compiler is invoked, or only | - |
| 409 | absolute paths to the source files are passed to the compiler. Otherwise, the | - |
| 410 | absolute path of the source directory cannot be determined. | - |
| 411 | | - |
| 412 | \b {Note:} For tests that use the \l QTEST_APPLESS_MAIN() macro to generate a | - |
| 413 | \c{main()} function, \c{QFINDTESTDATA} will not attempt to find test data | - |
| 414 | relative to QCoreApplication::applicationDirPath(). In practice, this means that | - |
| 415 | tests using \c{QTEST_APPLESS_MAIN()} will fail to find their test data | - |
| 416 | if run from a shadow build tree. | - |
| 417 | */ | - |
| 418 | | - |
| 419 | /*! \macro QTEST_MAIN(TestClass) | - |
| 420 | | - |
| 421 | \relates QTest | - |
| 422 | | - |
| 423 | Implements a main() function that instantiates an application object and | - |
| 424 | the \a TestClass, and executes all tests in the order they were defined. | - |
| 425 | Use this macro to build stand-alone executables. | - |
| 426 | | - |
| 427 | If \c QT_WIDGETS_LIB is defined, the application object will be a QApplication, | - |
| 428 | if \c QT_GUI_LIB is defined, the application object will be a QGuiApplication, | - |
| 429 | otherwise it will be a QCoreApplication. If qmake is used and the configuration | - |
| 430 | includes \c{QT += widgets}, then \c QT_WIDGETS_LIB will be defined automatically. | - |
| 431 | Similarly, if qmake is used and the configuration includes \c{QT += gui}, then | - |
| 432 | \c QT_GUI_LIB will be defined automatically. | - |
| 433 | | - |
| 434 | \b {Note:} On platforms that have keypad navigation enabled by default, | - |
| 435 | this macro will forcefully disable it if \c QT_WIDGETS_LIB is defined. This is done | - |
| 436 | to simplify the usage of key events when writing autotests. If you wish to write a | - |
| 437 | test case that uses keypad navigation, you should enable it either in the | - |
| 438 | \c {initTestCase()} or \c {init()} functions of your test case by calling | - |
| 439 | \l {QApplication::setNavigationMode()}. | - |
| 440 | | - |
| 441 | Example: | - |
| 442 | \snippet code/src_qtestlib_qtestcase.cpp 11 | - |
| 443 | | - |
| 444 | \sa QTEST_APPLESS_MAIN(), QTEST_GUILESS_MAIN(), QTest::qExec(), | - |
| 445 | QApplication::setNavigationMode() | - |
| 446 | */ | - |
| 447 | | - |
| 448 | /*! \macro QTEST_APPLESS_MAIN(TestClass) | - |
| 449 | | - |
| 450 | \relates QTest | - |
| 451 | | - |
| 452 | Implements a main() function that executes all tests in \a TestClass. | - |
| 453 | | - |
| 454 | Behaves like \l QTEST_MAIN(), but doesn't instantiate a QApplication | - |
| 455 | object. Use this macro for really simple stand-alone non-GUI tests. | - |
| 456 | | - |
| 457 | \sa QTEST_MAIN() | - |
| 458 | */ | - |
| 459 | | - |
| 460 | /*! \macro QTEST_GUILESS_MAIN(TestClass) | - |
| 461 | \since 5.0 | - |
| 462 | | - |
| 463 | \relates QTest | - |
| 464 | | - |
| 465 | Implements a main() function that instantiates a QCoreApplication object | - |
| 466 | and the \a TestClass, and executes all tests in the order they were | - |
| 467 | defined. Use this macro to build stand-alone executables. | - |
| 468 | | - |
| 469 | Behaves like \l QTEST_MAIN(), but instantiates a QCoreApplication instead | - |
| 470 | of the QApplication object. Use this macro if your test case doesn't need | - |
| 471 | functionality offered by QApplication, but the event loop is still necessary. | - |
| 472 | | - |
| 473 | \sa QTEST_MAIN() | - |
| 474 | */ | - |
| 475 | | - |
| 476 | /*! | - |
| 477 | \macro QBENCHMARK | - |
| 478 | | - |
| 479 | \relates QTest | - |
| 480 | | - |
| 481 | This macro is used to measure the performance of code within a test. | - |
| 482 | The code to be benchmarked is contained within a code block following | - |
| 483 | this macro. | - |
| 484 | | - |
| 485 | For example: | - |
| 486 | | - |
| 487 | \snippet code/src_qtestlib_qtestcase.cpp 27 | - |
| 488 | | - |
| 489 | \sa {Qt Test Overview#Creating a Benchmark}{Creating a Benchmark}, | - |
| 490 | {Chapter 5: Writing a Benchmark}{Writing a Benchmark} | - |
| 491 | */ | - |
| 492 | | - |
| 493 | /*! | - |
| 494 | \macro QBENCHMARK_ONCE | - |
| 495 | \since 4.6 | - |
| 496 | | - |
| 497 | \relates QTest | - |
| 498 | | - |
| 499 | \brief The QBENCHMARK_ONCE macro is for measuring performance of a | - |
| 500 | code block by running it once. | - |
| 501 | | - |
| 502 | This macro is used to measure the performance of code within a test. | - |
| 503 | The code to be benchmarked is contained within a code block following | - |
| 504 | this macro. | - |
| 505 | | - |
| 506 | Unlike QBENCHMARK, the contents of the contained code block is only run | - |
| 507 | once. The elapsed time will be reported as "0" if it's to short to | - |
| 508 | be measured by the selected backend. (Use) | - |
| 509 | | - |
| 510 | \sa {Qt Test Overview#Creating a Benchmark}{Creating a Benchmark}, | - |
| 511 | {Chapter 5: Writing a Benchmark}{Writing a Benchmark} | - |
| 512 | */ | - |
| 513 | | - |
| 514 | /*! \enum QTest::TestFailMode | - |
| 515 | | - |
| 516 | This enum describes the modes for handling an expected failure of the | - |
| 517 | \l QVERIFY() or \l QCOMPARE() macros. | - |
| 518 | | - |
| 519 | \value Abort Aborts the execution of the test. Use this mode when it | - |
| 520 | doesn't make sense to execute the test any further after the | - |
| 521 | expected failure. | - |
| 522 | | - |
| 523 | \value Continue Continues execution of the test after the expected failure. | - |
| 524 | | - |
| 525 | \sa QEXPECT_FAIL() | - |
| 526 | */ | - |
| 527 | | - |
| 528 | /*! \enum QTest::KeyAction | - |
| 529 | | - |
| 530 | This enum describes possible actions for key handling. | - |
| 531 | | - |
| 532 | \value Press The key is pressed. | - |
| 533 | \value Release The key is released. | - |
| 534 | \value Click The key is clicked (pressed and released). | - |
| 535 | */ | - |
| 536 | | - |
| 537 | /*! \enum QTest::MouseAction | - |
| 538 | | - |
| 539 | This enum describes possible actions for mouse handling. | - |
| 540 | | - |
| 541 | \value MousePress A mouse button is pressed. | - |
| 542 | \value MouseRelease A mouse button is released. | - |
| 543 | \value MouseClick A mouse button is clicked (pressed and released). | - |
| 544 | \value MouseDClick A mouse button is double clicked (pressed and released twice). | - |
| 545 | \value MouseMove The mouse pointer has moved. | - |
| 546 | */ | - |
| 547 | | - |
| 548 | /*! \fn void QTest::keyClick(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 549 | | - |
| 550 | \overload | - |
| 551 | | - |
| 552 | Simulates clicking of \a key with an optional \a modifier on a \a widget. | - |
| 553 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - |
| 554 | before clicking the key. | - |
| 555 | | - |
| 556 | Example: | - |
| 557 | \snippet code/src_qtestlib_qtestcase.cpp 13 | - |
| 558 | | - |
| 559 | The example above simulates clicking \c a on \c myWidget without | - |
| 560 | any keyboard modifiers and without delay of the test. | - |
| 561 | | - |
| 562 | \sa QTest::keyClicks() | - |
| 563 | */ | - |
| 564 | | - |
| 565 | /*! \fn void QTest::keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 566 | | - |
| 567 | Simulates clicking of \a key with an optional \a modifier on a \a widget. | - |
| 568 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - |
| 569 | before clicking the key. | - |
| 570 | | - |
| 571 | Examples: | - |
| 572 | \snippet code/src_qtestlib_qtestcase.cpp 14 | - |
| 573 | | - |
| 574 | The first example above simulates clicking the \c escape key on \c | - |
| 575 | myWidget without any keyboard modifiers and without delay. The | - |
| 576 | second example simulates clicking \c shift-escape on \c myWidget | - |
| 577 | following a 200 ms delay of the test. | - |
| 578 | | - |
| 579 | \sa QTest::keyClicks() | - |
| 580 | */ | - |
| 581 | | - |
| 582 | /*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 583 | | - |
| 584 | Sends a Qt key event to \a widget with the given \a key and an associated \a action. | - |
| 585 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay | - |
| 586 | (in milliseconds) of the test before sending the event. | - |
| 587 | */ | - |
| 588 | | - |
| 589 | /*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 590 | | - |
| 591 | \overload | - |
| 592 | | - |
| 593 | Sends a Qt key event to \a widget with the given key \a ascii and an associated \a action. | - |
| 594 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay | - |
| 595 | (in milliseconds) of the test before sending the event. | - |
| 596 | | - |
| 597 | */ | - |
| 598 | | - |
| 599 | /*! \fn void QTest::keyPress(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 600 | | - |
| 601 | Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay | - |
| 602 | is larger than 0, the test will wait for \a delay milliseconds before pressing the key. | - |
| 603 | | - |
| 604 | \b {Note:} At some point you should release the key using \l keyRelease(). | - |
| 605 | | - |
| 606 | \sa QTest::keyRelease(), QTest::keyClick() | - |
| 607 | */ | - |
| 608 | | - |
| 609 | /*! \fn void QTest::keyPress(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 610 | | - |
| 611 | \overload | - |
| 612 | | - |
| 613 | Simulates pressing a \a key with an optional \a modifier on a \a widget. | - |
| 614 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - |
| 615 | before pressing the key. | - |
| 616 | | - |
| 617 | \b {Note:} At some point you should release the key using \l keyRelease(). | - |
| 618 | | - |
| 619 | \sa QTest::keyRelease(), QTest::keyClick() | - |
| 620 | */ | - |
| 621 | | - |
| 622 | /*! \fn void QTest::keyRelease(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 623 | | - |
| 624 | Simulates releasing a \a key with an optional \a modifier on a \a widget. | - |
| 625 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - |
| 626 | before releasing the key. | - |
| 627 | | - |
| 628 | \sa QTest::keyPress(), QTest::keyClick() | - |
| 629 | */ | - |
| 630 | | - |
| 631 | /*! \fn void QTest::keyRelease(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 632 | | - |
| 633 | \overload | - |
| 634 | | - |
| 635 | Simulates releasing a \a key with an optional \a modifier on a \a widget. | - |
| 636 | If \a delay is larger than 0, the test will wait for \a delay milliseconds | - |
| 637 | before releasing the key. | - |
| 638 | | - |
| 639 | \sa QTest::keyClick() | - |
| 640 | */ | - |
| 641 | | - |
| 642 | | - |
| 643 | /*! \fn void QTest::keyClicks(QWidget *widget, const QString &sequence, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) | - |
| 644 | | - |
| 645 | Simulates clicking a \a sequence of keys on a \a | - |
| 646 | widget. Optionally, a keyboard \a modifier can be specified as | - |
| 647 | well as a \a delay (in milliseconds) of the test before each key | - |
| 648 | click. | - |
| 649 | | - |
| 650 | Example: | - |
| 651 | \snippet code/src_qtestlib_qtestcase.cpp 15 | - |
| 652 | | - |
| 653 | The example above simulates clicking the sequence of keys | - |
| 654 | representing "hello world" on \c myWidget without any keyboard | - |
| 655 | modifiers and without delay of the test. | - |
| 656 | | - |
| 657 | \sa QTest::keyClick() | - |
| 658 | */ | - |
| 659 | | - |
| 660 | /*! \fn void QTest::mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - |
| 661 | | - |
| 662 | Simulates pressing a mouse \a button with an optional \a modifier | - |
| 663 | on a \a widget. The position is defined by \a pos; the default | - |
| 664 | position is the center of the widget. If \a delay is specified, | - |
| 665 | the test will wait for the specified amount of milliseconds before | - |
| 666 | the press. | - |
| 667 | | - |
| 668 | \sa QTest::mouseRelease(), QTest::mouseClick() | - |
| 669 | */ | - |
| 670 | | - |
| 671 | /*! \fn void QTest::mouseRelease(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - |
| 672 | | - |
| 673 | Simulates releasing a mouse \a button with an optional \a modifier | - |
| 674 | on a \a widget. The position of the release is defined by \a pos; | - |
| 675 | the default position is the center of the widget. If \a delay is | - |
| 676 | specified, the test will wait for the specified amount of | - |
| 677 | milliseconds before releasing the button. | - |
| 678 | | - |
| 679 | \sa QTest::mousePress(), QTest::mouseClick() | - |
| 680 | */ | - |
| 681 | | - |
| 682 | /*! \fn void QTest::mouseClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - |
| 683 | | - |
| 684 | Simulates clicking a mouse \a button with an optional \a modifier | - |
| 685 | on a \a widget. The position of the click is defined by \a pos; | - |
| 686 | the default position is the center of the widget. If \a delay is | - |
| 687 | specified, the test will wait for the specified amount of | - |
| 688 | milliseconds before pressing and before releasing the button. | - |
| 689 | | - |
| 690 | \sa QTest::mousePress(), QTest::mouseRelease() | - |
| 691 | */ | - |
| 692 | | - |
| 693 | /*! \fn void QTest::mouseDClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) | - |
| 694 | | - |
| 695 | Simulates double clicking a mouse \a button with an optional \a | - |
| 696 | modifier on a \a widget. The position of the click is defined by | - |
| 697 | \a pos; the default position is the center of the widget. If \a | - |
| 698 | delay is specified, the test will wait for the specified amount of | - |
| 699 | milliseconds before each press and release. | - |
| 700 | | - |
| 701 | \sa QTest::mouseClick() | - |
| 702 | */ | - |
| 703 | | - |
| 704 | /*! \fn void QTest::mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1) | - |
| 705 | | - |
| 706 | Moves the mouse pointer to a \a widget. If \a pos is not | - |
| 707 | specified, the mouse pointer moves to the center of the widget. If | - |
| 708 | a \a delay (in milliseconds) is given, the test will wait before | - |
| 709 | moving the mouse pointer. | - |
| 710 | */ | - |
| 711 | | - |
| 712 | /*! | - |
| 713 | \fn char *QTest::toString(const T &value) | - |
| 714 | | - |
| 715 | Returns a textual representation of \a value. This function is used by | - |
| 716 | \l QCOMPARE() to output verbose information in case of a test failure. | - |
| 717 | | - |
| 718 | You can add specializations of this function to your test to enable | - |
| 719 | verbose output. | - |
| 720 | | - |
| 721 | \b {Note:} The caller of toString() must delete the returned data | - |
| 722 | using \c{delete[]}. Your implementation should return a string | - |
| 723 | created with \c{new[]} or qstrdup(). | - |
| 724 | | - |
| 725 | Example: | - |
| 726 | | - |
| 727 | \snippet code/src_qtestlib_qtestcase.cpp 16 | - |
| 728 | | - |
| 729 | The example above defines a toString() specialization for a class | - |
| 730 | called \c MyPoint. Whenever a comparison of two instances of \c | - |
| 731 | MyPoint fails, \l QCOMPARE() will call this function to output the | - |
| 732 | contents of \c MyPoint to the test log. | - |
| 733 | | - |
| 734 | \sa QCOMPARE() | - |
| 735 | */ | - |
| 736 | | - |
| 737 | /*! | - |
| 738 | \fn char *QTest::toString(const QLatin1String &string) | - |
| 739 | \overload | - |
| 740 | | - |
| 741 | Returns a textual representation of the given \a string. | - |
| 742 | */ | - |
| 743 | | - |
| 744 | /*! | - |
| 745 | \fn char *QTest::toString(const QString &string) | - |
| 746 | \overload | - |
| 747 | | - |
| 748 | Returns a textual representation of the given \a string. | - |
| 749 | */ | - |
| 750 | | - |
| 751 | /*! | - |
| 752 | \fn char *QTest::toString(const QByteArray &ba) | - |
| 753 | \overload | - |
| 754 | | - |
| 755 | Returns a textual representation of the byte array \a ba. | - |
| 756 | | - |
| 757 | \sa QTest::toHexRepresentation() | - |
| 758 | */ | - |
| 759 | | - |
| 760 | /*! | - |
| 761 | \fn char *QTest::toString(const QTime &time) | - |
| 762 | \overload | - |
| 763 | | - |
| 764 | Returns a textual representation of the given \a time. | - |
| 765 | */ | - |
| 766 | | - |
| 767 | /*! | - |
| 768 | \fn char *QTest::toString(const QDate &date) | - |
| 769 | \overload | - |
| 770 | | - |
| 771 | Returns a textual representation of the given \a date. | - |
| 772 | */ | - |
| 773 | | - |
| 774 | /*! | - |
| 775 | \fn char *QTest::toString(const QDateTime &dateTime) | - |
| 776 | \overload | - |
| 777 | | - |
| 778 | Returns a textual representation of the date and time specified by | - |
| 779 | \a dateTime. | - |
| 780 | */ | - |
| 781 | | - |
| 782 | /*! | - |
| 783 | \fn char *QTest::toString(const QChar &character) | - |
| 784 | \overload | - |
| 785 | | - |
| 786 | Returns a textual representation of the given \a character. | - |
| 787 | */ | - |
| 788 | | - |
| 789 | /*! | - |
| 790 | \fn char *QTest::toString(const QPoint &point) | - |
| 791 | \overload | - |
| 792 | | - |
| 793 | Returns a textual representation of the given \a point. | - |
| 794 | */ | - |
| 795 | | - |
| 796 | /*! | - |
| 797 | \fn char *QTest::toString(const QSize &size) | - |
| 798 | \overload | - |
| 799 | | - |
| 800 | Returns a textual representation of the given \a size. | - |
| 801 | */ | - |
| 802 | | - |
| 803 | /*! | - |
| 804 | \fn char *QTest::toString(const QRect &rectangle) | - |
| 805 | \overload | - |
| 806 | | - |
| 807 | Returns a textual representation of the given \a rectangle. | - |
| 808 | */ | - |
| 809 | | - |
| 810 | /*! | - |
| 811 | \fn char *QTest::toString(const QUrl &url) | - |
| 812 | \since 4.4 | - |
| 813 | \overload | - |
| 814 | | - |
| 815 | Returns a textual representation of the given \a url. | - |
| 816 | */ | - |
| 817 | | - |
| 818 | /*! | - |
| 819 | \fn char *QTest::toString(const QPointF &point) | - |
| 820 | \overload | - |
| 821 | | - |
| 822 | Returns a textual representation of the given \a point. | - |
| 823 | */ | - |
| 824 | | - |
| 825 | /*! | - |
| 826 | \fn char *QTest::toString(const QSizeF &size) | - |
| 827 | \overload | - |
| 828 | | - |
| 829 | Returns a textual representation of the given \a size. | - |
| 830 | */ | - |
| 831 | | - |
| 832 | /*! | - |
| 833 | \fn char *QTest::toString(const QRectF &rectangle) | - |
| 834 | \overload | - |
| 835 | | - |
| 836 | Returns a textual representation of the given \a rectangle. | - |
| 837 | */ | - |
| 838 | | - |
| 839 | /*! | - |
| 840 | \fn char *QTest::toString(const QVariant &variant) | - |
| 841 | \overload | - |
| 842 | | - |
| 843 | Returns a textual representation of the given \a variant. | - |
| 844 | */ | - |
| 845 | | - |
| 846 | /*! \fn void QTest::qWait(int ms) | - |
| 847 | | - |
| 848 | Waits for \a ms milliseconds. While waiting, events will be processed and | - |
| 849 | your test will stay responsive to user interface events or network communication. | - |
| 850 | | - |
| 851 | Example: | - |
| 852 | \snippet code/src_qtestlib_qtestcase.cpp 17 | - |
| 853 | | - |
| 854 | The code above will wait until the network server is responding for a | - |
| 855 | maximum of about 12.5 seconds. | - |
| 856 | | - |
| 857 | \sa QTest::qSleep(), QSignalSpy::wait() | - |
| 858 | */ | - |
| 859 | | - |
| 860 | /*! \fn bool QTest::qWaitForWindowExposed(QWindow *window, int timeout) | - |
| 861 | \since 5.0 | - |
| 862 | | - |
| 863 | Waits for \a timeout milliseconds or until the \a window is exposed. | - |
| 864 | Returns true if \c window is exposed within \a timeout milliseconds, otherwise returns false. | - |
| 865 | | - |
| 866 | This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some | - |
| 867 | time after being asked to show itself on the screen. | - |
| 868 | | - |
| 869 | \sa QTest::qWaitForWindowActive(), QWindow::isExposed() | - |
| 870 | */ | - |
| 871 | | - |
| 872 | /*! \fn bool QTest::qWaitForWindowActive(QWindow *window, int timeout) | - |
| 873 | \since 5.0 | - |
| 874 | | - |
| 875 | Waits for \a timeout milliseconds or until the \a window is active. | - |
| 876 | | - |
| 877 | Returns true if \c window is active within \a timeout milliseconds, otherwise returns false. | - |
| 878 | | - |
| 879 | \sa QTest::qWaitForWindowExposed(), QWindow::isActive() | - |
| 880 | */ | - |
| 881 | | - |
| 882 | /*! \fn bool QTest::qWaitForWindowExposed(QWidget *widget, int timeout) | - |
| 883 | \since 5.0 | - |
| 884 | | - |
| 885 | Waits for \a timeout milliseconds or until the \a widget's window is exposed. | - |
| 886 | Returns true if \c widget's window is exposed within \a timeout milliseconds, otherwise returns false. | - |
| 887 | | - |
| 888 | This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some | - |
| 889 | time after being asked to show itself on the screen. | - |
| 890 | | - |
| 891 | \sa QTest::qWaitForWindowActive() | - |
| 892 | */ | - |
| 893 | | - |
| 894 | /*! \fn bool QTest::qWaitForWindowActive(QWidget *widget, int timeout) | - |
| 895 | \since 5.0 | - |
| 896 | | - |
| 897 | Waits for \a timeout milliseconds or until the \a widget's window is active. | - |
| 898 | | - |
| 899 | Returns true if \c widget's window is active within \a timeout milliseconds, otherwise returns false. | - |
| 900 | | - |
| 901 | \sa QTest::qWaitForWindowExposed(), QWidget::isActiveWindow() | - |
| 902 | */ | - |
| 903 | | - |
| 904 | /*! \fn bool QTest::qWaitForWindowShown(QWidget *widget, int timeout) | - |
| 905 | \since 5.0 | - |
| 906 | \deprecated | - |
| 907 | | - |
| 908 | Waits for \a timeout milliseconds or until the \a widget's window is exposed. | - |
| 909 | Returns true if \c widget's window is exposed within \a timeout milliseconds, otherwise returns false. | - |
| 910 | | - |
| 911 | This function does the same as qWaitForWindowExposed(). | - |
| 912 | | - |
| 913 | Example: | - |
| 914 | \snippet code/src_qtestlib_qtestcase.cpp 24 | - |
| 915 | | - |
| 916 | \sa QTest::qWaitForWindowActive(), QTest::qWaitForWindowExposed() | - |
| 917 | */ | - |
| 918 | | - |
| 919 | /*! | - |
| 920 | \class QTest::QTouchEventSequence | - |
| 921 | \inmodule QtTest | - |
| 922 | \since 4.6 | - |
| 923 | | - |
| 924 | \brief The QTouchEventSequence class is used to simulate a sequence of touch events. | - |
| 925 | | - |
| 926 | To simulate a sequence of touch events on a specific device for a window or widget, call | - |
| 927 | QTest::touchEvent to create a QTouchEventSequence instance. Add touch events to | - |
| 928 | the sequence by calling press(), move(), release() and stationary(), and let the | - |
| 929 | instance run out of scope to commit the sequence to the event system. | - |
| 930 | | - |
| 931 | Example: | - |
| 932 | \snippet code/src_qtestlib_qtestcase.cpp 25 | - |
| 933 | */ | - |
| 934 | | - |
| 935 | /*! | - |
| 936 | \fn QTest::QTouchEventSequence::~QTouchEventSequence() | - |
| 937 | | - |
| 938 | Commits this sequence of touch events, unless autoCommit was disabled, and frees allocated resources. | - |
| 939 | */ | - |
| 940 | | - |
| 941 | /*! | - |
| 942 | \fn void QTest::QTouchEventSequence::commit(bool processEvents) | - |
| 943 | | - |
| 944 | Commits this sequence of touch events to the event system. Normally there is no need to call this | - |
| 945 | function because it is called from the destructor. However, if autoCommit is disabled, the events | - |
| 946 | only get committed upon explicitly calling this function. | - |
| 947 | | - |
| 948 | In special cases tests may want to disable the processing of the events. This can be achieved by | - |
| 949 | setting \a processEvents to false. This results in merely queuing the events, the event loop will | - |
| 950 | not be forced to process them. | - |
| 951 | */ | - |
| 952 | | - |
| 953 | /*! | - |
| 954 | \fn QTouchEventSequence &QTest::QTouchEventSequence::press(int touchId, const QPoint &pt, QWindow *window) | - |
| 955 | \since 5.0 | - |
| 956 | | - |
| 957 | Adds a press event for touchpoint \a touchId at position \a pt to this sequence and returns | - |
| 958 | a reference to this QTouchEventSequence. | - |
| 959 | | - |
| 960 | The position \a pt is interpreted as relative to \a window. If \a window is the null pointer, then | - |
| 961 | \a pt is interpreted as relative to the window provided when instantiating this QTouchEventSequence. | - |
| 962 | | - |
| 963 | Simulates that the user pressed the touch screen or pad with the finger identified by \a touchId. | - |
| 964 | */ | - |
| 965 | | - |
| 966 | /*! | - |
| 967 | \fn QTouchEventSequence &QTest::QTouchEventSequence::press(int touchId, const QPoint &pt, QWidget *widget) | - |
| 968 | | - |
| 969 | Adds a press event for touchpoint \a touchId at position \a pt to this sequence and returns | - |
| 970 | a reference to this QTouchEventSequence. | - |
| 971 | | - |
| 972 | The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then | - |
| 973 | \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence. | - |
| 974 | | - |
| 975 | Simulates that the user pressed the touch screen or pad with the finger identified by \a touchId. | - |
| 976 | */ | - |
| 977 | | - |
| 978 | /*! | - |
| 979 | \fn QTouchEventSequence &QTest::QTouchEventSequence::move(int touchId, const QPoint &pt, QWindow *window) | - |
| 980 | \since 5.0 | - |
| 981 | | - |
| 982 | Adds a move event for touchpoint \a touchId at position \a pt to this sequence and returns | - |
| 983 | a reference to this QTouchEventSequence. | - |
| 984 | | - |
| 985 | The position \a pt is interpreted as relative to \a window. If \a window is the null pointer, then | - |
| 986 | \a pt is interpreted as relative to the window provided when instantiating this QTouchEventSequence. | - |
| 987 | | - |
| 988 | Simulates that the user moved the finger identified by \a touchId. | - |
| 989 | */ | - |
| 990 | | - |
| 991 | /*! | - |
| 992 | \fn QTouchEventSequence &QTest::QTouchEventSequence::move(int touchId, const QPoint &pt, QWidget *widget) | - |
| 993 | | - |
| 994 | Adds a move event for touchpoint \a touchId at position \a pt to this sequence and returns | - |
| 995 | a reference to this QTouchEventSequence. | - |
| 996 | | - |
| 997 | The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then | - |
| 998 | \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence. | - |
| 999 | | - |
| 1000 | Simulates that the user moved the finger identified by \a touchId. | - |
| 1001 | */ | - |
| 1002 | | - |
| 1003 | /*! | - |
| 1004 | \fn QTouchEventSequence &QTest::QTouchEventSequence::release(int touchId, const QPoint &pt, QWindow *window) | - |
| 1005 | \since 5.0 | - |
| 1006 | | - |
| 1007 | Adds a release event for touchpoint \a touchId at position \a pt to this sequence and returns | - |
| 1008 | a reference to this QTouchEventSequence. | - |
| 1009 | | - |
| 1010 | The position \a pt is interpreted as relative to \a window. If \a window is the null pointer, then | - |
| 1011 | \a pt is interpreted as relative to the window provided when instantiating this QTouchEventSequence. | - |
| 1012 | | - |
| 1013 | Simulates that the user lifted the finger identified by \a touchId. | - |
| 1014 | */ | - |
| 1015 | | - |
| 1016 | /*! | - |
| 1017 | \fn QTouchEventSequence &QTest::QTouchEventSequence::release(int touchId, const QPoint &pt, QWidget *widget) | - |
| 1018 | | - |
| 1019 | Adds a release event for touchpoint \a touchId at position \a pt to this sequence and returns | - |
| 1020 | a reference to this QTouchEventSequence. | - |
| 1021 | | - |
| 1022 | The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then | - |
| 1023 | \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence. | - |
| 1024 | | - |
| 1025 | Simulates that the user lifted the finger identified by \a touchId. | - |
| 1026 | */ | - |
| 1027 | | - |
| 1028 | /*! | - |
| 1029 | \fn QTouchEventSequence &QTest::QTouchEventSequence::stationary(int touchId) | - |
| 1030 | | - |
| 1031 | Adds a stationary event for touchpoint \a touchId to this sequence and returns | - |
| 1032 | a reference to this QTouchEventSequence. | - |
| 1033 | | - |
| 1034 | Simulates that the user did not move the finger identified by \a touchId. | - |
| 1035 | */ | - |
| 1036 | | - |
| 1037 | /*! | - |
| 1038 | \fn QTouchEventSequence QTest::touchEvent(QWindow *window, QTouchDevice *device, bool autoCommit = true) | - |
| 1039 | \since 5.0 | - |
| 1040 | | - |
| 1041 | Creates and returns a QTouchEventSequence for the \a device to | - |
| 1042 | simulate events for \a window. | - |
| 1043 | | - |
| 1044 | When adding touch events to the sequence, \a window will also be used to translate | - |
| 1045 | the position provided to screen coordinates, unless another window is provided in the | - |
| 1046 | respective calls to press(), move() etc. | - |
| 1047 | | - |
| 1048 | The touch events are committed to the event system when the destructor of the | - |
| 1049 | QTouchEventSequence is called (ie when the object returned runs out of scope), unless | - |
| 1050 | \a autoCommit is set to false. When \a autoCommit is false, commit() has to be called | - |
| 1051 | manually. | - |
| 1052 | */ | - |
| 1053 | | - |
| 1054 | /*! | - |
| 1055 | \fn QTouchEventSequence QTest::touchEvent(QWidget *widget, QTouchDevice *device, bool autoCommit = true) | - |
| 1056 | | - |
| 1057 | Creates and returns a QTouchEventSequence for the \a device to | - |
| 1058 | simulate events for \a widget. | - |
| 1059 | | - |
| 1060 | When adding touch events to the sequence, \a widget will also be used to translate | - |
| 1061 | the position provided to screen coordinates, unless another widget is provided in the | - |
| 1062 | respective calls to press(), move() etc. | - |
| 1063 | | - |
| 1064 | The touch events are committed to the event system when the destructor of the | - |
| 1065 | QTouchEventSequence is called (ie when the object returned runs out of scope), unless | - |
| 1066 | \a autoCommit is set to false. When \a autoCommit is false, commit() has to be called | - |
| 1067 | manually. | - |
| 1068 | */ | - |
| 1069 | | - |
| 1070 | static bool installCoverageTool(const char * appname, const char * testname) | - |
| 1071 | { | - |
| 1072 | #ifdef __COVERAGESCANNER__ | - |
| 1073 | if (!qEnvironmentVariableIsEmpty("QT_TESTCOCOON_ACTIVE")) | - |
| 1074 | return false; | - |
| 1075 | // Set environment variable QT_TESTCOCOON_ACTIVE to prevent an eventual subtest from | - |
| 1076 | // being considered as a stand-alone test regarding the coverage analysis. | - |
| 1077 | qputenv("QT_TESTCOCOON_ACTIVE", "1"); | - |
| 1078 | | - |
| 1079 | // Install Coverage Tool | - |
| 1080 | __coveragescanner_install(appname); | - |
| 1081 | __coveragescanner_testname(testname); | - |
| 1082 | __coveragescanner_clear(); | - |
| 1083 | return true; | - |
| 1084 | #else | - |
| 1085 | Q_UNUSED(appname); | - |
| 1086 | Q_UNUSED(testname); | - |
| 1087 | return false; | - |
| 1088 | #endif | - |
| 1089 | } | - |
| 1090 | | - |
| 1091 | namespace QTest | - |
| 1092 | { | - |
| 1093 | static QObject *currentTestObject = 0; | - |
| 1094 | | - |
| 1095 | class TestFunction { | - |
| 1096 | public: | - |
| 1097 | TestFunction() : function_(-1), data_(0) {} | - |
| 1098 | void set(int function, char *data) { function_ = function; data_ = data; } | - |
| 1099 | char *data() const { return data_; } | - |
| 1100 | int function() const { return function_; } | - |
| 1101 | ~TestFunction() { delete[] data_; } | - |
| 1102 | private: | - |
| 1103 | int function_; | - |
| 1104 | char *data_; | - |
| 1105 | }; | - |
| 1106 | /** | - |
| 1107 | * Contains the list of test functions that was supplied | - |
| 1108 | * on the command line, if any. Hence, if not empty, | - |
| 1109 | * those functions should be run instead of | - |
| 1110 | * all appearing in the test case. | - |
| 1111 | */ | - |
| 1112 | static TestFunction * testFuncs = 0; | - |
| 1113 | static int testFuncCount = 0; | - |
| 1114 | | - |
| 1115 | /** Don't leak testFuncs on exit even on error */ | - |
| 1116 | static struct TestFuncCleanup | - |
| 1117 | { | - |
| 1118 | void cleanup() | - |
| 1119 | { | - |
| 1120 | delete[] testFuncs; | - |
| 1121 | testFuncCount = 0; | - |
| 1122 | testFuncs = 0; | - |
| 1123 | } | - |
| 1124 | | - |
| 1125 | ~TestFuncCleanup() { cleanup(); } | - |
| 1126 | } testFuncCleaner; | - |
| 1127 | | - |
| 1128 | static int keyDelay = -1; | - |
| 1129 | static int mouseDelay = -1; | - |
| 1130 | static int eventDelay = -1; | - |
| 1131 | #if defined(Q_OS_UNIX) | - |
| 1132 | static bool noCrashHandler = false; | - |
| 1133 | #endif | - |
| 1134 | | - |
| 1135 | /*! \internal | - |
| 1136 | Invoke a method of the object without generating warning if the method does not exist | - |
| 1137 | */ | - |
| 1138 | static void invokeMethod(QObject *obj, const char *methodName) | - |
| 1139 | { | - |
| 1140 | const QMetaObject *metaObject = obj->metaObject(); | - |
| 1141 | int funcIndex = metaObject->indexOfMethod(methodName); | - |
| 1142 | if (funcIndex >= 0) { | - |
| 1143 | QMetaMethod method = metaObject->method(funcIndex); | - |
| 1144 | method.invoke(obj, Qt::DirectConnection); | - |
| 1145 | } | - |
| 1146 | } | - |
| 1147 | | - |
| 1148 | int defaultEventDelay() | - |
| 1149 | { | - |
| 1150 | if (eventDelay == -1) { | - |
| 1151 | const QByteArray env = qgetenv("QTEST_EVENT_DELAY"); | - |
| 1152 | if (!env.isEmpty()) | - |
| 1153 | eventDelay = atoi(env.constData()); | - |
| 1154 | else | - |
| 1155 | eventDelay = 0; | - |
| 1156 | } | - |
| 1157 | return eventDelay; | - |
| 1158 | } | - |
| 1159 | | - |
| 1160 | int Q_TESTLIB_EXPORT defaultMouseDelay() | - |
| 1161 | { | - |
| 1162 | if (mouseDelay == -1) { | - |
| 1163 | const QByteArray env = qgetenv("QTEST_MOUSEEVENT_DELAY"); | - |
| 1164 | if (!env.isEmpty()) | - |
| 1165 | mouseDelay = atoi(env.constData()); | - |
| 1166 | else | - |
| 1167 | mouseDelay = defaultEventDelay(); | - |
| 1168 | } | - |
| 1169 | return mouseDelay; | - |
| 1170 | } | - |
| 1171 | | - |
| 1172 | int Q_TESTLIB_EXPORT defaultKeyDelay() | - |
| 1173 | { | - |
| 1174 | if (keyDelay == -1) { | - |
| 1175 | const QByteArray env = qgetenv("QTEST_KEYEVENT_DELAY"); | - |
| 1176 | if (!env.isEmpty()) | - |
| 1177 | keyDelay = atoi(env.constData()); | - |
| 1178 | else | - |
| 1179 | keyDelay = defaultEventDelay(); | - |
| 1180 | } | - |
| 1181 | return keyDelay; | - |
| 1182 | } | - |
| 1183 | | - |
| 1184 | static bool isValidSlot(const QMetaMethod &sl) | - |
| 1185 | { | - |
| 1186 | if (sl.access() != QMetaMethod::Private || sl.parameterCount() != 0 | - |
| 1187 | || sl.returnType() != QMetaType::Void || sl.methodType() != QMetaMethod::Slot) | - |
| 1188 | return false; | - |
| 1189 | QByteArray name = sl.name(); | - |
| 1190 | if (name.isEmpty()) | - |
| 1191 | return false; | - |
| 1192 | if (name.endsWith("_data")) | - |
| 1193 | return false; | - |
| 1194 | if (name == "initTestCase" || name == "cleanupTestCase" | - |
| 1195 | || name == "cleanup" || name == "init") | - |
| 1196 | return false; | - |
| 1197 | return true; | - |
| 1198 | } | - |
| 1199 | | - |
| 1200 | Q_TESTLIB_EXPORT bool printAvailableFunctions = false; | - |
| 1201 | Q_TESTLIB_EXPORT QStringList testFunctions; | - |
| 1202 | Q_TESTLIB_EXPORT QStringList testTags; | - |
| 1203 | | - |
| 1204 | static void qPrintTestSlots(FILE *stream, const char *filter = 0) | - |
| 1205 | { | - |
| 1206 | for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { | - |
| 1207 | QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); | - |
| 1208 | if (isValidSlot(sl)) { | - |
| 1209 | const QByteArray signature = sl.methodSignature(); | - |
| 1210 | if (!filter || QString::fromLatin1(signature).contains(QLatin1String(filter), Qt::CaseInsensitive)) | - |
| 1211 | fprintf(stream, "%s\n", signature.constData()); | - |
| 1212 | } | - |
| 1213 | } | - |
| 1214 | } | - |
| 1215 | | - |
| 1216 | static void qPrintDataTags(FILE *stream) | - |
| 1217 | { | - |
| 1218 | // Avoid invoking the actual test functions, and also avoid printing irrelevant output: | - |
| 1219 | QTestLog::setPrintAvailableTagsMode(); | - |
| 1220 | | - |
| 1221 | // Get global data tags: | - |
| 1222 | QTestTable::globalTestTable(); | - |
| 1223 | invokeMethod(QTest::currentTestObject, "initTestCase_data()"); | - |
| 1224 | const QTestTable *gTable = QTestTable::globalTestTable(); | - |
| 1225 | | - |
| 1226 | const QMetaObject *currTestMetaObj = QTest::currentTestObject->metaObject(); | - |
| 1227 | | - |
| 1228 | // Process test functions: | - |
| 1229 | for (int i = 0; i < currTestMetaObj->methodCount(); ++i) { | - |
| 1230 | QMetaMethod tf = currTestMetaObj->method(i); | - |
| 1231 | | - |
| 1232 | if (isValidSlot(tf)) { | - |
| 1233 | | - |
| 1234 | // Retrieve local tags: | - |
| 1235 | QStringList localTags; | - |
| 1236 | QTestTable table; | - |
| 1237 | char *slot = qstrdup(tf.methodSignature().constData()); | - |
| 1238 | slot[strlen(slot) - 2] = '\0'; | - |
| 1239 | QByteArray member; | - |
| 1240 | member.resize(qstrlen(slot) + qstrlen("_data()") + 1); | - |
| 1241 | qsnprintf(member.data(), member.size(), "%s_data()", slot); | - |
| 1242 | invokeMethod(QTest::currentTestObject, member.constData()); | - |
| 1243 | for (int j = 0; j < table.dataCount(); ++j) | - |
| 1244 | localTags << QLatin1String(table.testData(j)->dataTag()); | - |
| 1245 | | - |
| 1246 | // Print all tag combinations: | - |
| 1247 | if (gTable->dataCount() == 0) { | - |
| 1248 | if (localTags.count() == 0) { | - |
| 1249 | // No tags at all, so just print the test function: | - |
| 1250 | fprintf(stream, "%s %s\n", currTestMetaObj->className(), slot); | - |
| 1251 | } else { | - |
| 1252 | // Only local tags, so print each of them: | - |
| 1253 | for (int k = 0; k < localTags.size(); ++k) | - |
| 1254 | fprintf( | - |
| 1255 | stream, "%s %s %s\n", | - |
| 1256 | currTestMetaObj->className(), slot, localTags.at(k).toLatin1().data()); | - |
| 1257 | } | - |
| 1258 | } else { | - |
| 1259 | for (int j = 0; j < gTable->dataCount(); ++j) { | - |
| 1260 | if (localTags.count() == 0) { | - |
| 1261 | // Only global tags, so print the current one: | - |
| 1262 | fprintf( | - |
| 1263 | stream, "%s %s __global__ %s\n", | - |
| 1264 | currTestMetaObj->className(), slot, gTable->testData(j)->dataTag()); | - |
| 1265 | } else { | - |
| 1266 | // Local and global tags, so print each of the local ones and | - |
| 1267 | // the current global one: | - |
| 1268 | for (int k = 0; k < localTags.size(); ++k) | - |
| 1269 | fprintf( | - |
| 1270 | stream, "%s %s %s __global__ %s\n", currTestMetaObj->className(), slot, | - |
| 1271 | localTags.at(k).toLatin1().data(), gTable->testData(j)->dataTag()); | - |
| 1272 | } | - |
| 1273 | } | - |
| 1274 | } | - |
| 1275 | | - |
| 1276 | delete[] slot; | - |
| 1277 | } | - |
| 1278 | } | - |
| 1279 | } | - |
| 1280 | | - |
| 1281 | static int qToInt(char *str) | - |
| 1282 | { | - |
| 1283 | char *pEnd; | - |
| 1284 | int l = (int)strtol(str, &pEnd, 10); | - |
| 1285 | if (*pEnd != 0) { | - |
| 1286 | fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); | - |
| 1287 | exit(1); | - |
| 1288 | } | - |
| 1289 | return l; | - |
| 1290 | } | - |
| 1291 | | - |
| 1292 | Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) | - |
| 1293 | { | - |
| 1294 | QTestLog::LogMode logFormat = QTestLog::Plain; | - |
| 1295 | const char *logFilename = 0; | - |
| 1296 | | - |
| 1297 | const char *testOptions = | - |
| 1298 | " New-style logging options:\n" | - |
| 1299 | " -o filename,format : Output results to file in the specified format\n" | - |
| 1300 | " Use - to output to stdout\n" | - |
| 1301 | " Valid formats are:\n" | - |
| 1302 | " txt : Plain text\n" | - |
| 1303 | " xunitxml : XML XUnit document\n" | - |
| 1304 | " xml : XML document\n" | - |
| 1305 | " lightxml : A stream of XML tags\n" | - |
| 1306 | "\n" | - |
| 1307 | " *** Multiple loggers can be specified, but at most one can log to stdout.\n" | - |
| 1308 | "\n" | - |
| 1309 | " Old-style logging options:\n" | - |
| 1310 | " -o filename : Write the output into file\n" | - |
| 1311 | " -txt : Output results in Plain Text\n" | - |
| 1312 | " -xunitxml : Output results as XML XUnit document\n" | - |
| 1313 | " -xml : Output results as XML document\n" | - |
| 1314 | " -lightxml : Output results as stream of XML tags\n" | - |
| 1315 | "\n" | - |
| 1316 | " *** If no output file is specified, stdout is assumed.\n" | - |
| 1317 | " *** If no output format is specified, -txt is assumed.\n" | - |
| 1318 | "\n" | - |
| 1319 | " Test log detail options:\n" | - |
| 1320 | " -silent : Log failures and fatal errors only\n" | - |
| 1321 | " -v1 : Log the start of each testfunction\n" | - |
| 1322 | " -v2 : Log each QVERIFY/QCOMPARE/QTEST (implies -v1)\n" | - |
| 1323 | " -vs : Log every signal emission and resulting slot invocations\n" | - |
| 1324 | "\n" | - |
| 1325 | " *** The -silent and -v1 options only affect plain text output.\n" | - |
| 1326 | "\n" | - |
| 1327 | " Testing options:\n" | - |
| 1328 | " -functions : Returns a list of current testfunctions\n" | - |
| 1329 | " -datatags : Returns a list of current data tags.\n" | - |
| 1330 | " A global data tag is preceded by ' __global__ '.\n" | - |
| 1331 | " -eventdelay ms : Set default delay for mouse and keyboard simulation to ms milliseconds\n" | - |
| 1332 | " -keydelay ms : Set default delay for keyboard simulation to ms milliseconds\n" | - |
| 1333 | " -mousedelay ms : Set default delay for mouse simulation to ms milliseconds\n" | - |
| 1334 | " -maxwarnings n : Sets the maximum amount of messages to output.\n" | - |
| 1335 | " 0 means unlimited, default: 2000\n" | - |
| 1336 | #if defined(Q_OS_UNIX) | - |
| 1337 | " -nocrashhandler : Disables the crash handler\n" | - |
| 1338 | #endif | - |
| 1339 | "\n" | - |
| 1340 | " Benchmarking options:\n" | - |
| 1341 | #ifdef QTESTLIB_USE_VALGRIND | - |
| 1342 | " -callgrind : Use callgrind to time benchmarks\n" | - |
| 1343 | #endif | - |
| 1344 | #ifdef HAVE_TICK_COUNTER | - |
| 1345 | " -tickcounter : Use CPU tick counters to time benchmarks\n" | - |
| 1346 | #endif | - |
| 1347 | " -eventcounter : Counts events received during benchmarks\n" | - |
| 1348 | " -minimumvalue n : Sets the minimum acceptable measurement value\n" | - |
| 1349 | " -iterations n : Sets the number of accumulation iterations.\n" | - |
| 1350 | " -median n : Sets the number of median iterations.\n" | - |
| 1351 | " -vb : Print out verbose benchmarking information.\n"; | - |
| 1352 | | - |
| 1353 | for (int i = 1; i < argc; ++i) { | - |
| 1354 | if (strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "--help") == 0 | - |
| 1355 | || strcmp(argv[i], "/?") == 0) { | - |
| 1356 | printf(" Usage: %s [options] [testfunction[:testdata]]...\n" | - |
| 1357 | " By default, all testfunctions will be run.\n\n" | - |
| 1358 | "%s", argv[0], testOptions); | - |
| 1359 | | - |
| 1360 | if (qml) { | - |
| 1361 | printf ("\n" | - |
| 1362 | " QmlTest options:\n" | - |
| 1363 | " -import dir : Specify an import directory.\n" | - |
| 1364 | " -input dir/file : Specify the root directory for test cases or a single test case file.\n" | - |
| 1365 | " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" | - |
| 1366 | " -translation file : Specify the translation file.\n" | - |
| 1367 | ); | - |
| 1368 | } | - |
| 1369 | | - |
| 1370 | printf("\n" | - |
| 1371 | " -help : This help\n"); | - |
| 1372 | exit(0); | - |
| 1373 | } else if (strcmp(argv[i], "-functions") == 0) { | - |
| 1374 | if (qml) { | - |
| 1375 | QTest::printAvailableFunctions = true; | - |
| 1376 | } else { | - |
| 1377 | qPrintTestSlots(stdout); | - |
| 1378 | exit(0); | - |
| 1379 | } | - |
| 1380 | } else if (strcmp(argv[i], "-datatags") == 0) { | - |
| 1381 | if (!qml) { | - |
| 1382 | qPrintDataTags(stdout); | - |
| 1383 | exit(0); | - |
| 1384 | } | - |
| 1385 | } else if (strcmp(argv[i], "-txt") == 0) { | - |
| 1386 | logFormat = QTestLog::Plain; | - |
| 1387 | } else if (strcmp(argv[i], "-xunitxml") == 0) { | - |
| 1388 | logFormat = QTestLog::XunitXML; | - |
| 1389 | } else if (strcmp(argv[i], "-xml") == 0) { | - |
| 1390 | logFormat = QTestLog::XML; | - |
| 1391 | } else if (strcmp(argv[i], "-lightxml") == 0) { | - |
| 1392 | logFormat = QTestLog::LightXML; | - |
| 1393 | } else if (strcmp(argv[i], "-silent") == 0) { | - |
| 1394 | QTestLog::setVerboseLevel(-1); | - |
| 1395 | } else if (strcmp(argv[i], "-v1") == 0) { | - |
| 1396 | QTestLog::setVerboseLevel(1); | - |
| 1397 | } else if (strcmp(argv[i], "-v2") == 0) { | - |
| 1398 | QTestLog::setVerboseLevel(2); | - |
| 1399 | } else if (strcmp(argv[i], "-vs") == 0) { | - |
| 1400 | QSignalDumper::startDump(); | - |
| 1401 | } else if (strcmp(argv[i], "-o") == 0) { | - |
| 1402 | if (i + 1 >= argc) { | - |
| 1403 | fprintf(stderr, "-o needs an extra parameter specifying the filename and optional format\n"); | - |
| 1404 | exit(1); | - |
| 1405 | } | - |
| 1406 | ++i; | - |
| 1407 | // Do we have the old or new style -o option? | - |
| 1408 | char *filename = new char[strlen(argv[i])+1]; | - |
| 1409 | char *format = new char[strlen(argv[i])+1]; | - |
| 1410 | if (sscanf(argv[i], "%[^,],%s", filename, format) == 1) { | - |
| 1411 | // Old-style | - |
| 1412 | logFilename = argv[i]; | - |
| 1413 | } else { | - |
| 1414 | // New-style | - |
| 1415 | if (strcmp(format, "txt") == 0) | - |
| 1416 | logFormat = QTestLog::Plain; | - |
| 1417 | else if (strcmp(format, "lightxml") == 0) | - |
| 1418 | logFormat = QTestLog::LightXML; | - |
| 1419 | else if (strcmp(format, "xml") == 0) | - |
| 1420 | logFormat = QTestLog::XML; | - |
| 1421 | else if (strcmp(format, "xunitxml") == 0) | - |
| 1422 | logFormat = QTestLog::XunitXML; | - |
| 1423 | else { | - |
| 1424 | fprintf(stderr, "output format must be one of txt, lightxml, xml or xunitxml\n"); | - |
| 1425 | exit(1); | - |
| 1426 | } | - |
| 1427 | if (strcmp(filename, "-") == 0 && QTestLog::loggerUsingStdout()) { | - |
| 1428 | fprintf(stderr, "only one logger can log to stdout\n"); | - |
| 1429 | exit(1); | - |
| 1430 | } | - |
| 1431 | QTestLog::addLogger(logFormat, filename); | - |
| 1432 | } | - |
| 1433 | delete [] filename; | - |
| 1434 | delete [] format; | - |
| 1435 | } else if (strcmp(argv[i], "-eventdelay") == 0) { | - |
| 1436 | if (i + 1 >= argc) { | - |
| 1437 | fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); | - |
| 1438 | exit(1); | - |
| 1439 | } else { | - |
| 1440 | QTest::eventDelay = qToInt(argv[++i]); | - |
| 1441 | } | - |
| 1442 | } else if (strcmp(argv[i], "-keydelay") == 0) { | - |
| 1443 | if (i + 1 >= argc) { | - |
| 1444 | fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); | - |
| 1445 | exit(1); | - |
| 1446 | } else { | - |
| 1447 | QTest::keyDelay = qToInt(argv[++i]); | - |
| 1448 | } | - |
| 1449 | } else if (strcmp(argv[i], "-mousedelay") == 0) { | - |
| 1450 | if (i + 1 >= argc) { | - |
| 1451 | fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); | - |
| 1452 | exit(1); | - |
| 1453 | } else { | - |
| 1454 | QTest::mouseDelay = qToInt(argv[++i]); | - |
| 1455 | } | - |
| 1456 | } else if (strcmp(argv[i], "-maxwarnings") == 0) { | - |
| 1457 | if (i + 1 >= argc) { | - |
| 1458 | fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); | - |
| 1459 | exit(1); | - |
| 1460 | } else { | - |
| 1461 | QTestLog::setMaxWarnings(qToInt(argv[++i])); | - |
| 1462 | } | - |
| 1463 | #if defined(Q_OS_UNIX) | - |
| 1464 | } else if (strcmp(argv[i], "-nocrashhandler") == 0) { | - |
| 1465 | QTest::noCrashHandler = true; | - |
| 1466 | #endif | - |
| 1467 | #ifdef QTESTLIB_USE_VALGRIND | - |
| 1468 | } else if (strcmp(argv[i], "-callgrind") == 0) { | - |
| 1469 | if (QBenchmarkValgrindUtils::haveValgrind()) | - |
| 1470 | if (QFileInfo(QDir::currentPath()).isWritable()) { | - |
| 1471 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); | - |
| 1472 | } else { | - |
| 1473 | fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); | - |
| 1474 | } | - |
| 1475 | else { | - |
| 1476 | fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " | - |
| 1477 | "Using the walltime measurer.\n"); | - |
| 1478 | } | - |
| 1479 | } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option | - |
| 1480 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindChildProcess); | - |
| 1481 | QBenchmarkGlobalData::current->callgrindOutFileBase = | - |
| 1482 | QBenchmarkValgrindUtils::outFileBase(); | - |
| 1483 | #endif | - |
| 1484 | #ifdef HAVE_TICK_COUNTER | - |
| 1485 | } else if (strcmp(argv[i], "-tickcounter") == 0) { | - |
| 1486 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::TickCounter); | - |
| 1487 | #endif | - |
| 1488 | } else if (strcmp(argv[i], "-eventcounter") == 0) { | - |
| 1489 | QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::EventCounter); | - |
| 1490 | } else if (strcmp(argv[i], "-minimumvalue") == 0) { | - |
| 1491 | if (i + 1 >= argc) { | - |
| 1492 | fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); | - |
| 1493 | exit(1); | - |
| 1494 | } else { | - |
| 1495 | QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); | - |
| 1496 | } | - |
| 1497 | } else if (strcmp(argv[i], "-iterations") == 0) { | - |
| 1498 | if (i + 1 >= argc) { | - |
| 1499 | fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); | - |
| 1500 | exit(1); | - |
| 1501 | } else { | - |
| 1502 | QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); | - |
| 1503 | } | - |
| 1504 | } else if (strcmp(argv[i], "-median") == 0) { | - |
| 1505 | if (i + 1 >= argc) { | - |
| 1506 | fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); | - |
| 1507 | exit(1); | - |
| 1508 | } else { | - |
| 1509 | QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); | - |
| 1510 | } | - |
| 1511 | | - |
| 1512 | } else if (strcmp(argv[i], "-vb") == 0) { | - |
| 1513 | QBenchmarkGlobalData::current->verboseOutput = true; | - |
| 1514 | } else if (argv[i][0] == '-') { | - |
| 1515 | fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); | - |
| 1516 | if (qml) { | - |
| 1517 | fprintf(stderr, "\nqmltest related options:\n" | - |
| 1518 | " -import : Specify an import directory.\n" | - |
| 1519 | " -input : Specify the root directory for test cases.\n" | - |
| 1520 | " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" | - |
| 1521 | ); | - |
| 1522 | } | - |
| 1523 | | - |
| 1524 | fprintf(stderr, "\n" | - |
| 1525 | " -help : This help\n"); | - |
| 1526 | exit(1); | - |
| 1527 | } else if (qml) { | - |
| 1528 | // We can't check the availability of test functions until | - |
| 1529 | // we load the QML files. So just store the data for now. | - |
| 1530 | int colon = -1; | - |
| 1531 | int offset; | - |
| 1532 | for (offset = 0; *(argv[i]+offset); ++offset) { | - |
| 1533 | if (*(argv[i]+offset) == ':') { | - |
| 1534 | if (*(argv[i]+offset+1) == ':') { | - |
| 1535 | // "::" is used as a test name separator. | - |
| 1536 | // e.g. "ClickTests::test_click:row1". | - |
| 1537 | ++offset; | - |
| 1538 | } else { | - |
| 1539 | colon = offset; | - |
| 1540 | break; | - |
| 1541 | } | - |
| 1542 | } | - |
| 1543 | } | - |
| 1544 | if (colon == -1) { | - |
| 1545 | QTest::testFunctions += QString::fromLatin1(argv[i]); | - |
| 1546 | QTest::testTags += QString(); | - |
| 1547 | } else { | - |
| 1548 | QTest::testFunctions += | - |
| 1549 | QString::fromLatin1(argv[i], colon); | - |
| 1550 | QTest::testTags += | - |
| 1551 | QString::fromLatin1(argv[i] + colon + 1); | - |
| 1552 | } | - |
| 1553 | } else { | - |
| 1554 | if (!QTest::testFuncs) { | - |
| 1555 | QTest::testFuncs = new QTest::TestFunction[512]; | - |
| 1556 | } | - |
| 1557 | | - |
| 1558 | int colon = -1; | - |
| 1559 | char buf[512], *data=0; | - |
| 1560 | int off; | - |
| 1561 | for (off = 0; *(argv[i]+off); ++off) { | - |
| 1562 | if (*(argv[i]+off) == ':') { | - |
| 1563 | colon = off; | - |
| 1564 | break; | - |
| 1565 | } | - |
| 1566 | } | - |
| 1567 | if (colon != -1) { | - |
| 1568 | data = qstrdup(argv[i]+colon+1); | - |
| 1569 | } | - |
| 1570 | qsnprintf(buf, qMin(512, off + 1), "%s", argv[i]); // copy text before the ':' into buf | - |
| 1571 | qsnprintf(buf + off, qMin(512 - off, 3), "()"); // append "()" | - |
| 1572 | int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); | - |
| 1573 | if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) { | - |
| 1574 | fprintf(stderr, "Unknown test function: '%s'. Possible matches:\n", buf); | - |
| 1575 | buf[off] = 0; | - |
| 1576 | qPrintTestSlots(stderr, buf); | - |
| 1577 | fprintf(stderr, "\n%s -functions\nlists all available test functions.\n", argv[0]); | - |
| 1578 | exit(1); | - |
| 1579 | } | - |
| 1580 | testFuncs[testFuncCount].set(idx, data); | - |
| 1581 | testFuncCount++; | - |
| 1582 | QTEST_ASSERT(QTest::testFuncCount < 512); | - |
| 1583 | } | - |
| 1584 | } | - |
| 1585 | | - |
| 1586 | bool installedTestCoverage = installCoverageTool(QTestResult::currentAppname(), QTestResult::currentTestObjectName()); | - |
| 1587 | QTestLog::setInstalledTestCoverage(installedTestCoverage); | - |
| 1588 | | - |
| 1589 | // If no loggers were created by the long version of the -o command-line | - |
| 1590 | // option, create a logger using whatever filename and format were | - |
| 1591 | // set using the old-style command-line options. | - |
| 1592 | if (QTestLog::loggerCount() == 0) | - |
| 1593 | QTestLog::addLogger(logFormat, logFilename); | - |
| 1594 | } | - |
| 1595 | | - |
| 1596 | QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container) | - |
| 1597 | { | - |
| 1598 | const int count = container.count(); | - |
| 1599 | if (count == 0) | - |
| 1600 | return QBenchmarkResult(); | - |
| 1601 | | - |
| 1602 | if (count == 1) | - |
| 1603 | return container.at(0); | - |
| 1604 | | - |
| 1605 | QList<QBenchmarkResult> containerCopy = container; | - |
| 1606 | qSort(containerCopy); | - |
| 1607 | | - |
| 1608 | const int middle = count / 2; | - |
| 1609 | | - |
| 1610 | // ### handle even-sized containers here by doing an aritmetic mean of the two middle items. | - |
| 1611 | return containerCopy.at(middle); | - |
| 1612 | } | - |
| 1613 | | - |
| 1614 | struct QTestDataSetter | - |
| 1615 | { | - |
| 1616 | QTestDataSetter(QTestData *data) | - |
| 1617 | { | - |
| 1618 | QTestResult::setCurrentTestData(data); | - |
| 1619 | } | - |
| 1620 | ~QTestDataSetter() | - |
| 1621 | { | - |
| 1622 | QTestResult::setCurrentTestData(0); | - |
| 1623 | } | - |
| 1624 | }; | - |
| 1625 | | - |
| 1626 | static void qInvokeTestMethodDataEntry(char *slot) | - |
| 1627 | { | - |
| 1628 | /* Benchmarking: for each median iteration*/ | - |
| 1629 | | - |
| 1630 | bool isBenchmark = false; | - |
| 1631 | int i = (QBenchmarkGlobalData::current->measurer->needsWarmupIteration()) ? -1 : 0; | - |
| 1632 | | - |
| 1633 | QList<QBenchmarkResult> results; | - |
| 1634 | do { | - |
| 1635 | QBenchmarkTestMethodData::current->beginDataRun(); | - |
| 1636 | | - |
| 1637 | /* Benchmarking: for each accumulation iteration*/ | - |
| 1638 | bool invokeOk; | - |
| 1639 | do { | - |
| 1640 | invokeMethod(QTest::currentTestObject, "init()"); | - |
| 1641 | if (QTestResult::skipCurrentTest() || QTestResult::currentTestFailed()) | - |
| 1642 | break; | - |
| 1643 | | - |
| 1644 | QBenchmarkTestMethodData::current->result = QBenchmarkResult(); | - |
| 1645 | QBenchmarkTestMethodData::current->resultAccepted = false; | - |
| 1646 | | - |
| 1647 | QBenchmarkGlobalData::current->context.tag = | - |
| 1648 | QLatin1String( | - |
| 1649 | QTestResult::currentDataTag() | - |
| 1650 | ? QTestResult::currentDataTag() : ""); | - |
| 1651 | | - |
| 1652 | invokeOk = QMetaObject::invokeMethod(QTest::currentTestObject, slot, | - |
| 1653 | Qt::DirectConnection); | - |
| 1654 | if (!invokeOk) | - |
| 1655 | QTestResult::addFailure("Unable to execute slot", __FILE__, __LINE__); | - |
| 1656 | | - |
| 1657 | isBenchmark = QBenchmarkTestMethodData::current->isBenchmark(); | - |
| 1658 | | - |
| 1659 | QTestResult::finishedCurrentTestData(); | - |
| 1660 | | - |
| 1661 | invokeMethod(QTest::currentTestObject, "cleanup()"); | - |
| 1662 | | - |
| 1663 | // If the test isn't a benchmark, finalize the result after cleanup() has finished. | - |
| 1664 | if (!isBenchmark) | - |
| 1665 | QTestResult::finishedCurrentTestDataCleanup(); | - |
| 1666 | | - |
| 1667 | // If this test method has a benchmark, repeat until all measurements are | - |
| 1668 | // acceptable. | - |
| 1669 | // The QBENCHMARK macro increases the number of iterations for each run until | - |
| 1670 | // this happens. | - |
| 1671 | } while (invokeOk && isBenchmark | - |
| 1672 | && QBenchmarkTestMethodData::current->resultsAccepted() == false | - |
| 1673 | && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed()); | - |
| 1674 | | - |
| 1675 | QBenchmarkTestMethodData::current->endDataRun(); | - |
| 1676 | if (!QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed()) { | - |
| 1677 | if (i > -1) // iteration -1 is the warmup iteration. | - |
| 1678 | results.append(QBenchmarkTestMethodData::current->result); | - |
| 1679 | | - |
| 1680 | if (isBenchmark && QBenchmarkGlobalData::current->verboseOutput) { | - |
| 1681 | if (i == -1) { | - |
| 1682 | QTestLog::info(qPrintable( | - |
| 1683 | QString::fromLatin1("warmup stage result : %1") | - |
| 1684 | .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0); | - |
| 1685 | } else { | - |
| 1686 | QTestLog::info(qPrintable( | - |
| 1687 | QString::fromLatin1("accumulation stage result: %1") | - |
| 1688 | .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0); | - |
| 1689 | } | - |
| 1690 | } | - |
| 1691 | } | - |
| 1692 | } while (isBenchmark | - |
| 1693 | && (++i < QBenchmarkGlobalData::current->adjustMedianIterationCount()) | - |
| 1694 | && !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed()); | - |
| 1695 | | - |
| 1696 | // If the test is a benchmark, finalize the result after all iterations have finished. | - |
| 1697 | if (isBenchmark) { | - |
| 1698 | bool testPassed = !QTestResult::skipCurrentTest() && !QTestResult::currentTestFailed(); | - |
| 1699 | QTestResult::finishedCurrentTestDataCleanup(); | - |
| 1700 | // Only report benchmark figures if the test passed | - |
| 1701 | if (testPassed && QBenchmarkTestMethodData::current->resultsAccepted()) | - |
| 1702 | QTestLog::addBenchmarkResult(qMedian(results)); | - |
| 1703 | } | - |
| 1704 | } | - |
| 1705 | | - |
| 1706 | /*! | - |
| 1707 | \internal | - |
| 1708 | | - |
| 1709 | Call slot_data(), init(), slot(), cleanup(), init(), slot(), cleanup(), ... | - |
| 1710 | If data is set then it is the only test that is performed | - |
| 1711 | | - |
| 1712 | If the function was successfully called, true is returned, otherwise | - |
| 1713 | false. | - |
| 1714 | */ | - |
| 1715 | static bool qInvokeTestMethod(const char *slotName, const char *data=0) | - |
| 1716 | { | - |
| 1717 | QTEST_ASSERT(slotName); | - |
| 1718 | | - |
| 1719 | QBenchmarkTestMethodData benchmarkData; | - |
| 1720 | QBenchmarkTestMethodData::current = &benchmarkData; | - |
| 1721 | | - |
| 1722 | QBenchmarkGlobalData::current->context.slotName = QLatin1String(slotName); | - |
| 1723 | | - |
| 1724 | char member[512]; | - |
| 1725 | QTestTable table; | - |
| 1726 | | - |
| 1727 | char *slot = qstrdup(slotName); | - |
| 1728 | slot[strlen(slot) - 2] = '\0'; | - |
| 1729 | QTestResult::setCurrentTestFunction(slot); | - |
| 1730 | | - |
| 1731 | const QTestTable *gTable = QTestTable::globalTestTable(); | - |
| 1732 | const int globalDataCount = gTable->dataCount(); | - |
| 1733 | int curGlobalDataIndex = 0; | - |
| 1734 | | - |
| 1735 | /* For each test function that has a *_data() table/function, do: */ | - |
| 1736 | do { | - |
| 1737 | if (!gTable->isEmpty()) | - |
| 1738 | QTestResult::setCurrentGlobalTestData(gTable->testData(curGlobalDataIndex)); | - |
| 1739 | | - |
| 1740 | if (curGlobalDataIndex == 0) { | - |
| 1741 | qsnprintf(member, 512, "%s_data()", slot); | - |
| 1742 | invokeMethod(QTest::currentTestObject, member); | - |
| 1743 | } | - |
| 1744 | | - |
| 1745 | bool foundFunction = false; | - |
| 1746 | if (!QTestResult::skipCurrentTest()) { | - |
| 1747 | int curDataIndex = 0; | - |
| 1748 | const int dataCount = table.dataCount(); | - |
| 1749 | | - |
| 1750 | // Data tag requested but none available? | - |
| 1751 | if (data && !dataCount) { | - |
| 1752 | // Let empty data tag through. | - |
| 1753 | if (!*data) | - |
| 1754 | data = 0; | - |
| 1755 | else { | - |
| 1756 | fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); | - |
| 1757 | fprintf(stderr, "Function has no testdata.\n"); | - |
| 1758 | return false; | - |
| 1759 | } | - |
| 1760 | } | - |
| 1761 | | - |
| 1762 | /* For each entry in the data table, do: */ | - |
| 1763 | do { | - |
| 1764 | QTestResult::setSkipCurrentTest(false); | - |
| 1765 | if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) { | - |
| 1766 | foundFunction = true; | - |
| 1767 | QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0) | - |
| 1768 | : table.testData(curDataIndex)); | - |
| 1769 | | - |
| 1770 | qInvokeTestMethodDataEntry(slot); | - |
| 1771 | | - |
| 1772 | if (data) | - |
| 1773 | break; | - |
| 1774 | } | - |
| 1775 | ++curDataIndex; | - |
| 1776 | } while (curDataIndex < dataCount); | - |
| 1777 | } | - |
| 1778 | | - |
| 1779 | if (data && !foundFunction) { | - |
| 1780 | fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); | - |
| 1781 | fprintf(stderr, "Available testdata:\n"); | - |
| 1782 | for (int i = 0; i < table.dataCount(); ++i) | - |
| 1783 | fprintf(stderr, "%s\n", table.testData(i)->dataTag()); | - |
| 1784 | return false; | - |
| 1785 | } | - |
| 1786 | | - |
| 1787 | QTestResult::setCurrentGlobalTestData(0); | - |
| 1788 | ++curGlobalDataIndex; | - |
| 1789 | } while (curGlobalDataIndex < globalDataCount); | - |
| 1790 | | - |
| 1791 | QTestResult::finishedCurrentTestFunction(); | - |
| 1792 | QTestResult::setSkipCurrentTest(false); | - |
| 1793 | QTestResult::setCurrentTestData(0); | - |
| 1794 | delete[] slot; | - |
| 1795 | | - |
| 1796 | return true; | - |
| 1797 | } | - |
| 1798 | | - |
| 1799 | void *fetchData(QTestData *data, const char *tagName, int typeId) | - |
| 1800 | { | - |
| 1801 | QTEST_ASSERT(typeId); | - |
| 1802 | QTEST_ASSERT_X(data, "QTest::fetchData()", "Test data requested, but no testdata available."); | - |
| 1803 | QTEST_ASSERT(data->parent()); | - |
| 1804 | | - |
| 1805 | int idx = data->parent()->indexOf(tagName); | - |
| 1806 | | - |
| 1807 | if (idx == -1 || idx >= data->dataCount()) { | - |
| 1808 | qFatal("QFETCH: Requested testdata '%s' not available, check your _data function.", | - |
| 1809 | tagName); | - |
| 1810 | } | - |
| 1811 | | - |
| 1812 | if (typeId != data->parent()->elementTypeId(idx)) { | - |
| 1813 | qFatal("Requested type '%s' does not match available type '%s'.", | - |
| 1814 | QMetaType::typeName(typeId), | - |
| 1815 | QMetaType::typeName(data->parent()->elementTypeId(idx))); | - |
| 1816 | } | - |
| 1817 | | - |
| 1818 | return data->data(idx); | - |
| 1819 | } | - |
| 1820 | | - |
| 1821 | /*! | - |
| 1822 | \fn char* QTest::toHexRepresentation(const char *ba, int length) | - |
| 1823 | | - |
| 1824 | Returns a pointer to a string that is the string \a ba represented | - |
| 1825 | as a space-separated sequence of hex characters. If the input is | - |
| 1826 | considered too long, it is truncated. A trucation is indicated in | - |
| 1827 | the returned string as an ellipsis at the end. | - |
| 1828 | | - |
| 1829 | \a length is the length of the string \a ba. | - |
| 1830 | */ | - |
| 1831 | char *toHexRepresentation(const char *ba, int length) | - |
| 1832 | { | - |
| 1833 | if (length == 0) | - |
| 1834 | return qstrdup(""); | - |
| 1835 | | - |
| 1836 | /* We output at maximum about maxLen characters in order to avoid | - |
| | * running out of memory and flooding things when the byte array | |
| | * is large. | |
| | * | |
| | * maxLen can't be for example 200 because QTestLib is sprinkled with fixed | |
| | * size char arrays. | |
| | * */* We output at maximum about maxLen characters in order to avoid | |
| 1837 | * running out of memory and flooding things when the byte array | - |
| 1838 | * is large. | - |
| 1839 | * | - |
| 1840 | * maxLen can't be for example 200 because Qt Test is sprinkled with fixed | - |
| 1841 | * size char arrays. | - |
| 1842 | * */ | - |
| 1843 | const int maxLen = 50; | - |
| 1844 | const int len = qMin(maxLen, length); | - |
| 1845 | char *result = 0; | - |
| 1846 | | - |
| 1847 | if (length > maxLen) { | - |
| 1848 | const int size = len * 3 + 4; | - |
| 1849 | result = new char[size]; | - |
| 1850 | | - |
| 1851 | char *const forElipsis = result + size - 5; | - |
| 1852 | forElipsis[0] = ' '; | - |
| 1853 | forElipsis[1] = '.'; | - |
| 1854 | forElipsis[2] = '.'; | - |
| 1855 | forElipsis[3] = '.'; | - |
| 1856 | result[size - 1] = '\0'; | - |
| 1857 | } | - |
| 1858 | else { | - |
| 1859 | const int size = len * 3; | - |
| 1860 | result = new char[size]; | - |
| 1861 | result[size - 1] = '\0'; | - |
| 1862 | } | - |
| 1863 | | - |
| 1864 | const char toHex[] = "0123456789ABCDEF"; | - |
| 1865 | int i = 0; | - |
| 1866 | int o = 0; | - |
| 1867 | | - |
| 1868 | while (true) { | - |
| 1869 | const char at = ba[i]; | - |
| 1870 | | - |
| 1871 | result[o] = toHex[(at >> 4) & 0x0F]; | - |
| 1872 | ++o; | - |
| 1873 | result[o] = toHex[at & 0x0F]; | - |
| 1874 | | - |
| 1875 | ++i; | - |
| 1876 | ++o; | - |
| 1877 | if (i == len) | - |
| 1878 | break; | - |
| 1879 | else { | - |
| 1880 | result[o] = ' '; | - |
| 1881 | ++o; | - |
| 1882 | } | - |
| 1883 | } | - |
| 1884 | | - |
| 1885 | return result; | - |
| 1886 | } | - |
| 1887 | | - |
| 1888 | static void qInvokeTestMethods(QObject *testObject) | - |
| 1889 | { | - |
| 1890 | const QMetaObject *metaObject = testObject->metaObject(); | - |
| 1891 | QTEST_ASSERT(metaObject); | - |
| 1892 | QTestLog::startLogging(); | - |
| 1893 | QTestResult::setCurrentTestFunction("initTestCase"); | - |
| 1894 | QTestTable::globalTestTable(); | - |
| 1895 | invokeMethod(testObject, "initTestCase_data()"); | - |
| 1896 | | - |
| 1897 | if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) { | - |
| 1898 | invokeMethod(testObject, "initTestCase()"); | - |
| 1899 | | - |
| 1900 | // finishedCurrentTestDataCleanup() resets QTestResult::currentTestFailed(), so use a local copy. | - |
| 1901 | const bool previousFailed = QTestResult::currentTestFailed(); | - |
| 1902 | QTestResult::finishedCurrentTestData(); | - |
| 1903 | QTestResult::finishedCurrentTestDataCleanup(); | - |
| 1904 | QTestResult::finishedCurrentTestFunction(); | - |
| 1905 | | - |
| 1906 | if (!QTestResult::skipCurrentTest() && !previousFailed) { | - |
| 1907 | | - |
| 1908 | if (QTest::testFuncs) { | - |
| 1909 | for (int i = 0; i != QTest::testFuncCount; i++) { | - |
| 1910 | if (!qInvokeTestMethod(metaObject->method(QTest::testFuncs[i].function()).methodSignature().constData(), | - |
| 1911 | QTest::testFuncs[i].data())) { | - |
| 1912 | break; | - |
| 1913 | } | - |
| 1914 | } | - |
| 1915 | testFuncCleaner.cleanup(); | - |
| 1916 | } else { | - |
| 1917 | int methodCount = metaObject->methodCount(); | - |
| 1918 | QMetaMethod *testMethods = new QMetaMethod[methodCount]; | - |
| 1919 | for (int i = 0; i != methodCount; i++) | - |
| 1920 | testMethods[i] = metaObject->method(i); | - |
| 1921 | for (int i = 0; i != methodCount; i++) { | - |
| 1922 | if (!isValidSlot(testMethods[i])) | - |
| 1923 | continue; | - |
| 1924 | if (!qInvokeTestMethod(testMethods[i].methodSignature().constData())) | - |
| 1925 | break; | - |
| 1926 | } | - |
| 1927 | delete[] testMethods; | - |
| 1928 | testMethods = 0; | - |
| 1929 | } | - |
| 1930 | } | - |
| 1931 | | - |
| 1932 | QTestResult::setSkipCurrentTest(false); | - |
| 1933 | QTestResult::setCurrentTestFunction("cleanupTestCase"); | - |
| 1934 | invokeMethod(testObject, "cleanupTestCase()"); | - |
| 1935 | QTestResult::finishedCurrentTestData(); | - |
| 1936 | QTestResult::finishedCurrentTestDataCleanup(); | - |
| 1937 | } | - |
| 1938 | QTestResult::finishedCurrentTestFunction(); | - |
| 1939 | QTestResult::setCurrentTestFunction(0); | - |
| 1940 | QTestTable::clearGlobalTestTable(); | - |
| 1941 | | - |
| 1942 | QTestLog::stopLogging(); | - |
| 1943 | } | - |
| 1944 | | - |
| 1945 | #if defined(Q_OS_UNIX) | - |
| 1946 | class FatalSignalHandler | - |
| 1947 | { | - |
| 1948 | public: | - |
| 1949 | FatalSignalHandler(); | - |
| 1950 | ~FatalSignalHandler(); | - |
| 1951 | | - |
| 1952 | private: | - |
| 1953 | static void signal(int); | - |
| 1954 | sigset_t handledSignals; | - |
| 1955 | }; | - |
| 1956 | | - |
| 1957 | void FatalSignalHandler::signal(int signum) | - |
| 1958 | { | - |
| 1959 | qFatal("Received signal %d", signum); | - |
| 1960 | #if defined(Q_OS_INTEGRITY) | - |
| 1961 | { | - |
| 1962 | struct sigaction act; | - |
| 1963 | memset(&act, 0, sizeof(struct sigaction)); | - |
| 1964 | act.sa_handler = SIG_DFL; | - |
| 1965 | sigaction(signum, &act, NULL); | - |
| 1966 | } | - |
| 1967 | #endif | - |
| 1968 | } | - |
| 1969 | | - |
| 1970 | FatalSignalHandler::FatalSignalHandler() | - |
| 1971 | { | - |
| 1972 | sigemptyset(&handledSignals); | - |
| 1973 | | - |
| 1974 | const int fatalSignals[] = { | - |
| 1975 | SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 }; | - |
| 1976 | | - |
| 1977 | struct sigaction act; | - |
| 1978 | memset(&act, 0, sizeof(act)); | - |
| 1979 | act.sa_handler = FatalSignalHandler::signal; | - |
| 1980 | | - |
| 1981 | // Remove the handler after it is invoked. | - |
| 1982 | #if !defined(Q_OS_INTEGRITY) | - |
| 1983 | act.sa_flags = SA_RESETHAND; | - |
| 1984 | #endif | - |
| 1985 | // Block all fatal signals in our signal handler so we don't try to close | - |
| 1986 | // the testlog twice. | - |
| 1987 | sigemptyset(&act.sa_mask); | - |
| 1988 | for (int i = 0; fatalSignals[i]; ++i) | - |
| 1989 | sigaddset(&act.sa_mask, fatalSignals[i]); | - |
| 1990 | | - |
| 1991 | struct sigaction oldact; | - |
| 1992 | | - |
| 1993 | for (int i = 0; fatalSignals[i]; ++i) { | - |
| 1994 | sigaction(fatalSignals[i], &act, &oldact); | - |
| 1995 | if ( | - |
| 1996 | #ifdef SA_SIGINFO | - |
| 1997 | oldact.sa_flags & SA_SIGINFO || | - |
| 1998 | #endif | - |
| 1999 | oldact.sa_handler != SIG_DFL) { | - |
| 2000 | sigaction(fatalSignals[i], &oldact, 0); | - |
| 2001 | } else | - |
| 2002 | { | - |
| 2003 | sigaddset(&handledSignals, fatalSignals[i]); | - |
| 2004 | } | - |
| 2005 | } | - |
| 2006 | } | - |
| 2007 | | - |
| 2008 | | - |
| 2009 | FatalSignalHandler::~FatalSignalHandler() | - |
| 2010 | { | - |
| 2011 | // Unregister any of our remaining signal handlers | - |
| 2012 | struct sigaction act; | - |
| 2013 | memset(&act, 0, sizeof(act)); | - |
| 2014 | act.sa_handler = SIG_DFL; | - |
| 2015 | | - |
| 2016 | struct sigaction oldact; | - |
| 2017 | | - |
| 2018 | for (int i = 1; i < 32; ++i) { | - |
| 2019 | if (!sigismember(&handledSignals, i)) | - |
| 2020 | continue; | - |
| 2021 | sigaction(i, &act, &oldact); | - |
| 2022 | | - |
| 2023 | // If someone overwrote it in the mean time, put it back | - |
| 2024 | if (oldact.sa_handler != FatalSignalHandler::signal) | - |
| 2025 | sigaction(i, &oldact, 0); | - |
| 2026 | } | - |
| 2027 | } | - |
| 2028 | | - |
| 2029 | #endif | - |
| 2030 | | - |
| 2031 | | - |
| 2032 | } // namespace | - |
| 2033 | | - |
| 2034 | /*! | - |
| | Executes tests declared in \a testObject. In addition, the private slots | |
| | \c{initTestCase()}, \c{cleanupTestCase()}, \c{init()} and \c{cleanup()} | |
| | are executed if they exist. See \l{Creating a Test} for more details. | |
| | | |
| | Optionally, the command line arguments \a argc and \a argv can be provided. | |
| | For a list of recognized arguments, read \l {QTestLib Command Line Arguments}. | |
| | | |
| | The following example will run all tests in \c MyTestObject: | |
| | | |
| | \snippet code/src_qtestlib_qtestcase.cpp 18 | |
| | | |
| | This function returns 0 if no tests failed, or a value other than 0 if one | |
| | or more tests failed or in case of unhandled exceptions. (Skipped tests do | |
| | not influence the return value.) | |
| | | |
| | For stand-alone test applications, the convenience macro \l QTEST_MAIN() can | |
| | be used to declare a main() function that parses the command line arguments | |
| | and executes the tests, avoiding the need to call this function explicitly. | |
| | | |
| | The return value from this function is also the exit code of the test | |
| | application when the \l QTEST_MAIN() macro is used. | |
| | | |
| | For stand-alone test applications, this function should not be called more | |
| | than once, as command-line options for logging test output to files and | |
| | executing individual test functions will not behave correctly. | |
| | | |
| | Note: This function is not reentrant, only one test can run at a time. A | |
| | test that was executed with qExec() can't run another test via qExec() and | |
| | threads are not allowed to call qExec() simultaneously. | |
| | | |
| | If you have programatically created the arguments, as opposed to getting them | |
| | from the arguments in \c main(), it is likely of interest to use | |
| | QTest::qExec(QObject *, const QStringList &) since it is Unicode safe. | |
| | | |
| | \sa QTEST_MAIN() | |
| | */*! | |
| 2035 | Executes tests declared in \a testObject. In addition, the private slots | - |
| 2036 | \c{initTestCase()}, \c{cleanupTestCase()}, \c{init()} and \c{cleanup()} | - |
| 2037 | are executed if they exist. See \l{Creating a Test} for more details. | - |
| 2038 | | - |
| 2039 | Optionally, the command line arguments \a argc and \a argv can be provided. | - |
| 2040 | For a list of recognized arguments, read \l {Qt Test Command Line Arguments}. | - |
| 2041 | | - |
| 2042 | The following example will run all tests in \c MyTestObject: | - |
| 2043 | | - |
| 2044 | \snippet code/src_qtestlib_qtestcase.cpp 18 | - |
| 2045 | | - |
| 2046 | This function returns 0 if no tests failed, or a value other than 0 if one | - |
| 2047 | or more tests failed or in case of unhandled exceptions. (Skipped tests do | - |
| 2048 | not influence the return value.) | - |
| 2049 | | - |
| 2050 | For stand-alone test applications, the convenience macro \l QTEST_MAIN() can | - |
| 2051 | be used to declare a main() function that parses the command line arguments | - |
| 2052 | and executes the tests, avoiding the need to call this function explicitly. | - |
| 2053 | | - |
| 2054 | The return value from this function is also the exit code of the test | - |
| 2055 | application when the \l QTEST_MAIN() macro is used. | - |
| 2056 | | - |
| 2057 | For stand-alone test applications, this function should not be called more | - |
| 2058 | than once, as command-line options for logging test output to files and | - |
| 2059 | executing individual test functions will not behave correctly. | - |
| 2060 | | - |
| 2061 | Note: This function is not reentrant, only one test can run at a time. A | - |
| 2062 | test that was executed with qExec() can't run another test via qExec() and | - |
| 2063 | threads are not allowed to call qExec() simultaneously. | - |
| 2064 | | - |
| 2065 | If you have programatically created the arguments, as opposed to getting them | - |
| 2066 | from the arguments in \c main(), it is likely of interest to use | - |
| 2067 | QTest::qExec(QObject *, const QStringList &) since it is Unicode safe. | - |
| 2068 | | - |
| 2069 | \sa QTEST_MAIN() | - |
| 2070 | */ | - |
| 2071 | | - |
| 2072 | int QTest::qExec(QObject *testObject, int argc, char **argv) | - |
| 2073 | { | - |
| 2074 | QBenchmarkGlobalData benchmarkData; | - |
| 2075 | QBenchmarkGlobalData::current = &benchmarkData; | - |
| 2076 | | - |
| 2077 | #ifdef QTESTLIB_USE_VALGRIND | - |
| 2078 | int callgrindChildExitCode = 0; | - |
| 2079 | #endif | - |
| 2080 | | - |
| 2081 | #ifdef Q_OS_MAC | - |
| 2082 | bool macNeedsActivate = qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0); | - |
| 2083 | IOPMAssertionID powerID; | - |
| 2084 | #endif | - |
| 2085 | #ifndef QT_NO_EXCEPTIONS | - |
| 2086 | try { | - |
| 2087 | #endif | - |
| 2088 | | - |
| 2089 | #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) | - |
| 2090 | # if !defined(Q_CC_MINGW) | - |
| 2091 | _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG); | - |
| 2092 | # endif | - |
| 2093 | SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); | - |
| 2094 | #endif | - |
| 2095 | | - |
| 2096 | #ifdef Q_OS_MAC | - |
| 2097 | if (macNeedsActivate) { | - |
| 2098 | CFStringRef reasonForActivity= CFSTR("No Display Sleep"); | - |
| 2099 | IOReturn ok = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, reasonForActivity, &powerID); | - |
| 2100 | | - |
| 2101 | if (ok != kIOReturnSuccess) | - |
| 2102 | macNeedsActivate = false; // no need to release the assertion on exit. | - |
| 2103 | } | - |
| 2104 | #endif | - |
| 2105 | | - |
| 2106 | QTestResult::reset(); | - |
| 2107 | | - |
| 2108 | QTEST_ASSERT(testObject); | - |
| 2109 | QTEST_ASSERT(!currentTestObject); | - |
| 2110 | currentTestObject = testObject; | - |
| 2111 | | - |
| 2112 | const QMetaObject *metaObject = testObject->metaObject(); | - |
| 2113 | QTEST_ASSERT(metaObject); | - |
| 2114 | | - |
| 2115 | QTestResult::setCurrentTestObject(metaObject->className()); | - |
| 2116 | if (argc > 0) | - |
| 2117 | QTestResult::setCurrentAppname(argv[0]); | - |
| 2118 | | - |
| 2119 | qtest_qParseArgs(argc, argv, false); | - |
| 2120 | | - |
| 2121 | #ifdef QTESTLIB_USE_VALGRIND | - |
| 2122 | if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) { | - |
| 2123 | const QStringList origAppArgs(QCoreApplication::arguments()); | - |
| 2124 | if (!QBenchmarkValgrindUtils::rerunThroughCallgrind(origAppArgs, callgrindChildExitCode)) | - |
| 2125 | return -1; | - |
| 2126 | | - |
| 2127 | QBenchmarkValgrindUtils::cleanup(); | - |
| 2128 | | - |
| 2129 | } else | - |
| 2130 | #endif | - |
| 2131 | { | - |
| 2132 | #if defined(Q_OS_UNIX) | - |
| 2133 | QScopedPointer<FatalSignalHandler> handler; | - |
| 2134 | if (!noCrashHandler) | - |
| 2135 | handler.reset(new FatalSignalHandler); | - |
| 2136 | #endif | - |
| 2137 | qInvokeTestMethods(testObject); | - |
| 2138 | } | - |
| 2139 | | - |
| 2140 | #ifndef QT_NO_EXCEPTIONS | - |
| 2141 | } catch (...) { | - |
| 2142 | QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__); | - |
| 2143 | if (QTestResult::currentTestFunction()) { | - |
| 2144 | QTestResult::finishedCurrentTestFunction(); | - |
| 2145 | QTestResult::setCurrentTestFunction(0); | - |
| 2146 | } | - |
| 2147 | | - |
| 2148 | QTestLog::stopLogging(); | - |
| 2149 | #ifdef Q_OS_MAC | - |
| 2150 | if (macNeedsActivate) { | - |
| 2151 | IOPMAssertionRelease(powerID); | - |
| 2152 | } | - |
| 2153 | #endif | - |
| 2154 | currentTestObject = 0; | - |
| 2155 | | - |
| 2156 | // Rethrow exception to make debugging easier. | - |
| 2157 | throw; | - |
| 2158 | return 1; | - |
| 2159 | } | - |
| 2160 | #endif | - |
| 2161 | | - |
| 2162 | currentTestObject = 0; | - |
| 2163 | | - |
| 2164 | QSignalDumper::endDump(); | - |
| 2165 | | - |
| 2166 | #ifdef Q_OS_MAC | - |
| 2167 | if (macNeedsActivate) { | - |
| 2168 | IOPMAssertionRelease(powerID); | - |
| 2169 | } | - |
| 2170 | #endif | - |
| 2171 | | - |
| 2172 | #ifdef QTESTLIB_USE_VALGRIND | - |
| 2173 | if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) | - |
| 2174 | return callgrindChildExitCode; | - |
| 2175 | #endif | - |
| 2176 | // make sure our exit code is never going above 127 | - |
| 2177 | // since that could wrap and indicate 0 test fails | - |
| 2178 | return qMin(QTestLog::failCount(), 127); | - |
| 2179 | } | - |
| 2180 | | - |
| 2181 | /*! | - |
| 2182 | \overload | - |
| 2183 | \since 4.4 | - |
| 2184 | | - |
| 2185 | Behaves identically to qExec(QObject *, int, char**) but takes a | - |
| 2186 | QStringList of \a arguments instead of a \c char** list. | - |
| 2187 | */ | - |
| 2188 | int QTest::qExec(QObject *testObject, const QStringList &arguments) | - |
| 2189 | { | - |
| 2190 | const int argc = arguments.count(); | - |
| 2191 | QVarLengthArray<char *> argv(argc); | - |
| 2192 | | - |
| 2193 | QVector<QByteArray> args; | - |
| 2194 | args.reserve(argc); | - |
| 2195 | | - |
| 2196 | for (int i = 0; i < argc; ++i) | - |
| 2197 | { | - |
| 2198 | args.append(arguments.at(i).toLocal8Bit().constData()); | - |
| 2199 | argv[i] = args.last().data(); | - |
| 2200 | } | - |
| 2201 | | - |
| 2202 | return qExec(testObject, argc, argv.data()); | - |
| 2203 | } | - |
| 2204 | | - |
| 2205 | /*! \internal | - |
| 2206 | */ | - |
| 2207 | void QTest::qFail(const char *statementStr, const char *file, int line) | - |
| 2208 | { | - |
| 2209 | QTestResult::addFailure(statementStr, file, line); | - |
| 2210 | } | - |
| 2211 | | - |
| 2212 | /*! \internal | - |
| 2213 | */ | - |
| 2214 | bool QTest::qVerify(bool statement, const char *statementStr, const char *description, | - |
| 2215 | const char *file, int line) | - |
| 2216 | { | - |
| 2217 | return QTestResult::verify(statement, statementStr, description, file, line); | - |
| 2218 | } | - |
| 2219 | | - |
| 2220 | /*! \fn void QTest::qSkip(const char *message, const char *file, int line) | - |
| 2221 | \internal | - |
| 2222 | */ | - |
| 2223 | void QTest::qSkip(const char *message, const char *file, int line) | - |
| 2224 | { | - |
| 2225 | QTestResult::addSkip(message, file, line); | - |
| 2226 | QTestResult::setSkipCurrentTest(true); | - |
| 2227 | } | - |
| 2228 | | - |
| 2229 | /*! \fn bool QTest::qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line) | - |
| 2230 | \internal | - |
| 2231 | */ | - |
| 2232 | bool QTest::qExpectFail(const char *dataIndex, const char *comment, | - |
| 2233 | QTest::TestFailMode mode, const char *file, int line) | - |
| 2234 | { | - |
| 2235 | return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line); | - |
| 2236 | } | - |
| 2237 | | - |
| 2238 | /*! \internal | - |
| 2239 | */ | - |
| 2240 | void QTest::qWarn(const char *message, const char *file, int line) | - |
| 2241 | { | - |
| 2242 | QTestLog::warn(message, file, line); | - |
| 2243 | } | - |
| 2244 | | - |
| 2245 | /*! | - |
| 2246 | Ignores messages created by qDebug() or qWarning(). If the \a message | - |
| 2247 | with the corresponding \a type is outputted, it will be removed from the | - |
| 2248 | test log. If the test finished and the \a message was not outputted, | - |
| 2249 | a test failure is appended to the test log. | - |
| 2250 | | - |
| 2251 | \b {Note:} Invoking this function will only ignore one message. | - |
| 2252 | If the message you want to ignore is outputted twice, you have to | - |
| 2253 | call ignoreMessage() twice, too. | - |
| 2254 | | - |
| 2255 | Example: | - |
| 2256 | \snippet code/src_qtestlib_qtestcase.cpp 19 | - |
| 2257 | | - |
| 2258 | The example above tests that QDir::mkdir() outputs the right warning when invoked | - |
| 2259 | with an invalid file name. | - |
| 2260 | */ | - |
| 2261 | void QTest::ignoreMessage(QtMsgType type, const char *message) | - |
| 2262 | { | - |
| 2263 | QTestLog::ignoreMessage(type, message); | - |
| 2264 | } | - |
| 2265 | | - |
| 2266 | /*! \internal | - |
| 2267 | */ | - |
| 2268 | | - |
| 2269 | #ifdef Q_OS_WIN | - |
| 2270 | static inline bool isWindowsBuildDirectory(const QString &dirName) | - |
| 2271 | { | - |
| 2272 | return dirName.compare(QStringLiteral("Debug"), Qt::CaseInsensitive) == 0 | - |
| 2273 | || dirName.compare(QStringLiteral("Release"), Qt::CaseInsensitive) == 0; | - |
| 2274 | } | - |
| 2275 | #endif | - |
| 2276 | | - |
| 2277 | QString QTest::qFindTestData(const QString& base, const char *file, int line, const char *builddir) | - |
| 2278 | { | - |
| 2279 | QString found; | - |
| 2280 | | - |
| 2281 | // Testdata priorities: | - |
| 2282 | | - |
| 2283 | // 1. relative to test binary. | - |
| 2284 | if (qApp) { | - |
| 2285 | QDir binDirectory(QCoreApplication::applicationDirPath()); | - |
| 2286 | if (binDirectory.exists(base)) { | - |
| 2287 | found = binDirectory.absoluteFilePath(base); | - |
| 2288 | } | - |
| 2289 | #ifdef Q_OS_WIN | - |
| 2290 | // Windows: The executable is typically located in one of the | - |
| 2291 | // 'Release' or 'Debug' directories. | - |
| 2292 | else if (isWindowsBuildDirectory(binDirectory.dirName()) | - |
| 2293 | && binDirectory.cdUp() && binDirectory.exists(base)) { | - |
| 2294 | found = binDirectory.absoluteFilePath(base); | - |
| 2295 | } | - |
| 2296 | #endif // Q_OS_WIN | - |
| 2297 | else if (QTestLog::verboseLevel() >= 2) { | - |
| 2298 | const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QLatin1Char('/') + base); | - |
| 2299 | QTestLog::info(qPrintable( | - |
| 2300 | QString::fromLatin1("testdata %1 not found relative to test binary [%2]; " | - |
| 2301 | "checking next location").arg(base, candidate)), | - |
| 2302 | file, line); | - |
| 2303 | } | - |
| 2304 | } | - |
| 2305 | | - |
| 2306 | // 2. installed path. | - |
| 2307 | if (found.isEmpty()) { | - |
| 2308 | const char *testObjectName = QTestResult::currentTestObjectName(); | - |
| 2309 | if (testObjectName) { | - |
| 2310 | QString testsPath = QLibraryInfo::location(QLibraryInfo::TestsPath); | - |
| 2311 | QString candidate = QString::fromLatin1("%1/%2/%3") | - |
| 2312 | .arg(testsPath, QFile::decodeName(testObjectName).toLower(), base); | - |
| 2313 | if (QFileInfo(candidate).exists()) { | - |
| 2314 | found = candidate; | - |
| 2315 | } | - |
| 2316 | else if (QTestLog::verboseLevel() >= 2) { | - |
| 2317 | QTestLog::info(qPrintable( | - |
| 2318 | QString::fromLatin1("testdata %1 not found in tests install path [%2]; " | - |
| 2319 | "checking next location") | - |
| 2320 | .arg(base, QDir::toNativeSeparators(candidate))), | - |
| 2321 | file, line); | - |
| 2322 | } | - |
| 2323 | } | - |
| 2324 | } | - |
| 2325 | | - |
| 2326 | // 3. relative to test source. | - |
| 2327 | if (found.isEmpty()) { | - |
| 2328 | // srcdir is the directory containing the calling source file. | - |
| 2329 | QFileInfo srcdir = QFileInfo(QFile::decodeName(file)).path(); | - |
| 2330 | | - |
| 2331 | // If the srcdir is relative, that means it is relative to the current working | - |
| 2332 | // directory of the compiler at compile time, which should be passed in as `builddir'. | - |
| 2333 | if (!srcdir.isAbsolute() && builddir) { | - |
| 2334 | srcdir.setFile(QFile::decodeName(builddir) + QLatin1String("/") + srcdir.filePath()); | - |
| 2335 | } | - |
| 2336 | | - |
| 2337 | QString candidate = QString::fromLatin1("%1/%2").arg(srcdir.canonicalFilePath(), base); | - |
| 2338 | if (QFileInfo(candidate).exists()) { | - |
| 2339 | found = candidate; | - |
| 2340 | } | - |
| 2341 | else if (QTestLog::verboseLevel() >= 2) { | - |
| 2342 | QTestLog::info(qPrintable( | - |
| 2343 | QString::fromLatin1("testdata %1 not found relative to source path [%2]") | - |
| 2344 | .arg(base, QDir::toNativeSeparators(candidate))), | - |
| 2345 | file, line); | - |
| 2346 | } | - |
| 2347 | } | - |
| 2348 | | - |
| 2349 | if (found.isEmpty()) { | - |
| 2350 | QTest::qWarn(qPrintable( | - |
| 2351 | QString::fromLatin1("testdata %1 could not be located!").arg(base)), | - |
| 2352 | file, line); | - |
| 2353 | } | - |
| 2354 | else if (QTestLog::verboseLevel() >= 1) { | - |
| 2355 | QTestLog::info(qPrintable( | - |
| 2356 | QString::fromLatin1("testdata %1 was located at %2").arg(base, QDir::toNativeSeparators(found))), | - |
| 2357 | file, line); | - |
| 2358 | } | - |
| 2359 | | - |
| 2360 | return found; | - |
| 2361 | } | - |
| 2362 | | - |
| 2363 | /*! \internal | - |
| 2364 | */ | - |
| 2365 | QString QTest::qFindTestData(const char *base, const char *file, int line, const char *builddir) | - |
| 2366 | { | - |
| 2367 | return qFindTestData(QFile::decodeName(base), file, line, builddir); | - |
| 2368 | } | - |
| 2369 | | - |
| 2370 | /*! \internal | - |
| 2371 | */ | - |
| 2372 | void *QTest::qData(const char *tagName, int typeId) | - |
| 2373 | { | - |
| 2374 | return fetchData(QTestResult::currentTestData(), tagName, typeId); | - |
| 2375 | } | - |
| 2376 | | - |
| 2377 | /*! \internal | - |
| 2378 | */ | - |
| 2379 | void *QTest::qGlobalData(const char *tagName, int typeId) | - |
| 2380 | { | - |
| 2381 | return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId); | - |
| 2382 | } | - |
| 2383 | | - |
| 2384 | /*! \internal | - |
| 2385 | */ | - |
| 2386 | void *QTest::qElementData(const char *tagName, int metaTypeId) | - |
| 2387 | { | - |
| 2388 | QTEST_ASSERT(tagName); | - |
| 2389 | QTestData *data = QTestResult::currentTestData(); | - |
| 2390 | QTEST_ASSERT(data); | - |
| 2391 | QTEST_ASSERT(data->parent()); | - |
| 2392 | | - |
| 2393 | int idx = data->parent()->indexOf(tagName); | - |
| 2394 | QTEST_ASSERT(idx != -1); | - |
| 2395 | QTEST_ASSERT(data->parent()->elementTypeId(idx) == metaTypeId); | - |
| 2396 | | - |
| 2397 | return data->data(data->parent()->indexOf(tagName)); | - |
| 2398 | } | - |
| 2399 | | - |
| 2400 | /*! \internal | - |
| 2401 | */ | - |
| 2402 | void QTest::addColumnInternal(int id, const char *name) | - |
| 2403 | { | - |
| 2404 | QTestTable *tbl = QTestTable::currentTestTable(); | - |
| 2405 | QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot."); | - |
| 2406 | | - |
| 2407 | tbl->addColumn(id, name); | - |
| 2408 | } | - |
| 2409 | | - |
| 2410 | /*! | - |
| 2411 | Appends a new row to the current test data. \a dataTag is the name of | - |
| 2412 | the testdata that will appear in the test output. Returns a QTestData reference | - |
| 2413 | that can be used to stream in data. | - |
| 2414 | | - |
| 2415 | Example: | - |
| 2416 | \snippet code/src_qtestlib_qtestcase.cpp 20 | - |
| 2417 | | - |
| 2418 | \b {Note:} This macro can only be used in a test's data function | - |
| 2419 | that is invoked by the test framework. | - |
| 2420 | | - |
| 2421 | See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for | - |
| 2422 | a more extensive example. | - |
| 2423 | | - |
| 2424 | \sa addColumn(), QFETCH() | - |
| 2425 | */ | - |
| 2426 | QTestData &QTest::newRow(const char *dataTag) | - |
| 2427 | { | - |
| 2428 | QTEST_ASSERT_X(dataTag, "QTest::newRow()", "Data tag can not be null"); | - |
| 2429 | QTestTable *tbl = QTestTable::currentTestTable(); | - |
| 2430 | QTEST_ASSERT_X(tbl, "QTest::newRow()", "Cannot add testdata outside of a _data slot."); | - |
| 2431 | QTEST_ASSERT_X(tbl->elementCount(), "QTest::newRow()", "Must add columns before attempting to add rows."); | - |
| 2432 | | - |
| 2433 | return *tbl->newData(dataTag); | - |
| 2434 | } | - |
| 2435 | | - |
| 2436 | /*! \fn void QTest::addColumn(const char *name, T *dummy = 0) | - |
| 2437 | | - |
| 2438 | Adds a column with type \c{T} to the current test data. | - |
| 2439 | \a name is the name of the column. \a dummy is a workaround | - |
| 2440 | for buggy compilers and can be ignored. | - |
| 2441 | | - |
| 2442 | To populate the column with values, newRow() can be used. Use | - |
| 2443 | \l QFETCH() to fetch the data in the actual test. | - |
| 2444 | | - |
| 2445 | Example: | - |
| 2446 | \snippet code/src_qtestlib_qtestcase.cpp 21 | - |
| 2447 | | - |
| 2448 | To add custom types to the testdata, the type must be registered with | - |
| 2449 | QMetaType via \l Q_DECLARE_METATYPE(). | - |
| 2450 | | - |
| 2451 | \b {Note:} This macro can only be used in a test's data function | - |
| 2452 | that is invoked by the test framework. | - |
| 2453 | | - |
| 2454 | See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for | - |
| 2455 | a more extensive example. | - |
| 2456 | | - |
| 2457 | \sa QTest::newRow(), QFETCH(), QMetaType | - |
| 2458 | */ | - |
| 2459 | | - |
| 2460 | /*! | - |
| 2461 | Returns the name of the test function that is currently executed. | - |
| 2462 | | - |
| 2463 | Example: | - |
| 2464 | | - |
| 2465 | \snippet code/src_qtestlib_qtestcase.cpp 22 | - |
| 2466 | */ | - |
| 2467 | const char *QTest::currentTestFunction() | - |
| 2468 | { | - |
| 2469 | return QTestResult::currentTestFunction(); | - |
| 2470 | } | - |
| 2471 | | - |
| 2472 | /*! | - |
| 2473 | Returns the name of the current test data. If the test doesn't | - |
| 2474 | have any assigned testdata, the function returns 0. | - |
| 2475 | */ | - |
| 2476 | const char *QTest::currentDataTag() | - |
| 2477 | { | - |
| 2478 | return QTestResult::currentDataTag(); | - |
| 2479 | } | - |
| 2480 | | - |
| 2481 | /*! | - |
| 2482 | Returns true if the current test function failed, otherwise false. | - |
| 2483 | */ | - |
| 2484 | bool QTest::currentTestFailed() | - |
| 2485 | { | - |
| 2486 | return QTestResult::currentTestFailed(); | - |
| 2487 | } | - |
| 2488 | | - |
| 2489 | /*! | - |
| 2490 | Sleeps for \a ms milliseconds, blocking execution of the | - |
| 2491 | test. qSleep() will not do any event processing and leave your test | - |
| 2492 | unresponsive. Network communication might time out while | - |
| 2493 | sleeping. Use \l qWait() to do non-blocking sleeping. | - |
| 2494 | | - |
| 2495 | \a ms must be greater than 0. | - |
| 2496 | | - |
| 2497 | \b {Note:} The qSleep() function calls either \c nanosleep() on | - |
| 2498 | unix or \c Sleep() on windows, so the accuracy of time spent in | - |
| 2499 | qSleep() depends on the operating system. | - |
| 2500 | | - |
| 2501 | Example: | - |
| 2502 | \snippet code/src_qtestlib_qtestcase.cpp 23 | - |
| 2503 | | - |
| 2504 | \sa qWait() | - |
| 2505 | */ | - |
| 2506 | void QTest::qSleep(int ms) | - |
| 2507 | { | - |
| 2508 | QTEST_ASSERT(ms > 0); | - |
| 2509 | | - |
| 2510 | #ifdef Q_OS_WIN | - |
| 2511 | Sleep(uint(ms)); | - |
| 2512 | #else | - |
| 2513 | struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; | - |
| 2514 | nanosleep(&ts, NULL); | - |
| 2515 | #endif | - |
| 2516 | } | - |
| 2517 | | - |
| 2518 | /*! \internal | - |
| 2519 | */ | - |
| 2520 | QObject *QTest::testObject() | - |
| 2521 | { | - |
| 2522 | return currentTestObject; | - |
| 2523 | } | - |
| 2524 | | - |
| 2525 | /*! \internal | - |
| 2526 | This function is called by various specializations of QTest::qCompare | - |
| 2527 | to decide whether to report a failure and to produce verbose test output. | - |
| 2528 | | - |
| 2529 | The failureMsg parameter can be null, in which case a default message | - |
| 2530 | will be output if the compare fails. If the compare succeeds, failureMsg | - |
| 2531 | will not be output. | - |
| 2532 | | - |
| 2533 | If the caller has already passed a failure message showing the compared | - |
| 2534 | values, or if those values cannot be stringified, val1 and val2 can be null. | - |
| 2535 | */ | - |
| 2536 | bool QTest::compare_helper(bool success, const char *failureMsg, | - |
| 2537 | char *val1, char *val2, | - |
| 2538 | const char *actual, const char *expected, | - |
| 2539 | const char *file, int line) | - |
| 2540 | { | - |
| 2541 | return QTestResult::compare(success, failureMsg, val1, val2, actual, expected, file, line); | - |
| 2542 | } | - |
| 2543 | | - |
| 2544 | /*! \fn bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2545 | \internal | - |
| 2546 | */ | - |
| 2547 | bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected, | - |
| 2548 | const char *file, int line) | - |
| 2549 | { | - |
| 2550 | return compare_helper(qFuzzyCompare(t1, t2), "Compared floats are not the same (fuzzy compare)", | - |
| 2551 | toString(t1), toString(t2), actual, expected, file, line); | - |
| 2552 | } | - |
| 2553 | | - |
| 2554 | /*! \fn bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2555 | \internal | - |
| 2556 | */ | - |
| 2557 | bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected, | - |
| 2558 | const char *file, int line) | - |
| 2559 | { | - |
| 2560 | return compare_helper(qFuzzyCompare(t1, t2), "Compared doubles are not the same (fuzzy compare)", | - |
| 2561 | toString(t1), toString(t2), actual, expected, file, line); | - |
| 2562 | } | - |
| 2563 | | - |
| 2564 | #define TO_STRING_IMPL(TYPE, FORMAT) \ | - |
| 2565 | template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ | - |
| 2566 | { \ | - |
| 2567 | char *msg = new char[128]; \ | - |
| 2568 | qsnprintf(msg, 128, #FORMAT, t); \ | - |
| 2569 | return msg; \ | - |
| 2570 | } | - |
| 2571 | | - |
| 2572 | TO_STRING_IMPL(short, %hd) | - |
| 2573 | TO_STRING_IMPL(ushort, %hu) | - |
| 2574 | TO_STRING_IMPL(int, %d) | - |
| 2575 | TO_STRING_IMPL(uint, %u) | - |
| 2576 | TO_STRING_IMPL(long, %ld) | - |
| 2577 | TO_STRING_IMPL(ulong, %lu) | - |
| 2578 | #if defined(Q_OS_WIN) | - |
| 2579 | TO_STRING_IMPL(qint64, %I64d) | - |
| 2580 | TO_STRING_IMPL(quint64, %I64u) | - |
| 2581 | #else | - |
| 2582 | TO_STRING_IMPL(qint64, %lld) | - |
| 2583 | TO_STRING_IMPL(quint64, %llu) | - |
| 2584 | #endif | - |
| 2585 | TO_STRING_IMPL(bool, %d) | - |
| 2586 | TO_STRING_IMPL(char, %c) | - |
| 2587 | TO_STRING_IMPL(float, %g) | - |
| 2588 | TO_STRING_IMPL(double, %lg) | - |
| 2589 | | - |
| 2590 | /*! \internal | - |
| 2591 | */ | - |
| 2592 | char *QTest::toString(const char *str) | - |
| 2593 | { | - |
| 2594 | if (!str) | - |
| 2595 | return 0; | - |
| 2596 | char *msg = new char[strlen(str) + 1]; | - |
| 2597 | return qstrcpy(msg, str); | - |
| 2598 | } | - |
| 2599 | | - |
| 2600 | /*! \internal | - |
| 2601 | */ | - |
| 2602 | char *QTest::toString(const void *p) | - |
| 2603 | { | - |
| 2604 | char *msg = new char[128]; | - |
| 2605 | qsnprintf(msg, 128, "%p", p); | - |
| 2606 | return msg; | - |
| 2607 | } | - |
| 2608 | | - |
| 2609 | /*! \internal | - |
| 2610 | */ | - |
| 2611 | bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual, | - |
| 2612 | const char *expected, const char *file, int line) | - |
| 2613 | { | - |
| 2614 | return compare_helper(qstrcmp(t1, t2) == 0, "Compared strings are not the same", | - |
| 2615 | toString(t1), toString(t2), actual, expected, file, line); | - |
| 2616 | } | - |
| 2617 | | - |
| 2618 | /*! \fn bool QTest::compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line); | - |
| 2619 | \internal | - |
| 2620 | */ | - |
| 2621 | | - |
| 2622 | /*! \fn bool QTest::qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int); | - |
| 2623 | \internal | - |
| 2624 | */ | - |
| 2625 | | - |
| 2626 | | - |
| 2627 | /*! \fn void QTest::mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1) | - |
| 2628 | \internal | - |
| 2629 | */ | - |
| 2630 | | - |
| 2631 | /*! \fn bool QTest::qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2632 | \internal | - |
| 2633 | */ | - |
| 2634 | | - |
| 2635 | /*! \fn bool QTest::qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2636 | \internal | - |
| 2637 | */ | - |
| 2638 | | - |
| 2639 | /*! \fn bool QTest::qCompare(T const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2640 | \internal | - |
| 2641 | */ | - |
| 2642 | | - |
| 2643 | /*! \fn bool QTest::qCompare(const T *t1, const T *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2644 | \internal | - |
| 2645 | */ | - |
| 2646 | | - |
| 2647 | /*! \fn bool QTest::qCompare(T *t1, T *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2648 | \internal | - |
| 2649 | */ | - |
| 2650 | | - |
| 2651 | /*! \fn bool QTest::qCompare(const T1 *t1, const T2 *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2652 | \internal | - |
| 2653 | */ | - |
| 2654 | | - |
| 2655 | /*! \fn bool QTest::qCompare(T1 *t1, T2 *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2656 | \internal | - |
| 2657 | */ | - |
| 2658 | | - |
| 2659 | /*! \fn bool QTest::qCompare(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2660 | \internal | - |
| 2661 | */ | - |
| 2662 | | - |
| 2663 | /*! \fn bool QTest::qCompare(char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2664 | \internal | - |
| 2665 | */ | - |
| 2666 | | - |
| 2667 | /*! \fn bool QTest::qCompare(char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2668 | \internal | - |
| 2669 | */ | - |
| 2670 | | - |
| 2671 | /*! \fn bool QTest::qCompare(const char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2672 | \internal | - |
| 2673 | */ | - |
| 2674 | | - |
| 2675 | /*! \fn bool QTest::qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2676 | \internal | - |
| 2677 | */ | - |
| 2678 | | - |
| 2679 | /*! \fn bool QTest::qCompare(QLatin1String const &t1, QString const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2680 | \internal | - |
| 2681 | */ | - |
| 2682 | | - |
| 2683 | /*! \fn bool QTest::qCompare(QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2684 | \internal | - |
| 2685 | */ | - |
| 2686 | | - |
| 2687 | /*! \fn bool QTest::qCompare(QFlags<T> const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2688 | \internal | - |
| 2689 | */ | - |
| 2690 | | - |
| 2691 | /*! \fn bool QTest::qCompare(QFlags<T> const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2692 | \internal | - |
| 2693 | */ | - |
| 2694 | | - |
| 2695 | /*! \fn bool QTest::qCompare(bool const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line) | - |
| 2696 | \internal | - |
| 2697 | */ | - |
| 2698 | | - |
| 2699 | /*! \fn bool QTest::qTest(const T& actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line) | - |
| 2700 | \internal | - |
| 2701 | */ | - |
| 2702 | | - |
| 2703 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) | - |
| 2704 | \internal | - |
| 2705 | */ | - |
| 2706 | | - |
| 2707 | /*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) | - |
| 2708 | \internal | - |
| 2709 | */ | - |
| 2710 | | - |
| 2711 | /*! \fn void QTest::simulateEvent(QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) | - |
| 2712 | \internal | - |
| 2713 | */ | - |
| 2714 | | - |
| 2715 | QT_END_NAMESPACE | - |
| 2716 | | - |
| | |