summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-04-05 07:47:13 (GMT)
committerJason McDonald <jason.mcdonald@nokia.com>2011-04-05 07:47:13 (GMT)
commit6349d6aed801354167038a094b62ad91de6b8b57 (patch)
treeae7db593166e94d7fe5ab8687bb7a585ddaf980e
parentbfbf0888930d73540bd65a01da093b0da3582ecd (diff)
downloadQt-6349d6aed801354167038a094b62ad91de6b8b57.zip
Qt-6349d6aed801354167038a094b62ad91de6b8b57.tar.gz
Qt-6349d6aed801354167038a094b62ad91de6b8b57.tar.bz2
Add comments, eliminate duplication in qpointer autotest.
Test destruction of guarded objects in the destruction test function, rather than partly there and partly in the assignment test. Reviewed-by: Rohan McGovern
-rw-r--r--tests/auto/qpointer/tst_qpointer.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/tests/auto/qpointer/tst_qpointer.cpp b/tests/auto/qpointer/tst_qpointer.cpp
index 6c2dee8..b8a3da2 100644
--- a/tests/auto/qpointer/tst_qpointer.cpp
+++ b/tests/auto/qpointer/tst_qpointer.cpp
@@ -77,11 +77,20 @@ void tst_QPointer::constructors()
void tst_QPointer::destructor()
{
+ // Make two QPointer's to the same object
QObject *object = new QObject;
- QPointer<QObject> p = object;
- QCOMPARE(p, QPointer<QObject>(object));
+ QPointer<QObject> p1 = object;
+ QPointer<QObject> p2 = object;
+ // Check that they point to the correct object
+ QCOMPARE(p1, QPointer<QObject>(object));
+ QCOMPARE(p2, QPointer<QObject>(object));
+ QCOMPARE(p1, p2);
+ // Destroy the guarded object
delete object;
- QCOMPARE(p, QPointer<QObject>(0));
+ // Check that both pointers were zeroed
+ QCOMPARE(p1, QPointer<QObject>(0));
+ QCOMPARE(p2, QPointer<QObject>(0));
+ QCOMPARE(p1, p2);
}
void tst_QPointer::assignment_operators()
@@ -89,19 +98,21 @@ void tst_QPointer::assignment_operators()
QPointer<QObject> p1;
QPointer<QObject> p2;
+ // Test assignment with a QObject-derived object pointer
p1 = this;
p2 = p1;
-
QCOMPARE(p1, QPointer<QObject>(this));
QCOMPARE(p2, QPointer<QObject>(this));
QCOMPARE(p1, QPointer<QObject>(p2));
+ // Test assignment with a null pointer
p1 = 0;
p2 = p1;
QCOMPARE(p1, QPointer<QObject>(0));
QCOMPARE(p2, QPointer<QObject>(0));
QCOMPARE(p1, QPointer<QObject>(p2));
+ // Test assignment with a real QObject pointer
QObject *object = new QObject;
p1 = object;
@@ -110,10 +121,8 @@ void tst_QPointer::assignment_operators()
QCOMPARE(p2, QPointer<QObject>(object));
QCOMPARE(p1, QPointer<QObject>(p2));
+ // Cleanup
delete object;
- QCOMPARE(p1, QPointer<QObject>(0));
- QCOMPARE(p2, QPointer<QObject>(0));
- QCOMPARE(p1, QPointer<QObject>(p2));
}
void tst_QPointer::equality_operators()
@@ -180,6 +189,7 @@ void tst_QPointer::dereference_operators()
void tst_QPointer::disconnect()
{
+ // Verify that pointer remains guarded when all signals are disconencted.
QPointer<QObject> p1 = new QObject;
QVERIFY(!p1.isNull());
p1->disconnect();