diff options
Diffstat (limited to 'tests/auto/corelib')
121 files changed, 3905 insertions, 1624 deletions
diff --git a/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp b/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp index 320e0095d3..a8d64f1cd9 100644 --- a/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp +++ b/tests/auto/corelib/animation/qparallelanimationgroup/tst_qparallelanimationgroup.cpp @@ -62,8 +62,8 @@ private slots: void tst_QParallelAnimationGroup::initTestCase() { qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); -#if defined(Q_OS_MAC) || defined(Q_OS_WINCE) - // give the mac/wince app start event queue time to clear +#if defined(Q_OS_DARWIN) + // give the Darwin app start event queue time to clear QTest::qWait(1000); #endif } diff --git a/tests/auto/corelib/codecs/qtextcodec/qtextcodec.pro b/tests/auto/corelib/codecs/qtextcodec/qtextcodec.pro index 9f2e4f9c92..302d887fc7 100644 --- a/tests/auto/corelib/codecs/qtextcodec/qtextcodec.pro +++ b/tests/auto/corelib/codecs/qtextcodec/qtextcodec.pro @@ -1,4 +1,2 @@ TEMPLATE = subdirs -SUBDIRS = test - -!wince: SUBDIRS += echo +SUBDIRS = test echo diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index 554f0dc68d..bdd862e316 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -332,7 +332,8 @@ void tst_QTextCodec::codecForLocale() // find a codec that is not the codecForLocale() QTextCodec *codec2 = 0; - foreach (int mib, QTextCodec::availableMibs()) { + const auto availableMibs = QTextCodec::availableMibs(); + for (int mib : availableMibs ) { if (mib != codec->mibEnum()) { codec2 = QTextCodec::codecForMib(mib); if (codec2) @@ -2148,7 +2149,7 @@ public: void tst_QTextCodec::threadSafety() { QList<QByteArray> codecList = QTextCodec::availableCodecs(); - QList<int> mibList = QTextCodec::availableMibs(); + const QVector<int> mibList = QTextCodec::availableMibs().toVector(); QThreadPool::globalInstance()->setMaxThreadCount(12); QVector<QByteArray> res; @@ -2167,7 +2168,7 @@ void tst_QTextCodec::threadSafety() QThreadPool::globalInstance()->waitForDone(); QCOMPARE(res.toList(), codecList); - QCOMPARE(res2.toList(), mibList); + QCOMPARE(res2, mibList); } void tst_QTextCodec::invalidNames() @@ -2189,10 +2190,9 @@ void tst_QTextCodec::invalidNames() void tst_QTextCodec::checkAliases_data() { QTest::addColumn<QByteArray>("codecName"); - QList<QByteArray> codecList = QTextCodec::availableCodecs(); - foreach (const QByteArray &a, codecList) { + const QList<QByteArray> codecList = QTextCodec::availableCodecs(); + for (const QByteArray &a : codecList) QTest::newRow( a.constData() ) << a; - } } void tst_QTextCodec::checkAliases() @@ -2203,7 +2203,8 @@ void tst_QTextCodec::checkAliases() QCOMPARE(QTextCodec::codecForName(codecName), c); QCOMPARE(QTextCodec::codecForName(c->name()), c); - foreach(const QByteArray &a, c->aliases()) { + const auto aliases = c->aliases(); + for (const QByteArray &a : aliases) { QCOMPARE(QTextCodec::codecForName(a), c); } } diff --git a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp index 16265c6187..5666726a8c 100644 --- a/tests/auto/corelib/codecs/utf8/tst_utf8.cpp +++ b/tests/auto/corelib/codecs/utf8/tst_utf8.cpp @@ -29,7 +29,7 @@ #include <QtTest/QtTest> #include <qtextcodec.h> -#include <qsharedpointer.h> +#include <QScopedPointer> static const char utf8bom[] = "\xEF\xBB\xBF"; @@ -180,7 +180,7 @@ void tst_Utf8::charByChar() { // from utf16 to utf8 char by char: - QSharedPointer<QTextEncoder> encoder = QSharedPointer<QTextEncoder>(codec->makeEncoder()); + const QScopedPointer<QTextEncoder> encoder(codec->makeEncoder()); QByteArray encoded; for (int i = 0; i < utf16.length(); ++i) { @@ -194,7 +194,7 @@ void tst_Utf8::charByChar() } { // from utf8 to utf16 char by char: - QSharedPointer<QTextDecoder> decoder = QSharedPointer<QTextDecoder>(codec->makeDecoder()); + const QScopedPointer<QTextDecoder> decoder(codec->makeDecoder()); QString decoded; for (int i = 0; i < utf8.length(); ++i) { @@ -219,7 +219,7 @@ void tst_Utf8::invalidUtf8() QFETCH(QByteArray, utf8); QFETCH_GLOBAL(bool, useLocale); - QSharedPointer<QTextDecoder> decoder = QSharedPointer<QTextDecoder>(codec->makeDecoder()); + const QScopedPointer<QTextDecoder> decoder(codec->makeDecoder()); decoder->toUnicode(utf8); // Only enforce correctness on our UTF-8 decoder @@ -280,7 +280,7 @@ void tst_Utf8::nonCharacters() QFETCH(QString, utf16); QFETCH_GLOBAL(bool, useLocale); - QSharedPointer<QTextDecoder> decoder = QSharedPointer<QTextDecoder>(codec->makeDecoder()); + const QScopedPointer<QTextDecoder> decoder(codec->makeDecoder()); decoder->toUnicode(utf8); // Only enforce correctness on our UTF-8 decoder @@ -289,7 +289,7 @@ void tst_Utf8::nonCharacters() else if (decoder->hasFailure()) qWarning("System codec reports failure when it shouldn't. Should report bug upstream."); - QSharedPointer<QTextEncoder> encoder(codec->makeEncoder()); + const QScopedPointer<QTextEncoder> encoder(codec->makeEncoder()); encoder->fromUnicode(utf16); if (!useLocale) QVERIFY(!encoder->hasFailure()); diff --git a/tests/auto/corelib/corelib.pro b/tests/auto/corelib/corelib.pro index 4d88b04828..169579bd6b 100644 --- a/tests/auto/corelib/corelib.pro +++ b/tests/auto/corelib/corelib.pro @@ -3,7 +3,7 @@ TEMPLATE=subdirs SUBDIRS = \ kernel -!ios: SUBDIRS += \ +!uikit: SUBDIRS += \ animation \ codecs \ global \ diff --git a/tests/auto/corelib/global/qflags/qflags.pro b/tests/auto/corelib/global/qflags/qflags.pro index 29dfb0684c..c3c11fa81b 100644 --- a/tests/auto/corelib/global/qflags/qflags.pro +++ b/tests/auto/corelib/global/qflags/qflags.pro @@ -2,5 +2,5 @@ CONFIG += testcase TARGET = tst_qflags QT = core testlib SOURCES = tst_qflags.cpp -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 diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 10902b6f55..634d9a2df3 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -134,11 +134,11 @@ void tst_QFlags::signedness() // underlying type is implementation-defined, we need to allow for // a different signedness, so we only check that the relative // signedness of the types matches: - Q_STATIC_ASSERT((QtPrivate::is_unsigned<Qt::MouseButton>::value == - QtPrivate::is_unsigned<Qt::MouseButtons::Int>::value)); + Q_STATIC_ASSERT((QtPrivate::QIsUnsignedEnum<Qt::MouseButton>::value == + QtPrivate::QIsUnsignedEnum<Qt::MouseButtons::Int>::value)); - Q_STATIC_ASSERT((QtPrivate::is_signed<Qt::AlignmentFlag>::value == - QtPrivate::is_signed<Qt::Alignment::Int>::value)); + Q_STATIC_ASSERT((QtPrivate::QIsSignedEnum<Qt::AlignmentFlag>::value == + QtPrivate::QIsSignedEnum<Qt::Alignment::Int>::value)); } #if defined(Q_COMPILER_CLASS_ENUM) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index bb4d1f4bf2..bb6ec1c8e7 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -28,7 +28,6 @@ #include <QtTest/QtTest> -#include <QtCore/qtypetraits.h> #include <QPair> #include <QTextCodec> @@ -49,7 +48,6 @@ private slots: void qConstructorFunction(); void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); - void isEnum(); void qAlignOf(); void integerForSize(); void qprintable(); @@ -81,7 +79,7 @@ void tst_QGlobal::qIsNull() void tst_QGlobal::for_each() { - QList<int> list; + QVector<int> list; list << 0 << 1 << 2 << 3 << 4 << 5; int counter = 0; @@ -100,7 +98,7 @@ void tst_QGlobal::for_each() // check whether we can pass a constructor as container argument counter = 0; - foreach (int i, QList<int>(list)) { + foreach (int i, QVector<int>(list)) { QCOMPARE(i, counter++); } QCOMPARE(counter, list.count()); @@ -366,100 +364,6 @@ public: enum AnEnum {}; }; -#if defined (Q_COMPILER_CLASS_ENUM) -enum class isEnum_G : qint64 {}; -#endif - -void tst_QGlobal::isEnum() -{ -#if defined (Q_CC_MSVC) -#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true) -#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false) -#else -#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true && QtPrivate::is_enum<x>::value == true) -#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false && QtPrivate::is_enum<x>::value == false) -#endif - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Byte)); - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Short)); - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Int)); - - QVERIFY(IS_ENUM_TRUE(isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(const isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_F::AnEnum)); - - QVERIFY(IS_ENUM_FALSE(void)); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte &)); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[1])); - QVERIFY(IS_ENUM_FALSE(const isEnum_B_Byte[1])); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[])); - QVERIFY(IS_ENUM_FALSE(int)); - QVERIFY(IS_ENUM_FALSE(float)); - QVERIFY(IS_ENUM_FALSE(isEnum_A)); - QVERIFY(IS_ENUM_FALSE(isEnum_A *)); - QVERIFY(IS_ENUM_FALSE(const isEnum_A)); - QVERIFY(IS_ENUM_FALSE(isEnum_C)); - QVERIFY(IS_ENUM_FALSE(isEnum_D)); - QVERIFY(IS_ENUM_FALSE(isEnum_E)); - QVERIFY(IS_ENUM_FALSE(void())); - QVERIFY(IS_ENUM_FALSE(void(*)())); - QVERIFY(IS_ENUM_FALSE(int isEnum_A::*)); - QVERIFY(IS_ENUM_FALSE(void (isEnum_A::*)())); - - QVERIFY(IS_ENUM_FALSE(size_t)); - QVERIFY(IS_ENUM_FALSE(bool)); - QVERIFY(IS_ENUM_FALSE(wchar_t)); - - QVERIFY(IS_ENUM_FALSE(char)); - QVERIFY(IS_ENUM_FALSE(unsigned char)); - QVERIFY(IS_ENUM_FALSE(short)); - QVERIFY(IS_ENUM_FALSE(unsigned short)); - QVERIFY(IS_ENUM_FALSE(int)); - QVERIFY(IS_ENUM_FALSE(unsigned int)); - QVERIFY(IS_ENUM_FALSE(long)); - QVERIFY(IS_ENUM_FALSE(unsigned long)); - - QVERIFY(IS_ENUM_FALSE(qint8)); - QVERIFY(IS_ENUM_FALSE(quint8)); - QVERIFY(IS_ENUM_FALSE(qint16)); - QVERIFY(IS_ENUM_FALSE(quint16)); - QVERIFY(IS_ENUM_FALSE(qint32)); - QVERIFY(IS_ENUM_FALSE(quint32)); - QVERIFY(IS_ENUM_FALSE(qint64)); - QVERIFY(IS_ENUM_FALSE(quint64)); - - QVERIFY(IS_ENUM_FALSE(void *)); - QVERIFY(IS_ENUM_FALSE(int *)); - -#if defined (Q_COMPILER_UNICODE_STRINGS) - QVERIFY(IS_ENUM_FALSE(char16_t)); - QVERIFY(IS_ENUM_FALSE(char32_t)); -#endif - -#if defined (Q_COMPILER_CLASS_ENUM) - // Strongly type class enums are not handled by the - // fallback type traits implementation. Any compiler - // supported by Qt that supports C++0x class enums - // should also support the __is_enum intrinsic. - QVERIFY(Q_IS_ENUM(isEnum_G)); -#endif - -#undef IS_ENUM_TRUE -#undef IS_ENUM_FALSE -} - struct Empty {}; template <class T> struct AlignmentInStruct { T dummy; }; @@ -589,7 +493,7 @@ Q_DECLARE_METATYPE(stringpair) void tst_QGlobal::qprintable() { - QFETCH(QList<stringpair>, localestrings); + QFETCH(QVector<stringpair>, localestrings); QFETCH(int, utf8index); QVERIFY(utf8index >= 0 && utf8index < localestrings.count()); @@ -600,21 +504,21 @@ void tst_QGlobal::qprintable() QString string = QString::fromUtf8(utf8string); - foreach (const stringpair &pair, localestrings) { + for (const stringpair &pair : qAsConst(localestrings)) { QTextCodec *codec = QTextCodec::codecForName(pair.first); if (!codec) continue; QTextCodec::setCodecForLocale(codec); // test qPrintable() QVERIFY(qstrcmp(qPrintable(string), pair.second) == 0); - foreach (const stringpair &pair2, localestrings) { + for (const stringpair &pair2 : qAsConst(localestrings)) { if (pair2.second == pair.second) continue; QVERIFY(qstrcmp(qPrintable(string), pair2.second) != 0); } // test qUtf8Printable() QVERIFY(qstrcmp(qUtf8Printable(string), utf8string) == 0); - foreach (const stringpair &pair2, localestrings) { + for (const stringpair &pair2 : qAsConst(localestrings)) { if (qstrcmp(pair2.second, utf8string) == 0) continue; QVERIFY(qstrcmp(qUtf8Printable(string), pair2.second) != 0); @@ -626,7 +530,7 @@ void tst_QGlobal::qprintable() void tst_QGlobal::qprintable_data() { - QTest::addColumn<QList<stringpair> >("localestrings"); + QTest::addColumn<QVector<stringpair> >("localestrings"); QTest::addColumn<int>("utf8index"); // index of utf8 string // Unicode: HIRAGANA LETTER A, I, U, E, O (U+3442, U+3444, U+3446, U+3448, U+344a) @@ -634,7 +538,7 @@ void tst_QGlobal::qprintable_data() static const char *const eucjpstring = "\xa4\xa2\xa4\xa4\xa4\xa6\xa4\xa8\xa4\xaa"; static const char *const sjisstring = "\x82\xa0\x82\xa2\x82\xa4\x82\xa6\x82\xa8"; - QList<stringpair> japanesestrings; + QVector<stringpair> japanesestrings; japanesestrings << stringpair("UTF-8", utf8string) << stringpair("EUC-JP", eucjpstring) << stringpair("Shift_JIS", sjisstring); diff --git a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp index f0685d64c5..5fa7566e86 100644 --- a/tests/auto/corelib/global/qhooks/tst_qhooks.cpp +++ b/tests/auto/corelib/global/qhooks/tst_qhooks.cpp @@ -35,10 +35,18 @@ class tst_QHooks: public QObject Q_OBJECT private slots: + void cleanup(); void testVersion(); void testAddRemoveObject(); + void testChaining(); }; +void tst_QHooks::cleanup() +{ + qtHookData[QHooks::AddQObject] = 0; + qtHookData[QHooks::RemoveQObject] = 0; +} + void tst_QHooks::testVersion() { QVERIFY(qtHookData[QHooks::HookDataVersion] >= 3); @@ -73,5 +81,67 @@ void tst_QHooks::testAddRemoveObject() QCOMPARE(objectCount, 0); } +static QVector<QString> hookOrder; + +static QHooks::AddQObjectCallback existingAddHook = 0; +static QHooks::RemoveQObjectCallback existingRemoveHook = 0; + +static void firstAddHook(QObject *) +{ + hookOrder.append(QLatin1String("firstAddHook")); +} + +static void firstRemoveHook(QObject *) +{ + hookOrder.append(QLatin1String("firstRemoveHook")); +} + +static void secondAddHook(QObject *object) +{ + if (existingAddHook) + existingAddHook(object); + + hookOrder.append(QLatin1String("secondAddHook")); +} + +static void secondRemoveHook(QObject *object) +{ + if (existingRemoveHook) + existingRemoveHook(object); + + hookOrder.append(QLatin1String("secondRemoveHook")); +} + +// Tests that it's possible to "chain" hooks together (i.e. have multiple hooks) +void tst_QHooks::testChaining() +{ + QCOMPARE(qtHookData[QHooks::AddQObject], (quintptr)0); + QCOMPARE(qtHookData[QHooks::RemoveQObject], (quintptr)0); + + // Set the add and remove hooks (could just skip this and go straight to the next step, + // but it's for illustrative purposes). + qtHookData[QHooks::AddQObject] = (quintptr)&firstAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&firstRemoveHook; + + // Store them so that we can call them later. + existingAddHook = reinterpret_cast<QHooks::AddQObjectCallback>(qtHookData[QHooks::AddQObject]); + existingRemoveHook = reinterpret_cast<QHooks::RemoveQObjectCallback>(qtHookData[QHooks::RemoveQObject]); + + // Overide them with hooks that call them first. + qtHookData[QHooks::AddQObject] = (quintptr)&secondAddHook; + qtHookData[QHooks::RemoveQObject] = (quintptr)&secondRemoveHook; + + QObject *obj = new QObject; + QCOMPARE(hookOrder.size(), 2); + QCOMPARE(hookOrder.at(0), QLatin1String("firstAddHook")); + QCOMPARE(hookOrder.at(1), QLatin1String("secondAddHook")); + delete obj; + QCOMPARE(hookOrder.size(), 4); + QCOMPARE(hookOrder.at(2), QLatin1String("firstRemoveHook")); + QCOMPARE(hookOrder.at(3), QLatin1String("secondRemoveHook")); + + hookOrder.clear(); +} + QTEST_APPLESS_MAIN(tst_QHooks) #include "tst_qhooks.moc" diff --git a/tests/auto/corelib/global/qlogging/test/test.pro b/tests/auto/corelib/global/qlogging/test/test.pro index b5b75be3a6..93eee7307a 100644 --- a/tests/auto/corelib/global/qlogging/test/test.pro +++ b/tests/auto/corelib/global/qlogging/test/test.pro @@ -1,7 +1,7 @@ CONFIG += testcase CONFIG -= app_bundle debug_and_release_target -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_qlogging QT = core testlib SOURCES = ../tst_qlogging.cpp diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp index ce227a6c8b..c2d7338042 100644 --- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp +++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp @@ -30,7 +30,7 @@ #include <qdebug.h> #include <qglobal.h> #include <QtCore/QProcess> -#include <QtTest/QtTest> +#include <QtTest/QTest> class tst_qmessagehandler : public QObject { @@ -841,7 +841,7 @@ void tst_qmessagehandler::qMessagePattern() QVERIFY(!output.isEmpty()); QCOMPARE(!output.contains("QT_MESSAGE_PATTERN"), valid); - foreach (const QByteArray &e, expected) { + for (const QByteArray &e : qAsConst(expected)) { if (!output.contains(e)) { qDebug() << output; qDebug() << "expected: " << e; diff --git a/tests/auto/corelib/global/qtendian/qtendian.pro b/tests/auto/corelib/global/qtendian/qtendian.pro index 2b0af4fa4c..214c706ca5 100644 --- a/tests/auto/corelib/global/qtendian/qtendian.pro +++ b/tests/auto/corelib/global/qtendian/qtendian.pro @@ -2,7 +2,3 @@ CONFIG += testcase TARGET = tst_qtendian QT = core testlib SOURCES = tst_qtendian.cpp -wince* { # QTBUG-37194 , internal compiler errors with MSVC2008 for Windows CE - QMAKE_CFLAGS_RELEASE -= -O2 - QMAKE_CXXFLAGS_RELEASE -= -O2 -} diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro index 29717b3a1c..0542833456 100644 --- a/tests/auto/corelib/io/io.pro +++ b/tests/auto/corelib/io/io.pro @@ -35,7 +35,7 @@ SUBDIRS=\ qurlquery \ qwinoverlappedionotifier \ -!win32|wince* { +!win32 { SUBDIRS -=\ qwinoverlappedionotifier } @@ -49,14 +49,14 @@ SUBDIRS=\ qprocess \ qtextstream -!contains(QT_CONFIG, private_tests): SUBDIRS -= \ +!qtConfig(private_tests): SUBDIRS -= \ qabstractfileengine \ qfileinfo \ qipaddress \ qurlinternal \ qloggingregistry -win32:!contains(QT_CONFIG, private_tests): SUBDIRS -= \ +win32:!qtConfig(private_tests): SUBDIRS -= \ qfilesystementry winrt: SUBDIRS -= \ diff --git a/tests/auto/corelib/io/largefile/largefile.pro b/tests/auto/corelib/io/largefile/largefile.pro index caef116684..6c1bb8d7ea 100644 --- a/tests/auto/corelib/io/largefile/largefile.pro +++ b/tests/auto/corelib/io/largefile/largefile.pro @@ -2,5 +2,3 @@ CONFIG += testcase TARGET = tst_largefile QT = core testlib SOURCES = tst_largefile.cpp - -wince: SOURCES += $$QT_SOURCE_TREE/src/corelib/kernel/qfunctions_wince.cpp diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index e448093062..a19a5ce58d 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -39,18 +39,12 @@ #include <cstdio> #ifdef Q_OS_WIN - -#include <windows.h> - -#ifndef Q_OS_WINCE -#include <io.h> -#endif - -#ifndef FSCTL_SET_SPARSE +# include <qt_windows.h> +# include <io.h> +# ifndef FSCTL_SET_SPARSE // MinGW doesn't define this. -#define FSCTL_SET_SPARSE (0x900C4) -#endif - +# define FSCTL_SET_SPARSE (0x900C4) +# endif #endif // Q_OS_WIN class tst_LargeFile diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index 447cf2845e..5b03b35780 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -35,8 +35,6 @@ #include <QtGui/QPainter> #include <QtGui/QPen> -#include "../../../qtest-config.h" - class tst_QDataStream : public QObject { Q_OBJECT @@ -65,7 +63,7 @@ private slots: void stream_QByteArray_data(); void stream_QByteArray(); -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void stream_QCursor_data(); void stream_QCursor(); #endif @@ -88,10 +86,8 @@ private slots: void stream_QPen_data(); void stream_QPen(); -#ifndef Q_OS_WINCE void stream_QPixmap_data(); void stream_QPixmap(); -#endif void stream_QPoint_data(); void stream_QPoint(); @@ -123,10 +119,8 @@ private slots: void stream_qint64_data(); void stream_qint64(); -#ifndef Q_OS_WINCE void stream_QIcon_data(); void stream_QIcon(); -#endif void stream_QEasingCurve_data(); void stream_QEasingCurve(); @@ -193,7 +187,7 @@ private: void writeQBrush(QDataStream *s); void writeQColor(QDataStream *s); void writeQByteArray(QDataStream *s); -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void writeQCursor(QDataStream *s); #endif void writeQWaitCursor(QDataStream *s); @@ -222,7 +216,7 @@ private: void readQBrush(QDataStream *s); void readQColor(QDataStream *s); void readQByteArray(QDataStream *s); -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void readQCursor(QDataStream *s); #endif void readQDate(QDataStream *s); @@ -1023,7 +1017,7 @@ void tst_QDataStream::readQByteArray(QDataStream *s) } // ************************************ -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR static QCursor qCursorData(int index) { switch (index) { @@ -1042,21 +1036,21 @@ static QCursor qCursorData(int index) } #endif -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void tst_QDataStream::stream_QCursor_data() { stream_data(9); } #endif -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void tst_QDataStream::stream_QCursor() { STREAM_IMPL(QCursor); } #endif -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void tst_QDataStream::writeQCursor(QDataStream *s) { QCursor d5(qCursorData(dataIndex(QTest::currentDataTag()))); @@ -1064,7 +1058,7 @@ void tst_QDataStream::writeQCursor(QDataStream *s) } #endif -#ifndef QTEST_NO_CURSOR +#ifndef QT_NO_CURSOR void tst_QDataStream::readQCursor(QDataStream *s) { QCursor test(qCursorData(dataIndex(QTest::currentDataTag()))); @@ -1543,24 +1537,16 @@ void tst_QDataStream::readQPen(QDataStream *s) // pixmap testing is currently limited to one pixmap only. // -#ifndef Q_OS_WINCE -// Test depends on more memory than available on Qt/CE void tst_QDataStream::stream_QPixmap_data() { stream_data(1); } -#endif -#ifndef Q_OS_WINCE -// Test depends on more memory than available on Qt/CE void tst_QDataStream::stream_QPixmap() { STREAM_IMPL(QPixmap); } -#endif -#ifndef Q_OS_WINCE -// Test depends on more memory than available on Qt/CE void tst_QDataStream::stream_QIcon_data() { stream_data(1); @@ -1570,7 +1556,6 @@ void tst_QDataStream::stream_QIcon() { STREAM_IMPL(QIcon); } -#endif void tst_QDataStream::writeQPixmap(QDataStream *s) { @@ -1845,7 +1830,7 @@ static QRegion qRegionData(int index) case 4: return QRegion(100, -100, 2048, 4096, QRegion::Rectangle); case 5: return QRegion(-100, 100, 4096, 2048, QRegion::Rectangle); case 6: return QRegion(0, 0, 0, 0, QRegion::Ellipse); -#if (!defined(Q_OS_UNIX) && !defined(Q_OS_WINCE)) // all our Unix platforms use X regions. +#if !defined(Q_OS_UNIX) // all our Unix platforms use X regions. case 7: return QRegion(1, 2, 300, 400, QRegion::Ellipse); case 8: return QRegion(100, 100, 1024, 768, QRegion::Ellipse); case 9: return QRegion(-100, -100, 1024, 1024, QRegion::Ellipse); @@ -2497,12 +2482,10 @@ void tst_QDataStream::status_charptr_QByteArray_data() QTest::addColumn<int>("expectedStatus"); QTest::addColumn<QByteArray>("expectedString"); -#if !defined(Q_OS_WINCE) QByteArray oneMbMinus1(1024 * 1024 - 1, '\0'); for (int i = 0; i < oneMbMinus1.size(); ++i) oneMbMinus1[i] = 0x1 | (8 * ((uchar)i / 9)); QByteArray threeMbMinus1 = oneMbMinus1 + 'j' + oneMbMinus1 + 'k' + oneMbMinus1; -#endif // ok QTest::newRow("size 0") << QByteArray("\x00\x00\x00\x00", 4) << (int) QDataStream::Ok << QByteArray(); @@ -2511,14 +2494,12 @@ void tst_QDataStream::status_charptr_QByteArray_data() QTest::newRow("size 3") << QByteArray("\x00\x00\x00\x03jkl", 7) << (int) QDataStream::Ok << QByteArray("jkl"); QTest::newRow("size 4") << QByteArray("\x00\x00\x00\x04jklm", 8) << (int) QDataStream::Ok << QByteArray("jklm"); QTest::newRow("size 4j") << QByteArray("\x00\x00\x00\x04jklmj", 8) << (int) QDataStream::Ok << QByteArray("jklm"); -#if !defined(Q_OS_WINCE) QTest::newRow("size 1MB-1") << QByteArray("\x00\x0f\xff\xff", 4) + oneMbMinus1 + QByteArray("j") << (int) QDataStream::Ok << oneMbMinus1; QTest::newRow("size 1MB") << QByteArray("\x00\x10\x00\x00", 4) + oneMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << oneMbMinus1 + "j"; QTest::newRow("size 1MB+1") << QByteArray("\x00\x10\x00\x01", 4) + oneMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << oneMbMinus1 + "jk"; QTest::newRow("size 3MB-1") << QByteArray("\x00\x2f\xff\xff", 4) + threeMbMinus1 + QByteArray("j") << (int) QDataStream::Ok << threeMbMinus1; QTest::newRow("size 3MB") << QByteArray("\x00\x30\x00\x00", 4) + threeMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << threeMbMinus1 + "j"; QTest::newRow("size 3MB+1") << QByteArray("\x00\x30\x00\x01", 4) + threeMbMinus1 + QByteArray("jkl") << (int) QDataStream::Ok << threeMbMinus1 + "jk"; -#endif // past end QTest::newRow("empty") << QByteArray() << (int) QDataStream::ReadPastEnd << QByteArray(); @@ -2531,12 +2512,10 @@ void tst_QDataStream::status_charptr_QByteArray_data() QTest::newRow("badsize 2") << QByteArray("\x00\x00\x00\x02j", 5) << (int) QDataStream::ReadPastEnd << QByteArray(); QTest::newRow("badsize 3") << QByteArray("\x00\x00\x00\x03jk", 6) << (int) QDataStream::ReadPastEnd << QByteArray(); QTest::newRow("badsize 4") << QByteArray("\x00\x00\x00\x04jkl", 7) << (int) QDataStream::ReadPastEnd << QByteArray(); -#if !defined(Q_OS_WINCE) QTest::newRow("badsize 1MB") << QByteArray("\x00\x10\x00\x00", 4) + oneMbMinus1 << (int) QDataStream::ReadPastEnd << QByteArray(); QTest::newRow("badsize 1MB+1") << QByteArray("\x00\x10\x00\x01", 4) + oneMbMinus1 + QByteArray("j") << (int) QDataStream::ReadPastEnd << QByteArray(); QTest::newRow("badsize 3MB") << QByteArray("\x00\x30\x00\x00", 4) + threeMbMinus1 << (int) QDataStream::ReadPastEnd << QByteArray(); QTest::newRow("badsize 3MB+1") << QByteArray("\x00\x30\x00\x01", 4) + threeMbMinus1 + QByteArray("j") << (int) QDataStream::ReadPastEnd << QByteArray(); -#endif QTest::newRow("size -1") << QByteArray("\xff\xff\xff\xff", 4) << (int) QDataStream::ReadPastEnd << QByteArray(); QTest::newRow("size -2") << QByteArray("\xff\xff\xff\xfe", 4) << (int) QDataStream::ReadPastEnd << QByteArray(); } @@ -2601,7 +2580,6 @@ void tst_QDataStream::status_QString_data() QTest::addColumn<int>("expectedStatus"); QTest::addColumn<QString>("expectedString"); -#if !defined(Q_OS_WINCE) QString oneMbMinus1; oneMbMinus1.resize(1024 * 1024 - 1); for (int i = 0; i < oneMbMinus1.size(); ++i) @@ -2610,7 +2588,6 @@ void tst_QDataStream::status_QString_data() QByteArray threeMbMinus1Data = qstring2qbytearray(threeMbMinus1); QByteArray oneMbMinus1Data = qstring2qbytearray(oneMbMinus1); -#endif // ok QTest::newRow("size 0") << QByteArray("\x00\x00\x00\x00", 4) << (int) QDataStream::Ok << QString(); @@ -2619,14 +2596,12 @@ void tst_QDataStream::status_QString_data() QTest::newRow("size 3") << QByteArray("\x00\x00\x00\x06\x00j\x00k\x00l", 10) << (int) QDataStream::Ok << QString("jkl"); QTest::newRow("size 4") << QByteArray("\x00\x00\x00\x08\x00j\x00k\x00l\x00m", 12) << (int) QDataStream::Ok << QString("jklm"); QTest::newRow("size 4j") << QByteArray("\x00\x00\x00\x08\x00j\x00k\x00l\x00mjj", 14) << (int) QDataStream::Ok << QString("jklm"); -#if !defined(Q_OS_WINCE) QTest::newRow("size 1MB-1") << QByteArray("\x00\x1f\xff\xfe", 4) + oneMbMinus1Data + QByteArray("jj") << (int) QDataStream::Ok << oneMbMinus1; QTest::newRow("size 1MB") << QByteArray("\x00\x20\x00\x00", 4) + oneMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << oneMbMinus1 + "j"; QTest::newRow("size 1MB+1") << QByteArray("\x00\x20\x00\x02", 4) + oneMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << oneMbMinus1 + "jk"; QTest::newRow("size 3MB-1") << QByteArray("\x00\x5f\xff\xfe", 4) + threeMbMinus1Data + QByteArray("jj") << (int) QDataStream::Ok << threeMbMinus1; QTest::newRow("size 3MB") << QByteArray("\x00\x60\x00\x00", 4) + threeMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << threeMbMinus1 + "j"; QTest::newRow("size 3MB+1") << QByteArray("\x00\x60\x00\x02", 4) + threeMbMinus1Data + QByteArray("\x00j\x00k\x00l", 6) << (int) QDataStream::Ok << threeMbMinus1 + "jk"; -#endif // past end QTest::newRow("empty") << QByteArray() << (int) QDataStream::ReadPastEnd << QString(); @@ -2639,14 +2614,12 @@ void tst_QDataStream::status_QString_data() QTest::newRow("badsize 2") << QByteArray("\x00\x00\x00\x04jj", 6) << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("badsize 3") << QByteArray("\x00\x00\x00\x06jjkk", 8) << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("badsize 4") << QByteArray("\x00\x00\x00\x08jjkkll", 10) << (int) QDataStream::ReadPastEnd << QString(); -#if !defined(Q_OS_WINCE) QTest::newRow("badsize 1MB") << QByteArray("\x00\x20\x00\x00", 4) + oneMbMinus1Data << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("badsize 1MB+1") << QByteArray("\x00\x20\x00\x02", 4) + oneMbMinus1Data + QByteArray("j") << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("badsize 3MB") << QByteArray("\x00\x60\x00\x00", 4) + threeMbMinus1Data << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("badsize 3MB+1") << QByteArray("\x00\x60\x00\x02", 4) + threeMbMinus1Data + QByteArray("j") << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("size -2") << QByteArray("\xff\xff\xff\xfe", 4) << (int) QDataStream::ReadPastEnd << QString(); QTest::newRow("size MAX") << QByteArray("\x7f\xff\xff\xfe", 4) << (int) QDataStream::ReadPastEnd << QString(); -#endif // corrupt data QTest::newRow("corrupt1") << QByteArray("yyyy") << (int) QDataStream::ReadCorruptData << QString(); diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index 48b8db949f..294a53645e 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -35,7 +35,7 @@ #include <qregexp.h> #include <qstringlist.h> -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if defined(Q_OS_WIN) #include <QtCore/private/qfsfileengine_p.h> #include "../../../network-settings.h" #endif @@ -163,9 +163,8 @@ private slots: void operator_eq(); -#ifndef Q_OS_WINCE void dotAndDotDot(); -#endif + void homePath(); void tempPath(); void rootPath(); @@ -317,7 +316,7 @@ void tst_QDir::setPath_data() QTest::addColumn<QString>("dir2"); QTest::newRow("data0") << QString(".") << QString(".."); -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if defined(Q_OS_WIN) QTest::newRow("data1") << QString("c:/") << QDir::currentPath(); #endif } @@ -544,7 +543,7 @@ void tst_QDir::exists_data() QTest::newRow("simple dir") << (m_dataPath + "/resources") << true; QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << true; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; @@ -556,7 +555,7 @@ void tst_QDir::exists_data() QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << false; QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false; #endif -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINRT)) QTest::newRow("This drive should exist") << "C:/" << true; // find a non-existing drive and check if it does not exist #ifdef QT_BUILD_INTERNAL @@ -597,7 +596,7 @@ void tst_QDir::isRelativePath_data() QTest::addColumn<bool>("relative"); QTest::newRow("data0") << "../somedir" << true; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if defined(Q_OS_WIN) QTest::newRow("data1") << "C:/sOmedir" << false; #endif QTest::newRow("data2") << "somedir" << true; @@ -803,12 +802,6 @@ void tst_QDir::entryList() QFile::remove(entrylistPath + "brokenlink.lnk"); QFile::remove(entrylistPath + "brokenlink"); - // WinCE does not have . and .. in the directory listing -#if defined(Q_OS_WINCE) - expected.removeAll("."); - expected.removeAll(".."); -#endif - #ifndef Q_NO_SYMLINKS #if defined(Q_OS_WIN) // ### Sadly, this is a platform difference right now. @@ -901,15 +894,10 @@ void tst_QDir::entryListSimple_data() QTest::addColumn<int>("countMin"); QTest::newRow("data2") << "do_not_expect_this_path_to_exist/" << 0; -#if defined(Q_OS_WINCE) - QTest::newRow("simple dir") << (m_dataPath + "/resources") << 0; - QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << 0; -#else QTest::newRow("simple dir") << (m_dataPath + "/resources") << 2; QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << 2; -#endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << 2; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2; @@ -1000,15 +988,7 @@ void tst_QDir::canonicalPath_data() QTest::newRow("nonexistant") << "testd" << QString(); QTest::newRow("rootPath") << QDir::rootPath() << QDir::rootPath(); - -#ifdef Q_OS_MAC - // On Mac OS X 10.5 and earlier, canonicalPath depends on cleanPath which - // is itself very broken and fundamentally wrong on "/./" which, this would - // exercise - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) -#endif - QTest::newRow("rootPath + ./") << QDir::rootPath().append("./") << QDir::rootPath(); - + QTest::newRow("rootPath + ./") << QDir::rootPath().append("./") << QDir::rootPath(); QTest::newRow("rootPath + ../.. ") << QDir::rootPath().append("../..") << QDir::rootPath(); #if defined(Q_OS_WIN) QTest::newRow("drive:\\") << QDir::toNativeSeparators(QDir::rootPath()) << QDir::rootPath(); @@ -1171,7 +1151,6 @@ tst_QDir::cleanPath_data() QTest::newRow("data2") << "/" << "/"; QTest::newRow("data3") << QDir::cleanPath("../.") << ".."; QTest::newRow("data4") << QDir::cleanPath("../..") << "../.."; -#if !defined(Q_OS_WINCE) #if defined(Q_OS_WIN) QTest::newRow("data5") << "d:\\a\\bc\\def\\.." << "d:/a/bc"; QTest::newRow("data6") << "d:\\a\\bc\\def\\../../.." << "d:/"; @@ -1179,17 +1158,14 @@ tst_QDir::cleanPath_data() QTest::newRow("data5") << "d:\\a\\bc\\def\\.." << "d:\\a\\bc\\def\\.."; QTest::newRow("data6") << "d:\\a\\bc\\def\\../../.." << ".."; #endif -#endif QTest::newRow("data7") << ".//file1.txt" << "file1.txt"; QTest::newRow("data8") << "/foo/bar/..//file1.txt" << "/foo/file1.txt"; QTest::newRow("data9") << "//" << "/"; -#if !defined(Q_OS_WINCE) #if defined Q_OS_WIN QTest::newRow("data10") << "c:\\" << "c:/"; #else QTest::newRow("data10") << "/:/" << "/:"; #endif -#endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QTest::newRow("data11") << "//foo//bar" << "//foo/bar"; #endif @@ -1351,7 +1327,7 @@ void tst_QDir::absolutePath_data() QTest::addColumn<QString>("expectedPath"); QTest::newRow("0") << "/machine/share/dir1" << "/machine/share/dir1"; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINRT)) QTest::newRow("1") << "\\machine\\share\\dir1" << "/machine/share/dir1"; QTest::newRow("2") << "//machine/share/dir1" << "//machine/share/dir1"; QTest::newRow("3") << "\\\\machine\\share\\dir1" << "//machine/share/dir1"; @@ -1400,7 +1376,7 @@ void tst_QDir::relativeFilePath_data() QTest::newRow("same path 1") << "/tmp" << "/tmp" << "."; QTest::newRow("same path 2") << "//tmp" << "/tmp/" << "."; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if defined(Q_OS_WIN) QTest::newRow("12") << "C:/foo/bar" << "ding" << "ding"; QTest::newRow("13") << "C:/foo/bar" << "C:/ding/dong" << "../../ding/dong"; QTest::newRow("14") << "C:/foo/bar" << "/ding/dong" << "../../ding/dong"; @@ -1576,7 +1552,6 @@ void tst_QDir::operator_eq() dir1.setPath(".."); } -#ifndef Q_OS_WINCE // WinCE does not have . nor .. void tst_QDir::dotAndDotDot() { @@ -1586,7 +1561,6 @@ void tst_QDir::dotAndDotDot() entryList = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot); QCOMPARE(entryList, QStringList() << QString("dir") << QString("spaces")); } -#endif void tst_QDir::homePath() { @@ -1830,16 +1804,9 @@ void tst_QDir::updateFileLists() QDir dir(fs.absoluteFilePath(dirName)); -#if defined(Q_OS_WINCE) - //no . and .. on these OS. - QCOMPARE(dir.count(), uint(4)); - QCOMPARE(dir.entryList().size(), 4); - QCOMPARE(dir.entryInfoList().size(), 4); -#else QCOMPARE(dir.count(), uint(6)); QCOMPARE(dir.entryList().size(), 6); QCOMPARE(dir.entryInfoList().size(), 6); -#endif dir.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot); @@ -2020,13 +1987,7 @@ void tst_QDir::isRoot_data() QTest::newRow(QString("./ appended " + test).toLatin1()) << test << false; test = QDir(QDir::rootPath().append("./")).canonicalPath(); -#ifdef Q_OS_MAC - // On Mac OS X 10.5 and earlier, canonicalPath depends on cleanPath which - // is itself very broken and fundamentally wrong on "/./", which this would - // exercise - if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) -#endif - QTest::newRow(QString("canonicalPath " + test).toLatin1()) << test << true; + QTest::newRow(QString("canonicalPath " + test).toLatin1()) << test << true; #if defined(Q_OS_WIN) test = QDir::rootPath().left(2); diff --git a/tests/auto/corelib/io/qdiriterator/qdiriterator.pro b/tests/auto/corelib/io/qdiriterator/qdiriterator.pro index 5404e9058f..7c1f026bdb 100644 --- a/tests/auto/corelib/io/qdiriterator/qdiriterator.pro +++ b/tests/auto/corelib/io/qdiriterator/qdiriterator.pro @@ -6,5 +6,3 @@ RESOURCES += qdiriterator.qrc TESTDATA += entrylist contains(CONFIG, builtin_testdata): DEFINES += BUILTIN_TESTDATA - -wince*mips*|wincewm50smart-msvc200*: DEFINES += WINCE_BROKEN_ITERATE=1 diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp index 0fbce74055..6450e9af7b 100644 --- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp @@ -41,7 +41,7 @@ #define Q_NO_SYMLINKS #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) # include "../../../network-settings.h" #endif @@ -103,7 +103,7 @@ private slots: void longPath(); void dirorder(); void relativePaths(); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) void uncPaths_data(); void uncPaths(); #endif @@ -196,7 +196,7 @@ void tst_QDirIterator::initTestCase() # endif #endif -#if !defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_WIN) createDirectory("hiddenDirs_hiddenFiles"); createFile("hiddenDirs_hiddenFiles/normalFile"); createFile("hiddenDirs_hiddenFiles/.hiddenFile"); @@ -239,10 +239,8 @@ void tst_QDirIterator::iterateRelativeDirectory_data() << QString("entrylist") << QDirIterator::IteratorFlags(0) << QDir::Filters(QDir::NoFilter) << QStringList("*") << QString( -#if !defined(Q_OS_WINCE) "entrylist/.," "entrylist/..," -#endif "entrylist/file," #ifndef Q_NO_SYMLINKS "entrylist/linktofile.lnk," @@ -257,9 +255,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() << QString("entrylist") << QDirIterator::IteratorFlags(0) << QDir::Filters(QDir::AllEntries | QDir::NoDot) << QStringList("*") << QString( -#if !defined(Q_OS_WINCE) "entrylist/..," -#endif "entrylist/file," #ifndef Q_NO_SYMLINKS "entrylist/linktofile.lnk," @@ -274,9 +270,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() << QString("entrylist") << QDirIterator::IteratorFlags(0) << QDir::Filters(QDir::AllEntries | QDir::NoDotDot) << QStringList("*") << QString( -#if !defined(Q_OS_WINCE) "entrylist/.," -#endif "entrylist/file," #ifndef Q_NO_SYMLINKS "entrylist/linktofile.lnk," @@ -305,12 +299,10 @@ void tst_QDirIterator::iterateRelativeDirectory_data() << QString("entrylist") << QDirIterator::IteratorFlags(QDirIterator::Subdirectories | QDirIterator::FollowSymlinks) << QDir::Filters(QDir::NoFilter) << QStringList("*") << QString( -#if !defined(Q_OS_WINCE) "entrylist/.," "entrylist/..," "entrylist/directory/.," "entrylist/directory/..," -#endif "entrylist/file," #ifndef Q_NO_SYMLINKS "entrylist/linktofile.lnk," @@ -345,11 +337,7 @@ void tst_QDirIterator::iterateRelativeDirectory_data() QTest::newRow("empty, default") << QString("empty") << QDirIterator::IteratorFlags(0) << QDir::Filters(QDir::NoFilter) << QStringList("*") -#if defined(Q_OS_WINCE) - << QStringList(); -#else << QString("empty/.,empty/..").split(','); -#endif QTest::newRow("empty, QDir::NoDotAndDotDot") << QString("empty") << QDirIterator::IteratorFlags(0) @@ -562,13 +550,6 @@ void tst_QDirIterator::longPath() while (dir.exists(dirName) || dir.mkdir(dirName)) { ++n; dirName.append('x'); -#if defined(Q_OS_WINCE) && defined(WINCE_BROKEN_ITERATE) - // Some Windows CE devices/emulators are broken. - // though one can create directories of length <= 217, - // FindNextFile only reports entries until ~ 214. - if (n >= 210) - break; -#endif } QDirIterator it(dir.absolutePath(), QDir::NoDotAndDotDot|QDir::Dirs, QDirIterator::Subdirectories); @@ -606,7 +587,7 @@ void tst_QDirIterator::relativePaths() } } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) void tst_QDirIterator::uncPaths_data() { QTest::addColumn<QString>("dirName"); diff --git a/tests/auto/corelib/io/qfile/qfile.pro b/tests/auto/corelib/io/qfile/qfile.pro index 10c8d918f7..0735daedb3 100644 --- a/tests/auto/corelib/io/qfile/qfile.pro +++ b/tests/auto/corelib/io/qfile/qfile.pro @@ -1,7 +1,2 @@ TEMPLATE = subdirs -wince* { - SUBDIRS = test -} else { - SUBDIRS = test stdinprocess -} - +SUBDIRS = test stdinprocess diff --git a/tests/auto/corelib/io/qfile/test/test.pro b/tests/auto/corelib/io/qfile/test/test.pro index c9ba96cc1b..c0c4b9d5d2 100644 --- a/tests/auto/corelib/io/qfile/test/test.pro +++ b/tests/auto/corelib/io/qfile/test/test.pro @@ -6,7 +6,6 @@ else: DEFINES += QT_NO_NETWORK TARGET = ../tst_qfile SOURCES = ../tst_qfile.cpp -wince: SOURCES += $$QT_SOURCE_TREE/src/corelib/kernel/qfunctions_wince.cpp RESOURCES += ../qfile.qrc ../rename-fallback.qrc ../copy-fallback.qrc diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 7752930ae4..287b8aebd8 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -47,7 +47,7 @@ extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; QT_END_NAMESPACE #endif -#if !defined(Q_OS_WINCE) && !defined(QT_NO_NETWORK) +#if !defined(QT_NO_NETWORK) #include <QHostInfo> #endif #include <QProcess> @@ -66,8 +66,6 @@ QT_END_NAMESPACE # include <sys/mount.h> #elif defined(Q_OS_IRIX) # include <sys/statfs.h> -#elif defined(Q_OS_WINCE) -# include <qplatformdefs.h> #elif defined(Q_OS_VXWORKS) # include <fcntl.h> #if defined(_WRS_KERNEL) @@ -85,7 +83,7 @@ QT_END_NAMESPACE #include <stdio.h> #include <errno.h> -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) #include "../../../network-settings.h" #endif @@ -135,11 +133,9 @@ private slots: void readAll_data(); void readAll(); void readAllBuffer(); -#if !defined(Q_OS_WINCE) void readAllStdin(); void readLineStdin(); void readLineStdin_lineByLine(); -#endif void text(); void missingEndOfLine(); void readBlock(); @@ -159,17 +155,19 @@ private slots: void copyRemovesTemporaryFile() const; void copyShouldntOverwrite(); void copyFallback(); +#ifndef Q_OS_WINRT void link(); void linkToDir(); void absolutePathLinkToRelativePath(); void readBrokenLink(); +#endif void readTextFile_data(); void readTextFile(); void readTextFile2(); void writeTextFile_data(); void writeTextFile(); /* void largeFileSupport(); */ -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void largeUncFileSupport(); #endif void flush(); @@ -225,10 +223,8 @@ private slots: void mapWrittenFile_data(); void mapWrittenFile(); -#ifndef Q_OS_WINCE void openStandardStreamsFileDescriptors(); void openStandardStreamsBufferedStreams(); -#endif void resize_data(); void resize(); @@ -491,7 +487,7 @@ void tst_QFile::exists() file.remove(); QVERIFY(!file.exists()); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QString uncPath = "//" + QtNetworkSettings::winServerName() + "/testshare/readme.txt"; QFile unc(uncPath); QVERIFY2(unc.exists(), msgFileDoesNotExist(uncPath).constData()); @@ -543,7 +539,7 @@ void tst_QFile::open_data() << int(QIODevice::ReadOnly) << false << QFile::OpenError; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) //opening devices requires administrative privileges (and elevation). HANDLE hTest = CreateFile(_T("\\\\.\\PhysicalDrive0"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (hTest != INVALID_HANDLE_VALUE) { @@ -574,7 +570,7 @@ void tst_QFile::open() QSKIP("Running this test as root doesn't make sense"); #endif -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +#if defined(Q_OS_WIN32) || defined(Q_OS_WINRT) QEXPECT_FAIL("noreadfile", "Windows does not currently support non-readable files.", Abort); #endif if (filename.isEmpty()) @@ -626,7 +622,7 @@ void tst_QFile::size_data() QTest::addColumn<qint64>("size"); QTest::newRow( "exist01" ) << m_testFile << (qint64)245; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // Only test UNC on Windows./ QTest::newRow("unc") << "//" + QString(QtNetworkSettings::winServerName() + "/testshare/test.pri") << (qint64)34; #endif @@ -637,10 +633,6 @@ void tst_QFile::size() QFETCH( QString, filename ); QFETCH( qint64, size ); -#ifdef Q_OS_WINCE - filename = QFileInfo(filename).absoluteFilePath(); -#endif - { QFile f( filename ); QCOMPARE( f.size(), size ); @@ -660,9 +652,6 @@ void tst_QFile::size() fclose(stream); } - // Currently low level file I/O is not well supported on Windows CE, so - // skip this part of the test. -#ifndef Q_OS_WINCE { QFile f; @@ -675,7 +664,6 @@ void tst_QFile::size() f.close(); QT_CLOSE(fd); } -#endif } void tst_QFile::sizeNoExist() @@ -920,7 +908,6 @@ private: }; #endif // !QT_NO_PROCESS -#if !defined(Q_OS_WINCE) void tst_QFile::readAllStdin() { #ifdef QT_NO_PROCESS @@ -1011,7 +998,6 @@ void tst_QFile::readLineStdin_lineByLine() } #endif } -#endif void tst_QFile::text() { @@ -1112,7 +1098,7 @@ void tst_QFile::ungetChar() QCOMPARE(buf[2], '4'); } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QString driveLetters() { wchar_t volumeName[MAX_PATH]; @@ -1149,7 +1135,7 @@ void tst_QFile::invalidFile_data() #if !defined(Q_OS_WIN) QTest::newRow( "x11" ) << QString( "qwe//" ); #else -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) QTest::newRow( "colon2" ) << invalidDriveLetter() + QString::fromLatin1(":ail:invalid"); #endif QTest::newRow( "colon3" ) << QString( ":failinvalid" ); @@ -1211,13 +1197,11 @@ void tst_QFile::permissions_data() QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << uint(QFile::ExeUser) << true << false; QTest::newRow("data1") << m_testSourceFile << uint(QFile::ReadUser) << true << false; QTest::newRow("readonly") << QString::fromLatin1("readonlyfile") << uint(QFile::WriteUser) << false << false; -#ifndef Q_OS_WINCE QTest::newRow("longfile") << QString::fromLatin1("longFileNamelongFileNamelongFileNamelongFileName" "longFileNamelongFileNamelongFileNamelongFileName" "longFileNamelongFileNamelongFileNamelongFileName" "longFileNamelongFileNamelongFileNamelongFileName" "longFileNamelongFileNamelongFileNamelongFileName.txt") << uint(QFile::ReadUser) << true << true; -#endif QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << uint(QFile::ReadUser) << true << false; QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << uint(QFile::WriteUser) << false << false; QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << uint(QFile::ExeUser) << false << false; @@ -1244,7 +1228,7 @@ void tst_QFile::permissions() QFile::remove(file); } -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) if (qt_ntfs_permission_lookup) QEXPECT_FAIL("readonly", "QTBUG-25630", Abort); #endif @@ -1369,15 +1353,9 @@ void tst_QFile::copyFallback() QVERIFY(QFile::exists("file-copy-destination.txt")); QVERIFY(!file.isOpen()); -#ifdef Q_OS_WINCE - // Need to reset permissions on Windows to be able to delete - QVERIFY(QFile::setPermissions("file-copy-destination.txt", - QFile::WriteOther)); -#else // Need to reset permissions on Windows to be able to delete QVERIFY(QFile::setPermissions("file-copy-destination.txt", QFile::ReadOwner | QFile::WriteOwner)); -#endif QVERIFY(QFile::remove("file-copy-destination.txt")); // Fallback copy of open file. @@ -1398,7 +1376,7 @@ void tst_QFile::copyFallback() #endif #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) static QString getWorkingDirectoryForLink(const QString &linkFileName) { bool neededCoInit = false; @@ -1437,6 +1415,7 @@ static QString getWorkingDirectoryForLink(const QString &linkFileName) } #endif +#ifndef Q_OS_WINRT void tst_QFile::link() { QFile::remove("myLink.lnk"); @@ -1457,7 +1436,7 @@ void tst_QFile::link() QCOMPARE(QFile::symLinkTarget("myLink.lnk"), referenceTarget); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) QString wd = getWorkingDirectoryForLink(info2.absoluteFilePath()); QCOMPARE(QDir::fromNativeSeparators(wd), QDir::cleanPath(info1.absolutePath())); #endif @@ -1511,6 +1490,7 @@ void tst_QFile::readBrokenLink() QVERIFY(QFile::link("ole/..", "myLink2.lnk")); QCOMPARE(QFileInfo("myLink2.lnk").symLinkTarget(), QDir::currentPath()); } +#endif // Q_OS_WINRT void tst_QFile::readTextFile_data() { @@ -1595,7 +1575,7 @@ void tst_QFile::writeTextFile() QCOMPARE(file.readAll(), out); } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void tst_QFile::largeUncFileSupport() { qint64 size = Q_INT64_C(8589934592); @@ -1674,11 +1654,7 @@ void tst_QFile::bufferedRead() file.write("abcdef"); file.close(); -#if defined(Q_OS_WINCE) - FILE *stdFile = fopen((QCoreApplication::applicationDirPath() + "/stdfile.txt").toLatin1() , "r"); -#else FILE *stdFile = fopen("stdfile.txt", "r"); -#endif QVERIFY(stdFile); char c; QCOMPARE(int(fread(&c, 1, 1, stdFile)), 1); @@ -1823,11 +1799,7 @@ void tst_QFile::FILEReadWrite() f.close(); } -#ifdef Q_OS_WINCE - FILE *fp = fopen(qPrintable(QCoreApplication::applicationDirPath() + "\\FILEReadWrite.txt"), "r+b"); -#else FILE *fp = fopen("FILEReadWrite.txt", "r+b"); -#endif QVERIFY(fp); QFile file; QVERIFY2(file.open(fp, QFile::ReadWrite), msgOpenFailed(file).constData()); @@ -2032,10 +2004,6 @@ void tst_QFile::longFileName() } { QFile file(fileName); -#if defined(Q_OS_WINCE) - QEXPECT_FAIL("244 chars", "Full pathname must be less than 260 chars", Abort); - QEXPECT_FAIL("244 chars to absolutepath", "Full pathname must be less than 260 chars", Abort); -#endif QVERIFY2(file.open(QFile::WriteOnly | QFile::Text), msgOpenFailed(file).constData()); QTextStream ts(&file); ts << fileName << endl; @@ -2303,7 +2271,7 @@ void tst_QFile::writeLargeDataBlock_data() QTest::newRow("localfile-Fd") << "./largeblockfile.txt" << (int)OpenFd; QTest::newRow("localfile-Stream") << "./largeblockfile.txt" << (int)OpenStream; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) && !defined(QT_NO_NETWORK) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) && !defined(QT_NO_NETWORK) // Some semi-randomness to avoid collisions. QTest::newRow("unc file") << QString("//" + QtNetworkSettings::winServerName() + "/TESTSHAREWRITABLE/largefile-%1-%2.txt") @@ -2318,8 +2286,8 @@ static QByteArray getLargeDataBlock() if (array.isNull()) { -#if defined(Q_OS_WINCE) || defined(Q_OS_VXWORKS) - int resizeSize = 1024 * 1024; // WinCE does not have much space +#if defined(Q_OS_VXWORKS) + int resizeSize = 1024 * 1024; // VxWorks does not have much space #else int resizeSize = 64 * 1024 * 1024; #endif @@ -2447,9 +2415,7 @@ void tst_QFile::virtualFile() void tst_QFile::textFile() { -#if defined(Q_OS_WINCE) - FILE *fs = ::fopen((QCoreApplication::applicationDirPath() + "/writeabletextfile").toLatin1() , "wt"); -#elif defined(Q_OS_WIN) +#if defined(Q_OS_WIN) FILE *fs = ::fopen("writeabletextfile", "wt"); #else FILE *fs = ::fopen("writeabletextfile", "w"); @@ -2662,7 +2628,7 @@ void tst_QFile::appendAndRead() void tst_QFile::miscWithUncPathAsCurrentDir() { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QString current = QDir::currentPath(); const QString path = QLatin1String("//") + QtNetworkSettings::winServerName() + QLatin1String("/testshare"); @@ -2686,14 +2652,14 @@ void tst_QFile::standarderror() void tst_QFile::handle() { int fd; -#if !defined(Q_OS_WINCE) QFile file(m_testSourceFile); QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData()); fd = int(file.handle()); QVERIFY(fd > 2); QCOMPARE(int(file.handle()), fd); char c = '\0'; - QT_READ(int(file.handle()), &c, 1); + const auto readResult = QT_READ(int(file.handle()), &c, 1); + QCOMPARE(readResult, static_cast<decltype(readResult)>(1)); QCOMPARE(c, '/'); // test if the QFile and the handle remain in sync @@ -2714,7 +2680,6 @@ void tst_QFile::handle() #endif QCOMPARE(c, '*'); -#endif //test round trip of adopted stdio file handle QFile file2; @@ -2957,10 +2922,6 @@ void tst_QFile::map() QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile"; -#ifdef Q_OS_WINCE - fileName = QFileInfo(fileName).absoluteFilePath(); -#endif - if (QFile::exists(fileName)) { QVERIFY(QFile::setPermissions(fileName, QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser)); @@ -3002,7 +2963,7 @@ void tst_QFile::map() QCOMPARE(file.error(), QFile::NoError); // hpux won't let you map multiple times. -#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_HPUX) && !defined(Q_USE_DEPRECATED_MAP_API) // exotic test to make sure that multiple maps work // note: windows ce does not reference count mutliple maps @@ -3125,10 +3086,6 @@ void tst_QFile::mapOpenMode() QVERIFY2(file.open(om), msgOpenFailed(om, file).constData()); uchar *memory = file.map(0, fileSize, QFileDevice::MemoryMapFlags(flags)); -#if defined(Q_OS_WINCE) - QEXPECT_FAIL("ReadOnly + MapPrivate" , "Windows CE does not support MapPrivateOption.", Abort); - QEXPECT_FAIL("ReadWrite + MapPrivate", "Windows CE does not support MapPrivateOption.", Abort); -#endif QVERIFY(memory); QVERIFY(memcmp(memory, pattern, fileSize) == 0); @@ -3161,10 +3118,6 @@ void tst_QFile::mapWrittenFile() QString fileName = QDir::currentPath() + '/' + "qfile_map_testfile"; -#ifdef Q_OS_WINCE - fileName = QFileInfo(fileName).absoluteFilePath(); -#endif - if (QFile::exists(fileName)) { QVERIFY(QFile::setPermissions(fileName, QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser)); @@ -3263,10 +3216,6 @@ protected: bool MessageHandler::ok = true; QtMessageHandler MessageHandler::oldMessageHandler = 0; - //allthough Windows CE (not mobile!) has functions that allow redirecting - //the standard file descriptors to a file (see SetStdioPathW/GetStdioPathW) - //it does not have functions to simply open them like below . -#ifndef Q_OS_WINCE void tst_QFile::openStandardStreamsFileDescriptors() { @@ -3326,7 +3275,6 @@ void tst_QFile::openStandardStreamsBufferedStreams() QVERIFY(msgHandler.testPassed()); } -#endif void tst_QFile::writeNothing() { diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 485b24dc62..7bdebd1593 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -49,13 +49,13 @@ #ifdef Q_OS_WIN #include <qt_windows.h> #include <qlibrary.h> -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) #include <lm.h> #endif #endif #include <qplatformdefs.h> #include <qdebug.h> -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) #include "../../../network-settings.h" #endif #include <private/qfileinfo_p.h> @@ -141,7 +141,7 @@ inline bool qIsLikelyToBeNfs(int /* handle */) static QString seedAndTemplate() { - qsrand(QDateTime::currentDateTimeUtc().toTime_t()); + qsrand(QDateTime::currentSecsSinceEpoch()); return QDir::tempPath() + "/tst_qfileinfo-XXXXXX"; } @@ -256,7 +256,7 @@ private slots: void refresh(); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void ntfsJunctionPointsAndSymlinks_data(); void ntfsJunctionPointsAndSymlinks(); void brokenShortcut(); @@ -273,7 +273,7 @@ private slots: void detachingOperations(); -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) void owner(); #endif void group(); @@ -354,17 +354,8 @@ void tst_QFileInfo::copy() file.flush(); QTest::qWait(250); -#if defined(Q_OS_WIN) || defined(Q_OS_WINCE) - if (QSysInfo::windowsVersion() & QSysInfo::WV_VISTA || - QSysInfo::windowsVersion() & QSysInfo::WV_CE_based) - file.close(); -#endif -#if defined(Q_OS_WINCE) - // On Windows CE we need to close the file. - // Otherwise the content will be cached and not - // flushed to the storage, although we flushed it - // manually!!! CE has interim cache, we cannot influence. - QTest::qWait(5000); +#if defined(Q_OS_WIN) + file.close(); #endif info3.refresh(); privateInfo3 = getPrivate(info3); @@ -422,12 +413,12 @@ void tst_QFileInfo::isDir_data() QTest::newRow("broken link") << "brokenlink.lnk" << false; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINRT)) QTest::newRow("drive 1") << "c:" << true; QTest::newRow("drive 2") << "c:/" << true; //QTest::newRow("drive 2") << "t:s" << false; #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; @@ -464,13 +455,13 @@ void tst_QFileInfo::isRoot_data() QTest::newRow("simple dir") << m_resourcesDir << false; QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << false; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINRT)) QTest::newRow("drive 1") << "c:" << false; QTest::newRow("drive 2") << "c:/" << true; QTest::newRow("drive 3") << "p:/" << false; #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; @@ -519,7 +510,7 @@ void tst_QFileInfo::exists_data() QTest::newRow("simple dir") << m_resourcesDir << true; QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; @@ -554,7 +545,7 @@ void tst_QFileInfo::absolutePath_data() QTest::addColumn<QString>("filename"); QString drivePrefix; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINRT)) drivePrefix = QDir::currentPath().left(2); QString nonCurrentDrivePrefix = drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:"); @@ -573,7 +564,7 @@ void tst_QFileInfo::absolutePath_data() QTest::newRow("3") << "/usr/local/bin/" << drivePrefix + "/usr/local/bin" << ""; QTest::newRow("/test") << "/test" << drivePrefix + "/" << "test"; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QTest::newRow("c:\\autoexec.bat") << "c:\\autoexec.bat" << "C:/" << "autoexec.bat"; QTest::newRow("c:autoexec.bat") << QDir::currentPath().left(2) + "autoexec.bat" << QDir::currentPath() @@ -606,7 +597,7 @@ void tst_QFileInfo::absFilePath_data() QTest::newRow("relativeFile") << "tmp.txt" << QDir::currentPath() + "/tmp.txt"; QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << QDir::currentPath() + "/" + "temp/tmp.txt"; QString drivePrefix; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if defined(Q_OS_WIN) QString curr = QDir::currentPath(); curr.remove(0, 2); // Make it a absolute path with no drive specifier: \depot\qt-4.2\tests\auto\qfileinfo @@ -787,7 +778,7 @@ void tst_QFileInfo::fileName_data() QTest::newRow("relativeFile") << "tmp.txt" << "tmp.txt"; QTest::newRow("relativeFileInSubDir") << "temp/tmp.txt" << "tmp.txt"; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if defined(Q_OS_WIN) QTest::newRow("absFilePath") << "c:\\home\\andy\\tmp.txt" << "tmp.txt"; QTest::newRow("driveWithNoSlash") << "c:tmp.txt" << "tmp.txt"; #else @@ -1037,7 +1028,7 @@ void tst_QFileInfo::size() void tst_QFileInfo::systemFiles() { -#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) +#if !defined(Q_OS_WIN) || defined(Q_OS_WINRT) QSKIP("This is a Windows only test"); #endif QFileInfo fi("c:\\pagefile.sys"); @@ -1134,11 +1125,7 @@ void tst_QFileInfo::fileTimes_data() void tst_QFileInfo::fileTimes() { -#if defined(Q_OS_WINCE) - int sleepTime = 3000; -#else int sleepTime = 2000; -#endif QFETCH(QString, fileName); if (QFile::exists(fileName)) { QVERIFY(QFile::remove(fileName)); @@ -1146,10 +1133,6 @@ void tst_QFileInfo::fileTimes() QTest::qSleep(sleepTime); { QFile file(fileName); -#if defined(Q_OS_WINCE) - QEXPECT_FAIL("longfile", "No long filenames on WinCE", Abort); - QEXPECT_FAIL("longfile absolutepath", "No long filenames on WinCE", Abort); -#endif QVERIFY(file.open(QFile::WriteOnly | QFile::Text)); #if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) if (qIsLikelyToBeNfs(file.handle())) @@ -1175,7 +1158,7 @@ void tst_QFileInfo::fileTimes() { QFileInfo fileInfo(fileName); // On unix created() returns the same as lastModified(). -#if !defined(Q_OS_UNIX) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_UNIX) QVERIFY(fileInfo.created() < beforeWrite); #endif QVERIFY(fileInfo.lastModified() > beforeWrite); @@ -1187,7 +1170,7 @@ void tst_QFileInfo::fileTimes() } QFileInfo fileInfo(fileName); -#if !defined(Q_OS_UNIX) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_UNIX) QVERIFY(fileInfo.created() < beforeWrite); #endif //In Vista the last-access timestamp is not updated when the file is accessed/touched (by default). @@ -1206,9 +1189,7 @@ void tst_QFileInfo::fileTimes() RegCloseKey(key); } #endif -#if defined(Q_OS_WINCE) - QEXPECT_FAIL("simple", "WinCE only stores date of access data, not the time", Continue); -#elif defined(Q_OS_WINRT) +#if defined(Q_OS_WINRT) QEXPECT_FAIL("", "WinRT does not allow timestamp handling change in the filesystem due to sandboxing", Continue); #elif defined(Q_OS_QNX) QEXPECT_FAIL("", "QNX uses the noatime filesystem option", Continue); @@ -1224,8 +1205,8 @@ void tst_QFileInfo::fileTimes() void tst_QFileInfo::fileTimes_oldFile() { - // This is not supported on WinCE or WinRT -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) + // This is not supported on WinRT +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) // All files are opened in share mode (both read and write). DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; @@ -1323,7 +1304,7 @@ void tst_QFileInfo::isHidden_data() QTest::newRow(qPrintable("drive." + info.path())) << info.path() << false; } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) QVERIFY(QDir("./hidden-directory").exists() || QDir().mkdir("./hidden-directory")); QVERIFY(SetFileAttributesW(reinterpret_cast<LPCWSTR>(QString("./hidden-directory").utf16()),FILE_ATTRIBUTE_HIDDEN)); QTest::newRow("C:/path/to/hidden-directory") << QDir::currentPath() + QString::fromLatin1("/hidden-directory") << true; @@ -1426,7 +1407,7 @@ void tst_QFileInfo::isNativePath() void tst_QFileInfo::refresh() { -#if defined(Q_OS_WINCE) || defined(Q_OS_WIN) +#if defined(Q_OS_WIN) int sleepTime = 3000; #else int sleepTime = 2000; @@ -1449,17 +1430,8 @@ void tst_QFileInfo::refresh() QCOMPARE(info.lastModified(), lastModified); QCOMPARE(info.size(), qint64(7)); -#if defined(Q_OS_WIN) || defined(Q_OS_WINCE) - if (QSysInfo::windowsVersion() & QSysInfo::WV_VISTA || - QSysInfo::windowsVersion() & QSysInfo::WV_CE_based) - file.close(); -#endif -#if defined(Q_OS_WINCE) - // On Windows CE we need to close the file. - // Otherwise the content will be cached and not - // flushed to the storage, although we flushed it - // manually!!! CE has interim cache, we cannot influence. - QTest::qWait(5000); +#if defined(Q_OS_WIN) + file.close(); #endif info.refresh(); QCOMPARE(info.size(), qint64(13)); @@ -1472,7 +1444,7 @@ void tst_QFileInfo::refresh() QCOMPARE(info2.size(), info.size()); } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() { QTest::addColumn<QString>("path"); @@ -1646,11 +1618,7 @@ void tst_QFileInfo::isWritable() tempfile.remove(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -#ifdef Q_OS_WINCE - QFileInfo fi("\\Windows\\wince.nls"); -#else QFileInfo fi("c:\\pagefile.sys"); -#endif QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QVERIFY(!fi.isWritable()); #endif @@ -1826,8 +1794,7 @@ void tst_QFileInfo::detachingOperations() QVERIFY(!info1.caching()); } -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) -#if defined (Q_OS_WIN) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) BOOL IsUserAdmin() { BOOL b; @@ -1848,14 +1815,14 @@ BOOL IsUserAdmin() return(b); } -#endif -#if defined(Q_OS_WIN) QT_BEGIN_NAMESPACE extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; QT_END_NAMESPACE -#endif +#endif // Q_OS_WIN && !Q_OS_WINRT + +#ifndef Q_OS_WINRT void tst_QFileInfo::owner() { QString userName; @@ -1917,7 +1884,7 @@ void tst_QFileInfo::owner() qt_ntfs_permission_lookup = 0; #endif } -#endif +#endif // !Q_OS_WINRT void tst_QFileInfo::group() { diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 97b5e74bc2..0ee7599b2c 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -148,12 +148,7 @@ void tst_QFileSystemWatcher::basicTest() // resolution of the modification time is system dependent, but it's at most 1 second when using // the polling engine. I've heard rumors that FAT32 has a 2 second resolution. So, we have to // wait a bit before we can modify the file (hrmph)... -#ifndef Q_OS_WINCE QTest::qWait(2000); -#else - // WinCE is always a little bit slower. Give it a little bit more time - QTest::qWait(5000); -#endif testFile.open(QIODevice::WriteOnly | QIODevice::Append); testFile.write(QByteArray("world")); @@ -311,9 +306,6 @@ void tst_QFileSystemWatcher::watchDirectory() QVERIFY(temporaryDir.rmdir(testDirName)); // waiting max 5 seconds for notification for directory removal to trigger -#ifdef Q_OS_WINCE - QEXPECT_FAIL("poller", "Directory does not get updated on file removal(See #137910)", Abort); -#endif QTRY_COMPARE(changedSpy.count(), 2); QCOMPARE(changedSpy.at(0).count(), 1); QCOMPARE(changedSpy.at(1).count(), 1); @@ -555,9 +547,6 @@ void tst_QFileSystemWatcher::watchFileAndItsDirectory() QEXPECT_FAIL("", "See QTBUG-30943", Continue); #endif QCOMPARE(fileChangedSpyCount, 0); -#ifdef Q_OS_WINCE - QEXPECT_FAIL("poller", "Directory does not get updated on file removal(See #137910)", Abort); -#endif QCOMPARE(dirChangedSpy.count(), 1); dirChangedSpy.clear(); diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index 30eaa5aab9..5cb532f76b 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -100,9 +100,6 @@ void tst_QIODevice::getSetCheck() //---------------------------------------------------------------------------------- void tst_QIODevice::constructing_QTcpSocket() { -#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST) - QSKIP("Networking tests in a WinCE emulator are unstable"); -#endif if (!QtNetworkSettings::verifyTestNetworkSettings()) QSKIP("No network test server available"); @@ -205,9 +202,6 @@ void tst_QIODevice::read_QByteArray() //-------------------------------------------------------------------- void tst_QIODevice::unget() { -#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST) - QSKIP("Networking tests in a WinCE emulator are unstable"); -#endif #if defined(Q_OS_MAC) QSKIP("The unget network test is unstable on Mac. See QTBUG-39983."); #endif diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp index 2e5cfb1053..b21701f341 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp @@ -34,7 +34,7 @@ #include <qsysinfo.h> #if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) #include <unistd.h> -#elif defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#elif defined(Q_OS_WIN) && !defined(Q_OS_WINRT) # include <qt_windows.h> #endif @@ -281,7 +281,7 @@ void tst_QLockFile::staleLockFromCrashedProcessReusedPid() { #if defined(QT_NO_PROCESS) QSKIP("This test requires QProcess support"); -#elif defined(Q_OS_WINRT) || defined(Q_OS_WINCE) || defined(Q_OS_IOS) +#elif defined(Q_OS_WINRT) || defined(QT_PLATFORM_UIKIT) QSKIP("We cannot retrieve information about other processes on this platform."); #else const QString fileName = dir.path() + "/staleLockFromCrashedProcessReusedPid"; @@ -455,7 +455,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(ProcessProperties) static inline ProcessProperties processProperties() { ProcessProperties result; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) HANDLE processToken = NULL; if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &processToken)) { DWORD elevation; // struct containing a DWORD, not present in some MinGW headers. @@ -484,7 +484,7 @@ void tst_QLockFile::noPermissionsWindows() { // Windows: Do the permissions test in a system directory in which // files cannot be created. -#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) +#if !defined(Q_OS_WIN) || defined(Q_OS_WINRT) QSKIP("This test is for desktop Windows only"); #endif #ifdef Q_OS_WIN diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro index 6eb72343bc..7b83d5dbe8 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro @@ -4,4 +4,4 @@ TARGET = tst_qlockfile SOURCES += tst_qlockfile.cpp QT = core testlib concurrent -win32:!wince:!winrt:LIBS += -ladvapi32 +win32:!winrt:LIBS += -ladvapi32 diff --git a/tests/auto/corelib/io/qprocess/qprocess.pri b/tests/auto/corelib/io/qprocess/qprocess.pri index a43c823846..d5a7532ee1 100644 --- a/tests/auto/corelib/io/qprocess/qprocess.pri +++ b/tests/auto/corelib/io/qprocess/qprocess.pri @@ -10,13 +10,12 @@ SUBPROGRAMS = \ testProcessDeadWhileReading \ testProcessEOF \ testExitCodes \ + testForwarding \ testGuiProcess \ testDetached \ fileWriterProcess \ testSetWorkingDirectory \ testSoftExit -!contains(QMAKE_PLATFORM, wince): SUBPROGRAMS += testForwarding - !qtHaveModule(widgets): SUBPROGRAMS -= \ testGuiProcess diff --git a/tests/auto/corelib/io/qprocess/qprocess.pro b/tests/auto/corelib/io/qprocess/qprocess.pro index 6ba54b1e92..3867ac5741 100644 --- a/tests/auto/corelib/io/qprocess/qprocess.pro +++ b/tests/auto/corelib/io/qprocess/qprocess.pro @@ -8,7 +8,7 @@ SUBDIRS += testProcessSpacesArgs/nospace.pro \ testProcessSpacesArgs/twospaces.pro \ testSpaceInName -win32:!wince* { +win32 { SUBDIRS += \ testProcessEchoGui \ testSetNamedPipeHandleState diff --git a/tests/auto/corelib/io/qprocess/testProcessEcho/main.cpp b/tests/auto/corelib/io/qprocess/testProcessEcho/main.cpp index 19f30de552..e18e48e516 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEcho/main.cpp +++ b/tests/auto/corelib/io/qprocess/testProcessEcho/main.cpp @@ -31,9 +31,6 @@ int main() { -#if defined(_WIN32_WCE) && defined(_X86_) - return 0; -#else int c; while ((c = fgetc(stdin)) != -1) { if (c == '\0') @@ -42,5 +39,4 @@ int main() fflush(stdout); } return 0; -#endif } diff --git a/tests/auto/corelib/io/qprocess/testProcessEnvironment/main.cpp b/tests/auto/corelib/io/qprocess/testProcessEnvironment/main.cpp index 4de359d83f..9f13f5c00f 100644 --- a/tests/auto/corelib/io/qprocess/testProcessEnvironment/main.cpp +++ b/tests/auto/corelib/io/qprocess/testProcessEnvironment/main.cpp @@ -31,10 +31,6 @@ int main(int argc, char **argv) { -#if defined(_WIN32_WCE) - // no environment in Windows CE - return 0; -#else if (argc == 1) return 1; @@ -44,5 +40,4 @@ int main(int argc, char **argv) return 0; } return 1; -#endif } diff --git a/tests/auto/corelib/io/qprocess/testProcessOutput/main.cpp b/tests/auto/corelib/io/qprocess/testProcessOutput/main.cpp index 07409166f2..4934708153 100644 --- a/tests/auto/corelib/io/qprocess/testProcessOutput/main.cpp +++ b/tests/auto/corelib/io/qprocess/testProcessOutput/main.cpp @@ -31,11 +31,7 @@ int main() { -#if defined(_WIN32_WCE) - for (int i=0; i<240; i++) { -#else //fprintf Output is very slow on Windows CE for (int i=0; i<10240; i++) { -#endif fprintf(stdout, "%d -this is a number\n", i); fflush(stderr); } diff --git a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/main.cpp b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/main.cpp index 494d8147a7..0d40a9b83c 100644 --- a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/main.cpp +++ b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/main.cpp @@ -31,21 +31,10 @@ int main(int argc, char ** argv) { -#if defined(WINCE) || defined(_WIN32_WCE) - // No pipes on this "OS" - FILE* file = fopen("\\temp\\qprocess_args_test.txt","w+"); - for (int i = 0; i < argc; ++i) { - if (i) - fprintf(file, "|"); - fprintf(file, argv[i]); - } - fclose(file); -#else for (int i = 0; i < argc; ++i) { if (i) printf("|"); printf("%s", argv[i]); } -#endif return 0; } diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro index d19a631cae..80e8bcad98 100644 --- a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro +++ b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro @@ -1,6 +1,6 @@ win32 { SOURCES = main_win.cpp - !wince: LIBS += -luser32 + LIBS += -luser32 } unix { SOURCES = main_unix.cpp diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 59f271d727..3f3533c9a1 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -64,7 +64,6 @@ private slots: void startDetached(); void crashTest(); void crashTest2(); -#ifndef Q_OS_WINCE void echoTest_data(); void echoTest(); void echoTest2(); @@ -110,7 +109,6 @@ private slots: void discardUnwantedOutput(); void setWorkingDirectory(); void setNonExistentWorkingDirectory(); -#endif // not Q_OS_WINCE void exitStatus_data(); void exitStatus(); @@ -154,11 +152,9 @@ protected slots: void readFromProcess(); void exitLoopSlot(); void processApplicationEvents(); -#ifndef Q_OS_WINCE void restartProcess(); void waitForReadyReadInAReadyReadSlotSlot(); void waitForBytesWrittenInABytesWrittenSlotSlot(); -#endif private: qint64 bytesAvailable; @@ -406,8 +402,6 @@ void tst_QProcess::crashTest2() QCOMPARE(process.exitStatus(), QProcess::CrashExit); } -#ifndef Q_OS_WINCE -//Reading and writing to a process is not supported on Qt/CE void tst_QProcess::echoTest_data() { QTest::addColumn<QByteArray>("input"); @@ -462,7 +456,6 @@ void tst_QProcess::echoTest() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif void tst_QProcess::exitLoopSlot() { @@ -474,8 +467,6 @@ void tst_QProcess::processApplicationEvents() QCoreApplication::processEvents(); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::echoTest2() { @@ -523,10 +514,8 @@ void tst_QProcess::echoTest2() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -// Reading and writing to a process is not supported on Qt/CE +#if defined(Q_OS_WIN) void tst_QProcess::echoTestGui() { QProcess process; @@ -555,10 +544,9 @@ void tst_QProcess::testSetNamedPipeHandleState() QCOMPARE(process.exitCode(), 0); QCOMPARE(process.exitStatus(), QProcess::NormalExit); } -#endif // !Q_OS_WINCE && Q_OS_WIN +#endif // Q_OS_WIN -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -// Batch files are not supported on Windows CE +#if defined(Q_OS_WIN) void tst_QProcess::batFiles_data() { QTest::addColumn<QString>("batFile"); @@ -585,7 +573,7 @@ void tst_QProcess::batFiles() QVERIFY(proc.readAll().startsWith(output)); } -#endif // !Q_OS_WINCE && Q_OS_WIN +#endif // Q_OS_WIN void tst_QProcess::exitStatus_data() { @@ -627,8 +615,6 @@ void tst_QProcess::exitStatus() } } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::loopBackTest() { @@ -649,10 +635,7 @@ void tst_QProcess::loopBackTest() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::readTimeoutAndThenCrash() { @@ -683,7 +666,6 @@ void tst_QProcess::readTimeoutAndThenCrash() QCOMPARE(spy2.count(), 1); QCOMPARE(*static_cast<const QProcess::ProcessError *>(spy2.at(0).at(0).constData()), QProcess::Crashed); } -#endif void tst_QProcess::waitForFinished() { @@ -694,9 +676,6 @@ void tst_QProcess::waitForFinished() QVERIFY(process.waitForFinished()); QCOMPARE(process.exitStatus(), QProcess::NormalExit); -#if defined (Q_OS_WINCE) - QEXPECT_FAIL("", "Reading and writing to a process is not supported on Qt/CE", Continue); -#endif QString output = process.readAll(); QCOMPARE(output.count("\n"), 10*1024); @@ -705,8 +684,6 @@ void tst_QProcess::waitForFinished() QCOMPARE(process.error(), QProcess::FailedToStart); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::deadWhileReading() { QProcess process; @@ -724,10 +701,7 @@ void tst_QProcess::deadWhileReading() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::restartProcessDeadlock() { @@ -757,10 +731,7 @@ void tst_QProcess::restartProcess() QVERIFY(process); process->start("testProcessEcho/testProcessEcho"); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::closeWriteChannel() { QByteArray testData("Data to read"); @@ -789,10 +760,7 @@ void tst_QProcess::closeWriteChannel() QCOMPARE(more.exitStatus(), QProcess::NormalExit); QCOMPARE(more.exitCode(), 0); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE" void tst_QProcess::closeReadChannel() { for (int i = 0; i < 10; ++i) { @@ -822,10 +790,7 @@ void tst_QProcess::closeReadChannel() QCOMPARE(proc.exitCode(), 0); } } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::openModes() { QProcess proc; @@ -866,10 +831,7 @@ void tst_QProcess::openModes() QVERIFY(!proc.isWritable()); QCOMPARE(proc.state(), QProcess::NotRunning); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() { @@ -903,17 +865,12 @@ void tst_QProcess::emitReadyReadOnlyWhenNewDataArrives() QCOMPARE(proc.exitStatus(), QProcess::NormalExit); QCOMPARE(proc.exitCode(), 0); } -#endif void tst_QProcess::hardExit() { QProcess proc; -#if defined(Q_OS_WINCE) - proc.start("testSoftExit/testSoftExit"); -#else proc.start("testProcessEcho/testProcessEcho"); -#endif QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString())); @@ -940,9 +897,7 @@ void tst_QProcess::softExit() proc.start("testSoftExit/testSoftExit"); QVERIFY(proc.waitForStarted(10000)); -#if !defined(Q_OS_WINCE) QVERIFY(proc.waitForReadyRead(10000)); -#endif QVERIFY(proc.processId() > 0); @@ -953,8 +908,6 @@ void tst_QProcess::softExit() QCOMPARE(int(proc.error()), int(QProcess::UnknownError)); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE class SoftExitProcess : public QProcess { Q_OBJECT @@ -1076,10 +1029,7 @@ void tst_QProcess::softExitInSlots() QTRY_VERIFY_WITH_TIMEOUT(proc.waitedForFinished, 10000); QCOMPARE(proc.state(), QProcess::NotRunning); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::mergedChannels() { QProcess process; @@ -1102,10 +1052,6 @@ void tst_QProcess::mergedChannels() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif - -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::forwardedChannels_data() { @@ -1158,10 +1104,7 @@ void tst_QProcess::forwardedChannels() QCOMPARE(process.readAllStandardOutput(), outdata); QCOMPARE(process.readAllStandardError(), errdata); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::atEnd() { QProcess process; @@ -1183,7 +1126,6 @@ void tst_QProcess::atEnd() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif class TestThread : public QThread { @@ -1205,9 +1147,7 @@ protected: process.start("testProcessEcho/testProcessEcho"); -#if !defined(Q_OS_WINCE) QCOMPARE(process.write("abc\0", 4), qint64(4)); -#endif exitCode = exec(); } @@ -1256,8 +1196,6 @@ void tst_QProcess::processesInMultipleThreads() } } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForFinishedWithTimeout() { QProcess process; @@ -1271,10 +1209,7 @@ void tst_QProcess::waitForFinishedWithTimeout() QVERIFY(process.waitForFinished()); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlot() { QProcess process; @@ -1300,10 +1235,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlot() QCOMPARE(process.exitCode(), 0); QVERIFY(process.bytesAvailable() > bytesAvailable); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() { QProcess *process = qobject_cast<QProcess *>(sender()); @@ -1313,10 +1245,7 @@ void tst_QProcess::waitForReadyReadInAReadyReadSlotSlot() QVERIFY(process->waitForReadyRead(5000)); QTestEventLoop::instance().exitLoop(); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() { QProcess process; @@ -1339,10 +1268,7 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() { QProcess *process = qobject_cast<QProcess *>(sender()); @@ -1351,7 +1277,6 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlotSlot() QVERIFY(process->waitForBytesWritten(5000)); QTestEventLoop::instance().exitLoop(); } -#endif void tst_QProcess::spaceArgsTest_data() { @@ -1430,14 +1355,12 @@ void tst_QProcess::spaceArgsTest() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); -#if !defined(Q_OS_WINCE) QStringList actual = QString::fromLatin1(process.readAll()).split("|"); QVERIFY(!actual.isEmpty()); // not interested in the program name, it might be different. actual.removeFirst(); QCOMPARE(actual, args); -#endif if (program.contains(QLatin1Char(' '))) program = QLatin1Char('"') + program + QLatin1Char('"'); @@ -1454,14 +1377,12 @@ void tst_QProcess::spaceArgsTest() QVERIFY2(started, errorMessage.constData()); QVERIFY(process.waitForFinished(5000)); -#if !defined(Q_OS_WINCE) actual = QString::fromLatin1(process.readAll()).split("|"); QVERIFY(!actual.isEmpty()); // not interested in the program name, it might be different. actual.removeFirst(); QCOMPARE(actual, args); -#endif } } @@ -1482,26 +1403,12 @@ void tst_QProcess::nativeArguments() QCOMPARE(proc.exitStatus(), QProcess::NormalExit); QCOMPARE(proc.exitCode(), 0); -#if defined(Q_OS_WINCE) - // WinCE test outputs to a file, so check that - FILE* file = fopen("\\temp\\qprocess_args_test.txt","r"); - QVERIFY(file); - char buf[256]; - fgets(buf, 256, file); - fclose(file); - QStringList actual = QString::fromLatin1(buf).split(QLatin1Char('|')); -#else QStringList actual = QString::fromLatin1(proc.readAll()).split(QLatin1Char('|')); -#endif QVERIFY(!actual.isEmpty()); // not interested in the program name, it might be different. actual.removeFirst(); QStringList expected; -#if defined(Q_OS_WINCE) - expected << "hello" << "kitty," << "\"*\"!"; // Weird, weird ... -#else expected << "hello" << "kitty," << "*!"; -#endif QCOMPARE(actual, expected); } @@ -1706,8 +1613,6 @@ void tst_QProcess::failToStartEmptyArgs() QCOMPARE(process.error(), QProcess::FailedToStart); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::removeFileWhileProcessIsRunning() { QFile file(m_temporaryDir.path() + QLatin1String("/removeFile.txt")); @@ -1725,9 +1630,7 @@ void tst_QProcess::removeFileWhileProcessIsRunning() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif -#ifndef Q_OS_WINCE -// OS doesn't support environment variables + void tst_QProcess::setEnvironment_data() { QTest::addColumn<QString>("name"); @@ -1802,9 +1705,7 @@ void tst_QProcess::setEnvironment() QCOMPARE(process.readAll(), value.toLocal8Bit()); } } -#endif -#ifndef Q_OS_WINCE -// OS doesn't support environment variables + void tst_QProcess::setProcessEnvironment_data() { setEnvironment_data(); @@ -1842,25 +1743,16 @@ void tst_QProcess::setProcessEnvironment() QCOMPARE(process.readAll(), value.toLocal8Bit()); } } -#endif void tst_QProcess::systemEnvironment() { -#if defined (Q_OS_WINCE) - // there is no concept of system variables on Windows CE as there is no console - QVERIFY(QProcess::systemEnvironment().isEmpty()); - QVERIFY(QProcessEnvironment::systemEnvironment().isEmpty()); -#else QVERIFY(!QProcess::systemEnvironment().isEmpty()); QVERIFY(!QProcessEnvironment::systemEnvironment().isEmpty()); QVERIFY(QProcessEnvironment::systemEnvironment().contains("PATH")); QVERIFY(!QProcess::systemEnvironment().filter(QRegExp("^PATH=", Qt::CaseInsensitive)).isEmpty()); -#endif } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::spaceInName() { QProcess process; @@ -1871,7 +1763,6 @@ void tst_QProcess::spaceInName() QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); } -#endif void tst_QProcess::lockupsInStartDetached() { @@ -1886,8 +1777,6 @@ void tst_QProcess::lockupsInStartDetached() QProcess::startDetached("yjhbrty"); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::atEnd2() { QProcess process; @@ -1902,7 +1791,6 @@ void tst_QProcess::atEnd2() } QCOMPARE(lines.size(), 7); } -#endif void tst_QProcess::waitForReadyReadForNonexistantProcess() { @@ -1932,8 +1820,6 @@ void tst_QProcess::waitForReadyReadForNonexistantProcess() QCOMPARE(finishedSpy2.count(), 0); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardInputFile() { static const char data[] = "A bunch\1of\2data\3\4\5\6\7..."; @@ -1961,10 +1847,7 @@ void tst_QProcess::setStandardInputFile() all = process2.readAll(); QCOMPARE(all.size(), 0); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputFile_data() { QTest::addColumn<int>("channelToTest"); @@ -2082,10 +1965,7 @@ void tst_QProcess::setStandardOutputFileAndWaitForBytesWritten() QCOMPARE(all, QByteArray::fromRawData(testdata, sizeof testdata - 1)); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::setStandardOutputProcess_data() { QTest::addColumn<bool>("merged"); @@ -2126,10 +2006,7 @@ void tst_QProcess::setStandardOutputProcess() else QCOMPARE(all, QByteArray("HHeelllloo,, WWoorrlldd")); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::fileWriterProcess() { const QByteArray line = QByteArrayLiteral(" -- testing testing 1 2 3\n"); @@ -2163,16 +2040,11 @@ void tst_QProcess::fileWriterProcess() QCOMPARE(QFile(fileName).size(), qint64(stdinStr.size())); } while (stopWatch.elapsed() < 3000); } -#endif void tst_QProcess::detachedWorkingDirectoryAndPid() { qint64 pid; -#ifdef Q_OS_WINCE - QTest::qSleep(1000); -#endif - QFile infoFile(m_temporaryDir.path() + QLatin1String("/detachedinfo.txt")); if (infoFile.exists()) QVERIFY(infoFile.remove()); @@ -2209,8 +2081,6 @@ void tst_QProcess::detachedWorkingDirectoryAndPid() QCOMPARE(actualPid, pid); } -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::switchReadChannels() { const char data[] = "ABCD"; @@ -2239,10 +2109,7 @@ void tst_QProcess::switchReadChannels() process.setReadChannel(QProcess::StandardOutput); QCOMPARE(process.read(1), QByteArray("D")); } -#endif -#ifndef Q_OS_WINCE -// Reading and writing to a process is not supported on Qt/CE void tst_QProcess::discardUnwantedOutput() { QProcess process; @@ -2260,11 +2127,8 @@ void tst_QProcess::discardUnwantedOutput() process.setReadChannel(QProcess::StandardError); QCOMPARE(process.bytesAvailable(), Q_INT64_C(0)); } -#endif -#ifndef Q_OS_WINCE // Q_OS_WIN - setWorkingDirectory will chdir before starting the process on unices -// Windows CE does not support working directory logic void tst_QProcess::setWorkingDirectory() { QProcess process; @@ -2300,7 +2164,6 @@ void tst_QProcess::setNonExistentWorkingDirectory() QVERIFY2(process.errorString().startsWith("chdir:"), process.errorString().toLocal8Bit()); #endif } -#endif void tst_QProcess::startFinishStartFinish() { @@ -2310,11 +2173,9 @@ void tst_QProcess::startFinishStartFinish() QCOMPARE(process.state(), QProcess::NotRunning); process.start("testProcessOutput/testProcessOutput"); -#if !defined(Q_OS_WINCE) QVERIFY(process.waitForReadyRead(10000)); QCOMPARE(QString::fromLatin1(process.readLine().trimmed()), QString("0 -this is a number")); -#endif if (process.state() != QProcess::NotRunning) { QVERIFY(process.waitForFinished(10000)); QCOMPARE(process.exitStatus(), QProcess::NormalExit); diff --git a/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp b/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp index a4a5d5b0c7..af5078a3dc 100644 --- a/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp +++ b/tests/auto/corelib/io/qprocessenvironment/tst_qprocessenvironment.cpp @@ -44,9 +44,7 @@ private slots: void caseSensitivity(); void systemEnvironment(); -#ifndef Q_OS_WINCE void putenv(); -#endif }; void tst_QProcessEnvironment::operator_eq() @@ -257,12 +255,6 @@ void tst_QProcessEnvironment::systemEnvironment() QVERIFY(nonexistant.isNull()); -#ifdef Q_OS_WINCE - // Windows CE has no environment - QVERIFY(path.isEmpty()); - QVERIFY(!system.contains("PATH")); - QVERIFY(system.isEmpty()); -#else // all other system have environments if (path.isEmpty()) QFAIL("Could not find the PATH environment variable -- please correct the test environment"); @@ -272,18 +264,15 @@ void tst_QProcessEnvironment::systemEnvironment() QVERIFY(!system.contains(envname)); -# ifdef Q_OS_WIN +#ifdef Q_OS_WIN // check case-insensitive too QVERIFY(system.contains("path")); QCOMPARE(system.value("path"), QString::fromLocal8Bit(path)); QVERIFY(!system.contains(QString(envname).toLower())); -# endif #endif } -#ifndef Q_OS_WINCE -//Windows CE has no environment void tst_QProcessEnvironment::putenv() { static const char envname[] = "WE_RE_SETTING_THIS_ENVIRONMENT_VARIABLE"; @@ -317,7 +306,6 @@ void tst_QProcessEnvironment::putenv() QCOMPARE(eAfter.value(lower), QString("Hello, World")); # endif } -#endif QTEST_MAIN(tst_QProcessEnvironment) diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 561ab193c6..7fdd00876f 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -55,6 +55,7 @@ private slots: void searchPath(); void doubleSlashInRoot(); void setLocale(); + void lastModified(); private: const QString m_runtimeResourceRcc; @@ -489,6 +490,20 @@ void tst_QResourceEngine::setLocale() QLocale::setDefault(QLocale::system()); } +void tst_QResourceEngine::lastModified() +{ + { + QFileInfo fi(":/"); + QVERIFY(fi.exists()); + QVERIFY2(!fi.lastModified().isValid(), qPrintable(fi.lastModified().toString())); + } + { + QFileInfo fi(":/search_file.txt"); + QVERIFY(fi.exists()); + QVERIFY(fi.lastModified().isValid()); + } +} + QTEST_MAIN(tst_QResourceEngine) #include "tst_qresourceengine.moc" diff --git a/tests/auto/corelib/io/qsettings/qsettings.pro b/tests/auto/corelib/io/qsettings/qsettings.pro index 3aa5ea6766..7da73a549a 100644 --- a/tests/auto/corelib/io/qsettings/qsettings.pro +++ b/tests/auto/corelib/io/qsettings/qsettings.pro @@ -3,6 +3,7 @@ TARGET = tst_qsettings QT = core-private gui testlib SOURCES = tst_qsettings.cpp RESOURCES += qsettings.qrc +INCLUDEPATH += $$PWD/../../kernel/qmetatype win32-msvc*:LIBS += advapi32.lib DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index ed298bfafa..dadf4b612e 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -41,6 +41,10 @@ #include <QtCore/QSysInfo> #include <QtGui/QKeySequence> +#include <QtCore> +#include <QtGui> +#include "tst_qmetatype.h" + #include <cctype> #include <stdlib.h> #if defined(Q_OS_WIN) && defined(Q_CC_GNU) @@ -54,6 +58,10 @@ #include <unistd.h> #endif +#if defined(Q_OS_DARWIN) +#include <CoreFoundation/CoreFoundation.h> +#endif + Q_DECLARE_METATYPE(QSettings::Format) #ifndef QSETTINGS_P_H_VERSION @@ -72,7 +80,19 @@ static inline bool canWriteNativeSystemSettings() else qErrnoWarning(result, "RegOpenKeyEx failed"); return result == ERROR_SUCCESS; -#else // Q_OS_WIN && !Q_OS_WINRT +#elif defined(Q_OS_DARWIN) + CFStringRef key = CFSTR("canWriteNativeSystemSettings"); + #define ANY_APP_USER_AND_HOST kCFPreferencesAnyApplication, kCFPreferencesAnyUser, kCFPreferencesAnyHost + CFPreferencesSetValue(key, CFSTR("true"), ANY_APP_USER_AND_HOST); + if (CFPreferencesSynchronize(ANY_APP_USER_AND_HOST)) { + // Cleanup + CFPreferencesSetValue(key, 0, ANY_APP_USER_AND_HOST); + CFPreferencesSynchronize(ANY_APP_USER_AND_HOST); + return true; + } else { + return false; + } +#else return true; #endif } @@ -149,6 +169,8 @@ private slots: void testNormalizedKey(); void testVariantTypes_data(); void testVariantTypes(); + void testMetaTypes_data(); + void testMetaTypes(); #endif void rainersSyncBugOnMac_data(); void rainersSyncBugOnMac(); @@ -1105,6 +1127,102 @@ void tst_QSettings::setValue() } #ifdef QT_BUILD_INTERNAL + +template<int MetaTypeId> +static void testMetaTypesHelper(QSettings::Format format) +{ + typedef typename MetaEnumToType<MetaTypeId>::Type Type; + const char *key = QMetaType::typeName(MetaTypeId); + Type *value = TestValueFactory<MetaTypeId>::create(); + QVariant inputVariant = QVariant::fromValue(*value); + + static const QSettings::Scope scope = QSettings::UserScope; + static const QString organization("example.org"); + static const QString applicationName("FooApp"); + + { + QSettings settings(format, scope, organization, applicationName); + settings.setValue(key, inputVariant); + } + + QConfFile::clearCache(); + + { + QSettings settings(format, scope, organization, applicationName); + QVariant outputVariant = settings.value(key); + if (MetaTypeId != QMetaType::QVariant) + QVERIFY(outputVariant.canConvert(MetaTypeId)); + if (outputVariant.type() != inputVariant.type()) + qWarning() << "type mismatch between" << inputVariant << "and" << outputVariant; + QCOMPARE(qvariant_cast<Type >(outputVariant), *value); + } + + delete value; +} + +#define FOR_EACH_NONSUPPORTED_METATYPE(F)\ + F(Void) \ + F(Nullptr) \ + F(QObjectStar) \ + F(QModelIndex) \ + F(QJsonObject) \ + F(QJsonValue) \ + F(QJsonArray) \ + F(QJsonDocument) \ + F(QPersistentModelIndex) \ + +#define EXCLUDE_NON_SUPPORTED_METATYPES(MetaTypeName) \ +template<> void testMetaTypesHelper<QMetaType::MetaTypeName>(QSettings::Format) \ +{ \ + QSKIP("This metatype is not supported by QSettings."); \ +} +FOR_EACH_NONSUPPORTED_METATYPE(EXCLUDE_NON_SUPPORTED_METATYPES) +#undef EXCLUDE_NON_SUPPORTED_METATYPES + +void tst_QSettings::testMetaTypes_data() +{ + QTest::addColumn<QSettings::Format>("format"); + QTest::addColumn<int>("type"); + +#define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ + { \ + const char *formatName = QMetaEnum::fromType<QSettings::Format>().valueToKey(formats[i]); \ + const char *typeName = QMetaType::typeName(QMetaType::MetaTypeName); \ + QTest::newRow(QString("%1:%2").arg(formatName).arg(typeName).toLatin1().constData()) \ + << QSettings::Format(formats[i]) << int(QMetaType::MetaTypeName); \ + } + int formats[] = { QSettings::NativeFormat, QSettings::IniFormat }; + for (int i = 0; i < int(sizeof(formats) / sizeof(int)); ++i) { + FOR_EACH_CORE_METATYPE(ADD_METATYPE_TEST_ROW) + } +#undef ADD_METATYPE_TEST_ROW +} + +typedef void (*TypeTestFunction)(QSettings::Format); + +void tst_QSettings::testMetaTypes() +{ + struct TypeTestFunctionGetter + { + static TypeTestFunction get(int type) + { + switch (type) { +#define RETURN_CREATE_FUNCTION(MetaTypeName, MetaTypeId, RealType) \ + case QMetaType::MetaTypeName: \ + return testMetaTypesHelper<QMetaType::MetaTypeName>; +FOR_EACH_CORE_METATYPE(RETURN_CREATE_FUNCTION) +#undef RETURN_CREATE_FUNCTION + } + return 0; + } + }; + + QFETCH(QSettings::Format, format); + QFETCH(int, type); + + TypeTestFunctionGetter::get(type)(format); +} + void tst_QSettings::testVariantTypes_data() { populateWithFormats(); @@ -1569,7 +1687,7 @@ void tst_QSettings::sync() // Now "some other app" will change other.software.org.ini QString userConfDir = settingsPath("__user__") + QDir::separator(); -#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if !defined(Q_OS_WINRT) unlink((userConfDir + "other.software.org.ini").toLatin1()); rename((userConfDir + "software.org.ini").toLatin1(), (userConfDir + "other.software.org.ini").toLatin1()); @@ -1778,10 +1896,10 @@ void tst_QSettings::testChildKeysAndGroups() void tst_QSettings::testUpdateRequestEvent() { -#ifdef Q_OS_WINRT const QString oldCur = QDir::currentPath(); - QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); -#endif + QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + QVERIFY(QDir::root().mkpath(dataLocation)); + QDir::setCurrent(dataLocation); QFile::remove("foo"); QVERIFY(!QFile::exists("foo")); @@ -1809,9 +1927,7 @@ void tst_QSettings::testUpdateRequestEvent() QTRY_COMPARE(QFileInfo("foo").size(), qint64(0)); -#ifdef Q_OS_WINRT QDir::setCurrent(oldCur); -#endif } const int NumIterations = 5; @@ -2110,13 +2226,10 @@ void tst_QSettings::fromFile() { QFETCH(QSettings::Format, format); - // Sandboxed WinRT applications cannot write into the - // application directory. Hence reset the current - // directory -#ifdef Q_OS_WINRT const QString oldCur = QDir::currentPath(); - QDir::setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)); -#endif + QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation); + QVERIFY(QDir::root().mkpath(dataLocation)); + QDir::setCurrent(dataLocation); QFile::remove("foo"); QVERIFY(!QFile::exists("foo")); @@ -2165,9 +2278,8 @@ void tst_QSettings::fromFile() QCOMPARE(settings1.value("gamma/foo.bar").toInt(), 4); QCOMPARE(settings1.allKeys().size(), 3); } -#ifdef Q_OS_WINRT + QDir::setCurrent(oldCur); -#endif } #ifdef QT_BUILD_INTERNAL @@ -2902,29 +3014,21 @@ void tst_QSettings::isWritable() QSettings s2(format, QSettings::SystemScope, "software.org", "Something Different"); QSettings s3(format, QSettings::SystemScope, "foo.org", "Something Different"); - if (s1.contains("foo")) { + if (s1.status() == QSettings::NoError && s1.contains("foo")) { #if defined(Q_OS_MACX) - if (QSysInfo::macVersion() >= QSysInfo::MV_10_9) { - QVERIFY(s1.isWritable()); - if (format == QSettings::NativeFormat) { - QVERIFY(!s2.isWritable()); - QVERIFY(!s3.isWritable()); - } else { - QVERIFY(s2.isWritable()); - QVERIFY(s3.isWritable()); - } - } else if (QSysInfo::macVersion() >= QSysInfo::MV_10_7 && - format == QSettings::NativeFormat) { - QVERIFY(!s1.isWritable()); + QVERIFY(s1.isWritable()); + if (format == QSettings::NativeFormat) { QVERIFY(!s2.isWritable()); QVERIFY(!s3.isWritable()); - } else -#endif - { - QVERIFY(s1.isWritable()); + } else { QVERIFY(s2.isWritable()); QVERIFY(s3.isWritable()); } +#else + QVERIFY(s1.isWritable()); + QVERIFY(s2.isWritable()); + QVERIFY(s3.isWritable()); +#endif } else { QVERIFY(!s1.isWritable()); QVERIFY(!s2.isWritable()); @@ -3359,9 +3463,9 @@ void tst_QSettings::rainersSyncBugOnMac() { QFETCH(QSettings::Format, format); -#if defined(Q_OS_OSX) || defined(Q_OS_WINRT) +#if defined(Q_OS_DARWIN) || defined(Q_OS_WINRT) if (format == QSettings::NativeFormat) - QSKIP("OSX does not support direct reads from and writes to .plist files, due to caching and background syncing. See QTBUG-34899."); + QSKIP("Apple OSes do not support direct reads from and writes to .plist files, due to caching and background syncing. See QTBUG-34899."); #endif QString fileName; diff --git a/tests/auto/corelib/io/qstorageinfo/BLACKLIST b/tests/auto/corelib/io/qstorageinfo/BLACKLIST new file mode 100644 index 0000000000..ab4f888dd9 --- /dev/null +++ b/tests/auto/corelib/io/qstorageinfo/BLACKLIST @@ -0,0 +1,2 @@ +[storageList] +opensuse-42.1 diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 0e73ea7862..487c13be94 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -307,7 +307,7 @@ void tst_QTemporaryDir::nonWritableCurrentDir() void tst_QTemporaryDir::openOnRootDrives() { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) unsigned int lastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); #endif // If it's possible to create a file in the root directory, it @@ -321,7 +321,7 @@ void tst_QTemporaryDir::openOnRootDrives() QVERIFY(dir.isValid()); } } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) SetErrorMode(lastErrorMode); #endif } diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 8ebde627df..59cd3a8411 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -415,9 +415,7 @@ void tst_QTemporaryFile::size() // On CE it takes more time for the filesystem to update // the information. Usually you have to close it or seek // to get latest information. flush() does not help either. -#if !defined(Q_OS_WINCE) QCOMPARE(file.size(), qint64(6)); -#endif file.seek(0); QCOMPARE(file.size(), qint64(6)); } @@ -436,7 +434,7 @@ void tst_QTemporaryFile::resize() void tst_QTemporaryFile::openOnRootDrives() { -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) unsigned int lastErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); #endif // If it's possible to create a file in the root directory, it @@ -450,19 +448,14 @@ void tst_QTemporaryFile::openOnRootDrives() QVERIFY(file.open()); } } -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) SetErrorMode(lastErrorMode); #endif } void tst_QTemporaryFile::stressTest() { -#if defined(Q_OS_WINCE) - // 200 is still ok, first colision happens after ~30 - const int iterations = 200; -#else const int iterations = 1000; -#endif QSet<QString> names; for (int i = 0; i < iterations; ++i) { diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 104873b85e..9533989b9d 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -175,20 +175,16 @@ private slots: void octTest(); void zeroTermination(); void ws_manipulator(); -#ifndef Q_OS_WINCE void stillOpenWhenAtEnd(); -#endif void readNewlines_data(); void readNewlines(); void seek(); void pos(); void pos2(); void pos3LargeFile(); -#if !defined(Q_OS_WINCE) void readStdin(); void readAllFromStdin(); void readLineFromStdin(); -#endif void read(); void qbool(); void forcePoint(); @@ -1207,8 +1203,6 @@ void tst_QTextStream::ws_manipulator() } // ------------------------------------------------------------------------------ -#ifndef Q_OS_WINCE -// Qt/CE: Cannot test network on emulator void tst_QTextStream::stillOpenWhenAtEnd() { QFile file(QFINDTESTDATA("tst_qtextstream.cpp")); @@ -1229,7 +1223,6 @@ void tst_QTextStream::stillOpenWhenAtEnd() while (!stream2.readLine().isNull()) {} QVERIFY(socket.isOpen()); } -#endif // ------------------------------------------------------------------------------ void tst_QTextStream::readNewlines_data() @@ -1498,8 +1491,6 @@ void tst_QTextStream::pos3LargeFile() } // ------------------------------------------------------------------------------ -// Qt/CE has no stdin/out support for processes -#if !defined(Q_OS_WINCE) void tst_QTextStream::readStdin() { #ifdef QT_NO_PROCESS @@ -1527,7 +1518,6 @@ void tst_QTextStream::readStdin() } // ------------------------------------------------------------------------------ -// Qt/CE has no stdin/out support for processes void tst_QTextStream::readAllFromStdin() { #ifdef QT_NO_PROCESS @@ -1549,7 +1539,6 @@ void tst_QTextStream::readAllFromStdin() } // ------------------------------------------------------------------------------ -// Qt/CE has no stdin/out support for processes void tst_QTextStream::readLineFromStdin() { #ifdef QT_NO_PROCESS @@ -1572,7 +1561,6 @@ void tst_QTextStream::readLineFromStdin() QVERIFY(stdinProcess.waitForFinished(5000)); #endif } -#endif // ------------------------------------------------------------------------------ void tst_QTextStream::read() @@ -2799,12 +2787,7 @@ void tst_QTextStream::status_real_read() void tst_QTextStream::status_integer_read() { -#ifdef Q_OS_WINCE - QString text = QLatin1String("123 abc "); - QTextStream s(&text); -#else QTextStream s("123 abc "); -#endif int i; QString w; s >> i; @@ -2822,12 +2805,7 @@ void tst_QTextStream::status_integer_read() void tst_QTextStream::status_word_read() { -#ifdef Q_OS_WINCE - QString text = QLatin1String("abc "); - QTextStream s(&text); -#else QTextStream s("abc "); -#endif QString w; s >> w; QCOMPARE(s.status(), QTextStream::Ok); diff --git a/tests/auto/corelib/io/qurlinternal/qurlinternal.pro b/tests/auto/corelib/io/qurlinternal/qurlinternal.pro index ae5e023446..3828512dce 100644 --- a/tests/auto/corelib/io/qurlinternal/qurlinternal.pro +++ b/tests/auto/corelib/io/qurlinternal/qurlinternal.pro @@ -1,5 +1,5 @@ CONFIG += testcase -requires(contains(QT_CONFIG,private_tests)) +requires(qtConfig(private_tests)) TARGET = tst_qurlinternal SOURCES += tst_qurlinternal.cpp ../../codecs/utf8/utf8data.cpp QT = core core-private testlib diff --git a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp index 4b3f76a78e..6ea7a38137 100644 --- a/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp +++ b/tests/auto/corelib/itemmodels/qitemmodel/modelstotest.cpp @@ -239,18 +239,10 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) // Basic tree StandardItemModel QModelIndex parent; QVariant blue = QVariant(QColor(Qt::blue)); -#ifndef Q_OS_WINCE for (int i = 0; i < 4; ++i) { -#else - for (int i = 0; i < 2; ++i) { -#endif parent = model->index(0, 0, parent); model->insertRows(0, 26 + i, parent); -#ifndef Q_OS_WINCE - model->insertColumns(0, 26 + i, parent); -#else model->insertColumns(0, 4 + i, parent); -#endif // Fill in some values to make it easier to debug /* for (int x = 0; x < 26 + i; ++x) { @@ -272,18 +264,10 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) // Basic tree StandardItemModel QModelIndex parent; QVariant blue = QVariant(QColor(Qt::blue)); -#ifndef Q_OS_WINCE for (int i = 0; i < 4; ++i) { -#else - for (int i = 0; i < 2; ++i) { -#endif parent = realModel->index(0, 0, parent); realModel->insertRows(0, 26+i, parent); -#ifndef Q_OS_WINCE - realModel->insertColumns(0, 26+i, parent); -#else realModel->insertColumns(0, 4, parent); -#endif // Fill in some values to make it easier to debug /* for (int x = 0; x < 26+i; ++x) { @@ -324,11 +308,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) QSqlQuery q; q.exec("CREATE TABLE test(id int primary key, name varchar(30))"); q.prepare("INSERT INTO test(id, name) values (?, ?)"); -#ifndef Q_OS_WINCE for (int i = 0; i < 1024; ++i) { -#else - for (int i = 0; i < 512; ++i) { -#endif q.addBindValue(i); q.addBindValue("Mr. Smith" + QString::number(i)); q.exec(); @@ -344,11 +324,7 @@ QModelIndex ModelsToTest::populateTestArea(QAbstractItemModel *model) } if (QListWidget *listWidget = qobject_cast<QListWidget *>(model->parent())) { -#ifndef Q_OS_WINCE - int items = 100; -#else int items = 50; -#endif while (items--) listWidget->addItem(QLatin1String("item ") + QString::number(items)); return QModelIndex(); diff --git a/tests/auto/corelib/json/json.pro b/tests/auto/corelib/json/json.pro index b3038d7ca1..16c2ae2fb7 100644 --- a/tests/auto/corelib/json/json.pro +++ b/tests/auto/corelib/json/json.pro @@ -1,12 +1,12 @@ TARGET = tst_json -QT = core testlib +QT = core-private testlib CONFIG -= app_bundle CONFIG += testcase !android:TESTDATA += bom.json test.json test.bjson test3.json test2.json else:RESOURCES += json.qrc -!contains(QT_CONFIG, doubleconversion):!contains(QT_CONFIG, system-doubleconversion) { +!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) { DEFINES += QT_NO_DOUBLECONVERSION } diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 02f3a1901e..6aa5165e24 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -138,6 +138,11 @@ private Q_SLOTS: void garbageAtEnd(); void removeNonLatinKey(); + void documentFromVariant(); + + void parseErrorOffset_data(); + void parseErrorOffset(); + private: QString testDataDir; }; @@ -1102,6 +1107,7 @@ void tst_QtJson::fromVariant() jsonObject["string"] = stringValue; jsonObject["array"] = jsonArray_variant; + QCOMPARE(QJsonValue::fromVariant(QVariant::fromValue(nullptr)), QJsonValue(QJsonValue::Null)); QCOMPARE(QJsonValue::fromVariant(QVariant(boolValue)), QJsonValue(boolValue)); QCOMPARE(QJsonValue::fromVariant(QVariant(intValue)), QJsonValue(intValue)); QCOMPARE(QJsonValue::fromVariant(QVariant(uintValue)), QJsonValue(static_cast<double>(uintValue))); @@ -1178,21 +1184,21 @@ void tst_QtJson::toVariantMap() array.append(true); array.append(999.); array.append(QLatin1String("string")); - array.append(QJsonValue()); + array.append(QJsonValue::Null); object.insert("Array", array); map = object.toVariantMap(); QCOMPARE(map.size(), 3); QCOMPARE(map.value("Key"), QVariant(QString("Value"))); - QCOMPARE(map.value("null"), QVariant()); + QCOMPARE(map.value("null"), QVariant::fromValue(nullptr)); QCOMPARE(map.value("Array").type(), QVariant::List); QVariantList list = map.value("Array").toList(); QCOMPARE(list.size(), 4); QCOMPARE(list.at(0), QVariant(true)); QCOMPARE(list.at(1), QVariant(999.)); QCOMPARE(list.at(2), QVariant(QLatin1String("string"))); - QCOMPARE(list.at(3), QVariant()); + QCOMPARE(list.at(3), QVariant::fromValue(nullptr)); } void tst_QtJson::toVariantHash() @@ -1202,26 +1208,26 @@ void tst_QtJson::toVariantHash() QVERIFY(hash.isEmpty()); object.insert("Key", QString("Value")); - object.insert("null", QJsonValue()); + object.insert("null", QJsonValue::Null); QJsonArray array; array.append(true); array.append(999.); array.append(QLatin1String("string")); - array.append(QJsonValue()); + array.append(QJsonValue::Null); object.insert("Array", array); hash = object.toVariantHash(); QCOMPARE(hash.size(), 3); QCOMPARE(hash.value("Key"), QVariant(QString("Value"))); - QCOMPARE(hash.value("null"), QVariant()); + QCOMPARE(hash.value("null"), QVariant::fromValue(nullptr)); QCOMPARE(hash.value("Array").type(), QVariant::List); QVariantList list = hash.value("Array").toList(); QCOMPARE(list.size(), 4); QCOMPARE(list.at(0), QVariant(true)); QCOMPARE(list.at(1), QVariant(999.)); QCOMPARE(list.at(2), QVariant(QLatin1String("string"))); - QCOMPARE(list.at(3), QVariant()); + QCOMPARE(list.at(3), QVariant::fromValue(nullptr)); } void tst_QtJson::toVariantList() @@ -1245,14 +1251,14 @@ void tst_QtJson::toVariantList() QCOMPARE(list.size(), 3); QCOMPARE(list[0], QVariant(QString("Value"))); - QCOMPARE(list[1], QVariant()); + QCOMPARE(list[1], QVariant::fromValue(nullptr)); QCOMPARE(list[2].type(), QVariant::List); QVariantList vlist = list[2].toList(); QCOMPARE(vlist.size(), 4); QCOMPARE(vlist.at(0), QVariant(true)); QCOMPARE(vlist.at(1), QVariant(999.)); QCOMPARE(vlist.at(2), QVariant(QLatin1String("string"))); - QCOMPARE(vlist.at(3), QVariant()); + QCOMPARE(vlist.at(3), QVariant::fromValue(nullptr)); } void tst_QtJson::toJson() @@ -2765,8 +2771,9 @@ void tst_QtJson::unicodeKeys() QCOMPARE(error.error, QJsonParseError::NoError); QJsonObject o = doc.object(); - QCOMPARE(o.keys().size(), 5); - Q_FOREACH (const QString &key, o.keys()) { + const auto keys = o.keys(); + QCOMPARE(keys.size(), 5); + for (const QString &key : keys) { QString suffix = key.mid(key.indexOf(QLatin1Char('_'))); QCOMPARE(o[key].toString(), QString("hello") + suffix); } @@ -2804,5 +2811,73 @@ void tst_QtJson::removeNonLatinKey() QVERIFY(restoredObject.contains(nonLatinKeyName)); } +void tst_QtJson::documentFromVariant() +{ + // Test the valid forms of QJsonDocument::fromVariant. + + QString string = QStringLiteral("value"); + + QStringList strList; + strList.append(string); + + QJsonDocument da1 = QJsonDocument::fromVariant(QVariant(strList)); + QVERIFY(da1.isArray()); + + QVariantList list; + list.append(string); + + QJsonDocument da2 = QJsonDocument::fromVariant(list); + QVERIFY(da2.isArray()); + + // As JSON arrays they should be equal. + QCOMPARE(da1.array(), da2.array()); + + + QMap <QString, QVariant> map; + map["key"] = string; + + QJsonDocument do1 = QJsonDocument::fromVariant(QVariant(map)); + QVERIFY(do1.isObject()); + + QHash <QString, QVariant> hash; + hash["key"] = string; + + QJsonDocument do2 = QJsonDocument::fromVariant(QVariant(hash)); + QVERIFY(do2.isObject()); + + // As JSON objects they should be equal. + QCOMPARE(do1.object(), do2.object()); +} + +void tst_QtJson::parseErrorOffset_data() +{ + QTest::addColumn<QByteArray>("json"); + QTest::addColumn<int>("errorOffset"); + + QTest::newRow("Trailing comma in object") << QByteArray("{ \"value\": false, }") << 19; + QTest::newRow("Trailing comma in object plus whitespace") << QByteArray("{ \"value\": false, } ") << 19; + QTest::newRow("Trailing comma in array") << QByteArray("[ false, ]") << 10; + QTest::newRow("Trailing comma in array plus whitespace") << QByteArray("[ false, ] ") << 10; + QTest::newRow("Missing value in object") << QByteArray("{ \"value\": , } ") << 12; + QTest::newRow("Missing value in array") << QByteArray("[ \"value\" , , ] ") << 13; + QTest::newRow("Leading comma in object") << QByteArray("{ , \"value\": false}") << 3; + QTest::newRow("Leading comma in array") << QByteArray("[ , false]") << 3; + QTest::newRow("Stray ,") << QByteArray(" , ") << 3; + QTest::newRow("Stray [") << QByteArray(" [ ") << 5; + QTest::newRow("Stray }") << QByteArray(" } ") << 3; +} + +void tst_QtJson::parseErrorOffset() +{ + QFETCH(QByteArray, json); + QFETCH(int, errorOffset); + + QJsonParseError error; + QJsonDocument::fromJson(json, &error); + + QVERIFY(error.error != QJsonParseError::NoError); + QCOMPARE(error.offset, errorOffset); +} + QTEST_MAIN(tst_QtJson) #include "tst_qtjson.moc" diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro index f85c39e9e6..75b98bcd09 100644 --- a/tests/auto/corelib/kernel/kernel.pro +++ b/tests/auto/corelib/kernel/kernel.pro @@ -1,6 +1,8 @@ TEMPLATE=subdirs SUBDIRS=\ qcoreapplication \ + qdeadlinetimer \ + qelapsedtimer \ qeventdispatcher \ qeventloop \ qmath \ @@ -31,11 +33,11 @@ SUBDIRS=\ qobject \ qsocketnotifier -!contains(QT_CONFIG, private_tests): SUBDIRS -= \ +!qtConfig(private_tests): SUBDIRS -= \ qsocketnotifier \ qsharedmemory # This test is only applicable on Windows !win32*|winrt: SUBDIRS -= qwineventnotifier -android|ios: SUBDIRS -= qsharedmemory qsystemsemaphore +android|uikit: SUBDIRS -= qclipboard qobject qsharedmemory qsystemsemaphore diff --git a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro index a49bb9ae1f..d166351490 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro +++ b/tests/auto/corelib/kernel/qcoreapplication/qcoreapplication.pro @@ -3,4 +3,4 @@ TARGET = tst_qcoreapplication QT = core testlib core-private SOURCES = tst_qcoreapplication.cpp HEADERS = tst_qcoreapplication.h -requires(contains(QT_CONFIG,private_tests)) +requires(qtConfig(private_tests)) diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index a8de5b7a9a..0691297497 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -155,7 +155,7 @@ void tst_QCoreApplication::qAppName() void tst_QCoreApplication::argc() { -#if defined(Q_OS_WINCE) || defined(Q_OS_WINRT) +#if defined(Q_OS_WINRT) QSKIP("QCoreApplication::arguments() parses arguments from actual command line on this platform."); #endif { diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/qdeadlinetimer.pro b/tests/auto/corelib/kernel/qdeadlinetimer/qdeadlinetimer.pro new file mode 100644 index 0000000000..12ad7dabc2 --- /dev/null +++ b/tests/auto/corelib/kernel/qdeadlinetimer/qdeadlinetimer.pro @@ -0,0 +1,5 @@ +CONFIG += testcase +TARGET = tst_qdeadlinetimer +QT = core testlib +SOURCES = tst_qdeadlinetimer.cpp + diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp new file mode 100644 index 0000000000..6ab24d2480 --- /dev/null +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -0,0 +1,625 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Intel Corporation. +** 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/QDeadlineTimer> +#include <QtTest/QtTest> + +#if QT_HAS_INCLUDE(<chrono>) +# include <chrono> +#endif + +static const int minResolution = 400; // the minimum resolution for the tests + +Q_DECLARE_METATYPE(Qt::TimerType) + +class tst_QDeadlineTimer : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase_data(); + void basics(); + void foreverness(); + void current(); + void deadlines(); + void setDeadline(); + void expire(); + void stdchrono(); +}; + +void tst_QDeadlineTimer::initTestCase_data() +{ + qRegisterMetaType<Qt::TimerType>(); + QTest::addColumn<Qt::TimerType>("timerType"); + QTest::newRow("precise") << Qt::PreciseTimer; + QTest::newRow("coarse") << Qt::CoarseTimer; +} + +void tst_QDeadlineTimer::basics() +{ + QDeadlineTimer deadline; + QCOMPARE(deadline.timerType(), Qt::CoarseTimer); + + QFETCH_GLOBAL(Qt::TimerType, timerType); + deadline = QDeadlineTimer(timerType); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline, QDeadlineTimer(timerType)); + QVERIFY(!(deadline != QDeadlineTimer(timerType))); + QVERIFY(!(deadline < QDeadlineTimer())); + QVERIFY(deadline <= QDeadlineTimer()); + QVERIFY(deadline >= QDeadlineTimer()); + QVERIFY(!(deadline > QDeadlineTimer())); + QVERIFY(!(deadline < deadline)); + QVERIFY(deadline <= deadline); + QVERIFY(deadline >= deadline); + QVERIFY(!(deadline > deadline)); + + // should have expired, but we may be running too early after boot + QTRY_VERIFY_WITH_TIMEOUT(deadline.hasExpired(), 100); + + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), qint64(0)); + QCOMPARE(deadline.deadlineNSecs(), qint64(0)); + + deadline.setRemainingTime(0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(0, 0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setDeadline(0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), qint64(0)); + QCOMPARE(deadline.deadlineNSecs(), qint64(0)); + + deadline.setPreciseDeadline(0, 0, timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), qint64(0)); + QCOMPARE(deadline.deadlineNSecs(), qint64(0)); +} + +void tst_QDeadlineTimer::foreverness() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + // we don't check whether timerType() is our type since it's possible it detects it's forever + + QDeadlineTimer deadline = QDeadlineTimer::Forever; + QCOMPARE(deadline.timerType(), Qt::CoarseTimer); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline = QDeadlineTimer(-1, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setRemainingTime(-1, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(-1, 0, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(-1, -1, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setDeadline(std::numeric_limits<qint64>::max(), timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + deadline.setPreciseDeadline(std::numeric_limits<qint64>::max(), 0, timerType); + QVERIFY(deadline.isForever()); + QVERIFY(!deadline.hasExpired()); + QCOMPARE(deadline.remainingTime(), qint64(-1)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), std::numeric_limits<qint64>::max()); + + QCOMPARE(deadline, deadline); + QVERIFY(!(deadline < deadline)); + QVERIFY(deadline <= deadline); + QVERIFY(deadline >= deadline); + QVERIFY(!(deadline > deadline)); + + // adding to forever must still be forever + QDeadlineTimer deadline2 = deadline + 1; + QVERIFY(deadline2.isForever()); + QVERIFY(!deadline2.hasExpired()); + QCOMPARE(deadline2.remainingTime(), qint64(-1)); + QCOMPARE(deadline2.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline2.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.deadlineNSecs(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.timerType(), deadline.timerType()); + + QCOMPARE(deadline2 - deadline, qint64(0)); + QCOMPARE(deadline2, deadline); + QVERIFY(!(deadline2 < deadline)); + QVERIFY(deadline2 <= deadline); + QVERIFY(deadline2 >= deadline); + QVERIFY(!(deadline2 > deadline)); + + // subtracting from forever is *also* forever + deadline2 = deadline - 1; + QVERIFY(deadline2.isForever()); + QVERIFY(!deadline2.hasExpired()); + QCOMPARE(deadline2.remainingTime(), qint64(-1)); + QCOMPARE(deadline2.remainingTimeNSecs(), qint64(-1)); + QCOMPARE(deadline2.deadline(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.deadlineNSecs(), std::numeric_limits<qint64>::max()); + QCOMPARE(deadline2.timerType(), deadline.timerType()); + + QCOMPARE(deadline2 - deadline, qint64(0)); + QCOMPARE(deadline2, deadline); + QVERIFY(!(deadline2 < deadline)); + QVERIFY(deadline2 <= deadline); + QVERIFY(deadline2 >= deadline); + QVERIFY(!(deadline2 > deadline)); + + // compare and order against a default-constructed object + QDeadlineTimer expired; + QVERIFY(!(deadline == expired)); + QVERIFY(deadline != expired); + QVERIFY(!(deadline < expired)); + QVERIFY(!(deadline <= expired)); + QVERIFY(deadline >= expired); + QVERIFY(deadline > expired); +} + +void tst_QDeadlineTimer::current() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + auto deadline = QDeadlineTimer::current(timerType); + QVERIFY(deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + // subtracting from current should be "more expired" + QDeadlineTimer earlierDeadline = deadline - 1; + QVERIFY(earlierDeadline.hasExpired()); + QVERIFY(!earlierDeadline.isForever()); + QCOMPARE(earlierDeadline.timerType(), timerType); + QCOMPARE(earlierDeadline.remainingTime(), qint64(0)); + QCOMPARE(earlierDeadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(earlierDeadline.deadline() != 0); + QVERIFY(earlierDeadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(earlierDeadline.deadlineNSecs() != 0); + QVERIFY(earlierDeadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + QCOMPARE(earlierDeadline.deadline(), deadline.deadline() - 1); + QCOMPARE(earlierDeadline.deadlineNSecs(), deadline.deadlineNSecs() - 1000*1000); + + QCOMPARE(earlierDeadline - deadline, qint64(-1)); + QVERIFY(earlierDeadline != deadline); + QVERIFY(earlierDeadline < deadline); + QVERIFY(earlierDeadline <= deadline); + QVERIFY(!(earlierDeadline >= deadline)); + QVERIFY(!(earlierDeadline > deadline)); +} + +void tst_QDeadlineTimer::deadlines() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + + QDeadlineTimer deadline(4 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setRemainingTime(4 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(0, 4000000 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + deadline.setPreciseRemainingTime(1, 0, timerType); // 1 sec + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (1000 - minResolution)); + QVERIFY(deadline.remainingTime() <= 1000); + QVERIFY(deadline.remainingTimeNSecs() > (1000 - minResolution)*1000*1000); + QVERIFY(deadline.remainingTimeNSecs() <= (1000*1000*1000)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + + // adding to a future deadline must still be further in the future + QDeadlineTimer laterDeadline = deadline + 1; + QVERIFY(!laterDeadline.hasExpired()); + QVERIFY(!laterDeadline.isForever()); + QCOMPARE(laterDeadline.timerType(), timerType); + QVERIFY(laterDeadline.remainingTime() > (1000 - minResolution)); + QVERIFY(laterDeadline.remainingTime() <= 1001); + QVERIFY(laterDeadline.remainingTimeNSecs() > (1001 - minResolution)*1000*1000); + QVERIFY(laterDeadline.remainingTimeNSecs() <= (1001*1000*1000)); + QVERIFY(laterDeadline.deadline() != 0); + QVERIFY(laterDeadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(laterDeadline.deadlineNSecs() != 0); + QVERIFY(laterDeadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + QCOMPARE(laterDeadline.deadline(), deadline.deadline() + 1); + QCOMPARE(laterDeadline.deadlineNSecs(), deadline.deadlineNSecs() + 1000*1000); + + QCOMPARE(laterDeadline - deadline, qint64(1)); + QVERIFY(laterDeadline != deadline); + QVERIFY(!(laterDeadline < deadline)); + QVERIFY(!(laterDeadline <= deadline)); + QVERIFY(laterDeadline >= deadline); + QVERIFY(laterDeadline > deadline); + + // compare and order against a default-constructed object + QDeadlineTimer expired; + QVERIFY(!(deadline == expired)); + QVERIFY(deadline != expired); + QVERIFY(!(deadline < expired)); + QVERIFY(!(deadline <= expired)); + QVERIFY(deadline >= expired); + QVERIFY(deadline > expired); + + // compare and order against a forever deadline + QDeadlineTimer forever_(QDeadlineTimer::Forever); + QVERIFY(!(deadline == forever_)); + QVERIFY(deadline != forever_); + QVERIFY(deadline < forever_); + QVERIFY(deadline <= forever_); + QVERIFY(!(deadline >= forever_)); + QVERIFY(!(deadline > forever_)); +} + +void tst_QDeadlineTimer::setDeadline() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + auto now = QDeadlineTimer::current(timerType); + QDeadlineTimer deadline; + + deadline.setDeadline(now.deadline(), timerType); + QVERIFY(deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), now.deadline()); + // don't check deadlineNSecs! + + deadline.setPreciseDeadline(now.deadlineNSecs() / (1000 * 1000 * 1000), + now.deadlineNSecs() % (1000 * 1000 * 1000), timerType); + QVERIFY(deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QCOMPARE(deadline.deadline(), now.deadline()); + QCOMPARE(deadline.deadlineNSecs(), now.deadlineNSecs()); + + now = QDeadlineTimer::current(timerType); + deadline.setDeadline(now.deadline() + 4 * minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QCOMPARE(deadline.deadline(), now.deadline() + 4 * minResolution); // yes, it's exact + // don't check deadlineNSecs! + + now = QDeadlineTimer::current(timerType); + qint64 nsec = now.deadlineNSecs() + 4000000 * minResolution; + deadline.setPreciseDeadline(nsec / (1000 * 1000 * 1000), + nsec % (1000 * 1000 * 1000), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTime() > (3 * minResolution)); + QVERIFY(deadline.remainingTime() <= (4 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() > (3000000 * minResolution)); + QVERIFY(deadline.remainingTimeNSecs() <= (4000000 * minResolution)); + QCOMPARE(deadline.deadline(), nsec / (1000 * 1000)); + QCOMPARE(deadline.deadlineNSecs(), nsec); +} + +void tst_QDeadlineTimer::expire() +{ + QFETCH_GLOBAL(Qt::TimerType, timerType); + + QDeadlineTimer deadline(minResolution, timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + + qint64 previousDeadline = deadline.deadlineNSecs(); + + QTest::qSleep(2 * minResolution); + + QCOMPARE(deadline.remainingTime(), qint64(0)); + QCOMPARE(deadline.remainingTimeNSecs(), qint64(0)); + QVERIFY(deadline.deadline() != 0); + QVERIFY(deadline.deadline() != std::numeric_limits<qint64>::max()); + QVERIFY(deadline.deadlineNSecs() != 0); + QVERIFY(deadline.deadlineNSecs() != std::numeric_limits<qint64>::max()); + QCOMPARE(deadline.deadlineNSecs(), previousDeadline); +} + +void tst_QDeadlineTimer::stdchrono() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("std::chrono not found on this system"); +#else + using namespace std::chrono; + QFETCH_GLOBAL(Qt::TimerType, timerType); + + // create some forevers + QDeadlineTimer deadline = milliseconds::max(); + QVERIFY(deadline.isForever()); + deadline = milliseconds::max(); + QVERIFY(deadline.isForever()); + deadline.setRemainingTime(milliseconds::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + deadline = nanoseconds::max(); + QVERIFY(deadline.isForever()); + deadline.setRemainingTime(nanoseconds::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + deadline = hours::max(); + QVERIFY(deadline.isForever()); + deadline.setRemainingTime(hours::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + + deadline = time_point<system_clock>::max(); + QVERIFY(deadline.isForever()); + deadline.setDeadline(time_point<system_clock>::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + deadline = time_point<steady_clock>::max(); + QVERIFY(deadline.isForever()); + deadline.setDeadline(time_point<steady_clock>::max(), timerType); + QVERIFY(deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + + QVERIFY(deadline == time_point<steady_clock>::max()); + QVERIFY(deadline == time_point<system_clock>::max()); + QCOMPARE(deadline.remainingTimeAsDuration(), nanoseconds::max()); + + // make it expired + deadline = time_point<system_clock>(); + QVERIFY(deadline.hasExpired()); + deadline.setDeadline(time_point<system_clock>(), timerType); + QVERIFY(deadline.hasExpired()); + QCOMPARE(deadline.timerType(), timerType); + deadline = time_point<steady_clock>(); + QVERIFY(deadline.hasExpired()); + deadline.setDeadline(time_point<steady_clock>(), timerType); + QVERIFY(deadline.hasExpired()); + QCOMPARE(deadline.timerType(), timerType); + + QCOMPARE(deadline.remainingTimeAsDuration(), nanoseconds::zero()); + + auto steady_before = steady_clock::now(); + auto system_before = system_clock::now(); + + QTest::qSleep(minResolution); + auto now = QDeadlineTimer::current(timerType); + QTest::qSleep(minResolution); + + auto steady_after = steady_clock::now(); + auto system_after = system_clock::now(); + + { + auto diff = duration_cast<milliseconds>(steady_after - now.deadline<steady_clock>()); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_after(steady_after, timerType); + QVERIFY2(now < dt_after, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; after = " + QLocale().toString(dt_after.deadlineNSecs())).toLatin1()); + + diff = duration_cast<milliseconds>(now.deadline<steady_clock>() - steady_before); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_before(steady_before, timerType); + QVERIFY2(now > dt_before, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; before = " + QLocale().toString(dt_before.deadlineNSecs())).toLatin1()); + } + { + auto diff = duration_cast<milliseconds>(system_after - now.deadline<system_clock>()); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_after(system_after, timerType); + QVERIFY2(now < dt_after, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; after = " + QLocale().toString(dt_after.deadlineNSecs())).toLatin1()); + + diff = duration_cast<milliseconds>(now.deadline<system_clock>() - system_before); + QVERIFY2(diff.count() > minResolution/2, QByteArray::number(qint64(diff.count()))); + QVERIFY2(diff.count() < 3*minResolution/2, QByteArray::number(qint64(diff.count()))); + QDeadlineTimer dt_before(system_before, timerType); + QVERIFY2(now > dt_before, + ("now = " + QLocale().toString(now.deadlineNSecs()) + + "; before = " + QLocale().toString(dt_before.deadlineNSecs())).toLatin1()); + } + + // make it regular + now = QDeadlineTimer::current(timerType); + deadline.setRemainingTime(milliseconds(4 * minResolution), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > milliseconds(3 * minResolution)); + QVERIFY(deadline.remainingTimeAsDuration() < milliseconds(5 * minResolution)); + QVERIFY(deadline.remainingTimeAsDuration() > nanoseconds(3000000 * minResolution)); + QVERIFY(deadline.remainingTimeAsDuration() < nanoseconds(5000000 * minResolution)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + milliseconds(3 * minResolution))); + QVERIFY(deadline.deadline<steady_clock>() < (steady_clock::now() + milliseconds(5 * minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + milliseconds(3 * minResolution))); + QVERIFY(deadline.deadline<system_clock>() < (system_clock::now() + milliseconds(5 * minResolution))); + if (timerType == Qt::CoarseTimer) { + QVERIFY(deadline > (now + milliseconds(3 * minResolution))); + QVERIFY(deadline < (now + milliseconds(5 * minResolution))); + QVERIFY(deadline > (now + nanoseconds(3000000 * minResolution))); + QVERIFY(deadline < (now + nanoseconds(5000000 * minResolution))); + QVERIFY(deadline > milliseconds(3 * minResolution)); + QVERIFY(deadline < milliseconds(5 * minResolution)); + QVERIFY(deadline > nanoseconds(3000000 * minResolution)); + QVERIFY(deadline < nanoseconds(5000000 * minResolution)); + QVERIFY(deadline >= steady_clock::now()); + QVERIFY(deadline >= system_clock::now()); + } + + now = QDeadlineTimer::current(timerType); + deadline = QDeadlineTimer(seconds(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= seconds(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); + if (timerType == Qt::CoarseTimer) { + QVERIFY(deadline > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline <= seconds(1)); + } + + now = QDeadlineTimer::current(timerType); + deadline.setRemainingTime(hours(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (hours(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= hours(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + hours(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + hours(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + hours(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + hours(1) + milliseconds(minResolution))); + + now = QDeadlineTimer::current(timerType); + deadline.setDeadline(system_clock::now() + seconds(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= seconds(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); + + now = QDeadlineTimer::current(timerType); + deadline.setDeadline(steady_clock::now() + seconds(1), timerType); + QVERIFY(!deadline.hasExpired()); + QVERIFY(!deadline.isForever()); + QCOMPARE(deadline.timerType(), timerType); + QVERIFY(deadline.remainingTimeAsDuration() > (seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.remainingTimeAsDuration() <= seconds(1)); + QVERIFY(deadline.deadline<steady_clock>() > (steady_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<steady_clock>() <= (steady_clock::now() + seconds(1) + milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() > (system_clock::now() + seconds(1) - milliseconds(minResolution))); + QVERIFY(deadline.deadline<system_clock>() <= (system_clock::now() + seconds(1) + milliseconds(minResolution))); +#endif +} + +QTEST_MAIN(tst_QDeadlineTimer) + +#include "tst_qdeadlinetimer.moc" diff --git a/tests/auto/corelib/tools/qelapsedtimer/qelapsedtimer.pro b/tests/auto/corelib/kernel/qelapsedtimer/qelapsedtimer.pro index 657a63a5d7..657a63a5d7 100644 --- a/tests/auto/corelib/tools/qelapsedtimer/qelapsedtimer.pro +++ b/tests/auto/corelib/kernel/qelapsedtimer/qelapsedtimer.pro diff --git a/tests/auto/corelib/tools/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp index 9db001c37d..9db001c37d 100644 --- a/tests/auto/corelib/tools/qelapsedtimer/tst_qelapsedtimer.cpp +++ b/tests/auto/corelib/kernel/qelapsedtimer/tst_qelapsedtimer.cpp diff --git a/tests/auto/corelib/kernel/qeventloop/qeventloop.pro b/tests/auto/corelib/kernel/qeventloop/qeventloop.pro index 5cd043b584..295a42aa9c 100644 --- a/tests/auto/corelib/kernel/qeventloop/qeventloop.pro +++ b/tests/auto/corelib/kernel/qeventloop/qeventloop.pro @@ -3,6 +3,6 @@ TARGET = tst_qeventloop QT = core network testlib core-private SOURCES = $$PWD/tst_qeventloop.cpp -win32:!wince:!winrt: LIBS += -luser32 +win32:!winrt: LIBS += -luser32 -contains(QT_CONFIG, glib): DEFINES += HAVE_GLIB +qtConfig(glib): DEFINES += HAVE_GLIB diff --git a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro index 1d4e647a4b..b5f1d0fe00 100644 --- a/tests/auto/corelib/kernel/qmetatype/qmetatype.pro +++ b/tests/auto/corelib/kernel/qmetatype/qmetatype.pro @@ -6,11 +6,11 @@ SOURCES = tst_qmetatype.cpp TESTDATA=./typeFlags.bin DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -win32-msvc*|wince|winrt { +win32-msvc*|winrt { # Prevents "fatal error C1128: number of sections exceeded object file format limit". QMAKE_CXXFLAGS += /bigobj # Reduce compile time - win32-msvc2012|wince|winrt { + win32-msvc2012|winrt { QMAKE_CXXFLAGS_RELEASE -= -O2 QMAKE_CFLAGS_RELEASE -= -O2 } diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index fbb6a30917..7d9f56ef38 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -30,6 +30,7 @@ #include <QtCore> #include <QtTest/QtTest> +#include "tst_qmetatype.h" #include "tst_qvariant_common.h" #ifdef Q_OS_LINUX @@ -464,18 +465,6 @@ void tst_QMetaType::type_fromSubString() QCOMPARE(QMetaType::type(ba), expectedType); } -#define FOR_EACH_PRIMITIVE_METATYPE(F) \ - QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ - QT_FOR_EACH_STATIC_CORE_POINTER(F) \ - -#define FOR_EACH_COMPLEX_CORE_METATYPE(F) \ - QT_FOR_EACH_STATIC_CORE_CLASS(F) \ - QT_FOR_EACH_STATIC_CORE_TEMPLATE(F) - -#define FOR_EACH_CORE_METATYPE(F) \ - FOR_EACH_PRIMITIVE_METATYPE(F) \ - FOR_EACH_COMPLEX_CORE_METATYPE(F) \ - namespace { template <typename T> struct static_assert_trigger { @@ -495,234 +484,6 @@ Q_STATIC_ASSERT((!QMetaTypeId2<QList<int> >::IsBuiltIn)); Q_STATIC_ASSERT((!QMetaTypeId2<QMap<int,int> >::IsBuiltIn)); Q_STATIC_ASSERT((!QMetaTypeId2<QMetaType::Type>::IsBuiltIn)); -template <int ID> -struct MetaEnumToType {}; - -#define DEFINE_META_ENUM_TO_TYPE(MetaTypeName, MetaTypeId, RealType) \ -template<> \ -struct MetaEnumToType<QMetaType::MetaTypeName> { \ - typedef RealType Type; \ -}; -FOR_EACH_CORE_METATYPE(DEFINE_META_ENUM_TO_TYPE) -#undef DEFINE_META_ENUM_TO_TYPE - -template <int ID> -struct DefaultValueFactory -{ - typedef typename MetaEnumToType<ID>::Type Type; - static Type *create() { return new Type; } -}; - -template <> -struct DefaultValueFactory<QMetaType::Void> -{ - typedef MetaEnumToType<QMetaType::Void>::Type Type; - static Type *create() { return 0; } -}; - -template <int ID> -struct DefaultValueTraits -{ - // By default we assume that a default-constructed value (new T) is - // initialized; e.g. QCOMPARE(*(new T), *(new T)) should succeed - enum { IsInitialized = true }; -}; - -#define DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS(MetaTypeName, MetaTypeId, RealType) \ -template<> struct DefaultValueTraits<QMetaType::MetaTypeName> { \ - enum { IsInitialized = false }; \ -}; -// Primitive types (int et al) aren't initialized -FOR_EACH_PRIMITIVE_METATYPE(DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS) -#undef DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS - -template <int ID> -struct TestValueFactory {}; - -template<> struct TestValueFactory<QMetaType::Void> { - static void *create() { return 0; } -}; - -template<> struct TestValueFactory<QMetaType::QString> { - static QString *create() { return new QString(QString::fromLatin1("QString")); } -}; -template<> struct TestValueFactory<QMetaType::Int> { - static int *create() { return new int(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::UInt> { - static uint *create() { return new uint(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::Bool> { - static bool *create() { return new bool(true); } -}; -template<> struct TestValueFactory<QMetaType::Double> { - static double *create() { return new double(3.14); } -}; -template<> struct TestValueFactory<QMetaType::QByteArray> { - static QByteArray *create() { return new QByteArray(QByteArray("QByteArray")); } -}; -template<> struct TestValueFactory<QMetaType::QByteArrayList> { - static QByteArrayList *create() { return new QByteArrayList(QByteArrayList() << "Q" << "Byte" << "Array" << "List"); } -}; -template<> struct TestValueFactory<QMetaType::QVariantMap> { - static QVariantMap *create() { return new QVariantMap(); } -}; -template<> struct TestValueFactory<QMetaType::QVariantHash> { - static QVariantHash *create() { return new QVariantHash(); } -}; -template<> struct TestValueFactory<QMetaType::QVariantList> { - static QVariantList *create() { return new QVariantList(QVariantList() << 123 << "Q" << "Variant" << "List"); } -}; -template<> struct TestValueFactory<QMetaType::QChar> { - static QChar *create() { return new QChar(QChar('q')); } -}; -template<> struct TestValueFactory<QMetaType::Long> { - static long *create() { return new long(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::Short> { - static short *create() { return new short(0x1234); } -}; -template<> struct TestValueFactory<QMetaType::Char> { - static char *create() { return new char('c'); } -}; -template<> struct TestValueFactory<QMetaType::ULong> { - static ulong *create() { return new ulong(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::UShort> { - static ushort *create() { return new ushort(0x1234); } -}; -template<> struct TestValueFactory<QMetaType::SChar> { - static signed char *create() { return new signed char(-12); } -}; -template<> struct TestValueFactory<QMetaType::UChar> { - static uchar *create() { return new uchar('u'); } -}; -template<> struct TestValueFactory<QMetaType::Float> { - static float *create() { return new float(3.14f); } -}; -template<> struct TestValueFactory<QMetaType::QObjectStar> { - static QObject * *create() { return new QObject *(0); } -}; -template<> struct TestValueFactory<QMetaType::VoidStar> { - static void * *create() { return new void *(0); } -}; -template<> struct TestValueFactory<QMetaType::LongLong> { - static qlonglong *create() { return new qlonglong(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::ULongLong> { - static qulonglong *create() { return new qulonglong(0x12345678); } -}; -template<> struct TestValueFactory<QMetaType::QStringList> { - static QStringList *create() { return new QStringList(QStringList() << "Q" << "t"); } -}; -template<> struct TestValueFactory<QMetaType::QBitArray> { - static QBitArray *create() { return new QBitArray(QBitArray(256, true)); } -}; -template<> struct TestValueFactory<QMetaType::QDate> { - static QDate *create() { return new QDate(QDate::currentDate()); } -}; -template<> struct TestValueFactory<QMetaType::QTime> { - static QTime *create() { return new QTime(QTime::currentTime()); } -}; -template<> struct TestValueFactory<QMetaType::QDateTime> { - static QDateTime *create() { return new QDateTime(QDateTime::currentDateTime()); } -}; -template<> struct TestValueFactory<QMetaType::QUrl> { - static QUrl *create() { return new QUrl("http://www.example.org"); } -}; -template<> struct TestValueFactory<QMetaType::QLocale> { - static QLocale *create() { return new QLocale(QLocale::c()); } -}; -template<> struct TestValueFactory<QMetaType::QRect> { - static QRect *create() { return new QRect(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QRectF> { - static QRectF *create() { return new QRectF(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QSize> { - static QSize *create() { return new QSize(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QSizeF> { - static QSizeF *create() { return new QSizeF(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QLine> { - static QLine *create() { return new QLine(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QLineF> { - static QLineF *create() { return new QLineF(10, 20, 30, 40); } -}; -template<> struct TestValueFactory<QMetaType::QPoint> { - static QPoint *create() { return new QPoint(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QPointF> { - static QPointF *create() { return new QPointF(10, 20); } -}; -template<> struct TestValueFactory<QMetaType::QEasingCurve> { - static QEasingCurve *create() { return new QEasingCurve(QEasingCurve::InOutElastic); } -}; -template<> struct TestValueFactory<QMetaType::QUuid> { - static QUuid *create() { return new QUuid(); } -}; -template<> struct TestValueFactory<QMetaType::QModelIndex> { - static QModelIndex *create() { return new QModelIndex(); } -}; -template<> struct TestValueFactory<QMetaType::QPersistentModelIndex> { - static QPersistentModelIndex *create() { return new QPersistentModelIndex(); } -}; -template<> struct TestValueFactory<QMetaType::QRegExp> { - static QRegExp *create() - { -#ifndef QT_NO_REGEXP - return new QRegExp("A*"); -#else - return 0; -#endif - } -}; -template<> struct TestValueFactory<QMetaType::QRegularExpression> { - static QRegularExpression *create() - { -#ifndef QT_NO_REGEXP - return new QRegularExpression("abc.*def"); -#else - return 0; -#endif - } -}; -template<> struct TestValueFactory<QMetaType::QJsonValue> { - static QJsonValue *create() { return new QJsonValue(123.); } -}; -template<> struct TestValueFactory<QMetaType::QJsonObject> { - static QJsonObject *create() { - QJsonObject *o = new QJsonObject(); - o->insert("a", 123.); - o->insert("b", true); - o->insert("c", QJsonValue::Null); - o->insert("d", QLatin1String("ciao")); - return o; - } -}; -template<> struct TestValueFactory<QMetaType::QJsonArray> { - static QJsonArray *create() { - QJsonArray *a = new QJsonArray(); - a->append(123.); - a->append(true); - a->append(QJsonValue::Null); - a->append(QLatin1String("ciao")); - return a; - } -}; -template<> struct TestValueFactory<QMetaType::QJsonDocument> { - static QJsonDocument *create() { - return new QJsonDocument( - QJsonDocument::fromJson("{ 'foo': 123, 'bar': [true, null, 'ciao'] }") - ); - } -}; -template<> struct TestValueFactory<QMetaType::QVariant> { - static QVariant *create() { return new QVariant(QStringList(QStringList() << "Q" << "t")); } -}; - void tst_QMetaType::create_data() { QTest::addColumn<int>("type"); @@ -951,7 +712,7 @@ void tst_QMetaType::flags_data() << bool(!QTypeInfo<RealType>::isStatic) \ << bool(QTypeInfo<RealType>::isComplex) \ << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \ - << bool(Q_IS_ENUM(RealType)); + << bool(std::is_enum<RealType>::value); QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) @@ -1798,6 +1559,7 @@ DECLARE_NONSTREAMABLE(QJsonArray) DECLARE_NONSTREAMABLE(QJsonDocument) DECLARE_NONSTREAMABLE(QObject*) DECLARE_NONSTREAMABLE(QWidget*) +DECLARE_NONSTREAMABLE(std::nullptr_t) #define DECLARE_GUI_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \ DECLARE_NONSTREAMABLE(RealType) diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h new file mode 100644 index 0000000000..93ff33bb67 --- /dev/null +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h @@ -0,0 +1,280 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +// Used by both tst_qmetatype and tst_qsettings + +#ifndef TST_QMETATYPE_H +#define TST_QMETATYPE_H + +#include <qmetatype.h> +#include <float.h> + +#define FOR_EACH_PRIMITIVE_METATYPE(F) \ + QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F) \ + QT_FOR_EACH_STATIC_CORE_POINTER(F) \ + +#define FOR_EACH_COMPLEX_CORE_METATYPE(F) \ + QT_FOR_EACH_STATIC_CORE_CLASS(F) \ + QT_FOR_EACH_STATIC_CORE_TEMPLATE(F) + +#define FOR_EACH_CORE_METATYPE(F) \ + FOR_EACH_PRIMITIVE_METATYPE(F) \ + FOR_EACH_COMPLEX_CORE_METATYPE(F) \ + +template <int ID> +struct MetaEnumToType {}; + +#define DEFINE_META_ENUM_TO_TYPE(MetaTypeName, MetaTypeId, RealType) \ +template<> \ +struct MetaEnumToType<QMetaType::MetaTypeName> { \ + typedef RealType Type; \ +}; +FOR_EACH_CORE_METATYPE(DEFINE_META_ENUM_TO_TYPE) +#undef DEFINE_META_ENUM_TO_TYPE + +template <int ID> +struct DefaultValueFactory +{ + typedef typename MetaEnumToType<ID>::Type Type; + static Type *create() { return new Type; } +}; + +template <> +struct DefaultValueFactory<QMetaType::Void> +{ + typedef MetaEnumToType<QMetaType::Void>::Type Type; + static Type *create() { return 0; } +}; + +template <int ID> +struct DefaultValueTraits +{ + // By default we assume that a default-constructed value (new T) is + // initialized; e.g. QCOMPARE(*(new T), *(new T)) should succeed + enum { IsInitialized = true }; +}; + +#define DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS(MetaTypeName, MetaTypeId, RealType) \ +template<> struct DefaultValueTraits<QMetaType::MetaTypeName> { \ + enum { IsInitialized = false }; \ +}; +// Primitive types (int et al) aren't initialized +FOR_EACH_PRIMITIVE_METATYPE(DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS) +#undef DEFINE_NON_INITIALIZED_DEFAULT_VALUE_TRAITS + +template <int ID> +struct TestValueFactory {}; + +template<> struct TestValueFactory<QMetaType::Void> { + static void *create() { return 0; } +}; + +template<> struct TestValueFactory<QMetaType::QString> { + static QString *create() { return new QString(QString::fromLatin1("QString")); } +}; +template<> struct TestValueFactory<QMetaType::Int> { + static int *create() { return new int(INT_MIN); } +}; +template<> struct TestValueFactory<QMetaType::UInt> { + static uint *create() { return new uint(UINT_MAX); } +}; +template<> struct TestValueFactory<QMetaType::Bool> { + static bool *create() { return new bool(true); } +}; +template<> struct TestValueFactory<QMetaType::Double> { + static double *create() { return new double(DBL_MIN); } +}; +template<> struct TestValueFactory<QMetaType::QByteArray> { + static QByteArray *create() { return new QByteArray(QByteArray("QByteArray")); } +}; +template<> struct TestValueFactory<QMetaType::QByteArrayList> { + static QByteArrayList *create() { return new QByteArrayList(QByteArrayList() << "Q" << "Byte" << "Array" << "List"); } +}; +template<> struct TestValueFactory<QMetaType::QVariantMap> { + static QVariantMap *create() { return new QVariantMap(); } +}; +template<> struct TestValueFactory<QMetaType::QVariantHash> { + static QVariantHash *create() { return new QVariantHash(); } +}; +template<> struct TestValueFactory<QMetaType::QVariantList> { + static QVariantList *create() { return new QVariantList(QVariantList() << 123 << "Q" << "Variant" << "List"); } +}; +template<> struct TestValueFactory<QMetaType::QChar> { + static QChar *create() { return new QChar(QChar('q')); } +}; +template<> struct TestValueFactory<QMetaType::Long> { + static long *create() { return new long(LONG_MIN); } +}; +template<> struct TestValueFactory<QMetaType::Short> { + static short *create() { return new short(SHRT_MIN); } +}; +template<> struct TestValueFactory<QMetaType::Char> { + static char *create() { return new char('c'); } +}; +template<> struct TestValueFactory<QMetaType::ULong> { + static ulong *create() { return new ulong(ULONG_MAX); } +}; +template<> struct TestValueFactory<QMetaType::UShort> { + static ushort *create() { return new ushort(USHRT_MAX); } +}; +template<> struct TestValueFactory<QMetaType::SChar> { + static signed char *create() { return new signed char(CHAR_MIN); } +}; +template<> struct TestValueFactory<QMetaType::UChar> { + static uchar *create() { return new uchar(UCHAR_MAX); } +}; +template<> struct TestValueFactory<QMetaType::Float> { + static float *create() { return new float(FLT_MIN); } +}; +template<> struct TestValueFactory<QMetaType::QObjectStar> { + static QObject * *create() { return new QObject *(0); } +}; +template<> struct TestValueFactory<QMetaType::VoidStar> { + static void * *create() { return new void *(0); } +}; +template<> struct TestValueFactory<QMetaType::LongLong> { + static qlonglong *create() { return new qlonglong(LLONG_MIN); } +}; +template<> struct TestValueFactory<QMetaType::ULongLong> { + static qulonglong *create() { return new qulonglong(ULLONG_MAX); } +}; +template<> struct TestValueFactory<QMetaType::QStringList> { + static QStringList *create() { return new QStringList(QStringList() << "Q" << "t"); } +}; +template<> struct TestValueFactory<QMetaType::QBitArray> { + static QBitArray *create() { return new QBitArray(QBitArray(256, true)); } +}; +template<> struct TestValueFactory<QMetaType::QDate> { + static QDate *create() { return new QDate(QDate::currentDate()); } +}; +template<> struct TestValueFactory<QMetaType::QTime> { + static QTime *create() { return new QTime(QTime::currentTime()); } +}; +template<> struct TestValueFactory<QMetaType::QDateTime> { + static QDateTime *create() { return new QDateTime(QDateTime::currentDateTime()); } +}; +template<> struct TestValueFactory<QMetaType::QUrl> { + static QUrl *create() { return new QUrl("http://www.example.org"); } +}; +template<> struct TestValueFactory<QMetaType::QLocale> { + static QLocale *create() { return new QLocale(QLocale::c()); } +}; +template<> struct TestValueFactory<QMetaType::QRect> { + static QRect *create() { return new QRect(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QRectF> { + static QRectF *create() { return new QRectF(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QSize> { + static QSize *create() { return new QSize(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QSizeF> { + static QSizeF *create() { return new QSizeF(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QLine> { + static QLine *create() { return new QLine(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QLineF> { + static QLineF *create() { return new QLineF(10, 20, 30, 40); } +}; +template<> struct TestValueFactory<QMetaType::QPoint> { + static QPoint *create() { return new QPoint(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QPointF> { + static QPointF *create() { return new QPointF(10, 20); } +}; +template<> struct TestValueFactory<QMetaType::QEasingCurve> { + static QEasingCurve *create() { return new QEasingCurve(QEasingCurve::InOutElastic); } +}; +template<> struct TestValueFactory<QMetaType::QUuid> { + static QUuid *create() { return new QUuid(); } +}; +template<> struct TestValueFactory<QMetaType::QModelIndex> { + static QModelIndex *create() { return new QModelIndex(); } +}; +template<> struct TestValueFactory<QMetaType::QPersistentModelIndex> { + static QPersistentModelIndex *create() { return new QPersistentModelIndex(); } +}; +template<> struct TestValueFactory<QMetaType::Nullptr> { + static std::nullptr_t *create() { return new std::nullptr_t; } +}; +template<> struct TestValueFactory<QMetaType::QRegExp> { + static QRegExp *create() + { +#ifndef QT_NO_REGEXP + return new QRegExp("A*"); +#else + return 0; +#endif + } +}; +template<> struct TestValueFactory<QMetaType::QRegularExpression> { + static QRegularExpression *create() + { +#ifndef QT_NO_REGEXP + return new QRegularExpression("abc.*def"); +#else + return 0; +#endif + } +}; +template<> struct TestValueFactory<QMetaType::QJsonValue> { + static QJsonValue *create() { return new QJsonValue(123.); } +}; +template<> struct TestValueFactory<QMetaType::QJsonObject> { + static QJsonObject *create() { + QJsonObject *o = new QJsonObject(); + o->insert("a", 123.); + o->insert("b", true); + o->insert("c", QJsonValue::Null); + o->insert("d", QLatin1String("ciao")); + return o; + } +}; +template<> struct TestValueFactory<QMetaType::QJsonArray> { + static QJsonArray *create() { + QJsonArray *a = new QJsonArray(); + a->append(123.); + a->append(true); + a->append(QJsonValue::Null); + a->append(QLatin1String("ciao")); + return a; + } +}; +template<> struct TestValueFactory<QMetaType::QJsonDocument> { + static QJsonDocument *create() { + return new QJsonDocument( + QJsonDocument::fromJson("{ 'foo': 123, 'bar': [true, null, 'ciao'] }") + ); + } +}; +template<> struct TestValueFactory<QMetaType::QVariant> { + static QVariant *create() { return new QVariant(QStringList(QStringList() << "Q" << "t")); } +}; + +#endif // TST_QMETATYPE_H diff --git a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro index 125915047a..cc51b4c661 100644 --- a/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro +++ b/tests/auto/corelib/kernel/qobject/signalbug/signalbug.pro @@ -2,9 +2,6 @@ CONFIG -= app_bundle debug_and_release CONFIG += console DESTDIR = ./ QT = core -wince { - LIBS += coredll.lib -} HEADERS += signalbug.h SOURCES += signalbug.cpp diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 333305d603..91810cdcd8 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -66,6 +66,7 @@ private slots: void connectDisconnectNotify(); void connectDisconnectNotifyPMF(); void disconnectNotify_receiverDestroyed(); + void disconnectNotify_metaObjConnection(); void connectNotify_connectSlotsByName(); void connectDisconnectNotify_shadowing(); void emitInDefinedOrder(); @@ -146,6 +147,7 @@ private slots: void noDeclarativeParentChangedOnDestruction(); void deleteLaterInAboutToBlockHandler(); void mutableFunctor(); + void checkArgumentsForNarrowing(); }; struct QObjectCreatedOnShutdown @@ -923,8 +925,7 @@ void tst_QObject::connectDisconnectNotifyPMF() // Test disconnectNotify when disconnecting by QMetaObject::Connection QVERIFY(QObject::disconnect(conn)); - // disconnectNotify() is not called, but it probably should be. - QVERIFY(s->disconnectedSignals.isEmpty()); + QVERIFY(!s->disconnectedSignals.isEmpty()); // Test connectNotify when connecting by function pointer s->clearNotifications(); @@ -969,6 +970,25 @@ void tst_QObject::disconnectNotify_receiverDestroyed() delete s; } +void tst_QObject::disconnectNotify_metaObjConnection() +{ + NotifyObject *s = new NotifyObject; + NotifyObject *r = new NotifyObject; + + QMetaObject::Connection c = QObject::connect((SenderObject*)s, SIGNAL(signal1()), + (ReceiverObject*)r, SLOT(slot1())); + QVERIFY(c); + QVERIFY(QObject::disconnect(c)); + + QCOMPARE(s->disconnectedSignals.count(), 1); + QCOMPARE(s->disconnectedSignals.at(0), QMetaMethod::fromSignal(&SenderObject::signal1)); + + delete r; + QCOMPARE(s->disconnectedSignals.count(), 1); + + delete s; +} + class ConnectByNameNotifySenderObject : public QObject { Q_OBJECT @@ -1575,11 +1595,7 @@ Q_DECLARE_METATYPE(PropertyObject::Priority) void tst_QObject::threadSignalEmissionCrash() { -#if defined(Q_OS_WINCE) - int loopCount = 100; -#else int loopCount = 1000; -#endif for (int i = 0; i < loopCount; ++i) { QTcpSocket socket; socket.connectToHost("localhost", 80); @@ -6731,6 +6747,515 @@ void tst_QObject::mutableFunctor() QCOMPARE(functor.count, 0); // but the original object should have been copied at connect time } +void tst_QObject::checkArgumentsForNarrowing() +{ + enum UnscopedEnum {}; + enum SignedUnscopedEnum { SignedUnscopedEnumV1 = -1, SignedUnscopedEnumV2 = 1 }; + + QVERIFY(sizeof(UnscopedEnum) <= sizeof(int)); + QVERIFY(sizeof(SignedUnscopedEnum) <= sizeof(int)); + + // floating point to integral + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, bool>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, bool>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, bool>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, short>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, int>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<float, long long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, long long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, long long>::value)); + + + // floating point to a smaller floating point + if (sizeof(double) > sizeof(float)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<double, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, float>::value)); + } + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<float, double>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<float, long double>::value)); + + if (sizeof(long double) > sizeof(double)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long double, float>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<double, long double>::value)); + + + // integral to floating point + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<char, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<char, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<char, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, long double>::value)); + + + // enum to floating point + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, long double>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, float>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, double>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, long double>::value)); + + + // integral to smaller integral + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<bool, bool>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<char, char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<signed char, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, unsigned long long>::value)); + + if (sizeof(bool) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned char>::value)); + + if (sizeof(bool) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned short>::value)); + + if (sizeof(bool) > sizeof(int)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned int>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned int>::value)); + + if (sizeof(bool) > sizeof(long)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long>::value)); + + if (sizeof(bool) > sizeof(long long)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long long>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<bool, unsigned long long>::value)); + + if (sizeof(short) > sizeof(char)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, signed char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, signed char>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<short, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, unsigned long long>::value)); + + if (sizeof(int) > sizeof(short)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned short>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned short>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, unsigned long long>::value)); + + if (sizeof(long) > sizeof(int)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned int>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned int>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<long, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<long, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned long, unsigned long long>::value)); + + if (sizeof(long long) > sizeof(long)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned long>::value)); + } + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<long long, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned long long, unsigned long long>::value)); + + + // integral to integral with different signedness. smaller ones tested above + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<signed char, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned char, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned char, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<short, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned short, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned short, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<int, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned int, int>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<unsigned int, long>::value), sizeof(int) >= sizeof(long)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<unsigned int, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<unsigned long, long long>::value), sizeof(long) >= sizeof(long long)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<long long, unsigned long long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<unsigned long long, long long>::value)); + + // enum to smaller integral + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, UnscopedEnum>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, SignedUnscopedEnum>::value)); + + if (std::is_signed<typename std::underlying_type<UnscopedEnum>::type>::value) { + if (sizeof(UnscopedEnum) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, signed char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, signed char>::value)); + + if (sizeof(UnscopedEnum) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, short>::value)); + + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, int>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, long>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, long long>::value)); + } else { + if (sizeof(UnscopedEnum) > sizeof(bool)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, bool>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, bool>::value)); + + if (sizeof(UnscopedEnum) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned char>::value)); + + if (sizeof(UnscopedEnum) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned short>::value)); + + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned int>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned long>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<UnscopedEnum, unsigned long long>::value)); + } + + QVERIFY(std::is_signed<typename std::underlying_type<SignedUnscopedEnum>::type>::value); + + if (sizeof(SignedUnscopedEnum) > sizeof(char)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, signed char>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, signed char>::value)); + + if (sizeof(SignedUnscopedEnum) > sizeof(short)) + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, short>::value)); + else + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, short>::value)); + + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, int>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, long>::value)); + QVERIFY(!(QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, long long>::value)); + + + enum class ScopedEnumBackedBySChar : signed char { A }; + enum class ScopedEnumBackedByUChar : unsigned char { A }; + enum class ScopedEnumBackedByShort : short { A }; + enum class ScopedEnumBackedByUShort : unsigned short { A }; + enum class ScopedEnumBackedByInt : int { A }; + enum class ScopedEnumBackedByUInt : unsigned int { A }; + enum class ScopedEnumBackedByLong : long { A }; + enum class ScopedEnumBackedByULong : unsigned long { A }; + enum class ScopedEnumBackedByLongLong : long long { A }; + enum class ScopedEnumBackedByULongLong : unsigned long long { A }; + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, ScopedEnumBackedBySChar>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, ScopedEnumBackedByUChar>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, ScopedEnumBackedByShort>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, ScopedEnumBackedByUShort>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, ScopedEnumBackedByInt>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, ScopedEnumBackedByUInt>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, ScopedEnumBackedByLong>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, ScopedEnumBackedByULong>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, ScopedEnumBackedByLongLong>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, ScopedEnumBackedByULongLong>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, long long>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, unsigned long long>::value)); + + if (sizeof(short) > sizeof(char)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, signed char>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned char>::value)); + } + + if (sizeof(int) > sizeof(short)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, short>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned short>::value)); + } + + if (sizeof(long) > sizeof(int)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, int>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned int>::value)); + } + + if (sizeof(long long) > sizeof(long)) { + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, unsigned long>::value)); + } + + // different signedness of the underlying type + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<SignedUnscopedEnum, unsigned long long>::value)); + + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedBySChar, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByShort, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByInt, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLong, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByLongLong, unsigned long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, signed char>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUChar, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, short>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, int>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUShort, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, int>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long>::value), sizeof(ScopedEnumBackedByUInt) >= sizeof(long)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByUInt, long long>::value)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long>::value)); + QCOMPARE((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULong, long long>::value), sizeof(ScopedEnumBackedByULong) >= sizeof(long long)); + + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, signed char>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, short>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, int>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, long>::value)); + QVERIFY((QtPrivate::AreArgumentsNarrowedBase<ScopedEnumBackedByULongLong, long long>::value)); + + // other types which should be always unaffected + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<void *, void *>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, QString>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString &, QString &>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<const QString &, const QString &>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QObject, QObject>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QObject *, QObject *>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<const QObject *, const QObject *>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<std::nullptr_t, std::nullptr_t>::value)); + + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, QObject>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, QVariant>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, void *>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<QString, long long>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<bool, const QObject *&>::value)); + QVERIFY((!QtPrivate::AreArgumentsNarrowedBase<int (*)(bool), void (QObject::*)()>::value)); +} + // Test for QtPrivate::HasQ_OBJECT_Macro Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value); Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value); diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp index b6f6d2a7f3..26caff4301 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp @@ -90,7 +90,7 @@ private slots: // extreme cases void useTooMuchMemory(); -#if !defined(Q_OS_HPUX) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_HPUX) void attachTooMuch(); #endif @@ -516,8 +516,7 @@ void tst_QSharedMemory::useTooMuchMemory() attach before the system runs out of resources. */ // HPUX doesn't allow for multiple attaches per process. -// For WinCE, this test nearly kills the system, so skip it. -#if !defined(Q_OS_HPUX) && !defined(Q_OS_WINCE) +#if !defined(Q_OS_HPUX) void tst_QSharedMemory::attachTooMuch() { QSKIP("disabled"); @@ -576,9 +575,7 @@ void tst_QSharedMemory::simpleProducerConsumer() char *get = (char*)consumer.data(); // On Windows CE you always have ReadWrite access. Thus // ViewMapOfFile returns the same pointer -#if !defined(Q_OS_WINCE) QVERIFY(put != get); -#endif for (int i = 0; i < size; ++i) { put[i] = 'Q'; QCOMPARE(get[i], 'Q'); diff --git a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro index 58e4b98af7..04806de5f7 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro +++ b/tests/auto/corelib/kernel/qsocketnotifier/qsocketnotifier.pro @@ -3,6 +3,6 @@ TARGET = tst_qsocketnotifier QT = core-private network-private testlib SOURCES = tst_qsocketnotifier.cpp -requires(contains(QT_CONFIG,private_tests)) +requires(qtConfig(private_tests)) include(../../../network/socket/platformsocketengine/platformsocketengine.pri) diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 6fd192c357..fe97695d19 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -52,6 +52,7 @@ private slots: void remainingTime(); void remainingTimeDuringActivation_data(); void remainingTimeDuringActivation(); + void basic_chrono(); void livelock_data(); void livelock(); void timerInfiniteRecursion_data(); @@ -68,6 +69,7 @@ private slots: void singleShotStaticFunctionZeroTimeout(); void recurseOnTimeoutAndStopTimer(); void singleShotToFunctors(); + void singleShot_chrono(); void crossThreadSingleShotToFunctor(); void dontBlockEvents(); @@ -214,6 +216,67 @@ void tst_QTimer::remainingTimeDuringActivation() } } +namespace { + +#if QT_HAS_INCLUDE(<chrono>) + template <typename T> + std::chrono::milliseconds to_ms(T t) + { return std::chrono::duration_cast<std::chrono::milliseconds>(t); } +#endif + +} // unnamed namespace + +void tst_QTimer::basic_chrono() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires C++11 <chrono> support"); +#else + // duplicates zeroTimer, singleShotTimeout, interval and remainingTime + using namespace std::chrono; + TimerHelper helper; + QTimer timer; + timer.setInterval(to_ms(nanoseconds(0))); + timer.start(); + QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(0)); + QCOMPARE(timer.remainingTimeAsDuration().count(), milliseconds::rep(0)); + + connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout())); + + QCoreApplication::processEvents(); + + QCOMPARE(helper.count, 1); + + helper.count = 0; + timer.start(milliseconds(100)); + QCOMPARE(helper.count, 0); + + QTest::qWait(TIMEOUT_TIMEOUT); + QVERIFY(helper.count > 0); + int oldCount = helper.count; + + QTest::qWait(TIMEOUT_TIMEOUT); + QVERIFY(helper.count > oldCount); + + helper.count = 0; + timer.start(to_ms(microseconds(200000))); + QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(200)); + QTest::qWait(50); + QCOMPARE(helper.count, 0); + + milliseconds rt = timer.remainingTimeAsDuration(); + QVERIFY2(qAbs(rt.count() - 150) < 50, qPrintable(QString::number(rt.count()))); + + helper.count = 0; + timer.setSingleShot(true); + timer.start(milliseconds(100)); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + helper.count = 0; +#endif +} + void tst_QTimer::livelock_data() { QTest::addColumn<int>("interval"); @@ -295,9 +358,6 @@ void tst_QTimer::livelock() QTRY_COMPARE(tester.timeoutsForFirst, 1); QCOMPARE(tester.timeoutsForExtra, 0); QTRY_COMPARE(tester.timeoutsForSecond, 1); -#if defined(Q_OS_WINCE) - QEXPECT_FAIL("non-zero timer", "Windows CE devices often too slow", Continue); -#endif QVERIFY(tester.postEventAtRightTime); } @@ -790,6 +850,51 @@ void tst_QTimer::singleShotToFunctors() _t = Q_NULLPTR; } +void tst_QTimer::singleShot_chrono() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires C++11 <chrono> support"); +#else + // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors + using namespace std::chrono; + TimerHelper helper; + + QTimer::singleShot(hours(0), &helper, SLOT(timeout())); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + QTest::qWait(500); + QCOMPARE(helper.count, 1); + + TimerHelper nhelper; + + QTimer::singleShot(seconds(0), &nhelper, &TimerHelper::timeout); + QCoreApplication::processEvents(); + QCOMPARE(nhelper.count, 1); + QCoreApplication::processEvents(); + QCOMPARE(nhelper.count, 1); + + int count = 0; + QTimer::singleShot(to_ms(microseconds(0)), CountedStruct(&count)); + QCoreApplication::processEvents(); + QCOMPARE(count, 1); + + _e.reset(new QEventLoop); + QTimer::singleShot(0, &StaticEventLoop::quitEventLoop); + QCOMPARE(_e->exec(), 0); + + QObject c3; + QTimer::singleShot(milliseconds(500), &c3, CountedStruct(&count)); + QTest::qWait(800); + QCOMPARE(count, 2); + + QTimer::singleShot(0, [&count] { ++count; }); + QCoreApplication::processEvents(); + QCOMPARE(count, 3); + + _e.reset(); +#endif +} + class DontBlockEvents : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/kernel/qvariant/qvariant.pro b/tests/auto/corelib/kernel/qvariant/qvariant.pro index 33e8b6e2ad..96071f9f73 100644 --- a/tests/auto/corelib/kernel/qvariant/qvariant.pro +++ b/tests/auto/corelib/kernel/qvariant/qvariant.pro @@ -5,7 +5,7 @@ INCLUDEPATH += $$PWD/../../../other/qvariant_common SOURCES = tst_qvariant.cpp RESOURCES += qvariant.qrc DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -contains(QT_CONFIG, c++11): CONFIG += c++11 -!contains(QT_CONFIG, doubleconversion):!contains(QT_CONFIG, system-doubleconversion) { +qtConfig(c++11): CONFIG += c++11 +!qtConfig(doubleconversion):!qtConfig(system-doubleconversion) { DEFINES += QT_NO_DOUBLECONVERSION } diff --git a/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin b/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin Binary files differindex ee3da63a18..e3a897c37d 100644 --- a/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin +++ b/tests/auto/corelib/kernel/qvariant/stream/qt5.0/qdatetime.bin diff --git a/tests/auto/corelib/mimetypes/mimetypes.pro b/tests/auto/corelib/mimetypes/mimetypes.pro index 9063d677e7..9dd091374f 100644 --- a/tests/auto/corelib/mimetypes/mimetypes.pro +++ b/tests/auto/corelib/mimetypes/mimetypes.pro @@ -4,5 +4,5 @@ SUBDIRS = \ qmimetype \ qmimedatabase -!contains(QT_CONFIG, private_tests): SUBDIRS -= \ +!qtConfig(private_tests): SUBDIRS -= \ qmimetype diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp index 61ca1a5ddd..2cf9ea4913 100644 --- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp +++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp @@ -41,7 +41,6 @@ #include <QtCore/QStandardPaths> #include <QtCore/QTemporaryDir> #include <QtCore/QTextStream> -#include <QFutureSynchronizer> #include <QtConcurrent/QtConcurrentRun> #include <QtTest/QtTest> @@ -116,7 +115,7 @@ Q_CONSTRUCTOR_FUNCTION(initializeLang) static QString seedAndTemplate() { - qsrand(QDateTime::currentDateTimeUtc().toTime_t()); + qsrand(QDateTime::currentSecsSinceEpoch()); return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX"; } @@ -844,18 +843,18 @@ void tst_QMimeDatabase::findByFile() void tst_QMimeDatabase::fromThreads() { - QThreadPool::globalInstance()->setMaxThreadCount(20); + QThreadPool tp; + tp.setMaxThreadCount(20); // Note that data-based tests cannot be used here (QTest::fetchData asserts). - QFutureSynchronizer<void> sync; - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::mimeTypeForName)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::aliases)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::allMimeTypes)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::icons)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::inheritance)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::knownSuffix)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::mimeTypeForFileWithContent)); - sync.addFuture(QtConcurrent::run(this, &tst_QMimeDatabase::allMimeTypes)); // a second time - // sync dtor blocks waiting for finished + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::mimeTypeForName); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::aliases); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::allMimeTypes); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::icons); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::inheritance); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::knownSuffix); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::mimeTypeForFileWithContent); + QtConcurrent::run(&tp, this, &tst_QMimeDatabase::allMimeTypes); // a second time + QVERIFY(tp.waitForDone(60000)); } #ifndef QT_NO_PROCESS diff --git a/tests/auto/corelib/plugin/plugin.pro b/tests/auto/corelib/plugin/plugin.pro index 777e920995..774edc655a 100644 --- a/tests/auto/corelib/plugin/plugin.pro +++ b/tests/auto/corelib/plugin/plugin.pro @@ -3,8 +3,7 @@ SUBDIRS=\ qfactoryloader \ quuid -load(qfeatures) -!contains(QT_DISABLED_FEATURES, library): SUBDIRS += \ +qtConfig(library): SUBDIRS += \ qpluginloader \ qplugin \ qlibrary diff --git a/tests/auto/corelib/plugin/qfactoryloader/test/test.pro b/tests/auto/corelib/plugin/qfactoryloader/test/test.pro index f1e76c31bf..3345651730 100644 --- a/tests/auto/corelib/plugin/qfactoryloader/test/test.pro +++ b/tests/auto/corelib/plugin/qfactoryloader/test/test.pro @@ -19,7 +19,6 @@ win32 { mac: CONFIG -= app_bundle -load(qfeatures) -contains(QT_DISABLED_FEATURES, library) { +!qtConfig(library) { LIBS += -L ../bin/ -lplugin1 -lplugin2 } diff --git a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro index 44bd0be14e..3e15861021 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib/lib.pro +++ b/tests/auto/corelib/plugin/qlibrary/lib/lib.pro @@ -6,7 +6,6 @@ TARGET = mylib DESTDIR = ../ QT = core -wince: DEFINES += WIN32_MSVC win32-msvc: DEFINES += WIN32_MSVC # This project is testdata for tst_qlibrary diff --git a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro index d55747501c..bd73227b3d 100644 --- a/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro +++ b/tests/auto/corelib/plugin/qlibrary/lib2/lib2.pro @@ -7,7 +7,6 @@ DESTDIR = ../ VERSION = 2 QT = core -wince: DEFINES += WIN32_MSVC win32-msvc: DEFINES += WIN32_MSVC # Force a copy of the library to have an extension that is non-standard. diff --git a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp index ed41ab51e1..42fed1191b 100644 --- a/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp +++ b/tests/auto/corelib/plugin/qlibrary/tst_qlibrary.cpp @@ -189,7 +189,7 @@ void tst_QLibrary::load_data() QTest::newRow("ok (libmylib ver. 1)") << appDir + "/libmylib" <<true; #endif -# if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +# if defined(Q_OS_WIN32) QTest::newRow( "ok01 (with suffix)" ) << appDir + "/mylib.dll" << true; QTest::newRow( "ok02 (with non-standard suffix)" ) << appDir + "/mylib.dl2" << true; QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.dll" << true; @@ -223,10 +223,6 @@ void tst_QLibrary::unload_data() QString appDir = QCoreApplication::applicationDirPath(); QTest::newRow( "mylib" ) << appDir + "/mylib" << true; -#ifdef Q_OS_MAC - if (QSysInfo::MacintoshVersion <= QSysInfo::MV_10_3) - QEXPECT_FAIL("mylib", "dlcompat cannot unload libraries", Continue); -#endif QTest::newRow( "ok01" ) << appDir + "/nolib" << false; } @@ -346,11 +342,7 @@ void tst_QLibrary::errorString_data() QTest::newRow("bad load()") << (int)Load << QString("nosuchlib") << false << QString("Cannot load library nosuchlib: .*"); QTest::newRow("call errorString() on QLibrary with no d-pointer (crashtest)") << (int)(Load | DontSetFileName) << QString() << false << QString("Unknown error"); -#ifdef Q_OS_WINCE - QTest::newRow("bad resolve") << (int)Resolve << appDir + "/mylib" << false << QString("Cannot resolve symbol \"nosuchsymbol\" in .*: .*"); -#else QTest::newRow("bad resolve") << (int)Resolve << appDir + "/mylib" << false << QString("Cannot resolve symbol \"nosuchsymbol\" in \\S+: .*"); -#endif QTest::newRow("good resolve") << (int)Resolve << appDir + "/mylib" << true << QString("Unknown error"); #ifdef Q_OS_WIN @@ -414,7 +406,7 @@ void tst_QLibrary::loadHints_data() QString appDir = QCoreApplication::applicationDirPath(); lh |= QLibrary::ResolveAllSymbolsHint; -# if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) +# if defined(Q_OS_WIN32) || defined(Q_OS_WINRT) QTest::newRow( "ok01 (with suffix)" ) << appDir + "/mylib.dll" << int(lh) << true; QTest::newRow( "ok02 (with non-standard suffix)" ) << appDir + "/mylib.dl2" << int(lh) << true; QTest::newRow( "ok03 (with many dots)" ) << appDir + "/system.qt.test.mylib.dll" << int(lh) << true; @@ -467,13 +459,8 @@ void tst_QLibrary::fileName_data() QTest::newRow( "ok02" ) << sys_qualifiedLibraryName(QLatin1String("mylib")) << sys_qualifiedLibraryName(QLatin1String("mylib")); #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -#ifndef Q_OS_WINCE QTest::newRow( "ok03" ) << "user32" << "USER32.dll"; -#else - QTest::newRow( "ok03" ) << "coredll" - << "coredll.dll"; -#endif #endif } diff --git a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp index 874429aab7..ee7cf7ded8 100644 --- a/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp +++ b/tests/auto/corelib/plugin/qplugin/tst_qplugin.cpp @@ -61,7 +61,8 @@ void tst_QPlugin::initTestCase() void tst_QPlugin::loadDebugPlugin() { - foreach (QString fileName, dir.entryList(QStringList() << "*debug*", QDir::Files)) { + const auto fileNames = dir.entryList(QStringList() << "*debug*", QDir::Files); + for (const QString &fileName : fileNames) { if (!QLibrary::isLibrary(fileName)) continue; QPluginLoader loader(dir.filePath(fileName)); @@ -87,8 +88,8 @@ void tst_QPlugin::loadDebugPlugin() void tst_QPlugin::loadReleasePlugin() { - foreach (QString fileName, dir.entryList(QStringList() << "*release*", QDir::Files)) { - if (!QLibrary::isLibrary(fileName)) + const auto fileNames = dir.entryList(QStringList() << "*release*", QDir::Files); + for (const QString &fileName : fileNames) { continue; QPluginLoader loader(dir.filePath(fileName)); #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) diff --git a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro index 83d00f7cd8..c681f5585c 100644 --- a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro +++ b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro @@ -5,7 +5,7 @@ SUBDIRS = lib \ theplugin \ tst !android: !win32: !mac: SUBDIRS += almostplugin -macx-*: contains(QT_CONFIG, private_tests): SUBDIRS += machtest +macx-*: qtConfig(private_tests): SUBDIRS += machtest TARGET = tst_qpluginloader # no special install rule for subdir diff --git a/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro b/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro index 101392927c..5f9fa6664b 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro +++ b/tests/auto/corelib/plugin/qpluginloader/tst/tst.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = ../tst_qpluginloader QT = core testlib -contains(QT_CONFIG, private_tests): QT += core-private +qtConfig(private_tests): QT += core-private SOURCES = ../tst_qpluginloader.cpp ../fakeplugin.cpp HEADERS = ../theplugin/plugininterface.h CONFIG -= app_bundle diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp index bc853de24e..499d276ef8 100644 --- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp +++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp @@ -140,11 +140,6 @@ void tst_QPluginLoader::cleanup() void tst_QPluginLoader::errorString() { -#if defined(Q_OS_WINCE) - // On WinCE we need an QCoreApplication object for current dir - int argc = 0; - QCoreApplication app(argc,0); -#endif const QString unknown(QLatin1String("Unknown error")); { diff --git a/tests/auto/corelib/thread/qmutex/qmutex.pro b/tests/auto/corelib/thread/qmutex/qmutex.pro index 229e57eb89..cb9d364b71 100644 --- a/tests/auto/corelib/thread/qmutex/qmutex.pro +++ b/tests/auto/corelib/thread/qmutex/qmutex.pro @@ -2,3 +2,4 @@ CONFIG += testcase TARGET = tst_qmutex QT = core testlib SOURCES = tst_qmutex.cpp +win32:QT += core-private diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 594bae674c..bf778e9fd1 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -31,16 +31,38 @@ #include <qatomic.h> #include <qcoreapplication.h> -#include <qdatetime.h> +#include <qelapsedtimer.h> #include <qmutex.h> #include <qthread.h> #include <qwaitcondition.h> +#ifdef Q_OS_WIN +#include <private/qsystemlibrary_p.h> +#include <cmath> +#endif + class tst_QMutex : public QObject { Q_OBJECT +public: + enum class TimeUnit { + Nanoseconds, + Microseconds, + Milliseconds, + Seconds, + }; + Q_ENUM(TimeUnit); + private slots: - void tryLock(); + void initTestCase(); + void convertToMilliseconds_data(); + void convertToMilliseconds(); + void tryLock_non_recursive(); + void try_lock_for_non_recursive(); + void try_lock_until_non_recursive(); + void tryLock_recursive(); + void try_lock_for_recursive(); + void try_lock_until_recursive(); void lock_unlock_locked_tryLock(); void stressTest(); void tryLockRace(); @@ -48,6 +70,8 @@ private slots: void tryLockNegative_data(); void tryLockNegative(); void moreStress(); +private: + void initializeSystemTimersResolution(); }; static const int iterations = 100; @@ -58,257 +82,922 @@ QSemaphore testsTurn; QSemaphore threadsTurn; enum { waitTime = 100 }; +uint systemTimersResolution = 1; + +#if QT_HAS_INCLUDE(<chrono>) +static Q_CONSTEXPR std::chrono::milliseconds waitTimeAsDuration(waitTime); +#endif + +/* + Depending on the OS, tryWaits may return early than expected because of the + resolution of the underlying timer is too coarse. E.g.: on Windows + WaitForSingleObjectEx does *not* use high resolution multimedia timers, and + it's actually very coarse, about 16msec by default. + + Try to find out the timer resolution in here, so that the tryLock tests can + actually take into account early wakes. +*/ +void tst_QMutex::initializeSystemTimersResolution() +{ +#ifdef Q_OS_WIN + // according to MSDN, Windows can default up to this + systemTimersResolution = 16; + + // private API. There's no way on Windows to otherwise know the + // actual resolution of the application's timers (you can only set it) + // cf. https://stackoverflow.com/questions/7685762/windows-7-timing-functions-how-to-use-getsystemtimeadjustment-correctly/11743614#11743614 + typedef NTSTATUS (NTAPI *NtQueryTimerResolutionType)(OUT PULONG MinimumResolution, + OUT PULONG MaximumResolution, + OUT PULONG ActualResolution); + + const NtQueryTimerResolutionType NtQueryTimerResolutionPtr = + reinterpret_cast<NtQueryTimerResolutionType>(QSystemLibrary::resolve(QStringLiteral("ntdll"), "NtQueryTimerResolution")); + + if (!NtQueryTimerResolutionPtr) + return; + + ULONG minimumResolution; + ULONG maximumResolution; + ULONG actualResolution; + + if (!NtQueryTimerResolutionPtr(&minimumResolution, &maximumResolution, &actualResolution)) { + // the result is in 100ns units => adjust to msec + const double actualResolutionMsec = actualResolution / 10000.0; + systemTimersResolution = static_cast<int>(std::ceil(actualResolutionMsec)); + } +#endif // Q_OS_WIN +} + +void tst_QMutex::initTestCase() +{ + initializeSystemTimersResolution(); +} -void tst_QMutex::tryLock() +void tst_QMutex::convertToMilliseconds_data() { - // test non-recursive mutex + QTest::addColumn<TimeUnit>("unit"); + QTest::addColumn<double>("doubleValue"); + QTest::addColumn<qint64>("intValue"); + QTest::addColumn<qint64>("expected"); + + + auto add = [](TimeUnit unit, double d, long long i, qint64 expected) { + const QScopedArrayPointer<char> enumName(QTest::toString(unit)); + QTest::newRow(qPrintable(QString::asprintf("%s:%f:%lld", enumName.data(), d, i))) + << unit << d << qint64(i) << expected; + }; + + auto forAllUnitsAdd = [=](double d, long long i, qint64 expected) { + for (auto unit : {TimeUnit::Nanoseconds, TimeUnit::Microseconds, TimeUnit::Milliseconds, TimeUnit::Seconds}) + add(unit, d, i, expected); + }; + + forAllUnitsAdd(-0.5, -1, 0); // all negative values result in 0 + + forAllUnitsAdd(0, 0, 0); + + add(TimeUnit::Nanoseconds, 1, 1, 1); + add(TimeUnit::Nanoseconds, 1000 * 1000, 1000 * 1000, 1); + add(TimeUnit::Nanoseconds, 1000 * 1000 + 0.5, 1000 * 1000 + 1, 2); + + add(TimeUnit::Microseconds, 1, 1, 1); + add(TimeUnit::Microseconds, 1000, 1000, 1); + add(TimeUnit::Microseconds, 1000 + 0.5, 1000 + 1, 2); + + add(TimeUnit::Milliseconds, 1, 1, 1); + add(TimeUnit::Milliseconds, 1.5, 2, 2); + + add(TimeUnit::Seconds, 0.9991, 1, 1000); + + // + // overflowing int results in INT_MAX (equivalent to a spurious wakeup after ~24 days); check it: + // + + // spot on: + add(TimeUnit::Nanoseconds, INT_MAX * 1000. * 1000, INT_MAX * Q_INT64_C(1000) * 1000, INT_MAX); + add(TimeUnit::Microseconds, INT_MAX * 1000., INT_MAX * Q_INT64_C(1000), INT_MAX); + add(TimeUnit::Milliseconds, INT_MAX, INT_MAX, INT_MAX); + + // minimally above: + add(TimeUnit::Nanoseconds, INT_MAX * 1000. * 1000 + 1, INT_MAX * Q_INT64_C(1000) * 1000 + 1, INT_MAX); + add(TimeUnit::Microseconds, INT_MAX * 1000. + 1, INT_MAX * Q_INT64_C(1000) + 1, INT_MAX); + add(TimeUnit::Milliseconds, INT_MAX + 1., INT_MAX + Q_INT64_C(1), INT_MAX); + add(TimeUnit::Seconds, INT_MAX / 1000. + 1, INT_MAX / 1000 + 1, INT_MAX); + + // minimally below: + add(TimeUnit::Nanoseconds, INT_MAX * 1000. * 1000 - 1, INT_MAX * Q_INT64_C(1000) * 1000 - 1, INT_MAX); + add(TimeUnit::Microseconds, INT_MAX * 1000. - 1, INT_MAX * Q_INT64_C(1000) - 1, INT_MAX); + add(TimeUnit::Milliseconds, INT_MAX - 0.1, INT_MAX , INT_MAX); + +} + +void tst_QMutex::convertToMilliseconds() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#else + QFETCH(TimeUnit, unit); + QFETCH(double, doubleValue); + QFETCH(qint64, intValue); + QFETCH(qint64, expected); + + Q_CONSTEXPR qint64 maxShort = std::numeric_limits<short>::max(); + Q_CONSTEXPR qint64 maxInt = std::numeric_limits<int>::max(); + Q_CONSTEXPR qint64 maxUInt = std::numeric_limits<uint>::max(); + + switch (unit) { +#define CASE(Unit, Period) \ + case TimeUnit::Unit: \ + DO(double, Period, doubleValue); \ + if (intValue < maxShort) \ + DO(short, Period, short(intValue)); \ + if (intValue < maxInt) \ + DO(int, Period, int(intValue)); \ + DO(qint64, Period, intValue); \ + if (intValue >= 0) { \ + if (intValue < maxUInt) \ + DO(uint, Period, uint(intValue)); \ + DO(quint64, Period, quint64(intValue)); \ + } \ + break +#define DO(Rep, Period, val) \ + do { \ + const std::chrono::duration<Rep, Period> wait((val)); \ + QCOMPARE(QMutex::convertToMilliseconds(wait), expected); \ + } while (0) + + CASE(Nanoseconds, std::nano); + CASE(Microseconds, std::micro); + CASE(Milliseconds, std::milli); + CASE(Seconds, std::ratio<1>); +#undef DO +#undef CASE + } +#endif +} + +void tst_QMutex::tryLock_non_recursive() +{ + class Thread : public QThread { - class Thread : public QThread + public: + void run() { - public: - void run() - { - testsTurn.release(); - - // TEST 1: thread can't acquire lock - threadsTurn.acquire(); - QVERIFY(!normalMutex.tryLock()); - testsTurn.release(); - - // TEST 2: thread can acquire lock - threadsTurn.acquire(); - QVERIFY(normalMutex.tryLock()); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - QVERIFY(!normalMutex.tryLock()); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - normalMutex.unlock(); - testsTurn.release(); - - // TEST 3: thread can't acquire lock, timeout = waitTime - threadsTurn.acquire(); - QTime timer; - timer.start(); - QVERIFY(!normalMutex.tryLock(waitTime)); - QVERIFY(timer.elapsed() >= waitTime); - testsTurn.release(); - - // TEST 4: thread can acquire lock, timeout = waitTime - threadsTurn.acquire(); - timer.start(); - QVERIFY(normalMutex.tryLock(waitTime)); - QVERIFY(timer.elapsed() <= waitTime); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - timer.start(); - // it's non-recursive, so the following lock needs to fail - QVERIFY(!normalMutex.tryLock(waitTime)); - QVERIFY(timer.elapsed() >= waitTime); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - normalMutex.unlock(); - testsTurn.release(); - - // TEST 5: thread can't acquire lock, timeout = 0 - threadsTurn.acquire(); - QVERIFY(!normalMutex.tryLock(0)); - testsTurn.release(); - - // TEST 6: thread can acquire lock, timeout = 0 - threadsTurn.acquire(); - timer.start(); - QVERIFY(normalMutex.tryLock(0)); - QVERIFY(timer.elapsed() < waitTime); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - QVERIFY(!normalMutex.tryLock(0)); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - normalMutex.unlock(); - testsTurn.release(); - - // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795) - threadsTurn.acquire(); - timer.start(); - QVERIFY(normalMutex.tryLock(3000)); - QVERIFY(timer.elapsed() < 3000); - normalMutex.unlock(); - testsTurn.release(); - - threadsTurn.acquire(); - } - }; + testsTurn.release(); + + // TEST 1: thread can't acquire lock + threadsTurn.acquire(); + QVERIFY(!normalMutex.tryLock()); + testsTurn.release(); + + // TEST 2: thread can acquire lock + threadsTurn.acquire(); + QVERIFY(normalMutex.tryLock()); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(!normalMutex.tryLock()); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 3: thread can't acquire lock, timeout = waitTime + threadsTurn.acquire(); + QElapsedTimer timer; + timer.start(); + QVERIFY(!normalMutex.tryLock(waitTime)); + QVERIFY(timer.elapsed() >= waitTime - systemTimersResolution); + testsTurn.release(); + + // TEST 4: thread can acquire lock, timeout = waitTime + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.tryLock(waitTime)); + QVERIFY(timer.elapsed() <= waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + timer.start(); + // it's non-recursive, so the following lock needs to fail + QVERIFY(!normalMutex.tryLock(waitTime)); + QVERIFY(timer.elapsed() >= waitTime - systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 5: thread can't acquire lock, timeout = 0 + threadsTurn.acquire(); + QVERIFY(!normalMutex.tryLock(0)); + testsTurn.release(); + + // TEST 6: thread can acquire lock, timeout = 0 + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.tryLock(0)); + QVERIFY(timer.elapsed() < waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(!normalMutex.tryLock(0)); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795) + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.tryLock(3000)); + QVERIFY(timer.elapsed() < 3000 + systemTimersResolution); + normalMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + } + }; - Thread thread; - thread.start(); + Thread thread; + thread.start(); + + // TEST 1: thread can't acquire lock + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 2: thread can acquire lock + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 3: thread can't acquire lock, timeout = waitTime + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 4: thread can acquire lock, timeout = waitTime + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 5: thread can't acquire lock, timeout = 0 + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 6: thread can acquire lock, timeout = 0 + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 7: thread can acquire lock, timeout = 3000 (QTBUG-24795) + testsTurn.acquire(); + normalMutex.lock(); + threadsTurn.release(); + QThread::msleep(100); + normalMutex.unlock(); + + // wait for thread to finish + testsTurn.acquire(); + threadsTurn.release(); + thread.wait(); +} - // TEST 1: thread can't acquire lock - testsTurn.acquire(); - normalMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - threadsTurn.release(); - - // TEST 2: thread can acquire lock - testsTurn.acquire(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - normalMutex.unlock(); - threadsTurn.release(); - - // TEST 3: thread can't acquire lock, timeout = waitTime - testsTurn.acquire(); - normalMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - threadsTurn.release(); - - // TEST 4: thread can acquire lock, timeout = waitTime - testsTurn.acquire(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - normalMutex.unlock(); - threadsTurn.release(); - - // TEST 5: thread can't acquire lock, timeout = 0 - testsTurn.acquire(); - normalMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - threadsTurn.release(); - - // TEST 6: thread can acquire lock, timeout = 0 - testsTurn.acquire(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - normalMutex.unlock(); - threadsTurn.release(); - - // TEST 7: thread can acquire lock, timeout = 3000 (QTBUG-24795) - testsTurn.acquire(); - normalMutex.lock(); - threadsTurn.release(); - QThread::msleep(100); - normalMutex.unlock(); - - // wait for thread to finish - testsTurn.acquire(); - threadsTurn.release(); - thread.wait(); - } +void tst_QMutex::try_lock_for_non_recursive() { +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#else + class Thread : public QThread + { + public: + void run() + { + testsTurn.release(); + + // TEST 1: thread can't acquire lock + threadsTurn.acquire(); + QVERIFY(!normalMutex.try_lock()); + testsTurn.release(); + + // TEST 2: thread can acquire lock + threadsTurn.acquire(); + QVERIFY(normalMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(!normalMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 3: thread can't acquire lock, timeout = waitTime + threadsTurn.acquire(); + QElapsedTimer timer; + timer.start(); + QVERIFY(!normalMutex.try_lock_for(waitTimeAsDuration)); + QVERIFY(timer.elapsed() >= waitTime - systemTimersResolution); + testsTurn.release(); + + // TEST 4: thread can acquire lock, timeout = waitTime + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.try_lock_for(waitTimeAsDuration)); + QVERIFY(timer.elapsed() <= waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + timer.start(); + // it's non-recursive, so the following lock needs to fail + QVERIFY(!normalMutex.try_lock_for(waitTimeAsDuration)); + QVERIFY(timer.elapsed() >= waitTime - systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 5: thread can't acquire lock, timeout = 0 + threadsTurn.acquire(); + QVERIFY(!normalMutex.try_lock_for(std::chrono::milliseconds::zero())); + testsTurn.release(); + + // TEST 6: thread can acquire lock, timeout = 0 + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.try_lock_for(std::chrono::milliseconds::zero())); + QVERIFY(timer.elapsed() < waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(!normalMutex.try_lock_for(std::chrono::milliseconds::zero())); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795) + threadsTurn.acquire(); + timer.start(); + QVERIFY(normalMutex.try_lock_for(std::chrono::milliseconds(3000))); + QVERIFY(timer.elapsed() < 3000 + systemTimersResolution); + normalMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + } + }; + + Thread thread; + thread.start(); + + // TEST 1: thread can't acquire lock + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 2: thread can acquire lock + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 3: thread can't acquire lock, timeout = waitTime + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 4: thread can acquire lock, timeout = waitTime + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 5: thread can't acquire lock, timeout = 0 + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 6: thread can acquire lock, timeout = 0 + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 7: thread can acquire lock, timeout = 3000 (QTBUG-24795) + testsTurn.acquire(); + normalMutex.lock(); + threadsTurn.release(); + QThread::msleep(100); + normalMutex.unlock(); + + // wait for thread to finish + testsTurn.acquire(); + threadsTurn.release(); + thread.wait(); +#endif +} - // test recursive mutex +void tst_QMutex::try_lock_until_non_recursive() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#else + class Thread : public QThread { - class Thread : public QThread + public: + void run() { - public: - void run() - { - testsTurn.release(); - - threadsTurn.acquire(); - QVERIFY(!recursiveMutex.tryLock()); - testsTurn.release(); - - threadsTurn.acquire(); - QVERIFY(recursiveMutex.tryLock()); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - QVERIFY(recursiveMutex.tryLock()); - QVERIFY(lockCount.testAndSetRelaxed(1, 2)); - QVERIFY(lockCount.testAndSetRelaxed(2, 1)); - recursiveMutex.unlock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - recursiveMutex.unlock(); - testsTurn.release(); - - threadsTurn.acquire(); - QTime timer; - timer.start(); - QVERIFY(!recursiveMutex.tryLock(waitTime)); - QVERIFY(timer.elapsed() >= waitTime); - QVERIFY(!recursiveMutex.tryLock(0)); - testsTurn.release(); - - threadsTurn.acquire(); - timer.start(); - QVERIFY(recursiveMutex.tryLock(waitTime)); - QVERIFY(timer.elapsed() <= waitTime); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - QVERIFY(recursiveMutex.tryLock(waitTime)); - QVERIFY(lockCount.testAndSetRelaxed(1, 2)); - QVERIFY(lockCount.testAndSetRelaxed(2, 1)); - recursiveMutex.unlock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - recursiveMutex.unlock(); - testsTurn.release(); - - threadsTurn.acquire(); - QVERIFY(!recursiveMutex.tryLock(0)); - QVERIFY(!recursiveMutex.tryLock(0)); - testsTurn.release(); - - threadsTurn.acquire(); - timer.start(); - QVERIFY(recursiveMutex.tryLock(0)); - QVERIFY(timer.elapsed() < waitTime); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - QVERIFY(recursiveMutex.tryLock(0)); - QVERIFY(lockCount.testAndSetRelaxed(1, 2)); - QVERIFY(lockCount.testAndSetRelaxed(2, 1)); - recursiveMutex.unlock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - recursiveMutex.unlock(); - testsTurn.release(); - - threadsTurn.acquire(); - } - }; + const std::chrono::milliseconds systemTimersResolutionAsDuration(systemTimersResolution); + testsTurn.release(); + + // TEST 1: thread can't acquire lock + threadsTurn.acquire(); + QVERIFY(!normalMutex.try_lock()); + testsTurn.release(); + + // TEST 2: thread can acquire lock + threadsTurn.acquire(); + QVERIFY(normalMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(!normalMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 3: thread can't acquire lock, timeout = waitTime + threadsTurn.acquire(); + auto endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(!normalMutex.try_lock_until(endTimePoint)); + QVERIFY(std::chrono::steady_clock::now() >= endTimePoint - systemTimersResolutionAsDuration); + testsTurn.release(); + + // TEST 4: thread can acquire lock, timeout = waitTime + threadsTurn.acquire(); + endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(normalMutex.try_lock_until(endTimePoint)); + QVERIFY(std::chrono::steady_clock::now() <= endTimePoint + systemTimersResolutionAsDuration); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + // it's non-recursive, so the following lock needs to fail + QVERIFY(!normalMutex.try_lock_until(endTimePoint)); + QVERIFY(std::chrono::steady_clock::now() >= endTimePoint - systemTimersResolutionAsDuration); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 5: thread can't acquire lock, timeout = 0 + threadsTurn.acquire(); + QVERIFY(!normalMutex.try_lock_until(std::chrono::steady_clock::now())); + testsTurn.release(); + + // TEST 6: thread can acquire lock, timeout = 0 + threadsTurn.acquire(); + endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(normalMutex.try_lock_until(std::chrono::steady_clock::now())); + QVERIFY(std::chrono::steady_clock::now() < endTimePoint + systemTimersResolutionAsDuration); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(!normalMutex.try_lock_until(std::chrono::steady_clock::now())); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + testsTurn.release(); + + // TEST 7 overflow: thread can acquire lock, timeout = 3000 (QTBUG-24795) + threadsTurn.acquire(); + endTimePoint = std::chrono::steady_clock::now() + std::chrono::milliseconds(3000); + QVERIFY(normalMutex.try_lock_until(endTimePoint)); + QVERIFY(std::chrono::steady_clock::now() < endTimePoint + systemTimersResolutionAsDuration); + normalMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + } + }; - Thread thread; - thread.start(); + Thread thread; + thread.start(); + + // TEST 1: thread can't acquire lock + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 2: thread can acquire lock + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 3: thread can't acquire lock, timeout = waitTime + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 4: thread can acquire lock, timeout = waitTime + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 5: thread can't acquire lock, timeout = 0 + testsTurn.acquire(); + normalMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + threadsTurn.release(); + + // TEST 6: thread can acquire lock, timeout = 0 + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + normalMutex.unlock(); + threadsTurn.release(); + + // TEST 7: thread can acquire lock, timeout = 3000 (QTBUG-24795) + testsTurn.acquire(); + normalMutex.lock(); + threadsTurn.release(); + QThread::msleep(100); + normalMutex.unlock(); + + // wait for thread to finish + testsTurn.acquire(); + threadsTurn.release(); + thread.wait(); +#endif +} - // thread can't acquire lock - testsTurn.acquire(); - recursiveMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - recursiveMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 2)); - threadsTurn.release(); - - // thread can acquire lock - testsTurn.acquire(); - QVERIFY(lockCount.testAndSetRelaxed(2, 1)); - recursiveMutex.unlock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - recursiveMutex.unlock(); - threadsTurn.release(); - - // thread can't acquire lock, timeout = waitTime - testsTurn.acquire(); - recursiveMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - recursiveMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 2)); - threadsTurn.release(); - - // thread can acquire lock, timeout = waitTime - testsTurn.acquire(); - QVERIFY(lockCount.testAndSetRelaxed(2, 1)); - recursiveMutex.unlock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - recursiveMutex.unlock(); - threadsTurn.release(); - - // thread can't acquire lock, timeout = 0 - testsTurn.acquire(); - recursiveMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(0, 1)); - recursiveMutex.lock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 2)); - threadsTurn.release(); - - // thread can acquire lock, timeout = 0 - testsTurn.acquire(); - QVERIFY(lockCount.testAndSetRelaxed(2, 1)); - recursiveMutex.unlock(); - QVERIFY(lockCount.testAndSetRelaxed(1, 0)); - recursiveMutex.unlock(); - threadsTurn.release(); - - // stop thread - testsTurn.acquire(); - threadsTurn.release(); - thread.wait(); - } +void tst_QMutex::tryLock_recursive() +{ + class Thread : public QThread + { + public: + void run() + { + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(!recursiveMutex.tryLock()); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(recursiveMutex.tryLock()); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.tryLock()); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + QElapsedTimer timer; + timer.start(); + QVERIFY(!recursiveMutex.tryLock(waitTime)); + QVERIFY(timer.elapsed() >= waitTime - systemTimersResolution); + QVERIFY(!recursiveMutex.tryLock(0)); + testsTurn.release(); + + threadsTurn.acquire(); + timer.start(); + QVERIFY(recursiveMutex.tryLock(waitTime)); + QVERIFY(timer.elapsed() <= waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.tryLock(waitTime)); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(!recursiveMutex.tryLock(0)); + QVERIFY(!recursiveMutex.tryLock(0)); + testsTurn.release(); + + threadsTurn.acquire(); + timer.start(); + QVERIFY(recursiveMutex.tryLock(0)); + QVERIFY(timer.elapsed() < waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.tryLock(0)); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + } + }; + + Thread thread; + thread.start(); + + // thread can't acquire lock + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // thread can't acquire lock, timeout = waitTime + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock, timeout = waitTime + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // thread can't acquire lock, timeout = 0 + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock, timeout = 0 + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // stop thread + testsTurn.acquire(); + threadsTurn.release(); + thread.wait(); +} + +void tst_QMutex::try_lock_for_recursive() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#else + class Thread : public QThread + { + public: + void run() + { + const std::chrono::milliseconds systemTimersResolutionAsDuration(systemTimersResolution); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(!recursiveMutex.try_lock()); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(recursiveMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + QElapsedTimer timer; + timer.start(); + QVERIFY(!recursiveMutex.try_lock_for(waitTimeAsDuration)); + QVERIFY(timer.elapsed() >= waitTime - systemTimersResolution); + QVERIFY(!recursiveMutex.try_lock_for(std::chrono::milliseconds::zero())); + testsTurn.release(); + + threadsTurn.acquire(); + timer.start(); + QVERIFY(recursiveMutex.try_lock_for(waitTimeAsDuration)); + QVERIFY(timer.elapsed() <= waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.try_lock_for(waitTimeAsDuration)); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(!recursiveMutex.try_lock_for(std::chrono::milliseconds::zero())); + QVERIFY(!recursiveMutex.try_lock_for(std::chrono::milliseconds::zero())); + testsTurn.release(); + + threadsTurn.acquire(); + timer.start(); + QVERIFY(recursiveMutex.try_lock_for(std::chrono::milliseconds::zero())); + QVERIFY(timer.elapsed() < waitTime + systemTimersResolution); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.try_lock_for(std::chrono::milliseconds::zero())); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + } + }; + + Thread thread; + thread.start(); + + // thread can't acquire lock + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // thread can't acquire lock, timeout = waitTime + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock, timeout = waitTime + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // thread can't acquire lock, timeout = 0 + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock, timeout = 0 + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // stop thread + testsTurn.acquire(); + threadsTurn.release(); + thread.wait(); +#endif +} + +void tst_QMutex::try_lock_until_recursive() +{ +#if !QT_HAS_INCLUDE(<chrono>) + QSKIP("This test requires <chrono>"); +#else + class Thread : public QThread + { + public: + void run() + { + const std::chrono::milliseconds systemTimersResolutionAsDuration(systemTimersResolution); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(!recursiveMutex.try_lock()); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(recursiveMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.try_lock()); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + auto endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(!recursiveMutex.try_lock_until(endTimePoint)); + QVERIFY(std::chrono::steady_clock::now() >= endTimePoint - systemTimersResolutionAsDuration); + QVERIFY(!recursiveMutex.try_lock()); + testsTurn.release(); + + threadsTurn.acquire(); + endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(recursiveMutex.try_lock_until(endTimePoint)); + QVERIFY(std::chrono::steady_clock::now() <= endTimePoint + systemTimersResolutionAsDuration); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(recursiveMutex.try_lock_until(endTimePoint)); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + QVERIFY(!recursiveMutex.try_lock_until(std::chrono::steady_clock::now())); + QVERIFY(!recursiveMutex.try_lock_until(std::chrono::steady_clock::now())); + testsTurn.release(); + + threadsTurn.acquire(); + endTimePoint = std::chrono::steady_clock::now() + waitTimeAsDuration; + QVERIFY(recursiveMutex.try_lock_until(std::chrono::steady_clock::now())); + QVERIFY(std::chrono::steady_clock::now() <= endTimePoint + systemTimersResolutionAsDuration); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + QVERIFY(recursiveMutex.try_lock_until(std::chrono::steady_clock::now())); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + testsTurn.release(); + + threadsTurn.acquire(); + } + }; + + Thread thread; + thread.start(); + + // thread can't acquire lock + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // thread can't acquire lock, timeout = waitTime + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock, timeout = waitTime + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // thread can't acquire lock, timeout = 0 + testsTurn.acquire(); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(0, 1)); + recursiveMutex.lock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 2)); + threadsTurn.release(); + + // thread can acquire lock, timeout = 0 + testsTurn.acquire(); + QVERIFY(lockCount.testAndSetRelaxed(2, 1)); + recursiveMutex.unlock(); + QVERIFY(lockCount.testAndSetRelaxed(1, 0)); + recursiveMutex.unlock(); + threadsTurn.release(); + + // stop thread + testsTurn.acquire(); + threadsTurn.release(); + thread.wait(); +#endif } class mutex_Thread : public QThread @@ -439,7 +1128,7 @@ enum { one_minute = 6 * 1000, //not really one minute, but else it is too long. class StressTestThread : public QThread { - QTime t; + QElapsedTimer t; public: static QBasicAtomicInt lockCount; static QBasicAtomicInt sentinel; @@ -491,7 +1180,7 @@ public: void run() { - QTime t; + QElapsedTimer t; t.start(); do { if (mutex.tryLock()) @@ -619,7 +1308,7 @@ void tst_QMutex::tryLockNegative() class MoreStressTestThread : public QThread { - QTime t; + QElapsedTimer t; public: static QAtomicInt lockCount; static QAtomicInt sentinel[threadCount]; diff --git a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp index 341bd21e5a..8597bf1a6d 100644 --- a/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp +++ b/tests/auto/corelib/thread/qsemaphore/tst_qsemaphore.cpp @@ -350,15 +350,9 @@ const int AlphabetSize = sizeof(alphabet) - 1; const int BufferSize = 4096; // GCD of BufferSize and alphabet size must be 1 char buffer[BufferSize]; -#ifndef Q_OS_WINCE const int ProducerChunkSize = 3; const int ConsumerChunkSize = 7; const int Multiplier = 10; -#else -const int ProducerChunkSize = 2; -const int ConsumerChunkSize = 5; -const int Multiplier = 3; -#endif // note: the code depends on the fact that DataSize is a multiple of // ProducerChunkSize, ConsumerChunkSize, and BufferSize diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp index bbd319d2db..0efbc5d01e 100644 --- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp +++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp @@ -95,9 +95,7 @@ private slots: void requestTermination(); -#ifndef Q_OS_WINCE void stressTest(); -#endif void quitLock(); }; @@ -664,7 +662,7 @@ void NativeThreadWrapper::start(FunctionPointer functionPointer, void *data) #if defined Q_OS_UNIX const int state = pthread_create(&nativeThreadHandle, 0, NativeThreadWrapper::runUnix, this); Q_UNUSED(state); -#elif defined(Q_OS_WINCE) || defined(Q_OS_WINRT) +#elif defined(Q_OS_WINRT) nativeThreadHandle = CreateThread(NULL, 0 , (LPTHREAD_START_ROUTINE)NativeThreadWrapper::runWin , this, 0, NULL); #elif defined Q_OS_WIN unsigned thrdid = 0; @@ -684,11 +682,7 @@ void NativeThreadWrapper::join() #if defined Q_OS_UNIX pthread_join(nativeThreadHandle, 0); #elif defined Q_OS_WIN -#ifndef Q_OS_WINCE WaitForSingleObjectEx(nativeThreadHandle, INFINITE, FALSE); -#else - WaitForSingleObject(nativeThreadHandle, INFINITE); -#endif CloseHandle(nativeThreadHandle); #endif } @@ -874,13 +868,8 @@ void tst_QThread::adoptedThreadExecFinished() void tst_QThread::adoptMultipleThreads() { #if defined(Q_OS_WIN) - // Windows CE is not capable of handling that many threads. On the emulator it is dead with 26 threads already. -# if defined(Q_OS_WINCE) - const int numThreads = 20; -# else // need to test lots of threads, so that we exceed MAXIMUM_WAIT_OBJECTS in qt_adopted_thread_watcher() const int numThreads = 200; -# endif #else const int numThreads = 5; #endif @@ -911,13 +900,8 @@ void tst_QThread::adoptMultipleThreads() void tst_QThread::adoptMultipleThreadsOverlap() { #if defined(Q_OS_WIN) - // Windows CE is not capable of handling that many threads. On the emulator it is dead with 26 threads already. -# if defined(Q_OS_WINCE) - const int numThreads = 20; -# else // need to test lots of threads, so that we exceed MAXIMUM_WAIT_OBJECTS in qt_adopted_thread_watcher() const int numThreads = 200; -# endif #else const int numThreads = 5; #endif @@ -950,7 +934,6 @@ void tst_QThread::adoptMultipleThreadsOverlap() QCOMPARE(recorder.activationCount.load(), numThreads); } -#ifndef Q_OS_WINCE // Disconnects on WinCE void tst_QThread::stressTest() { @@ -962,7 +945,6 @@ void tst_QThread::stressTest() t.wait(one_minute); } } -#endif class Syncronizer : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp b/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp index ba64bf2963..a9af182ed8 100644 --- a/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp +++ b/tests/auto/corelib/thread/qthreadonce/tst_qthreadonce.cpp @@ -120,7 +120,7 @@ void tst_QThreadOnce::sameThread() void tst_QThreadOnce::multipleThreads() { -#if defined(Q_OS_WINCE) || defined(Q_OS_VXWORKS) +#if defined(Q_OS_VXWORKS) const int NumberOfThreads = 20; #else const int NumberOfThreads = 100; diff --git a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp index f3eba5c823..49a3b3e4db 100644 --- a/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ b/tests/auto/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp @@ -40,10 +40,8 @@ #include <pthread.h> #endif #ifdef Q_OS_WIN -#ifndef Q_OS_WINCE -#include <process.h> -#endif -#include <windows.h> +# include <process.h> +# include <qt_windows.h> #endif class tst_QThreadStorage : public QObject @@ -202,6 +200,13 @@ void testAdoptedThreadStorageWin(void *p) } QObject::connect(QThread::currentThread(), SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); } +#ifdef Q_OS_WINRT +unsigned __stdcall testAdoptedThreadStorageWinRT(void *p) +{ + testAdoptedThreadStorageWin(p); + return 0; +} +#endif void *testAdoptedThreadStorageUnix(void *pointers) { testAdoptedThreadStorageWin(pointers); @@ -219,13 +224,14 @@ void tst_QThreadStorage::adoptedThreads() const int state = pthread_create(&thread, 0, testAdoptedThreadStorageUnix, &pointers); QCOMPARE(state, 0); pthread_join(thread, 0); -#elif defined Q_OS_WIN && !defined(Q_OS_WINRT) +#elif defined Q_OS_WINRT + HANDLE thread; + thread = (HANDLE) _beginthreadex(NULL, 0, testAdoptedThreadStorageWinRT, &pointers, 0, 0); + QVERIFY(thread); + WaitForSingleObjectEx(thread, INFINITE, FALSE); +#elif defined Q_OS_WIN HANDLE thread; -#if defined(Q_OS_WINCE) - thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)testAdoptedThreadStorageWin, &pointers, 0, NULL); -#else thread = (HANDLE)_beginthread(testAdoptedThreadStorageWin, 0, &pointers); -#endif QVERIFY(thread); WaitForSingleObject(thread, INFINITE); #endif 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/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 \ diff --git a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp index 9556a167c5..79cd17b5b3 100644 --- a/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp +++ b/tests/auto/corelib/xml/qxmlstream/tst_qxmlstream.cpp @@ -65,6 +65,16 @@ static inline int best(int a, int b, int c) return qMin(qMin(a, b), c); } +template <typename C> +const C sorted_by_name(C c) { // return by const value so we can feed directly into range-for loops below + using T = typename C::value_type; + auto byName = [](const T &lhs, const T &rhs) { + return lhs.name() < rhs.name(); + }; + std::sort(c.begin(), c.end(), byName); + return c; +} + /** * Opens \a filename and returns content produced as per * xmlconf/xmltest/canonxml.html. @@ -97,7 +107,8 @@ static QByteArray makeCanonical(const QString &filename, while (!reader.atEnd()) { reader.readNext(); if (reader.isDTD()) { - if (!reader.notationDeclarations().isEmpty()) { + const auto notationDeclarations = reader.notationDeclarations(); + if (!notationDeclarations.isEmpty()) { QString dtd; QTextStream writeDtd(&dtd); @@ -105,10 +116,7 @@ static QByteArray makeCanonical(const QString &filename, writeDtd << docType; writeDtd << " ["; writeDtd << endl; - QMap<QString, QXmlStreamNotationDeclaration> sortedNotationDeclarations; - foreach (QXmlStreamNotationDeclaration notation, reader.notationDeclarations()) - sortedNotationDeclarations.insert(notation.name().toString(), notation); - foreach (QXmlStreamNotationDeclaration notation, sortedNotationDeclarations.values()) { + for (const QXmlStreamNotationDeclaration ¬ation : sorted_by_name(notationDeclarations)) { writeDtd << "<!NOTATION "; writeDtd << notation.name().toString(); if (notation.publicId().isEmpty()) { @@ -135,11 +143,7 @@ static QByteArray makeCanonical(const QString &filename, } } else if (reader.isStartElement()) { writer.writeStartElement(reader.namespaceUri().toString(), reader.name().toString()); - - QMap<QString, QXmlStreamAttribute> sortedAttributes; - foreach(QXmlStreamAttribute attribute, reader.attributes()) - sortedAttributes.insert(attribute.name().toString(), attribute); - foreach(QXmlStreamAttribute attribute, sortedAttributes.values()) + for (const QXmlStreamAttribute &attribute : sorted_by_name(reader.attributes())) writer.writeAttribute(attribute); writer.writeCharacters(QString()); // write empty string to avoid having empty xml tags } else if (reader.isCharacters()) { @@ -236,6 +240,8 @@ public: */ class MissedBaseline { + friend class QVector<MissedBaseline>; + MissedBaseline() {} // for QVector, don't use public: MissedBaseline(const QString &aId, const QByteArray &aExpected, @@ -247,13 +253,20 @@ public: qFatal("%s: aId must not be an empty string", Q_FUNC_INFO); } + void swap(MissedBaseline &other) Q_DECL_NOTHROW + { + qSwap(id, other.id); + qSwap(expected, other.expected); + qSwap(output, other.output); + } + QString id; QByteArray expected; QByteArray output; }; - QList<GeneralFailure> failures; - QList<MissedBaseline> missedBaselines; + QVector<GeneralFailure> failures; + QVector<MissedBaseline> missedBaselines; /** * The count of how many tests that were run. @@ -507,6 +520,9 @@ private: QString m_ch; QStack<QUrl> m_baseURI; }; +QT_BEGIN_NAMESPACE +Q_DECLARE_SHARED(TestSuiteHandler::MissedBaseline) +QT_END_NAMESPACE class tst_QXmlStream: public QObject { @@ -718,8 +734,9 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) writer << " qualifiedName=\"" << reader.qualifiedName().toString() << '"'; if (!reader.prefix().isEmpty()) writer << " prefix=\"" << reader.prefix().toString() << '"'; - if (reader.attributes().size()) { - foreach(QXmlStreamAttribute attribute, reader.attributes()) { + const auto attributes = reader.attributes(); + if (attributes.size()) { + for (const QXmlStreamAttribute &attribute : attributes) { writer << endl << " Attribute("; if (!attribute.name().isEmpty()) writer << " name=\"" << attribute.name().toString() << '"'; @@ -734,8 +751,9 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) writer << " )" << endl; } } - if (reader.namespaceDeclarations().size()) { - foreach(QXmlStreamNamespaceDeclaration namespaceDeclaration, reader.namespaceDeclarations()) { + const auto namespaceDeclarations = reader.namespaceDeclarations(); + if (namespaceDeclarations.size()) { + for (const QXmlStreamNamespaceDeclaration &namespaceDeclaration : namespaceDeclarations) { writer << endl << " NamespaceDeclaration("; if (!namespaceDeclaration.prefix().isEmpty()) writer << " prefix=\"" << namespaceDeclaration.prefix().toString() << '"'; @@ -744,8 +762,9 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) writer << " )" << endl; } } - if (reader.notationDeclarations().size()) { - foreach(QXmlStreamNotationDeclaration notationDeclaration, reader.notationDeclarations()) { + const auto notationDeclarations = reader.notationDeclarations(); + if (notationDeclarations.size()) { + for (const QXmlStreamNotationDeclaration ¬ationDeclaration : notationDeclarations) { writer << endl << " NotationDeclaration("; if (!notationDeclaration.name().isEmpty()) writer << " name=\"" << notationDeclaration.name().toString() << '"'; @@ -756,8 +775,9 @@ QByteArray tst_QXmlStream::readFile(const QString &filename) writer << " )" << endl; } } - if (reader.entityDeclarations().size()) { - foreach(QXmlStreamEntityDeclaration entityDeclaration, reader.entityDeclarations()) { + const auto entityDeclarations = reader.entityDeclarations(); + if (entityDeclarations.size()) { + for (const QXmlStreamEntityDeclaration &entityDeclaration : entityDeclarations) { writer << endl << " EntityDeclaration("; if (!entityDeclaration.name().isEmpty()) writer << " name=\"" << entityDeclaration.name().toString() << '"'; @@ -803,7 +823,8 @@ void tst_QXmlStream::testReader_data() const QTest::addColumn<QString>("ref"); QDir dir; dir.cd(QFINDTESTDATA("data/")); - foreach(QString filename , dir.entryList(QStringList() << "*.xml")) { + const auto fileNames = dir.entryList(QStringList() << "*.xml"); + for (const QString &filename : fileNames) { QString reference = QFileInfo(filename).baseName() + ".ref"; QTest::newRow(dir.filePath(filename).toLatin1().data()) << dir.filePath(filename) << dir.filePath(reference); } |