From 1ed8a7bff503aacf55f7f880ddaad461ea15e5e1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 22 Feb 2016 20:29:32 +0100 Subject: 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) --- tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp') 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 +T *null() Q_DECL_NOTHROW { return nullptr; } +} + +void tst_Cmptest::compare_to_nullptr() +{ + QCOMPARE(null(), nullptr); + QCOMPARE(null(), nullptr); + QCOMPARE(null(), nullptr); + QCOMPARE(null(), nullptr); + + QCOMPARE(nullptr, null()); + QCOMPARE(nullptr, null()); + QCOMPARE(nullptr, null()); + QCOMPARE(nullptr, null()); +} + static int i = 0; static int *intptr() { return &i; } -- cgit v1.2.3