diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-07-11 11:04:52 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-07-11 20:02:41 +0000 |
commit | e6a5be1d81a3f8fce7e55906b4bc84d723e11ac5 (patch) | |
tree | 06c7a1335cbc0be36cfae221d4b42a0184ff767e /tests/auto/corelib/tools/qpair | |
parent | 6a7bae9a26aac877bceaf2810328064abc71c768 (diff) |
QPair: add test for pair of references
std::pair explicitly supports this (cf. std::tie),
so check we do, too.
Change-Id: Idc3c1739a4bc64a0da120dcf953def7e432f6f71
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/tools/qpair')
-rw-r--r-- | tests/auto/corelib/tools/qpair/tst_qpair.cpp | 30 |
1 files changed, 30 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..94740d74bc 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -40,6 +40,7 @@ class tst_QPair : public QObject { Q_OBJECT private Q_SLOTS: + void pairOfReferences(); void testConstexpr(); }; @@ -94,6 +95,35 @@ Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isDummy ); Q_STATIC_ASSERT(!QTypeInfo<QPairPP>::isPointer); +void tst_QPair::pairOfReferences() +{ + int i = 0; + QString s; + + QPair<int&, QString&> p(i, s); + + p.first = 1; + QCOMPARE(i, 1); + + i = 2; + QCOMPARE(p.first, 2); + + p.second = QLatin1String("Hello"); + QCOMPARE(s, QLatin1String("Hello")); + + s = QLatin1String("olleH"); + QCOMPARE(p.second, QLatin1String("olleH")); + + QPair<int&, QString&> q = p; + q.first = 3; + QCOMPARE(i, 3); + QCOMPARE(p.first, 3); + + q.second = QLatin1String("World"); + QCOMPARE(s, QLatin1String("World")); + QCOMPARE(p.second, QLatin1String("World")); +} + void tst_QPair::testConstexpr() { Q_CONSTEXPR QPair<int, double> pID = qMakePair(0, 0.0); |