diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2012-05-24 14:30:42 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-12 04:29:29 +0200 |
commit | 9e1a9878aaeac75f5c9e73a0d0e1a4e489e13cbc (patch) | |
tree | 8e38df68da719b51c2b96e48b73f96f3fc260b3e /tests/auto | |
parent | 4e3b225bb0e3344ca09fe7919dfe703b5d521a6a (diff) |
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>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 506bab6a23..7c3f0e5415 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -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; |