⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtestcase.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    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)COMPARE_IMPL2(qint64, %lld)COMPARE_IMPL2(quint64, %llu)COMPARE_IMPL2(bool, %d)COMPARE_IMPL2(char, %c)COMPARE_IMPL2(float, %f);COMPARE_IMPL2(double, %lf);/*! \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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -