summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2012-09-11 10:06:05 +0200
committerJędrzej Nowacki <jedrzej.nowacki@digia.com>2014-07-03 10:42:45 +0200
commit7021188778c6eb80a721c8975b68cf6b44444839 (patch)
treec2487b39ea216b3f43980e664f0dd4d74b4c5e5c
parent3fd2f0b7d8c5139eff9020062ed66c897eac32e7 (diff)
Add tests for assignment operator
Change-Id: I3265cb75c4d785faaf1efc183d8c1293dfff9165 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index 97f370f146..575811b2ce 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -178,6 +178,9 @@ private slots:
void copyConstructorInt() const;
void copyConstructorMovable() const;
void copyConstructorCustom() const;
+ void assignmentInt() const;
+ void assignmentMovable() const;
+ void assignmentCustom() const;
void addInt() const;
void addMovable() const;
void addCustom() const;
@@ -444,6 +447,52 @@ void tst_QVector::copyConstructorCustom() const
QCOMPARE(instancesCount, Custom::counter.loadAcquire());
}
+template <class T>
+static inline void testAssignment()
+{
+ QVector<T> v1(5);
+ QCOMPARE(v1.size(), 5);
+ QVERIFY(v1.isDetached());
+
+ QVector<T> v2(7);
+ QCOMPARE(v2.size(), 7);
+ QVERIFY(v2.isDetached());
+
+ QVERIFY(!v1.isSharedWith(v2));
+
+ v1 = v2;
+
+ QVERIFY(!v1.isDetached());
+ QVERIFY(!v2.isDetached());
+ QVERIFY(v1.isSharedWith(v2));
+
+ const void *const data1 = v1.constData();
+ const void *const data2 = v2.constData();
+
+ QCOMPARE(data1, data2);
+
+ v1.clear();
+
+ QVERIFY(v2.isDetached());
+ QVERIFY(!v1.isSharedWith(v2));
+ QCOMPARE((void *)v2.constData(), data2);
+}
+
+void tst_QVector::assignmentInt() const
+{
+ testAssignment<int>();
+}
+
+void tst_QVector::assignmentMovable() const
+{
+ testAssignment<Movable>();
+}
+
+void tst_QVector::assignmentCustom() const
+{
+ testAssignment<Custom>();
+}
+
template<typename T>
void tst_QVector::add() const
{