diff options
Diffstat (limited to 'tests/auto/corelib/tools/collections/tst_collections.cpp')
-rw-r--r-- | tests/auto/corelib/tools/collections/tst_collections.cpp | 189 |
1 files changed, 80 insertions, 109 deletions
diff --git a/tests/auto/corelib/tools/collections/tst_collections.cpp b/tests/auto/corelib/tools/collections/tst_collections.cpp index b9487cee33..af270ded98 100644 --- a/tests/auto/corelib/tools/collections/tst_collections.cpp +++ b/tests/auto/corelib/tools/collections/tst_collections.cpp @@ -1,31 +1,26 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:LGPL21$ +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms -** and conditions see http://www.qt.io/terms-conditions. For further -** information use the contact form at http://www.qt.io/contact-us. +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. ** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 or version 3 as published by the Free -** Software Foundation and appearing in the file LICENSE.LGPLv21 and -** LICENSE.LGPLv3 included in the packaging of this file. Please review the -** following information to ensure the GNU Lesser General Public License -** requirements will be met: https://www.gnu.org/licenses/lgpl.html and -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** As a special exception, The Qt Company gives you certain additional -** rights. These rights are described in The Qt Company LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. ** ** $QT_END_LICENSE$ ** @@ -98,13 +93,6 @@ class tst_Collections : public QObject { Q_OBJECT -public: - tst_Collections(); - ~tst_Collections(); - -public slots: - void init(); - void cleanup(); private slots: void typeinfo(); void qstring(); @@ -176,23 +164,6 @@ struct Pod { int i1, i2; }; -tst_Collections::tst_Collections() -{ -} - -tst_Collections::~tst_Collections() -{ - -} - -void tst_Collections::init() -{ -} - -void tst_Collections::cleanup() -{ -} - void tst_Collections::typeinfo() { QVERIFY(QTypeInfo<int*>::isPointer); @@ -519,11 +490,11 @@ void tst_Collections::list() QList<QString> list = vector.toList(); QVERIFY(list.size() == 5); - QVERIFY(list.at(0) == "99"); - QVERIFY(list.at(4) == "100"); + QCOMPARE(list.at(0), QLatin1String("99")); + QCOMPARE(list.at(4), QLatin1String("100")); list[0] = "10"; - QVERIFY(list.at(0) == "10"); - QVERIFY(vector.at(0) == "99"); + QCOMPARE(list.at(0), QLatin1String("10")); + QCOMPARE(vector.at(0), QLatin1String("99")); } @@ -535,15 +506,15 @@ void tst_Collections::list() QVERIFY((*it)[0] == QChar('H')); QVERIFY(it->constData()[0] == QChar('H')); it->replace(QChar('H'), QChar('X')); - QVERIFY(list.first() == "Xello"); + QCOMPARE(list.first(), QLatin1String("Xello")); QList<QString>::const_iterator cit = list.constBegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); cit = list.cbegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(),QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); } { @@ -577,10 +548,10 @@ void tst_Collections::list() list << "alpha" << "beta"; list += list; QVERIFY(list.size() == 4); - QVERIFY(list.at(0) == "alpha"); - QVERIFY(list.at(1) == "beta"); - QVERIFY(list.at(2) == "alpha"); - QVERIFY(list.at(3) == "beta"); + QCOMPARE(list.at(0), QLatin1String("alpha")); + QCOMPARE(list.at(1), QLatin1String("beta")); + QCOMPARE(list.at(2), QLatin1String("alpha")); + QCOMPARE(list.at(3), QLatin1String("beta")); } // test endcases for inserting into a qlist @@ -956,15 +927,15 @@ void tst_Collections::linkedList() QVERIFY((*it)[0] == QChar('H')); QVERIFY(it->constData()[0] == QChar('H')); it->replace(QChar('H'), QChar('X')); - QVERIFY(list.first() == "Xello"); + QCOMPARE(list.first(), QLatin1String("Xello")); QLinkedList<QString>::const_iterator cit = list.constBegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); cit = list.cbegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); } { @@ -972,10 +943,10 @@ void tst_Collections::linkedList() list << "alpha" << "beta"; list += list; QVERIFY(list.size() == 4); - QVERIFY(*list.begin() == "alpha"); - QVERIFY(*(list.begin() + 1) == "beta"); - QVERIFY(*(list.begin() + 2) == "alpha"); - QVERIFY(*(list.begin() + 3) == "beta"); + QCOMPARE(*list.begin(), QLatin1String("alpha")); + QCOMPARE(*(list.begin() + 1), QLatin1String("beta")); + QCOMPARE(*(list.begin() + 2), QLatin1String("alpha")); + QCOMPARE(*(list.begin() + 3), QLatin1String("beta")); } { @@ -1056,8 +1027,8 @@ void tst_Collections::vector() QVector<QString> vec; vec << "foo" << "bar"; vec.reserve( 512 ); - QVERIFY(vec[0] == "foo"); - QVERIFY(vec[1] == "bar"); + QCOMPARE(vec[0], QLatin1String("foo")); + QCOMPARE(vec[1], QLatin1String("bar")); int initialLargeStaticCount = LargeStatic::count; { @@ -1072,10 +1043,10 @@ void tst_Collections::vector() vector << "alpha" << "beta"; vector += vector; QVERIFY(vector.size() == 4); - QVERIFY(vector.at(0) == "alpha"); - QVERIFY(vector.at(1) == "beta"); - QVERIFY(vector.at(2) == "alpha"); - QVERIFY(vector.at(3) == "beta"); + QCOMPARE(vector.at(0), QLatin1String("alpha")); + QCOMPARE(vector.at(1), QLatin1String("beta")); + QCOMPARE(vector.at(2), QLatin1String("alpha")); + QCOMPARE(vector.at(3), QLatin1String("beta")); } int originalLargeStaticCount = LargeStatic::count; @@ -1596,15 +1567,15 @@ void tst_Collections::hash() QVERIFY((*it)[0] == QChar('H')); QVERIFY(it->constData()[0] == QChar('H')); it->replace(QChar('H'), QChar('X')); - QVERIFY(*hash.begin() == "Xello"); + QCOMPARE(*hash.begin(), QLatin1String("Xello")); QHash<int, QString>::const_iterator cit = hash.constBegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); cit = hash.cbegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); } { @@ -1917,15 +1888,15 @@ void tst_Collections::map() QVERIFY((*it)[0] == QChar('H')); QVERIFY(it->constData()[0] == QChar('H')); it->replace(QChar('H'), QChar('X')); - QVERIFY(*map.begin() == "Xello"); + QCOMPARE(*map.begin(), QLatin1String("Xello")); QMap<int, QString>::const_iterator cit = map.constBegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); cit = map.cbegin(); - QVERIFY((*cit).toLower() == "xello"); - QVERIFY(cit->toUpper() == "XELLO"); + QCOMPARE((*cit).toLower(), QLatin1String("xello")); + QCOMPARE(cit->toUpper(), QLatin1String("XELLO")); } { @@ -2007,17 +1978,17 @@ void tst_Collections::qstring() QVERIFY(hello.left(0) == ""); QVERIFY(!hello.left(0).isNull()); - QVERIFY(hello.left(1) == "h"); - QVERIFY(hello.left(2) == "he"); - QVERIFY(hello.left(200) == "hello"); + QCOMPARE(hello.left(1), QLatin1String("h")); + QCOMPARE(hello.left(2), QLatin1String("he")); + QCOMPARE(hello.left(200), QLatin1String("hello")); QVERIFY(hello.left(hello.size()) == hello); QVERIFY(hello.left(hello.size()+1) == hello); QVERIFY(hello.right(0) == ""); QVERIFY(!hello.right(0).isNull()); - QVERIFY(hello.right(1) == "o"); - QVERIFY(hello.right(2) == "lo"); - QVERIFY(hello.right(200) == "hello"); + QCOMPARE(hello.right(1), QLatin1String("o")); + QCOMPARE(hello.right(2), QLatin1String("lo")); + QCOMPARE(hello.right(200), QLatin1String("hello")); QVERIFY(hello.right(hello.size()) == hello); QVERIFY(hello.right(hello.size()+1) == hello); @@ -2025,16 +1996,16 @@ void tst_Collections::qstring() QVERIFY(hello.mid(0, 1) == "h"); QVERIFY(hello.mid(0, 2) == "he"); QVERIFY(hello.mid(0, 200) == "hello"); - QVERIFY(hello.mid(0) == "hello"); + QCOMPARE(hello.mid(0), QLatin1String("hello")); QVERIFY(hello.mid(0, hello.size()) == hello); QVERIFY(hello.mid(0, hello.size()+1) == hello); QVERIFY(hello.mid(hello.size()-0) == ""); QVERIFY(hello.mid(hello.size()-0).isEmpty()); QVERIFY(!hello.mid(hello.size()-0).isNull()); - QVERIFY(hello.mid(hello.size()-1) == "o"); - QVERIFY(hello.mid(hello.size()-2) == "lo"); - QVERIFY(hello.mid(hello.size()-200) == "hello"); + QCOMPARE(hello.mid(hello.size()-1), QLatin1String("o")); + QCOMPARE(hello.mid(hello.size()-2), QLatin1String("lo")); + QCOMPARE(hello.mid(hello.size()-200), QLatin1String("hello")); QString null; QString nonNull = ""; @@ -2050,7 +2021,7 @@ void tst_Collections::qstring() QString fill = "123"; fill.fill('a'); - QVERIFY(fill == "aaa"); + QCOMPARE(fill, QLatin1String("aaa")); s.clear(); s = hello; @@ -2062,15 +2033,15 @@ void tst_Collections::qstring() QVERIFY(s == helloWorld); s = "012345"; s.insert(3, 'E'); - QVERIFY(s == "012E345"); + QCOMPARE(s, QLatin1String("012E345")); s.insert(3, "INSID"); - QVERIFY(s == "012INSIDE345"); + QCOMPARE(s, QLatin1String("012INSIDE345")); s = "short"; s.insert(7, 'E'); - QVERIFY(s == "short E"); + QCOMPARE(s, QLatin1String("short E")); s = "short"; s.insert(7, "END"); - QVERIFY(s == "short END"); + QCOMPARE(s, QLatin1String("short END")); QVERIFY(QString::fromLatin1("hello") == "hello"); @@ -2127,25 +2098,25 @@ void tst_Collections::qstring() s += QChar((uchar) 0xb0); QVERIFY(s.toUtf8() != s.toLatin1()); QCOMPARE(s[s.length()-1].unicode(), (ushort)0xb0); - QVERIFY(s.left(s.length()-1) == "ascii"); + QCOMPARE(s.left(s.length()-1), QLatin1String("ascii")); QVERIFY(s == QString::fromUtf8(s.toUtf8().constData())); s = "12"; s.append('3'); s += '4'; - QVERIFY(s == "1234"); + QCOMPARE(s, QLatin1String("1234")); s = "repend"; s.prepend('p'); - QVERIFY(s == "prepend"); + QCOMPARE(s, QLatin1String("prepend")); s.prepend("abc "); - QVERIFY(s == "abc prepend"); + QCOMPARE(s, QLatin1String("abc prepend")); s = " whitespace "; - QVERIFY(s.trimmed() == "whitespace"); + QCOMPARE(s.trimmed(), QLatin1String("whitespace")); s = " lots of stuff "; - QVERIFY(s.simplified() == "lots of stuff"); + QCOMPARE(s.simplified(), QLatin1String("lots of stuff")); s = "a hat, a stick, a ski"; QVERIFY(s[2] == 'h'); @@ -2154,17 +2125,17 @@ void tst_Collections::qstring() s = "12223"; s.remove(1, 2); - QVERIFY(s == "123"); + QCOMPARE(s, QLatin1String("123")); s = "(%1)(%2)"; s = s.arg("foo").arg(7); - QVERIFY(s == "(foo)(7)"); + QCOMPARE(s, QLatin1String("(foo)(7)")); s = "stl rocks"; std::string stl_string = s.toStdString(); // TODO: std::string stl_string = s does not work. - QVERIFY(s == "stl rocks"); + QCOMPARE(s, QLatin1String("stl rocks")); s = QString::fromStdString(stl_string); // TODO: s = stl_string does not work. - QVERIFY(s == "stl rocks"); + QCOMPARE(s, QLatin1String("stl rocks")); { QString str("Bananas"); @@ -2180,10 +2151,10 @@ void tst_Collections::qstring() QString str = "Hello"; QString cstr = QString::fromRawData(str.unicode(), str.length()); - QVERIFY(str == "Hello"); - QVERIFY(cstr == "Hello"); + QCOMPARE(str, QLatin1String("Hello")); + QCOMPARE(cstr, QLatin1String("Hello")); cstr.clear(); - QVERIFY(str == "Hello"); + QCOMPARE(str, QLatin1String("Hello")); QVERIFY(cstr.isEmpty()); { @@ -2330,7 +2301,7 @@ void tst_Collections::pair() QPair<int, QString> a(1, "Zebra"), b(2, "Ying"), c(3, "Yang"), d(3, "Ying"), e(5, "Alabama"); QVERIFY(a.first == 1); - QVERIFY(a.second == "Zebra"); + QCOMPARE(a.second, QLatin1String("Zebra")); QVERIFY(a == qMakePair(1, QString("Zebra"))); QVERIFY(a == a && b == b && c == c && d == d && e == e); @@ -3484,7 +3455,7 @@ template<class Container> void foreach_test_arrays(const Container &container) void tst_Collections::foreach_2() { - QStringList strlist = QString::fromLatin1("a,b,c,d,e,f,g,h,ih,kl,mn,op,qr,st,uvw,xyz").split(","); + QStringList strlist = QString::fromLatin1("a,b,c,d,e,f,g,h,ih,kl,mn,op,qr,st,uvw,xyz").split(QLatin1Char(',')); foreach_test_arrays(strlist); foreach_test_arrays(QList<QString>(strlist)); foreach_test_arrays(strlist.toVector()); |