Add QVarLengthArray::length().
This also adds a unit test for length()/count()/size(), since there wasn't one testing it explicitly. Change-Id: Ifb7f113aa97beef5f76e5fb246eb38495344b0ad Reviewed-by: João Abecasis <joao.abecasis@nokia.com> Reviewed-by: Marco Schmidt <Marco.Schmidt@Taugamma.de> Reviewed-by: Olivier Goffart <ogoffart@woboq.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
This commit is contained in:
parent
3ac957690c
commit
6802e3165e
@ -95,6 +95,7 @@ public:
|
|||||||
}
|
}
|
||||||
inline int size() const { return s; }
|
inline int size() const { return s; }
|
||||||
inline int count() const { return s; }
|
inline int count() const { return s; }
|
||||||
|
inline int length() const { return s; }
|
||||||
inline bool isEmpty() const { return (s == 0); }
|
inline bool isEmpty() const { return (s == 0); }
|
||||||
inline void resize(int size);
|
inline void resize(int size);
|
||||||
inline void clear() { resize(0); }
|
inline void clear() { resize(0); }
|
||||||
|
@ -118,6 +118,13 @@
|
|||||||
\sa isEmpty(), resize()
|
\sa isEmpty(), resize()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*! \fn int QVarLengthArray::length() const
|
||||||
|
|
||||||
|
Same as size().
|
||||||
|
|
||||||
|
\sa isEmpty(), resize()
|
||||||
|
*/
|
||||||
|
|
||||||
/*! \fn bool QVarLengthArray::isEmpty() const
|
/*! \fn bool QVarLengthArray::isEmpty() const
|
||||||
|
|
||||||
Returns true if the array has size 0; otherwise returns false.
|
Returns true if the array has size 0; otherwise returns false.
|
||||||
|
@ -55,6 +55,7 @@ private slots:
|
|||||||
void appendCausingRealloc();
|
void appendCausingRealloc();
|
||||||
void resize();
|
void resize();
|
||||||
void realloc();
|
void realloc();
|
||||||
|
void count();
|
||||||
};
|
};
|
||||||
|
|
||||||
int fooCtor = 0;
|
int fooCtor = 0;
|
||||||
@ -593,5 +594,66 @@ void tst_QVarLengthArray::realloc()
|
|||||||
QVERIFY(reallocTestProceed);
|
QVERIFY(reallocTestProceed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QVarLengthArray::count()
|
||||||
|
{
|
||||||
|
// tests size(), count() and length(), since they're the same thing
|
||||||
|
{
|
||||||
|
const QVarLengthArray<int> list;
|
||||||
|
QCOMPARE(list.length(), 0);
|
||||||
|
QCOMPARE(list.count(), 0);
|
||||||
|
QCOMPARE(list.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QVarLengthArray<int> list;
|
||||||
|
list.append(0);
|
||||||
|
QCOMPARE(list.length(), 1);
|
||||||
|
QCOMPARE(list.count(), 1);
|
||||||
|
QCOMPARE(list.size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QVarLengthArray<int> list;
|
||||||
|
list.append(0);
|
||||||
|
list.append(1);
|
||||||
|
QCOMPARE(list.length(), 2);
|
||||||
|
QCOMPARE(list.count(), 2);
|
||||||
|
QCOMPARE(list.size(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
QVarLengthArray<int> list;
|
||||||
|
list.append(0);
|
||||||
|
list.append(0);
|
||||||
|
list.append(0);
|
||||||
|
QCOMPARE(list.length(), 3);
|
||||||
|
QCOMPARE(list.count(), 3);
|
||||||
|
QCOMPARE(list.size(), 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// test removals too
|
||||||
|
{
|
||||||
|
QVarLengthArray<int> list;
|
||||||
|
list.append(0);
|
||||||
|
list.append(0);
|
||||||
|
list.append(0);
|
||||||
|
QCOMPARE(list.length(), 3);
|
||||||
|
QCOMPARE(list.count(), 3);
|
||||||
|
QCOMPARE(list.size(), 3);
|
||||||
|
list.removeLast();
|
||||||
|
QCOMPARE(list.length(), 2);
|
||||||
|
QCOMPARE(list.count(), 2);
|
||||||
|
QCOMPARE(list.size(), 2);
|
||||||
|
list.removeLast();
|
||||||
|
QCOMPARE(list.length(), 1);
|
||||||
|
QCOMPARE(list.count(), 1);
|
||||||
|
QCOMPARE(list.size(), 1);
|
||||||
|
list.removeLast();
|
||||||
|
QCOMPARE(list.length(), 0);
|
||||||
|
QCOMPARE(list.count(), 0);
|
||||||
|
QCOMPARE(list.size(), 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_APPLESS_MAIN(tst_QVarLengthArray)
|
QTEST_APPLESS_MAIN(tst_QVarLengthArray)
|
||||||
#include "tst_qvarlengtharray.moc"
|
#include "tst_qvarlengtharray.moc"
|
||||||
|
Loading…
Reference in New Issue
Block a user