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