mirror of https://github.com/qt/qtbase.git
tst_QGraphicsLinearLayout: fix memleaks in itemAt()
The old code used a data-driven test to check that itemAt(i), 0 ≤ i ≤
2, was returning non-nullptr. It re-created the widgets and the layout
for each data tag anew, leaking the widgets by the way.
Using data-driven test machinery here is overkill. Remove it and
create the widgets in a C array on the stack, so they're not leaked,
and iterate over them using range-for.
Also check not just for nullptr, but also that the pointer matches the
widgets we put into layout, at the position we put them in.
Amends the start of the public history.
Pick-to: 6.8 6.5 5.15
Change-Id: Ib808aa6756c6550a61a4768edfc5021f2f6ae3b3
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 159029b587
)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
c144326b2d
commit
a961848c16
|
@ -34,7 +34,6 @@ private slots:
|
|||
void insertStretch();
|
||||
void invalidate_data();
|
||||
void invalidate();
|
||||
void itemAt_data();
|
||||
void itemAt();
|
||||
void itemAt_visualOrder();
|
||||
void orientation_data();
|
||||
|
@ -633,24 +632,19 @@ void tst_QGraphicsLinearLayout::invalidate()
|
|||
delete widget;
|
||||
}
|
||||
|
||||
void tst_QGraphicsLinearLayout::itemAt_data()
|
||||
{
|
||||
QTest::addColumn<int>("index");
|
||||
QTest::newRow("0") << 0;
|
||||
QTest::newRow("1") << 1;
|
||||
QTest::newRow("2") << 2;
|
||||
}
|
||||
|
||||
// QGraphicsLayoutItem* itemAt(int index) const public
|
||||
void tst_QGraphicsLinearLayout::itemAt()
|
||||
{
|
||||
// see also the insertItem() etc tests
|
||||
QFETCH(int, index);
|
||||
SubQGraphicsLinearLayout layout;
|
||||
for (int i = 0; i < 3; ++i)
|
||||
layout.addItem(new QGraphicsWidget);
|
||||
|
||||
QVERIFY(layout.itemAt(index) != 0);
|
||||
QGraphicsWidget widgets[3];
|
||||
for (auto &w : widgets)
|
||||
layout.addItem(&w);
|
||||
|
||||
int i = 0;
|
||||
for (const auto &w : widgets)
|
||||
QCOMPARE(layout.itemAt(i++), &w);
|
||||
}
|
||||
|
||||
void tst_QGraphicsLinearLayout::itemAt_visualOrder()
|
||||
|
|
Loading…
Reference in New Issue