summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qscopedpointer.h34
-rw-r--r--tests/auto/qscopedpointer/tst_qscopedpointer.cpp27
2 files changed, 59 insertions, 2 deletions
diff --git a/src/corelib/tools/qscopedpointer.h b/src/corelib/tools/qscopedpointer.h
index 769ad10..344964b 100644
--- a/src/corelib/tools/qscopedpointer.h
+++ b/src/corelib/tools/qscopedpointer.h
@@ -113,12 +113,12 @@ public:
return d;
}
- inline bool operator==(const QScopedPointer<T> &other) const
+ inline bool operator==(const QScopedPointer<T, Cleanup> &other) const
{
return d == other.d;
}
- inline bool operator!=(const QScopedPointer<T> &other) const
+ inline bool operator!=(const QScopedPointer<T, Cleanup> &other) const
{
return d != other.d;
}
@@ -194,6 +194,16 @@ public:
return this->d[i];
}
+ inline bool operator==(const QScopedArrayPointer<T, Cleanup> &other) const
+ {
+ return this->d == other.d;
+ }
+
+ inline bool operator!=(const QScopedArrayPointer<T, Cleanup> &other) const
+ {
+ return this->d != other.d;
+ }
+
private:
Q_DISABLE_COPY(QScopedArrayPointer)
};
@@ -214,6 +224,16 @@ public:
return this->d;
}
+ inline bool operator==(const QCustomScopedPointer<T, Cleanup> &other) const
+ {
+ return this->d == other.d;
+ }
+
+ inline bool operator!=(const QCustomScopedPointer<T, Cleanup> &other) const
+ {
+ return this->d != other.d;
+ }
+
private:
Q_DISABLE_COPY(QCustomScopedPointer)
};
@@ -258,6 +278,16 @@ public:
QScopedPointerSharedDeleter<T>::cleanup(oldD);
}
+ inline bool operator==(const QScopedSharedPointer<T> &other) const
+ {
+ return this->d == other.d;
+ }
+
+ inline bool operator!=(const QScopedSharedPointer<T> &other) const
+ {
+ return this->d != other.d;
+ }
+
private:
Q_DISABLE_COPY(QScopedSharedPointer)
};
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"