| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtTest module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 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 |
|
|---|
| 58 | #include "QtTest/private/qtestlog_p.h"
|
|---|
| 59 | #include "QtTest/private/qtesttable_p.h"
|
|---|
| 60 | #include "QtTest/qtestdata.h"
|
|---|
| 61 | #include "QtTest/private/qtestresult_p.h"
|
|---|
| 62 | #include "QtTest/private/qsignaldumper_p.h"
|
|---|
| 63 | #include "QtTest/private/qbenchmark_p.h"
|
|---|
| 64 | #include "3rdparty/cycle_p.h"
|
|---|
| 65 |
|
|---|
| 66 | #include <stdarg.h>
|
|---|
| 67 | #include <stdio.h>
|
|---|
| 68 | #include <stdlib.h>
|
|---|
| 69 |
|
|---|
| 70 | #ifdef Q_OS_WIN
|
|---|
| 71 | #include <windows.h> // for Sleep
|
|---|
| 72 | #endif
|
|---|
| 73 | #ifdef Q_OS_UNIX
|
|---|
| 74 | #include <errno.h>
|
|---|
| 75 | #include <signal.h>
|
|---|
| 76 | #include <time.h>
|
|---|
| 77 | #endif
|
|---|
| 78 |
|
|---|
| 79 | #ifdef Q_WS_MAC
|
|---|
| 80 | #include <Carbon/Carbon.h> // for SetFrontProcess
|
|---|
| 81 | #ifdef QT_MAC_USE_COCOA
|
|---|
| 82 | #include <IOKit/pwr_mgt/IOPMLib.h>
|
|---|
| 83 | #else
|
|---|
| 84 | #include <Security/AuthSession.h>
|
|---|
| 85 | #endif
|
|---|
| 86 | #undef verify
|
|---|
| 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 the QTestLib tool.
|
|---|
| 97 |
|
|---|
| 98 | Please refer to the \l{QTestLib Manual} documentation for information on
|
|---|
| 99 | how to write unit tests.
|
|---|
| 100 | */
|
|---|
| 101 |
|
|---|
| 102 | /*! \macro QVERIFY(condition)
|
|---|
| 103 |
|
|---|
| 104 | \relates QTest
|
|---|
| 105 |
|
|---|
| 106 | The QVERIFY() macro checks whether the \a condition is true or not. If it is
|
|---|
| 107 | true, execution continues. If not, a failure is recorded in the test log
|
|---|
| 108 | and the test won't be executed further.
|
|---|
| 109 |
|
|---|
| 110 | \bold {Note:} This macro can only be used in a test function that is invoked
|
|---|
| 111 | by the test framework.
|
|---|
| 112 |
|
|---|
| 113 | Example:
|
|---|
| 114 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 0
|
|---|
| 115 |
|
|---|
| 116 | \sa QCOMPARE()
|
|---|
| 117 | */
|
|---|
| 118 |
|
|---|
| 119 | /*! \macro QVERIFY2(condition, message)
|
|---|
| 120 |
|
|---|
| 121 | \relates QTest
|
|---|
| 122 |
|
|---|
| 123 | The QVERIFY2() macro behaves exactly like QVERIFY(), except that it outputs
|
|---|
| 124 | a verbose \a message when \a condition is false. The \a message is a plain
|
|---|
| 125 | C string.
|
|---|
| 126 |
|
|---|
| 127 | Example:
|
|---|
| 128 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 1
|
|---|
| 129 |
|
|---|
| 130 | \sa QVERIFY(), QCOMPARE()
|
|---|
| 131 | */
|
|---|
| 132 |
|
|---|
| 133 | /*! \macro QCOMPARE(actual, expected)
|
|---|
| 134 |
|
|---|
| 135 | \relates QTest
|
|---|
| 136 |
|
|---|
| 137 | The QCOMPARE macro compares an \a actual value to an \a expected value using
|
|---|
| 138 | the equals operator. If \a actual and \a expected are identical, execution
|
|---|
| 139 | continues. If not, a failure is recorded in the test log and the test
|
|---|
| 140 | won't be executed further.
|
|---|
| 141 |
|
|---|
| 142 | In the case of comparing floats and doubles, qFuzzyCompare() is used for
|
|---|
| 143 | comparing. This means that comparing to 0 will likely fail. One solution
|
|---|
| 144 | to this is to compare to 1, and add 1 to the produced output.
|
|---|
| 145 |
|
|---|
| 146 | QCOMPARE tries to output the contents of the values if the comparison fails,
|
|---|
| 147 | so it is visible from the test log why the comparison failed.
|
|---|
| 148 |
|
|---|
| 149 | QCOMPARE is very strict on the data types. Both \a actual and \a expected
|
|---|
| 150 | have to be of the same type, otherwise the test won't compile. This prohibits
|
|---|
| 151 | unspecified behavior from being introduced; that is behavior that usually
|
|---|
| 152 | occurs when the compiler implicitly casts the argument.
|
|---|
| 153 |
|
|---|
| 154 | If you use QCOMPARE() to compare two QStringList objects, it will start
|
|---|
| 155 | comparing the objects from the end of the lists.
|
|---|
| 156 |
|
|---|
| 157 | For your own classes, you can use \l QTest::toString() to format values for
|
|---|
| 158 | outputting into the test log.
|
|---|
| 159 |
|
|---|
| 160 | \note This macro can only be used in a test function that is invoked
|
|---|
| 161 | by the test framework.
|
|---|
| 162 |
|
|---|
| 163 | Example:
|
|---|
| 164 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 2
|
|---|
| 165 |
|
|---|
| 166 | \sa QVERIFY(), QTest::toString()
|
|---|
| 167 | */
|
|---|
| 168 |
|
|---|
| 169 | /*! \macro QFETCH(type, name)
|
|---|
| 170 |
|
|---|
| 171 | \relates QTest
|
|---|
| 172 |
|
|---|
| 173 | The fetch macro creates a local variable named \a name with the type \a type
|
|---|
| 174 | on the stack. \a name has to match the element name from the test's data.
|
|---|
| 175 | If no such element exists, the test will assert.
|
|---|
| 176 |
|
|---|
| 177 | Assuming a test has the following data:
|
|---|
| 178 |
|
|---|
| 179 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 3
|
|---|
| 180 |
|
|---|
| 181 | The test data has two elements, a QString called \c aString and an integer
|
|---|
| 182 | called \c expected. To fetch these values in the actual test:
|
|---|
| 183 |
|
|---|
| 184 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 4
|
|---|
| 185 |
|
|---|
| 186 | \c aString and \c expected are variables on the stack that are initialized with
|
|---|
| 187 | the current test data.
|
|---|
| 188 |
|
|---|
| 189 | \bold {Note:} This macro can only be used in a test function that is invoked
|
|---|
| 190 | by the test framework. The test function must have a _data function.
|
|---|
| 191 | */
|
|---|
| 192 |
|
|---|
| 193 | /*! \macro QWARN(message)
|
|---|
| 194 |
|
|---|
| 195 | \relates QTest
|
|---|
| 196 | \threadsafe
|
|---|
| 197 |
|
|---|
| 198 | Appends \a message as a warning to the test log. This macro can be used anywhere
|
|---|
| 199 | in your tests.
|
|---|
| 200 | */
|
|---|
| 201 |
|
|---|
| 202 | /*! \macro QFAIL(message)
|
|---|
| 203 |
|
|---|
| 204 | \relates QTest
|
|---|
| 205 |
|
|---|
| 206 | This macro can be used to force a test failure. The test stops
|
|---|
| 207 | executing and the failure \a message is appended to the test log.
|
|---|
| 208 |
|
|---|
| 209 | \bold {Note:} This macro can only be used in a test function that is invoked
|
|---|
| 210 | by the test framework.
|
|---|
| 211 |
|
|---|
| 212 | Example:
|
|---|
| 213 |
|
|---|
| 214 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 5
|
|---|
| 215 | */
|
|---|
| 216 |
|
|---|
| 217 | /*! \macro QTEST(actual, testElement)
|
|---|
| 218 |
|
|---|
| 219 | \relates QTest
|
|---|
| 220 |
|
|---|
| 221 | QTEST() is a convenience macro for \l QCOMPARE() that compares
|
|---|
| 222 | the value \a actual with the element \a testElement from the test's data.
|
|---|
| 223 | If there is no such element, the test asserts.
|
|---|
| 224 |
|
|---|
| 225 | Apart from that, QTEST() behaves exactly as \l QCOMPARE().
|
|---|
| 226 |
|
|---|
| 227 | Instead of writing:
|
|---|
| 228 |
|
|---|
| 229 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 6
|
|---|
| 230 |
|
|---|
| 231 | you can write:
|
|---|
| 232 |
|
|---|
| 233 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 7
|
|---|
| 234 |
|
|---|
| 235 | \sa QCOMPARE()
|
|---|
| 236 | */
|
|---|
| 237 |
|
|---|
| 238 | /*! \macro QSKIP(description, mode)
|
|---|
| 239 |
|
|---|
| 240 | \relates QTest
|
|---|
| 241 |
|
|---|
| 242 | The QSKIP() macro stops execution of the test without adding a failure to the
|
|---|
| 243 | test log. You can use it to skip tests that wouldn't make sense in the current
|
|---|
| 244 | configuration. The text \a description is appended to the test log and should
|
|---|
| 245 | contain an explanation why the test couldn't be executed. \a mode is a QTest::SkipMode
|
|---|
| 246 | and describes whether to proceed with the rest of the test data or not.
|
|---|
| 247 |
|
|---|
| 248 | \bold {Note:} This macro can only be used in a test function that is invoked
|
|---|
| 249 | by the test framework.
|
|---|
| 250 |
|
|---|
| 251 | Example:
|
|---|
| 252 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 8
|
|---|
| 253 |
|
|---|
| 254 | \sa QTest::SkipMode
|
|---|
| 255 | */
|
|---|
| 256 |
|
|---|
| 257 | /*! \macro QEXPECT_FAIL(dataIndex, comment, mode)
|
|---|
| 258 |
|
|---|
| 259 | \relates QTest
|
|---|
| 260 |
|
|---|
| 261 | The QEXPECT_FAIL() macro marks the next \l QCOMPARE() or \l QVERIFY() as an
|
|---|
| 262 | expected failure. Instead of adding a failure to the test log, an expected
|
|---|
| 263 | failure will be reported.
|
|---|
| 264 |
|
|---|
| 265 | If a \l QVERIFY() or \l QCOMPARE() is marked as an expected failure,
|
|---|
| 266 | but passes instead, an unexpected pass (XPASS) is written to the test log.
|
|---|
| 267 |
|
|---|
| 268 | The parameter \a dataIndex describes for which entry in the test data the
|
|---|
| 269 | failure is expected. Pass an empty string (\c{""}) if the failure
|
|---|
| 270 | is expected for all entries or if no test data exists.
|
|---|
| 271 |
|
|---|
| 272 | \a comment will be appended to the test log for the expected failure.
|
|---|
| 273 |
|
|---|
| 274 | \a mode is a \l QTest::TestFailMode and sets whether the test should
|
|---|
| 275 | continue to execute or not.
|
|---|
| 276 |
|
|---|
| 277 | \bold {Note:} This macro can only be used in a test function that is invoked
|
|---|
| 278 | by the test framework.
|
|---|
| 279 |
|
|---|
| 280 | Example 1:
|
|---|
| 281 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 9
|
|---|
| 282 |
|
|---|
| 283 | In the example above, an expected fail will be written into the test output
|
|---|
| 284 | if the variable \c i is not 42. If the variable \c i is 42, an unexpected pass
|
|---|
| 285 | is written instead. The QEXPECT_FAIL() has no influence on the second QCOMPARE()
|
|---|
| 286 | statement in the example.
|
|---|
| 287 |
|
|---|
| 288 | Example 2:
|
|---|
| 289 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 10
|
|---|
| 290 |
|
|---|
| 291 | The above testfunction will not continue executing for the test data
|
|---|
| 292 | entry \c{data27}.
|
|---|
| 293 |
|
|---|
| 294 | \sa QTest::TestFailMode, QVERIFY(), QCOMPARE()
|
|---|
| 295 | */
|
|---|
| 296 |
|
|---|
| 297 | /*! \macro QTEST_MAIN(TestClass)
|
|---|
| 298 |
|
|---|
| 299 | \relates QTest
|
|---|
| 300 |
|
|---|
| 301 | Implements a main() function that instantiates an application object and
|
|---|
| 302 | the \a TestClass, and executes all tests in the order they were defined.
|
|---|
| 303 | Use this macro to build stand-alone executables.
|
|---|
| 304 |
|
|---|
| 305 | If \c QT_GUI_LIB is defined, the application object will be a QApplication,
|
|---|
| 306 | otherwise it will be a QCoreApplication. If qmake is used and the configuration
|
|---|
| 307 | includes \c{QT += gui}, then \c QT_GUI_LIB will be defined automatically.
|
|---|
| 308 |
|
|---|
| 309 | \bold {Note:} On platforms that have keypad navigation enabled by default (eg: Symbian),
|
|---|
| 310 | this macro will forcfully disable it to simplify the usage of key events when writing
|
|---|
| 311 | autotests. If you wish to write a test case that uses keypad navigation, you should
|
|---|
| 312 | enable it either in the \c {initTestCase()} or \c {init()} functions of your test case.
|
|---|
| 313 |
|
|---|
| 314 | Example:
|
|---|
| 315 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 11
|
|---|
| 316 |
|
|---|
| 317 | \sa QTEST_APPLESS_MAIN(), QTest::qExec(), QApplication::setNavigationMode()
|
|---|
| 318 | */
|
|---|
| 319 |
|
|---|
| 320 | /*! \macro QTEST_APPLESS_MAIN(TestClass)
|
|---|
| 321 |
|
|---|
| 322 | \relates QTest
|
|---|
| 323 |
|
|---|
| 324 | Implements a main() function that executes all tests in \a TestClass.
|
|---|
| 325 |
|
|---|
| 326 | Behaves like \l QTEST_MAIN(), but doesn't instantiate a QApplication
|
|---|
| 327 | object. Use this macro for really simple stand-alone non-GUI tests.
|
|---|
| 328 |
|
|---|
| 329 | \sa QTEST_MAIN()
|
|---|
| 330 | */
|
|---|
| 331 |
|
|---|
| 332 | /*! \macro QTEST_NOOP_MAIN()
|
|---|
| 333 |
|
|---|
| 334 | \relates QTest
|
|---|
| 335 |
|
|---|
| 336 | Implements a main() function with a test class that does absolutely nothing.
|
|---|
| 337 | Use this macro to create a test that produces valid test output but just
|
|---|
| 338 | doesn't execute any test, for example in conditional compilations:
|
|---|
| 339 |
|
|---|
| 340 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 12
|
|---|
| 341 |
|
|---|
| 342 | \sa QTEST_MAIN()
|
|---|
| 343 | */
|
|---|
| 344 |
|
|---|
| 345 | /*!
|
|---|
| 346 | \macro QBENCHMARK
|
|---|
| 347 |
|
|---|
| 348 | \relates QTest
|
|---|
| 349 |
|
|---|
| 350 | This macro is used to measure the performance of code within a test.
|
|---|
| 351 | The code to be benchmarked is contained within a code block following
|
|---|
| 352 | this macro.
|
|---|
| 353 |
|
|---|
| 354 | For example:
|
|---|
| 355 |
|
|---|
| 356 | \snippet examples/qtestlib/tutorial5/benchmarking.cpp 0
|
|---|
| 357 |
|
|---|
| 358 | \sa {QTestLib Manual#Creating a Benchmark}{Creating a Benchmark},
|
|---|
| 359 | {Chapter 5: Writing a Benchmark}{Writing a Benchmark}
|
|---|
| 360 | */
|
|---|
| 361 |
|
|---|
| 362 | /*!
|
|---|
| 363 | \macro QBENCHMARK_ONCE
|
|---|
| 364 | \since 4.6
|
|---|
| 365 |
|
|---|
| 366 | \relates QTest
|
|---|
| 367 |
|
|---|
| 368 | \brief The QBENCHMARK_ONCE macro is for measuring performance of a
|
|---|
| 369 | code block by running it once.
|
|---|
| 370 |
|
|---|
| 371 | This macro is used to measure the performance of code within a test.
|
|---|
| 372 | The code to be benchmarked is contained within a code block following
|
|---|
| 373 | this macro.
|
|---|
| 374 |
|
|---|
| 375 | Unlike QBENCHMARK, the contents of the contained code block is only run
|
|---|
| 376 | once. The elapsed time will be reported as "0" if it's to short to
|
|---|
| 377 | be measured by the selected backend. (Use)
|
|---|
| 378 |
|
|---|
| 379 | \sa {QTestLib Manual#Creating a Benchmark}{Creating a Benchmark},
|
|---|
| 380 | {Chapter 5: Writing a Benchmark}{Writing a Benchmark}
|
|---|
| 381 | */
|
|---|
| 382 |
|
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 | /*! \enum QTest::SkipMode
|
|---|
| 386 |
|
|---|
| 387 | This enum describes the modes for skipping tests during execution
|
|---|
| 388 | of the test data.
|
|---|
| 389 |
|
|---|
| 390 | \value SkipSingle Skips the current entry in the test table; continues
|
|---|
| 391 | execution of all the other entries in the table.
|
|---|
| 392 |
|
|---|
| 393 | \value SkipAll Skips all the entries in the test table; the test won't
|
|---|
| 394 | be executed further.
|
|---|
| 395 |
|
|---|
| 396 | \sa QSKIP()
|
|---|
| 397 | */
|
|---|
| 398 |
|
|---|
| 399 | /*! \enum QTest::TestFailMode
|
|---|
| 400 |
|
|---|
| 401 | This enum describes the modes for handling an expected failure of the
|
|---|
| 402 | \l QVERIFY() or \l QCOMPARE() macros.
|
|---|
| 403 |
|
|---|
| 404 | \value Abort Aborts the execution of the test. Use this mode when it
|
|---|
| 405 | doesn't make sense to execute the test any further after the
|
|---|
| 406 | expected failure.
|
|---|
| 407 |
|
|---|
| 408 | \value Continue Continues execution of the test after the expected failure.
|
|---|
| 409 |
|
|---|
| 410 | \sa QEXPECT_FAIL()
|
|---|
| 411 | */
|
|---|
| 412 |
|
|---|
| 413 | /*! \enum QTest::KeyAction
|
|---|
| 414 |
|
|---|
| 415 | This enum describes possible actions for key handling.
|
|---|
| 416 |
|
|---|
| 417 | \value Press The key is pressed.
|
|---|
| 418 | \value Release The key is released.
|
|---|
| 419 | \value Click The key is clicked (pressed and released).
|
|---|
| 420 | */
|
|---|
| 421 |
|
|---|
| 422 | /*! \enum QTest::MouseAction
|
|---|
| 423 |
|
|---|
| 424 | This enum describes possible actions for mouse handling.
|
|---|
| 425 |
|
|---|
| 426 | \value MousePress A mouse button is pressed.
|
|---|
| 427 | \value MouseRelease A mouse button is released.
|
|---|
| 428 | \value MouseClick A mouse button is clicked (pressed and released).
|
|---|
| 429 | \value MouseDClick A mouse button is double clicked (pressed and released twice).
|
|---|
| 430 | \value MouseMove The mouse pointer has moved.
|
|---|
| 431 | */
|
|---|
| 432 |
|
|---|
| 433 | /*! \fn void QTest::keyClick(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 434 |
|
|---|
| 435 | \overload
|
|---|
| 436 |
|
|---|
| 437 | Simulates clicking of \a key with an optional \a modifier on a \a widget.
|
|---|
| 438 | If \a delay is larger than 0, the test will wait for \a delay milliseconds.
|
|---|
| 439 |
|
|---|
| 440 | Example:
|
|---|
| 441 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 13
|
|---|
| 442 |
|
|---|
| 443 | The example above simulates clicking \c a on \c myWidget without
|
|---|
| 444 | any keyboard modifiers and without delay of the test.
|
|---|
| 445 |
|
|---|
| 446 | \sa QTest::keyClicks()
|
|---|
| 447 | */
|
|---|
| 448 |
|
|---|
| 449 | /*! \fn void QTest::keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 450 |
|
|---|
| 451 | Simulates clicking of \a key with an optional \a modifier on a \a widget.
|
|---|
| 452 | If \a delay is larger than 0, the test will wait for \a delay milliseconds.
|
|---|
| 453 |
|
|---|
| 454 | Examples:
|
|---|
| 455 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 14
|
|---|
| 456 |
|
|---|
| 457 | The first example above simulates clicking the \c escape key on \c
|
|---|
| 458 | myWidget without any keyboard modifiers and without delay. The
|
|---|
| 459 | second example simulates clicking \c shift-escape on \c myWidget
|
|---|
| 460 | with a following 200 ms delay of the test.
|
|---|
| 461 |
|
|---|
| 462 | \sa QTest::keyClicks()
|
|---|
| 463 | */
|
|---|
| 464 |
|
|---|
| 465 | /*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 466 |
|
|---|
| 467 | Sends a Qt key event to \a widget with the given \a key and an associated \a action.
|
|---|
| 468 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay
|
|---|
| 469 | (in milliseconds) of the test before sending the event.
|
|---|
| 470 | */
|
|---|
| 471 |
|
|---|
| 472 | /*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 473 |
|
|---|
| 474 | \overload
|
|---|
| 475 |
|
|---|
| 476 | Sends a Qt key event to \a widget with the given key \a ascii and an associated \a action.
|
|---|
| 477 | Optionally, a keyboard \a modifier can be specified, as well as a \a delay
|
|---|
| 478 | (in milliseconds) of the test before sending the event.
|
|---|
| 479 |
|
|---|
| 480 | */
|
|---|
| 481 |
|
|---|
| 482 | /*! \fn void QTest::keyPress(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 483 |
|
|---|
| 484 | Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay
|
|---|
| 485 | is larger than 0, the test will wait for \a delay milliseconds.
|
|---|
| 486 |
|
|---|
| 487 | \bold {Note:} At some point you should release the key using \l keyRelease().
|
|---|
| 488 |
|
|---|
| 489 | \sa QTest::keyRelease(), QTest::keyClick()
|
|---|
| 490 | */
|
|---|
| 491 |
|
|---|
| 492 | /*! \fn void QTest::keyPress(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 493 |
|
|---|
| 494 | \overload
|
|---|
| 495 |
|
|---|
| 496 | Simulates pressing a \a key with an optional \a modifier on a \a widget.
|
|---|
| 497 | If \a delay is larger than 0, the test will wait for \a delay milliseconds.
|
|---|
| 498 |
|
|---|
| 499 | \bold {Note:} At some point you should release the key using \l keyRelease().
|
|---|
| 500 |
|
|---|
| 501 | \sa QTest::keyRelease(), QTest::keyClick()
|
|---|
| 502 | */
|
|---|
| 503 |
|
|---|
| 504 | /*! \fn void QTest::keyRelease(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 505 |
|
|---|
| 506 | Simulates releasing a \a key with an optional \a modifier on a \a widget.
|
|---|
| 507 | If \a delay is larger than 0, the test will wait for \a delay milliseconds.
|
|---|
| 508 |
|
|---|
| 509 | \sa QTest::keyPress(), QTest::keyClick()
|
|---|
| 510 | */
|
|---|
| 511 |
|
|---|
| 512 | /*! \fn void QTest::keyRelease(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 513 |
|
|---|
| 514 | \overload
|
|---|
| 515 |
|
|---|
| 516 | Simulates releasing a \a key with an optional \a modifier on a \a widget.
|
|---|
| 517 | If \a delay is larger than 0, the test will wait for \a delay milliseconds.
|
|---|
| 518 |
|
|---|
| 519 | \sa QTest::keyClick()
|
|---|
| 520 | */
|
|---|
| 521 |
|
|---|
| 522 |
|
|---|
| 523 | /*! \fn void QTest::keyClicks(QWidget *widget, const QString &sequence, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
|
|---|
| 524 |
|
|---|
| 525 | Simulates clicking a \a sequence of keys on a \a
|
|---|
| 526 | widget. Optionally, a keyboard \a modifier can be specified as
|
|---|
| 527 | well as a \a delay (in milliseconds) of the test before each key
|
|---|
| 528 | click.
|
|---|
| 529 |
|
|---|
| 530 | Example:
|
|---|
| 531 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 15
|
|---|
| 532 |
|
|---|
| 533 | The example above simulates clicking the sequence of keys
|
|---|
| 534 | representing "hello world" on \c myWidget without any keyboard
|
|---|
| 535 | modifiers and without delay of the test.
|
|---|
| 536 |
|
|---|
| 537 | \sa QTest::keyClick()
|
|---|
| 538 | */
|
|---|
| 539 |
|
|---|
| 540 | /*! \fn void QTest::mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1)
|
|---|
| 541 |
|
|---|
| 542 | Simulates pressing a mouse \a button with an optional \a modifier
|
|---|
| 543 | on a \a widget. The position is defined by \a pos; the default
|
|---|
| 544 | position is the center of the widget. If \a delay is specified,
|
|---|
| 545 | the test will wait for the specified amount of milliseconds before
|
|---|
| 546 | the press.
|
|---|
| 547 |
|
|---|
| 548 | \sa QTest::mouseRelease(), QTest::mouseClick()
|
|---|
| 549 | */
|
|---|
| 550 |
|
|---|
| 551 | /*! \fn void QTest::mouseRelease(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1)
|
|---|
| 552 |
|
|---|
| 553 | Simulates releasing a mouse \a button with an optional \a modifier
|
|---|
| 554 | on a \a widget. The position of the release is defined by \a pos;
|
|---|
| 555 | the default position is the center of the widget. If \a delay is
|
|---|
| 556 | specified, the test will wait for the specified amount of
|
|---|
| 557 | milliseconds before releasing the button.
|
|---|
| 558 |
|
|---|
| 559 | \sa QTest::mousePress(), QTest::mouseClick()
|
|---|
| 560 | */
|
|---|
| 561 |
|
|---|
| 562 | /*! \fn void QTest::mouseClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1)
|
|---|
| 563 |
|
|---|
| 564 | Simulates clicking a mouse \a button with an optional \a modifier
|
|---|
| 565 | on a \a widget. The position of the click is defined by \a pos;
|
|---|
| 566 | the default position is the center of the widget. If \a delay is
|
|---|
| 567 | specified, the test will wait for the specified amount of
|
|---|
| 568 | milliseconds before pressing and before releasing the button.
|
|---|
| 569 |
|
|---|
| 570 | \sa QTest::mousePress(), QTest::mouseRelease()
|
|---|
| 571 | */
|
|---|
| 572 |
|
|---|
| 573 | /*! \fn void QTest::mouseDClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1)
|
|---|
| 574 |
|
|---|
| 575 | Simulates double clicking a mouse \a button with an optional \a
|
|---|
| 576 | modifier on a \a widget. The position of the click is defined by
|
|---|
| 577 | \a pos; the default position is the center of the widget. If \a
|
|---|
| 578 | delay is specified, the test will wait for the specified amount of
|
|---|
| 579 | milliseconds before each press and release.
|
|---|
| 580 |
|
|---|
| 581 | \sa QTest::mouseClick()
|
|---|
| 582 | */
|
|---|
| 583 |
|
|---|
| 584 | /*! \fn void QTest::mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1)
|
|---|
| 585 |
|
|---|
| 586 | Moves the mouse pointer to a \a widget. If \a pos is not
|
|---|
| 587 | specified, the mouse pointer moves to the center of the widget. If
|
|---|
| 588 | a \a delay (in milliseconds) is given, the test will wait before
|
|---|
| 589 | moving the mouse pointer.
|
|---|
| 590 | */
|
|---|
| 591 |
|
|---|
| 592 | /*!
|
|---|
| 593 | \fn char *QTest::toString(const T &value)
|
|---|
| 594 |
|
|---|
| 595 | Returns a textual representation of \a value. This function is used by
|
|---|
| 596 | \l QCOMPARE() to output verbose information in case of a test failure.
|
|---|
| 597 |
|
|---|
| 598 | You can add specializations of this function to your test to enable
|
|---|
| 599 | verbose output.
|
|---|
| 600 |
|
|---|
| 601 | \bold {Note:} The caller of toString() must delete the returned data
|
|---|
| 602 | using \c{delete[]}. Your implementation should return a string
|
|---|
| 603 | created with \c{new[]} or qstrdup().
|
|---|
| 604 |
|
|---|
| 605 | Example:
|
|---|
| 606 |
|
|---|
| 607 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 16
|
|---|
| 608 |
|
|---|
| 609 | The example above defines a toString() specialization for a class
|
|---|
| 610 | called \c MyPoint. Whenever a comparison of two instances of \c
|
|---|
| 611 | MyPoint fails, \l QCOMPARE() will call this function to output the
|
|---|
| 612 | contents of \c MyPoint to the test log.
|
|---|
| 613 |
|
|---|
| 614 | \sa QCOMPARE()
|
|---|
| 615 | */
|
|---|
| 616 |
|
|---|
| 617 | /*!
|
|---|
| 618 | \fn char *QTest::toString(const QLatin1String &string)
|
|---|
| 619 | \overload
|
|---|
| 620 |
|
|---|
| 621 | Returns a textual representation of the given \a string.
|
|---|
| 622 | */
|
|---|
| 623 |
|
|---|
| 624 | /*!
|
|---|
| 625 | \fn char *QTest::toString(const QString &string)
|
|---|
| 626 | \overload
|
|---|
| 627 |
|
|---|
| 628 | Returns a textual representation of the given \a string.
|
|---|
| 629 | */
|
|---|
| 630 |
|
|---|
| 631 | /*!
|
|---|
| 632 | \fn char *QTest::toString(const QByteArray &ba)
|
|---|
| 633 | \overload
|
|---|
| 634 |
|
|---|
| 635 | Returns a textual representation of the byte array \a ba.
|
|---|
| 636 |
|
|---|
| 637 | \sa QTest::toHexRepresentation()
|
|---|
| 638 | */
|
|---|
| 639 |
|
|---|
| 640 | /*!
|
|---|
| 641 | \fn char *QTest::toString(const QTime &time)
|
|---|
| 642 | \overload
|
|---|
| 643 |
|
|---|
| 644 | Returns a textual representation of the given \a time.
|
|---|
| 645 | */
|
|---|
| 646 |
|
|---|
| 647 | /*!
|
|---|
| 648 | \fn char *QTest::toString(const QDate &date)
|
|---|
| 649 | \overload
|
|---|
| 650 |
|
|---|
| 651 | Returns a textual representation of the given \a date.
|
|---|
| 652 | */
|
|---|
| 653 |
|
|---|
| 654 | /*!
|
|---|
| 655 | \fn char *QTest::toString(const QDateTime &dateTime)
|
|---|
| 656 | \overload
|
|---|
| 657 |
|
|---|
| 658 | Returns a textual representation of the date and time specified by
|
|---|
| 659 | \a dateTime.
|
|---|
| 660 | */
|
|---|
| 661 |
|
|---|
| 662 | /*!
|
|---|
| 663 | \fn char *QTest::toString(const QChar &character)
|
|---|
| 664 | \overload
|
|---|
| 665 |
|
|---|
| 666 | Returns a textual representation of the given \a character.
|
|---|
| 667 | */
|
|---|
| 668 |
|
|---|
| 669 | /*!
|
|---|
| 670 | \fn char *QTest::toString(const QPoint &point)
|
|---|
| 671 | \overload
|
|---|
| 672 |
|
|---|
| 673 | Returns a textual representation of the given \a point.
|
|---|
| 674 | */
|
|---|
| 675 |
|
|---|
| 676 | /*!
|
|---|
| 677 | \fn char *QTest::toString(const QSize &size)
|
|---|
| 678 | \overload
|
|---|
| 679 |
|
|---|
| 680 | Returns a textual representation of the given \a size.
|
|---|
| 681 | */
|
|---|
| 682 |
|
|---|
| 683 | /*!
|
|---|
| 684 | \fn char *QTest::toString(const QRect &rectangle)
|
|---|
| 685 | \overload
|
|---|
| 686 |
|
|---|
| 687 | Returns a textual representation of the given \a rectangle.
|
|---|
| 688 | */
|
|---|
| 689 |
|
|---|
| 690 | /*!
|
|---|
| 691 | \fn char *QTest::toString(const QUrl &url)
|
|---|
| 692 | \since 4.4
|
|---|
| 693 | \overload
|
|---|
| 694 |
|
|---|
| 695 | Returns a textual representation of the given \a url.
|
|---|
| 696 | */
|
|---|
| 697 |
|
|---|
| 698 | /*!
|
|---|
| 699 | \fn char *QTest::toString(const QPointF &point)
|
|---|
| 700 | \overload
|
|---|
| 701 |
|
|---|
| 702 | Returns a textual representation of the given \a point.
|
|---|
| 703 | */
|
|---|
| 704 |
|
|---|
| 705 | /*!
|
|---|
| 706 | \fn char *QTest::toString(const QSizeF &size)
|
|---|
| 707 | \overload
|
|---|
| 708 |
|
|---|
| 709 | Returns a textual representation of the given \a size.
|
|---|
| 710 | */
|
|---|
| 711 |
|
|---|
| 712 | /*!
|
|---|
| 713 | \fn char *QTest::toString(const QRectF &rectangle)
|
|---|
| 714 | \overload
|
|---|
| 715 |
|
|---|
| 716 | Returns a textual representation of the given \a rectangle.
|
|---|
| 717 | */
|
|---|
| 718 |
|
|---|
| 719 | /*!
|
|---|
| 720 | \fn char *QTest::toString(const QVariant &variant)
|
|---|
| 721 | \overload
|
|---|
| 722 |
|
|---|
| 723 | Returns a textual representation of the given \a variant.
|
|---|
| 724 | */
|
|---|
| 725 |
|
|---|
| 726 | /*! \fn void QTest::qWait(int ms)
|
|---|
| 727 |
|
|---|
| 728 | Waits for \a ms milliseconds. While waiting, events will be processed and
|
|---|
| 729 | your test will stay responsive to user interface events or network communication.
|
|---|
| 730 |
|
|---|
| 731 | Example:
|
|---|
| 732 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 17
|
|---|
| 733 |
|
|---|
| 734 | The code above will wait until the network server is responding for a
|
|---|
| 735 | maximum of about 12.5 seconds.
|
|---|
| 736 |
|
|---|
| 737 | \sa QTest::qSleep()
|
|---|
| 738 | */
|
|---|
| 739 |
|
|---|
| 740 | /*! \fn bool QTest::qWaitForWindowShown(QWidget *window)
|
|---|
| 741 | \since 4.6
|
|---|
| 742 |
|
|---|
| 743 | Waits until the \a window is shown in the screen. This is mainly useful for
|
|---|
| 744 | asynchronous systems like X11, where a window will be mapped to screen some
|
|---|
| 745 | time after being asked to show itself on the screen. Returns true.
|
|---|
| 746 |
|
|---|
| 747 | Example:
|
|---|
| 748 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 24
|
|---|
| 749 | */
|
|---|
| 750 |
|
|---|
| 751 | /*!
|
|---|
| 752 | \class QTest::QTouchEventSequence
|
|---|
| 753 | \inmodule QtTest
|
|---|
| 754 | \since 4.6
|
|---|
| 755 |
|
|---|
| 756 | \brief The QTouchEventSequence class is used to simulate a sequence of touch events.
|
|---|
| 757 |
|
|---|
| 758 | To simulate a sequence of touch events on a specific device for a widget, call
|
|---|
| 759 | QTest::touchEvent to create a QTouchEventSequence instance. Add touch events to
|
|---|
| 760 | the sequence by calling press(), move(), release() and stationary(), and let the
|
|---|
| 761 | instance run out of scope to commit the sequence to the event system.
|
|---|
| 762 |
|
|---|
| 763 | Example:
|
|---|
| 764 | \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 25
|
|---|
| 765 | */
|
|---|
| 766 |
|
|---|
| 767 | /*!
|
|---|
| 768 | \fn QTest::QTouchEventSequence::~QTouchEventSequence()
|
|---|
|
|---|