summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorLars Schmertmann <Lars.Schmertmann@governikus.de>2020-06-29 16:23:28 +0200
committerLars Schmertmann <lars.schmertmann@governikus.de>2020-07-06 09:42:36 +0000
commit11b3092cc4672f9832bfa26d5c31b63927d0e696 (patch)
tree5caa9442e5cad5a0678d66162ceabb928f90e924 /tests/auto/corelib
parenta5025efccfa877426dcdf31d91cacb1a6c52b276 (diff)
Refactor tst_Collections
This improves the readability and avoids code duplication in tst_Collections::forwardDeclared. Also some warnings are fixed: * qSort is deprecated. * The = operator for LargeStatic needs to be implemented explicitly when a copy constructor is given. * QMap::insertMulti is deprecated, a MultiMap is required. Task-number: QTBUG-82978 Change-Id: I577f851394edfaa30154bd3417ce391635cc546d Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp70
1 files changed, 50 insertions, 20 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index ea68b21898..f7b6f478cf 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -129,6 +129,12 @@ struct LargeStatic {
static int count;
LargeStatic():c(count) { ++count; }
LargeStatic(const LargeStatic& o):c(o.c) { ++count; }
+ LargeStatic &operator=(const LargeStatic &o)
+ {
+ c = o.c;
+ ++count;
+ return *this;
+ };
~LargeStatic() { --count; }
int c;
int data[8];
@@ -1326,19 +1332,19 @@ void tst_Collections::hash()
hash1.unite(hash2);
QCOMPARE(hash1.size(), 5);
auto values = hash1.values();
- qSort(values);
+ std::sort(values.begin(), values.end());
QList<QString> expected;
expected << "Gamma" << "Gamma" << "Beta" << "Gamma" << "Alpha";
- qSort(expected);
+ std::sort(expected.begin(), expected.end());
QCOMPARE(values, expected);
hash2 = hash1;
hash2.unite(hash2);
QCOMPARE(hash2.size(), 10);
values = hash2.values();
- qSort(values);
+ std::sort(values.begin(), values.end());
expected += expected;
- qSort(expected);
+ std::sort(expected.begin(), expected.end());
QCOMPARE(values, expected);
}
}
@@ -1645,12 +1651,12 @@ void tst_Collections::map()
}
{
- QMap<int, QString> map1, map2;
- map1.insertMulti(1, "Alpha");
- map1.insertMulti(1, "Gamma");
- map2.insertMulti(1, "Beta");
- map2.insertMulti(1, "Gamma");
- map2.insertMulti(1, "Gamma");
+ QMultiMap<int, QString> map1, map2;
+ map1.insert(1, "Alpha");
+ map1.insert(1, "Gamma");
+ map2.insert(1, "Beta");
+ map2.insert(1, "Gamma");
+ map2.insert(1, "Gamma");
map1.unite(map2);
QCOMPARE(map1.size(), 5);
@@ -2895,16 +2901,40 @@ class T2;
void tst_Collections::forwardDeclared()
{
- { typedef QHash<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
- { typedef QMultiHash<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
- { typedef QMap<Key1, T1> C; C *x = 0; C::iterator i; C::const_iterator j; Q_UNUSED(x) }
- { 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 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) }
+#define COMMA ,
+#define TEST(type) do { \
+ using C = type; \
+ C *x = nullptr; \
+ C::iterator i; \
+ C::const_iterator j; \
+ Q_UNUSED(x); \
+ Q_UNUSED(i); \
+ Q_UNUSED(j); \
+ } while (false)
+
+ TEST(QHash<Key1 COMMA T1>);
+ TEST(QMap<Key1 COMMA T1>);
+ TEST(QMultiMap<Key1 COMMA T1>);
+ TEST(QList<T1>);
+ TEST(QVector<T1>);
+ TEST(QStack<T1>);
+ TEST(QQueue<T1>);
+#undef TEST
+#undef COMMA
+
+ {
+ using C = QPair<T1, T2>;
+ C *x = nullptr;
+ Q_UNUSED(x);
+ }
+
+ {
+ using C = QSet<T1>;
+ C *x = nullptr;
+ C::const_iterator j;
+ Q_UNUSED(x);
+ Q_UNUSED(j);
+ }
}
class alignas(4) Aligned4