diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-05-14 15:03:24 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-08-13 17:26:11 +0200 |
commit | 19b52e7c1dc2c447c1682f9438ebd37cbfc7d31d (patch) | |
tree | d9b9d20b11d3c399809f15585b27671ae7b12dfb /tests | |
parent | 743fdd3fe7ad8d3cafa237a202c089fa6ff1c78c (diff) |
tst_QFormLayout: use QAutoPointer to simplify test and avoid leak
... in case of a test failure. QAutoPointer is private API, but here we can use it.
Change-Id: I45b734385cd13fdea95d0100f2d8152f969612f9
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/kernel/qformlayout/qformlayout.pro | 2 | ||||
-rw-r--r-- | 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 <QtWidgets/QLabel> #include <QtWidgets/QLineEdit> #include <QtWidgets/QPushButton> + +#include <private/qdialog_p.h> + #include <QStyleFactory> #include <QSharedPointer> @@ -1196,22 +1199,20 @@ void tst_QFormLayout::layoutAlone() void tst_QFormLayout::taskQTBUG_27420_takeAtShouldUnparentLayout() { QSharedPointer<QFormLayout> outer(new QFormLayout); - QPointer<QFormLayout> inner = new QFormLayout; + QAutoPointer<QFormLayout> 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(){ |