From 12a9d6be28344e93741e10b9b90bd7c154bf15c2 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 25 Nov 2015 12:40:59 +0100 Subject: QPair: add tests for conversion ctor/assignment operators Change-Id: Id54ada05f477aa3262ad99d82bc243c3d17e06f0 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/tools/qpair/tst_qpair.cpp | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'tests/auto/corelib/tools/qpair') 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 rhs(42, 4.5); + const QPair pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + const QPair pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); + } + + // assignment from lvalue: + { + const QPair rhs(42, 4.5); + QPair pii; + pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + QPair pif; + pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); + } + + // construction from rvalue: + { +#define rhs qMakePair(42, 4.5) + const QPair pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + const QPair pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); +#undef rhs + } + + // assignment from rvalue: + { +#define rhs qMakePair(42, 4.5) + QPair pii; + pii = rhs; + QCOMPARE(pii.first, 42); + QCOMPARE(pii.second, 4); + + QPair pif; + pif = rhs; + QCOMPARE(pif.first, 42); + QCOMPARE(pif.second, 4.5f); +#undef rhs + } +} + QTEST_APPLESS_MAIN(tst_QPair) #include "tst_qpair.moc" -- cgit v1.2.3