summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/collections/tst_collections.cpp43
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp236
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro1
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp147
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp30
-rw-r--r--tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp151
6 files changed, 275 insertions, 333 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp
index 023b22b4ba..f319244bd3 100644
--- a/tests/auto/corelib/tools/collections/tst_collections.cpp
+++ b/tests/auto/corelib/tools/collections/tst_collections.cpp
@@ -1551,12 +1551,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);
@@ -1986,15 +1986,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"));
@@ -2710,8 +2701,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);
@@ -2721,8 +2714,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);
@@ -2933,10 +2924,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>
@@ -2944,10 +2931,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>
@@ -3020,11 +3006,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);
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 91cd3eb0bd..4052eff0ae 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -451,20 +451,6 @@ void tst_QHash::insert1()
QCOMPARE(hash.find(searchKey).value(), id01.id); // last-inserted value
QCOMPARE(hash.find(searchKey).key().id, id00.id); // but first-inserted key
}
- {
- QMultiHash<IdentityTracker, int> hash;
- QCOMPARE(hash.size(), 0);
- const int dummy = -1;
- IdentityTracker id00 = {0, 0}, id01 = {0, 1}, searchKey = {0, dummy};
- QCOMPARE(hash.insert(id00, id00.id).key().id, id00.id);
- QCOMPARE(hash.size(), 1);
- QCOMPARE(hash.insert(id01, id01.id).key().id, id01.id);
- QCOMPARE(hash.size(), 2);
- QMultiHash<IdentityTracker, int>::const_iterator pos = hash.constFind(searchKey);
- QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with
- ++pos;
- QCOMPARE(pos.value(), pos.key().id); // key fits to value it was inserted with
- }
}
void tst_QHash::erase()
@@ -491,13 +477,15 @@ void tst_QHash::erase()
++n;
}
QVERIFY(n == 3);
- QHash<int, int> h2;
- h2.insertMulti(20, 41);
- h2.insertMulti(20, 42);
+
+ QMultiHash<int, int> h2;
+ h2.insert(20, 41);
+ h2.insert(20, 42);
QVERIFY(h2.size() == 2);
- it1 = h2.erase(h2.begin());
- it1 = h2.erase(h2.begin());
- QVERIFY(it1 == h2.end());
+ auto bit = h2.begin();
+ auto mit = h2.erase(bit);
+ mit = h2.erase(h2.begin());
+ QVERIFY(mit == h2.end());
}
void tst_QHash::key()
@@ -631,14 +619,15 @@ void tst_QHash::find()
QCOMPARE(map1.find(1).value(), QLatin1String("Mayer"));
QCOMPARE(map1.find(2).value(), QLatin1String("Hej"));
- for(i = 3; i < 10; ++i) {
+ QMultiHash<int, QString> multiMap(map1);
+ for (i = 3; i < 10; ++i) {
compareString = testString.arg(i);
- map1.insertMulti(4, compareString);
+ multiMap.insert(4, compareString);
}
- QHash<int, QString>::const_iterator it=map1.constFind(4);
+ auto it = multiMap.constFind(4);
- for(i = 9; i > 2 && it != map1.constEnd() && it.key() == 4; --i) {
+ for (i = 9; i > 2 && it != multiMap.constEnd() && it.key() == 4; --i) {
compareString = testString.arg(i);
QVERIFY(it.value() == compareString);
++it;
@@ -664,14 +653,15 @@ void tst_QHash::constFind()
QCOMPARE(map1.constFind(1).value(), QLatin1String("Mayer"));
QCOMPARE(map1.constFind(2).value(), QLatin1String("Hej"));
- for(i = 3; i < 10; ++i) {
+ QMultiHash<int, QString> multiMap(map1);
+ for (i = 3; i < 10; ++i) {
compareString = testString.arg(i);
- map1.insertMulti(4, compareString);
+ multiMap.insert(4, compareString);
}
- QHash<int, QString>::const_iterator it=map1.constFind(4);
+ auto it = multiMap.constFind(4);
- for(i = 9; i > 2 && it != map1.constEnd() && it.key() == 4; --i) {
+ for (i = 9; i > 2 && it != multiMap.constEnd() && it.key() == 4; --i) {
compareString = testString.arg(i);
QVERIFY(it.value() == compareString);
++it;
@@ -689,9 +679,9 @@ void tst_QHash::contains()
map1.insert(1, "one");
QVERIFY(map1.contains(1));
- for(i=2; i < 100; ++i)
+ for (i=2; i < 100; ++i)
map1.insert(i, "teststring");
- for(i=99; i > 1; --i)
+ for (i=99; i > 1; --i)
QVERIFY(map1.contains(i));
map1.remove(43);
@@ -855,33 +845,33 @@ void tst_QHash::operator_eq()
// regardless of insertion or iteration order
{
- QHash<int, int> a;
- QHash<int, int> b;
+ QMultiHash<int, int> a;
+ QMultiHash<int, int> b;
- a.insertMulti(0, 0);
- a.insertMulti(0, 1);
+ a.insert(0, 0);
+ a.insert(0, 1);
- b.insertMulti(0, 1);
- b.insertMulti(0, 0);
+ b.insert(0, 1);
+ b.insert(0, 0);
QVERIFY(a == b);
QVERIFY(!(a != b));
}
{
- QHash<int, int> a;
- QHash<int, int> b;
+ QMultiHash<int, int> a;
+ QMultiHash<int, int> b;
enum { Count = 100 };
for (int key = 0; key < Count; ++key) {
for (int value = 0; value < Count; ++value)
- a.insertMulti(key, value);
+ a.insert(key, value);
}
for (int key = Count - 1; key >= 0; --key) {
for (int value = 0; value < Count; ++value)
- b.insertMulti(key, value);
+ b.insert(key, value);
}
QVERIFY(a == b);
@@ -889,8 +879,8 @@ void tst_QHash::operator_eq()
}
{
- QHash<int, int> a;
- QHash<int, int> b;
+ QMultiHash<int, int> a;
+ QMultiHash<int, int> b;
enum {
Count = 100,
@@ -900,7 +890,7 @@ void tst_QHash::operator_eq()
for (int key = 0; key < Count; ++key) {
for (int value = 0; value < Count; ++value)
- a.insertMulti(key, value);
+ a.insert(key, value);
}
// Generates two permutations of [0, Count) for the keys and values,
@@ -909,7 +899,7 @@ void tst_QHash::operator_eq()
for (int k = 0; k < Count; ++k) {
const int key = (k * KeyStep) % Count;
for (int v = 0; v < Count; ++v)
- b.insertMulti(key, (v * ValueStep) % Count);
+ b.insert(key, (v * ValueStep) % Count);
}
QVERIFY(a == b);
@@ -923,10 +913,10 @@ void tst_QHash::compare()
QString testString = "Teststring %1";
int i;
- for(i = 0; i < 1000; ++i)
+ for (i = 0; i < 1000; ++i)
hash1.insert(i,testString.arg(i));
- for(--i; i >= 0; --i)
+ for (--i; i >= 0; --i)
hash2.insert(i,testString.arg(i));
hash1.squeeze();
@@ -947,39 +937,39 @@ void tst_QHash::compare()
void tst_QHash::compare2()
{
- QHash<int, int> a;
- QHash<int, int> b;
+ QMultiHash<int, int> a;
+ QMultiHash<int, int> b;
- a.insertMulti(17, 1);
- a.insertMulti(17 * 2, 1);
- b.insertMulti(17 * 2, 1);
- b.insertMulti(17, 1);
+ a.insert(17, 1);
+ a.insert(17 * 2, 1);
+ b.insert(17 * 2, 1);
+ b.insert(17, 1);
QVERIFY(a == b);
QVERIFY(b == a);
- a.insertMulti(17, 2);
- a.insertMulti(17 * 2, 3);
- b.insertMulti(17 * 2, 3);
- b.insertMulti(17, 2);
+ a.insert(17, 2);
+ a.insert(17 * 2, 3);
+ b.insert(17 * 2, 3);
+ b.insert(17, 2);
QVERIFY(a == b);
QVERIFY(b == a);
- a.insertMulti(17, 4);
- a.insertMulti(17 * 2, 5);
- b.insertMulti(17 * 2, 4);
- b.insertMulti(17, 5);
+ a.insert(17, 4);
+ a.insert(17 * 2, 5);
+ b.insert(17 * 2, 4);
+ b.insert(17, 5);
QVERIFY(!(a == b));
QVERIFY(!(b == a));
a.clear();
b.clear();
- a.insertMulti(1, 1);
- a.insertMulti(1, 2);
- a.insertMulti(1, 3);
- b.insertMulti(1, 1);
- b.insertMulti(1, 2);
- b.insertMulti(1, 3);
- b.insertMulti(1, 4);
+ a.insert(1, 1);
+ a.insert(1, 2);
+ a.insert(1, 3);
+ b.insert(1, 1);
+ b.insert(1, 2);
+ b.insert(1, 3);
+ b.insert(1, 4);
QVERIFY(!(a == b));
QVERIFY(!(b == a));
}
@@ -993,7 +983,7 @@ void tst_QHash::iterators()
QString testString1;
int i;
- for(i = 1; i < 100; ++i)
+ for (i = 1; i < 100; ++i)
hash.insert(i, testString.arg(i));
//to get some chaos in the hash
@@ -1010,18 +1000,13 @@ void tst_QHash::iterators()
QVERIFY(stlIt.value() == testMap.value(1));
- stlIt+=5;
+ for (int i = 0; i < 5; ++i)
+ ++stlIt;
QVERIFY(stlIt.value() == testMap.value(6));
stlIt++;
QVERIFY(stlIt.value() == testMap.value(7));
- stlIt-=3;
- QVERIFY(stlIt.value() == testMap.value(4));
-
- stlIt--;
- QVERIFY(stlIt.value() == testMap.value(3));
-
testMap.clear();
//STL-Style const-iterators
@@ -1035,18 +1020,13 @@ void tst_QHash::iterators()
QVERIFY(cstlIt.value() == testMap.value(1));
- cstlIt+=5;
+ for (int i = 0; i < 5; ++i)
+ ++cstlIt;
QVERIFY(cstlIt.value() == testMap.value(6));
cstlIt++;
QVERIFY(cstlIt.value() == testMap.value(7));
- cstlIt-=3;
- QVERIFY(cstlIt.value() == testMap.value(4));
-
- cstlIt--;
- QVERIFY(cstlIt.value() == testMap.value(3));
-
testMap.clear();
//Java-Style iterators
@@ -1068,14 +1048,7 @@ void tst_QHash::iterators()
QVERIFY(javaIt.value() == testMap.value(i));
}
- ++i;
- while(javaIt.hasPrevious()) {
- --i;
- javaIt.previous();
- QVERIFY(javaIt.value() == testMap.value(i));
- }
-
- //peekNext() peekPrevious()
+ //peekNext()
javaIt.toFront();
javaIt.next();
while(javaIt.hasNext()) {
@@ -1083,14 +1056,6 @@ void tst_QHash::iterators()
testString1 = javaIt.peekNext().value();
javaIt.next();
QVERIFY(javaIt.value() == testString1);
- QCOMPARE(javaIt.peekPrevious().value(), testString1);
- }
- while(javaIt.hasPrevious()) {
- testString = javaIt.value();
- testString1 = javaIt.peekPrevious().value();
- javaIt.previous();
- QVERIFY(javaIt.value() == testString1);
- QCOMPARE(javaIt.peekNext().value(), testString1);
}
}
@@ -1115,9 +1080,15 @@ void tst_QHash::keyIterator()
QVERIFY(key_it != hash.keyEnd());
QCOMPARE(*key_it, it.key());
QCOMPARE(*(key_it++), (it++).key());
- QCOMPARE(*(key_it--), (it--).key());
- QCOMPARE(*(++key_it), (++it).key());
- QCOMPARE(*(--key_it), (--it).key());
+ if (key_it != hash.keyEnd()) {
+ QVERIFY(it != hash.end());
+ ++key_it;
+ ++it;
+ if (key_it != hash.keyEnd())
+ QCOMPARE(*key_it, it.key());
+ else
+ QVERIFY(it == hash.end());
+ }
QCOMPARE(std::count(hash.keyBegin(), hash.keyEnd(), 99), 1);
@@ -1162,19 +1133,11 @@ void tst_QHash::keyValueIterator()
++it;
++key_value_it;
- QCOMPARE(*key_value_it, entry_type(it.key(), it.value()));
-
- --it;
- --key_value_it;
- QCOMPARE(*key_value_it, entry_type(it.key(), it.value()));
-
- ++it;
- ++key_value_it;
- QCOMPARE(*key_value_it, entry_type(it.key(), it.value()));
+ if (it != hash.end())
+ QCOMPARE(*key_value_it, entry_type(it.key(), it.value()));
+ else
+ QVERIFY(key_value_it == hash.constKeyValueEnd());
- --it;
- --key_value_it;
- QCOMPARE(*key_value_it, entry_type(it.key(), it.value()));
key = 99;
value = 99 * 100;
QCOMPARE(std::count(hash.constKeyValueBegin(), hash.constKeyValueEnd(), entry_type(key, value)), 1);
@@ -1184,9 +1147,9 @@ void tst_QHash::rehash_isnt_quadratic()
{
// this test should be incredibly slow if rehash() is quadratic
for (int j = 0; j < 5; ++j) {
- QHash<int, int> testHash;
+ QMultiHash<int, int> testHash;
for (int i = 0; i < 500000; ++i)
- testHash.insertMulti(1, 1);
+ testHash.insert(1, 1);
}
}
@@ -1330,27 +1293,27 @@ QList<T> sorted(const QList<T> &list)
void tst_QHash::keys_values_uniqueKeys()
{
- QHash<QString, int> hash;
+ QMultiHash<QString, int> hash;
QVERIFY(hash.uniqueKeys().isEmpty());
QVERIFY(hash.keys().isEmpty());
QVERIFY(hash.values().isEmpty());
- hash.insertMulti("alpha", 1);
+ hash.insert("alpha", 1);
QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha"));
QVERIFY(hash.keys() == hash.uniqueKeys());
QVERIFY(hash.values() == (QList<int>() << 1));
- hash.insertMulti("beta", -2);
+ hash.insert("beta", -2);
QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "beta"));
QVERIFY(hash.keys() == hash.uniqueKeys());
QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 1 << -2));
- hash.insertMulti("alpha", 2);
+ hash.insert("alpha", 2);
QVERIFY(sorted(hash.uniqueKeys()) == (QList<QString>() << "alpha" << "beta"));
QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "alpha" << "beta"));
QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 2 << 1 << -2));
- hash.insertMulti("beta", 4);
+ hash.insert("beta", 4);
QVERIFY(sorted(hash.uniqueKeys()) == (QList<QString>() << "alpha" << "beta"));
QVERIFY(sorted(hash.keys()) == (QList<QString>() << "alpha" << "alpha" << "beta" << "beta"));
QVERIFY(sorted(hash.values()) == sorted(QList<int>() << 2 << 1 << 4 << -2));
@@ -1504,14 +1467,14 @@ void tst_QHash::initializerList()
void tst_QHash::eraseValidIteratorOnSharedHash()
{
- QHash<int, int> a, b;
+ QMultiHash<int, int> a, b;
a.insert(10, 10);
- a.insertMulti(10, 25);
- a.insertMulti(10, 30);
+ a.insert(10, 25);
+ a.insert(10, 30);
a.insert(20, 20);
a.insert(40, 40);
- QHash<int, int>::iterator i = a.begin();
+ auto i = a.begin();
while (i.value() != 25)
++i;
@@ -1533,7 +1496,7 @@ void tst_QHash::eraseValidIteratorOnSharedHash()
void tst_QHash::equal_range()
{
- QHash<int, QString> hash;
+ QMultiHash<int, QString> hash;
auto result = hash.equal_range(0);
QCOMPARE(result.first, hash.end());
@@ -1546,7 +1509,7 @@ void tst_QHash::equal_range()
QCOMPARE(result.first, hash.find(1));
QVERIFY(std::distance(result.first, result.second) == 1);
- QHash<int, int> h1;
+ QMultiHash<int, int> h1;
{
auto p = h1.equal_range(0);
QVERIFY(p.first == p.second);
@@ -1597,7 +1560,7 @@ void tst_QHash::equal_range()
QVERIFY(p2.first == m1.begin() || p2.second == m1.end());
}
- const QHash<int, int> ch1 = h1;
+ const QMultiHash<int, int> ch1 = h1;
{
auto p1 = ch1.equal_range(9);
QVERIFY(p1.first == p1.second);
@@ -1623,10 +1586,10 @@ void tst_QHash::equal_range()
QVERIFY(p2.first == cm1.cbegin() || p2.second == cm1.cend());
}
- QHash<int, int> h2;
+ QMultiHash<int, int> h2;
for (int i = 0; i < 8; ++i)
for (int j = 0; j < 8; ++j)
- h2.insertMulti(i, i*j);
+ h2.insert(i, i*j);
for (int i = 0; i < 8; ++i) {
auto pair = h2.equal_range(i);
@@ -1692,21 +1655,6 @@ void tst_QHash::insert_hash()
QCOMPARE(hash[2], 5);
QCOMPARE(hash[7], 55);
}
- {
- // This will use a QMultiHash and then insert that into QHash,
- // the ordering is undefined so we won't test that but make
- // sure this isn't adding multiple entries with the same key
- // to the QHash.
- QHash<int, int> hash;
- QMultiHash<int, int> hash2;
- hash2.insert(0, 5);
- hash2.insert(0, 6);
- hash2.insert(0, 7);
-
- hash.insert(hash2);
-
- QCOMPARE(hash.count(), 1);
- }
}
QTEST_APPLESS_MAIN(tst_QHash)
diff --git a/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro b/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro
index c8e6a8e05a..6c00f4f081 100644
--- a/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro
+++ b/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro
@@ -1,6 +1,5 @@
CONFIG += testcase
TARGET = tst_qoffsetstringarray
QT = core testlib core-private
-CONFIG += c++11
CONFIG += strict_c++
SOURCES = $$PWD/tst_qoffsetstringarray.cpp
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index 6638ad8b60..0ca8be7fa3 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -59,7 +59,6 @@ private slots:
void begin();
void end();
void insert();
- void reverseIterators();
void setOperations();
void stlIterator();
void stlMutableIterator();
@@ -577,21 +576,6 @@ void tst_QSet::insert()
}
}
-void tst_QSet::reverseIterators()
-{
- QSet<int> s;
- s << 1 << 17 << 61 << 127 << 911;
- std::vector<int> v(s.begin(), s.end());
- std::reverse(v.begin(), v.end());
- const QSet<int> &cs = s;
- QVERIFY(std::equal(v.begin(), v.end(), s.rbegin()));
- QVERIFY(std::equal(v.begin(), v.end(), s.crbegin()));
- QVERIFY(std::equal(v.begin(), v.end(), cs.rbegin()));
- QVERIFY(std::equal(s.rbegin(), s.rend(), v.begin()));
- QVERIFY(std::equal(s.crbegin(), s.crend(), v.begin()));
- QVERIFY(std::equal(cs.rbegin(), cs.rend(), v.begin()));
-}
-
void tst_QSet::setOperations()
{
QSet<QString> set1, set2;
@@ -705,16 +689,6 @@ void tst_QSet::stlIterator()
}
QVERIFY(sum == 24999 * 25000 / 2);
}
-
- {
- int sum = 0;
- QSet<QString>::const_iterator i = set1.end();
- while (i != set1.begin()) {
- --i;
- sum += toNumber(*i);
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
}
void tst_QSet::stlMutableIterator()
@@ -734,21 +708,10 @@ void tst_QSet::stlMutableIterator()
}
{
- int sum = 0;
- QSet<QString>::iterator i = set1.end();
- while (i != set1.begin()) {
- --i;
- sum += toNumber(*i);
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
QSet<QString> set2 = set1;
QSet<QString> set3 = set2;
QSet<QString>::iterator i = set2.begin();
- QSet<QString>::iterator j = set3.begin();
while (i != set2.end()) {
i = set2.erase(i);
@@ -756,24 +719,7 @@ void tst_QSet::stlMutableIterator()
QVERIFY(set2.isEmpty());
QVERIFY(!set3.isEmpty());
- j = set3.end();
- while (j != set3.begin()) {
- j--;
- if (j + 1 != set3.end())
- set3.erase(j + 1);
- }
- if (set3.begin() != set3.end())
- set3.erase(set3.begin());
-
- QVERIFY(set2.isEmpty());
- QVERIFY(set3.isEmpty());
-
-// #if QT_VERSION >= 0x050000
-// i = set2.insert("foo");
-// #else
- QSet<QString>::const_iterator k = set2.insert("foo");
- i = reinterpret_cast<QSet<QString>::iterator &>(k);
-// #endif
+ i = set2.insert("foo");
QCOMPARE(*i, QLatin1String("foo"));
}
}
@@ -802,47 +748,6 @@ void tst_QSet::javaIterator()
QVERIFY(sum == 24999 * 25000 / 2);
}
- {
- int sum = 0;
- QSetIterator<QString> i(set1);
- while (i.hasNext()) {
- i.next();
- sum += toNumber(i.peekPrevious());
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
- int sum = 0;
- QSetIterator<QString> i(set1);
- i.toBack();
- while (i.hasPrevious())
- sum += toNumber(i.previous());
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
- int sum = 0;
- QSetIterator<QString> i(set1);
- i.toBack();
- while (i.hasPrevious()) {
- sum += toNumber(i.peekPrevious());
- i.previous();
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
- int sum = 0;
- QSetIterator<QString> i(set1);
- i.toBack();
- while (i.hasPrevious()) {
- i.previous();
- sum += toNumber(i.peekNext());
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
int sum1 = 0;
int sum2 = 0;
QSetIterator<QString> i(set1);
@@ -897,52 +802,10 @@ void tst_QSet::javaMutableIterator()
}
{
- int sum = 0;
- QMutableSetIterator<QString> i(set1);
- while (i.hasNext()) {
- i.next();
- sum += toNumber(i.peekPrevious());
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
- int sum = 0;
- QMutableSetIterator<QString> i(set1);
- i.toBack();
- while (i.hasPrevious())
- sum += toNumber(i.previous());
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
- int sum = 0;
- QMutableSetIterator<QString> i(set1);
- i.toBack();
- while (i.hasPrevious()) {
- sum += toNumber(i.peekPrevious());
- i.previous();
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
- int sum = 0;
- QMutableSetIterator<QString> i(set1);
- i.toBack();
- while (i.hasPrevious()) {
- i.previous();
- sum += toNumber(i.peekNext());
- }
- QVERIFY(sum == 24999 * 25000 / 2);
- }
-
- {
QSet<QString> set2 = set1;
QSet<QString> set3 = set2;
QMutableSetIterator<QString> i(set2);
- QMutableSetIterator<QString> j(set3);
while (i.hasNext()) {
i.next();
@@ -950,14 +813,6 @@ void tst_QSet::javaMutableIterator()
}
QVERIFY(set2.isEmpty());
QVERIFY(!set3.isEmpty());
-
- j.toBack();
- while (j.hasPrevious()) {
- j.previous();
- j.remove();
- }
- QVERIFY(set2.isEmpty());
- QVERIFY(set3.isEmpty());
}
}
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index a9fd282ac9..8a621cd5d9 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -2155,7 +2155,7 @@ void tst_QSharedPointer::threadStressTest()
}
}
-template<typename Container, bool Ordered>
+template<typename Container, bool Ordered, bool Multi>
void hashAndMapTest()
{
typedef typename Container::key_type Key;
@@ -2200,26 +2200,30 @@ void hashAndMapTest()
QVERIFY(it == c.end());
}
- c.insertMulti(k1, Value(47));
- it = c.find(k1);
- QVERIFY(it != c.end());
- QCOMPARE(it.key(), k1);
- ++it;
- QVERIFY(it != c.end());
- QCOMPARE(it.key(), k1);
- ++it;
- if (Ordered)
- QVERIFY(it == c.end());
+ if (Multi) {
+ c.insert(k1, Value(47));
+ it = c.find(k1);
+ QVERIFY(it != c.end());
+ QCOMPARE(it.key(), k1);
+ ++it;
+ QVERIFY(it != c.end());
+ QCOMPARE(it.key(), k1);
+ ++it;
+ if (Ordered)
+ QVERIFY(it == c.end());
+ }
}
void tst_QSharedPointer::map()
{
- hashAndMapTest<QMap<QSharedPointer<int>, int>, true>();
+ hashAndMapTest<QMap<QSharedPointer<int>, int>, true, false>();
+ hashAndMapTest<QMultiMap<QSharedPointer<int>, int>, true, true>();
}
void tst_QSharedPointer::hash()
{
- hashAndMapTest<QHash<QSharedPointer<int>, int>, false>();
+ hashAndMapTest<QHash<QSharedPointer<int>, int>, false, false>();
+ hashAndMapTest<QMultiHash<QSharedPointer<int>, int>, false, true>();
}
void tst_QSharedPointer::validConstructs()
diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
index 7c4d1071ce..928bd365fd 100644
--- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
+++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
@@ -81,6 +81,10 @@ private slots:
void serialize();
void moveSemantics();
void qtVersion();
+ void qTypeRevision_data();
+ void qTypeRevision();
+ void qTypeRevisionTypes();
+ void qTypeRevisionComparison();
};
void tst_QVersionNumber::singleInstanceData()
@@ -645,6 +649,153 @@ void tst_QVersionNumber::qtVersion()
QCOMPARE(v.toString(), QString(qVersion()));
}
+template<typename Integer>
+void compileTestRevisionMajorMinor()
+{
+ const Integer major = 8;
+ const Integer minor = 4;
+
+ const QTypeRevision r2 = QTypeRevision::fromVersion(major, minor);
+ QCOMPARE(r2.majorVersion(), 8);
+ QCOMPARE(r2.minorVersion(), 4);
+
+ const QTypeRevision r3 = QTypeRevision::fromMajorVersion(major);
+ QCOMPARE(r3.majorVersion(), 8);
+ QVERIFY(!r3.hasMinorVersion());
+
+ const QTypeRevision r4 = QTypeRevision::fromMinorVersion(minor);
+ QVERIFY(!r4.hasMajorVersion());
+ QCOMPARE(r4.minorVersion(), 4);
+}
+
+
+template<typename Integer>
+void compileTestRevision()
+{
+ if (std::is_signed<Integer>::value)
+ compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Signed>();
+ else
+ compileTestRevision<typename QIntegerForSize<sizeof(Integer) / 2>::Unsigned>();
+
+ const Integer value = 0x0510;
+ const QTypeRevision r = QTypeRevision::fromEncodedVersion(value);
+
+ QCOMPARE(r.majorVersion(), 5);
+ QCOMPARE(r.minorVersion(), 16);
+ QCOMPARE(r.toEncodedVersion<Integer>(), value);
+
+ compileTestRevisionMajorMinor<Integer>();
+}
+
+template<>
+void compileTestRevision<qint16>()
+{
+ compileTestRevisionMajorMinor<quint8>();
+}
+
+template<>
+void compileTestRevision<quint8>()
+{
+ compileTestRevisionMajorMinor<quint8>();
+}
+
+template<>
+void compileTestRevision<qint8>()
+{
+ compileTestRevisionMajorMinor<qint8>();
+}
+
+void tst_QVersionNumber::qTypeRevision_data()
+{
+ QTest::addColumn<QTypeRevision>("revision");
+ QTest::addColumn<bool>("valid");
+ QTest::addColumn<int>("major");
+ QTest::addColumn<int>("minor");
+
+ QTest::addRow("Qt revision") << QTypeRevision::fromVersion(QT_VERSION_MAJOR, QT_VERSION_MINOR)
+ << true << QT_VERSION_MAJOR << QT_VERSION_MINOR;
+ QTest::addRow("invalid") << QTypeRevision() << false << 0xff << 0xff;
+ QTest::addRow("major") << QTypeRevision::fromMajorVersion(6) << true << 6 << 0xff;
+ QTest::addRow("minor") << QTypeRevision::fromMinorVersion(15) << true << 0xff << 15;
+ QTest::addRow("zero") << QTypeRevision::fromVersion(0, 0) << true << 0 << 0;
+
+ // We're intentionally not testing negative numbers.
+ // There are asserts against negative numbers in QTypeRevision.
+ // You must not pass them as major or minor versions, or values.
+}
+
+void tst_QVersionNumber::qTypeRevision()
+{
+ const QTypeRevision other = QTypeRevision::fromVersion(127, 128);
+
+ QFETCH(QTypeRevision, revision);
+
+ QFETCH(bool, valid);
+ QFETCH(int, major);
+ QFETCH(int, minor);
+
+ QCOMPARE(revision.isValid(), valid);
+ QCOMPARE(revision.majorVersion(), major);
+ QCOMPARE(revision.minorVersion(), minor);
+
+ QCOMPARE(revision.hasMajorVersion(), QTypeRevision::isValidSegment(major));
+ QCOMPARE(revision.hasMinorVersion(), QTypeRevision::isValidSegment(minor));
+
+ const QTypeRevision copy = QTypeRevision::fromEncodedVersion(revision.toEncodedVersion<int>());
+ QCOMPARE(copy, revision);
+
+ QVERIFY(revision != other);
+ QVERIFY(copy != other);
+}
+
+void tst_QVersionNumber::qTypeRevisionTypes()
+{
+ compileTestRevision<quint64>();
+ compileTestRevision<qint64>();
+
+ QVERIFY(!QTypeRevision::isValidSegment(0xff));
+ QVERIFY(!QTypeRevision::isValidSegment(-1));
+
+ const QTypeRevision maxRevision = QTypeRevision::fromVersion(254, 254);
+ QVERIFY(maxRevision.hasMajorVersion());
+ QVERIFY(maxRevision.hasMinorVersion());
+}
+
+void tst_QVersionNumber::qTypeRevisionComparison()
+{
+ const QTypeRevision revisions[] = {
+ QTypeRevision::zero(),
+ QTypeRevision::fromMajorVersion(0),
+ QTypeRevision::fromVersion(0, 1),
+ QTypeRevision::fromVersion(0, 20),
+ QTypeRevision::fromMinorVersion(0),
+ QTypeRevision(),
+ QTypeRevision::fromMinorVersion(1),
+ QTypeRevision::fromMinorVersion(20),
+ QTypeRevision::fromVersion(1, 0),
+ QTypeRevision::fromMajorVersion(1),
+ QTypeRevision::fromVersion(1, 1),
+ QTypeRevision::fromVersion(1, 20),
+ QTypeRevision::fromVersion(20, 0),
+ QTypeRevision::fromMajorVersion(20),
+ QTypeRevision::fromVersion(20, 1),
+ QTypeRevision::fromVersion(20, 20),
+ };
+
+ const int length = sizeof(revisions) / sizeof(QTypeRevision);
+
+ for (int i = 0; i < length; ++i) {
+ for (int j = 0; j < length; ++j) {
+ QCOMPARE(revisions[i] == revisions[j], i == j);
+ QCOMPARE(revisions[i] != revisions[j], i != j);
+ QCOMPARE(revisions[i] < revisions[j], i < j);
+ QCOMPARE(revisions[i] > revisions[j], i > j);
+ QCOMPARE(revisions[i] <= revisions[j], i <= j);
+ QCOMPARE(revisions[i] >= revisions[j], i >= j);
+ }
+ }
+}
+
QTEST_APPLESS_MAIN(tst_QVersionNumber)
#include "tst_qversionnumber.moc"