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>
bb10
Marc Mutz 2019-05-14 15:03:24 +02:00
parent 743fdd3fe7
commit 19b52e7c1d
2 changed files with 8 additions and 7 deletions

View File

@ -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

View File

@ -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(){