diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-25 12:40:59 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-11-26 15:11:32 +0000 |
commit | 12a9d6be28344e93741e10b9b90bd7c154bf15c2 (patch) | |
tree | 6c4b4c3e06290b1f590781fa1a8364b4402d3a76 | |
parent | a9a11f020f0731c3ef5d82d0426b3e1bfbfbf998 (diff) |
QPair: add tests for conversion ctor/assignment operators
Change-Id: Id54ada05f477aa3262ad99d82bc243c3d17e06f0
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
-rw-r--r-- | tests/auto/corelib/tools/qpair/tst_qpair.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp index 076efc5428..f7cb07125b 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -41,6 +41,7 @@ class tst_QPair : public QObject Q_OBJECT private Q_SLOTS: void testConstexpr(); + void testConversions(); }; class C { char _[4]; }; @@ -108,5 +109,62 @@ void tst_QPair::testConstexpr() Q_UNUSED(pSI); } +void tst_QPair::testConversions() +{ + // construction from lvalue: + { + const QPair<int, double> rhs(42, 4.5); + const QPair<int, int> pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + const QPair<int, float> pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); + } + + // assignment from lvalue: + { + const QPair<int, double> rhs(42, 4.5); + QPair<int, int> pii; + pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + QPair<int, float> pif; + pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); + } + + // construction from rvalue: + { +#define rhs qMakePair(42, 4.5) + const QPair<int, int> pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + const QPair<int, float> pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); +#undef rhs + } + + // assignment from rvalue: + { +#define rhs qMakePair(42, 4.5) + QPair<int, int> pii; + pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + QPair<int, float> pif; + pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); +#undef rhs + } +} + QTEST_APPLESS_MAIN(tst_QPair) #include "tst_qpair.moc" |