diff options
Diffstat (limited to 'tests/auto/corelib/tools')
9 files changed, 243 insertions, 59 deletions
diff --git a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp index 85b4c4bfb7..2d2c536453 100644 --- a/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp +++ b/tests/auto/corelib/tools/qbytearraylist/tst_qbytearraylist.cpp @@ -49,6 +49,9 @@ private slots: void operator_plus() const; void operator_plus_data() const; + void indexOf_data() const; + void indexOf() const; + void initializerList() const; }; @@ -259,6 +262,29 @@ void tst_QByteArrayList::operator_plus_data() const << ( QByteArrayList() << "a" << "" << "c" ); } +void tst_QByteArrayList::indexOf_data() const +{ + QTest::addColumn<QByteArrayList>("list"); + QTest::addColumn<QByteArray>("item"); + QTest::addColumn<int>("expectedResult"); + + QTest::newRow("empty") << QByteArrayList() << QByteArray("a") << -1; + QTest::newRow("found_1") << ( QByteArrayList() << "a" ) << QByteArray("a") << 0; + QTest::newRow("not_found_1") << ( QByteArrayList() << "a" ) << QByteArray("b") << -1; + QTest::newRow("found_2") << ( QByteArrayList() << "hello" << "world" ) << QByteArray("world") << 1; + QTest::newRow("returns_first") << ( QByteArrayList() << "hello" << "world" << "hello" << "again" ) << QByteArray("hello") << 0; +} + +void tst_QByteArrayList::indexOf() const +{ + QFETCH(QByteArrayList, list); + QFETCH(QByteArray, item); + QFETCH(int, expectedResult); + + QCOMPARE(list.indexOf(item), expectedResult); + QCOMPARE(list.indexOf(item.constData()), expectedResult); +} + void tst_QByteArrayList::initializerList() const { #ifdef Q_COMPILER_INITIALIZER_LISTS diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp index 62c29229e1..7980f1f8f4 100644 --- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp +++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp @@ -74,6 +74,7 @@ private slots: void testHelpOption_data(); void testHelpOption(); void testQuoteEscaping(); + void testUnknownOption(); }; static char *empty_argv[] = { 0 }; @@ -648,6 +649,27 @@ void tst_QCommandLineParser::testQuoteEscaping() #endif // QT_CONFIG(process) } +void tst_QCommandLineParser::testUnknownOption() +{ +#if !QT_CONFIG(process) + QSKIP("This test requires QProcess support"); +#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) + QSKIP("Deploying executable applications to file system on Android not supported."); +#else + QCoreApplication app(empty_argc, empty_argv); + QProcess process; + process.start("testhelper/qcommandlineparser_test_helper", QStringList() << + QString::number(QCommandLineParser::ParseAsLongOptions) << + "-unknown-option"); + QVERIFY(process.waitForFinished(5000)); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + process.setReadChannel(QProcess::StandardError); + QString output = process.readAll(); + QVERIFY2(output.contains("qcommandlineparser_test_helper"), qPrintable(output)); // separate in case of .exe extension + QVERIFY2(output.contains(": Unknown option 'unknown-option'"), qPrintable(output)); +#endif // QT_CONFIG(process) +} + QTEST_APPLESS_MAIN(tst_QCommandLineParser) #include "tst_qcommandlineparser.moc" diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index b128ccebc5..6ad3357f40 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -37,9 +37,6 @@ #ifdef Q_OS_WIN # include <qt_windows.h> -# if defined(Q_OS_WINRT) -# define tzset() -# endif #endif class tst_QDateTime : public QObject @@ -145,9 +142,7 @@ private slots: void isDaylightTime() const; void daylightTransitions() const; void timeZones() const; -#if defined(Q_OS_UNIX) void systemTimeZoneChange() const; -#endif void invalid() const; @@ -174,7 +169,7 @@ private: void reset(const QByteArray &zone) { qputenv("TZ", zone.constData()); - tzset(); + qTzSet(); } ~TimeZoneRollback() { @@ -182,7 +177,7 @@ private: qunsetenv("TZ"); else qputenv("TZ", prior.constData()); - tzset(); + qTzSet(); } }; }; @@ -3425,33 +3420,10 @@ void tst_QDateTime::timeZones() const QCOMPARE(future.offsetFromUtc(), 28800); } -#if defined(Q_OS_UNIX) -// Currently disabled on Windows as adjusting the timezone -// requires additional privileges that aren't normally -// enabled for a process. This can be achieved by calling -// AdjustTokenPrivileges() and then SetTimeZoneInformation(), -// which will require linking to a different library to access that API. -static void setTimeZone(const QByteArray &tz) -{ - qputenv("TZ", tz); - ::tzset(); - -// following left for future reference, see comment above -// #if defined(Q_OS_WIN32) -// ::_tzset(); -// #endif -} - void tst_QDateTime::systemTimeZoneChange() const { - struct ResetTZ { - QByteArray original; - ResetTZ() : original(qgetenv("TZ")) {} - ~ResetTZ() { setTimeZone(original); } - } scopedReset; - // Set the timezone to Brisbane time - setTimeZone(QByteArray("AEST-10:00")); + TimeZoneRollback useZone(QByteArray("AEST-10:00")); QDateTime localDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime); QDateTime utcDate = QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC); @@ -3464,16 +3436,18 @@ void tst_QDateTime::systemTimeZoneChange() const QVERIFY(tzDate.timeZone().isValid()); // Change to Indian time - setTimeZone(QByteArray("IST-05:30")); + useZone.reset(QByteArray("IST-05:30")); QCOMPARE(localDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime)); +#ifdef Q_OS_WINRT + QEXPECT_FAIL("", "WinRT gets this wrong, QTBUG-71185", Continue); +#endif QVERIFY(localMsecs != localDate.toMSecsSinceEpoch()); QCOMPARE(utcDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC)); QCOMPARE(utcDate.toMSecsSinceEpoch(), utcMsecs); QCOMPARE(tzDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), QTimeZone("Australia/Brisbane"))); QCOMPARE(tzDate.toMSecsSinceEpoch(), tzMsecs); } -#endif void tst_QDateTime::invalid() const { diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 5d344834e6..9bb0c6811d 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -1989,9 +1989,11 @@ static void setWinLocaleInfo(LCTYPE type, const QString &value) # define LOCALE_SSHORTTIME 0x00000079 #endif -class RestoreLocaleHelper { +class RestoreLocaleHelper +{ public: - RestoreLocaleHelper() { + RestoreLocaleHelper() + { m_decimal = getWinLocaleInfo(LOCALE_SDECIMAL); m_thousand = getWinLocaleInfo(LOCALE_STHOUSAND); m_sdate = getWinLocaleInfo(LOCALE_SSHORTDATE); @@ -1999,7 +2001,8 @@ public: m_time = getWinLocaleInfo(LOCALE_SSHORTTIME); } - ~RestoreLocaleHelper() { + ~RestoreLocaleHelper() + { // restore these, or the user will get a surprise setWinLocaleInfo(LOCALE_SDECIMAL, m_decimal); setWinLocaleInfo(LOCALE_STHOUSAND, m_thousand); @@ -2007,12 +2010,10 @@ public: setWinLocaleInfo(LOCALE_SLONGDATE, m_ldate); setWinLocaleInfo(LOCALE_SSHORTTIME, m_time); - // make sure QLocale::system() gets updated - QLocalePrivate::updateSystemPrivate(); + QSystemLocale dummy; // to provoke a refresh of the system locale } QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; - }; void tst_QLocale::windowsDefaultLocale() @@ -2028,8 +2029,7 @@ void tst_QLocale::windowsDefaultLocale() const QString shortTimeFormat = QStringLiteral("h^m^s"); setWinLocaleInfo(LOCALE_SSHORTTIME, shortTimeFormat); - // make sure QLocale::system() gets updated - QLocalePrivate::updateSystemPrivate(); + QSystemLocale dummy; // to provoke a refresh of the system locale QLocale locale = QLocale::system(); // make sure we are seeing the system's format strings @@ -2770,9 +2770,11 @@ void tst_QLocale::textDirection_data() case QLocale::Sabaean: case QLocale::Samaritan: case QLocale::Sindhi: + case QLocale::SouthernKurdish: case QLocale::Syriac: case QLocale::Uighur: case QLocale::Urdu: + case QLocale::WesternBalochi: case QLocale::Yiddish: // false if there is no locale data for language: rightToLeft = (QLocale(QLocale::Language(language)).language() diff --git a/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro b/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro new file mode 100644 index 0000000000..c8e6a8e05a --- /dev/null +++ b/tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro @@ -0,0 +1,6 @@ +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/qoffsetstringarray/tst_qoffsetstringarray.cpp b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp new file mode 100644 index 0000000000..dfa0450b18 --- /dev/null +++ b/tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2018 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: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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** 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$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#include <private/qoffsetstringarray_p.h> + + +class tst_QOffsetStringArray : public QObject +{ + Q_OBJECT + +private slots: + void init(); + void access(); +}; + + +constexpr const auto messages = qOffsetStringArray( + "level - 0", + "level - 1", + "level - 2", + "level - 3", + "level - 4", + "" +); + +constexpr const auto messages257 = qOffsetStringArray( + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "", "", "", "", + "", "", "", "", "", "", "end" +); + +constexpr const auto messagesBigOffsets = qOffsetStringArray( + " 10 20 30 40 50 60 70 80 90", + " 10 20 30 40 50 60 70 80 90", + " 10 20 30 40 50 60 70 80 90", + " 10 20 30 40 50 60 70 80 90" +); + +void tst_QOffsetStringArray::init() +{ + static_assert(messages.sizeString == 51, "message.sizeString"); + static_assert(messages.sizeOffsets == 6, "message.sizeOffsets"); + static_assert(std::is_same<decltype(messages)::Type, quint8>::value, "messages::Type != quint8"); + + static_assert(messages257.sizeOffsets == 257, "messages257.sizeOffsets"); + static_assert(messages257.sizeString == 260, "messages257.sizeString"); + static_assert(std::is_same<decltype(messages257)::Type, quint16>::value, + "messages257::Type != quint16"); + + static_assert(messagesBigOffsets.sizeOffsets == 4, "messagesBigOffsets.sizeOffsets"); + static_assert(messagesBigOffsets.sizeString == 364, "messagesBigOffsets.sizeString"); + static_assert(std::is_same<decltype(messagesBigOffsets)::Type, quint16>::value, + "messagesBigOffsets::Type != quint16"); +} + +void tst_QOffsetStringArray::access() +{ + QCOMPARE(messages[0], "level - 0"); + QCOMPARE(messages[1], "level - 1"); + QCOMPARE(messages[2], "level - 2"); + QCOMPARE(messages[3], "level - 3"); + QCOMPARE(messages[4], "level - 4"); + QCOMPARE(messages[5], ""); + QCOMPARE(messages[6], ""); +} + + +QTEST_APPLESS_MAIN(tst_QOffsetStringArray) +#include "tst_qoffsetstringarray.moc" diff --git a/tests/auto/corelib/tools/qpair/tst_qpair.cpp b/tests/auto/corelib/tools/qpair/tst_qpair.cpp index 1d5f7536c8..dedc353e67 100644 --- a/tests/auto/corelib/tools/qpair/tst_qpair.cpp +++ b/tests/auto/corelib/tools/qpair/tst_qpair.cpp @@ -41,8 +41,8 @@ private Q_SLOTS: void taskQTBUG_48780_pairContainingCArray(); }; -class C { char _[4]; }; -class M { char _[4]; }; +class C { C() {} char _[4]; }; +class M { M() {} char _[4]; }; class P { char _[4]; }; QT_BEGIN_NAMESPACE diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp index a3aec4c299..42bdf62a93 100644 --- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp +++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp @@ -43,7 +43,9 @@ private slots: void removeDuplicates(); void removeDuplicates_data(); void contains(); + void indexOf_data(); void indexOf(); + void lastIndexOf_data(); void lastIndexOf(); void indexOf_regExp(); @@ -141,20 +143,52 @@ void tst_QStringList::lastIndexOf_regExp() } +void tst_QStringList::indexOf_data() +{ + QTest::addColumn<QString>("search"); + QTest::addColumn<int>("from"); + QTest::addColumn<int>("expectedResult"); + + QTest::newRow("harald") << "harald" << 0 << 0; + QTest::newRow("trond") << "trond" << 0 << 1; + QTest::newRow("vohi") << "vohi" << 0 << 2; + QTest::newRow("harald-1") << "harald" << 1 << 3; + + QTest::newRow("hans") << "hans" << 0 << -1; + QTest::newRow("trond-1") << "trond" << 2 << -1; + QTest::newRow("harald-2") << "harald" << -1 << 3; + QTest::newRow("vohi-1") << "vohi" << -3 << 2; +} + void tst_QStringList::indexOf() { QStringList list; list << "harald" << "trond" << "vohi" << "harald"; - QCOMPARE(list.indexOf("harald"), 0); - QCOMPARE(list.indexOf("trond"), 1); - QCOMPARE(list.indexOf("vohi"), 2); - QCOMPARE(list.indexOf("harald", 1), 3); + QFETCH(QString, search); + QFETCH(int, from); + QFETCH(int, expectedResult); - QCOMPARE(list.indexOf("hans"), -1); - QCOMPARE(list.indexOf("trond", 2), -1); - QCOMPARE(list.indexOf("harald", -1), 3); - QCOMPARE(list.indexOf("vohi", -3), 2); + QCOMPARE(list.indexOf(search, from), expectedResult); + QCOMPARE(list.indexOf(QStringView(search), from), expectedResult); + QCOMPARE(list.indexOf(QLatin1String(search.toLatin1()), from), expectedResult); +} + +void tst_QStringList::lastIndexOf_data() +{ + QTest::addColumn<QString>("search"); + QTest::addColumn<int>("from"); + QTest::addColumn<int>("expectedResult"); + + QTest::newRow("harald") << "harald" << -1 << 3; + QTest::newRow("trond") << "trond" << -1 << 1; + QTest::newRow("vohi") << "vohi" << -1 << 2; + QTest::newRow("harald-1") << "harald" << 2 << 0; + + QTest::newRow("hans") << "hans" << -1 << -1; + QTest::newRow("vohi-1") << "vohi" << 1 << -1; + QTest::newRow("vohi-2") << "vohi" << -1 << 2; + QTest::newRow("vohi-3") << "vohi" << -3 << -1; } void tst_QStringList::lastIndexOf() @@ -162,15 +196,13 @@ void tst_QStringList::lastIndexOf() QStringList list; list << "harald" << "trond" << "vohi" << "harald"; - QCOMPARE(list.lastIndexOf("harald"), 3); - QCOMPARE(list.lastIndexOf("trond"), 1); - QCOMPARE(list.lastIndexOf("vohi"), 2); - QCOMPARE(list.lastIndexOf("harald", 2), 0); + QFETCH(QString, search); + QFETCH(int, from); + QFETCH(int, expectedResult); - QCOMPARE(list.lastIndexOf("hans"), -1); - QCOMPARE(list.lastIndexOf("vohi", 1), -1); - QCOMPARE(list.lastIndexOf("vohi", -1), 2); - QCOMPARE(list.lastIndexOf("vohi", -3), -1); + QCOMPARE(list.lastIndexOf(search, from), expectedResult); + QCOMPARE(list.lastIndexOf(QStringView(search), from), expectedResult); + QCOMPARE(list.lastIndexOf(QLatin1String(search.toLatin1()), from), expectedResult); } void tst_QStringList::filter() diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index f28cf21b8b..2a975e67d1 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -35,6 +35,7 @@ SUBDIRS=\ qmap_strictiterators \ qmargins \ qmessageauthenticationcode \ + qoffsetstringarray \ qpair \ qpoint \ qpointf \ |