summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-14 13:04:30 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-14 15:33:28 (GMT)
commit78fbb9cf6ef5e8440f0453ef60bd7845ce418745 (patch)
treea8e784f5e6b509b79d88e6fdd4092c4f89517441 /tests
parenta931fac02fe0430439a351dacc5167ddeca1d4d0 (diff)
downloadQt-78fbb9cf6ef5e8440f0453ef60bd7845ce418745.zip
Qt-78fbb9cf6ef5e8440f0453ef60bd7845ce418745.tar.gz
Qt-78fbb9cf6ef5e8440f0453ef60bd7845ce418745.tar.bz2
Reimplement qSwap and Q_DECLARE_SHARED differently.
This enables the use of Q_DECLARE_SHARED with d-pointers that are QExplicitlySharedDataPointer<PrivateClass>. Also, this enables swapping atomically QSharedPointers. Reviewed-by: Harald Fernengel
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp20
-rw-r--r--tests/auto/qsharedpointer/tst_qsharedpointer.cpp32
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp b/tests/auto/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
index 4cdeb5c..97e57f1 100644
--- a/tests/auto/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
+++ b/tests/auto/qexplicitlyshareddatapointer/tst_qexplicitlyshareddatapointer.cpp
@@ -61,6 +61,7 @@ private Q_SLOTS:
void clone() const;
void data() const;
void reset() const;
+ void swap() const;
};
class MyClass : public QSharedData
@@ -233,6 +234,25 @@ void tst_QExplicitlySharedDataPointer::reset() const
}
}
+void tst_QExplicitlySharedDataPointer::swap() const
+{
+ QExplicitlySharedDataPointer<MyClass> p1(0), p2(new MyClass());
+ QVERIFY(!p1.data());
+ QVERIFY(p2.data());
+
+ p1.swap(p2);
+ QVERIFY(p1.data());
+ QVERIFY(!p2.data());
+
+ p1.swap(p2);
+ QVERIFY(!p1.data());
+ QVERIFY(p2.data());
+
+ qSwap(p1, p2);
+ QVERIFY(p1.data());
+ QVERIFY(!p2.data());
+}
+
QTEST_MAIN(tst_QExplicitlySharedDataPointer)
#include "tst_qexplicitlyshareddatapointer.moc"
diff --git a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
index 58e5401..ab75c91 100644
--- a/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/qsharedpointer/tst_qsharedpointer.cpp
@@ -62,6 +62,7 @@ class tst_QSharedPointer: public QObject
private slots:
void basics_data();
void basics();
+ void swap();
void forwardDeclaration1();
void forwardDeclaration2();
void memoryManagement();
@@ -263,6 +264,37 @@ void tst_QSharedPointer::basics()
// aData is deleted here
}
+void tst_QSharedPointer::swap()
+{
+ QSharedPointer<int> p1, p2(new int(42)), control = p2;
+ QVERIFY(p1 != control);
+ QVERIFY(p1.isNull());
+ QVERIFY(p2 == control);
+ QVERIFY(!p2.isNull());
+ QVERIFY(*p2 == 42);
+
+ p1.swap(p2);
+ QVERIFY(p1 == control);
+ QVERIFY(!p1.isNull());
+ QVERIFY(p2 != control);
+ QVERIFY(p2.isNull());
+ QVERIFY(*p1 == 42);
+
+ p1.swap(p2);
+ QVERIFY(p1 != control);
+ QVERIFY(p1.isNull());
+ QVERIFY(p2 == control);
+ QVERIFY(!p2.isNull());
+ QVERIFY(*p2 == 42);
+
+ qSwap(p1, p2);
+ QVERIFY(p1 == control);
+ QVERIFY(!p1.isNull());
+ QVERIFY(p2 != control);
+ QVERIFY(p2.isNull());
+ QVERIFY(*p1 == 42);
+}
+
class ForwardDeclared;
ForwardDeclared *forwardPointer();
void externalForwardDeclaration();