Logo Search packages:      
Sourcecode: qt4-x11 version File versions

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:

   QVERIFY(1 + 1 == 2);

See also:
QCOMPARE()
QVERIFY2(condition, message)

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

Example:

    QVERIFY2(1 + 1 == 2, "A breach in basic arithmetic occured.");

See also:
QVERIFY(), QCOMPARE()
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.

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.

{Note:} QCOMPARE is very strict on the data types. Both actual and expected have to be of the same type, otherwise the test won't compile. This prohibits unspecified behavior from being introduced; that is behavior that usually occurs when the compiler implicitely casts the argument.

Note that, for your own classes, you can use QTest::toString() to format values for outputting into the test log.

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

Example:

   QCOMPARE(QString("hello").toUpper(), QString("HELLO"));

See also:
QVERIFY(), QTest::toString()
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:

   void TestQString::toInt_data()
   {
       QTest::addColumn<QString>("aString");
       QTest::addColumn<int>("expected");

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

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

   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.

QWARN(message)

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

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:

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

QTEST(actual, testElement)

QTEST() is a convenience macro for QCOMPARE() 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 QCOMPARE().

Instead of writing:

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

you can write:

   QTEST(QString("hello").toUpper(), "myString");

See also:
QCOMPARE()
QSKIP(description, mode)

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 why the test couldn't be executed. mode is a QTest::SkipMode and describes whether to proceed with the rest of the test data or not.

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

Example:

   if (!QSqlDatabase::drivers().contains("SQLITE"))
       QSKIP("This test requires the SQLITE database driver", SkipAll);

See also:
QTest::SkipMode
QEXPECT_FAIL(dataIndex, comment, mode)

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

If a QVERIFY() or QCOMPARE() 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:

   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 QCOMPARE() statement in the example.

Example 2:

   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:
QTest::TestFailMode, QVERIFY(), QCOMPARE()
QTEST_MAIN(TestClass)

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

Example:

    class TestQString: public QObject { ... };
    QTEST_MAIN(TestQString)

See also:
QTEST_APPLESS_MAIN(), QTest::qExec()
QTEST_APPLESS_MAIN(TestClass)

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

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

See also:
QTEST_MAIN()
QTEST_NOOP_MAIN()

Implements a main() function with a test class that does absolutely nothing. Use this macro to create a test that produces valid test output but just doesn't execute any test, for example in conditional compilations:

    #ifdef Q_WS_X11
        QTEST_MAIN(MyX11Test)
    #else
        // do nothing on non-X11 platforms
        QTEST_NOOP_MAIN
    #endif

See also:
QTEST_MAIN()
This enum describes the modes for skipping tests during execution of the test data.

SkipSingle Skips the current entry in the test table; continues execution of all the other entries in the table.

SkipAll Skips all the entries in the test table; the test won't be executed further.

See also:
QSKIP()

Definition at line 52 of file qtest_global.h.

{ SkipSingle = 1, SkipAll = 2 };


Generated by  Doxygen 1.6.0   Back to index