diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index b118a2066b..afed0247d4 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -367,6 +367,11 @@ namespace QTest return toString(static_cast(arg)); } + template <> inline const char *genericToString(const void *) + { + return QTest::toString(nullptr); + } + template const char *pointerToString(const void *arg) { using QTest::toString; diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index 36e355c614..79101d7716 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -281,10 +281,10 @@ void tst_Cmptest::compareQObjects() object1.setObjectName(QStringLiteral("object1")); QObject object2; object2.setObjectName(QStringLiteral("object2")); - QCOMPARE(&object1, &object1); - QCOMPARE(&object1, &object2); - QCOMPARE(&object1, nullptr); - QCOMPARE(nullptr, &object2); + [&] { QCOMPARE(&object1, &object1); }(); + [&] { QCOMPARE(&object1, &object2); }(); + [&] { QCOMPARE(&object1, nullptr); }(); + [&] { QCOMPARE(nullptr, &object2); }(); } struct PhonyClass diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml index 9c54d20650..2e31258281 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.lightxml +++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml @@ -129,6 +129,16 @@ + + + + + + diff --git a/tests/auto/testlib/selftests/expected_cmptest.tap b/tests/auto/testlib/selftests/expected_cmptest.tap index a5f5c3c8a2..58af83b3a0 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.tap +++ b/tests/auto/testlib/selftests/expected_cmptest.tap @@ -172,6 +172,30 @@ not ok 21 - compareQObjects() file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp line: 0 ... +not ok 21 - compareQObjects() + --- + type: QCOMPARE + message: Compared QObject pointers are not the same + wanted: "nullptr" (nullptr) + found: QObject/"object1" (&object1) + expected: "nullptr" (nullptr) + actual: QObject/"object1" (&object1) + at: tst_Cmptest::compareQObjects() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0) + file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp + line: 0 + ... +not ok 21 - compareQObjects() + --- + type: QCOMPARE + message: Compared QObject pointers are not the same + wanted: QObject/"object2" (&object2) + found: "nullptr" (nullptr) + expected: QObject/"object2" (&object2) + actual: "nullptr" (nullptr) + at: tst_Cmptest::compareQObjects() (qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp:0) + file: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp + line: 0 + ... ok 22 - compareQStringLists(empty lists) ok 23 - compareQStringLists(equal lists) not ok 24 - compareQStringLists(last item different) diff --git a/tests/auto/testlib/selftests/expected_cmptest.teamcity b/tests/auto/testlib/selftests/expected_cmptest.teamcity index b5ff675465..0a137aae7f 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.teamcity +++ b/tests/auto/testlib/selftests/expected_cmptest.teamcity @@ -55,6 +55,10 @@ ##teamcity[testStarted name='compareQObjects()' flowId='tst_Cmptest'] ##teamcity[testFailed name='compareQObjects()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared QObject pointers are not the same|n Actual (&object1): QObject/"object1"|n Expected (&object2): QObject/"object2"' flowId='tst_Cmptest'] ##teamcity[testFinished name='compareQObjects()' flowId='tst_Cmptest'] +##teamcity[testFailed name='compareQObjects()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared QObject pointers are not the same|n Actual (&object1): QObject/"object1"|n Expected (nullptr) : "nullptr"' flowId='tst_Cmptest'] +##teamcity[testFinished name='compareQObjects()' flowId='tst_Cmptest'] +##teamcity[testFailed name='compareQObjects()' message='Failure! |[Loc: qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)|]' details='Compared QObject pointers are not the same|n Actual (nullptr) : "nullptr"|n Expected (&object2): QObject/"object2"' flowId='tst_Cmptest'] +##teamcity[testFinished name='compareQObjects()' flowId='tst_Cmptest'] ##teamcity[testStarted name='compareQStringLists(empty lists)' flowId='tst_Cmptest'] ##teamcity[testFinished name='compareQStringLists(empty lists)' flowId='tst_Cmptest'] ##teamcity[testStarted name='compareQStringLists(equal lists)' flowId='tst_Cmptest'] diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt index ff81a46397..a42e9b9a17 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.txt +++ b/tests/auto/testlib/selftests/expected_cmptest.txt @@ -63,6 +63,14 @@ FAIL! : tst_Cmptest::compareQObjects() Compared QObject pointers are not the sa Actual (&object1): QObject/"object1" Expected (&object2): QObject/"object2" Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +FAIL! : tst_Cmptest::compareQObjects() Compared QObject pointers are not the same + Actual (&object1): QObject/"object1" + Expected (nullptr) : "nullptr" + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] +FAIL! : tst_Cmptest::compareQObjects() Compared QObject pointers are not the same + Actual (nullptr) : "nullptr" + Expected (&object2): QObject/"object2" + Loc: [qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(0)] PASS : tst_Cmptest::compareQStringLists(empty lists) PASS : tst_Cmptest::compareQStringLists(equal lists) FAIL! : tst_Cmptest::compareQStringLists(last item different) Compared lists differ at index 2. diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml index df4d8b28be..f352b95cf5 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.xml +++ b/tests/auto/testlib/selftests/expected_cmptest.xml @@ -131,6 +131,16 @@ + + + + + +