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/qbytearraylist/tst_qbytearraylist.cpp26
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp40
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp18
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/qoffsetstringarray.pro6
-rw-r--r--tests/auto/corelib/tools/qoffsetstringarray/tst_qoffsetstringarray.cpp121
-rw-r--r--tests/auto/corelib/tools/tools.pro1
6 files changed, 171 insertions, 41 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/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index 943805e228..56792f38fb 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();
}
};
};
@@ -3412,33 +3407,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);
@@ -3451,16 +3423,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 261689d401..ff36beadcb 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -1869,9 +1869,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);
@@ -1879,7 +1881,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);
@@ -1887,12 +1890,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()
@@ -1908,8 +1909,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
@@ -2650,9 +2650,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/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 \