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/qbytearray/tst_qbytearray.cpp14
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp3
-rw-r--r--tests/auto/corelib/tools/qcollator/qcollator.pro4
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp6
-rw-r--r--tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp17
-rw-r--r--tests/auto/corelib/tools/qdate/tst_qdate.cpp1
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp192
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm11
-rw-r--r--tests/auto/corelib/tools/qelapsedtimer/qelapsedtimer.pro5
-rw-r--r--tests/auto/corelib/tools/qelapsedtimer/tst_qelapsedtimer.cpp139
-rw-r--r--tests/auto/corelib/tools/qfreelist/qfreelist.pro2
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp68
-rw-r--r--tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp3
-rw-r--r--tests/auto/corelib/tools/qlatin1string/qlatin1string.pro4
-rw-r--r--tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp30
-rw-r--r--tests/auto/corelib/tools/qline/tst_qline.cpp77
-rw-r--r--tests/auto/corelib/tools/qlocale/test/test.pro2
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp22
-rw-r--r--tests/auto/corelib/tools/qregexp/tst_qregexp.cpp20
-rw-r--r--tests/auto/corelib/tools/qregularexpression/qregularexpression.pro2
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp26
-rw-r--r--tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp26
-rw-r--r--tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp4
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.cpp4
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp149
-rw-r--r--tests/auto/corelib/tools/qstring/qstring.pro8
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp80
-rw-r--r--tests/auto/corelib/tools/qstringapisymmetry/.gitignore1
-rw-r--r--tests/auto/corelib/tools/qstringapisymmetry/qstringapisymmetry.pro5
-rw-r--r--tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp262
-rw-r--r--tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp14
-rw-r--r--tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp14
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp43
-rw-r--r--tests/auto/corelib/tools/qtime/tst_qtime.cpp3
-rw-r--r--tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp4
-rw-r--r--tests/auto/corelib/tools/qtimezone/qtimezone.pro2
-rw-r--r--tests/auto/corelib/tools/qvector/qvector.pro2
-rw-r--r--tests/auto/corelib/tools/qversionnumber/qversionnumber.pro4
-rw-r--r--tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp13
-rw-r--r--tests/auto/corelib/tools/tools.pro2
40 files changed, 861 insertions, 427 deletions
diff --git a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
index a100de4c41..310c5f6fd3 100644
--- a/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
+++ b/tests/auto/corelib/tools/qbytearray/tst_qbytearray.cpp
@@ -34,9 +34,6 @@
#include <qhash.h>
#include <limits.h>
#include <private/qtools_p.h>
-#if defined(Q_OS_WINCE)
-#include <qcoreapplication.h>
-#endif
class tst_QByteArray : public QObject
{
@@ -246,11 +243,7 @@ void tst_QByteArray::qCompress_data()
{
QTest::addColumn<QByteArray>("ba");
-#ifndef Q_OS_WINCE
const int size1 = 1024*1024;
-#else
- const int size1 = 1024;
-#endif
QByteArray ba1( size1, 0 );
QTest::newRow( "00" ) << QByteArray();
@@ -267,11 +260,6 @@ void tst_QByteArray::qCompress_data()
ba1.fill( 'A' );
QTest::newRow( "03" ) << ba1;
-#if defined(Q_OS_WINCE)
- int tmpArgc = 0;
- char** tmpArgv = 0;
- QCoreApplication app(tmpArgc, tmpArgv);
-#endif
QFile file( QFINDTESTDATA("rfc3252.txt") );
QVERIFY( file.open(QIODevice::ReadOnly) );
QTest::newRow( "04" ) << file.readAll();
@@ -728,7 +716,7 @@ void tst_QByteArray::qvsnprintf()
memset(buf, 42, sizeof(buf));
#ifdef Q_OS_WIN
// VS 2005 uses the Qt implementation of vsnprintf.
-# if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
+# if defined(_MSC_VER)
QCOMPARE(::qsnprintf(buf, 3, "%s", "bubu"), -1);
QCOMPARE(static_cast<const char*>(buf), "bu");
# else
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index e51f5d4694..92585fd471 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -31,9 +31,6 @@
#include <qfile.h>
#include <qstringlist.h>
#include <private/qunicodetables_p.h>
-#if defined(Q_OS_WINCE)
-#include <qcoreapplication.h>
-#endif
class tst_QChar : public QObject
{
diff --git a/tests/auto/corelib/tools/qcollator/qcollator.pro b/tests/auto/corelib/tools/qcollator/qcollator.pro
index ed879ee70e..2f3995a75f 100644
--- a/tests/auto/corelib/tools/qcollator/qcollator.pro
+++ b/tests/auto/corelib/tools/qcollator/qcollator.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qcollator
-QT = core testlib
+QT = core-private testlib
SOURCES = tst_qcollator.cpp
DEFINES += QT_NO_CAST_TO_ASCII
-contains(QT_CONFIG,icu):DEFINES += QT_USE_ICU
+qtConfig(icu): DEFINES += QT_USE_ICU
diff --git a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
index 36bc8621d2..30c7b1bf69 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/testhelper/qcommandlineparser_test_helper.cpp
@@ -71,8 +71,12 @@ int main(int argc, char *argv[])
// A hidden option
QCommandLineOption hiddenOption(QStringList() << QStringLiteral("hidden"));
hiddenOption.setDescription(QStringLiteral("THIS SHOULD NEVER APPEAR"));
- hiddenOption.setHidden(true);
+ hiddenOption.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(hiddenOption);
+ QCommandLineOption hiddenOption2(QStringList() << QStringLiteral("hidden2"));
+ hiddenOption2.setDescription(QStringLiteral("NEITHER SHOULD THIS"));
+ hiddenOption2.setHidden(true);
+ parser.addOption(hiddenOption2);
// This program supports different options depending on the "command" (first argument).
// Call parse() to find out the positional arguments.
diff --git a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
index 9552152136..a54ad3d9c9 100644
--- a/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
+++ b/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
@@ -450,6 +450,13 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes_data()
<< QStringList("abc") << QStringList("val");
QTest::newRow("implicitlylong_with_space") << QCommandLineParser::ParseAsCompactedShortOptions << (QStringList() << "-c" << "val")
<< QStringList("c") << QStringList("val");
+
+ QTest::newRow("forceshort_detached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I" << "45")
+ << QStringList("I") << QStringList("45");
+ QTest::newRow("forceshort_attached") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I46")
+ << QStringList("I") << QStringList("46");
+ QTest::newRow("forceshort_mixed") << QCommandLineParser::ParseAsLongOptions << (QStringList() << "-I45" << "-nn")
+ << (QStringList() << "I" << "nn") << QStringList("45");
}
void tst_QCommandLineParser::testSingleDashWordOptionModes()
@@ -468,6 +475,10 @@ void tst_QCommandLineParser::testSingleDashWordOptionModes()
parser.addOption(QCommandLineOption("b", QStringLiteral("b option.")));
parser.addOption(QCommandLineOption(QStringList() << "c" << "abc", QStringLiteral("c option."), QStringLiteral("value")));
parser.addOption(QCommandLineOption("nn", QStringLiteral("nn option.")));
+ QCommandLineOption forceShort(QStringLiteral("I"), QStringLiteral("always short option"),
+ QStringLiteral("path"), QStringLiteral("default"));
+ forceShort.setFlags(QCommandLineOption::ShortOptionStyle);
+ parser.addOption(forceShort);
QVERIFY(parser.parse(commandLine));
QCOMPARE(parser.optionNames(), expectedOptionNames);
for (int i = 0; i < expectedOptionValues.count(); ++i)
@@ -501,9 +512,6 @@ void tst_QCommandLineParser::testVersionOption()
#ifdef QT_NO_PROCESS
QSKIP("This test requires QProcess support");
#else
-#ifdef Q_OS_WINCE
- QSKIP("Reading and writing to a process is not supported on Qt/CE");
-#endif
#if defined(Q_OS_ANDROID)
QSKIP("Deploying executable applications to file system on Android not supported.");
#endif
@@ -570,9 +578,6 @@ void tst_QCommandLineParser::testHelpOption()
#ifdef QT_NO_PROCESS
QSKIP("This test requires QProcess support");
#else
-#ifdef Q_OS_WINCE
- QSKIP("Reading and writing to a process is not supported on Qt/CE");
-#endif
#if defined(Q_OS_ANDROID)
QSKIP("Deploying executable applications to file system on Android not supported.");
#endif
diff --git a/tests/auto/corelib/tools/qdate/tst_qdate.cpp b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
index f22138b795..0e189ba7aa 100644
--- a/tests/auto/corelib/tools/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/tools/qdate/tst_qdate.cpp
@@ -1145,6 +1145,7 @@ void tst_QDate::toStringDateFormat_data()
QTest::newRow("year < 0") << QDate(-1,1,1) << Qt::ISODate << QString();
QTest::newRow("year > 9999") << QDate(-1,1,1) << Qt::ISODate << QString();
QTest::newRow("RFC2822Date") << QDate(1974,12,1) << Qt::RFC2822Date << QString("01 Dec 1974");
+ QTest::newRow("ISODateWithMs") << QDate(1974,12,1) << Qt::ISODateWithMs << QString("1974-12-01");
}
void tst_QDate::toStringDateFormat()
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index cfec327319..4604e664b0 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -28,10 +28,7 @@
****************************************************************************/
#include <QtTest/QtTest>
-#ifndef Q_OS_WINCE
#include <time.h>
-#endif
-
#include <qdatetime.h>
#include <private/qdatetime_p.h>
@@ -62,8 +59,8 @@ private slots:
void date();
void time();
void timeSpec();
- void toTime_t_data();
- void toTime_t();
+ void toSecsSinceEpoch_data();
+ void toSecsSinceEpoch();
void daylightSavingsTimeChange_data();
void daylightSavingsTimeChange();
void springForward_data();
@@ -73,7 +70,7 @@ private slots:
void setTime();
void setTimeSpec_data();
void setTimeSpec();
- void setTime_t();
+ void setSecsSinceEpoch();
void setMSecsSinceEpoch_data();
void setMSecsSinceEpoch();
void fromMSecsSinceEpoch_data();
@@ -108,10 +105,8 @@ private slots:
void msecsTo();
void operator_eqeq_data();
void operator_eqeq();
-#ifndef Q_OS_WINCE
void operator_insert_extract_data();
void operator_insert_extract();
-#endif
void currentDateTime();
void currentDateTimeUtc();
void currentDateTimeUtc2();
@@ -180,22 +175,22 @@ tst_QDateTime::tst_QDateTime()
differently, so don't probe them here.
*/
const uint day = 24 * 3600; // in seconds
- zoneIsCET = (QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7)).toTime_t() == 0x7fffffff
+ zoneIsCET = (QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7)).toSecsSinceEpoch() == 0x7fffffff
// Entries a year apart robustly differ by multiples of day.
- && QDateTime(QDate(2015, 7, 1), QTime()).toTime_t() == 1435701600
- && QDateTime(QDate(2015, 1, 1), QTime()).toTime_t() == 1420066800
- && QDateTime(QDate(2013, 7, 1), QTime()).toTime_t() == 1372629600
- && QDateTime(QDate(2013, 1, 1), QTime()).toTime_t() == 1356994800
- && QDateTime(QDate(2012, 7, 1), QTime()).toTime_t() == 1341093600
- && QDateTime(QDate(2012, 1, 1), QTime()).toTime_t() == 1325372400
- && QDateTime(QDate(2008, 7, 1), QTime()).toTime_t() == 1214863200
- && QDateTime(QDate(2004, 1, 1), QTime()).toTime_t() == 1072911600
- && QDateTime(QDate(2000, 1, 1), QTime()).toTime_t() == 946681200
- && QDateTime(QDate(1990, 7, 1), QTime()).toTime_t() == 646783200
- && QDateTime(QDate(1990, 1, 1), QTime()).toTime_t() == 631148400
- && QDateTime(QDate(1979, 1, 1), QTime()).toTime_t() == 283993200
- // .toTime_t() returns -1 for everything before this:
- && QDateTime(QDate(1970, 1, 1), QTime(1, 0, 0)).toTime_t() == 0);
+ && QDateTime(QDate(2015, 7, 1), QTime()).toSecsSinceEpoch() == 1435701600
+ && QDateTime(QDate(2015, 1, 1), QTime()).toSecsSinceEpoch() == 1420066800
+ && QDateTime(QDate(2013, 7, 1), QTime()).toSecsSinceEpoch() == 1372629600
+ && QDateTime(QDate(2013, 1, 1), QTime()).toSecsSinceEpoch() == 1356994800
+ && QDateTime(QDate(2012, 7, 1), QTime()).toSecsSinceEpoch() == 1341093600
+ && QDateTime(QDate(2012, 1, 1), QTime()).toSecsSinceEpoch() == 1325372400
+ && QDateTime(QDate(2008, 7, 1), QTime()).toSecsSinceEpoch() == 1214863200
+ && QDateTime(QDate(2004, 1, 1), QTime()).toSecsSinceEpoch() == 1072911600
+ && QDateTime(QDate(2000, 1, 1), QTime()).toSecsSinceEpoch() == 946681200
+ && QDateTime(QDate(1990, 7, 1), QTime()).toSecsSinceEpoch() == 646783200
+ && QDateTime(QDate(1990, 1, 1), QTime()).toSecsSinceEpoch() == 631148400
+ && QDateTime(QDate(1979, 1, 1), QTime()).toSecsSinceEpoch() == 283993200
+ // .toSecsSinceEpoch() returns -1 for everything before this:
+ && QDateTime(QDate(1970, 1, 1), QTime(1, 0, 0)).toSecsSinceEpoch() == 0);
// Use .toMSecsSinceEpoch() if you really need to test anything earlier.
/*
@@ -207,12 +202,12 @@ tst_QDateTime::tst_QDateTime()
*/
const int sampled = 3;
// UTC starts of months in 2004, 2038 and 1970:
- uint jans[sampled] = { 12418 * day, 24837 * day, 0 };
- uint juls[sampled] = { 12600 * day, 25018 * day, 181 * day };
+ qint64 jans[sampled] = { 12418 * day, 24837 * day, 0 };
+ qint64 juls[sampled] = { 12600 * day, 25018 * day, 181 * day };
localTimeType = LocalTimeIsUtc;
for (int i = sampled; i-- > 0; ) {
- QDateTime jan = QDateTime::fromTime_t(jans[i]);
- QDateTime jul = QDateTime::fromTime_t(juls[i]);
+ QDateTime jan = QDateTime::fromSecsSinceEpoch(jans[i]);
+ QDateTime jul = QDateTime::fromSecsSinceEpoch(juls[i]);
if (jan.date().year() < 1970 || jul.date().month() < 7) {
localTimeType = LocalTimeBehindUtc;
break;
@@ -259,9 +254,7 @@ void tst_QDateTime::initTestCase()
void tst_QDateTime::init()
{
-#if defined(Q_OS_WINCE)
- SetUserDefaultLCID(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
-#elif defined(Q_OS_WIN32)
+#if defined(Q_OS_WIN32)
SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
#endif
}
@@ -523,52 +516,52 @@ void tst_QDateTime::setTimeSpec()
QCOMPARE(dateTime.timeSpec(), newTimeSpec);
}
-void tst_QDateTime::setTime_t()
+void tst_QDateTime::setSecsSinceEpoch()
{
QDateTime dt1;
- dt1.setTime_t(0);
+ dt1.setSecsSinceEpoch(0);
QCOMPARE(dt1.toUTC(), QDateTime(QDate(1970, 1, 1), QTime(), Qt::UTC));
QCOMPARE(dt1.timeSpec(), Qt::LocalTime);
dt1.setTimeSpec(Qt::UTC);
- dt1.setTime_t(0);
+ dt1.setSecsSinceEpoch(0);
QCOMPARE(dt1, QDateTime(QDate(1970, 1, 1), QTime(), Qt::UTC));
QCOMPARE(dt1.timeSpec(), Qt::UTC);
- dt1.setTime_t(123456);
+ dt1.setSecsSinceEpoch(123456);
QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), Qt::UTC));
if (zoneIsCET) {
QDateTime dt2;
- dt2.setTime_t(123456);
+ dt2.setSecsSinceEpoch(123456);
QCOMPARE(dt2, QDateTime(QDate(1970, 1, 2), QTime(11, 17, 36), Qt::LocalTime));
}
- dt1.setTime_t((uint)(quint32)-123456);
+ dt1.setSecsSinceEpoch((uint)(quint32)-123456);
QCOMPARE(dt1, QDateTime(QDate(2106, 2, 5), QTime(20, 10, 40), Qt::UTC));
if (zoneIsCET) {
QDateTime dt2;
- dt2.setTime_t((uint)(quint32)-123456);
+ dt2.setSecsSinceEpoch((uint)(quint32)-123456);
QCOMPARE(dt2, QDateTime(QDate(2106, 2, 5), QTime(21, 10, 40), Qt::LocalTime));
}
- dt1.setTime_t(1214567890);
+ dt1.setSecsSinceEpoch(1214567890);
QCOMPARE(dt1, QDateTime(QDate(2008, 6, 27), QTime(11, 58, 10), Qt::UTC));
if (zoneIsCET) {
QDateTime dt2;
- dt2.setTime_t(1214567890);
+ dt2.setSecsSinceEpoch(1214567890);
QCOMPARE(dt2, QDateTime(QDate(2008, 6, 27), QTime(13, 58, 10), Qt::LocalTime));
}
- dt1.setTime_t(0x7FFFFFFF);
+ dt1.setSecsSinceEpoch(0x7FFFFFFF);
QCOMPARE(dt1, QDateTime(QDate(2038, 1, 19), QTime(3, 14, 7), Qt::UTC));
if (zoneIsCET) {
QDateTime dt2;
- dt2.setTime_t(0x7FFFFFFF);
+ dt2.setSecsSinceEpoch(0x7FFFFFFF);
QCOMPARE(dt2, QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7), Qt::LocalTime));
}
dt1 = QDateTime(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::OffsetFromUTC, 60 * 60);
- dt1.setTime_t(123456);
+ dt1.setSecsSinceEpoch(123456);
QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), Qt::UTC));
QCOMPARE(dt1.timeSpec(), Qt::OffsetFromUTC);
QCOMPARE(dt1.offsetFromUtc(), 60 * 60);
@@ -672,7 +665,7 @@ void tst_QDateTime::setMSecsSinceEpoch()
QCOMPARE(dt.toMSecsSinceEpoch(), msecs);
if (quint64(msecs / 1000) < 0xFFFFFFFF) {
- QCOMPARE(qint64(dt.toTime_t()), msecs / 1000);
+ QCOMPARE(qint64(dt.toSecsSinceEpoch()), msecs / 1000);
}
QDateTime reference(QDate(1970, 1, 1), QTime(), Qt::UTC);
@@ -723,9 +716,9 @@ void tst_QDateTime::fromMSecsSinceEpoch()
QCOMPARE(dtOffset.toMSecsSinceEpoch(), msecs);
if (quint64(msecs / 1000) < 0xFFFFFFFF) {
- QCOMPARE(qint64(dtLocal.toTime_t()), msecs / 1000);
- QCOMPARE(qint64(dtUtc.toTime_t()), msecs / 1000);
- QCOMPARE(qint64(dtOffset.toTime_t()), msecs / 1000);
+ QCOMPARE(qint64(dtLocal.toSecsSinceEpoch()), msecs / 1000);
+ QCOMPARE(qint64(dtUtc.toSecsSinceEpoch()), msecs / 1000);
+ QCOMPARE(qint64(dtOffset.toSecsSinceEpoch()), msecs / 1000);
}
QDateTime reference(QDate(1970, 1, 1), QTime(), Qt::UTC);
@@ -739,46 +732,56 @@ void tst_QDateTime::fromMSecsSinceEpoch()
void tst_QDateTime::toString_isoDate_data()
{
QTest::addColumn<QDateTime>("datetime");
+ QTest::addColumn<Qt::DateFormat>("format");
QTest::addColumn<QString>("expected");
QTest::newRow("localtime")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34))
- << QString("1978-11-09T13:28:34");
+ << Qt::ISODate << QString("1978-11-09T13:28:34");
QTest::newRow("UTC")
<< QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34), Qt::UTC)
- << QString("1978-11-09T13:28:34Z");
+ << Qt::ISODate << QString("1978-11-09T13:28:34Z");
QDateTime dt(QDate(1978, 11, 9), QTime(13, 28, 34));
dt.setOffsetFromUtc(19800);
QTest::newRow("positive OffsetFromUTC")
- << dt
+ << dt << Qt::ISODate
<< QString("1978-11-09T13:28:34+05:30");
dt.setUtcOffset(-7200);
QTest::newRow("negative OffsetFromUTC")
- << dt
+ << dt << Qt::ISODate
<< QString("1978-11-09T13:28:34-02:00");
dt.setUtcOffset(-900);
QTest::newRow("negative non-integral OffsetFromUTC")
- << dt
+ << dt << Qt::ISODate
<< QString("1978-11-09T13:28:34-00:15");
QTest::newRow("invalid")
<< QDateTime(QDate(-1, 11, 9), QTime(13, 28, 34), Qt::UTC)
- << QString();
+ << Qt::ISODate << QString();
+ QTest::newRow("without-ms")
+ << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34, 20))
+ << Qt::ISODate << QString("1978-11-09T13:28:34");
+ QTest::newRow("with-ms")
+ << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34, 20))
+ << Qt::ISODateWithMs << QString("1978-11-09T13:28:34.020");
}
void tst_QDateTime::toString_isoDate()
{
QFETCH(QDateTime, datetime);
+ QFETCH(Qt::DateFormat, format);
QFETCH(QString, expected);
QLocale oldLocale;
QLocale::setDefault(QLocale("en_US"));
- QString result = datetime.toString(Qt::ISODate);
+ QString result = datetime.toString(format);
QCOMPARE(result, expected);
- QDateTime resultDatetime = QDateTime::fromString(result, Qt::ISODate);
+ QDateTime resultDatetime = QDateTime::fromString(result, format);
// If expecting invalid result the datetime may still be valid, i.e. year < 0 or > 9999
if (!expected.isEmpty()) {
+ QEXPECT_FAIL("without-ms", "Qt::ISODate truncates milliseconds (QTBUG-56552)", Abort);
+
QCOMPARE(resultDatetime, datetime);
QCOMPARE(resultDatetime.date(), datetime.date());
QCOMPARE(resultDatetime.time(), datetime.time());
@@ -1429,27 +1432,19 @@ void tst_QDateTime::msecsTo()
void tst_QDateTime::currentDateTime()
{
-#if defined(Q_OS_WINCE)
- __time64_t buf1, buf2;
- ::_time64(&buf1);
-#else
time_t buf1, buf2;
::time(&buf1);
-#endif
QDateTime lowerBound;
- lowerBound.setTime_t(buf1);
+ lowerBound.setSecsSinceEpoch(buf1);
QDateTime dt1 = QDateTime::currentDateTime();
QDateTime dt2 = QDateTime::currentDateTime().toLocalTime();
QDateTime dt3 = QDateTime::currentDateTime().toUTC();
-#if defined(Q_OS_WINCE)
- ::_time64(&buf2);
-#else
::time(&buf2);
-#endif
+
QDateTime upperBound;
- upperBound.setTime_t(buf2);
+ upperBound.setSecsSinceEpoch(buf2);
// Note we must add 2 seconds here because time() may return up to
// 1 second difference from the more accurate method used by QDateTime::currentDateTime()
upperBound = upperBound.addSecs(2);
@@ -1460,11 +1455,11 @@ void tst_QDateTime::currentDateTime()
"dt2: %3\n"
"dt3: %4\n"
"upperBound: %5\n")
- .arg(lowerBound.toTime_t())
- .arg(dt1.toTime_t())
- .arg(dt2.toTime_t())
- .arg(dt3.toTime_t())
- .arg(upperBound.toTime_t());
+ .arg(lowerBound.toSecsSinceEpoch())
+ .arg(dt1.toSecsSinceEpoch())
+ .arg(dt2.toSecsSinceEpoch())
+ .arg(dt3.toSecsSinceEpoch())
+ .arg(upperBound.toSecsSinceEpoch());
QVERIFY2(lowerBound < upperBound, qPrintable(details));
@@ -1482,27 +1477,20 @@ void tst_QDateTime::currentDateTime()
void tst_QDateTime::currentDateTimeUtc()
{
-#if defined(Q_OS_WINCE)
- __time64_t buf1, buf2;
- ::_time64(&buf1);
-#else
time_t buf1, buf2;
::time(&buf1);
-#endif
+
QDateTime lowerBound;
- lowerBound.setTime_t(buf1);
+ lowerBound.setSecsSinceEpoch(buf1);
QDateTime dt1 = QDateTime::currentDateTimeUtc();
QDateTime dt2 = QDateTime::currentDateTimeUtc().toLocalTime();
QDateTime dt3 = QDateTime::currentDateTimeUtc().toUTC();
-#if defined(Q_OS_WINCE)
- ::_time64(&buf2);
-#else
::time(&buf2);
-#endif
+
QDateTime upperBound;
- upperBound.setTime_t(buf2);
+ upperBound.setSecsSinceEpoch(buf2);
// Note we must add 2 seconds here because time() may return up to
// 1 second difference from the more accurate method used by QDateTime::currentDateTime()
upperBound = upperBound.addSecs(2);
@@ -1513,11 +1501,11 @@ void tst_QDateTime::currentDateTimeUtc()
"dt2: %3\n"
"dt3: %4\n"
"upperBound: %5\n")
- .arg(lowerBound.toTime_t())
- .arg(dt1.toTime_t())
- .arg(dt2.toTime_t())
- .arg(dt3.toTime_t())
- .arg(upperBound.toTime_t());
+ .arg(lowerBound.toSecsSinceEpoch())
+ .arg(dt1.toSecsSinceEpoch())
+ .arg(dt2.toSecsSinceEpoch())
+ .arg(dt3.toSecsSinceEpoch())
+ .arg(upperBound.toSecsSinceEpoch());
QVERIFY2(lowerBound < upperBound, qPrintable(details));
@@ -1562,14 +1550,14 @@ void tst_QDateTime::currentDateTimeUtc2()
QCOMPARE(local.toUTC(), utc);
QCOMPARE(utc.toLocalTime(), local);
- // and finally, the time_t should equal our number
- QCOMPARE(qint64(utc.toTime_t()), msec / 1000);
- QCOMPARE(qint64(local.toTime_t()), msec / 1000);
+ // and finally, the SecsSinceEpoch should equal our number
+ QCOMPARE(qint64(utc.toSecsSinceEpoch()), msec / 1000);
+ QCOMPARE(qint64(local.toSecsSinceEpoch()), msec / 1000);
QCOMPARE(utc.toMSecsSinceEpoch(), msec);
QCOMPARE(local.toMSecsSinceEpoch(), msec);
}
-void tst_QDateTime::toTime_t_data()
+void tst_QDateTime::toSecsSinceEpoch_data()
{
QTest::addColumn<QString>("dateTimeStr");
QTest::addColumn<bool>("res");
@@ -1585,11 +1573,12 @@ void tst_QDateTime::toTime_t_data()
<< bool( sizeof(uint) > 32 && sizeof(time_t) > 32 );
}
-void tst_QDateTime::toTime_t()
+void tst_QDateTime::toSecsSinceEpoch()
{
QFETCH( QString, dateTimeStr );
QDateTime datetime = dt( dateTimeStr );
+ qint64 asSecsSinceEpoch = datetime.toSecsSinceEpoch();
uint asTime_t = datetime.toTime_t();
QFETCH( bool, res );
if (res) {
@@ -1597,11 +1586,14 @@ void tst_QDateTime::toTime_t()
} else {
QVERIFY( asTime_t == (uint)-1 );
}
+ QCOMPARE(asSecsSinceEpoch, datetime.toMSecsSinceEpoch() / 1000);
if ( asTime_t != (uint) -1 ) {
QDateTime datetime2 = QDateTime::fromTime_t( asTime_t );
QCOMPARE(datetime, datetime2);
}
+ QDateTime datetime2 = QDateTime::fromSecsSinceEpoch(asSecsSinceEpoch);
+ QCOMPARE(datetime, datetime2);
}
void tst_QDateTime::daylightSavingsTimeChange_data()
@@ -1640,7 +1632,7 @@ void tst_QDateTime::daylightSavingsTimeChange()
// First with simple construction
QDateTime dt = QDateTime(outDST, QTime(0, 0, 0), Qt::LocalTime);
- int outDSTsecs = dt.toTime_t();
+ int outDSTsecs = dt.toSecsSinceEpoch();
dt.setDate(inDST);
dt = dt.addSecs(1);
@@ -1662,8 +1654,8 @@ void tst_QDateTime::daylightSavingsTimeChange()
dt = dt.addMonths(-months).addSecs(1);
QCOMPARE(dt, QDateTime(inDST, QTime(0, 0, 5)));
- // now using fromTime_t
- dt = QDateTime::fromTime_t(outDSTsecs);
+ // now using fromSecsSinceEpoch
+ dt = QDateTime::fromSecsSinceEpoch(outDSTsecs);
QCOMPARE(dt, QDateTime(outDST, QTime(0, 0, 0)));
dt.setDate(inDST);
@@ -1717,7 +1709,7 @@ void tst_QDateTime::springForward_data()
QTest::addColumn<int>("adjust"); // minutes ahead of UTC on day stepped from
/*
- Zone tests compare a summer and winter moment's time_t to known values.
+ Zone tests compare a summer and winter moment's SecsSinceEpoch to known values.
This could in principle be flawed (two DST-using zones in the same
hemisphere with the same DST and standard times but different transition
times) but no actual example is known where this is a problem. Please
@@ -1727,8 +1719,8 @@ void tst_QDateTime::springForward_data()
test.
*/
- uint winter = QDateTime(QDate(2015, 1, 1), QTime()).toTime_t();
- uint summer = QDateTime(QDate(2015, 7, 1), QTime()).toTime_t();
+ uint winter = QDateTime(QDate(2015, 1, 1), QTime()).toSecsSinceEpoch();
+ uint summer = QDateTime(QDate(2015, 7, 1), QTime()).toSecsSinceEpoch();
if (winter == 1420066800 && summer == 1435701600) {
QTest::newRow("CET from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60;
@@ -1859,7 +1851,6 @@ void tst_QDateTime::operator_eqeq()
}
}
-#ifndef Q_OS_WINCE
Q_DECLARE_METATYPE(QDataStream::Version)
void tst_QDateTime::operator_insert_extract_data()
@@ -1988,7 +1979,6 @@ void tst_QDateTime::operator_insert_extract()
qputenv("TZ", previousTimeZone.constData());
tzset();
}
-#endif
void tst_QDateTime::toString_strformat()
{
@@ -2442,7 +2432,7 @@ void tst_QDateTime::setOffsetFromUtc()
dt1.setMSecsSinceEpoch(123456789);
QCOMPARE(dt1.timeSpec(), Qt::OffsetFromUTC);
QCOMPARE(dt1.offsetFromUtc(), 60 * 60);
- dt1.setTime_t(123456789);
+ dt1.setSecsSinceEpoch(123456789);
QCOMPARE(dt1.timeSpec(), Qt::OffsetFromUTC);
QCOMPARE(dt1.offsetFromUtc(), 60 * 60);
@@ -3060,7 +3050,7 @@ void tst_QDateTime::timeZones() const
QCOMPARE(dt1.time(), QTime(0, 0, 0));
QCOMPARE(dt1.timeZone(), nzTz);
- QDateTime dt2 = QDateTime::fromTime_t(1338465600, nzTz);
+ QDateTime dt2 = QDateTime::fromSecsSinceEpoch(1338465600, nzTz);
QCOMPARE(dt2.date(), dt1.date());
QCOMPARE(dt2.time(), dt1.time());
QCOMPARE(dt2.timeSpec(), dt1.timeSpec());
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
index fb49b8952e..f73c7b9d5d 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime_mac.mm
@@ -36,8 +36,11 @@
void tst_QDateTime_macTypes()
{
// QDateTime <-> CFDate
- {
- QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+
+ static const int kMsPerSecond = 1000;
+
+ for (int i = 0; i < kMsPerSecond; ++i) {
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(i);
const CFDateRef cfDate = qtDateTime.toCFDate();
QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTime);
CFRelease(cfDate);
@@ -50,9 +53,9 @@ void tst_QDateTime_macTypes()
QCOMPARE(QDateTime::fromCFDate(cfDate), qtDateTimeCopy);
}
// QDateTime <-> NSDate
- {
+ for (int i = 0; i < kMsPerSecond; ++i) {
QMacAutoReleasePool pool;
- QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(0);
+ QDateTime qtDateTime = QDateTime::fromMSecsSinceEpoch(i);
const NSDate *nsDate = qtDateTime.toNSDate();
QCOMPARE(QDateTime::fromNSDate(nsDate), qtDateTime);
}
diff --git a/tests/auto/corelib/tools/qelapsedtimer/qelapsedtimer.pro b/tests/auto/corelib/tools/qelapsedtimer/qelapsedtimer.pro
deleted file mode 100644
index 657a63a5d7..0000000000
--- a/tests/auto/corelib/tools/qelapsedtimer/qelapsedtimer.pro
+++ /dev/null
@@ -1,5 +0,0 @@
-CONFIG += testcase
-TARGET = tst_qelapsedtimer
-QT = core testlib
-SOURCES = tst_qelapsedtimer.cpp
-
diff --git a/tests/auto/corelib/tools/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/corelib/tools/qelapsedtimer/tst_qelapsedtimer.cpp
deleted file mode 100644
index 9db001c37d..0000000000
--- a/tests/auto/corelib/tools/qelapsedtimer/tst_qelapsedtimer.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/****************************************************************************
-**
-** 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: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 <QtCore/QString>
-#include <QtCore/QTime>
-#include <QtCore/QElapsedTimer>
-#include <QtTest/QtTest>
-
-static const int minResolution = 50; // the minimum resolution for the tests
-
-QDebug operator<<(QDebug s, const QElapsedTimer &t)
-{
- s.nospace() << "(" << t.msecsSinceReference() << ")";
- return s.space();
-}
-
-class tst_QElapsedTimer : public QObject
-{
- Q_OBJECT
-
-private Q_SLOTS:
- void statics();
- void validity();
- void basics();
- void elapsed();
-};
-
-void tst_QElapsedTimer::statics()
-{
- qDebug() << "Clock type is" << QElapsedTimer::clockType();
- qDebug() << "Said clock is" << (QElapsedTimer::isMonotonic() ? "monotonic" : "not monotonic");
- QElapsedTimer t;
- t.start();
- qDebug() << "Current time is" << t.msecsSinceReference();
-}
-
-void tst_QElapsedTimer::validity()
-{
- QElapsedTimer t;
-
- QVERIFY(!t.isValid()); // non-POD now, it should always start invalid
-
- t.start();
- QVERIFY(t.isValid());
-
- t.invalidate();
- QVERIFY(!t.isValid());
-}
-
-void tst_QElapsedTimer::basics()
-{
- QElapsedTimer t1;
- t1.start();
-
- QVERIFY(t1.msecsSinceReference() != 0);
-
- QCOMPARE(t1, t1);
- QVERIFY(!(t1 != t1));
- QVERIFY(!(t1 < t1));
- QCOMPARE(t1.msecsTo(t1), qint64(0));
- QCOMPARE(t1.secsTo(t1), qint64(0));
-
- quint64 value1 = t1.msecsSinceReference();
- qDebug() << "value1:" << value1 << "t1:" << t1;
- qint64 nsecs = t1.nsecsElapsed();
- qint64 elapsed = t1.restart();
- QVERIFY(elapsed < minResolution);
- QVERIFY(nsecs / 1000000 < minResolution);
-
- quint64 value2 = t1.msecsSinceReference();
- qDebug() << "value2:" << value2 << "t1:" << t1
- << "elapsed:" << elapsed << "nsecs:" << nsecs;
- // in theory, elapsed == value2 - value1
-
- // However, since QElapsedTimer keeps internally the full resolution,
- // we have here a rounding error due to integer division
- QVERIFY(qAbs(elapsed - qint64(value2 - value1)) <= 1);
-}
-
-void tst_QElapsedTimer::elapsed()
-{
- QElapsedTimer t1;
- t1.start();
-
- QTest::qSleep(4*minResolution);
- QElapsedTimer t2;
- t2.start();
-
- QVERIFY(t1 != t2);
- QVERIFY(!(t1 == t2));
- QVERIFY(t1 < t2);
- QVERIFY(t1.msecsTo(t2) > 0);
-
- QVERIFY(t1.nsecsElapsed() > 0);
- QVERIFY(t1.elapsed() > 0);
- // the number of elapsed nanoseconds and milliseconds should match
- QVERIFY(t1.nsecsElapsed() - t1.elapsed() * 1000000 < 1000000);
- QVERIFY(t1.hasExpired(minResolution));
- QVERIFY(!t1.hasExpired(8*minResolution));
- QVERIFY(!t2.hasExpired(minResolution));
-
- QVERIFY(!t1.hasExpired(-1));
- QVERIFY(!t2.hasExpired(-1));
-
- qint64 elapsed = t1.restart();
- QVERIFY(elapsed > 3*minResolution);
- QVERIFY(elapsed < 5*minResolution);
- qint64 diff = t2.msecsTo(t1);
- QVERIFY(diff < minResolution);
-}
-
-QTEST_MAIN(tst_QElapsedTimer);
-
-#include "tst_qelapsedtimer.moc"
diff --git a/tests/auto/corelib/tools/qfreelist/qfreelist.pro b/tests/auto/corelib/tools/qfreelist/qfreelist.pro
index fb108338bd..4825987bcf 100644
--- a/tests/auto/corelib/tools/qfreelist/qfreelist.pro
+++ b/tests/auto/corelib/tools/qfreelist/qfreelist.pro
@@ -2,4 +2,4 @@ CONFIG += testcase
TARGET = tst_qfreelist
QT = core-private testlib
SOURCES = tst_qfreelist.cpp
-!contains(QT_CONFIG,private_tests): SOURCES += $$QT_SOURCE_TREE/src/corelib/tools/qfreelist.cpp
+!qtConfig(private_tests): SOURCES += $$QT_SOURCE_TREE/src/corelib/tools/qfreelist.cpp
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 06ff09dc6c..0b864e71d4 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -49,6 +49,7 @@ private slots:
void find(); // copied from tst_QMap
void constFind(); // copied from tst_QMap
void contains(); // copied from tst_QMap
+ void qhash();
void take(); // copied from tst_QMap
void operator_eq(); // copied from tst_QMap
void rehash_isnt_quadratic();
@@ -695,6 +696,69 @@ void tst_QHash::contains()
QVERIFY(!map1.contains(43));
}
+namespace {
+class QGlobalQHashSeedResetter
+{
+ int oldSeed;
+public:
+ // not entirely correct (may lost changes made by another thread between the query
+ // of the old and the setting of the new seed), but qSetGlobalQHashSeed doesn't
+ // return the old value, so this is the best we can do:
+ explicit QGlobalQHashSeedResetter(int newSeed)
+ : oldSeed(qGlobalQHashSeed())
+ {
+ qSetGlobalQHashSeed(newSeed);
+ }
+ ~QGlobalQHashSeedResetter()
+ {
+ qSetGlobalQHashSeed(oldSeed);
+ }
+};
+
+template <typename Key, typename T>
+QHash<T, Key> inverted(const QHash<Key, T> &in)
+{
+ QHash<T, Key> result;
+ for (auto it = in.begin(), end = in.end(); it != end; ++it)
+ result[it.value()] = it.key();
+ return result;
+}
+
+template <typename AssociativeContainer>
+void make_test_data(AssociativeContainer &c)
+{
+ c["one"] = "1";
+ c["two"] = "2";
+}
+
+}
+
+void tst_QHash::qhash()
+{
+ const QGlobalQHashSeedResetter seed1(0);
+
+ QHash<QString, QString> hash1;
+ make_test_data(hash1);
+ const QHash<QString, QString> hsah1 = inverted(hash1);
+
+ const QGlobalQHashSeedResetter seed2(1);
+
+ QHash<QString, QString> hash2;
+ make_test_data(hash2);
+ const QHash<QString, QString> hsah2 = inverted(hash2);
+
+ QCOMPARE(hash1, hash2);
+ QCOMPARE(hsah1, hsah2);
+ QCOMPARE(qHash(hash1), qHash(hash2));
+ QCOMPARE(qHash(hsah1), qHash(hsah2));
+
+ // by construction this is almost impossible to cause false collisions:
+ QVERIFY(hash1 != hsah1);
+ QVERIFY(hash2 != hsah2);
+ QVERIFY(qHash(hash1) != qHash(hsah1));
+ QVERIFY(qHash(hash2) != qHash(hsah2));
+}
+
//copied from tst_QMap
void tst_QHash::take()
{
@@ -996,11 +1060,7 @@ 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;
-#if defined(Q_OS_WINCE) // mobiles do not have infinite mem...
- for (int i = 0; i < 50000; ++i)
-#else
for (int i = 0; i < 500000; ++i)
-#endif
testHash.insertMulti(1, 1);
}
}
diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
index 1a70ac5e75..0c890eafbc 100644
--- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
+++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
@@ -29,7 +29,6 @@
#include <QtTest/QtTest>
#include <qhash.h>
-#include <qtypetraits.h>
#include <iterator>
#include <sstream>
@@ -197,7 +196,7 @@ void tst_QHashFunctions::range()
{
// verify that the input iterator category suffices:
std::stringstream sstream;
- Q_STATIC_ASSERT((QtPrivate::is_same<std::input_iterator_tag, std::istream_iterator<int>::iterator_category>::value));
+ Q_STATIC_ASSERT((std::is_same<std::input_iterator_tag, std::istream_iterator<int>::iterator_category>::value));
std::copy(ints, ints + numInts, std::ostream_iterator<int>(sstream, " "));
sstream.seekg(0);
std::istream_iterator<int> it(sstream), end;
diff --git a/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro b/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro
index a996dab23e..61054b40e4 100644
--- a/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro
+++ b/tests/auto/corelib/tools/qlatin1string/qlatin1string.pro
@@ -3,7 +3,7 @@ TARGET = tst_qlatin1string
QT = core testlib
SOURCES = tst_qlatin1string.cpp
DEFINES += QT_NO_CAST_TO_ASCII
-contains(QT_CONFIG,c++11): CONFIG += c++11
-contains(QT_CONFIG,c++14): CONFIG += c++14
+qtConfig(c++11): CONFIG += c++11
+qtConfig(c++14): CONFIG += c++14
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp
index 878b4b52b6..06e2e1cc45 100644
--- a/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp
+++ b/tests/auto/corelib/tools/qlatin1string/tst_qlatin1string.cpp
@@ -44,12 +44,42 @@ class tst_QLatin1String : public QObject
Q_OBJECT
private Q_SLOTS:
+ void at();
+ void midLeftRight();
void nullString();
void emptyString();
void relationalOperators_data();
void relationalOperators();
};
+
+void tst_QLatin1String::at()
+{
+ const QLatin1String l1("Hello World");
+ QCOMPARE(l1.at(0), QLatin1Char('H'));
+ QCOMPARE(l1.at(l1.size() - 1), QLatin1Char('d'));
+ QCOMPARE(l1[0], QLatin1Char('H'));
+ QCOMPARE(l1[l1.size() - 1], QLatin1Char('d'));
+}
+
+void tst_QLatin1String::midLeftRight()
+{
+ const QLatin1String l1("Hello World");
+ QCOMPARE(l1.mid(0), l1);
+ QCOMPARE(l1.mid(0, l1.size()), l1);
+ QCOMPARE(l1.left(l1.size()), l1);
+ QCOMPARE(l1.right(l1.size()), l1);
+
+ QCOMPARE(l1.mid(6), QLatin1String("World"));
+ QCOMPARE(l1.mid(6, 5), QLatin1String("World"));
+ QCOMPARE(l1.right(5), QLatin1String("World"));
+
+ QCOMPARE(l1.mid(6, 1), QLatin1String("W"));
+ QCOMPARE(l1.right(5).left(1), QLatin1String("W"));
+
+ QCOMPARE(l1.left(5), QLatin1String("Hello"));
+}
+
void tst_QLatin1String::nullString()
{
// default ctor
diff --git a/tests/auto/corelib/tools/qline/tst_qline.cpp b/tests/auto/corelib/tools/qline/tst_qline.cpp
index 3aee0ff17d..6e020ac35b 100644
--- a/tests/auto/corelib/tools/qline/tst_qline.cpp
+++ b/tests/auto/corelib/tools/qline/tst_qline.cpp
@@ -44,6 +44,12 @@ private slots:
void testLength();
void testLength_data();
+ void testCenter();
+ void testCenter_data();
+
+ void testCenterF();
+ void testCenterF_data();
+
void testNormalVector();
void testNormalVector_data();
@@ -268,6 +274,77 @@ void tst_QLine::testLength()
QCOMPARE(l.dy(), qreal(vy));
}
+void tst_QLine::testCenter()
+{
+ QFETCH(int, x1);
+ QFETCH(int, y1);
+ QFETCH(int, x2);
+ QFETCH(int, y2);
+ QFETCH(int, centerX);
+ QFETCH(int, centerY);
+
+ const QPoint c = QLine(x1, y1, x2, y2).center();
+ QCOMPARE(centerX, c.x());
+ QCOMPARE(centerY, c.y());
+}
+
+void tst_QLine::testCenter_data()
+{
+ QTest::addColumn<int>("x1");
+ QTest::addColumn<int>("y1");
+ QTest::addColumn<int>("x2");
+ QTest::addColumn<int>("y2");
+ QTest::addColumn<int>("centerX");
+ QTest::addColumn<int>("centerY");
+
+ QTest::newRow("[0, 0]") << 0 << 0 << 0 << 0 << 0 << 0;
+ QTest::newRow("top") << 0 << 0 << 2 << 0 << 1 << 0;
+ QTest::newRow("right") << 0 << 0 << 0 << 2 << 0 << 1;
+ QTest::newRow("bottom") << 0 << 0 << -2 << 0 << -1 << 0;
+ QTest::newRow("left") << 0 << 0 << 0 << -2 << 0 << -1;
+
+ QTest::newRow("precision+") << 0 << 0 << 1 << 1 << 0 << 0;
+ QTest::newRow("precision-") << -1 << -1 << 0 << 0 << 0 << 0;
+
+ const int max = std::numeric_limits<int>::max();
+ const int min = std::numeric_limits<int>::min();
+ QTest::newRow("max") << max << max << max << max << max << max;
+ QTest::newRow("min") << min << min << min << min << min << min;
+ QTest::newRow("minmax") << min << min << max << max << 0 << 0;
+}
+
+void tst_QLine::testCenterF()
+{
+ QFETCH(double, x1);
+ QFETCH(double, y1);
+ QFETCH(double, x2);
+ QFETCH(double, y2);
+ QFETCH(double, centerX);
+ QFETCH(double, centerY);
+
+ const QPointF c = QLineF(x1, y1, x2, y2).center();
+ QCOMPARE(centerX, c.x());
+ QCOMPARE(centerY, c.y());
+}
+
+void tst_QLine::testCenterF_data()
+{
+ QTest::addColumn<double>("x1");
+ QTest::addColumn<double>("y1");
+ QTest::addColumn<double>("x2");
+ QTest::addColumn<double>("y2");
+ QTest::addColumn<double>("centerX");
+ QTest::addColumn<double>("centerY");
+
+ QTest::newRow("[0, 0]") << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0;
+ QTest::newRow("top") << 0.0 << 0.0 << 1.0 << 0.0 << 0.5 << 0.0;
+ QTest::newRow("right") << 0.0 << 0.0 << 0.0 << 1.0 << 0.0 << 0.5;
+ QTest::newRow("bottom") << 0.0 << 0.0 << -1.0 << 0.0 << -0.5 << 0.0;
+ QTest::newRow("left") << 0.0 << 0.0 << 0.0 << -1.0 << 0.0 << -0.5;
+
+ const double max = std::numeric_limits<qreal>::max();
+ QTest::newRow("max") << max << max << max << max << max << max;
+}
void tst_QLine::testNormalVector_data()
{
diff --git a/tests/auto/corelib/tools/qlocale/test/test.pro b/tests/auto/corelib/tools/qlocale/test/test.pro
index d9004d1eb6..595ee258e7 100644
--- a/tests/auto/corelib/tools/qlocale/test/test.pro
+++ b/tests/auto/corelib/tools/qlocale/test/test.pro
@@ -4,7 +4,7 @@ QT = core testlib core-private
embedded: QT += gui
SOURCES = ../tst_qlocale.cpp
-!contains(QT_CONFIG, doubleconversion):!contains(QT_CONFIG, system-doubleconversion) {
+!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) {
DEFINES += QT_NO_DOUBLECONVERSION
}
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index ee706e9f3d..8d9a789507 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -52,15 +52,6 @@
# include <fenv.h>
#endif
-#ifdef Q_OS_WINCE
-#include <windows.h> // needed for GetUserDefaultLCID
-#define _control87 _controlfp
-extern "C" DWORD GetThreadLocale(void) {
- return GetUserDefaultLCID();
-}
-
-#endif
-
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
# include <stdlib.h>
#endif
@@ -85,9 +76,7 @@ private slots:
#endif
void ctor();
-#if !defined(Q_OS_WINCE)
void emptyCtor();
-#endif
void legacyNames();
void unixLocaleName();
void matchingLocales();
@@ -156,8 +145,8 @@ tst_QLocale::tst_QLocale()
qRegisterMetaType<QLocale::FormatType>("QLocale::FormatType");
// Test if in Central European Time zone
- uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t();
- uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t();
+ uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toSecsSinceEpoch();
+ uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toSecsSinceEpoch();
europeanTimeZone = (x1 == 631148400 && x2 == 644191200);
}
@@ -394,10 +383,7 @@ void tst_QLocale::ctor()
#undef TEST_CTOR
}
-#if !defined(Q_OS_WINCE) && !defined(QT_NO_PROCESS)
-// Not when Q_OS_WINCE is defined because the test uses unsupported
-// Windows CE QProcess functionality (std streams, env)
-// Also Qt needs to be compiled without QT_NO_PROCESS
+#if !defined(QT_NO_PROCESS)
static inline bool runSysApp(const QString &binary,
const QStringList &env,
QString *output,
@@ -447,7 +433,6 @@ static inline bool runSysAppTest(const QString &binary,
}
#endif
-#if !defined(Q_OS_WINCE)
void tst_QLocale::emptyCtor()
{
#ifdef QT_NO_PROCESS
@@ -517,7 +502,6 @@ void tst_QLocale::emptyCtor()
#undef TEST_CTOR
#endif
}
-#endif
void tst_QLocale::legacyNames()
{
diff --git a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
index 2f285f3393..a98d37d733 100644
--- a/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
+++ b/tests/auto/corelib/tools/qregexp/tst_qregexp.cpp
@@ -927,11 +927,7 @@ void tst_QRegExp::rainersSlowRegExpCopyBug()
{
// this test should take an extreme amount of time if QRegExp is broken
QRegExp original(email);
-#if defined(Q_OS_WINCE)
- for (int i = 0; i < 100; ++i) {
-#else
for (int i = 0; i < 100000; ++i) {
-#endif
QRegExp copy = original;
(void)copy.exactMatch("~");
QRegExp copy2 = original;
@@ -980,13 +976,9 @@ void Thread::run()
str += "abbbdekcz";
int x;
-#if defined(Q_OS_WINCE)
- for (int j = 0; j < 100; ++j) {
-#else
- for (int j = 0; j < 10000; ++j) {
-#endif
+ for (int j = 0; j < 10000; ++j)
x = rx.indexIn(str);
- }
+
QCOMPARE(x, 3072);
}
@@ -1022,13 +1014,9 @@ void Thread2::run()
str += "abbbdekcz";
int x;
-#if defined(Q_OS_WINCE)
- for (int j = 0; j < 100; ++j) {
-#else
- for (int j = 0; j < 10000; ++j) {
-#endif
+ for (int j = 0; j < 10000; ++j)
x = rx.indexIn(str);
- }
+
QCOMPARE(x, 3072);
}
diff --git a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro
index c030f04a27..e1840808ff 100644
--- a/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro
+++ b/tests/auto/corelib/tools/qregularexpression/qregularexpression.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = defaultoptimize forceoptimize
-contains(QT_CONFIG,private_tests):SUBDIRS += alwaysoptimize
+qtConfig(private_tests): SUBDIRS += alwaysoptimize
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index 5825bdb6d6..2a93250ba5 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -61,6 +61,9 @@ struct Match
QStringList captured;
QHash<QString, QString> namedCaptured;
};
+QT_BEGIN_NAMESPACE
+Q_DECLARE_TYPEINFO(Match, Q_MOVABLE_TYPE);
+QT_END_NAMESPACE
Q_DECLARE_METATYPE(Match)
@@ -85,9 +88,9 @@ bool operator==(const QRegularExpressionMatch &rem, const Match &m)
}
}
- Q_FOREACH (const QString &name, m.namedCaptured.keys()) {
- QString remCaptured = rem.captured(name);
- QString mCaptured = m.namedCaptured.value(name);
+ for (auto it = m.namedCaptured.begin(), end = m.namedCaptured.end(); it != end; ++it) {
+ const QString remCaptured = rem.captured(it.key());
+ const QString mCaptured = it.value();
if (remCaptured != mCaptured
|| remCaptured.isNull() != mCaptured.isNull()
|| remCaptured.isEmpty() != mCaptured.isEmpty()) {
@@ -115,12 +118,11 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem)
}
-bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
+bool operator==(const QRegularExpressionMatchIterator &iterator, const QVector<Match> &expectedMatchList)
{
QRegularExpressionMatchIterator i = iterator;
- foreach (const Match &expectedMatch, expectedMatchList)
- {
+ for (const Match &expectedMatch : expectedMatchList) {
if (!i.hasNext())
return false;
@@ -135,17 +137,17 @@ bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Mat
return true;
}
-bool operator==(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator)
+bool operator==(const QVector<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator)
{
return operator==(iterator, expectedMatchList);
}
-bool operator!=(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
+bool operator!=(const QRegularExpressionMatchIterator &iterator, const QVector<Match> &expectedMatchList)
{
return !operator==(iterator, expectedMatchList);
}
-bool operator!=(const QList<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator)
+bool operator!=(const QVector<Match> &expectedMatchList, const QRegularExpressionMatchIterator &iterator)
{
return !operator==(expectedMatchList, iterator);
}
@@ -1117,9 +1119,9 @@ void tst_QRegularExpression::globalMatch_data()
QTest::addColumn<int>("offset");
QTest::addColumn<QRegularExpression::MatchType>("matchType");
QTest::addColumn<QRegularExpression::MatchOptions>("matchOptions");
- QTest::addColumn<QList<Match> >("matchList");
+ QTest::addColumn<QVector<Match> >("matchList");
- QList<Match> matchList;
+ QVector<Match> matchList;
Match m;
matchList.clear();
@@ -1375,7 +1377,7 @@ void tst_QRegularExpression::globalMatch()
QFETCH(int, offset);
QFETCH(QRegularExpression::MatchType, matchType);
QFETCH(QRegularExpression::MatchOptions, matchOptions);
- QFETCH(QList<Match>, matchList);
+ QFETCH(QVector<Match>, matchList);
testMatch<QRegularExpressionMatchIterator>(regexp,
static_cast<QREGlobalMatchStringPMF>(&QRegularExpression::globalMatch),
diff --git a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
index c212589f59..145ba7ff72 100644
--- a/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
+++ b/tests/auto/corelib/tools/qringbuffer/tst_qringbuffer.cpp
@@ -45,6 +45,7 @@ private slots:
void sizeWhenReserved();
void free();
void reserveAndRead();
+ void reserveAndReadInPacketMode();
void reserveFrontAndRead();
void chop();
void ungetChar();
@@ -58,6 +59,12 @@ void tst_QRingBuffer::constructing()
{
QRingBuffer ringBuffer;
+ const int chunkSize = ringBuffer.chunkSize();
+ ringBuffer.setChunkSize(0);
+ QCOMPARE(ringBuffer.chunkSize(), Q_INT64_C(0));
+ ringBuffer.setChunkSize(chunkSize);
+ QCOMPARE(ringBuffer.chunkSize(), chunkSize);
+
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
QVERIFY(ringBuffer.isEmpty());
QCOMPARE(ringBuffer.nextDataBlockSize(), Q_INT64_C(0));
@@ -237,6 +244,25 @@ void tst_QRingBuffer::reserveAndRead()
QCOMPARE(ringBuffer.size(), Q_INT64_C(0));
}
+void tst_QRingBuffer::reserveAndReadInPacketMode()
+{
+ QRingBuffer ringBuffer(0);
+ // try to allocate 255 buffers
+ for (int i = 1; i < 256; ++i) {
+ char *ringPos = ringBuffer.reserve(i);
+ QVERIFY(ringPos);
+ }
+
+ // count and check the size of stored buffers
+ int buffersCount = 0;
+ while (!ringBuffer.isEmpty()) {
+ QByteArray ba = ringBuffer.read();
+ ++buffersCount;
+ QCOMPARE(ba.size(), buffersCount);
+ }
+ QCOMPARE(buffersCount, 255);
+}
+
void tst_QRingBuffer::reserveFrontAndRead()
{
QRingBuffer ringBuffer;
diff --git a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
index 7fde84af5d..21efaede00 100644
--- a/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
+++ b/tests/auto/corelib/tools/qscopedpointer/tst_qscopedpointer.cpp
@@ -278,12 +278,16 @@ void tst_QScopedPointer::isNull()
{
QScopedPointer<int> p;
QVERIFY(p.isNull());
+ QVERIFY(p == nullptr);
+ QVERIFY(nullptr == p);
}
/* Invoke on a set value. */
{
QScopedPointer<int> p(new int(69));
QVERIFY(!p.isNull());
+ QVERIFY(p != nullptr);
+ QVERIFY(nullptr != p);
}
}
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
index 0cccdb8262..7bebe5e9e0 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.cpp
@@ -342,7 +342,7 @@ namespace QTest {
"\n"
"#ifdef Q_OS_WIN\n"
"#include <windows.h>\n"
- "#if defined(Q_CC_MSVC) && !defined(Q_OS_WINCE)\n"
+ "#if defined(Q_CC_MSVC)\n"
"#include <crtdbg.h>\n"
"#endif\n"
"static void q_test_setup()\n"
@@ -358,7 +358,7 @@ namespace QTest {
"#endif\n"
"int main(int argc, char **argv)\n"
"{\n"
- "#if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) && !defined(Q_OS_WINCE)\n"
+ "#if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR)\n"
" _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, CrtDbgHook);\n"
"#endif\n";
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index b5912badf2..d0a0feb125 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -57,11 +57,13 @@ private slots:
void basics_data();
void basics();
void operators();
+ void nullptrOps();
void swap();
void moveSemantics();
void useOfForwardDeclared();
void memoryManagement();
void dropLastReferenceOfForwardDeclared();
+ void nonVirtualDestructors();
void lock();
void downCast();
void functionCallDownCast();
@@ -362,6 +364,50 @@ void tst_QSharedPointer::operators()
QCOMPARE(qHash(p2), qHash(p2.data()));
}
+void tst_QSharedPointer::nullptrOps()
+{
+ QSharedPointer<char> p1(nullptr);
+ QSharedPointer<char> p2 = nullptr;
+ QSharedPointer<char> null;
+
+ QVERIFY(p1 == null);
+ QVERIFY(p1 == nullptr);
+ QVERIFY(nullptr == p1);
+ QVERIFY(!p1);
+ QVERIFY(!p1.data());
+ QVERIFY(p2 == null);
+ QVERIFY(p2 == nullptr);
+ QVERIFY(nullptr == p2);
+ QVERIFY(!p2);
+ QVERIFY(!p2.data());
+ QVERIFY(p1 == p2);
+
+ QSharedPointer<char> p3 = p1;
+ QVERIFY(p3 == p1);
+ QVERIFY(p3 == null);
+ QVERIFY(p3 == nullptr);
+ QVERIFY(nullptr == p3);
+ QVERIFY(!p3.data());
+
+ p3 = nullptr;
+
+ // check for non-ambiguity
+ QSharedPointer<char> p1_zero(0);
+ QSharedPointer<char> p2_zero = 0;
+
+ p3 = 0;
+
+ QSharedPointer<char> p4(new char);
+ QVERIFY(p4);
+ QVERIFY(p4.data());
+ QVERIFY(p4 != nullptr);
+ QVERIFY(nullptr != p4);
+ QVERIFY(p4 != p1);
+ QVERIFY(p4 != p2);
+ QVERIFY(p4 != null);
+ QVERIFY(p4 != p3);
+}
+
void tst_QSharedPointer::swap()
{
QSharedPointer<int> p1, p2(new int(42)), control = p2;
@@ -578,6 +624,56 @@ void tst_QSharedPointer::dropLastReferenceOfForwardDeclared()
QCOMPARE(forwardDeclaredDestructorRunCount, 1);
}
+// NVD for "non-virtual destructor"
+struct NVDData
+{
+ static int destructorCounter;
+ ~NVDData() { ++destructorCounter; }
+
+ int dummy;
+};
+int NVDData::destructorCounter;
+
+struct NVDDerivedData : NVDData
+{
+ static int destructorCounter;
+ ~NVDDerivedData() { ++destructorCounter; }
+};
+int NVDDerivedData::destructorCounter;
+
+void tst_QSharedPointer::nonVirtualDestructors()
+{
+ NVDData::destructorCounter = NVDDerivedData::destructorCounter = 0;
+ {
+ QSharedPointer<NVDData> ptr(new NVDData);
+ }
+ QCOMPARE(NVDData::destructorCounter, 1);
+ QCOMPARE(NVDDerivedData::destructorCounter, 0);
+
+ NVDData::destructorCounter = NVDDerivedData::destructorCounter = 0;
+ {
+ QSharedPointer<NVDDerivedData> ptr(new NVDDerivedData);
+ }
+ QCOMPARE(NVDData::destructorCounter, 1);
+ QCOMPARE(NVDDerivedData::destructorCounter, 1);
+
+ NVDData::destructorCounter = NVDDerivedData::destructorCounter = 0;
+ {
+ QSharedPointer<NVDData> bptr;
+ QSharedPointer<NVDDerivedData> ptr(new NVDDerivedData);
+ bptr = ptr;
+ }
+ QCOMPARE(NVDData::destructorCounter, 1);
+ QCOMPARE(NVDDerivedData::destructorCounter, 1);
+
+ NVDData::destructorCounter = NVDDerivedData::destructorCounter = 0;
+ {
+ QSharedPointer<NVDData> ptr(new NVDDerivedData);
+ }
+ QCOMPARE(NVDData::destructorCounter, 1);
+ QCOMPARE(NVDDerivedData::destructorCounter, 1);
+}
+
void tst_QSharedPointer::lock()
{
QSharedPointer<int> sp = QSharedPointer<int>::create();
@@ -1310,6 +1406,18 @@ template<typename T> int CustomDeleter<T>::callCount = 0;
void tst_QSharedPointer::customDeleter()
{
{
+ QSharedPointer<Data> ptr(0, &Data::doDelete);
+ QSharedPointer<Data> ptr2(0, &Data::alsoDelete);
+ QSharedPointer<Data> ptr3(0, &Data::virtualDelete);
+ }
+ safetyCheck();
+ {
+ QSharedPointer<Data> ptr(nullptr, &Data::doDelete);
+ QSharedPointer<Data> ptr2(nullptr, &Data::alsoDelete);
+ QSharedPointer<Data> ptr3(nullptr, &Data::virtualDelete);
+ }
+ safetyCheck();
+ {
QSharedPointer<Data> ptr(new Data, &Data::doDelete);
QSharedPointer<Data> ptr2(new Data, &Data::alsoDelete);
QSharedPointer<Data> ptr3(new Data, &Data::virtualDelete);
@@ -1492,6 +1600,33 @@ void tst_QSharedPointer::customDeleter()
QCOMPARE(refcount, 2);
safetyCheck();
+ CustomDeleter<NVDData> nvdeleter;
+ nvdeleter.callCount = 0;
+ {
+ QSharedPointer<NVDData> ptr(new NVDData, nvdeleter);
+ }
+ QCOMPARE(nvdeleter.callCount, 1);
+ safetyCheck();
+
+ CustomDeleter<NVDDerivedData> nvderiveddeleter;
+ nvdeleter.callCount = 0;
+ nvderiveddeleter.callCount = 0;
+ {
+ QSharedPointer<NVDDerivedData> ptr(new NVDDerivedData, nvderiveddeleter);
+ }
+ QCOMPARE(nvdeleter.callCount, 0);
+ QCOMPARE(nvderiveddeleter.callCount, 1);
+ safetyCheck();
+
+ nvdeleter.callCount = 0;
+ nvderiveddeleter.callCount = 0;
+ {
+ QSharedPointer<NVDData> ptr(new NVDDerivedData, nvderiveddeleter);
+ }
+ QCOMPARE(nvdeleter.callCount, 0);
+ QCOMPARE(nvderiveddeleter.callCount, 1);
+ safetyCheck();
+
// a custom deleter with a different pointer parameter
{
QSharedPointer<char> ptr(static_cast<char *>(malloc(1)), free);
@@ -1603,9 +1738,6 @@ void tst_QSharedPointer::creating()
void tst_QSharedPointer::creatingVariadic()
{
-#if !defined(Q_COMPILER_RVALUE_REFS) || !defined(Q_COMPILER_VARIADIC_TEMPLATES)
- QSKIP("This compiler is not in C++11 mode or it doesn't support rvalue refs and variadic templates");
-#else
int i = 42;
{
@@ -1633,12 +1765,10 @@ void tst_QSharedPointer::creatingVariadic()
QCOMPARE(ptr->i, 2);
QCOMPARE(ptr->ptr, (void*)0);
-#ifdef Q_COMPILER_NULLPTR
NoDefaultConstructor2(nullptr, 3); // control check
ptr = QSharedPointer<NoDefaultConstructor2>::create(nullptr, 3);
QCOMPARE(ptr->i, 3);
QCOMPARE(ptr->ptr, (void*)nullptr);
-#endif
}
{
NoDefaultConstructorRef1 x(i); // control check
@@ -1674,7 +1804,6 @@ void tst_QSharedPointer::creatingVariadic()
QCOMPARE(ptr->str, QString("bytearray"));
QCOMPARE(ptr->i, 42);
}
-#endif
}
void tst_QSharedPointer::creatingQObject()
@@ -1771,13 +1900,11 @@ void tst_QSharedPointer::threadStressTest_data()
QTest::newRow("1+1") << 1 << 1;
QTest::newRow("2+10") << 2 << 10;
-#ifndef Q_OS_WINCE
- // Windows CE cannot run this many threads
+
QTest::newRow("5+10") << 5 << 10;
QTest::newRow("5+30") << 5 << 30;
QTest::newRow("100+100") << 100 << 100;
-#endif
}
void tst_QSharedPointer::threadStressTest()
@@ -1811,11 +1938,7 @@ void tst_QSharedPointer::threadStressTest()
base.clear();
-#ifdef Q_OS_WINCE
- srand(QDateTime::currentDateTime().toTime_t());
-#else
srand(time(NULL));
-#endif
// start threads
for (int i = 0; i < allThreads.count(); ++i)
if (allThreads[i]) allThreads[i]->start();
diff --git a/tests/auto/corelib/tools/qstring/qstring.pro b/tests/auto/corelib/tools/qstring/qstring.pro
index 1ff9a4fc9e..ec8a9b5df5 100644
--- a/tests/auto/corelib/tools/qstring/qstring.pro
+++ b/tests/auto/corelib/tools/qstring/qstring.pro
@@ -1,13 +1,13 @@
CONFIG += testcase
TARGET = tst_qstring
-QT = core testlib
+QT = core-private testlib
SOURCES = tst_qstring.cpp
DEFINES += QT_NO_CAST_TO_ASCII
-contains(QT_CONFIG,icu):DEFINES += QT_USE_ICU
-contains(QT_CONFIG,c++11): CONFIG += c++11
+qtConfig(icu): DEFINES += QT_USE_ICU
+qtConfig(c++11): CONFIG += c++11
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
-!contains(QT_CONFIG, doubleconversion):!contains(QT_CONFIG, system-doubleconversion) {
+!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) {
DEFINES += QT_NO_DOUBLECONVERSION
}
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 44b8135410..a0a872710c 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -37,10 +37,6 @@
# undef QT_ASCII_CAST_WARNINGS
#endif
-#if defined(Q_OS_WIN) && defined(Q_OS_WINCE)
-#define Q_OS_WIN_AND_WINCE
-#endif
-
#include <QtTest/QtTest>
#include <qregexp.h>
#include <qregularexpression.h>
@@ -88,11 +84,11 @@ public:
template <typename MemFun>
void apply0(QString &s, MemFun mf) const
- { Q_FOREACH (QChar ch, this->pinned) (s.*mf)(ch); }
+ { for (QChar ch : qAsConst(this->pinned)) (s.*mf)(ch); }
template <typename MemFun, typename A1>
void apply1(QString &s, MemFun mf, A1 a1) const
- { Q_FOREACH (QChar ch, this->pinned) (s.*mf)(a1, ch); }
+ { for (QChar ch : qAsConst(this->pinned)) (s.*mf)(a1, ch); }
};
template <>
@@ -258,6 +254,9 @@ public:
};
} // unnamed namespace
+QT_BEGIN_NAMESPACE
+Q_DECLARE_TYPEINFO(CharStarContainer, Q_PRIMITIVE_TYPE);
+QT_END_NAMESPACE
Q_DECLARE_METATYPE(CharStarContainer)
@@ -531,7 +530,7 @@ private slots:
void integer_conversion();
void tortureSprintfDouble();
void toNum();
-#if !defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
+#if !defined(Q_OS_WIN)
void localeAwareCompare_data();
void localeAwareCompare();
#endif
@@ -649,7 +648,7 @@ QString verifyZeroTermination(const QString &str)
} while (0) \
/**/
-typedef QList<int> IntList;
+typedef QVector<int> IntList;
tst_QString::tst_QString()
{
@@ -1057,10 +1056,6 @@ void tst_QString::acc_01()
QVERIFY(a.isNull());
QVERIFY(*a.toLatin1().constData() == '\0');
{
-#if defined(Q_OS_WINCE)
- int argc = 0;
- QCoreApplication app(argc, 0);
-#endif
QFile f("COMPARE.txt");
f.open(QIODevice::ReadOnly);
QTextStream ts( &f );
@@ -1204,7 +1199,7 @@ void tst_QString::macTypes()
#ifndef Q_OS_MAC
QSKIP("This is a Mac-only test");
#else
- extern void tst_QString_macTypes(); // in qstring_mac.mm
+ extern void tst_QString_macTypes(); // in qcore_foundation.mm
tst_QString_macTypes();
#endif
}
@@ -5082,6 +5077,12 @@ void tst_QString::operator_eqeq_nullstring()
QVERIFY( QString("") == "" );
QVERIFY( "" == QString("") );
+ QVERIFY(QString() == nullptr);
+ QVERIFY(nullptr == QString());
+
+ QVERIFY(QString("") == nullptr);
+ QVERIFY(nullptr == QString(""));
+
QVERIFY( QString().size() == 0 );
QVERIFY( QString("").size() == 0 );
@@ -5095,6 +5096,8 @@ void tst_QString::operator_smaller()
QString null;
QString empty("");
QString foo("foo");
+ const char *nullC = nullptr;
+ const char *emptyC = "";
QVERIFY( !(null < QString()) );
QVERIFY( !(null > QString()) );
@@ -5105,6 +5108,12 @@ void tst_QString::operator_smaller()
QVERIFY( !(null < empty) );
QVERIFY( !(null > empty) );
+ QVERIFY( !(nullC < empty) );
+ QVERIFY( !(nullC > empty) );
+
+ QVERIFY( !(null < emptyC) );
+ QVERIFY( !(null > emptyC) );
+
QVERIFY( null < foo );
QVERIFY( !(null > foo) );
QVERIFY( foo > null );
@@ -5436,15 +5445,11 @@ void tst_QString::tortureSprintfDouble()
#include <locale.h>
-#if !defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
-// On Q_OS_WIN others than Win CE, we cannot set the system or user locale
+#if !defined(Q_OS_WIN)
+// On Q_OS_WIN, we cannot set the system or user locale
void tst_QString::localeAwareCompare_data()
{
-#ifdef Q_OS_WIN_AND_WINCE
- QTest::addColumn<ulong>("locale");
-#else
QTest::addColumn<QString>("locale");
-#endif
QTest::addColumn<QString>("s1");
QTest::addColumn<QString>("s2");
QTest::addColumn<int>("result");
@@ -5454,15 +5459,9 @@ void tst_QString::localeAwareCompare_data()
Latin-1-specific characters (I think). Compare with Swedish
below.
*/
-#ifdef Q_OS_WIN_AND_WINCE // assume c locale to be english
- QTest::newRow("c1") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << 1;
- QTest::newRow("c2") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
- QTest::newRow("c3") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
-#else
QTest::newRow("c1") << QString("C") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << 1;
QTest::newRow("c2") << QString("C") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("c3") << QString("C") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
-#endif
/*
It's hard to test English, because it's treated differently
@@ -5472,15 +5471,9 @@ void tst_QString::localeAwareCompare_data()
comparison of Latin-1 values, although I'm not sure. So I
just test digits to make sure that it's not totally broken.
*/
-#ifdef Q_OS_WIN_AND_WINCE
- QTest::newRow("english1") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("5") << QString("4") << 1;
- QTest::newRow("english2") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("4") << QString("6") << -1;
- QTest::newRow("english3") << MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT) << QString("5") << QString("6") << -1;
-#else
QTest::newRow("english1") << QString("en_US") << QString("5") << QString("4") << 1;
QTest::newRow("english2") << QString("en_US") << QString("4") << QString("6") << -1;
QTest::newRow("english3") << QString("en_US") << QString("5") << QString("6") << -1;
-#endif
/*
In Swedish, a with ring above (E5) comes before a with
diaresis (E4), which comes before o diaresis (F6), which
@@ -5491,11 +5484,6 @@ void tst_QString::localeAwareCompare_data()
QTest::newRow("swedish2") << QString("sv_SE.ISO8859-1") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("swedish3") << QString("sv_SE.ISO8859-1") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("swedish4") << QString("sv_SE.ISO8859-1") << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1;
-#elif defined(Q_OS_WIN_AND_WINCE)
- QTest::newRow("swedish1") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1;
- QTest::newRow("swedish2") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
- QTest::newRow("swedish3") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1;
- QTest::newRow("swedish4") << MAKELCID(MAKELANGID(LANG_SWEDISH, SUBLANG_SWEDISH), SORT_DEFAULT) << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1;
#else
QTest::newRow("swedish1") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1;
QTest::newRow("swedish2") << QString("sv_SE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
@@ -5521,10 +5509,6 @@ void tst_QString::localeAwareCompare_data()
QTest::newRow("german1") << QString("de_DE.ISO8859-1") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1;
QTest::newRow("german2") << QString("de_DE.ISO8859-1") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
QTest::newRow("german3") << QString("de_DE.ISO8859-1") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1;
-#elif defined(Q_OS_WIN_AND_WINCE)
- QTest::newRow("german1") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1;
- QTest::newRow("german2") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
- QTest::newRow("german3") << MAKELCID(MAKELANGID(LANG_GERMAN, SUBLANG_GERMAN), SORT_DEFAULT) << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1;
#else
QTest::newRow("german1") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1;
QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1;
@@ -5534,11 +5518,7 @@ void tst_QString::localeAwareCompare_data()
void tst_QString::localeAwareCompare()
{
-#ifdef Q_OS_WIN_AND_WINCE
- QFETCH(ulong, locale);
-#else
QFETCH(QString, locale);
-#endif
QFETCH(QString, s1);
QFETCH(QString, s2);
QFETCH(int, result);
@@ -5546,11 +5526,7 @@ void tst_QString::localeAwareCompare()
QStringRef r1(&s1, 0, s1.length());
QStringRef r2(&s2, 0, s2.length());
-#ifdef Q_OS_WIN_AND_WINCE
- DWORD oldLcid = GetUserDefaultLCID();
- SetUserDefaultLCID(locale);
- QCOMPARE(locale, GetUserDefaultLCID());
-#elif defined (Q_OS_MAC) || defined(QT_USE_ICU)
+#if defined (Q_OS_DARWIN) || defined(QT_USE_ICU)
QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)");
#else
if (!locale.isEmpty()) {
@@ -5612,14 +5588,10 @@ void tst_QString::localeAwareCompare()
QVERIFY(testres == 0);
}
-#ifdef Q_OS_WIN_AND_WINCE
- SetUserDefaultLCID(oldLcid);
-#else
if (!locale.isEmpty())
setlocale(LC_ALL, "");
-#endif
}
-#endif //!defined(Q_OS_WIN) || defined(Q_OS_WIN_AND_WINCE)
+#endif //!defined(Q_OS_WIN)
void tst_QString::reverseIterators()
{
diff --git a/tests/auto/corelib/tools/qstringapisymmetry/.gitignore b/tests/auto/corelib/tools/qstringapisymmetry/.gitignore
new file mode 100644
index 0000000000..d28de05438
--- /dev/null
+++ b/tests/auto/corelib/tools/qstringapisymmetry/.gitignore
@@ -0,0 +1 @@
+tst_qstringapisymmetry
diff --git a/tests/auto/corelib/tools/qstringapisymmetry/qstringapisymmetry.pro b/tests/auto/corelib/tools/qstringapisymmetry/qstringapisymmetry.pro
new file mode 100644
index 0000000000..bc38b17949
--- /dev/null
+++ b/tests/auto/corelib/tools/qstringapisymmetry/qstringapisymmetry.pro
@@ -0,0 +1,5 @@
+CONFIG += testcase
+TARGET = tst_qstringapisymmetry
+QT = core testlib
+SOURCES = tst_qstringapisymmetry.cpp
+qtConfig(c++14): CONFIG += c++14
diff --git a/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
new file mode 100644
index 0000000000..7305a00d94
--- /dev/null
+++ b/tests/auto/corelib/tools/qstringapisymmetry/tst_qstringapisymmetry.cpp
@@ -0,0 +1,262 @@
+/****************************************************************************
+**
+** Copyright (C) 2015 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
+** 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$
+**
+****************************************************************************/
+
+#undef QT_NO_CAST_FROM_ASCII
+#undef QT_NO_CAST_TO_ASCII
+#undef QT_ASCII_CAST_WARNINGS
+
+#include <QString>
+#include <QChar>
+#include <QStringRef>
+#include <QLatin1String>
+
+#include <QTest>
+
+Q_DECLARE_METATYPE(QLatin1String)
+Q_DECLARE_METATYPE(QStringRef)
+
+template <typename T>
+QString toQString(const T &t) { return QString(t); }
+QString toQString(const QStringRef &ref) { return ref.toString(); }
+
+// FIXME: these are missing at the time of writing, add them, then remove the dummies here:
+#define MAKE_RELOP(op, A1, A2) \
+ static bool operator op (A1 lhs, A2 rhs) \
+ { return toQString(lhs) op toQString(rhs); } \
+ /*end*/
+#define MAKE_ALL(A1, A2) \
+ MAKE_RELOP(==, A1, A2) \
+ MAKE_RELOP(!=, A1, A2) \
+ MAKE_RELOP(<, A1, A2) \
+ MAKE_RELOP(>, A1, A2) \
+ MAKE_RELOP(<=, A1, A2) \
+ MAKE_RELOP(>=, A1, A2) \
+ /*end*/
+
+MAKE_ALL(QByteArray, QChar)
+MAKE_ALL(QByteArray, QLatin1String)
+
+MAKE_ALL(const char*, QChar)
+
+#undef MAKE_ALL
+#undef MAKE_RELOP
+// END FIXME
+
+class tst_QStringApiSymmetry : public QObject
+{
+ Q_OBJECT
+
+ void compare_data(bool hasConceptOfNullAndEmpty=true);
+ template <typename LHS, typename RHS>
+ void compare_impl() const;
+
+private Q_SLOTS:
+ // test all combinations of {QChar, QStringRef, QString, QLatin1String, QByteArray, const char*}
+ void compare_QChar_QChar_data() { compare_data(false); }
+ void compare_QChar_QChar() { compare_impl<QChar, QChar>(); }
+ void compare_QChar_QStringRef_data() { compare_data(false); }
+ void compare_QChar_QStringRef() { compare_impl<QChar, QStringRef>(); }
+ void compare_QChar_QString_data() { compare_data(false); }
+ void compare_QChar_QString() { compare_impl<QChar, QString>(); }
+ void compare_QChar_QLatin1String_data() { compare_data(false); }
+ void compare_QChar_QLatin1String() { compare_impl<QChar, QLatin1String>(); }
+ void compare_QChar_QByteArray_data() { compare_data(false); }
+ void compare_QChar_QByteArray() { compare_impl<QChar, QByteArray>(); }
+ void compare_QChar_const_char_star_data() { compare_data(false); }
+ void compare_QChar_const_char_star() { compare_impl<QChar, const char *>(); }
+
+ void compare_QStringRef_QChar_data() { compare_data(false); }
+ void compare_QStringRef_QChar() { compare_impl<QStringRef, QChar>(); }
+ void compare_QStringRef_QStringRef_data() { compare_data(); }
+ void compare_QStringRef_QStringRef() { compare_impl<QStringRef, QStringRef>(); }
+ void compare_QStringRef_QString_data() { compare_data(); }
+ void compare_QStringRef_QString() { compare_impl<QStringRef, QString>(); }
+ void compare_QStringRef_QLatin1String_data() { compare_data(); }
+ void compare_QStringRef_QLatin1String() { compare_impl<QStringRef, QLatin1String>(); }
+ void compare_QStringRef_QByteArray_data() { compare_data(); }
+ void compare_QStringRef_QByteArray() { compare_impl<QStringRef, QByteArray>(); }
+ void compare_QStringRef_const_char_star_data() { compare_data(); }
+ void compare_QStringRef_const_char_star() { compare_impl<QStringRef, const char *>(); }
+
+ void compare_QString_QChar_data() { compare_data(false); }
+ void compare_QString_QChar() { compare_impl<QString, QChar>(); }
+ void compare_QString_QStringRef_data() { compare_data(); }
+ void compare_QString_QStringRef() { compare_impl<QString, QStringRef>(); }
+ void compare_QString_QString_data() { compare_data(); }
+ void compare_QString_QString() { compare_impl<QString, QString>(); }
+ void compare_QString_QLatin1String_data() { compare_data(); }
+ void compare_QString_QLatin1String() { compare_impl<QString, QLatin1String>(); }
+ void compare_QString_QByteArray_data() { compare_data(); }
+ void compare_QString_QByteArray() { compare_impl<QString, QByteArray>(); }
+ void compare_QString_const_char_star_data() { compare_data(); }
+ void compare_QString_const_char_star() { compare_impl<QString, const char *>(); }
+
+ void compare_QLatin1String_QChar_data() { compare_data(false); }
+ void compare_QLatin1String_QChar() { compare_impl<QLatin1String, QChar>(); }
+ void compare_QLatin1String_QStringRef_data() { compare_data(); }
+ void compare_QLatin1String_QStringRef() { compare_impl<QLatin1String, QStringRef>(); }
+ void compare_QLatin1String_QString_data() { compare_data(); }
+ void compare_QLatin1String_QString() { compare_impl<QLatin1String, QString>(); }
+ void compare_QLatin1String_QLatin1String_data() { compare_data(); }
+ void compare_QLatin1String_QLatin1String() { compare_impl<QLatin1String, QLatin1String>(); }
+ void compare_QLatin1String_QByteArray_data() { compare_data(); }
+ void compare_QLatin1String_QByteArray() { compare_impl<QLatin1String, QByteArray>(); }
+ void compare_QLatin1String_const_char_star_data() { compare_data(); }
+ void compare_QLatin1String_const_char_star() { compare_impl<QLatin1String, const char *>(); }
+
+ void compare_QByteArray_QChar_data() { compare_data(false); }
+ void compare_QByteArray_QChar() { compare_impl<QByteArray, QChar>(); }
+ void compare_QByteArray_QStringRef_data() { compare_data(); }
+ void compare_QByteArray_QStringRef() { compare_impl<QByteArray, QStringRef>(); }
+ void compare_QByteArray_QString_data() { compare_data(); }
+ void compare_QByteArray_QString() { compare_impl<QByteArray, QString>(); }
+ void compare_QByteArray_QLatin1String_data() { compare_data(); }
+ void compare_QByteArray_QLatin1String() { compare_impl<QByteArray, QLatin1String>(); }
+ void compare_QByteArray_QByteArray_data() { compare_data(); }
+ void compare_QByteArray_QByteArray() { compare_impl<QByteArray, QByteArray>(); }
+ void compare_QByteArray_const_char_star_data() { compare_data(); }
+ void compare_QByteArray_const_char_star() { compare_impl<QByteArray, const char *>(); }
+
+ void compare_const_char_star_QChar_data() { compare_data(false); }
+ void compare_const_char_star_QChar() { compare_impl<const char *, QChar>(); }
+ void compare_const_char_star_QStringRef_data() { compare_data(); }
+ void compare_const_char_star_QStringRef() { compare_impl<const char *, QStringRef>(); }
+ void compare_const_char_star_QString_data() { compare_data(); }
+ void compare_const_char_star_QString() { compare_impl<const char *, QString>(); }
+ void compare_const_char_star_QLatin1String_data() { compare_data(false); }
+ void compare_const_char_star_QLatin1String() { compare_impl<const char *, QLatin1String>(); }
+ void compare_const_char_star_QByteArray_data() { compare_data(); }
+ void compare_const_char_star_QByteArray() { compare_impl<const char *, QByteArray>(); }
+ //void compare_const_char_star_const_char_star_data() { compare_data(); }
+ //void compare_const_char_star_const_char_star() { compare_impl<const char *, const char *>(); }
+
+};
+
+void tst_QStringApiSymmetry::compare_data(bool hasConceptOfNullAndEmpty)
+{
+ QTest::addColumn<QStringRef>("lhsUnicode");
+ QTest::addColumn<QLatin1String>("lhsLatin1");
+ QTest::addColumn<QStringRef>("rhsUnicode");
+ QTest::addColumn<QLatin1String>("rhsLatin1");
+ QTest::addColumn<int>("caseSensitiveCompareResult");
+ QTest::addColumn<int>("caseInsensitiveCompareResult");
+
+ if (hasConceptOfNullAndEmpty) {
+ QTest::newRow("null <> null") << QStringRef() << QLatin1String()
+ << QStringRef() << QLatin1String()
+ << 0 << 0;
+ static const QString empty("");
+ QTest::newRow("null <> empty") << QStringRef() << QLatin1String()
+ << QStringRef(&empty) << QLatin1String("")
+ << 0 << 0;
+ }
+
+#define ROW(lhs, rhs) \
+ do { \
+ static const QString pinned[] = { \
+ QString(QLatin1String(lhs)), \
+ QString(QLatin1String(rhs)), \
+ }; \
+ QTest::newRow(qUtf8Printable(QLatin1String("'" lhs "' <> '" rhs "': "))) \
+ << QStringRef(&pinned[0]) << QLatin1String(lhs) \
+ << QStringRef(&pinned[1]) << QLatin1String(rhs) \
+ << qstrcmp(lhs, rhs) << qstricmp(lhs, rhs); \
+ } while (false)
+ ROW("", "0");
+ ROW("0", "");
+ ROW("0", "1");
+ ROW("0", "0");
+ ROW("\xE4", "\xE4"); // ä <> ä
+ ROW("\xE4", "\xC4"); // ä <> Ä
+#undef ROW
+}
+
+template <class Str> Str make(const QStringRef &sf, QLatin1String l1, const QByteArray &u8);
+template <> QChar make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf.isEmpty() ? QChar() : sf.at(0); }
+template <> QStringRef make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf; }
+template <> QString make(const QStringRef &sf, QLatin1String, const QByteArray &) { return sf.toString(); }
+template <> QLatin1String make(const QStringRef &, QLatin1String l1, const QByteArray &) { return l1; }
+template <> QByteArray make(const QStringRef &, QLatin1String, const QByteArray &u8) { return u8; }
+template <> const char * make(const QStringRef &, QLatin1String, const QByteArray &u8) { return u8.data(); }
+
+template <typename> struct is_utf8_encoded : std::false_type {};
+template <> struct is_utf8_encoded<const char*> : std::true_type {};
+template <> struct is_utf8_encoded<QByteArray> : std::true_type {};
+
+template <typename> struct is_latin1_encoded : std::false_type {};
+template <> struct is_latin1_encoded<QLatin1String> : std::true_type {};
+
+template <typename LHS, typename RHS>
+struct has_nothrow_compare {
+ enum { value = is_utf8_encoded<LHS>::value == is_utf8_encoded<RHS>::value };
+};
+
+template <typename LHS, typename RHS>
+void tst_QStringApiSymmetry::compare_impl() const
+{
+ QFETCH(QStringRef, lhsUnicode);
+ QFETCH(QLatin1String, lhsLatin1);
+ QFETCH(QStringRef, rhsUnicode);
+ QFETCH(QLatin1String, rhsLatin1);
+ QFETCH(int, caseSensitiveCompareResult);
+
+ const auto lhsU8 = lhsUnicode.toUtf8();
+ const auto rhsU8 = rhsUnicode.toUtf8();
+
+ const auto lhs = make<LHS>(lhsUnicode, lhsLatin1, lhsU8);
+ const auto rhs = make<RHS>(rhsUnicode, rhsLatin1, rhsU8);
+
+#ifdef Q_COMPILER_NOEXCEPT
+# define QVERIFY_NOEXCEPT(expr) do { \
+ if (has_nothrow_compare<LHS, RHS>::value) {} else \
+ QEXPECT_FAIL("", "Qt is missing a nothrow utf8-utf16 comparator", Continue); \
+ QVERIFY(noexcept(expr)); } while (0)
+#else
+# define QVERIFY_NOEXCEPT(expr)
+#endif
+
+#define CHECK(op) \
+ QVERIFY_NOEXCEPT(lhs op rhs); \
+ do { if (caseSensitiveCompareResult op 0) { \
+ QVERIFY(lhs op rhs); \
+ } else { \
+ QVERIFY(!(lhs op rhs)); \
+ } } while (false)
+
+ CHECK(==);
+ CHECK(!=);
+ CHECK(<);
+ CHECK(>);
+ CHECK(<=);
+ CHECK(>=);
+#undef CHECK
+}
+
+QTEST_APPLESS_MAIN(tst_QStringApiSymmetry)
+
+#include "tst_qstringapisymmetry.moc"
diff --git a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
index 7a361c0693..f6a1432f5c 100644
--- a/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
+++ b/tests/auto/corelib/tools/qstringbuilder/qstringbuilder1/stringbuilder.cpp
@@ -73,8 +73,22 @@ void runScenario()
QCOMPARE(r, r2);
r = stringref Q stringref;
QCOMPARE(r, QString(stringref.toString() + stringref.toString()));
+ r = stringref P stringref;
+ QCOMPARE(r, QString(stringref.toString() + stringref.toString()));
r = string P l1string;
QCOMPARE(r, r2);
+ r = l1string P stringref;
+ QCOMPARE(r, QString(l1string + stringref.toString()));
+ r = stringref P l1string;
+ QCOMPARE(r, QString(stringref.toString() + l1string));
+ r = stringref P string;
+ QCOMPARE(r, QString(stringref.toString() + string));
+ r = string P stringref;
+ QCOMPARE(r, QString(string + stringref.toString()));
+ r = stringref P achar;
+ QCOMPARE(r, QString(stringref.toString() + achar));
+ r = achar P stringref;
+ QCOMPARE(r, QString(achar + stringref.toString()));
r = string Q QStringLiteral(LITERAL);
QCOMPARE(r, r2);
r = QStringLiteral(LITERAL) Q string;
diff --git a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp
index dc3547f9ba..2385aa992c 100644
--- a/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp
+++ b/tests/auto/corelib/tools/qstringlist/tst_qstringlist.cpp
@@ -32,9 +32,6 @@
#include <qstringlist.h>
#include <locale.h>
-#ifdef Q_OS_WINCE
-#include <windows.h> // needed for GetUserDefaultLCID
-#endif
class tst_QStringList : public QObject
{
@@ -205,13 +202,7 @@ void tst_QStringList::sort()
list2 << "BETA" << "Gamma" << "alpha" << "beta" << "epsilon" << "gAmma" << "gamma";
QCOMPARE( list1, list2 );
-#ifdef Q_OS_WINCE
- DWORD oldLcid = GetUserDefaultLCID();
- // Assume c locale to be english
- SetUserDefaultLCID(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
-#else
char *current_locale = setlocale(LC_ALL, "C");
-#endif
QStringList list3, list4;
list3 << "alpha" << "beta" << "BETA" << "gamma" << "Gamma" << "gAmma" << "epsilon";
list3.sort(Qt::CaseInsensitive);
@@ -224,11 +215,7 @@ void tst_QStringList::sort()
QCOMPARE(list4.at(0), QString("alpha"));
QVERIFY(list4.indexOf("epsilon") > 0);
QVERIFY(list4.indexOf("epsilon") < (list4.count() - 1));
-#ifdef Q_OS_WINCE
- SetUserDefaultLCID(oldLcid);
-#else
setlocale(LC_ALL, current_locale);
-#endif
}
void tst_QStringList::replaceInStrings()
@@ -354,6 +341,7 @@ void tst_QStringList::join() const
QFETCH(QString, expectedResult);
QCOMPARE(input.join(separator), expectedResult);
+ QCOMPARE(input.join(QLatin1String(separator.toLatin1())), expectedResult);
}
void tst_QStringList::join_data() const
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 25b97ceaa8..d2374fe0ae 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -81,6 +81,7 @@ private slots:
void integer_conversion();
void trimmed();
void truncate();
+ void chop();
void left();
void right();
void mid();
@@ -1904,6 +1905,48 @@ void tst_QStringRef::truncate()
}
}
+void tst_QStringRef::chop()
+{
+ const QString originalString = QStringLiteral("OriginalString~");
+ const QStringRef cref(&originalString);
+ {
+ const int n = 1;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), QLatin1String("OriginalString"));
+ QCOMPARE(ref.toString(), str);
+ }
+ {
+ const int n = -1;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), originalString);
+ QCOMPARE(ref.toString(), str);
+ }
+ {
+ const int n = 0;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), originalString);
+ QCOMPARE(ref.toString(), str);
+ }
+ {
+ const int n = 1000;
+ QStringRef ref = cref;
+ QString str = originalString;
+ ref.chop(n);
+ str.chop(n);
+ QCOMPARE(ref.toString(), str);
+ QVERIFY(ref.isEmpty());
+ }
+}
+
void tst_QStringRef::left()
{
QString originalString = "OrginalString~";
diff --git a/tests/auto/corelib/tools/qtime/tst_qtime.cpp b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
index 45af10c3ab..059e1e519b 100644
--- a/tests/auto/corelib/tools/qtime/tst_qtime.cpp
+++ b/tests/auto/corelib/tools/qtime/tst_qtime.cpp
@@ -675,6 +675,9 @@ void tst_QTime::toStringDateFormat_data()
QTest::newRow("Text 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::TextDate << QString("10:12:34");
QTest::newRow("ISO 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODate << QString("10:12:34");
QTest::newRow("RFC2822Date") << QTime(10, 12, 34, 999) << Qt::RFC2822Date << QString("10:12:34");
+ QTest::newRow("ISOWithMs 10:12:34.000") << QTime(10, 12, 34, 0) << Qt::ISODateWithMs << QString("10:12:34.000");
+ QTest::newRow("ISOWithMs 10:12:34.020") << QTime(10, 12, 34, 20) << Qt::ISODateWithMs << QString("10:12:34.020");
+ QTest::newRow("ISOWithMs 10:12:34.999") << QTime(10, 12, 34, 999) << Qt::ISODateWithMs << QString("10:12:34.999");
}
void tst_QTime::toStringDateFormat()
diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
index cf43e391b5..383f357206 100644
--- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
+++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
@@ -68,11 +68,7 @@ protected:
void tst_QTimeLine::range()
{
-#ifdef Q_OS_WINCE //On WinCE timer resolution is bad - using longer times instead
- QTimeLine timeLine(2000);
-#else
QTimeLine timeLine(200);
-#endif
QCOMPARE(timeLine.startFrame(), 0);
QCOMPARE(timeLine.endFrame(), 0);
timeLine.setFrameRange(0, 1);
diff --git a/tests/auto/corelib/tools/qtimezone/qtimezone.pro b/tests/auto/corelib/tools/qtimezone/qtimezone.pro
index 4459ed6020..afc4c59dfe 100644
--- a/tests/auto/corelib/tools/qtimezone/qtimezone.pro
+++ b/tests/auto/corelib/tools/qtimezone/qtimezone.pro
@@ -2,6 +2,6 @@ CONFIG += testcase
TARGET = tst_qtimezone
QT = core-private testlib
SOURCES = tst_qtimezone.cpp
-contains(QT_CONFIG,icu) {
+qtConfig(icu) {
DEFINES += QT_USE_ICU
}
diff --git a/tests/auto/corelib/tools/qvector/qvector.pro b/tests/auto/corelib/tools/qvector/qvector.pro
index d49516923f..b9a4ae747b 100644
--- a/tests/auto/corelib/tools/qvector/qvector.pro
+++ b/tests/auto/corelib/tools/qvector/qvector.pro
@@ -1,5 +1,5 @@
CONFIG += testcase
-contains(QT_CONFIG, c++11):CONFIG += c++11
+qtConfig(c++11): CONFIG += c++11
TARGET = tst_qvector
QT = core testlib
SOURCES = $$PWD/tst_qvector.cpp
diff --git a/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro b/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
index 834fc85a29..e2ae91cb64 100644
--- a/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
+++ b/tests/auto/corelib/tools/qversionnumber/qversionnumber.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
-contains(QT_CONFIG, c++11):CONFIG += c++11
-contains(QT_CONFIG, c++14):CONFIG += c++14
+qtConfig(c++11): CONFIG += c++11
+qtConfig(c++14): CONFIG += c++14
TARGET = tst_qversionnumber
QT = core testlib
SOURCES = tst_qversionnumber.cpp
diff --git a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
index 34d9256244..c37a15089a 100644
--- a/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
+++ b/tests/auto/corelib/tools/qversionnumber/tst_qversionnumber.cpp
@@ -29,6 +29,7 @@
#include <QtTest/QtTest>
#include <QtCore/qversionnumber.h>
+#include <QtCore/qlibraryinfo.h>
class tst_QVersionNumber : public QObject
{
@@ -79,6 +80,7 @@ private slots:
void serialize_data();
void serialize();
void moveSemantics();
+ void qtVersion();
};
void tst_QVersionNumber::singleInstanceData()
@@ -636,6 +638,17 @@ void tst_QVersionNumber::moveSemantics()
#endif
}
+void tst_QVersionNumber::qtVersion()
+{
+ QVersionNumber v = QLibraryInfo::version();
+ QVERIFY(!v.isNull());
+ QCOMPARE(v.majorVersion(), QT_VERSION_MAJOR);
+ // we can't compare the minor and micro version:
+ // the library may change without the test being recompiled
+
+ QCOMPARE(v.toString(), QString(qVersion()));
+}
+
QTEST_APPLESS_MAIN(tst_QVersionNumber)
#include "tst_qversionnumber.moc"
diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro
index f9e1c454e7..e45771a704 100644
--- a/tests/auto/corelib/tools/tools.pro
+++ b/tests/auto/corelib/tools/tools.pro
@@ -18,7 +18,6 @@ SUBDIRS=\
qdate \
qdatetime \
qeasingcurve \
- qelapsedtimer \
qexplicitlyshareddatapointer \
qfreelist \
qhash \
@@ -51,6 +50,7 @@ SUBDIRS=\
qstl \
qstring \
qstring_no_cast_from_bytearray \
+ qstringapisymmetry \
qstringbuilder \
qstringiterator \
qstringlist \