From 6349d6aed801354167038a094b62ad91de6b8b57 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 5 Apr 2011 17:47:13 +1000 Subject: 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 --- tests/auto/qpointer/tst_qpointer.cpp | 24 +++++++++++++++++------- 1 file 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 p = object; - QCOMPARE(p, QPointer(object)); + QPointer p1 = object; + QPointer p2 = object; + // Check that they point to the correct object + QCOMPARE(p1, QPointer(object)); + QCOMPARE(p2, QPointer(object)); + QCOMPARE(p1, p2); + // Destroy the guarded object delete object; - QCOMPARE(p, QPointer(0)); + // Check that both pointers were zeroed + QCOMPARE(p1, QPointer(0)); + QCOMPARE(p2, QPointer(0)); + QCOMPARE(p1, p2); } void tst_QPointer::assignment_operators() @@ -89,19 +98,21 @@ void tst_QPointer::assignment_operators() QPointer p1; QPointer p2; + // Test assignment with a QObject-derived object pointer p1 = this; p2 = p1; - QCOMPARE(p1, QPointer(this)); QCOMPARE(p2, QPointer(this)); QCOMPARE(p1, QPointer(p2)); + // Test assignment with a null pointer p1 = 0; p2 = p1; QCOMPARE(p1, QPointer(0)); QCOMPARE(p2, QPointer(0)); QCOMPARE(p1, QPointer(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(object)); QCOMPARE(p1, QPointer(p2)); + // Cleanup delete object; - QCOMPARE(p1, QPointer(0)); - QCOMPARE(p2, QPointer(0)); - QCOMPARE(p1, QPointer(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 p1 = new QObject; QVERIFY(!p1.isNull()); p1->disconnect(); -- cgit v0.12