summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2010-11-02 14:20:37 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-11-03 10:50:48 (GMT)
commitd12681a4cf1227d0e92fc7cf12aa3977e6ffe3fe (patch)
tree32306cd47731503f85a3d88881a5e28901506432
parent9ff533aa0ddf944b73b0c29193fc9936c644142e (diff)
downloadQt-d12681a4cf1227d0e92fc7cf12aa3977e6ffe3fe.zip
Qt-d12681a4cf1227d0e92fc7cf12aa3977e6ffe3fe.tar.gz
Qt-d12681a4cf1227d0e92fc7cf12aa3977e6ffe3fe.tar.bz2
Containers: add member-swap
Member-swap is required by the STL Sequence concept, but is also needed to write exception-safe code. Merge-request: 871 Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
-rw-r--r--src/corelib/tools/qbitarray.cpp7
-rw-r--r--src/corelib/tools/qbitarray.h2
-rw-r--r--src/corelib/tools/qbytearray.cpp7
-rw-r--r--src/corelib/tools/qbytearray.h2
-rw-r--r--src/corelib/tools/qcontiguouscache.cpp7
-rw-r--r--src/corelib/tools/qcontiguouscache.h1
-rw-r--r--src/corelib/tools/qhash.cpp13
-rw-r--r--src/corelib/tools/qhash.h2
-rw-r--r--src/corelib/tools/qlinkedlist.cpp7
-rw-r--r--src/corelib/tools/qlinkedlist.h1
-rw-r--r--src/corelib/tools/qlist.cpp7
-rw-r--r--src/corelib/tools/qlist.h1
-rw-r--r--src/corelib/tools/qmap.cpp13
-rw-r--r--src/corelib/tools/qmap.h2
-rw-r--r--src/corelib/tools/qqueue.cpp8
-rw-r--r--src/corelib/tools/qqueue.h1
-rw-r--r--src/corelib/tools/qset.h1
-rw-r--r--src/corelib/tools/qset.qdoc7
-rw-r--r--src/corelib/tools/qstack.cpp8
-rw-r--r--src/corelib/tools/qstack.h1
-rw-r--r--src/corelib/tools/qstring.cpp7
-rw-r--r--src/corelib/tools/qstring.h1
-rw-r--r--src/corelib/tools/qvector.cpp7
-rw-r--r--src/corelib/tools/qvector.h1
-rw-r--r--src/gui/painting/qpolygon.cpp14
-rw-r--r--src/gui/painting/qpolygon.h3
-rw-r--r--tests/auto/qbitarray/tst_qbitarray.cpp9
-rw-r--r--tests/auto/qbytearray/tst_qbytearray.cpp9
-rw-r--r--tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp13
-rw-r--r--tests/auto/qhash/tst_qhash.cpp11
-rw-r--r--tests/auto/qlist/tst_qlist.cpp7
-rw-r--r--tests/auto/qmap/tst_qmap.cpp12
-rw-r--r--tests/auto/qpolygon/tst_qpolygon.cpp10
-rw-r--r--tests/auto/qset/tst_qset.cpp11
-rw-r--r--tests/auto/qstring/tst_qstring.cpp11
-rw-r--r--tests/auto/qvector/tst_qvector.cpp12
36 files changed, 236 insertions, 0 deletions
diff --git a/src/corelib/tools/qbitarray.cpp b/src/corelib/tools/qbitarray.cpp
index 04018ba..a1ad787 100644
--- a/src/corelib/tools/qbitarray.cpp
+++ b/src/corelib/tools/qbitarray.cpp
@@ -418,6 +418,13 @@ void QBitArray::fill(bool value, int begin, int end)
this bit array.
*/
+/*! \fn void QBitArray::swap(QBitArray &other)
+ \since 4.8
+
+ Swaps bit array \a other with this bit array. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QBitArray::operator==(const QBitArray &other) const
Returns true if \a other is equal to this bit array; otherwise
diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h
index bd79904..ddda5e7 100644
--- a/src/corelib/tools/qbitarray.h
+++ b/src/corelib/tools/qbitarray.h
@@ -68,6 +68,8 @@ public:
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QBitArray &other) { qSwap(d, other.d); }
+
inline int size() const { return (d.size() << 3) - *d.constData(); }
inline int count() const { return (d.size() << 3) - *d.constData(); }
int count(bool on) const;
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 6ba9fd3..dc2e8e9 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -904,6 +904,13 @@ QByteArray &QByteArray::operator=(const char *str)
return *this;
}
+/*! \fn void QByteArray::swap(QByteArray &other)
+ \since 4.8
+
+ Swaps byte array \a other with this byte array. This operation is very
+ fast and never fails.
+*/
+
/*! \fn int QByteArray::size() const
Returns the number of bytes in this byte array.
diff --git a/src/corelib/tools/qbytearray.h b/src/corelib/tools/qbytearray.h
index 3cdcaab..b625f4c 100644
--- a/src/corelib/tools/qbytearray.h
+++ b/src/corelib/tools/qbytearray.h
@@ -149,6 +149,8 @@ public:
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QByteArray &other) { qSwap(d, other.d); }
+
inline int size() const;
bool isEmpty() const;
void resize(int size);
diff --git a/src/corelib/tools/qcontiguouscache.cpp b/src/corelib/tools/qcontiguouscache.cpp
index 3ba5186..7880bd3 100644
--- a/src/corelib/tools/qcontiguouscache.cpp
+++ b/src/corelib/tools/qcontiguouscache.cpp
@@ -194,6 +194,13 @@ MyRecord record(int row) const
Assigns \a other to this cache and returns a reference to this cache.
*/
+/*! \fn void QContiguousCache::swap(QContiguousCache<T> &other)
+ \since 4.8
+
+ Swaps cache \a other with this cache. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QContiguousCache::operator==(const QContiguousCache<T> &other) const
Returns true if \a other is equal to this cache; otherwise returns false.
diff --git a/src/corelib/tools/qcontiguouscache.h b/src/corelib/tools/qcontiguouscache.h
index 4c1a846..3d0a159 100644
--- a/src/corelib/tools/qcontiguouscache.h
+++ b/src/corelib/tools/qcontiguouscache.h
@@ -114,6 +114,7 @@ public:
inline QContiguousCache<T> &operator=(QContiguousCache<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QContiguousCache<T> &other) { qSwap(d, other.d); }
bool operator==(const QContiguousCache<T> &other) const;
inline bool operator!=(const QContiguousCache<T> &other) const { return !(*this == other); }
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 2971c06..5a8057d 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -730,6 +730,19 @@ void QHashData::checkSanity()
Assigns \a other to this hash and returns a reference to this hash.
*/
+/*! \fn void QHash::swap(QHash<Key, T> &other)
+ \since 4.8
+
+ Swaps hash \a other with this hash. This operation is very
+ fast and never fails.
+*/
+
+/*! \fn void QMultiHash::swap(QMultiHash<Key, T> &other)
+
+ Swaps hash \a other with this hash. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QHash::operator==(const QHash<Key, T> &other) const
Returns true if \a other is equal to this hash; otherwise returns
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 992ff33..21fca2d 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -287,6 +287,7 @@ public:
inline QHash<Key, T> &operator=(QHash<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QHash<Key, T> &other) { qSwap(d, other.d); }
bool operator==(const QHash<Key, T> &other) const;
inline bool operator!=(const QHash<Key, T> &other) const { return !(*this == other); }
@@ -925,6 +926,7 @@ class QMultiHash : public QHash<Key, T>
public:
QMultiHash() {}
QMultiHash(const QHash<Key, T> &other) : QHash<Key, T>(other) {}
+ inline void swap(QMultiHash<Key, T> &other) { QHash<Key, T>::swap(other); } // prevent QMultiHash<->QHash swaps
inline typename QHash<Key, T>::iterator replace(const Key &key, const T &value)
{ return QHash<Key, T>::insert(key, value); }
diff --git a/src/corelib/tools/qlinkedlist.cpp b/src/corelib/tools/qlinkedlist.cpp
index 7213c6e..7b452fc 100644
--- a/src/corelib/tools/qlinkedlist.cpp
+++ b/src/corelib/tools/qlinkedlist.cpp
@@ -147,6 +147,13 @@ QLinkedListData QLinkedListData::shared_null = {
list.
*/
+/*! \fn void QLinkedList::swap(QLinkedList<T> &other)
+ \since 4.8
+
+ Swaps list \a other with this list. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QLinkedList::operator==(const QLinkedList<T> &other) const
Returns true if \a other is equal to this list; otherwise returns
diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h
index c087944..849bfd3 100644
--- a/src/corelib/tools/qlinkedlist.h
+++ b/src/corelib/tools/qlinkedlist.h
@@ -89,6 +89,7 @@ public:
inline QLinkedList<T> &operator=(QLinkedList<T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QLinkedList<T> &other) { qSwap(d, other.d); }
bool operator==(const QLinkedList<T> &l) const;
inline bool operator!=(const QLinkedList<T> &l) const { return !(*this == l); }
diff --git a/src/corelib/tools/qlist.cpp b/src/corelib/tools/qlist.cpp
index 9ba3768..5706171 100644
--- a/src/corelib/tools/qlist.cpp
+++ b/src/corelib/tools/qlist.cpp
@@ -602,6 +602,13 @@ void **QListData::erase(void **xi)
list.
*/
+/*! \fn void QList::swap(QList<T> &other)
+ \since 4.8
+
+ Swaps list \a other with this list. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QList::operator==(const QList<T> &other) const
Returns true if \a other is equal to this list; otherwise returns
diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h
index 8f988d6..b1fcabf 100644
--- a/src/corelib/tools/qlist.h
+++ b/src/corelib/tools/qlist.h
@@ -126,6 +126,7 @@ public:
inline QList &operator=(QList &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QList<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QList(std::initializer_list<T> args) : d(&QListData::shared_null)
{ d->ref.ref(); qCopy(args.begin(), args.end(), std::back_inserter(*this)); }
diff --git a/src/corelib/tools/qmap.cpp b/src/corelib/tools/qmap.cpp
index 3143ee4..7b814b3 100644
--- a/src/corelib/tools/qmap.cpp
+++ b/src/corelib/tools/qmap.cpp
@@ -404,6 +404,19 @@ void QMapData::dump()
Assigns \a other to this map and returns a reference to this map.
*/
+/*! \fn void QMap::swap(QMap<Key, T> &other)
+ \since 4.8
+
+ Swaps map \a other with this map. This operation is very
+ fast and never fails.
+*/
+
+/*! \fn void QMultiMap::swap(QMultiMap<Key, T> &other)
+
+ Swaps map \a other with this map. This operation is very
+ fast and never fails.
+*/
+
/*! \fn bool QMap::operator==(const QMap<Key, T> &other) const
Returns true if \a other is equal to this map; otherwise returns
diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h
index ce8fd75..2897529 100644
--- a/src/corelib/tools/qmap.h
+++ b/src/corelib/tools/qmap.h
@@ -189,6 +189,7 @@ public:
inline QMap<Key, T> &operator=(QMap<Key, T> &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QMap<Key, T> &other) { qSwap(d, other.d); }
#ifndef QT_NO_STL
explicit QMap(const typename std::map<Key, T> &other);
std::map<Key, T> toStdMap() const;
@@ -973,6 +974,7 @@ class QMultiMap : public QMap<Key, T>
public:
QMultiMap() {}
QMultiMap(const QMap<Key, T> &other) : QMap<Key, T>(other) {}
+ inline void swap(QMultiMap<Key, T> &other) { QMap<Key, T>::swap(other); }
inline typename QMap<Key, T>::iterator replace(const Key &key, const T &value)
{ return QMap<Key, T>::insert(key, value); }
diff --git a/src/corelib/tools/qqueue.cpp b/src/corelib/tools/qqueue.cpp
index 849bb0b..3602695 100644
--- a/src/corelib/tools/qqueue.cpp
+++ b/src/corelib/tools/qqueue.cpp
@@ -91,6 +91,14 @@
*/
/*!
+ \fn void QQueue::swap(QQueue<T> &other)
+ \since 4.8
+
+ Swaps queue \a other with this queue. This operation is very
+ fast and never fails.
+*/
+
+/*!
\fn void QQueue::enqueue(const T& t)
Adds value \a t to the tail of the queue.
diff --git a/src/corelib/tools/qqueue.h b/src/corelib/tools/qqueue.h
index c29134b..4ef1a61 100644
--- a/src/corelib/tools/qqueue.h
+++ b/src/corelib/tools/qqueue.h
@@ -56,6 +56,7 @@ class QQueue : public QList<T>
public:
inline QQueue() {}
inline ~QQueue() {}
+ inline void swap(QQueue<T> &other) { QList<T>::swap(other); } // prevent QList<->QQueue swaps
inline void enqueue(const T &t) { QList<T>::append(t); }
inline T dequeue() { return QList<T>::takeFirst(); }
inline T &head() { return QList<T>::first(); }
diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h
index dc3c45a..472078f 100644
--- a/src/corelib/tools/qset.h
+++ b/src/corelib/tools/qset.h
@@ -65,6 +65,7 @@ public:
inline QSet<T> &operator=(QSet<T> &&other)
{ qSwap(q_hash, other.q_hash); return *this; }
#endif
+ inline void swap(QSet<T> &other) { q_hash.swap(other.q_hash); }
inline bool operator==(const QSet<T> &other) const
{ return q_hash == other.q_hash; }
diff --git a/src/corelib/tools/qset.qdoc b/src/corelib/tools/qset.qdoc
index 0bc2d2d..57368f0 100644
--- a/src/corelib/tools/qset.qdoc
+++ b/src/corelib/tools/qset.qdoc
@@ -123,6 +123,13 @@
*/
/*!
+ \fn void QSet::swap(QSet<T> &other)
+
+ Swaps set \a other with this set. This operation is very fast and
+ never fails.
+*/
+
+/*!
\fn bool QSet::operator==(const QSet<T> &other) const
Returns true if the \a other set is equal to this set; otherwise
diff --git a/src/corelib/tools/qstack.cpp b/src/corelib/tools/qstack.cpp
index fa14900..b42fe3b 100644
--- a/src/corelib/tools/qstack.cpp
+++ b/src/corelib/tools/qstack.cpp
@@ -91,6 +91,14 @@
*/
/*!
+ \fn void QStack::swap(QStack<T> &other)
+ \since 4.8
+
+ Swaps stack \a other with this stack. This operation is very fast and
+ never fails.
+*/
+
+/*!
\fn void QStack::push(const T& t)
Adds element \a t to the top of the stack.
diff --git a/src/corelib/tools/qstack.h b/src/corelib/tools/qstack.h
index 526c705..6ddc381 100644
--- a/src/corelib/tools/qstack.h
+++ b/src/corelib/tools/qstack.h
@@ -56,6 +56,7 @@ class QStack : public QVector<T>
public:
inline QStack() {}
inline ~QStack() {}
+ inline void swap(QStack<T> &other) { QVector<T>::swap(other); } // prevent QVector<->QStack swaps
inline void push(const T &t) { QVector<T>::append(t); }
T pop();
T &top();
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index 2737574..a3d89f2 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -1174,6 +1174,13 @@ QString::QString(QChar ch)
*/
+/*! \fn void QString::swap(QString &other)
+ \since 4.8
+
+ Swaps string \a other with this string. This operation is very fast and
+ never fails.
+*/
+
/*! \fn void QString::detach()
\internal
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 589fdc2..07f43ca 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -108,6 +108,7 @@ public:
inline QString &operator=(QString &&other)
{ qSwap(d, other.d); return *this; }
#endif
+ inline void swap(QString &other) { qSwap(d, other.d); }
inline int size() const { return d->size; }
inline int count() const { return d->size; }
inline int length() const;
diff --git a/src/corelib/tools/qvector.cpp b/src/corelib/tools/qvector.cpp
index 3a13540..0497211 100644
--- a/src/corelib/tools/qvector.cpp
+++ b/src/corelib/tools/qvector.cpp
@@ -285,6 +285,13 @@ int QVectorData::grow(int sizeofTypedData, int size, int sizeofT, bool excessive
vector.
*/
+/*! \fn void QVector::swap(QVector<T> &other)
+ \since 4.8
+
+ Swaps vector \a other with this vector. This operation is very fast and
+ never fails.
+*/
+
/*! \fn bool QVector::operator==(const QVector<T> &other) const
Returns true if \a other is equal to this vector; otherwise
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index c16aefb..4044a66 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -125,6 +125,7 @@ public:
inline QVector<T> operator=(QVector<T> &&other)
{ qSwap(p, other.p); return *this; }
#endif
+ inline void swap(QVector<T> &other) { qSwap(d, other.d); }
#ifdef Q_COMPILER_INITIALIZER_LISTS
inline QVector(std::initializer_list<T> args);
#endif
diff --git a/src/gui/painting/qpolygon.cpp b/src/gui/painting/qpolygon.cpp
index 2fb52b5..76b11d7 100644
--- a/src/gui/painting/qpolygon.cpp
+++ b/src/gui/painting/qpolygon.cpp
@@ -700,6 +700,20 @@ QPolygon QPolygonF::toPolygon() const
}
/*!
+ \fn void QPolygon::swap(QPolygon &other)
+ \since 4.8
+
+ Swaps polygon \a other with this polygon. This operation is very
+ fast and never fails.
+*/
+
+/*!
+ \fn void QPolygonF::swap(QPolygonF &other)
+ Swaps polygon \a other with this polygon. This operation is very
+ fast and never fails.
+*/
+
+/*!
Returns the polygon as a QVariant
*/
QPolygon::operator QVariant() const
diff --git a/src/gui/painting/qpolygon.h b/src/gui/painting/qpolygon.h
index 7a49e29..5baffc8 100644
--- a/src/gui/painting/qpolygon.h
+++ b/src/gui/painting/qpolygon.h
@@ -67,6 +67,8 @@ public:
inline QPolygon(const QVector<QPoint> &v) : QVector<QPoint>(v) {}
QPolygon(const QRect &r, bool closed=false);
QPolygon(int nPoints, const int *points);
+ inline void swap(QPolygon &other) { QVector<QPoint>::swap(other); } // prevent QVector<QPoint><->QPolygon swaps
+
operator QVariant() const;
void translate(int dx, int dy);
@@ -139,6 +141,7 @@ public:
inline QPolygonF(const QVector<QPointF> &v) : QVector<QPointF>(v) {}
QPolygonF(const QRectF &r);
QPolygonF(const QPolygon &a);
+ inline void swap(QPolygonF &other) { QVector<QPointF>::swap(other); } // prevent QVector<QPointF><->QPolygonF swaps
inline void translate(qreal dx, qreal dy);
void translate(const QPointF &offset);
diff --git a/tests/auto/qbitarray/tst_qbitarray.cpp b/tests/auto/qbitarray/tst_qbitarray.cpp
index 30f4f58..7b9543e 100644
--- a/tests/auto/qbitarray/tst_qbitarray.cpp
+++ b/tests/auto/qbitarray/tst_qbitarray.cpp
@@ -88,6 +88,7 @@ private slots:
void countBits();
void countBits2();
void isEmpty();
+ void swap();
void fill();
void toggleBit_data();
void toggleBit();
@@ -269,6 +270,14 @@ void tst_QBitArray::isEmpty()
QVERIFY(a1.size() == 2);
}
+void tst_QBitArray::swap()
+{
+ QBitArray b1 = QStringToQBitArray("1"), b2 = QStringToQBitArray("10");
+ b1.swap(b2);
+ QCOMPARE(b1,QStringToQBitArray("10"));
+ QCOMPARE(b2,QStringToQBitArray("1"));
+}
+
void tst_QBitArray::fill()
{
int N = 64;
diff --git a/tests/auto/qbytearray/tst_qbytearray.cpp b/tests/auto/qbytearray/tst_qbytearray.cpp
index 0dc2282..c291c6a 100644
--- a/tests/auto/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/qbytearray/tst_qbytearray.cpp
@@ -71,6 +71,7 @@ public slots:
void init();
void cleanup();
private slots:
+ void swap();
void qCompress_data();
#ifndef QT_NO_COMPRESS
void qCompress();
@@ -453,6 +454,14 @@ void tst_QByteArray::split()
QCOMPARE(list.count(), size);
}
+void tst_QByteArray::swap()
+{
+ QByteArray b1 = "b1", b2 = "b2";
+ b1.swap(b2);
+ QCOMPARE(b1, QByteArray("b2"));
+ QCOMPARE(b2, QByteArray("b1"));
+}
+
void tst_QByteArray::base64_data()
{
QTest::addColumn<QByteArray>("rawdata");
diff --git a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp
index f64e815..568ba06 100644
--- a/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp
+++ b/tests/auto/qcontiguouscache/tst_qcontiguouscache.cpp
@@ -55,6 +55,8 @@ public:
virtual ~tst_QContiguousCache() {}
private slots:
void empty();
+ void swap();
+
void append_data();
void append();
@@ -99,6 +101,17 @@ void tst_QContiguousCache::empty()
QCOMPARE(c.capacity(), 10);
}
+void tst_QContiguousCache::swap()
+{
+ QContiguousCache<int> c1(10), c2(100);
+ c1.append(1);
+ c1.swap(c2);
+ QCOMPARE(c1.capacity(), 100);
+ QCOMPARE(c1.count(), 0 );
+ QCOMPARE(c2.capacity(), 10 );
+ QCOMPARE(c2.count(), 1 );
+}
+
void tst_QContiguousCache::append_data()
{
QTest::addColumn<int>("start");
diff --git a/tests/auto/qhash/tst_qhash.cpp b/tests/auto/qhash/tst_qhash.cpp
index 3a7b54a..ea6e010 100644
--- a/tests/auto/qhash/tst_qhash.cpp
+++ b/tests/auto/qhash/tst_qhash.cpp
@@ -60,6 +60,7 @@ private slots:
void erase();
void key();
+ void swap();
void count(); // copied from tst_QMap
void clear(); // copied from tst_QMap
void empty(); // copied from tst_QMap
@@ -553,6 +554,16 @@ void tst_QHash::key()
}
}
+void tst_QHash::swap()
+{
+ QHash<int,QString> h1, h2;
+ h1[0] = "h1[0]";
+ h2[1] = "h2[1]";
+ h1.swap(h2);
+ QCOMPARE(h1.value(1),QLatin1String("h2[1]"));
+ QCOMPARE(h2.value(0),QLatin1String("h1[0]"));
+}
+
// copied from tst_QMap
void tst_QHash::clear()
{
diff --git a/tests/auto/qlist/tst_qlist.cpp b/tests/auto/qlist/tst_qlist.cpp
index 14b8057..9ab7cf7 100644
--- a/tests/auto/qlist/tst_qlist.cpp
+++ b/tests/auto/qlist/tst_qlist.cpp
@@ -499,6 +499,13 @@ void tst_QList::swap() const
// swap again
list.swap(1, 2);
QCOMPARE(list, QList<QString>() << "baz" << "foo" << "bar");
+
+ QList<QString> list2;
+ list2 << "alpha" << "beta";
+
+ list.swap(list2);
+ QCOMPARE(list, QList<QString>() << "alpha" << "beta");
+ QCOMPARE(list2, QList<QString>() << "baz" << "foo" << "bar");
}
void tst_QList::takeAt() const
diff --git a/tests/auto/qmap/tst_qmap.cpp b/tests/auto/qmap/tst_qmap.cpp
index a1b8de7..311b0b6 100644
--- a/tests/auto/qmap/tst_qmap.cpp
+++ b/tests/auto/qmap/tst_qmap.cpp
@@ -65,6 +65,8 @@ private slots:
void beginEnd();
void key();
+ void swap();
+
void operator_eq();
void empty();
@@ -392,6 +394,16 @@ void tst_QMap::key()
}
}
+void tst_QMap::swap()
+{
+ QMap<int,QString> m1, m2;
+ m1[0] = "m1[0]";
+ m2[1] = "m2[1]";
+ m1.swap(m2);
+ QCOMPARE(m1.value(1),QLatin1String("m2[1]"));
+ QCOMPARE(m2.value(0),QLatin1String("m1[0]"));
+}
+
void tst_QMap::operator_eq()
{
{
diff --git a/tests/auto/qpolygon/tst_qpolygon.cpp b/tests/auto/qpolygon/tst_qpolygon.cpp
index eb7cbd5..a79c0c8 100644
--- a/tests/auto/qpolygon/tst_qpolygon.cpp
+++ b/tests/auto/qpolygon/tst_qpolygon.cpp
@@ -63,6 +63,7 @@ public:
private slots:
void makeEllipse();
+ void swap();
};
tst_QPolygon::tst_QPolygon()
@@ -91,5 +92,14 @@ void tst_QPolygon::makeEllipse()
QVERIFY( !err );
}
+void tst_QPolygon::swap()
+{
+ QPolygon p1(QVector<QPoint>() << QPoint(0,0) << QPoint(10,10) << QPoint(-10,10));
+ QPolygon p2(QVector<QPoint>() << QPoint(0,0) << QPoint( 0,10) << QPoint( 10,10) << QPoint(10,0));
+ p1.swap(p2);
+ QCOMPARE(p1.count(),4);
+ QCOMPARE(p2.count(),3);
+}
+
QTEST_APPLESS_MAIN(tst_QPolygon)
#include "tst_qpolygon.moc"
diff --git a/tests/auto/qset/tst_qset.cpp b/tests/auto/qset/tst_qset.cpp
index 319cdf4..6f377f5 100644
--- a/tests/auto/qset/tst_qset.cpp
+++ b/tests/auto/qset/tst_qset.cpp
@@ -65,6 +65,7 @@ public:
private slots:
void operator_eq();
+ void swap();
void size();
void capacity();
void reserve();
@@ -145,6 +146,16 @@ void tst_QSet::operator_eq()
}
}
+void tst_QSet::swap()
+{
+ QSet<int> s1, s2;
+ s1.insert(1);
+ s2.insert(2);
+ s1.swap(s2);
+ QCOMPARE(*s1.begin(),2);
+ QCOMPARE(*s2.begin(),1);
+}
+
void tst_QSet::size()
{
QSet<int> set;
diff --git a/tests/auto/qstring/tst_qstring.cpp b/tests/auto/qstring/tst_qstring.cpp
index 003332c..c3f14f2 100644
--- a/tests/auto/qstring/tst_qstring.cpp
+++ b/tests/auto/qstring/tst_qstring.cpp
@@ -114,6 +114,7 @@ private slots:
void remove_string();
void remove_regexp_data();
void remove_regexp();
+ void swap();
void prepend();
void prepend_bytearray_data();
void prepend_bytearray();
@@ -1852,6 +1853,16 @@ void tst_QString::operator_pluseq_bytearray()
}
}
+void tst_QString::swap()
+{
+ QString s1, s2;
+ s1 = "s1";
+ s2 = "s2";
+ s1.swap(s2);
+ QCOMPARE(s1,QLatin1String("s2"));
+ QCOMPARE(s2,QLatin1String("s1"));
+}
+
void tst_QString::prepend()
{
QString a;
diff --git a/tests/auto/qvector/tst_qvector.cpp b/tests/auto/qvector/tst_qvector.cpp
index a04ce60..b3decc8 100644
--- a/tests/auto/qvector/tst_qvector.cpp
+++ b/tests/auto/qvector/tst_qvector.cpp
@@ -80,6 +80,7 @@ private slots:
void remove() const;
void size() const;
void startsWith() const;
+ void swap() const;
void toList() const;
void toStdVector() const;
void value() const;
@@ -579,6 +580,17 @@ void tst_QVector::startsWith() const
QVERIFY(myvec.startsWith(1));
}
+void tst_QVector::swap() const
+{
+ QVector<int> v1, v2;
+ v1 << 1 << 2 << 3;
+ v2 << 4 << 5 << 6;
+
+ v1.swap(v2);
+ QCOMPARE(v1,QVector<int>() << 4 << 5 << 6);
+ QCOMPARE(v2,QVector<int>() << 1 << 2 << 3);
+}
+
void tst_QVector::toList() const
{
QVector<QString> myvec;