Improve selftest coverage of QEXPECT_FAIL feature.

The existing expectfail selftest did not test QEXPECT_FAIL with a
data-driven test function.  This commit adds such a test.

Change-Id: I39fa9aa227b58779ce5268dd37bf55468e7269c5
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2012-01-11 16:18:55 +10:00 committed by Qt by Nokia
parent d3f6faedb5
commit a59bc6a6e4
5 changed files with 85 additions and 15 deletions

View File

@ -9,7 +9,7 @@
<Message type="qdebug" file="" line="0">
<Description><![CDATA[begin]]></Description>
</Message>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="60">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="64">
<Description><![CDATA[This should xfail]]></Description>
</Incident>
<Message type="qdebug" file="" line="0">
@ -21,20 +21,31 @@
<Message type="qdebug" file="" line="0">
<Description><![CDATA[begin]]></Description>
</Message>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="68">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="72">
<Description><![CDATA[This should xfail]]></Description>
</Incident>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="xfailWithQString">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="75">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="79">
<Description><![CDATA[A string]]></Description>
</Incident>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="80">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="84">
<Description><![CDATA[Bug 5 (The message)]]></Description>
</Incident>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="dataDrivenTest">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="113">
<DataTag><![CDATA[Abort]]></DataTag>
<Description><![CDATA[This test should xfail]]></Description>
</Incident>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="113">
<DataTag><![CDATA[Continue]]></DataTag>
<Description><![CDATA[This test should xfail]]></Description>
</Incident>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>

View File

@ -3,18 +3,23 @@ Config: Using QTest library @INSERT_QT_VERSION_HERE@, Qt @INSERT_QT_VERSION_HERE
PASS : tst_ExpectFail::initTestCase()
QDEBUG : tst_ExpectFail::expectAndContinue() begin
XFAIL : tst_ExpectFail::expectAndContinue() This should xfail
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(27)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(64)]
QDEBUG : tst_ExpectFail::expectAndContinue() after
PASS : tst_ExpectFail::expectAndContinue()
QDEBUG : tst_ExpectFail::expectAndAbort() begin
XFAIL : tst_ExpectFail::expectAndAbort() This should xfail
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(35)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(72)]
PASS : tst_ExpectFail::expectAndAbort()
XFAIL : tst_ExpectFail::xfailWithQString() A string
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(42)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(79)]
XFAIL : tst_ExpectFail::xfailWithQString() Bug 5 (The message)
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(47)]
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(84)]
PASS : tst_ExpectFail::xfailWithQString()
XFAIL : tst_ExpectFail::dataDrivenTest(Abort) This test should xfail
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(113)]
XFAIL : tst_ExpectFail::dataDrivenTest(Continue) This test should xfail
Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp(113)]
PASS : tst_ExpectFail::dataDrivenTest()
PASS : tst_ExpectFail::cleanupTestCase()
Totals: 5 passed, 0 failed, 0 skipped
Totals: 6 passed, 0 failed, 0 skipped
********* Finished testing of tst_ExpectFail *********

View File

@ -11,7 +11,7 @@
<Message type="qdebug" file="" line="0">
<Description><![CDATA[begin]]></Description>
</Message>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="60">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="64">
<Description><![CDATA[This should xfail]]></Description>
</Incident>
<Message type="qdebug" file="" line="0">
@ -23,20 +23,31 @@
<Message type="qdebug" file="" line="0">
<Description><![CDATA[begin]]></Description>
</Message>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="68">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="72">
<Description><![CDATA[This should xfail]]></Description>
</Incident>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="xfailWithQString">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="75">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="79">
<Description><![CDATA[A string]]></Description>
</Incident>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="80">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="84">
<Description><![CDATA[Bug 5 (The message)]]></Description>
</Incident>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="dataDrivenTest">
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="113">
<DataTag><![CDATA[Abort]]></DataTag>
<Description><![CDATA[This test should xfail]]></Description>
</Incident>
<Incident type="xfail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp" line="113">
<DataTag><![CDATA[Continue]]></DataTag>
<Description><![CDATA[This test should xfail]]></Description>
</Incident>
<Incident type="pass" file="" line="0" />
</TestFunction>
<TestFunction name="cleanupTestCase">
<Incident type="pass" file="" line="0" />
</TestFunction>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="7" failures="0" tests="5" name="tst_ExpectFail">
<testsuite errors="9" failures="0" tests="6" name="tst_ExpectFail">
<properties>
<property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/>
<property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/>
@ -18,6 +18,10 @@
<!-- message="A string" type="info" -->
<!-- message="Bug 5 (The message)" type="info" -->
</testcase>
<testcase result="xfail" name="dataDrivenTest">
<!-- tag="Abort" message="This test should xfail" type="info" -->
<!-- tag="Continue" message="This test should xfail" type="info" -->
</testcase>
<testcase result="pass" name="cleanupTestCase"/>
<system-err>
<![CDATA[begin]]>
@ -27,5 +31,7 @@
<![CDATA[This should xfail]]>
<![CDATA[A string]]>
<![CDATA[Bug 5 (The message)]]>
<![CDATA[This test should xfail]]>
<![CDATA[This test should xfail]]>
</system-err>
</testsuite>

View File

@ -43,6 +43,8 @@
#include <QtCore/QCoreApplication>
#include <QtTest/QtTest>
Q_DECLARE_METATYPE(QTest::TestFailMode)
class tst_ExpectFail: public QObject
{
Q_OBJECT
@ -51,6 +53,8 @@ private slots:
void expectAndContinue() const;
void expectAndAbort() const;
void xfailWithQString() const;
void dataDrivenTest_data() const;
void dataDrivenTest() const;
};
void tst_ExpectFail::expectAndContinue() const
@ -80,6 +84,39 @@ void tst_ExpectFail::xfailWithQString() const
QVERIFY(false);
}
QTEST_MAIN(tst_ExpectFail)
void tst_ExpectFail::dataDrivenTest_data() const
{
QTest::addColumn<bool>("shouldPass");
QTest::addColumn<QTest::TestFailMode>("failMode");
QTest::newRow("Pass 1") << true << QTest::Abort;
QTest::newRow("Pass 2") << true << QTest::Continue;
QTest::newRow("Abort") << false << QTest::Abort;
QTest::newRow("Continue") << false << QTest::Continue;
}
void tst_ExpectFail::dataDrivenTest() const
{
QFETCH(bool, shouldPass);
QFETCH(QTest::TestFailMode, failMode);
// You can't pass a variable as the last parameter of QEXPECT_FAIL,
// because the macro adds "QTest::" in front of the last parameter.
// That is why the following code appears to be a little strange.
if (!shouldPass) {
if (failMode == QTest::Abort)
QEXPECT_FAIL(QTest::currentDataTag(), "This test should xfail", Abort);
else
QEXPECT_FAIL(QTest::currentDataTag(), "This test should xfail", Continue);
}
QVERIFY(shouldPass);
// If we get here, we either expected to pass or we expected to
// fail and the failure mode was Continue.
if (!shouldPass)
QCOMPARE(failMode, QTest::Continue);
}
QTEST_MAIN(tst_ExpectFail)
#include "tst_expectfail.moc"