📄 qtestcase.cpp
字号:
any keyboard modifiers and without delay of the test. \sa QTest::keyClicks()*//*! \fn void QTest::keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) Simulates clicking of \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds. Examples: \code QTest::keyClick(myWidget, Qt::Key_Escape); QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200); \endcode The first example above simulates clicking the \c escape key on \c myWidget without any keyboard modifiers and without delay. The second example simulates clicking \c shift-escape on \c myWidget with a following 200 ms delay of the test. \sa QTest::keyClicks()*//*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) Sends a Qt key event to \a widget with the given \a key and an associated \a action. Optionally, a keyboard \a modifier can be specified, as well as a \a delay (in milliseconds) of the test before sending the event.*//*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, char ascii, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) \overload Sends a Qt key event to \a widget with the given key \a ascii and an associated \a action. Optionally, a keyboard \a modifier can be specified, as well as a \a delay (in milliseconds) of the test before sending the event.*//*! \fn void QTest::keyPress(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds. \bold {Note:} At some point you should release the key using \l keyRelease(). \sa QTest::keyRelease(), QTest::keyClick()*//*! \fn void QTest::keyPress(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) \overload Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds. \bold {Note:} At some point you should release the key using \l keyRelease(). \sa QTest::keyRelease(), QTest::keyClick()*//*! \fn void QTest::keyRelease(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) Simulates releasing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds. \sa QTest::keyPress(), QTest::keyClick()*//*! \fn void QTest::keyRelease(QWidget *widget, char key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) \overload Simulates releasing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds. \sa QTest::keyClick()*//*! \fn void QTest::keyClicks(QWidget *widget, const QString &sequence, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1) Simulates clicking a \a sequence of keys on a \a widget. Optionally, a keyboard \a modifier can be specified as well as a \a delay (in milliseconds) of the test before each key click. Example: \code QTest::keyClicks(myWidget, "hello world"); \endcode The example above simulates clicking the sequence of keys representing "hello world" on \c myWidget without any keyboard modifiers and without delay of the test. \sa QTest::keyClick()*//*! \fn void QTest::mousePress(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) Simulates pressing a mouse \a button with an optional \a modifier on a \a widget. The position is defined by \a pos; the default position is the center of the widget. If \a delay is specified, the test will wait for the specified amount of milliseconds before the press. \sa QTest::mouseRelease(), QTest::mouseClick()*//*! \fn void QTest::mouseRelease(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) Simulates releasing a mouse \a button with an optional \a modifier on a \a widget. The position of the release is defined by \a pos; the default position is the center of the widget. If \a delay is specified, the test will wait for the specified amount of milliseconds before releasing the button. \sa QTest::mousePress(), QTest::mouseClick()*//*! \fn void QTest::mouseClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) Simulates clicking a mouse \a button with an optional \a modifier on a \a widget. The position of the click is defined by \a pos; the default position is the center of the widget. If \a delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button. \sa QTest::mousePress(), QTest::mouseRelease()*//*! \fn void QTest::mouseDClick(QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay=-1) Simulates double clicking a mouse \a button with an optional \a modifier on a \a widget. The position of the click is defined by \a pos; the default position is the center of the widget. If \a delay is specified, the test will wait for the specified amount of milliseconds before each press and release. \sa QTest::mouseClick()*//*! \fn void QTest::mouseMove(QWidget *widget, QPoint pos = QPoint(), int delay=-1) Moves the mouse pointer to a \a widget. If \a pos is not specified, the mouse pointer moves to the center of the widget. If a \a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.*//*! \fn char *QTest::toString(const T &value) Returns a textual representation of \a value. This function is used by \l QCOMPARE() to output verbose information in case of a test failure. You can add specializations of this function to your test to enable verbose output. \bold {Note:} The caller of toString() must delete the returned data using \c{delete[]}. Your implementation should return a string created with \c{new[]} or qstrdup(). Example: \code namespace QTest { template<> char *toString(const MyPoint &point) { QByteArray ba = "MyPoint("; ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y()); ba += ")"; return qstrdup(ba.data()); } } \endcode The example above defines a toString() specialization for a class called \c MyPoint. Whenever a comparison of two instances of \c MyPoint fails, \l QCOMPARE() will call this function to output the contents of \c MyPoint to the test log. \sa QCOMPARE()*//*! \fn char *QTest::toString(const QLatin1String &string) \overload Returns a textual representation of the given \a string. This function is used by \l QCOMPARE() to output verbose information in case of a test failure.*//*! \fn char *QTest::toString(const QString &string) \overload Returns a textual representation of the given \a string. This function is used by \l QCOMPARE() to output verbose information in case of a test failure.*//*! \fn char *QTest::toString(const QTime &time) \overload Returns a textual representation of the given \a time. This function is used by \l QCOMPARE() to output verbose information in case of a test failure.*//*! \fn char *QTest::toString(const QDate &date) \overload Returns a textual representation of the given \a date. This function is used by \l QCOMPARE() to output verbose information in case of a test failure.*//*! \fn char *QTest::toString(const QDateTime &dateTime) \overload Returns a textual representation of the date and time specified by \a dateTime. This function is used by \l QCOMPARE() to output verbose information in case of a test failure.*//*! \fn char *QTest::toString(const QChar &character) \overload Returns a textual representation of the given \a character. This function is used by \l QCOMPARE() to output verbose information in case of a test failure.*//*! \fn void QTest::qWait(int ms) Waits for \a ms milliseconds. While waiting, events will be processed and your test will stay responsive to user interface events or network communication. Example: \code int i = 0; while (myNetworkServerNotResponding() && i++ < 50) QTest::qWait(250); \endcode The code above will wait until the network server is responding for a maximum of about 12.5 seconds. \sa QTest::qSleep()*/namespace QTest{ static bool skipCurrentTest = false; static QObject *currentTestObject = 0; struct TestFunction { TestFunction():function(0), data(0) {} ~TestFunction() { delete [] data; } int function; char *data; } testFuncs[512]; static int lastTestFuncIdx = -1; static int keyDelay = -1; static int mouseDelay = -1; static int eventDelay = -1; static int keyVerbose = -1;/*! \internal */int qt_snprintf(char *str, int size, const char *format, ...){ va_list ap; int res = 0; va_start(ap, format); ::qvsnprintf(str, size, format, ap); va_end(ap); str[size - 1] = '\0'; char *idx = str; while (*idx) { if (((*idx < 0x20 && *idx != '\n' && *idx != '\t') || *idx > 0x7e)) *idx = '?'; ++idx; } return res;}bool Q_TESTLIB_EXPORT defaultKeyVerbose(){ if (keyVerbose == -1) { keyVerbose = ::qgetenv("QTEST_KEYEVENT_VERBOSE").constData() ? 1 : 0; } return keyVerbose == 1;}int defaultEventDelay(){ if (eventDelay == -1) { if (qgetenv("QTEST_EVENT_DELAY").constData()) eventDelay = atoi(::qgetenv("QTEST_EVENT_DELAY")); else eventDelay = 0; } return eventDelay;}int Q_TESTLIB_EXPORT defaultMouseDelay(){ if (mouseDelay == -1) { if (::qgetenv("QTEST_MOUSEEVENT_DELAY").constData()) mouseDelay = atoi((::qgetenv("QTEST_MOUSEEVENT_DELAY"))); else mouseDelay = defaultEventDelay(); } return mouseDelay;}int Q_TESTLIB_EXPORT defaultKeyDelay(){ if (keyDelay == -1) { if (::qgetenv("QTEST_KEYEVENT_DELAY").constData()) keyDelay = atoi(qgetenv("QTEST_KEYEVENT_DELAY").constData()); else keyDelay = defaultEventDelay(); } return keyDelay;}static bool isValidSlot(const QMetaMethod &sl){ if (sl.access() != QMetaMethod::Private || !sl.parameterTypes().isEmpty() || qstrlen(sl.typeName()) || sl.methodType() != QMetaMethod::Slot) return false; const char *sig = sl.signature(); int len = qstrlen(sig); if (len < 2) return false; if (sig[len - 2] != '(' || sig[len - 1] != ')') return false; if (len > 7 && strcmp(sig + (len - 7), "_data()") == 0) return false; if (strcmp(sig, "initTestCase()") == 0 || strcmp(sig, "cleanupTestCase()") == 0 || strcmp(sig, "cleanup()") == 0 || strcmp(sig, "init()") == 0) return false; return true;}static void qPrintTestSlots(){ for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); if (isValidSlot(sl)) printf("%s\n", sl.signature()); }}static int qToInt(char *str){ char *pEnd; int l = (int)strtol(str, &pEnd, 10); if (*pEnd != 0) { printf("Invalid numeric parameter: '%s'\n", str); exit(1); } return l;}static void qParseArgs(int argc, char *argv[]){ const char *testOptions = " options:\n" " -functions : Returns a list of current testfunctions\n" " -xml : Outputs results as XML document\n" " -lightxml : Outputs results as stream of XML tags\n" " -o filename: Writes all output into a file\n" " -v1 : Print enter messages for each testfunction\n" " -v2 : Also print out each QVERIFY/QCOMPARE/QTEST\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -