summaryrefslogtreecommitdiffstats
path: root/tests/auto/qsharedpointer
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-07-31 23:07:54 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-03 12:14:57 (GMT)
commit7e0b201285c712a3c98c848033bbd8e5ab75a590 (patch)
treed4594a747ccc01245a4ab9e52aa0653eb3701337 /tests/auto/qsharedpointer
parent788a33f7a061552e3f9e5d2fe6cf7faad516892e (diff)
downloadQt-7e0b201285c712a3c98c848033bbd8e5ab75a590.zip
Qt-7e0b201285c712a3c98c848033bbd8e5ab75a590.tar.gz
Qt-7e0b201285c712a3c98c848033bbd8e5ab75a590.tar.bz2
Don't forget to delete the deleter object too in QSharedPointer.
Destructors have to be run for the subobjects we initialise. Reviewed-By: Bradley T. Hughes
Diffstat (limited to 'tests/auto/qsharedpointer')
-rw-r--r--tests/auto/qsharedpointer/tst_qsharedpointer.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
index 1c2c60f..481377a 100644
--- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
@@ -871,9 +871,14 @@ void customDeleterFn(Data *ptr)
delete ptr;
}
+static int refcount;
+
template <typename T>
struct CustomDeleter
{
+ CustomDeleter() { ++refcount; }
+ CustomDeleter(const CustomDeleter &) { ++refcount; }
+ ~CustomDeleter() { --refcount; }
inline void operator()(T *ptr)
{
delete ptr;
@@ -971,6 +976,7 @@ void tst_QSharedPointer::customDeleter()
QCOMPARE(customDeleterFnCallCount, 1);
check();
+ refcount = 0;
CustomDeleter<Data> dataDeleter;
dataDeleter.callCount = 0;
{
@@ -979,6 +985,7 @@ void tst_QSharedPointer::customDeleter()
QCOMPARE(dataDeleter.callCount, 0);
}
QCOMPARE(dataDeleter.callCount, 1);
+ QCOMPARE(refcount, 1);
check();
dataDeleter.callCount = 0;
@@ -989,6 +996,7 @@ void tst_QSharedPointer::customDeleter()
QCOMPARE(dataDeleter.callCount, 0);
}
QCOMPARE(dataDeleter.callCount, 1);
+ QCOMPARE(refcount, 1);
check();
dataDeleter.callCount = 0;
@@ -1002,6 +1010,7 @@ void tst_QSharedPointer::customDeleter()
QCOMPARE(dataDeleter.callCount, 0);
}
QCOMPARE(dataDeleter.callCount, 1);
+ QCOMPARE(refcount, 1);
check();
dataDeleter.callCount = 0;
@@ -1011,6 +1020,7 @@ void tst_QSharedPointer::customDeleter()
QCOMPARE(dataDeleter.callCount, 0);
}
QCOMPARE(dataDeleter.callCount, 1);
+ QCOMPARE(refcount, 1);
check();
CustomDeleter<DerivedData> derivedDataDeleter;
@@ -1024,6 +1034,7 @@ void tst_QSharedPointer::customDeleter()
}
QCOMPARE(dataDeleter.callCount, 0);
QCOMPARE(derivedDataDeleter.callCount, 1);
+ QCOMPARE(refcount, 2);
check();
derivedDataDeleter.callCount = 0;
@@ -1041,6 +1052,7 @@ void tst_QSharedPointer::customDeleter()
}
QCOMPARE(dataDeleter.callCount, 1);
QCOMPARE(derivedDataDeleter.callCount, 0);
+ QCOMPARE(refcount, 2);
check();
derivedDataDeleter.callCount = 0;
@@ -1058,6 +1070,7 @@ void tst_QSharedPointer::customDeleter()
}
QCOMPARE(dataDeleter.callCount, 0);
QCOMPARE(derivedDataDeleter.callCount, 1);
+ QCOMPARE(refcount, 2);
}
void tst_QSharedPointer::creating()