Add test for QVector::setSharable
Change-Id: Id31761bfb642d4ce515768c1ffe1e3088d883353 Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
fed603fde5
commit
b29338e805
@ -85,6 +85,8 @@ private slots:
|
|||||||
void initializeList();
|
void initializeList();
|
||||||
|
|
||||||
void const_shared_null();
|
void const_shared_null();
|
||||||
|
void setSharable_data();
|
||||||
|
void setSharable();
|
||||||
};
|
};
|
||||||
|
|
||||||
void tst_QVector::constructors() const
|
void tst_QVector::constructors() const
|
||||||
@ -946,5 +948,97 @@ void tst_QVector::const_shared_null()
|
|||||||
QVERIFY(!v2.isDetached());
|
QVERIFY(!v2.isDetached());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(QVector<int>);
|
||||||
|
|
||||||
|
void tst_QVector::setSharable_data()
|
||||||
|
{
|
||||||
|
QTest::addColumn<QVector<int> >("vector");
|
||||||
|
QTest::addColumn<int>("size");
|
||||||
|
QTest::addColumn<int>("capacity");
|
||||||
|
QTest::addColumn<bool>("isCapacityReserved");
|
||||||
|
|
||||||
|
QVector<int> null;
|
||||||
|
QVector<int> empty(0, 5);
|
||||||
|
QVector<int> emptyReserved;
|
||||||
|
QVector<int> nonEmpty;
|
||||||
|
QVector<int> nonEmptyReserved;
|
||||||
|
|
||||||
|
emptyReserved.reserve(10);
|
||||||
|
nonEmptyReserved.reserve(15);
|
||||||
|
|
||||||
|
nonEmpty << 0 << 1 << 2 << 3 << 4;
|
||||||
|
nonEmptyReserved << 0 << 1 << 2 << 3 << 4 << 5 << 6;
|
||||||
|
|
||||||
|
QVERIFY(emptyReserved.capacity() >= 10);
|
||||||
|
QVERIFY(nonEmptyReserved.capacity() >= 15);
|
||||||
|
|
||||||
|
QTest::newRow("null") << null << 0 << 0 << false;
|
||||||
|
QTest::newRow("empty") << empty << 0 << 0 << false;
|
||||||
|
QTest::newRow("empty, Reserved") << emptyReserved << 0 << 10 << true;
|
||||||
|
QTest::newRow("non-empty") << nonEmpty << 5 << 0 << false;
|
||||||
|
QTest::newRow("non-empty, Reserved") << nonEmptyReserved << 7 << 15 << true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QVector::setSharable()
|
||||||
|
{
|
||||||
|
QFETCH(QVector<int>, vector);
|
||||||
|
QFETCH(int, size);
|
||||||
|
QFETCH(int, capacity);
|
||||||
|
QFETCH(bool, isCapacityReserved);
|
||||||
|
|
||||||
|
QVERIFY(!vector.isDetached()); // Shared with QTest
|
||||||
|
|
||||||
|
vector.setSharable(true);
|
||||||
|
|
||||||
|
QCOMPARE(vector.size(), size);
|
||||||
|
if (isCapacityReserved)
|
||||||
|
QVERIFY2(vector.capacity() >= capacity,
|
||||||
|
qPrintable(QString("Capacity is %1, expected at least %2.")
|
||||||
|
.arg(vector.capacity())
|
||||||
|
.arg(capacity)));
|
||||||
|
|
||||||
|
{
|
||||||
|
QVector<int> copy(vector);
|
||||||
|
|
||||||
|
QVERIFY(!copy.isDetached());
|
||||||
|
QVERIFY(copy.isSharedWith(vector));
|
||||||
|
}
|
||||||
|
|
||||||
|
vector.setSharable(false);
|
||||||
|
QVERIFY(vector.isDetached() || vector.isSharedWith(QVector<int>()));
|
||||||
|
|
||||||
|
{
|
||||||
|
QVector<int> copy(vector);
|
||||||
|
|
||||||
|
QVERIFY(copy.isDetached() || copy.isSharedWith(QVector<int>()));
|
||||||
|
QCOMPARE(copy.size(), size);
|
||||||
|
if (isCapacityReserved)
|
||||||
|
QVERIFY2(copy.capacity() >= capacity,
|
||||||
|
qPrintable(QString("Capacity is %1, expected at least %2.")
|
||||||
|
.arg(vector.capacity())
|
||||||
|
.arg(capacity)));
|
||||||
|
QCOMPARE(copy, vector);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector.setSharable(true);
|
||||||
|
|
||||||
|
{
|
||||||
|
QVector<int> copy(vector);
|
||||||
|
|
||||||
|
QVERIFY(!copy.isDetached());
|
||||||
|
QVERIFY(copy.isSharedWith(vector));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < vector.size(); ++i)
|
||||||
|
QCOMPARE(vector[i], i);
|
||||||
|
|
||||||
|
QCOMPARE(vector.size(), size);
|
||||||
|
if (isCapacityReserved)
|
||||||
|
QVERIFY2(vector.capacity() >= capacity,
|
||||||
|
qPrintable(QString("Capacity is %1, expected at least %2.")
|
||||||
|
.arg(vector.capacity())
|
||||||
|
.arg(capacity)));
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QVector)
|
QTEST_APPLESS_MAIN(tst_QVector)
|
||||||
#include "tst_qvector.moc"
|
#include "tst_qvector.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user