From 19b52e7c1dc2c447c1682f9438ebd37cbfc7d31d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 14 May 2019 15:03:24 +0200 Subject: tst_QFormLayout: use QAutoPointer to simplify test and avoid leak MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... in case of a test failure. QAutoPointer is private API, but here we can use it. Change-Id: I45b734385cd13fdea95d0100f2d8152f969612f9 Reviewed-by: Friedemann Kleint Reviewed-by: Jan Arve Sæther --- tests/auto/widgets/kernel/qformlayout/qformlayout.pro | 2 +- tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/auto/widgets/kernel/qformlayout/qformlayout.pro b/tests/auto/widgets/kernel/qformlayout/qformlayout.pro index 617183fee6..0766b50f68 100644 --- a/tests/auto/widgets/kernel/qformlayout/qformlayout.pro +++ b/tests/auto/widgets/kernel/qformlayout/qformlayout.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qformlayout -QT += widgets testlib testlib-private +QT += widgets widgets-private testlib testlib-private SOURCES += tst_qformlayout.cpp diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index ab32643061..c6760000f4 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -38,6 +38,9 @@ #include #include #include + +#include + #include #include @@ -1196,22 +1199,20 @@ void tst_QFormLayout::layoutAlone() void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout() { QSharedPointer outer(new QFormLayout); - QPointer inner = new QFormLayout; + QAutoPointer holder{new QFormLayout}; + auto inner = holder.get(); outer->addRow(inner); QCOMPARE(outer->count(), 1); QCOMPARE(inner->parent(), outer.data()); QLayoutItem *item = outer->takeAt(0); - QCOMPARE(item->layout(), inner.data()); + QCOMPARE(item->layout(), inner); QVERIFY(!item->layout()->parent()); outer.reset(); - if (inner) - delete item; // success: a taken item/layout should not be deleted when the old parent is deleted - else - QVERIFY(!inner.isNull()); + QVERIFY(holder); // a taken item/layout should not be deleted when the old parent is deleted } void tst_QFormLayout::taskQTBUG_40609_addingWidgetToItsOwnLayout(){ -- cgit v1.2.3