summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-22 20:29:32 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-04-08 05:38:33 +0000
commit1ed8a7bff503aacf55f7f880ddaad461ea15e5e1 (patch)
tree06b264813602be5a9c442b3ba395e3b7227943a2 /tests/auto/testlib
parent3f41e8a2f51698d690a6b1f6a1f4acfe13ff50af (diff)
QTest: support nullptr in QCOMPARE
This allows to write QCOMPARE(ptr, nullptr); instead of QVERIFY(ptr); Task-number: QTBUG-49973 Change-Id: I6e1327d4327bcf17bd9b59de4352fdcaae98ac27 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/testlib')
-rw-r--r--tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp19
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.lightxml4
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.teamcity2
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.txt3
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xml4
-rw-r--r--tests/auto/testlib/selftests/expected_cmptest.xunitxml3
6 files changed, 33 insertions, 2 deletions
diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
index 204758f68a..9ada718682 100644
--- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
+++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp
@@ -128,6 +128,7 @@ private slots:
void compare_registered_enums();
void compare_class_enums();
void compare_boolfuncs();
+ void compare_to_nullptr();
void compare_pointerfuncs();
void compare_tostring();
void compare_tostring_data();
@@ -180,6 +181,24 @@ void tst_Cmptest::compare_boolfuncs()
QCOMPARE(!boolfunc(), false);
}
+namespace {
+template <typename T>
+T *null() Q_DECL_NOTHROW { return nullptr; }
+}
+
+void tst_Cmptest::compare_to_nullptr()
+{
+ QCOMPARE(null<int>(), nullptr);
+ QCOMPARE(null<const int>(), nullptr);
+ QCOMPARE(null<volatile int>(), nullptr);
+ QCOMPARE(null<const volatile int>(), nullptr);
+
+ QCOMPARE(nullptr, null<int>());
+ QCOMPARE(nullptr, null<const int>());
+ QCOMPARE(nullptr, null<volatile int>());
+ QCOMPARE(nullptr, null<const volatile int>());
+}
+
static int i = 0;
static int *intptr() { return &i; }
diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml
index 440429e430..d4ba020000 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.lightxml
+++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml
@@ -33,6 +33,10 @@
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
</TestFunction>
+<TestFunction name="compare_to_nullptr">
+<Incident type="pass" file="" line="0" />
+ <Duration msecs="0"/>
+</TestFunction>
<TestFunction name="compare_pointerfuncs">
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
diff --git a/tests/auto/testlib/selftests/expected_cmptest.teamcity b/tests/auto/testlib/selftests/expected_cmptest.teamcity
index dea19b60b4..c64060fdf2 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.teamcity
+++ b/tests/auto/testlib/selftests/expected_cmptest.teamcity
@@ -12,6 +12,8 @@
##teamcity[testFinished name='compare_class_enums()']
##teamcity[testStarted name='compare_boolfuncs()']
##teamcity[testFinished name='compare_boolfuncs()']
+##teamcity[testStarted name='compare_to_nullptr()']
+##teamcity[testFinished name='compare_to_nullptr()']
##teamcity[testStarted name='compare_pointerfuncs()']
##teamcity[testFinished name='compare_pointerfuncs()']
##teamcity[testStarted name='compare_tostring(int, string)']
diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt
index 100fd5e8ef..ceee0f1efa 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.txt
+++ b/tests/auto/testlib/selftests/expected_cmptest.txt
@@ -12,6 +12,7 @@ FAIL! : tst_Cmptest::compare_class_enums() Compared values are not the same
Expected (MyClassEnum::MyClassEnumValue2): MyClassEnumValue2
Loc: [tst_cmptest.cpp(168)]
PASS : tst_Cmptest::compare_boolfuncs()
+PASS : tst_Cmptest::compare_to_nullptr()
PASS : tst_Cmptest::compare_pointerfuncs()
FAIL! : tst_Cmptest::compare_tostring(int, string) Compared values are not the same
Actual (actual) : QVariant(int,123)
@@ -109,5 +110,5 @@ FAIL! : tst_Cmptest::tryVerify() 'opaqueFunc() < 2' returned FALSE. ()
FAIL! : tst_Cmptest::tryVerify2() 'opaqueFunc() < 2' returned FALSE. (42)
Loc: [tst_cmptest.cpp(439)]
PASS : tst_Cmptest::cleanupTestCase()
-Totals: 11 passed, 28 failed, 0 skipped, 0 blacklisted, 247ms
+Totals: 12 passed, 28 failed, 0 skipped, 0 blacklisted, 247ms
********* Finished testing of tst_Cmptest *********
diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml
index f45d9ba1da..2eddfa67d9 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.xml
+++ b/tests/auto/testlib/selftests/expected_cmptest.xml
@@ -35,6 +35,10 @@
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
</TestFunction>
+<TestFunction name="compare_to_nullptr">
+<Incident type="pass" file="" line="0" />
+ <Duration msecs="0"/>
+</TestFunction>
<TestFunction name="compare_pointerfuncs">
<Incident type="pass" file="" line="0" />
<Duration msecs="0"/>
diff --git a/tests/auto/testlib/selftests/expected_cmptest.xunitxml b/tests/auto/testlib/selftests/expected_cmptest.xunitxml
index ec2c3f023c..d044771b14 100644
--- a/tests/auto/testlib/selftests/expected_cmptest.xunitxml
+++ b/tests/auto/testlib/selftests/expected_cmptest.xunitxml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<testsuite errors="0" failures="28" tests="18" name="tst_Cmptest">
+<testsuite errors="0" failures="28" tests="19" name="tst_Cmptest">
<properties>
<property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/>
<property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/>
@@ -20,6 +20,7 @@
Expected (MyClassEnum::MyClassEnumValue2): MyClassEnumValue2" result="fail"/>
</testcase>
<testcase result="pass" name="compare_boolfuncs"/>
+ <testcase result="pass" name="compare_to_nullptr"/>
<testcase result="pass" name="compare_pointerfuncs"/>
<testcase result="fail" name="compare_tostring">
<failure tag="int, string" message="Compared values are not the same