qtestcase.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,706 行 · 第 1/4 页
CPP
1,706 行
/*! \fn void QTest::qSkip(const char *message, SkipMode mode, const char *file, int line)\internal */void QTest::qSkip(const char *message, QTest::SkipMode mode, const char *file, int line){ QTestResult::addSkip(message, mode, file, line); if (mode == QTest::SkipAll) QTestResult::setSkipCurrentTest(true);}/*! \fn bool QTest::qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line)\internal */bool QTest::qExpectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line){ return QTestResult::expectFail(dataIndex, qstrdup(comment), mode, file, line);}/*! \internal */void QTest::qWarn(const char *message){ QTestLog::warn(message);}/*! Ignores messages created by qDebug() or qWarning(). If the \a message with the corresponding \a type is outputted, it will be removed from the test log. If the test finished and the \a message was not outputted, a test failure is appended to the test log. \bold {Note:} Invoking this function will only ignore one message. If the message you want to ignore is outputted twice, you have to call ignoreMessage() twice, too. Example: \code QDir dir; QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)"); dir.mkdir(""); \endcode The example above tests that QDir::mkdir() outputs the right warning when invoked with an invalid file name.*/void QTest::ignoreMessage(QtMsgType type, const char *message){ QTestResult::ignoreMessage(type, message);}/*! \internal */void *QTest::qData(const char *tagName, int typeId){ return fetchData(QTestResult::currentTestData(), tagName, typeId);}/*! \internal */void *QTest::qGlobalData(const char *tagName, int typeId){ return fetchData(QTestResult::currentGlobalTestData(), tagName, typeId);}/*! \internal */void *QTest::qElementData(const char *tagName, int metaTypeId){ QTEST_ASSERT(tagName); QTestData *data = QTestResult::currentTestData(); QTEST_ASSERT(data); QTEST_ASSERT(data->parent()); int idx = data->parent()->indexOf(tagName); QTEST_ASSERT(idx != -1); QTEST_ASSERT(data->parent()->elementTypeId(idx) == metaTypeId); return data->data(data->parent()->indexOf(tagName));}/*! \internal */void QTest::addColumnInternal(int id, const char *name){ QTestTable *tbl = QTestTable::currentTestTable(); QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot."); tbl->addColumn(id, name);}/*! Appends a new row to the current test data. \a dataTag is the name of the testdata that will appear in the test output. Returns a QTestData reference that can be used to stream in data. Example: \code void myTestFunction_data() { QTest::addColumn<QString>("aString"); QTest::newRow("just hello") << QString("hello"); QTest::newRow("a null string") << QString(); } \endcode \bold {Note:} This macro can only be used in a test's data function that is invoked by the test framework. See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for a more extensive example. \sa addColumn(), QFETCH()*/QTestData &QTest::newRow(const char *dataTag){ QTestTable *tbl = QTestTable::currentTestTable(); QTEST_ASSERT_X(tbl, "QTest::addColumn()", "Cannot add testdata outside of a _data slot."); return *tbl->newData(dataTag);}/*! \fn void QTest::addColumn(const char *name, T *dummy = 0) Adds a column with type \c{T} to the current test data. \a name is the name of the column. \a dummy is a workaround for buggy compilers and can be ignored. To populate the column with values, newRow() can be used. Use \l QFETCH() to fetch the data in the actual test. Example: \code void myTestFunction_data() { QTest::addColumn<int>("intval"); QTest::addColumn<QString>("str"); QTest::addColumn<double>("dbl"); QTest::newRow("row1") << 1 << "hello" << 1.5; } \endcode To add custom types to the testdata, the type must be registered with QMetaType via \l Q_DECLARE_METATYPE(). \bold {Note:} This macro can only be used in a test's data function that is invoked by the test framework. See \l {Chapter 2: Data Driven Testing}{Data Driven Testing} for a more extensive example. \sa QTest::newRow(), QFETCH(), QMetaType*//*! Returns the name of the test function that is currently executed. Example: \code void MyTestClass::cleanup() { if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) { // clean up all database connections closeAllDatabases(); } } \endcode*/const char *QTest::currentTestFunction(){ return QTestResult::currentTestFunction();}/*! Returns the name of the current test data. If the test doesn't have any assigned testdata, the function returns 0.*/const char *QTest::currentDataTag(){ return QTestResult::currentDataTag();}/*! Returns true if the current test function failed, otherwise false.*/bool QTest::currentTestFailed(){ return QTestResult::currentTestFailed();}/*! Sleeps for \a ms milliseconds, blocking execution of the test. qSleep() will not do any event processing and leave your test unresponsive. Network communication might time out while sleeping. Use \l qWait() to do non-blocking sleeping. \a ms must be greater than 0. \bold {Note:} The qSleep() function calls either \c nanosleep() on unix or \c Sleep() on windows, so the accuracy of time spent in qSleep() depends on the operating system. Example: \code QTest::qSleep(250); \endcode \sa qWait()*/void QTest::qSleep(int ms){ QTEST_ASSERT(ms > 0);#ifdef Q_OS_WIN Sleep(uint(ms));#else struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; nanosleep(&ts, NULL);#endif}/*! \internal */QObject *QTest::testObject(){ return currentTestObject;}/*! \internal */bool QTest::compare_helper(bool success, const char *msg, const char *file, int line){ return QTestResult::compare(success, msg, file, line);}/*! \internal */bool QTest::compare_helper(bool success, const char *msg, char *val1, char *val2, const char *actual, const char *expected, const char *file, int line){ return QTestResult::compare(success, msg, val1, val2, actual, expected, file, line);}/*! \fn bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line)\internal */template <>bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected, const char *file, int line){ return (qAbs(t1 - t2) < 0.00001f) ? compare_helper(true, "COMPARE()", file, line) : compare_helper(false, "Compared floats are not the same (fuzzy compare)", toString(t1), toString(t2), actual, expected, file, line);}/*! \fn bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line)\internal */template <>bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected, const char *file, int line){ return (qAbs(t1 - t2) < 0.000000000001) ? compare_helper(true, "COMPARE()", file, line) : compare_helper(false, "Compared doubles are not the same (fuzzy compare)", toString(t1), toString(t2), actual, expected, file, line);}#define COMPARE_IMPL2(TYPE, FORMAT) \template <> char *QTest::toString<TYPE >(const TYPE &t) \{ \ char *msg = new char[128]; \ qt_snprintf(msg, 128, #FORMAT, t); \ return msg; \}COMPARE_IMPL2(short, %hd)COMPARE_IMPL2(ushort, %hu)COMPARE_IMPL2(int, %d)COMPARE_IMPL2(uint, %u)COMPARE_IMPL2(long, %ld)COMPARE_IMPL2(ulong, %lu)#if defined(Q_OS_WIN)COMPARE_IMPL2(qint64, %I64d)COMPARE_IMPL2(quint64, %I64u)#elseCOMPARE_IMPL2(qint64, %lld)COMPARE_IMPL2(quint64, %llu)#endifCOMPARE_IMPL2(bool, %d)COMPARE_IMPL2(char, %c)COMPARE_IMPL2(float, %g);COMPARE_IMPL2(double, %lg);/*! \internal */char *QTest::toString(const char *str){ if (!str) return 0; char *msg = new char[strlen(str) + 1]; return qstrcpy(msg, str);}/*! \internal */char *QTest::toString(const void *p){ char *msg = new char[128]; qt_snprintf(msg, 128, "%p", p); return msg;}/*! \internal */bool QTest::compare_string_helper(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line){ return (qstrcmp(t1, t2) == 0) ? compare_helper(true, "COMPARE()", file, line) : compare_helper(false, "Compared strings are not the same", toString(t1), toString(t2), actual, expected, file, line);}/*! \fn bool QTest::compare_ptr_helper(const void *t1, const void *t2, const char *actual, const char *expected, const char *file, int line); \internal*//*! \fn bool QTest::qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int); \internal*//*! \fn void QTest::mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1) \internal*//*! \fn bool QTest::qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(QPixmap const &t1, QPixmap const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(T const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(const T *t1, const T *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(T *t1, T *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(const T1 *t1, const T2 *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(T1 *t1, T2 *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(const char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(char *t1, const char *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(const char *t1, char *t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(QString const &t1, QLatin1String const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(QLatin1String const &t1, QString const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(QStringList const &t1, QStringList const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(QFlags<T> const &t1, T const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qCompare(QFlags<T> const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line) \internal*//*! \fn bool QTest::qTest(const T& actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line) \internal*//*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, QString text, Qt::KeyboardModifiers modifier, int delay=-1) \internal*//*! \fn void QTest::sendKeyEvent(KeyAction action, QWidget *widget, Qt::Key code, char ascii, Qt::KeyboardModifiers modifier, int delay=-1) \internal*//*! \fn void QTest::simulateEvent(QWidget *widget, bool press, int code, Qt::KeyboardModifiers modifier, QString text, bool repeat, int delay=-1) \internal*//*! \fn int QTest::qt_snprintf(char *str, int size, const char *format, ...) \internal*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?