tst_QStringListModel: don't leak memory when tests fail

Simply allocate objects on the stack instead of the heap.

Change-Id: Ic047d78e49668878821cce1c8ab599a8551b6476
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Marc Mutz 2016-08-03 14:08:04 +03:00
parent b57f743c46
commit c38ac3dab8

View File

@ -139,22 +139,19 @@ void tst_QStringListModel::rowsAboutToBeRemoved_rowsRemoved()
QFETCH(QStringList, aboutto);
QFETCH(QStringList, res);
QStringListModel *model = new QStringListModel(input);
QModelListener *pListener = new QModelListener(&aboutto, &res, model);
pListener->connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) );
QStringListModel model(input);
QModelListener listener(&aboutto, &res, &model);
connect(&model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)),
&listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)));
pListener->connect(model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) );
connect(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
&listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)));
model->removeRows(row,count);
model.removeRows(row, count);
// At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
delete pListener;
delete model;
}
void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted_data()
@ -203,22 +200,19 @@ void tst_QStringListModel::rowsAboutToBeInserted_rowsInserted()
QFETCH(QStringList, aboutto);
QFETCH(QStringList, res);
QStringListModel *model = new QStringListModel(input);
QModelListener *pListener = new QModelListener(&aboutto, &res, model);
connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
pListener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)) );
QStringListModel model(input);
QModelListener listener(&aboutto, &res, &model);
connect(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
&listener, SLOT(rowsAboutToBeRemovedOrInserted(QModelIndex,int,int)));
connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
pListener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)) );
connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)),
&listener, SLOT(rowsRemovedOrInserted(QModelIndex,int,int)));
model->insertRows(row,count);
model.insertRows(row, count);
// At this point, control goes to our connected slots inn this order:
// 1. rowsAboutToBeRemovedOrInserted
// 2. rowsRemovedOrInserted
// Control returns here
delete pListener;
delete model;
}
void tst_QStringListModel::setData_emits_both_roles_data()