diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2010-11-02 14:20:38 (GMT) |
---|---|---|
committer | Olivier Goffart <olivier.goffart@nokia.com> | 2010-11-03 10:50:48 (GMT) |
commit | 86ea8521c6f145be24c40c799b6b4e8f6e854e2b (patch) | |
tree | bbceb07abeb3f8b974287ea648fd995b4ba8345c /tests | |
parent | d12681a4cf1227d0e92fc7cf12aa3977e6ffe3fe (diff) | |
download | Qt-86ea8521c6f145be24c40c799b6b4e8f6e854e2b.zip Qt-86ea8521c6f145be24c40c799b6b4e8f6e854e2b.tar.gz Qt-86ea8521c6f145be24c40c799b6b4e8f6e854e2b.tar.bz2 |
Add member-swap to shared datatypes that don't have it.
For consistency.
Merge-request: 871
Reviewed-by: Olivier Goffart <olivier.goffart@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qbrush/tst_qbrush.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qicon/tst_qicon.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qimage/tst_qimage.cpp | 15 | ||||
-rw-r--r-- | tests/auto/qkeysequence/tst_qkeysequence.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qpainterpath/tst_qpainterpath.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qpen/tst_qpen.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qpicture/tst_qpicture.cpp | 13 | ||||
-rw-r--r-- | tests/auto/qpixmap/tst_qpixmap.cpp | 16 | ||||
-rw-r--r-- | tests/auto/qregexp/tst_qregexp.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qregion/tst_qregion.cpp | 10 | ||||
-rw-r--r-- | tests/auto/qurl/tst_qurl.cpp | 9 | ||||
-rw-r--r-- | tests/auto/qvariant/tst_qvariant.cpp | 11 |
12 files changed, 140 insertions, 0 deletions
diff --git a/tests/auto/qbrush/tst_qbrush.cpp b/tests/auto/qbrush/tst_qbrush.cpp index 7e94f37..c9be552 100644 --- a/tests/auto/qbrush/tst_qbrush.cpp +++ b/tests/auto/qbrush/tst_qbrush.cpp @@ -76,6 +76,7 @@ private slots: void textures(); + void swap(); void nullBrush(); void isOpaque(); void debug(); @@ -385,6 +386,14 @@ void tst_QBrush::textures() QCOMPARE(image_brush.textureImage(), image_source); } +void tst_QBrush::swap() +{ + QBrush b1(Qt::black), b2(Qt::white); + b1.swap(b2); + QCOMPARE(b1.color(), QColor(Qt::white)); + QCOMPARE(b2.color(), QColor(Qt::black)); +} + void tst_QBrush::nullBrush() { QBrush brush(QColor(100,0,0), Qt::NoBrush); diff --git a/tests/auto/qicon/tst_qicon.cpp b/tests/auto/qicon/tst_qicon.cpp index e68664c..6b35378 100644 --- a/tests/auto/qicon/tst_qicon.cpp +++ b/tests/auto/qicon/tst_qicon.cpp @@ -70,6 +70,7 @@ private slots: void actualSize2(); void svgActualSize(); void isNull(); + void swap(); void bestMatch(); void cacheKey(); void detach(); @@ -259,6 +260,21 @@ void tst_QIcon::isNull() { QVERIFY(iconSupportedFormat.actualSize(QSize(32, 32)).isValid()); } +void tst_QIcon::swap() +{ + QPixmap p1(1, 1), p2(2, 2); + p1.fill(Qt::black); + p2.fill(Qt::black); + + QIcon i1(p1), i2(p2); + const qint64 i1k = i1.cacheKey(); + const qint64 i2k = i2.cacheKey(); + QVERIFY(i1k != i2k); + i1.swap(i2); + QCOMPARE(i1.cacheKey(), i2k); + QCOMPARE(i2.cacheKey(), i1k); +} + void tst_QIcon::bestMatch() { QPixmap p1(1, 1); diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp index 6b8028c..6cce05cd1 100644 --- a/tests/auto/qimage/tst_qimage.cpp +++ b/tests/auto/qimage/tst_qimage.cpp @@ -69,6 +69,7 @@ public: tst_QImage(); private slots: + void swap(); void create(); void createInvalidXPM(); void createFromUChar(); @@ -155,6 +156,20 @@ tst_QImage::tst_QImage() { } +void tst_QImage::swap() +{ + QImage i1( 16, 16, QImage::Format_RGB32 ), i2( 32, 32, QImage::Format_RGB32 ); + i1.fill( Qt::white ); + i2.fill( Qt::black ); + const qint64 i1k = i1.cacheKey(); + const qint64 i2k = i2.cacheKey(); + i1.swap(i2); + QCOMPARE(i1.cacheKey(), i2k); + QCOMPARE(i1.size(), QSize(32,32)); + QCOMPARE(i2.cacheKey(), i1k); + QCOMPARE(i2.size(), QSize(16,16)); +} + // Test if QImage (or any functions called from QImage) throws an // exception when creating an extremely large image. // QImage::create() should return "false" in this case. diff --git a/tests/auto/qkeysequence/tst_qkeysequence.cpp b/tests/auto/qkeysequence/tst_qkeysequence.cpp index 60f022f..256f9f3 100644 --- a/tests/auto/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/qkeysequence/tst_qkeysequence.cpp @@ -112,6 +112,7 @@ public: virtual ~tst_QKeySequence(); private slots: + void swap(); void operatorQString_data(); void operatorQString(); void compareConstructors_data(); @@ -176,6 +177,15 @@ void tst_QKeySequence::initTestCase() qtTranslator->load(":/qt_de"); } +void tst_QKeySequence::swap() +{ + QKeySequence ks1(Qt::CTRL+Qt::Key_O); + QKeySequence ks2(Qt::CTRL+Qt::Key_L); + ks1.swap(ks2); + QCOMPARE(ks1[0], int(Qt::CTRL+Qt::Key_L)); + QCOMPARE(ks2[0], int(Qt::CTRL+Qt::Key_O)); +} + void tst_QKeySequence::operatorQString_data() { QTest::addColumn<int>("modifiers"); diff --git a/tests/auto/qpainterpath/tst_qpainterpath.cpp b/tests/auto/qpainterpath/tst_qpainterpath.cpp index d0cddda..19b3156 100644 --- a/tests/auto/qpainterpath/tst_qpainterpath.cpp +++ b/tests/auto/qpainterpath/tst_qpainterpath.cpp @@ -60,6 +60,8 @@ public: private slots: void getSetCheck(); + void swap(); + void contains_QPointF_data(); void contains_QPointF(); @@ -139,6 +141,17 @@ void tst_QPainterPath::getSetCheck() QCOMPARE(qreal(1.1), obj1.curveThreshold()); } +void tst_QPainterPath::swap() +{ + QPainterPath p1; + p1.addRect( 0, 0,10,10); + QPainterPath p2; + p2.addRect(10,10,10,10); + p1.swap(p2); + QCOMPARE(p1.boundingRect().toRect(), QRect(10,10,10,10)); + QCOMPARE(p2.boundingRect().toRect(), QRect( 0, 0,10,10)); +} + Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(QPointF) Q_DECLARE_METATYPE(QRectF) diff --git a/tests/auto/qpen/tst_qpen.cpp b/tests/auto/qpen/tst_qpen.cpp index b0c2cad..674a520 100644 --- a/tests/auto/qpen/tst_qpen.cpp +++ b/tests/auto/qpen/tst_qpen.cpp @@ -59,6 +59,7 @@ public: private slots: void getSetCheck(); + void swap(); void operator_eq_eq(); void operator_eq_eq_data(); @@ -95,6 +96,14 @@ void tst_QPen::getSetCheck() } } +void tst_QPen::swap() +{ + QPen p1(Qt::black), p2(Qt::white); + p1.swap(p2); + QCOMPARE(p1.color(), QColor(Qt::white)); + QCOMPARE(p2.color(), QColor(Qt::black)); +} + Q_DECLARE_METATYPE(QPen) Q_DECLARE_METATYPE(QBrush) diff --git a/tests/auto/qpicture/tst_qpicture.cpp b/tests/auto/qpicture/tst_qpicture.cpp index 09f6503..10e5961 100644 --- a/tests/auto/qpicture/tst_qpicture.cpp +++ b/tests/auto/qpicture/tst_qpicture.cpp @@ -64,6 +64,7 @@ private slots: void devType(); void paintingActive(); void boundingRect(); + void swap(); void operator_lt_lt(); void save_restore(); @@ -155,6 +156,18 @@ void tst_QPicture::boundingRect() } } +void tst_QPicture::swap() +{ + QPicture p1, p2; + QPainter(&p1).drawLine(0, 0, 5, 5); + QPainter(&p2).drawLine(0, 3, 3, 0); + QCOMPARE(p1.boundingRect(), QRect(0,0,5,5)); + QCOMPARE(p2.boundingRect(), QRect(0,0,3,3)); + p1.swap(p2); + QCOMPARE(p1.boundingRect(), QRect(0,0,3,3)); + QCOMPARE(p2.boundingRect(), QRect(0,0,5,5)); +} + // operator<< and operator>> void tst_QPicture::operator_lt_lt() { diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp index fdf8311..551e261 100644 --- a/tests/auto/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/qpixmap/tst_qpixmap.cpp @@ -95,6 +95,8 @@ public slots: void cleanup(); private slots: + void swap(); + void setAlphaChannel_data(); void setAlphaChannel(); @@ -247,6 +249,20 @@ void tst_QPixmap::cleanup() { } +void tst_QPixmap::swap() +{ + QPixmap p1( 16, 16 ), p2( 32, 32 ); + p1.fill( Qt::white ); + p2.fill( Qt::black ); + const qint64 p1k = p1.cacheKey(); + const qint64 p2k = p2.cacheKey(); + p1.swap(p2); + QCOMPARE(p1.cacheKey(), p2k); + QCOMPARE(p1.size(), QSize(32,32)); + QCOMPARE(p2.cacheKey(), p1k); + QCOMPARE(p2.size(), QSize(16,16)); +} + void tst_QPixmap::setAlphaChannel_data() { QTest::addColumn<int>("red"); diff --git a/tests/auto/qregexp/tst_qregexp.cpp b/tests/auto/qregexp/tst_qregexp.cpp index d0d26ee..52f2041 100644 --- a/tests/auto/qregexp/tst_qregexp.cpp +++ b/tests/auto/qregexp/tst_qregexp.cpp @@ -77,6 +77,7 @@ private slots: void caretAnchoredOptimization(); void isEmpty(); void prepareEngineOptimization(); + void swap(); void operator_eq(); /* @@ -1290,6 +1291,14 @@ void tst_QRegExp::prepareEngineOptimization() QCOMPARE(rx11.matchedLength(), -1); } +void tst_QRegExp::swap() +{ + QRegExp r1(QLatin1String(".*")), r2(QLatin1String("a*")); + r1.swap(r2); + QCOMPARE(r1.pattern(),QLatin1String("a*")); + QCOMPARE(r2.pattern(),QLatin1String(".*")); +} + void tst_QRegExp::operator_eq() { const int I = 2; diff --git a/tests/auto/qregion/tst_qregion.cpp b/tests/auto/qregion/tst_qregion.cpp index 1716c94..f335051 100644 --- a/tests/auto/qregion/tst_qregion.cpp +++ b/tests/auto/qregion/tst_qregion.cpp @@ -64,6 +64,7 @@ public: private slots: void boundingRect(); void rects(); + void swap(); void setRects(); void ellipseRegion(); void polygonRegion(); @@ -168,6 +169,15 @@ void tst_QRegion::rects() } } +void tst_QRegion::swap() +{ + QRegion r1(QRect( 0, 0,10,10)); + QRegion r2(QRect(10,10,10,10)); + r1.swap(r2); + QCOMPARE(r1.rects().front(), QRect(10,10,10,10)); + QCOMPARE(r2.rects().front(), QRect( 0, 0,10,10)); +} + void tst_QRegion::setRects() { { diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index eff4658..c089a59 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -132,6 +132,7 @@ private slots: void compat_encode(); void percentEncoding_data(); void percentEncoding(); + void swap(); void symmetry(); void ipv6_data(); void ipv6(); @@ -2210,6 +2211,14 @@ void tst_QUrl::toPercentEncoding() QCOMPARE(original, QUrl::fromPercentEncoding(encodedUrl)); } +void tst_QUrl::swap() +{ + QUrl u1(QLatin1String("http://qt.nokia.com")), u2(QLatin1String("http://www.kdab.com")); + u1.swap(u2); + QCOMPARE(u2.host(),QLatin1String("qt.nokia.com")); + QCOMPARE(u1.host(),QLatin1String("www.kdab.com")); +} + void tst_QUrl::symmetry() { QUrl url(QString::fromLatin1("http://www.räksmörgås.se/pub?a=b&a=dø&a=f#vræl")); diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index 98d7436..159a806 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -100,6 +100,7 @@ private slots: void constructor(); void copy_constructor(); void isNull(); + void swap(); void canConvert_data(); void canConvert(); @@ -372,6 +373,16 @@ void tst_QVariant::isNull() QVERIFY(var7.isNull()); } +void tst_QVariant::swap() +{ + QVariant v1 = 1, v2 = 2.0; + v1.swap(v2); + QCOMPARE(v1.type(),QVariant::Double); + QCOMPARE(v1.toDouble(),2.0); + QCOMPARE(v2.type(),QVariant::Int); + QCOMPARE(v2.toInt(),1); +} + void tst_QVariant::canConvert_data() { QTest::addColumn<QVariant>("val"); |