summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/collections/tst_collections.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/collections/tst_collections.cpp')
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp385
1 files changed, 19 insertions, 366 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index e79a4dba29..6fcf726c21 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -32,7 +32,6 @@
static QCache<int, int> *cacheX;
static QHash<int, int> *hashX;
-static QLinkedList<int> *linkedListX;
static QList<int> *listX;
static QMap<int, int> *mapX;
static QMultiHash<int, int> *multiHashX;
@@ -49,7 +48,6 @@ void foo()
{
cacheX = 0;
hashX = 0;
- linkedListX = 0;
listX = 0;
mapX = 0;
multiHashX = 0;
@@ -71,7 +69,6 @@ void foo()
#include "qbytearray.h"
#include "qcache.h"
#include "qhash.h"
-#include "qlinkedlist.h"
#include "qlist.h"
#include "qmap.h"
#include "qpair.h"
@@ -84,10 +81,6 @@ void foo()
#include "qvector.h"
#include "qqueue.h"
-QT_BEGIN_NAMESPACE
-template class QList<int>;
-QT_END_NAMESPACE
-
class tst_Collections : public QObject
{
Q_OBJECT
@@ -96,7 +89,6 @@ private slots:
void typeinfo();
void qstring();
void list();
- void linkedList();
void vector();
void byteArray();
void stack();
@@ -109,7 +101,6 @@ private slots:
#endif
void pair();
void sharableQList();
- void sharableQLinkedList();
void sharableQVector();
void sharableQMap();
void sharableQHash();
@@ -121,8 +112,6 @@ private slots:
void vector_stl();
void list_stl_data();
void list_stl();
- void linkedlist_stl_data();
- void linkedlist_stl();
void q_init();
void pointersize();
void containerInstantiation();
@@ -551,19 +540,12 @@ void tst_Collections::list()
list << "foo" << "bar";
QVERIFY(!list.isEmpty());
- list.insert(-1, "lessthanzero");
- QCOMPARE(list.at(0), QString("lessthanzero"));
-
list.insert(0, "atzero");
QCOMPARE(list.at(0), QString("atzero"));
int listCount = list.count();
list.insert(listCount, "atcount");
QCOMPARE(list.at(listCount), QString("atcount"));
-
- listCount = list.count();
- list.insert(listCount + 1, "beyondcount");
- QCOMPARE(list.at(listCount), QString("beyondcount"));
}
{
@@ -736,228 +718,6 @@ void tst_Collections::list()
}
}
-void tst_Collections::linkedList()
-{
- {
- QLinkedList<int> list;
- QVERIFY(list.isEmpty());
- list.append(1);
- list.push_back(2);
- list += (3);
- list << 4 << 5 << 6;
- QVERIFY(!list.isEmpty());
- QVERIFY(list.size() == 6);
- {
- int sum = 0;
- QLinkedListIterator<int> i = list;
- while (i.hasNext()) {
- sum += i.next();
- }
- QVERIFY(sum == 21);
- }
- {
- int sum = 0;
- QLinkedList<int>::const_iterator i = list.begin();
- while (i != list.end())
- sum += *i++;
- QVERIFY(sum == 21);
- }
- {
- QMutableLinkedListIterator<int> i = list;
- while (i.hasNext())
- i.setValue(2*i.next());
- }
- {
- int sum = 0;
- QLinkedListIterator<int> i = list;
- i.toBack();
- while (i.hasPrevious())
- sum += i.previous();
- QVERIFY(sum == 2*21);
- }
- {
- QMutableLinkedListIterator<int> i = list;
- i.toBack();
- while (i.hasPrevious())
- i.setValue(2*i.previous());
- }
- {
- int sum = 0;
- QLinkedListIterator<int> i = list;
- i.toBack();
- while (i.hasPrevious())
- sum += i.previous();
- QVERIFY(sum == 2*2*21);
- }
- {
- QMutableLinkedListIterator<int> i = list;
- while (i.hasNext()) {
- int a = i.next();
- i.insert(a);
- }
- }
- {
- int sum = 0;
- QLinkedList<int>::iterator i = list.begin();
- while (i != list.end())
- sum += *i++;
- QVERIFY(sum == 2*2*2*21);
- }
- {
- int duplicates = 0;
- QLinkedListIterator<int> i = list;
- while (i.hasNext()) {
- int a = i.next();
- if (i.hasNext() && a == i.peekNext())
- duplicates++;
- }
- QVERIFY(duplicates == 6);
- }
- {
- int duplicates = 0;
- QLinkedListIterator<int> i = list;
- i.toBack();
- while (i.hasPrevious()) {
- int a = i.previous();
- if (i.hasPrevious() && a == i.peekPrevious())
- duplicates++;
- }
- QVERIFY(duplicates == 6);
- }
- {
- QMutableLinkedListIterator<int> i = list;
- while (i.hasNext()) {
- int a = i.next();
- if (i.hasNext() &&
- i.peekNext() == a)
- i.remove();
- }
- }
- {
- int duplicates = 0;
- QMutableLinkedListIterator<int> i = list;
- i.toBack();
- while (i.hasPrevious()) {
- int a = i.previous();
- if (i.hasPrevious() && a == i.peekPrevious())
- duplicates++;
- }
- QVERIFY(duplicates == 0);
- }
- {
- QVERIFY(list.size() == 6);
- QMutableLinkedListIterator<int> i = list;
- while (i.hasNext()) {
- int a = i.peekNext();
- i.insert(42);
- QVERIFY(i.peekPrevious() == 42 && i.peekNext() == a);
- i.next();
- }
- QVERIFY(list.size() == 12);
- i.toFront();
- while (i.findNext(42))
- i.remove();
- }
- {
- QLinkedList<int> l;
- l << 4 << 8 << 12 << 16 << 20 << 24;
- QVERIFY(l == list);
- QLinkedList<int> copy = list;
- list += list;
- QVERIFY(l != list && l.size() == list.size()/2 && l == copy);
- l += copy;
- QVERIFY(l == list);
- list = copy;
- }
- {
- QLinkedList<int> copy = list;
- list.prepend(999);
- list.append(999);
- QVERIFY(list.contains(999));
- QVERIFY(list.count(999) == 2);
- list.removeAll(999);
- QVERIFY(list == copy);
- }
- {
- QLinkedList<QString> list;
- list << "one" << "two" << "three" << "four" << "five" << "six";
- while (!list.isEmpty())
- list.removeAll(list.first());
- }
- {
- QLinkedList<QString> list;
- list << "one" << "two" << "one" << "two";
- QVERIFY(!list.removeOne("three"));
- QVERIFY(list.removeOne("two"));
- QCOMPARE(list, QLinkedList<QString>() << "one" << "one" << "two");;
- QVERIFY(list.removeOne("two"));
- QCOMPARE(list, QLinkedList<QString>() << "one" << "one");
- QVERIFY(!list.removeOne("two"));
- QCOMPARE(list, QLinkedList<QString>() << "one" << "one");
- QVERIFY(list.removeOne("one"));
- QCOMPARE(list, QLinkedList<QString>() << "one");
- QVERIFY(list.removeOne("one"));
- QVERIFY(list.isEmpty());
- QVERIFY(!list.removeOne("one"));
- QVERIFY(list.isEmpty());
- }
- {
- list.clear();
- QVERIFY(list.isEmpty());
- QVERIFY(list.begin() == list.end());
- QLinkedListIterator<int> i(list);
- QVERIFY(!i.hasNext() && !i.hasPrevious());
- }
- }
-
- {
- QLinkedList<QString> list;
- list.append("Hello");
-
- QLinkedList<QString>::iterator it = list.begin();
- QVERIFY((*it)[0] == QChar('H'));
- QVERIFY(it->constData()[0] == QChar('H'));
- it->replace(QChar('H'), QChar('X'));
- QCOMPARE(list.first(), QLatin1String("Xello"));
-
- QLinkedList<QString>::const_iterator cit = list.constBegin();
- QCOMPARE((*cit).toLower(), QLatin1String("xello"));
- QCOMPARE(cit->toUpper(), QLatin1String("XELLO"));
-
- cit = list.cbegin();
- QCOMPARE((*cit).toLower(), QLatin1String("xello"));
- QCOMPARE(cit->toUpper(), QLatin1String("XELLO"));
- }
-
- {
- QLinkedList<QString> list;
- list << "alpha" << "beta";
- list += list;
- QVERIFY(list.size() == 4);
- QCOMPARE(*list.begin(), QLatin1String("alpha"));
- QCOMPARE(*(list.begin() + 1), QLatin1String("beta"));
- QCOMPARE(*(list.begin() + 2), QLatin1String("alpha"));
- QCOMPARE(*(list.begin() + 3), QLatin1String("beta"));
- }
-
- {
- QLinkedList<int> a;
- QCOMPARE(a.startsWith(1), false);
- QCOMPARE(a.endsWith(1), false);
- a.append(1);
- QCOMPARE(a.startsWith(1), true);
- QCOMPARE(a.startsWith(2), false);
- QCOMPARE(a.endsWith(1), true);
- QCOMPARE(a.endsWith(2), false);
- a.append(2);
- QCOMPARE(a.startsWith(1), true);
- QCOMPARE(a.startsWith(2), false);
- QCOMPARE(a.endsWith(1), false);
- QCOMPARE(a.endsWith(2), true);
- }
-};
-
-
void tst_Collections::vector()
{
QVector<int> v1;
@@ -1562,12 +1322,12 @@ void tst_Collections::hash()
}
{
- QHash<int, QString> hash1, hash2;
- hash1.insertMulti(1, "Alpha");
- hash1.insertMulti(1, "Gamma");
- hash2.insertMulti(1, "Beta");
- hash2.insertMulti(1, "Gamma");
- hash2.insertMulti(1, "Gamma");
+ QMultiHash<int, QString> hash1, hash2;
+ hash1.insert(1, "Alpha");
+ hash1.insert(1, "Gamma");
+ hash2.insert(1, "Beta");
+ hash2.insert(1, "Gamma");
+ hash2.insert(1, "Gamma");
hash1.unite(hash2);
QCOMPARE(hash1.size(), 5);
@@ -1997,15 +1757,6 @@ void tst_Collections::qstring()
QVERIFY(null.isNull());
QVERIFY(!nonNull.isNull());
-#if QT_DEPRECATED_SINCE(5, 9)
- QVERIFY(null == QString::null);
- QVERIFY(QString::null == null);
- QVERIFY(nonNull != QString::null);
- QVERIFY(QString::null != nonNull);
- QVERIFY(null == nonNull);
- QVERIFY(QString::null == QString::null);
-#endif
-
QString fill = "123";
fill.fill('a');
QCOMPARE(fill, QLatin1String("aaa"));
@@ -2331,18 +2082,6 @@ void populate(QList<int> &container)
}
template <>
-void populate(QLinkedList<int> &container)
-{
- container << 1 << 2 << 4 << 8;
-}
-
-template <>
-void populate(QVector<int> &container)
-{
- container << 1 << 2 << 4 << 8;
-}
-
-template <>
void populate(QMap<int, int> &container)
{
container.insert(1, 1);
@@ -2431,11 +2170,6 @@ void tst_Collections::sharableQList()
TEST_SEQUENTIAL_CONTAINER(List);
}
-void tst_Collections::sharableQLinkedList()
-{
- TEST_SEQUENTIAL_CONTAINER(LinkedList);
-}
-
void tst_Collections::sharableQVector()
{
TEST_SEQUENTIAL_CONTAINER(Vector);
@@ -2727,8 +2461,10 @@ void testMapLikeStlIterators()
QString t;
fake.insert(k, t);
- typename Container::iterator i1 = fake.begin(), i2 = i1 + 1;
- typename Container::const_iterator c1 = i1, c2 = c1 + 1;
+ typename Container::iterator i1 = fake.begin(), i2 = i1;
+ ++i2;
+ typename Container::const_iterator c1 = i1, c2 = c1;
+ ++c2;
QVERIFY(i1 == i1);
QVERIFY(i1 == c1);
@@ -2738,8 +2474,6 @@ void testMapLikeStlIterators()
QVERIFY(i2 == c2);
QVERIFY(c2 == i2);
QVERIFY(c2 == c2);
- QVERIFY(1 + i1 == i1 + 1);
- QVERIFY(1 + c1 == c1 + 1);
QVERIFY(i1 != i2);
QVERIFY(i1 != c2);
@@ -2755,7 +2489,6 @@ void tst_Collections::constAndNonConstStlIterators()
{
testListLikeStlIterators<QList<int> >();
testListLikeStlIterators<QStringList >();
- testLinkedListLikeStlIterators<QLinkedList<int> >();
testListLikeStlIterators<QVector<int> >();
testMapLikeStlIterators<QMap<QString, QString> >();
testMapLikeStlIterators<QMultiMap<QString, QString> >();
@@ -2798,31 +2531,6 @@ void tst_Collections::vector_stl()
QCOMPARE(QVector<QString>(stdVector.begin(), stdVector.end()), vector);
}
-void tst_Collections::linkedlist_stl_data()
-{
- list_stl_data();
-}
-
-void tst_Collections::linkedlist_stl()
-{
- QFETCH(QStringList, elements);
-
- QLinkedList<QString> list;
- for (int i = 0; i < elements.count(); ++i)
- list << elements.at(i);
-
- std::list<QString> stdList = list.toStdList();
-
- QCOMPARE(int(stdList.size()), elements.size());
-
- std::list<QString>::const_iterator it = stdList.begin();
- QLinkedList<QString>::const_iterator it2 = list.cbegin();
- for (uint j = 0; j < stdList.size(); ++j, ++it, ++it2)
- QCOMPARE(*it, *it2);
-
- QCOMPARE(QLinkedList<QString>::fromStdList(stdList), list);
-}
-
void tst_Collections::list_stl_data()
{
QTest::addColumn<QStringList>("elements");
@@ -2950,10 +2658,6 @@ void instantiateMutableIterationContainer()
it = container.begin();
it = container.end();
Q_UNUSED(it)
-
- // QSet lacks count(T).
- const ValueType value = ValueType();
- container.count(value);
}
template <typename ContainerType, typename ValueType>
@@ -2961,10 +2665,9 @@ void instantiateSequence()
{
instantiateMutableIterationContainer<ContainerType, ValueType>();
-// QVector lacks removeAll(T)
-// ValueType value = ValueType();
-// ContainerType container;
-// container.removeAll(value);
+ ValueType value = ValueType();
+ ContainerType container;
+ container.removeAll(value);
}
template <typename ContainerType, typename ValueType>
@@ -3037,11 +2740,10 @@ void instantiatePairAssociative()
constContainer.keys();
container.remove(key);
container.take(key);
- container.unite(constContainer);
+ container.insert(constContainer);
container.value(key);
container.value(key, value);
container.values();
- container.values(key);
container[key];
const int foo = constContainer[key];
Q_UNUSED(foo);
@@ -3070,15 +2772,6 @@ void tst_Collections::containerInstantiation()
typedef QSet<EqualsComparable> Set;
instantiateAssociative<Set, EqualsComparable>();
- //Instantiate QLinkedList member functions.
- typedef QLinkedList<EqualsComparable> LinkedList;
- instantiateSequence<LinkedList, EqualsComparable> ();
- {
- EqualsComparable value;
- LinkedList list;
- list.removeAll(value);
- }
-
//Instantiate QList member functions.
typedef QList<EqualsComparable> List;
instantiateRandomAccess<List, EqualsComparable>();
@@ -3185,7 +2878,6 @@ void tst_Collections::containerTypedefs()
testContainerTypedefs(QVector<int>());
testContainerTypedefs(QStack<int>());
testContainerTypedefs(QList<int>());
- testContainerTypedefs(QLinkedList<int>());
testContainerTypedefs(QQueue<int>());
testPairAssociativeContainerTypedefs(QMap<int, int>());
@@ -3207,16 +2899,13 @@ void tst_Collections::forwardDeclared()
{ typedef QMultiMap<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
{ typedef QPair<T1, T2> C; C *x = 0; Q_UNUSED(x) }
{ typedef QList<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
- { typedef QLinkedList<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
{ typedef QVector<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) Q_UNUSED(i) Q_UNUSED(j) }
{ typedef QStack<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) Q_UNUSED(i) Q_UNUSED(j) }
{ typedef QQueue<T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
{ typedef QSet<T1> C; C *x = 0; /* C::iterator i; */ C::const_iterator j; Q_UNUSED(x) }
}
-#if defined(Q_ALIGNOF) && defined(Q_DECL_ALIGN)
-
-class Q_DECL_ALIGN(4) Aligned4
+class alignas(4) Aligned4
{
char i;
public:
@@ -3228,7 +2917,7 @@ public:
inline bool operator<(const Aligned4 &other) const { return i < other.i; }
friend inline int qHash(const Aligned4 &a) { return qHash(a.i); }
};
-Q_STATIC_ASSERT(Q_ALIGNOF(Aligned4) % 4 == 0);
+Q_STATIC_ASSERT(alignof(Aligned4) % 4 == 0);
#if defined(Q_PROCESSOR_ARM)
# if defined(Q_COMPILER_ALIGNAS) && defined(__BIGGEST_ALIGNMENT__)
@@ -3242,7 +2931,7 @@ Q_STATIC_ASSERT(Q_ALIGNOF(Aligned4) % 4 == 0);
# define BIGGEST_ALIGNMENT_TO_TEST 128
#endif
-class Q_DECL_ALIGN(BIGGEST_ALIGNMENT_TO_TEST) AlignedBiggest
+class alignas(BIGGEST_ALIGNMENT_TO_TEST) AlignedBiggest
{
char i;
public:
@@ -3254,7 +2943,7 @@ public:
inline bool operator<(const AlignedBiggest &other) const { return i < other.i; }
friend inline int qHash(const AlignedBiggest &a) { return qHash(a.i); }
};
-Q_STATIC_ASSERT(Q_ALIGNOF(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0);
+Q_STATIC_ASSERT(alignof(AlignedBiggest) % BIGGEST_ALIGNMENT_TO_TEST == 0);
template<typename C>
void testVectorAlignment()
@@ -3325,13 +3014,6 @@ void tst_Collections::alignment()
testAssociativeContainerAlignment<QHash<AlignedBiggest, AlignedBiggest> >();
}
-#else
-void tst_Collections::alignment()
-{
- QSKIP("Compiler doesn't support necessary extension keywords");
-}
-#endif
-
#ifndef QT_NO_TEMPLATE_TEMPLATE_PARAMETERS
template<template<class> class C>
@@ -3441,7 +3123,6 @@ void tst_Collections::QTBUG13079_collectionInsideCollection()
QTBUG13079_collectionInsideCollectionImpl<QVector>();
QTBUG13079_collectionInsideCollectionImpl<QStack>();
QTBUG13079_collectionInsideCollectionImpl<QList>();
- QTBUG13079_collectionInsideCollectionImpl<QLinkedList>();
QTBUG13079_collectionInsideCollectionImpl<QQueue>();
{
@@ -3510,9 +3191,6 @@ void tst_Collections::foreach_2()
QCOMPARE(varl1.count(), intlist.count());
QCOMPARE(varl2.count(), intlist.count());
QCOMPARE(varl3.count(), intlist.count());
- foreach_test_arrays(varl1);
- foreach_test_arrays(varl2);
- foreach_test_arrays(varl3);
QVarLengthArray<QString> varl4;
QVarLengthArray<QString, 3> varl5;
@@ -3525,9 +3203,6 @@ void tst_Collections::foreach_2()
QCOMPARE(varl4.count(), strlist.count());
QCOMPARE(varl5.count(), strlist.count());
QCOMPARE(varl6.count(), strlist.count());
- foreach_test_arrays(varl4);
- foreach_test_arrays(varl5);
- foreach_test_arrays(varl6);
}
struct IntOrString
@@ -3615,30 +3290,8 @@ template<class Container> void insert_remove_loop_impl()
}
-//Add insert(int, int, T) so it has the same interface as QVector and QVarLengthArray for the test.
template<typename T>
-struct ExtList : QList<T> {
- using QList<T>::insert;
- void insert(int before, int n, const T&x) {
- while (n--) {
- this->insert(before, x );
- }
- }
- void insert(typename QList<T>::iterator before, int n, const T&x) {
- while (n--) {
- before = this->insert(before, x);
- }
- }
-
- void remove(int i) {
- this->removeAt(i);
- }
- void remove(int i, int n) {
- while (n--) {
- this->removeAt(i);
- }
- }
-};
+using ExtList = QList<T>;
void tst_Collections::insert_remove_loop()
{