Add a unit test to QSharedPointer being deleted by a C++11 lambda
This already worked, but let's have a test so we can be sure it doesn't regress. Change-Id: I358b436d216e3ec4310f05ccf4f70f9e7aad3281 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
parent
4e3b225bb0
commit
9e1a9878aa
@ -89,6 +89,7 @@ private slots:
|
||||
#endif
|
||||
void constCorrectness();
|
||||
void customDeleter();
|
||||
void lambdaCustomDeleter();
|
||||
void creating();
|
||||
void creatingQObject();
|
||||
void mixTrackingPointerCode();
|
||||
@ -1336,6 +1337,37 @@ void tst_QSharedPointer::customDeleter()
|
||||
safetyCheck();
|
||||
}
|
||||
|
||||
void tst_QSharedPointer::lambdaCustomDeleter()
|
||||
{
|
||||
#ifndef Q_COMPILER_LAMBDA
|
||||
QSKIP("This compiler is not in C++11 mode or does not support lambdas");
|
||||
#else
|
||||
{
|
||||
// stateless, one-argument
|
||||
QSharedPointer<Data> ptr(new Data, [](Data *d) { delete d; });
|
||||
QSharedPointer<Data> ptr2(new Data, [](Data *d) { d->doDelete(); });
|
||||
}
|
||||
safetyCheck();
|
||||
|
||||
customDeleterFnCallCount = 0;
|
||||
{
|
||||
// stateless, one-argument, modifies globals
|
||||
QSharedPointer<Data> ptr(new Data, [](Data *d) { ++customDeleterFnCallCount; delete d; });
|
||||
}
|
||||
safetyCheck();
|
||||
QCOMPARE(customDeleterFnCallCount, 1);
|
||||
|
||||
{
|
||||
// stateful by ref, one-argument
|
||||
int i = 0;
|
||||
QSharedPointer<Data> ptr(new Data, [&i](Data *d) { i = 42; delete d; });
|
||||
ptr.clear();
|
||||
QCOMPARE(i, 42);
|
||||
}
|
||||
safetyCheck();
|
||||
#endif
|
||||
}
|
||||
|
||||
void customQObjectDeleterFn(QObject *obj)
|
||||
{
|
||||
++customDeleterFnCallCount;
|
||||
|
Loading…
Reference in New Issue
Block a user