summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qarraydata
diff options
context:
space:
mode:
authorJoão Abecasis <joao.abecasis@nokia.com>2011-11-22 17:28:14 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-09 17:19:30 +0100
commitf1e48d48fd58b28b1dc18652af3fc74da5e112fd (patch)
tree41f355093999ea8dabf9c196afb4e0ad275ce547 /tests/auto/corelib/tools/qarraydata
parentd91b4f0b13926a0861d7e172f14437d20d06332e (diff)
Add AllocateOptions to QArrayData
This approach is better for future ABI evolution than using individual bool parameters. QArrayData now also offers to calculate allocate options for typical detach and clone operations: the CapacityReserved flag is preserved, while cloning resets the Unsharable state. Change-Id: I256e135adcf27a52a5c7d6130069c35c8b946bc3 Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'tests/auto/corelib/tools/qarraydata')
-rw-r--r--tests/auto/corelib/tools/qarraydata/simplevector.h12
-rw-r--r--tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp42
2 files changed, 34 insertions, 20 deletions
diff --git a/tests/auto/corelib/tools/qarraydata/simplevector.h b/tests/auto/corelib/tools/qarraydata/simplevector.h
index 9ab28a9ddd..4f02df1c40 100644
--- a/tests/auto/corelib/tools/qarraydata/simplevector.h
+++ b/tests/auto/corelib/tools/qarraydata/simplevector.h
@@ -140,7 +140,8 @@ public:
|| (n
&& !d->capacityReserved
&& (d->ref != 1 || (d->capacityReserved = 1, false)))) {
- SimpleVector detached(Data::allocate(n, true));
+ SimpleVector detached(Data::allocate(n,
+ d->detachFlags() | Data::CapacityReserved));
detached.d->copyAppend(constBegin(), constEnd());
detached.swap(*this);
}
@@ -160,7 +161,8 @@ public:
if (d->ref != 1
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
- qMax(capacity(), size() + (last - first)), d->capacityReserved));
+ qMax(capacity(), size() + (last - first)),
+ d->detachFlags()));
detached.d->copyAppend(first, last);
detached.d->copyAppend(begin, begin + d->size);
@@ -180,7 +182,8 @@ public:
if (d->ref != 1
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
- qMax(capacity(), size() + (last - first)), d->capacityReserved));
+ qMax(capacity(), size() + (last - first)),
+ d->detachFlags()));
if (d->size) {
const T *const begin = constBegin();
@@ -219,7 +222,8 @@ public:
if (d->ref != 1
|| capacity() - size() < size_t(last - first)) {
SimpleVector detached(Data::allocate(
- qMax(capacity(), size() + (last - first)), d->capacityReserved));
+ qMax(capacity(), size() + (last - first)),
+ d->detachFlags()));
if (position)
detached.d->copyAppend(begin, where);
diff --git a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
index 47d5e2a32b..2df4131f4a 100644
--- a/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
+++ b/tests/auto/corelib/tools/qarraydata/tst_qarraydata.cpp
@@ -153,7 +153,7 @@ void tst_QArrayData::referenceCounting()
void tst_QArrayData::sharedNullEmpty()
{
QArrayData *null = const_cast<QArrayData *>(&QArrayData::shared_null);
- QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0, false, true);
+ QArrayData *empty = QArrayData::allocate(1, Q_ALIGNOF(QArrayData), 0);
QVERIFY(null->ref.isStatic());
QVERIFY(null->ref.isSharable());
@@ -473,11 +473,13 @@ struct Deallocator
};
Q_DECLARE_METATYPE(const QArrayData *)
+Q_DECLARE_METATYPE(QArrayData::AllocateOptions)
void tst_QArrayData::allocate_data()
{
QTest::addColumn<size_t>("objectSize");
QTest::addColumn<size_t>("alignment");
+ QTest::addColumn<QArrayData::AllocateOptions>("allocateOptions");
QTest::addColumn<bool>("isCapacityReserved");
QTest::addColumn<bool>("isSharable");
QTest::addColumn<const QArrayData *>("commonEmpty");
@@ -492,22 +494,25 @@ void tst_QArrayData::allocate_data()
{ "void *", sizeof(void *), Q_ALIGNOF(void *) }
};
- QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, false, true);
- QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, false, false);
+ QArrayData *shared_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0);
+ QArrayData *unsharable_empty = QArrayData::allocate(0, Q_ALIGNOF(QArrayData), 0, QArrayData::Unsharable);
QVERIFY(shared_empty);
QVERIFY(unsharable_empty);
struct {
char const *description;
+ QArrayData::AllocateOptions allocateOptions;
bool isCapacityReserved;
bool isSharable;
const QArrayData *commonEmpty;
} options[] = {
- { "Default", false, true, shared_empty },
- { "Reserved", true, true, shared_empty },
- { "Reserved | Unsharable", true, false, unsharable_empty },
- { "Unsharable", false, false, unsharable_empty },
+ { "Default", QArrayData::Default, false, true, shared_empty },
+ { "Reserved", QArrayData::CapacityReserved, true, true, shared_empty },
+ { "Reserved | Unsharable",
+ QArrayData::CapacityReserved | QArrayData::Unsharable, true, false,
+ unsharable_empty },
+ { "Unsharable", QArrayData::Unsharable, false, false, unsharable_empty },
};
for (size_t i = 0; i < sizeof(types)/sizeof(types[0]); ++i)
@@ -517,14 +522,15 @@ void tst_QArrayData::allocate_data()
+ QLatin1String(": ")
+ QLatin1String(options[j].description)))
<< types[i].objectSize << types[i].alignment
- << options[j].isCapacityReserved << options[j].isSharable
- << options[j].commonEmpty;
+ << options[j].allocateOptions << options[j].isCapacityReserved
+ << options[j].isSharable << options[j].commonEmpty;
}
void tst_QArrayData::allocate()
{
QFETCH(size_t, objectSize);
QFETCH(size_t, alignment);
+ QFETCH(QArrayData::AllocateOptions, allocateOptions);
QFETCH(bool, isCapacityReserved);
QFETCH(bool, isSharable);
QFETCH(const QArrayData *, commonEmpty);
@@ -535,14 +541,14 @@ void tst_QArrayData::allocate()
// Shared Empty
QCOMPARE(QArrayData::allocate(objectSize, minAlignment, 0,
- isCapacityReserved, isSharable), commonEmpty);
+ QArrayData::AllocateOptions(allocateOptions)), commonEmpty);
Deallocator keeper(objectSize, minAlignment);
keeper.headers.reserve(1024);
for (int capacity = 1; capacity <= 1024; capacity <<= 1) {
QArrayData *data = QArrayData::allocate(objectSize, minAlignment,
- capacity, isCapacityReserved, isSharable);
+ capacity, QArrayData::AllocateOptions(allocateOptions));
keeper.headers.append(data);
QCOMPARE(data->size, 0);
@@ -584,7 +590,7 @@ void tst_QArrayData::alignment()
for (int i = 0; i < 100; ++i) {
QArrayData *data = QArrayData::allocate(sizeof(Unaligned),
- minAlignment, 8, false, true);
+ minAlignment, 8, QArrayData::Default);
keeper.headers.append(data);
QVERIFY(data);
@@ -952,10 +958,14 @@ void tst_QArrayData::setSharable_data()
{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 }
};
- QArrayDataPointer<int> emptyReserved(QTypedArrayData<int>::allocate(5, true, true));
- QArrayDataPointer<int> nonEmpty(QTypedArrayData<int>::allocate(10, false, true));
- QArrayDataPointer<int> nonEmptyReserved(QTypedArrayData<int>::allocate(15, true, true));
- QArrayDataPointer<int> staticArray(static_cast<QTypedArrayData<int> *>(&staticArrayData.header));
+ QArrayDataPointer<int> emptyReserved(QTypedArrayData<int>::allocate(5,
+ QArrayData::CapacityReserved));
+ QArrayDataPointer<int> nonEmpty(QTypedArrayData<int>::allocate(10,
+ QArrayData::Default));
+ QArrayDataPointer<int> nonEmptyReserved(QTypedArrayData<int>::allocate(15,
+ QArrayData::CapacityReserved));
+ QArrayDataPointer<int> staticArray(
+ static_cast<QTypedArrayData<int> *>(&staticArrayData.header));
nonEmpty->copyAppend(5, 1);
nonEmptyReserved->copyAppend(7, 2);