add missing tests of rvalue overloads for QVarLengthArray and QVector

they were missing in dd58ddd5d9

Change-Id: I52a2f855ead7716f8fe887524b27d4bd258f43d3
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
Eric Lemanissier 2018-03-09 12:09:09 +01:00
parent fee8944cbe
commit 1e27219968
2 changed files with 24 additions and 1 deletions

View File

@ -966,12 +966,14 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::liveCount, 4);
vec.append(std::move(m3));
QVERIFY(m3.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
QCOMPARE(MyBase::errorCount, 0);
QCOMPARE(MyBase::liveCount, 4);
QCOMPARE(MyBase::movedCount, 1);
vec.push_back(std::move(m4));
QVERIFY(m4.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
QVERIFY(vec.at(1).wasConstructedAt(&m4));
QCOMPARE(MyBase::errorCount, 0);
@ -979,6 +981,7 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::movedCount, 2);
vec.prepend(std::move(m1));
QVERIFY(m1.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m3));
QVERIFY(vec.at(2).wasConstructedAt(&m4));
@ -987,9 +990,11 @@ void tst_QVarLengthArray::insertMove()
QCOMPARE(MyBase::movedCount, 3);
vec.insert(1, std::move(m2));
QVERIFY(m2.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m2));
QVERIFY(vec.at(2).wasConstructedAt(&m3));
QVERIFY(vec.at(3).wasConstructedAt(&m4));
QCOMPARE(MyBase::copyCount, 0);
QCOMPARE(MyBase::liveCount, 4);
@ -1014,15 +1019,19 @@ void tst_QVarLengthArray::nonCopyable()
int *const ptr4 = val4.get();
vec.append(std::move(val3));
QVERIFY(!val3);
QVERIFY(ptr3 == vec.at(0).get());
vec.append(std::move(val4));
QVERIFY(!val4);
QVERIFY(ptr3 == vec.at(0).get());
QVERIFY(ptr4 == vec.at(1).get());
vec.prepend(std::move(val1));
QVERIFY(!val1);
QVERIFY(ptr1 == vec.at(0).get());
QVERIFY(ptr3 == vec.at(1).get());
QVERIFY(ptr4 == vec.at(2).get());
vec.insert(1, std::move(val2));
QVERIFY(!val2);
QVERIFY(ptr1 == vec.at(0).get());
QVERIFY(ptr2 == vec.at(1).get());
QVERIFY(ptr3 == vec.at(2).get());

View File

@ -2895,26 +2895,40 @@ void tst_QVector::insertMove() const
const int instancesCount = Movable::counter.loadAcquire();
{
QVector<Movable> vec;
vec.reserve(5);
Movable m0;
Movable m1;
Movable m2;
Movable m3;
Movable m4;
vec.append(std::move(m3));
QVERIFY(m3.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
vec.push_back(std::move(m4));
QVERIFY(m4.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m3));
QVERIFY(vec.at(1).wasConstructedAt(&m4));
vec.prepend(std::move(m1));
QVERIFY(m1.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m3));
QVERIFY(vec.at(2).wasConstructedAt(&m4));
vec.insert(1, std::move(m2));
QVERIFY(m2.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m1));
QVERIFY(vec.at(1).wasConstructedAt(&m2));
QVERIFY(vec.at(2).wasConstructedAt(&m3));
QVERIFY(vec.at(3).wasConstructedAt(&m4));
vec.push_front(std::move(m0));
QVERIFY(m0.wasConstructedAt(nullptr));
QVERIFY(vec.at(0).wasConstructedAt(&m0));
QVERIFY(vec.at(1).wasConstructedAt(&m1));
QVERIFY(vec.at(2).wasConstructedAt(&m2));
QVERIFY(vec.at(3).wasConstructedAt(&m3));
QVERIFY(vec.at(4).wasConstructedAt(&m4));
QCOMPARE(Movable::counter.loadAcquire(), instancesCount + 8);
QCOMPARE(Movable::counter.loadAcquire(), instancesCount + 10);
}
QCOMPARE(Movable::counter.loadAcquire(), instancesCount);
}