summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/expectfail
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2012-01-11 16:18:55 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-12 06:41:29 +0100
commita59bc6a6e4c7c9f291e7d1b654c3b1ee157d8379 (patch)
tree53b7d50402da799a5bf9806e4c6290a1ee638eb0 /tests/auto/testlib/selftests/expectfail
parentd3f6faedb5bb02accca3c3ae5f81530e5d60b39a (diff)
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>
Diffstat (limited to 'tests/auto/testlib/selftests/expectfail')
-rw-r--r--tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp b/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp
index 6df919a9a0..28b00dccf7 100644
--- a/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp
+++ b/tests/auto/testlib/selftests/expectfail/tst_expectfail.cpp
@@ -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"