diff options
author | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-08-11 09:52:05 (GMT) |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@digia.com> | 2009-08-11 09:52:05 (GMT) |
commit | 0ec7c55b241d7f281e49edbd7b496f7b5be01305 (patch) | |
tree | d0c9d4741327fd1dc57a0ec4755acc7977d5b79c /tests/auto/qscopedpointer/tst_qscopedpointer.cpp | |
parent | f79228b71b05d28b83014f262bc47e3fe9557a14 (diff) | |
parent | 7f7965212438405c64566416c0f8972f06d6dcd1 (diff) | |
download | Qt-0ec7c55b241d7f281e49edbd7b496f7b5be01305.zip Qt-0ec7c55b241d7f281e49edbd7b496f7b5be01305.tar.gz Qt-0ec7c55b241d7f281e49edbd7b496f7b5be01305.tar.bz2 |
Merge branch 'master' of git@scm.dev.troll.no:qt/qt-s60-public
Diffstat (limited to 'tests/auto/qscopedpointer/tst_qscopedpointer.cpp')
-rw-r--r-- | tests/auto/qscopedpointer/tst_qscopedpointer.cpp | 99 |
1 files changed, 63 insertions, 36 deletions
diff --git a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp index e9b1cce..7f571a9 100644 --- a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp +++ b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp @@ -54,34 +54,35 @@ class tst_QScopedPointer : public QObject Q_OBJECT private Q_SLOTS: - void defaultConstructor() const; - void dataOnDefaultConstructed() const; - void useSubClassInConstructor() const; - void dataOnValue() const; - void dataSignature() const; - void reset() const; - void dereferenceOperator() const; - void dereferenceOperatorSignature() const; - void pointerOperator() const; - void pointerOperatorSignature() const; - void negationOperator() const; - void negationOperatorSignature() const; - void operatorBool() const; - void operatorBoolSignature() const; - void isNull() const; - void isNullSignature() const; - void objectSize() const; - // TODO instansiate on const object + void defaultConstructor(); + void dataOnDefaultConstructed(); + void useSubClassInConstructor(); + void dataOnValue(); + void dataSignature(); + void reset(); + void dereferenceOperator(); + void dereferenceOperatorSignature(); + void pointerOperator(); + void pointerOperatorSignature(); + void negationOperator(); + void negationOperatorSignature(); + void operatorBool(); + void operatorBoolSignature(); + void isNull(); + void isNullSignature(); + void objectSize(); + void comparison(); + // TODO instanciate on const object }; -void tst_QScopedPointer::defaultConstructor() const +void tst_QScopedPointer::defaultConstructor() { /* Check that the members, one, is correctly initialized. */ QScopedPointer<int> p; QCOMPARE(p.data(), static_cast<int *>(0)); } -void tst_QScopedPointer::dataOnDefaultConstructed() const +void tst_QScopedPointer::dataOnDefaultConstructed() { QScopedPointer<int> p; @@ -96,13 +97,13 @@ class MySubClass : public MyClass { }; -void tst_QScopedPointer::useSubClassInConstructor() const +void tst_QScopedPointer::useSubClassInConstructor() { /* Use a syntax which users typically would do. */ QScopedPointer<MyClass> p(new MyClass()); } -void tst_QScopedPointer::dataOnValue() const +void tst_QScopedPointer::dataOnValue() { int *const rawPointer = new int(5); QScopedPointer<int> p(rawPointer); @@ -110,14 +111,14 @@ void tst_QScopedPointer::dataOnValue() const QCOMPARE(p.data(), rawPointer); } -void tst_QScopedPointer::dataSignature() const +void tst_QScopedPointer::dataSignature() { const QScopedPointer<int> p; /* data() should be const. */ p.data(); } -void tst_QScopedPointer::reset() const +void tst_QScopedPointer::reset() { /* Call reset() on a default constructed value. */ { @@ -171,7 +172,7 @@ public: } }; -void tst_QScopedPointer::dereferenceOperator() const +void tst_QScopedPointer::dereferenceOperator() { /* Dereference a basic value. */ { @@ -191,7 +192,7 @@ void tst_QScopedPointer::dereferenceOperator() const } } -void tst_QScopedPointer::dereferenceOperatorSignature() const +void tst_QScopedPointer::dereferenceOperatorSignature() { /* The operator should be const. */ { @@ -218,7 +219,7 @@ public: int value; }; -void tst_QScopedPointer::pointerOperator() const +void tst_QScopedPointer::pointerOperator() { QScopedPointer<AnyForm> p(new AnyForm()); p->value = 5; @@ -226,7 +227,7 @@ void tst_QScopedPointer::pointerOperator() const QCOMPARE(p->value, 5); } -void tst_QScopedPointer::pointerOperatorSignature() const +void tst_QScopedPointer::pointerOperatorSignature() { /* The operator should be const. */ const QScopedPointer<AnyForm> p(new AnyForm); @@ -235,7 +236,7 @@ void tst_QScopedPointer::pointerOperatorSignature() const QVERIFY(p->value); } -void tst_QScopedPointer::negationOperator() const +void tst_QScopedPointer::negationOperator() { /* Invoke on default constructed value. */ { @@ -250,7 +251,7 @@ void tst_QScopedPointer::negationOperator() const } } -void tst_QScopedPointer::negationOperatorSignature() const +void tst_QScopedPointer::negationOperatorSignature() { /* The signature should be const. */ const QScopedPointer<int> p; @@ -260,7 +261,7 @@ void tst_QScopedPointer::negationOperatorSignature() const static_cast<bool>(!p); } -void tst_QScopedPointer::operatorBool() const +void tst_QScopedPointer::operatorBool() { /* Invoke on default constructed value. */ { @@ -275,15 +276,15 @@ void tst_QScopedPointer::operatorBool() const } } -void tst_QScopedPointer::operatorBoolSignature() const +void tst_QScopedPointer::operatorBoolSignature() { /* The signature should be const and return bool. */ const QScopedPointer<int> p; - static_cast<bool>(p); + (void)static_cast<bool>(p); } -void tst_QScopedPointer::isNull() const +void tst_QScopedPointer::isNull() { /* Invoke on default constructed value. */ { @@ -298,7 +299,7 @@ void tst_QScopedPointer::isNull() const } } -void tst_QScopedPointer::isNullSignature() const +void tst_QScopedPointer::isNullSignature() { const QScopedPointer<int> p(new int(69)); @@ -306,11 +307,37 @@ void tst_QScopedPointer::isNullSignature() const static_cast<bool>(p.isNull()); } -void tst_QScopedPointer::objectSize() const +void tst_QScopedPointer::objectSize() { /* The size of QScopedPointer should be the same as one pointer. */ QCOMPARE(sizeof(QScopedPointer<int>), sizeof(void *)); } +void tst_QScopedPointer::comparison() +{ + int *a = new int(42); + int *b = new int(43); + + QScopedPointer<int> pa(a); + QScopedPointer<int> pa2(a); + QScopedPointer<int> pb(b); + + // test equality on equal pointers + QVERIFY(pa == pa2); + QVERIFY(pa2 == pa); + + // test unequality on equal pointers + QVERIFY(!(pa != pa2)); + QVERIFY(!(pa2 != pa)); + + // test on unequal pointers + QVERIFY(!(pa == pb)); + QVERIFY(!(pb == pa)); + QVERIFY(pb != pa); + QVERIFY(pa != pb); + + pa2.take(); +} + QTEST_MAIN(tst_QScopedPointer) #include "tst_qscopedpointer.moc" |