diff options
author | Harald Fernengel <harald@trolltech.com> | 2009-08-10 16:16:16 (GMT) |
---|---|---|
committer | Harald Fernengel <harald@trolltech.com> | 2009-08-10 16:16:16 (GMT) |
commit | 975b75bcda1570adc2aa0d0327c5445b25da1515 (patch) | |
tree | 3723f824a33a2a8a7de83b5d4c0d84ce49b00870 /tests | |
parent | 361e40191a82b69fe7549215bd27db94c05fc083 (diff) | |
download | Qt-975b75bcda1570adc2aa0d0327c5445b25da1515.zip Qt-975b75bcda1570adc2aa0d0327c5445b25da1515.tar.gz Qt-975b75bcda1570adc2aa0d0327c5445b25da1515.tar.bz2 |
Add comparison operators also to subclasses
Compiler would for some reason choose operator bool()
instead when comparing subclasses of QScopedPointer.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qscopedpointer/tst_qscopedpointer.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp index e9b1cce..b8e0f0a 100644 --- a/tests/auto/qscopedpointer/tst_qscopedpointer.cpp +++ b/tests/auto/qscopedpointer/tst_qscopedpointer.cpp @@ -71,6 +71,7 @@ private Q_SLOTS: void isNull() const; void isNullSignature() const; void objectSize() const; + void comparison() const; // TODO instansiate on const object }; @@ -312,5 +313,31 @@ void tst_QScopedPointer::objectSize() const QCOMPARE(sizeof(QScopedPointer<int>), sizeof(void *)); } +void tst_QScopedPointer::comparison() const +{ + 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" |