From bfbf0888930d73540bd65a01da093b0da3582ecd Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 5 Apr 2011 16:26:44 +1000 Subject: Remove redundant includes and functions from qpointer autotest. Reviewed-by: Rohan McGovern --- tests/auto/qpointer/tst_qpointer.cpp | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/tests/auto/qpointer/tst_qpointer.cpp b/tests/auto/qpointer/tst_qpointer.cpp index 0485a17..6c2dee8 100644 --- a/tests/auto/qpointer/tst_qpointer.cpp +++ b/tests/auto/qpointer/tst_qpointer.cpp @@ -39,11 +39,8 @@ ** ****************************************************************************/ - #include -#include -#include #include #include @@ -51,17 +48,9 @@ class tst_QPointer : public QObject { Q_OBJECT public: - tst_QPointer(); - ~tst_QPointer(); - inline tst_QPointer *me() const { return const_cast(this); } -public slots: - void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); private slots: void constructors(); void destructor(); @@ -76,24 +65,6 @@ private slots: void threadSafety(); }; -tst_QPointer::tst_QPointer() -{ } - -tst_QPointer::~tst_QPointer() -{ } - -void tst_QPointer::initTestCase() -{ } - -void tst_QPointer::cleanupTestCase() -{ } - -void tst_QPointer::init() -{ } - -void tst_QPointer::cleanup() -{ } - void tst_QPointer::constructors() { QPointer p1; -- cgit v0.12 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 From 6260df3316cf7a3756fa8616f5e7f2561acabea1 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Tue, 5 Apr 2011 17:57:29 +1000 Subject: Improve coverage of qpointer autotest Coverage analysis revealed that the assignment test was not exercising code that shortcuts assignment when assigning the value that is already held. Reviewed-by: Rohan McGovern --- tests/auto/qpointer/tst_qpointer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/auto/qpointer/tst_qpointer.cpp b/tests/auto/qpointer/tst_qpointer.cpp index b8a3da2..7bc5fb6 100644 --- a/tests/auto/qpointer/tst_qpointer.cpp +++ b/tests/auto/qpointer/tst_qpointer.cpp @@ -121,6 +121,13 @@ void tst_QPointer::assignment_operators() QCOMPARE(p2, QPointer(object)); QCOMPARE(p1, QPointer(p2)); + // Test assignment with the same pointer that's already guarded + p1 = object; + p2 = p1; + QCOMPARE(p1, QPointer(object)); + QCOMPARE(p2, QPointer(object)); + QCOMPARE(p1, QPointer(p2)); + // Cleanup delete object; } -- cgit v0.12 From fca618cb287a312a1159ce785947f19db4bc5fba Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 6 Apr 2011 11:37:01 +1000 Subject: Prefer QCOMPARE to QVERIFY for comparisons. Reviewed-by: Rohan McGovern --- tests/auto/qpointer/tst_qpointer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/qpointer/tst_qpointer.cpp b/tests/auto/qpointer/tst_qpointer.cpp index 7bc5fb6..9f2c0da 100644 --- a/tests/auto/qpointer/tst_qpointer.cpp +++ b/tests/auto/qpointer/tst_qpointer.cpp @@ -185,13 +185,13 @@ void tst_QPointer::dereference_operators() QPointer p1 = this; QObject *object = p1->me(); - QVERIFY(object == this); + QCOMPARE(object, this); QObject &ref = *p1; - QVERIFY(&ref == this); + QCOMPARE(&ref, this); object = static_cast(p1); - QVERIFY(object == this); + QCOMPARE(object, this); } void tst_QPointer::disconnect() -- cgit v0.12 From d894a4720d652f11cdc791b5f556bd8b29845667 Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 6 Apr 2011 12:12:45 +1000 Subject: Refactor qpointer dereference tests The data method is just another way of dereferencing a QPointer, so test it in the same place as the other dereference operators. Reviewed-by: Rohan McGovern --- tests/auto/qpointer/tst_qpointer.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/tests/auto/qpointer/tst_qpointer.cpp b/tests/auto/qpointer/tst_qpointer.cpp index 9f2c0da..0fb4610 100644 --- a/tests/auto/qpointer/tst_qpointer.cpp +++ b/tests/auto/qpointer/tst_qpointer.cpp @@ -60,7 +60,6 @@ private slots: void dereference_operators(); void disconnect(); void castDuringDestruction(); - void data() const; void dataSignature() const; void threadSafety(); }; @@ -183,15 +182,23 @@ void tst_QPointer::isNull() void tst_QPointer::dereference_operators() { QPointer p1 = this; + QPointer p2; + // operator->() -- only makes sense if not null QObject *object = p1->me(); QCOMPARE(object, this); + // operator*() -- only makes sense if not null QObject &ref = *p1; QCOMPARE(&ref, this); - object = static_cast(p1); - QCOMPARE(object, this); + // operator T*() + QCOMPARE(static_cast(p1), this); + QCOMPARE(static_cast(p2), static_cast(0)); + + // data() + QCOMPARE(p1.data(), this); + QCOMPARE(p2.data(), static_cast(0)); } void tst_QPointer::disconnect() @@ -302,22 +309,6 @@ void tst_QPointer::castDuringDestruction() } } -void tst_QPointer::data() const -{ - /* Check value of a default constructed object. */ - { - QPointer p; - QCOMPARE(p.data(), static_cast(0)); - } - - /* Check value of a default constructed object. */ - { - QObject *const object = new QObject(); - QPointer p(object); - QCOMPARE(p.data(), object); - } -} - void tst_QPointer::dataSignature() const { /* data() should be const. */ -- cgit v0.12 From 7f6230cfff222fe938d333ee19b94e339257b1ba Mon Sep 17 00:00:00 2001 From: Jason McDonald Date: Wed, 6 Apr 2011 12:57:55 +1000 Subject: Remove test for compiler correctness Unit tests are supposed to verify Qt, verifying the compiler is a different task entirely. Reviewed-by: Rohan McGovern --- tests/auto/qpointer/tst_qpointer.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/auto/qpointer/tst_qpointer.cpp b/tests/auto/qpointer/tst_qpointer.cpp index 0fb4610..67579fd 100644 --- a/tests/auto/qpointer/tst_qpointer.cpp +++ b/tests/auto/qpointer/tst_qpointer.cpp @@ -60,7 +60,6 @@ private slots: void dereference_operators(); void disconnect(); void castDuringDestruction(); - void dataSignature() const; void threadSafety(); }; @@ -309,22 +308,6 @@ void tst_QPointer::castDuringDestruction() } } -void tst_QPointer::dataSignature() const -{ - /* data() should be const. */ - { - const QPointer p; - p.data(); - } - - /* The return type should be T. */ - { - const QPointer p; - /* If the types differs, the QCOMPARE will fail to instansiate. */ - QCOMPARE(p.data(), static_cast(0)); - } -} - class TestRunnable : public QObject, public QRunnable { void run() { QPointer obj1 = new QObject; -- cgit v0.12