IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QTest Namespace

The https:// namespace contains all the functions and declarations that are related to Qt Test.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QTest Namespace▲

  • Header: QTest

  • qmake: QT += testlib

Detailed Description▲

See the https:// for information about how to write unit tests.

Classes▲

 

class QTouchEventSequence▲

The https:// class is used to simulate a sequence of touch events.

Type Documentation▲

 

enum QTest::KeyAction▲

This enum describes possible actions for key handling.

Constant

Value

Description

https://::Press

0

The key is pressed.

https://::Release

1

The key is released.

https://::Click

2

The key is clicked (pressed and released).

https://::Shortcut

3

A shortcut is activated. This value has been added in Qt 5.6.

enum QTest::MouseAction▲

This enum describes possible actions for mouse handling.

Constant

Value

Description

https://::MousePress

0

A mouse button is pressed.

https://::MouseRelease

1

A mouse button is released.

https://::MouseClick

2

A mouse button is clicked (pressed and released).

https://::MouseDClick

3

A mouse button is double clicked (pressed and released twice).

https://::MouseMove

4

The mouse pointer has moved.

Function Documentation▲

 

void QTest::addColumn(const char *name, T *dummy = 0)▲

Adds a column with type T to the current test data. name is the name of the column. dummy is a workaround for buggy compilers and can be ignored.

To populate the column with values, newRow() can be used. Use https://() to fetch the data in the actual test.

Example:

 
Sélectionnez
void myTestFunction_data() {
    QTest::addColumn<int>("intval");
    QTest::addColumn<QString>("str");
    QTest::addColumn<double>("dbl");

    QTest::newRow("row1") << 1 << "hello" << 1.5;
}

To add custom types to the testdata, the type must be registered with https:// via https://().

Note: This macro can only be used in a test's data function that is invoked by the test framework.

See https:// for a more extensive example.

See Also▲

See also QTest::newRow(), https://(), https://

void QTest::keyClick(int *widget, int key, int modifier = ..., int delay = -1)▲

Simulates clicking of key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key.

Examples:

 
Sélectionnez
QTest::keyClick(myWidget, Qt::Key_Escape);

QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);

The first example above simulates clicking the escape key on myWidget without any keyboard modifiers and without delay. The second example simulates clicking shift-escape on myWidget following a 200 ms delay of the test.

See Also▲

See also https://()

[since 5.0] int QTest::keyClick(QWindow *window, int key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates clicking of key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key.

Examples:

 
Sélectionnez
QTest::keyClick(myWindow, Qt::Key_Escape);

QTest::keyClick(myWindow, Qt::Key_Escape, Qt::ShiftModifier, 200);

The first example above simulates clicking the escape key on myWindow without any keyboard modifiers and without delay. The second example simulates clicking shift-escape on myWindow following a 200 ms delay of the test.

This function was introduced in Qt 5.0.

See Also▲

See also https://()

[since 5.0] int QTest::keyClick(QWindow *window, char key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates clicking of key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key.

Example:

 
Sélectionnez
QTest::keyClick(myWindow, 'a');

The example above simulates clicking a on myWindow without any keyboard modifiers and without delay of the test.

This function was introduced in Qt 5.0.

See Also▲

See also https://()

void QTest::keyClick(int *widget, char key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates clicking of key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before clicking the key.

Example:

 
Sélectionnez
QTest::keyClick(myWidget, 'a');

The example above simulates clicking a on myWidget without any keyboard modifiers and without delay of the test.

See Also▲

See also https://()

void QTest::keyClicks(int *widget, const int &sequence, int modifier = ..., int delay = -1)▲

Simulates clicking a sequence of keys on a widget. Optionally, a keyboard modifier can be specified as well as a delay (in milliseconds) of the test before each key click.

Example:

 
Sélectionnez
QTest::keyClicks(myWidget, "hello world");

The example above simulates clicking the sequence of keys representing "hello world" on myWidget without any keyboard modifiers and without delay of the test.

See Also▲

See also https://()

void QTest::keyEvent(QTest::KeyAction action, int *widget, int key, int modifier = ..., int delay = -1)▲

Sends a Qt key event to widget with the given key and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event.

[since 5.0] void QTest::keyEvent(QTest::KeyAction action, QWindow *window, char ascii, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Sends a Qt key event to window with the given key ascii and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event.

This function was introduced in Qt 5.0.

[since 5.0] void QTest::keyEvent(QTest::KeyAction action, QWindow *window, int key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Sends a Qt key event to window with the given key and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event.

This function was introduced in Qt 5.0.

void QTest::keyEvent(QTest::KeyAction action, int *widget, char ascii, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Sends a Qt key event to widget with the given key ascii and an associated action. Optionally, a keyboard modifier can be specified, as well as a delay (in milliseconds) of the test before sending the event.

void QTest::keyPress(int *widget, int key, int modifier = ..., int delay = -1)▲

Simulates pressing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key.

Note: At some point you should release the key using https://().

See Also▲

See also https://(), https://()

[since 5.0] int QTest::keyPress(QWindow *window, char key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates pressing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key.

Note: At some point you should release the key using https://().

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

[since 5.0] int QTest::keyPress(QWindow *window, int key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates pressing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key.

Note: At some point you should release the key using https://().

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

void QTest::keyPress(int *widget, char key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates pressing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before pressing the key.

Note: At some point you should release the key using https://().

See Also▲

See also https://(), https://()

void QTest::keyRelease(int *widget, int key, int modifier = ..., int delay = -1)▲

Simulates releasing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key.

See Also▲

See also https://(), https://()

[since 5.0] int QTest::keyRelease(QWindow *window, char key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates releasing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key.

This function was introduced in Qt 5.0.

See Also▲

See also https://()

[since 5.0] int QTest::keyRelease(QWindow *window, int key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates releasing a key with an optional modifier on a window. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

void QTest::keyRelease(int *widget, char key, int modifier = ..., int delay = -1)▲

This is an overloaded function.

Simulates releasing a key with an optional modifier on a widget. If delay is larger than 0, the test will wait for delay milliseconds before releasing the key.

See Also▲

See also https://()

void QTest::mouseClick(int *widget, int button, int modifier = 0, int pos = QPoint(), int delay = -1)▲

Simulates clicking a mouse button with an optional modifier on a widget. The position of the click is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button.

See Also▲

See also https://(), https://()

[since 5.0] void QTest::mouseClick(QWindow *window, int button, int stateKey = 0, int pos = QPoint(), int delay = -1)▲

This is an overloaded function.

Simulates clicking a mouse button with an optional stateKey modifier on a window. The position of the click is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before pressing and before releasing the button.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

void QTest::mouseDClick(int *widget, int button, int modifier = 0, int pos = QPoint(), int delay = -1)▲

Simulates double clicking a mouse button with an optional modifier on a widget. The position of the click is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before each press and release.

See Also▲

See also https://()

[since 5.0] void QTest::mouseDClick(QWindow *window, int button, int stateKey = 0, int pos = QPoint(), int delay = -1)▲

This is an overloaded function.

Simulates double clicking a mouse button with an optional stateKey modifier on a window. The position of the click is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before each press and release.

This function was introduced in Qt 5.0.

See Also▲

See also https://()

void QTest::mouseMove(int *widget, int pos = QPoint(), int delay = -1)▲

Moves the mouse pointer to a widget. If pos is not specified, the mouse pointer moves to the center of the widget. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.

[since 5.0] void QTest::mouseMove(QWindow *window, int pos = QPoint(), int delay = -1)▲

This is an overloaded function.

Moves the mouse pointer to a window. If pos is not specified, the mouse pointer moves to the center of the window. If a delay (in milliseconds) is given, the test will wait before moving the mouse pointer.

This function was introduced in Qt 5.0.

void QTest::mousePress(int *widget, int button, int modifier = 0, int pos = QPoint(), int delay = -1)▲

Simulates pressing a mouse button with an optional modifier on a widget. The position is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before the press.

See Also▲

See also https://(), https://()

[since 5.0] void QTest::mousePress(QWindow *window, int button, int stateKey = 0, int pos = QPoint(), int delay = -1)▲

This is an overloaded function.

Simulates pressing a mouse button with an optional stateKey modifier on a window. The position is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before the press.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

void QTest::mouseRelease(int *widget, int button, int modifier = 0, int pos = QPoint(), int delay = -1)▲

Simulates releasing a mouse button with an optional modifier on a widget. The position of the release is defined by pos; the default position is the center of the widget. If delay is specified, the test will wait for the specified amount of milliseconds before releasing the button.

See Also▲

See also https://(), https://()

[since 5.0] void QTest::mouseRelease(QWindow *window, int button, int stateKey = 0, int pos = QPoint(), int delay = -1)▲

This is an overloaded function.

Simulates releasing a mouse button with an optional stateKey modifier on a window. The position of the release is defined by pos; the default position is the center of the window. If delay is specified, the test will wait for the specified amount of milliseconds before releasing the button.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), https://()

[since 5.0] bool QTest::qWaitForWindowActive(QWindow *window, int timeout = 5000)▲

Waits for timeout milliseconds or until the window is active.

Returns true if window is active within timeout milliseconds, otherwise returns false.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), QWindow::isActive()

[since 5.0] bool QTest::qWaitForWindowExposed(QWindow *window, int timeout = 5000)▲

Waits for timeout milliseconds or until the window is exposed. Returns true if window is exposed within timeout milliseconds, otherwise returns false.

This is mainly useful for asynchronous systems like X11, where a window will be mapped to screen some time after being asked to show itself on the screen.

Note that a window that is mapped to screen may still not be considered exposed if the window client area is completely covered by other windows, or if the window is otherwise not visible. This function will then time out when waiting for such a window.

This function was introduced in Qt 5.0.

See Also▲

See also https://(), QWindow::isExposed()

int *QTest::toHexRepresentation(const char *ba, int length)▲

Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex characters. If the input is considered too long, it is truncated. A trucation is indicated in the returned string as an ellipsis at the end. The caller has ownership of the returned pointer and must ensure it is later passed to operator delete[].

length is the length of the string ba.

[since 5.5] char *QTest::toString(int sp)▲

This is an overloaded function.

Returns a textual representation of size policy sp.

This function was introduced in Qt 5.5.

[since 4.4] char *QTest::toString(const int &variant)▲

This is an overloaded function.

Returns a textual representation of the given variant.

This function was introduced in Qt 4.4.

[since 5.12] char *QTest::toString(const std::tuple<Types...> &tuple)▲

This is an overloaded function.

Returns a textual representation of the given tuple.

This function was introduced in Qt 5.12.

char *QTest::toString(const T &value)▲

Returns a textual representation of value. This function is used by https://() to output verbose information in case of a test failure.

You can add specializations or overloads of this function to your test to enable verbose output.

Note: Starting with Qt 5.5, you should prefer to provide a https://() function in the type's namespace instead of specializing this template. If your code needs to continue to work with the QTestLib from Qt 5.4 or earlier, you need to continue to use specialization.

Note: The caller of https://() must delete the returned data using delete[]. Your implementation should return a string created with new[] or https://(). The easiest way to do so is to create a QByteArray or QString and calling https://() on it (see second example below).

Example for specializing (Qt ≤ 5.4):

 
Sélectionnez
namespace QTest {
    template&lt;&gt;
    char *toString(const MyPoint &amp;point)
    {
        QByteArray ba = "MyPoint(";
        ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
        ba += ')';
        return qstrdup(ba.data());
    }
}

The example above defines a https://() specialization for a class called MyPoint. Whenever a comparison of two instances of MyPoint fails, https://() will call this function to output the contents of MyPoint to the test log.

Same example, but with overloading (Qt ≥ 5.5):

 
Sélectionnez
namespace MyNamespace {
    char *toString(const MyPoint &amp;point)
    {
        // bring QTest::toString overloads into scope:
        using QTest::toString;
        // delegate char* handling to QTest::toString(QByteArray):
        return toString("MyPoint(" +
                        QByteArray::number(point.x()) + ", " +
                        QByteArray::number(point.y()) + ')');
    }
}
See Also▲

See also https://()

Macro Documentation▲

 

QBENCHMARK▲

This macro is used to measure the performance of code within a test. The code to be benchmarked is contained within a code block following this macro.

For example:

 
Sélectionnez
void TestBenchmark::simple()
{
    QString str1 = QLatin1String("This is a test string");
    QString str2 = QLatin1String("This is a test string");

    QCOMPARE(str1.localeAwareCompare(str2), 0);

    QBENCHMARK {
        str1.localeAwareCompare(str2);
    }
}
See Also▲

See also https://, https://

[since 4.6] QBENCHMARK_ONCE▲

The QBENCHMARK_ONCE macro is for measuring performance of a code block by running it once.

This macro is used to measure the performance of code within a test. The code to be benchmarked is contained within a code block following this macro.

Unlike QBENCHMARK, the contents of the contained code block is only run once. The elapsed time will be reported as "0" if it's to short to be measured by the selected backend. (Use)

This macro was introduced in Qt 4.6.

See Also▲

See also https://, https://

QCOMPARE(actual, expected)▲

The QCOMPARE macro compares an actual value to an expected value using the equals operator. If actual and expected are identical, execution continues. If not, a failure is recorded in the test log and the test won't be executed further.

In the case of comparing floats and doubles, https://() is used for comparing. This means that comparing to 0 will likely fail. One solution to this is to compare to 1, and add 1 to the produced output.

QCOMPARE tries to output the contents of the values if the comparison fails, so it is visible from the test log why the comparison failed.

For your own classes, you can use https://() to format values for outputting into the test log.

This macro can only be used in a test function that is invoked by the test framework.

Example:

 
Sélectionnez
QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
See Also▲

See also https://(), https://(), https://()

QEXPECT_FAIL(dataIndex, comment, mode)▲

The QEXPECT_FAIL() macro marks the next https://() or https://() as an expected failure. Instead of adding a failure to the test log, an expected failure will be reported.

If a https://() or https://() is marked as an expected failure, but passes instead, an unexpected pass (XPASS) is written to the test log.

The parameter dataIndex describes for which entry in the test data the failure is expected. Pass an empty string ("") if the failure is expected for all entries or if no test data exists.

comment will be appended to the test log for the expected failure.

mode is a QTest::TestFailMode and sets whether the test should continue to execute or not.

Note: This macro can only be used in a test function that is invoked by the test framework.

Example 1:

 
Sélectionnez
QEXPECT_FAIL("", "Will fix in the next release", Continue);
QCOMPARE(i, 42);
QCOMPARE(j, 43);

In the example above, an expected fail will be written into the test output if the variable i is not 42. If the variable i is 42, an unexpected pass is written instead. The QEXPECT_FAIL() has no influence on the second https://() statement in the example.

Example 2:

 
Sélectionnez
QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort);
QCOMPARE(i, 42);

The above testfunction will not continue executing for the test data entry data27.

See Also▲

See also QTest::TestFailMode, https://(), https://()

QFAIL(message)▲

This macro can be used to force a test failure. The test stops executing and the failure message is appended to the test log.

Note: This macro can only be used in a test function that is invoked by the test framework.

Example:

 
Sélectionnez
if (sizeof(int) != 4)
    QFAIL("This test has not been ported to this platform yet.");

QFETCH(type, name)▲

The fetch macro creates a local variable named name with the type type on the stack. name has to match the element name from the test's data. If no such element exists, the test will assert.

Assuming a test has the following data:

 
Sélectionnez
void TestQString::toInt_data()
{
    QTest::addColumn&lt;QString&gt;("aString");
    QTest::addColumn&lt;int&gt;("expected");

    QTest::newRow("positive value") &lt;&lt; "42" &lt;&lt; 42;
    QTest::newRow("negative value") &lt;&lt; "-42" &lt;&lt; -42;
    QTest::newRow("zero") &lt;&lt; "0" &lt;&lt; 0;
}

The test data has two elements, a QString called aString and an integer called expected. To fetch these values in the actual test:

 
Sélectionnez
void TestQString::toInt()
{
     QFETCH(QString, aString);
     QFETCH(int, expected);

     QCOMPARE(aString.toInt(), expected);
}

aString and expected are variables on the stack that are initialized with the current test data.

Note: This macro can only be used in a test function that is invoked by the test framework. The test function must have a _data function.

[since 5.0] QFINDTESTDATA(filename)▲

Returns a QString for the testdata file referred to by filename, or an empty QString if the testdata file could not be found.

This macro allows the test to load data from an external file without hardcoding an absolute filename into the test, or using relative paths which may be error prone.

The returned path will be the first path from the following list which resolves to an existing file or directory:

  • filename relative to QCoreApplication::applicationDirPath() (only if a QCoreApplication or QApplication object has been created).

  • filename relative to the test's standard install directory (QLibraryInfo::TestsPath with the lowercased testcase name appended).

  • filename relative to the directory containing the source file from which QFINDTESTDATA is invoked.

If the named file/directory does not exist at any of these locations, a warning is printed to the test log.

For example, in this code:

 
Sélectionnez
// Source: /home/user/sources/myxmlparser/tests/tst_myxmlparser/tst_myxmlparser.cpp
// Build:  /home/user/build/myxmlparser/tests/tst_myxmlparser
// Qt:     /usr/local/Qt-5.0.0
void tst_MyXmlParser::parse()
{
    MyXmlParser parser;
    QString input = QFINDTESTDATA("testxml/simple1.xml");
    QVERIFY(parser.parse(input));
}

The testdata file will be resolved as the first existing file from:

  • /home/user/build/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml

  • /usr/local/Qt-5.0.0/tests/tst_myxmlparser/testxml/simple1.xml

  • /home/user/sources/myxmlparser/tests/tst_myxmlparser/testxml/simple1.xml

This allows the test to find its testdata regardless of whether the test has been installed, and regardless of whether the test's build tree is equal to the test's source tree.

Note: reliable detection of testdata from the source directory requires either that qmake is used, or the QT_TESTCASE_BUILDDIR macro is defined to point to the working directory from which the compiler is invoked, or only absolute paths to the source files are passed to the compiler. Otherwise, the absolute path of the source directory cannot be determined.

Note: For tests that use the https://() macro to generate a main() function, QFINDTESTDATA will not attempt to find test data relative to QCoreApplication::applicationDirPath(). In practice, this means that tests using QTEST_APPLESS_MAIN() will fail to find their test data if run from a shadow build tree.

This macro was introduced in Qt 5.0.

QSKIP(description)▲

If called from a test function, the QSKIP() macro stops execution of the test without adding a failure to the test log. You can use it to skip tests that wouldn't make sense in the current configuration. The text description is appended to the test log and should contain an explanation of why the test couldn't be executed.

If the test is data-driven, each call to QSKIP() will skip only the current row of test data, so an unconditional call to QSKIP will produce one skip message in the test log for each row of test data.

If called from an _data function, the QSKIP() macro will stop execution of the _data function and will prevent execution of the associated test function.

If called from initTestCase() or initTestCase_data(), the QSKIP() macro will skip all test and _data functions.

Note: This macro can only be used in a test function or _data function that is invoked by the test framework.

Example:

 
Sélectionnez
if (!QSqlDatabase::drivers().contains("SQLITE"))
    QSKIP("This test requires the SQLITE database driver");

QTEST(actual, testElement)▲

QTEST() is a convenience macro for https://() that compares the value actual with the element testElement from the test's data. If there is no such element, the test asserts.

Apart from that, QTEST() behaves exactly as https://().

Instead of writing:

 
Sélectionnez
QFETCH(QString, myString);
QCOMPARE(QString("hello").toUpper(), myString);

you can write:

 
Sélectionnez
QTEST(QString("hello").toUpper(), "myString");
See Also▲

See also https://()

QTEST_APPLESS_MAIN(TestClass)▲

Implements a main() function that executes all tests in TestClass.

Behaves like https://(), but doesn't instantiate a QApplication object. Use this macro for really simple stand-alone non-GUI tests.

See Also▲

See also https://()

[since 5.0] QTEST_GUILESS_MAIN(TestClass)▲

Implements a main() function that instantiates a QCoreApplication object and the TestClass, and executes all tests in the order they were defined. Use this macro to build stand-alone executables.

Behaves like https://(), but instantiates a QCoreApplication instead of the QApplication object. Use this macro if your test case doesn't need functionality offered by QApplication, but the event loop is still necessary.

This macro was introduced in Qt 5.0.

See Also▲

See also https://()

QTEST_MAIN(TestClass)▲

Implements a main() function that instantiates an application object and the TestClass, and executes all tests in the order they were defined. Use this macro to build stand-alone executables.

If QT_WIDGETS_LIB is defined, the application object will be a QApplication, if QT_GUI_LIB is defined, the application object will be a QGuiApplication, otherwise it will be a QCoreApplication. If qmake is used and the configuration includes QT += widgets, then QT_WIDGETS_LIB will be defined automatically. Similarly, if qmake is used and the configuration includes QT += gui, then QT_GUI_LIB will be defined automatically.

Note: On platforms that have keypad navigation enabled by default, this macro will forcefully disable it if QT_WIDGETS_LIB is defined. This is done to simplify the usage of key events when writing autotests. If you wish to write a test case that uses keypad navigation, you should enable it either in the initTestCase() or init() functions of your test case by calling QApplication::setNavigationMode().

Example:

 
Sélectionnez
class TestQString: public QObject { ... };
QTEST_MAIN(TestQString)
See Also▲

See also https://(), https://(), QTest::qExec(), QApplication::setNavigationMode()

[since 5.0] QTRY_COMPARE(actual, expected)▲

Performs a comparison of the actual and expected values by invoking https://() with a timeout of five seconds.

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://(), https://()

[since 5.0] QTRY_COMPARE_WITH_TIMEOUT(actual, expected, timeout)▲

The QTRY_COMPARE_WITH_TIMEOUT() macro is similar to https://(), but performs the comparison of the actual and expected values repeatedly, until either the two values are equal or the timeout (in milliseconds) is reached. Between each comparison, events will be processed. If the timeout is reached, a failure is recorded in the test log and the test won't be executed further.

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://(), https://()

[since 5.6] QTRY_VERIFY2(condition, message)▲

Checks the condition by invoking https://() with a timeout of five seconds. If condition is then still false, message is output. The message is a plain C string.

Example:

 
Sélectionnez
QTRY_VERIFY2_WITH_TIMEOUT(list.size() &gt; 2, QByteArray::number(list.size()).constData());

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.6.

See Also▲

See also https://(), https://(), QVERIFY(), https://(), https://()

[since 5.0] QTRY_VERIFY(condition)▲

Checks the condition by invoking https://() with a timeout of five seconds.

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

[since 5.6] QTRY_VERIFY2_WITH_TIMEOUT(condition, message, timeout)▲

The QTRY_VERIFY2_WITH_TIMEOUT macro is similar to https://() except that it outputs a verbose message when condition is still false after the specified timeout (in milliseconds). The message is a plain C string.

Example:

 
Sélectionnez
QTRY_VERIFY2_WITH_TIMEOUT(list.size() &gt; 2, QByteArray::number(list.size()).constData(), 10000);

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.6.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

[since 5.0] QTRY_VERIFY_WITH_TIMEOUT(condition, timeout)▲

The QTRY_VERIFY_WITH_TIMEOUT() macro is similar to https://(), but checks the condition repeatedly, until either the condition becomes true or the timeout (in milliseconds) is reached. Between each evaluation, events will be processed. If the timeout is reached, a failure is recorded in the test log and the test won't be executed further.

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.0.

See Also▲

See also https://(), https://(), https://(), https://(), https://()

QVERIFY2(condition, message)▲

The QVERIFY2() macro behaves exactly like https://(), except that it outputs a verbose message when condition is false. The message is a plain C string.

Example:

 
Sélectionnez
QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occurred.");
See Also▲

See also https://(), https://()

QVERIFY(condition)▲

The QVERIFY() macro checks whether the condition is true or not. If it is true, execution continues. If not, a failure is recorded in the test log and the test won't be executed further.

Note: This macro can only be used in a test function that is invoked by the test framework.

Example:

 
Sélectionnez
QVERIFY(1 + 1 == 2);
See Also▲

See also https://(), https://()

[since 5.3] QVERIFY_EXCEPTION_THROWN(expression, exceptiontype)▲

The QVERIFY_EXCEPTION_THROWN macro executes an expression and tries to catch an exception thrown from the expression. If the expression throws an exception and its type is the same as exceptiontype or exceptiontype is substitutable with the type of thrown exception (i.e. usually the type of thrown exception is publicly derived from exceptiontype) then execution will be continued. If not-substitutable type of exception is thrown or the expression doesn't throw an exception at all, then a failure will be recorded in the test log and the test won't be executed further.

This macro can only be used in a test function that is invoked by the test framework.

This macro was introduced in Qt 5.3.

QWARN(message)▲

Appends message as a warning to the test log. This macro can be used anywhere in your tests.

This macro is https://.

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+   

Ce document est disponible sous la licence https:// telle que publiée par la Free Software Foundation.