summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp2
-rw-r--r--tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp75
-rw-r--r--tests/auto/corelib/global/global.pro4
-rw-r--r--tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp7
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp31
-rw-r--r--tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro12
-rw-r--r--tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp236
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp77
-rw-r--r--tests/auto/corelib/global/qrand/tst_qrand.cpp2
-rw-r--r--tests/auto/corelib/io/io.pro8
-rw-r--r--tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp2
-rw-r--r--tests/auto/corelib/io/qdebug/tst_qdebug.cpp54
-rw-r--r--tests/auto/corelib/io/qfile/stdinprocess/main.cpp2
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp33
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp149
-rw-r--r--tests/auto/corelib/io/qlockfile/qlockfile.pro3
-rw-r--r--tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp78
-rw-r--r--tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro7
-rw-r--r--tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp379
-rw-r--r--tests/auto/corelib/io/qlockfile/tst_qlockfile.pro6
-rw-r--r--tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp4
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/testSoftExit/main_unix.cpp2
-rw-r--r--tests/auto/corelib/io/qprocess/testSoftExit/main_win.cpp2
-rw-r--r--tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro1
-rw-r--r--tests/auto/corelib/io/qprocess/tst_qprocess.cpp21
-rw-r--r--tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp2
-rw-r--r--tests/auto/corelib/io/qsavefile/qsavefile.pro5
-rw-r--r--tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp272
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp2
-rw-r--r--tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp14
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp48
-rw-r--r--tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp14
-rw-r--r--tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp13
-rw-r--r--tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp5
-rw-r--r--tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp2
-rw-r--r--tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp189
-rw-r--r--tests/auto/corelib/json/tst_qtjson.cpp136
-rw-r--r--tests/auto/corelib/kernel/kernel.pro6
-rw-r--r--tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp12
-rw-r--r--tests/auto/corelib/kernel/qmath/tst_qmath.cpp77
-rw-r--r--tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro2
-rw-r--r--tests/auto/corelib/kernel/qmetaobjectbuilder/qmetaobjectbuilder.pro2
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp14
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp393
-rw-r--r--tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp7
-rw-r--r--tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp2
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp4
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/lib/mylib.c6
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro2
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp6
-rw-r--r--tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp69
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp2
-rw-r--r--tests/auto/corelib/statemachine/qstate/tst_qstate.cpp16
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp32
-rw-r--r--tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp12
-rw-r--r--tests/auto/corelib/thread/qthread/tst_qthread.cpp2
-rw-r--r--tests/auto/corelib/thread/qthreadonce/qthreadonce.h4
-rw-r--r--tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp36
-rw-r--r--tests/auto/corelib/tools/qchar/tst_qchar.cpp68
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp73
-rw-r--r--tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp48
-rw-r--r--tests/auto/corelib/tools/qhash/tst_qhash.cpp34
-rw-r--r--tests/auto/corelib/tools/qlocale/tst_qlocale.cpp30
-rw-r--r--tests/auto/corelib/tools/qmap/tst_qmap.cpp161
-rw-r--r--tests/auto/corelib/tools/qmargins/tst_qmargins.cpp46
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore1
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro7
-rw-r--r--tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp151
-rw-r--r--tests/auto/corelib/tools/qpoint/tst_qpoint.cpp25
-rw-r--r--tests/auto/corelib/tools/qpointf/tst_qpointf.cpp26
-rw-r--r--tests/auto/corelib/tools/qqueue/tst_qqueue.cpp18
-rw-r--r--tests/auto/corelib/tools/qrect/tst_qrect.cpp21
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp217
-rw-r--r--tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h5
-rw-r--r--tests/auto/corelib/tools/qset/tst_qset.cpp22
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/externaltests.pri2
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp122
-rw-r--r--tests/auto/corelib/tools/qstring/tst_qstring.cpp107
-rw-r--r--tests/auto/corelib/tools/qstringref/tst_qstringref.cpp954
-rw-r--r--tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp23
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp24
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp98
-rw-r--r--tests/auto/corelib/tools/tools.pro1
-rw-r--r--tests/auto/corelib/xml/xml.pro2
90 files changed, 4493 insertions, 404 deletions
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
index ccc23851b7..51f07993cd 100644
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
+++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp
@@ -44,7 +44,6 @@
#include <QtCore/qsequentialanimationgroup.h>
Q_DECLARE_METATYPE(QAbstractAnimation::State)
-Q_DECLARE_METATYPE(QAbstractAnimation*)
class tst_QSequentialAnimationGroup : public QObject
{
@@ -84,7 +83,6 @@ private slots:
void tst_QSequentialAnimationGroup::initTestCase()
{
qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State");
- qRegisterMetaType<QAbstractAnimation*>("QAbstractAnimation*");
}
void tst_QSequentialAnimationGroup::construction()
diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp
index 6c566e017b..b5f736cfbb 100644
--- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp
+++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp
@@ -84,6 +84,7 @@ private slots:
void utfHeaders_data();
void utfHeaders();
+ void codecForHtml_data();
void codecForHtml();
void codecForUtfText_data();
@@ -1853,23 +1854,81 @@ void tst_QTextCodec::utfHeaders()
}
}
-void tst_QTextCodec::codecForHtml()
+void tst_QTextCodec::codecForHtml_data()
{
- QByteArray html("<html><head></head><body>blah</body></html>");
+ QTest::addColumn<QByteArray>("html");
+ QTest::addColumn<int>("defaultCodecMib");
+ QTest::addColumn<int>("expectedMibEnum");
- QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1
+ int noDefault = -1;
+ int fallback = 4; // latin 1
+ QByteArray html = "<html><head></head><body>blah</body></html>";
+ QTest::newRow("no charset, latin 1") << html << noDefault << fallback;
- QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8
+ QTest::newRow("no charset, default UTF-8") << html << 106 << 106;
html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-15\" /></head></html>";
- QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15
+ QTest::newRow("latin 15, default UTF-8") << html << 106 << 111;
html = "<html><head><meta content=\"text/html; charset=ISO-8859-15\" http-equiv=\"content-type\" /></head></html>";
- QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15
+ QTest::newRow("latin 15, default UTF-8 (#2)") << html << 106 << 111;
+
+ html = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><title>Test</title></head>";
+ QTest::newRow("UTF-8, no default") << html << noDefault << 106;
+
+ html = "<!DOCTYPE html><html><head><meta charset=\"ISO_8859-1:1987\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><title>Test</title></head>";
+ QTest::newRow("latin 1, no default") << html << noDefault << 4;
+
+ html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset=\"utf-8\"><title>Test</title></head>";
+ QTest::newRow("UTF-8, no default (#2)") << html << noDefault << 106;
+
+ html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8/></head></html>";
+ QTest::newRow("UTF-8, no quotes") << html << noDefault << 106;
+
+ html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset='UTF-8'/></head></html>";
+ QTest::newRow("UTF-8, single quotes") << html << noDefault << 106;
+
+ html = "<!DOCTYPE html><html><head><meta charset=utf-8><title>Test</title></head>";
+ QTest::newRow("UTF-8, > terminator") << html << noDefault << 106;
+
+ html = "<!DOCTYPE html><html><head><meta charset= utf-8 ><title>Test</title></head>";
+ QTest::newRow("UTF-8, > terminator with spaces") << html << noDefault << 106;
+
+ html = "<!DOCTYPE html><html><head><meta charset= utf/8 ><title>Test</title></head>";
+ QTest::newRow("UTF-8, > teminator with early backslash)") << html << noDefault << 106;
+ // Test invalid charsets.
html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=invalid-foo\" /></head></html>";
- QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8
- QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1
+ QTest::newRow("invalid charset, no default") << html << noDefault << fallback;
+ QTest::newRow("invalid charset, default UTF-8") << html << 106 << 106;
+
+ html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset=\"";
+ html.prepend(QByteArray().fill(' ', 512 - html.size()));
+ QTest::newRow("invalid charset (large header)") << html << noDefault << fallback;
+
+ html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset=\"utf-8";
+ QTest::newRow("invalid charset (no closing double quote)") << html << noDefault << fallback;
+
+ html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset='utf-8";
+ QTest::newRow("invalid charset (no closing single quote)") << html << noDefault << fallback;
+
+ html = "<!DOCTYPE html><html><head><meta charset=utf-8 foo=bar><title>Test</title></head>";
+ QTest::newRow("invalid (space terminator)") << html << noDefault << fallback;
+
+ html = "<!DOCTYPE html><html><head><meta charset=\" utf' 8 /><title>Test</title></head>";
+ QTest::newRow("invalid charset, early terminator (')") << html << noDefault << fallback;
+}
+
+void tst_QTextCodec::codecForHtml()
+{
+ QFETCH(QByteArray, html);
+ QFETCH(int, defaultCodecMib);
+ QFETCH(int, expectedMibEnum);
+
+ if (defaultCodecMib != -1)
+ QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(defaultCodecMib))->mibEnum(), expectedMibEnum);
+ else // Test one parameter version when there is no default codec.
+ QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), expectedMibEnum);
}
void tst_QTextCodec::codecForUtfText_data()
diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro
index 5489b8330d..c05905bd15 100644
--- a/tests/auto/corelib/global/global.pro
+++ b/tests/auto/corelib/global/global.pro
@@ -7,4 +7,6 @@ SUBDIRS=\
qnumeric \
qrand \
qlogging \
- qtendian
+ qtendian \
+ qglobalstatic \
+
diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
index a4aca82aa9..ef41ef8801 100644
--- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
+++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
@@ -75,6 +75,13 @@ void tst_QGetPutEnv::getSetCheck()
QVERIFY(result == "supervalue");
qputenv(varName,QByteArray());
+
+ // Now test qunsetenv
+ QVERIFY(qunsetenv(varName));
+ QVERIFY(!qEnvironmentVariableIsSet(varName));
+ QVERIFY(qEnvironmentVariableIsEmpty(varName));
+ result = qgetenv(varName);
+ QCOMPARE(result, QByteArray());
}
QTEST_MAIN(tst_QGetPutEnv)
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
index f54af657c0..3696ee264f 100644
--- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
+++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
@@ -55,6 +55,8 @@ private slots:
void checkptr();
void qstaticassert();
void qConstructorFunction();
+ void qCoreAppStartupFunction();
+ void qCoreAppStartupFunctionRestart();
void isEnum();
void qAlignOf();
};
@@ -303,6 +305,33 @@ void tst_QGlobal::qConstructorFunction()
QCOMPARE(qConstructorFunctionValue, 123);
}
+static int qStartupFunctionValue;
+static void myStartupFunc()
+{
+ Q_ASSERT(QCoreApplication::instance());
+ if (QCoreApplication::instance())
+ qStartupFunctionValue += 124;
+}
+
+Q_COREAPP_STARTUP_FUNCTION(myStartupFunc)
+
+void tst_QGlobal::qCoreAppStartupFunction()
+{
+ QCOMPARE(qStartupFunctionValue, 0);
+ int argc = 1;
+ char *argv[] = { const_cast<char*>("tst_qglobal") };
+ QCoreApplication app(argc, argv);
+ QCOMPARE(qStartupFunctionValue, 124);
+}
+
+void tst_QGlobal::qCoreAppStartupFunctionRestart()
+{
+ qStartupFunctionValue = 0;
+ qCoreAppStartupFunction();
+ qStartupFunctionValue = 0;
+ qCoreAppStartupFunction();
+}
+
struct isEnum_A {
int n_;
};
@@ -532,5 +561,5 @@ void tst_QGlobal::qAlignOf()
#undef TEST_AlignOf_RValueRef
#undef TEST_AlignOf_impl
-QTEST_MAIN(tst_QGlobal)
+QTEST_APPLESS_MAIN(tst_QGlobal)
#include "tst_qglobal.moc"
diff --git a/tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro b/tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro
new file mode 100644
index 0000000000..21cab8f67d
--- /dev/null
+++ b/tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro
@@ -0,0 +1,12 @@
+QT += testlib core-private
+
+QT -= gui
+
+TARGET = tst_qglobalstatic
+CONFIG += console
+CONFIG -= app_bundle
+CONFIG += exceptions
+
+SOURCES += tst_qglobalstatic.cpp
+DEFINES += SRCDIR=\\\"$$PWD/\\\"
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp
new file mode 100644
index 0000000000..131b37f821
--- /dev/null
+++ b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp
@@ -0,0 +1,236 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Thiago Macieira <thiago@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** You may use this file under the terms of the BSD license as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
+** of its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtCore/QThread>
+#include <QtTest/QtTest>
+
+class tst_QGlobalStatic : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void beforeInitialization();
+ void api();
+ void constVolatile();
+ void exception();
+ void threadedException();
+ void threadStressTest();
+ void afterDestruction();
+};
+
+Q_GLOBAL_STATIC_WITH_ARGS(const int, constInt, (42))
+Q_GLOBAL_STATIC_WITH_ARGS(volatile int, volatileInt, (-47))
+
+void otherFunction()
+{
+ // never called
+ constInt();
+ volatileInt();
+}
+
+// do not initialize the following Q_GLOBAL_STATIC
+Q_GLOBAL_STATIC(int, checkedBeforeInitialization)
+void tst_QGlobalStatic::beforeInitialization()
+{
+ QVERIFY(!checkedBeforeInitialization.exists());
+ QVERIFY(!checkedBeforeInitialization.isDestroyed());
+}
+
+struct Type {
+ int i;
+};
+
+Q_GLOBAL_STATIC(Type, checkedAfterInitialization)
+void tst_QGlobalStatic::api()
+{
+ // check the API
+ QVERIFY((Type *)checkedAfterInitialization);
+ QVERIFY(checkedAfterInitialization());
+ *checkedAfterInitialization = Type();
+ *checkedAfterInitialization() = Type();
+
+ checkedAfterInitialization()->i = 47;
+ checkedAfterInitialization->i = 42;
+ QCOMPARE(checkedAfterInitialization()->i, 42);
+ checkedAfterInitialization()->i = 47;
+ QCOMPARE(checkedAfterInitialization->i, 47);
+
+ QVERIFY(checkedAfterInitialization.exists());
+ QVERIFY(!checkedAfterInitialization.isDestroyed());
+}
+
+void tst_QGlobalStatic::constVolatile()
+{
+ QCOMPARE(*constInt(), 42);
+ QCOMPARE((int)*volatileInt(), -47);
+ QCOMPARE(*constInt(), 42);
+ QCOMPARE((int)*volatileInt(), -47);
+}
+
+struct ThrowingType
+{
+ static QBasicAtomicInt constructedCount;
+ static QBasicAtomicInt destructedCount;
+ ThrowingType()
+ {
+ throw 0;
+ }
+
+ ThrowingType(QBasicAtomicInt &throwControl)
+ {
+ constructedCount.ref();
+ if (throwControl.fetchAndAddRelaxed(-1) != 0)
+ throw 0;
+ }
+ ~ThrowingType() { destructedCount.ref(); }
+};
+
+QBasicAtomicInt ThrowingType::constructedCount = Q_BASIC_ATOMIC_INITIALIZER(0);
+QBasicAtomicInt ThrowingType::destructedCount = Q_BASIC_ATOMIC_INITIALIZER(0);
+
+Q_GLOBAL_STATIC(ThrowingType, throwingGS)
+void tst_QGlobalStatic::exception()
+{
+ bool exceptionCaught = false;
+ try {
+ throwingGS();
+ } catch (int) {
+ exceptionCaught = true;
+ }
+ QVERIFY(exceptionCaught);
+ QCOMPARE(Q_QGS_throwingGS::guard.load(), 0);
+ QVERIFY(!throwingGS.exists());
+ QVERIFY(!throwingGS.isDestroyed());
+}
+
+QBasicAtomicInt exceptionControlVar = Q_BASIC_ATOMIC_INITIALIZER(1);
+Q_GLOBAL_STATIC_WITH_ARGS(ThrowingType, exceptionGS, (exceptionControlVar))
+void tst_QGlobalStatic::threadedException()
+{
+ if (exceptionControlVar.load() != 1)
+ QSKIP("This test cannot be run more than once");
+ ThrowingType::constructedCount.store(0);
+ ThrowingType::destructedCount.store(0);
+
+ bool exceptionCaught = false;
+ try {
+ exceptionGS();
+ } catch (int) {
+ exceptionCaught = true;
+ }
+ QCOMPARE(ThrowingType::constructedCount.load(), 1);
+ QVERIFY(exceptionCaught);
+
+ exceptionGS();
+ QCOMPARE(ThrowingType::constructedCount.load(), 2);
+}
+
+QBasicAtomicInt threadStressTestControlVar = Q_BASIC_ATOMIC_INITIALIZER(5);
+Q_GLOBAL_STATIC_WITH_ARGS(ThrowingType, threadStressTestGS, (threadStressTestControlVar))
+
+
+void tst_QGlobalStatic::threadStressTest()
+{
+ class ThreadStressTestThread: public QThread
+ {
+ public:
+ QReadWriteLock *lock;
+ void run()
+ {
+ QReadLocker l(lock);
+ //usleep(qrand() * 200 / RAND_MAX);
+ // thundering herd
+ try {
+ threadStressTestGS();
+ } catch (int) {
+ }
+ }
+ };
+
+ ThrowingType::constructedCount.store(0);
+ ThrowingType::destructedCount.store(0);
+ int expectedConstructionCount = threadStressTestControlVar.load() + 1;
+ if (expectedConstructionCount <= 0)
+ QSKIP("This test cannot be run more than once");
+
+ const int numThreads = 200;
+ ThreadStressTestThread threads[numThreads];
+ QReadWriteLock lock;
+ lock.lockForWrite();
+ for (int i = 0; i < numThreads; ++i) {
+ threads[i].lock = &lock;
+ threads[i].start();
+ }
+
+ // wait for all threads
+ // release the herd
+ lock.unlock();
+
+ for (int i = 0; i < numThreads; ++i)
+ threads[i].wait();
+
+ QCOMPARE(ThrowingType::constructedCount.loadAcquire(), expectedConstructionCount);
+ QCOMPARE(ThrowingType::destructedCount.loadAcquire(), 0);
+}
+
+Q_GLOBAL_STATIC(int, checkedAfterDestruction)
+void tst_QGlobalStatic::afterDestruction()
+{
+ // this test will not produce results now
+ // it will simply run some code on destruction (after the global statics have been deleted)
+ // if that fails, this will cause a crash
+
+ // static destruction is LIFO: so we must add our exit-time code before the
+ // global static is used for the first time
+ static struct RunAtExit {
+ ~RunAtExit() {
+ int *ptr = checkedAfterDestruction();
+ if (ptr)
+ qFatal("Global static is not null as was expected");
+ }
+ } runAtExit;
+ (void) runAtExit;
+
+ *checkedAfterDestruction = 42;
+}
+
+QTEST_APPLESS_MAIN(tst_QGlobalStatic);
+
+#include "tst_qglobalstatic.moc"
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index fc96d656a0..04ce504189 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -64,9 +64,11 @@ private slots:
#endif
void qMessagePattern();
+ void qMessagePatternIf();
private:
QString m_appDir;
+ QStringList m_baseEnvironment;
};
static QtMsgType s_type;
@@ -98,6 +100,14 @@ void tst_qmessagehandler::initTestCase()
m_appDir = QFINDTESTDATA("app");
QVERIFY2(!m_appDir.isEmpty(), qPrintable(
QString::fromLatin1("Couldn't find helper app dir starting from %1.").arg(QDir::currentPath())));
+
+ m_baseEnvironment = QProcess::systemEnvironment();
+ for (int i = 0; i < m_baseEnvironment.count(); ++i) {
+ if (m_baseEnvironment.at(i).startsWith("QT_MESSAGE_PATTERN=")) {
+ m_baseEnvironment.removeAt(i);
+ break;
+ }
+ }
}
void tst_qmessagehandler::cleanup()
@@ -637,7 +647,7 @@ void tst_qmessagehandler::qMessagePattern()
//
// test QT_MESSAGE_PATTERN
//
- QStringList environment = QProcess::systemEnvironment();
+ QStringList environment = m_baseEnvironment;
// %{file} is tricky because of shadow builds
environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\"");
process.setEnvironment(environment);
@@ -659,7 +669,7 @@ void tst_qmessagehandler::qMessagePattern()
QVERIFY(output.contains("critical tst_qlogging 58 main qCritical"));
QVERIFY(output.contains("debug tst_qlogging 62 main qDebug2"));
- environment = QProcess::systemEnvironment();
+ environment = m_baseEnvironment;
environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\"");
process.setEnvironment(environment);
@@ -702,5 +712,68 @@ void tst_qmessagehandler::qMessagePattern()
QCOMPARE(QString::fromLatin1(output), QString::fromLatin1(expected));
}
+void tst_qmessagehandler::qMessagePatternIf()
+{
+ QProcess process;
+ const QString appExe = m_appDir + "/app";
+
+ QStringList environment = m_baseEnvironment;
+ environment.prepend("QT_MESSAGE_PATTERN=\"[%{if-debug}D%{endif}%{if-warning}W%{endif}%{if-critical}C%{endif}%{if-fatal}F%{endif}] %{message}\"");
+ process.setEnvironment(environment);
+ process.start(appExe);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ QByteArray output = process.readAllStandardError();
+ // qDebug() << output;
+ QVERIFY(!output.isEmpty());
+ QVERIFY(!output.contains("QT_MESSAGE_PATTERN"));
+
+ QVERIFY(output.contains("[D] static constructor"));
+ // we can't be sure whether the QT_MESSAGE_PATTERN is already destructed
+ QVERIFY(output.contains("static destructor"));
+ QVERIFY(output.contains("[D] qDebug"));
+ QVERIFY(output.contains("[W] qWarning"));
+ QVERIFY(output.contains("[C] qCritical"));
+ QVERIFY(output.contains("[D] qDebug2"));
+
+ //
+ // Tests some errors
+ //
+ environment = m_baseEnvironment;
+ environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{endif} %{if-warning}\"");
+ process.setEnvironment(environment);
+
+ process.start(appExe);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ output = process.readAllStandardError();
+ // qDebug() << output;
+ QVERIFY(!output.isEmpty());
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: Unknown placeholder %{unknown}"));
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: %{endif} without an %{if-*}"));
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: missing %{endif}"));
+
+
+ environment = m_baseEnvironment;
+ environment.prepend("QT_MESSAGE_PATTERN=\"A %{if-debug}DEBUG%{if-warning}WARNING%{endif} %{message} \"");
+ process.setEnvironment(environment);
+
+ process.start(appExe);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ output = process.readAllStandardError();
+ // qDebug() << output;
+ QVERIFY(!output.isEmpty());
+ QVERIFY(output.contains("QT_MESSAGE_PATTERN: %{if-*} cannot be nested"));
+ QVERIFY(output.contains("A DEBUG qDebug"));
+ QVERIFY(output.contains("A qWarning"));
+}
+
QTEST_MAIN(tst_qmessagehandler)
#include "tst_qlogging.moc"
diff --git a/tests/auto/corelib/global/qrand/tst_qrand.cpp b/tests/auto/corelib/global/qrand/tst_qrand.cpp
index 6f64ad74b2..4cbbb8de0f 100644
--- a/tests/auto/corelib/global/qrand/tst_qrand.cpp
+++ b/tests/auto/corelib/global/qrand/tst_qrand.cpp
@@ -64,7 +64,7 @@ void tst_QRand::testqrand()
for (int i=0; i<numTestValues; ++i)
if (generatedNumbers[i] != qrand())
generatesSameSequence = false;
-
+
QVERIFY(generatesSameSequence);
for (unsigned int seed=1; seed < 10; seed+=100) {
diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro
index 03b42a2cbb..b3a51c6f6e 100644
--- a/tests/auto/corelib/io/io.pro
+++ b/tests/auto/corelib/io/io.pro
@@ -14,12 +14,14 @@ SUBDIRS=\
qfilesystemwatcher \
qiodevice \
qipaddress \
+ qlockfile \
qnodebug \
qprocess \
qprocess-noapplication \
qprocessenvironment \
qresourceengine \
qsettings \
+ qsavefile \
qstandardpaths \
qtemporarydir \
qtemporaryfile \
@@ -34,6 +36,12 @@ SUBDIRS=\
qwinoverlappedionotifier
}
+!qtHaveModule(network): SUBDIRS -= \
+ qfile \
+ qiodevice \
+ qprocess \
+ qtextstream
+
!contains(QT_CONFIG, private_tests): SUBDIRS -= \
qabstractfileengine \
qfileinfo \
diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
index 299d375c9c..d7fc76d980 100644
--- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
+++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp
@@ -883,7 +883,7 @@ static QBrush qBrushData(int index)
return custom;
}
case 7:
- QLinearGradient gradient(QPoint(2.718, 3.142), QPoint(3.1337, 42));
+ QLinearGradient gradient(QPointF(2.718, 3.142), QPointF(3.1337, 42));
gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
gradient.setSpread(QGradient::ReflectSpread);
gradient.setInterpolationMode(QGradient::ComponentInterpolation);
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
index 333ccc8e49..f452efc1b3 100644
--- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
+++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp
@@ -52,7 +52,8 @@ private slots:
void warningWithoutDebug() const;
void criticalWithoutDebug() const;
void debugWithBool() const;
- void debugNoSpaces() const;
+ void debugSpaceHandling() const;
+ void stateSaver() const;
void veryLongWarningMessage() const;
void qDebugQStringRef() const;
void qDebugQLatin1String() const;
@@ -150,7 +151,36 @@ void tst_QDebug::debugWithBool() const
QCOMPARE(QString::fromLatin1(s_function), function);
}
-void tst_QDebug::debugNoSpaces() const
+class MyPoint
+{
+public:
+ MyPoint(int val1, int val2)
+ : v1(val1), v2(val2) {}
+ int v1;
+ int v2;
+};
+QDebug operator<< (QDebug s, const MyPoint& point)
+{
+ const QDebugStateSaver saver(s);
+ return s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")";
+}
+
+class MyLine
+{
+public:
+ MyLine(const MyPoint& point1, const MyPoint& point2)
+ : p1(point1), p2(point2) {}
+ MyPoint p1;
+ MyPoint p2;
+};
+QDebug operator<< (QDebug s, const MyLine& line)
+{
+ const QDebugStateSaver saver(s);
+ s.nospace() << "MyLine(" << line.p1 << ", " << line.p2 << ")";
+ return s;
+}
+
+void tst_QDebug::debugSpaceHandling() const
{
MessageHandlerSetter mhs(myMessageHandler);
{
@@ -166,8 +196,26 @@ void tst_QDebug::debugNoSpaces() const
d << "key=" << "value";
d.space();
d << 1 << 2;
+ MyLine line(MyPoint(10, 11), MyPoint (12, 13));
+ d << line;
+ // With the old implementation of MyPoint doing dbg.nospace() << ...; dbg.space() we ended up with
+ // MyLine(MyPoint(10, 11) , MyPoint(12, 13) )
+ }
+ QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13))"));
+}
+
+void tst_QDebug::stateSaver() const
+{
+ MessageHandlerSetter mhs(myMessageHandler);
+ {
+ QDebug d = qDebug();
+ {
+ QDebugStateSaver saver(d);
+ d.nospace() << hex << right << qSetFieldWidth(3) << qSetPadChar('0') << 42;
+ }
+ d.space() << 42;
}
- QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 "));
+ QCOMPARE(s_msg, QString::fromLatin1("02a 42 "));
}
void tst_QDebug::veryLongWarningMessage() const
diff --git a/tests/auto/corelib/io/qfile/stdinprocess/main.cpp b/tests/auto/corelib/io/qfile/stdinprocess/main.cpp
index 1c22da45b3..9ca531f615 100644
--- a/tests/auto/corelib/io/qfile/stdinprocess/main.cpp
+++ b/tests/auto/corelib/io/qfile/stdinprocess/main.cpp
@@ -50,7 +50,7 @@ int main(int argc, char *argv[])
printf("echos all its input to its output.\n");
return 1;
}
-
+
QFile file;
if (strcmp(argv[1], "all") == 0) {
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index df7b397481..929865d4d6 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -80,6 +80,18 @@ QT_END_NAMESPACE
# include <sys/statfs.h>
#elif defined(Q_OS_WINCE)
# include <qplatformdefs.h>
+#elif defined(Q_OS_VXWORKS)
+# include <fcntl.h>
+#if defined(_WRS_KERNEL)
+#undef QT_OPEN
+#define QT_OPEN(path, oflag) ::open(path, oflag, 0)
+#endif
+#endif
+
+#ifdef Q_OS_QNX
+#ifdef open
+#undef open
+#endif
#endif
#include <stdio.h>
@@ -481,11 +493,6 @@ void tst_QFile::open_data()
QTest::addColumn<bool>("ok");
QTest::addColumn<QFile::FileError>("status");
-#ifdef Q_OS_MAC
- static const QString denied("Operation not permitted");
-#else
- static const QString denied("Permission denied");
-#endif
QTest::newRow( "exist_readOnly" )
<< m_testFile << int(QIODevice::ReadOnly)
<< true << QFile::NoError;
@@ -545,7 +552,7 @@ void tst_QFile::open()
QFETCH( bool, ok );
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
if (::getuid() == 0)
// root and Chuck Norris don't care for file permissions. Skip.
QSKIP("Running this test as root doesn't make sense");
@@ -1315,7 +1322,7 @@ void tst_QFile::copyFallback()
QVERIFY(QFile::exists("file-copy-destination.txt"));
QVERIFY(!file.isOpen());
- file.close();
+ file.close();
QFile::setPermissions("file-copy-destination.txt",
QFile::ReadOwner | QFile::WriteOwner);
}
@@ -2242,7 +2249,7 @@ static QByteArray getLargeDataBlock()
if (array.isNull())
{
-#if defined(Q_OS_WINCE)
+#if defined(Q_OS_WINCE) || defined(Q_OS_VXWORKS)
int resizeSize = 1024 * 1024; // WinCE does not have much space
#else
int resizeSize = 64 * 1024 * 1024;
@@ -2432,7 +2439,9 @@ void tst_QFile::rename()
#if defined(Q_OS_UNIX)
if (strcmp(QTest::currentDataTag(), "renamefile -> /etc/renamefile") == 0) {
+#if !defined(Q_OS_VXWORKS)
if (::getuid() == 0)
+#endif
QSKIP("Running this test as root doesn't make sense");
}
#endif
@@ -2919,8 +2928,8 @@ void tst_QFile::map()
// exotic test to make sure that multiple maps work
// note: windows ce does not reference count mutliple maps
- // it's essentially just the same reference but it
- // cause a resource lock on the file which prevents it
+ // it's essentially just the same reference but it
+ // cause a resource lock on the file which prevents it
// from being removed uchar *memory1 = file.map(0, file.size());
uchar *memory1 = file.map(0, file.size());
QCOMPARE(file.error(), QFile::NoError);
@@ -2941,6 +2950,7 @@ void tst_QFile::map()
file.close();
+#if !defined(Q_OS_VXWORKS)
#if defined(Q_OS_UNIX)
if (::getuid() != 0)
// root always has permissions
@@ -2955,6 +2965,7 @@ void tst_QFile::map()
QVERIFY(!memory);
QVERIFY(file.setPermissions(originalPermissions));
}
+#endif
QVERIFY(file.remove());
}
@@ -3336,7 +3347,7 @@ void tst_QFile::autocloseHandle()
{
QFile file("readonlyfile");
QVERIFY(openFile(file, QIODevice::ReadOnly, OpenStream, QFile::DontCloseHandle));
- QCOMPARE(file.handle(), QT_FILENO(stream_));
+ QCOMPARE(file.handle(), int(QT_FILENO(stream_)));
file.close();
QCOMPARE(file.handle(), -1);
//file is not closed, read should succeed
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index ded77c649f..bcc971bf4b 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -46,6 +46,7 @@
#include <qcoreapplication.h>
#include <qlibrary.h>
#include <qtemporaryfile.h>
+#include <qtemporarydir.h>
#include <qdir.h>
#include <qfileinfo.h>
#ifdef Q_OS_UNIX
@@ -54,10 +55,11 @@
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
+#ifndef Q_OS_VXWORKS
#include <pwd.h>
#endif
+#endif
#ifdef Q_OS_WIN
-#define _WIN32_WINNT 0x500
#include <qt_windows.h>
#include <qlibrary.h>
#if !defined(Q_OS_WINCE)
@@ -72,6 +74,10 @@
#include <private/qfileinfo_p.h>
#include "../../../../shared/filesystem.h"
+#if defined(Q_OS_VXWORKS)
+#define Q_NO_SYMLINKS
+#endif
+
QT_BEGIN_NAMESPACE
extern Q_AUTOTEST_EXPORT bool qIsLikelyToBeNfs(int /* handle */);
QT_END_NAMESPACE
@@ -80,7 +86,11 @@ class tst_QFileInfo : public QObject
{
Q_OBJECT
+public:
+ tst_QFileInfo() : m_currentDir(QDir::currentPath()) {}
+
private slots:
+ void initTestCase();
void cleanupTestCase();
void getSetCheck();
@@ -190,32 +200,27 @@ private slots:
void invalidState();
void nonExistingFileDates();
+
+private:
+ const QString m_currentDir;
+ QString m_sourceFile;
+ QString m_resourcesDir;
+ QTemporaryDir m_dir;
};
-void tst_QFileInfo::cleanupTestCase()
+void tst_QFileInfo::initTestCase()
{
- QFile::remove("brokenlink.lnk");
- QFile::remove("link.lnk");
- QFile::remove("file1");
- QFile::remove("dummyfile");
- QFile::remove("simplefile.txt");
- QFile::remove("longFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileName.txt");
- QFile::remove("tempfile.txt");
+ m_sourceFile = QFINDTESTDATA("tst_qfileinfo.cpp");
+ QVERIFY(!m_sourceFile.isEmpty());
+ m_resourcesDir = QFINDTESTDATA("resources");
+ QVERIFY(!m_resourcesDir.isEmpty());
+ QVERIFY(m_dir.isValid());
+ QVERIFY(QDir::setCurrent(m_dir.path()));
+}
-#if defined(Q_OS_UNIX)
- QDir().rmdir("./.hidden-directory");
- QFile::remove("link_to_tst_qfileinfo");
-#endif
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- QDir().rmdir("./hidden-directory");
- QDir().rmdir("abs_symlink");
- QDir().rmdir("rel_symlink");
- QDir().rmdir("junction_pwd");
- QDir().rmdir("junction_root");
- QDir().rmdir("mountpoint");
- QFile::remove("abs_symlink.cpp");
- QFile::remove("rel_symlink.cpp");
-#endif
+void tst_QFileInfo::cleanupTestCase()
+{
+ QDir::setCurrent(m_currentDir); // Release temporary directory so that it can be deleted on Windows
}
// Testing get/set functions
@@ -237,10 +242,9 @@ static QFileInfoPrivate* getPrivate(QFileInfo &info)
void tst_QFileInfo::copy()
{
- QTemporaryFile *t;
- t = new QTemporaryFile;
- t->open();
- QFileInfo info(t->fileName());
+ QTemporaryFile t;
+ t.open();
+ QFileInfo info(t.fileName());
QVERIFY(info.exists());
//copy constructor
@@ -287,7 +291,7 @@ void tst_QFileInfo::isFile_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QDir::currentPath() << false;
- QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true;
+ QTest::newRow("data1") << m_sourceFile << true;
QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << false;
QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << true;
QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false;
@@ -320,13 +324,13 @@ void tst_QFileInfo::isDir_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QDir::currentPath() << true;
- QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << false;
+ QTest::newRow("data1") << m_sourceFile << false;
QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << true;
QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << false;
QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false;
- QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true;
- QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true;
+ QTest::newRow("simple dir") << m_resourcesDir << true;
+ QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true;
QTest::newRow("broken link") << "brokenlink.lnk" << false;
@@ -366,8 +370,8 @@ void tst_QFileInfo::isRoot_data()
QTest::newRow("data4") << ":/tst_qfileinfo/resources/" << false;
QTest::newRow("data5") << ":/" << true;
- QTest::newRow("simple dir") << QFINDTESTDATA("resources") << false;
- QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << false;
+ 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))
QTest::newRow("drive 1") << "c:" << false;
QTest::newRow("drive 2") << "c:/" << true;
@@ -398,21 +402,21 @@ void tst_QFileInfo::exists_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QDir::currentPath() << true;
- QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true;
+ QTest::newRow("data1") << m_sourceFile << true;
QTest::newRow("data2") << "/I/do_not_expect_this_path_to_exist/" << false;
QTest::newRow("data3") << ":/tst_qfileinfo/resources/" << true;
QTest::newRow("data4") << ":/tst_qfileinfo/resources/file1" << true;
QTest::newRow("data5") << ":/I/do_not_expect_this_path_to_exist/" << false;
- QTest::newRow("data6") << (QFINDTESTDATA("resources/") + "*") << false;
- QTest::newRow("data7") << (QFINDTESTDATA("resources/") + "*.foo") << false;
- QTest::newRow("data8") << (QFINDTESTDATA("resources/") + "*.ext1") << false;
- QTest::newRow("data9") << (QFINDTESTDATA("resources/") + "file?.ext1") << false;
+ QTest::newRow("data6") << (m_resourcesDir + "/*") << false;
+ QTest::newRow("data7") << (m_resourcesDir + "/*.foo") << false;
+ QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false;
+ QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false;
QTest::newRow("data10") << "." << true;
QTest::newRow("data11") << ". " << false;
QTest::newRow("empty") << "" << false;
- QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true;
- QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true;
+ 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)
QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
@@ -561,7 +565,7 @@ void tst_QFileInfo::canonicalFilePath()
// test symlinks
QFile::remove("link.lnk");
{
- QFile file(QFINDTESTDATA("tst_qfileinfo.cpp"));
+ QFile file(m_sourceFile);
if (file.link("link.lnk")) {
QFileInfo info1(file);
QFileInfo info2("link.lnk");
@@ -587,7 +591,7 @@ void tst_QFileInfo::canonicalFilePath()
QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath());
QFileInfo info3(link + QDir::separator() + "link.lnk");
- QFileInfo info4(QFINDTESTDATA("tst_qfileinfo.cpp"));
+ QFileInfo info4(m_sourceFile);
QVERIFY(!info3.canonicalFilePath().isEmpty());
QCOMPARE(info4.canonicalFilePath(), info3.canonicalFilePath());
@@ -621,20 +625,21 @@ void tst_QFileInfo::canonicalFilePath()
// CreateSymbolicLink can return TRUE & still fail to create the link,
// the error code in that case is ERROR_PRIVILEGE_NOT_HELD (1314)
SetLastError(0);
- BOOL ret = ptrCreateSymbolicLink((wchar_t*)QString("res").utf16(), (wchar_t*)QString("resources").utf16(), 1);
+ const QString linkTarget = QStringLiteral("res");
+ BOOL ret = ptrCreateSymbolicLink((wchar_t*)linkTarget.utf16(), (wchar_t*)m_resourcesDir.utf16(), 1);
DWORD dwErr = GetLastError();
if (!ret)
QSKIP("Symbolic links aren't supported by FS");
QString currentPath = QDir::currentPath();
- bool is_res_Current = QDir::setCurrent("res");
+ bool is_res_Current = QDir::setCurrent(linkTarget);
if (!is_res_Current && dwErr == 1314)
QSKIP("Not enough privilages to create Symbolic links");
QCOMPARE(is_res_Current, true);
+ const QString actualCanonicalPath = QFileInfo("file1").canonicalFilePath();
+ QVERIFY(QDir::setCurrent(currentPath));
+ QCOMPARE(actualCanonicalPath, m_resourcesDir + QStringLiteral("/file1"));
- QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1");
-
- QCOMPARE(QDir::setCurrent(currentPath), true);
- QDir::current().rmdir("res");
+ QDir::current().rmdir(linkTarget);
}
#endif
}
@@ -855,7 +860,7 @@ void tst_QFileInfo::permission_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << int(QFile::ExeUser) << true;
- QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << int(QFile::ReadUser) << true;
+ QTest::newRow("data1") << m_sourceFile << int(QFile::ReadUser) << true;
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true;
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false;
QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ExeUser) << false;
@@ -921,13 +926,15 @@ void tst_QFileInfo::compare_data()
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6)
caseSensitiveOnMac = false;
#endif
+ QString caseChangedSource = m_sourceFile;
+ caseChangedSource.replace("info", "Info");
QTest::newRow("data0")
- << QFINDTESTDATA("tst_qfileinfo.cpp")
- << QFINDTESTDATA("tst_qfileinfo.cpp")
+ << m_sourceFile
+ << m_sourceFile
<< true;
QTest::newRow("data1")
- << QFINDTESTDATA("tst_qfileinfo.cpp")
+ << m_sourceFile
<< QString::fromLatin1("/tst_qfileinfo.cpp")
<< false;
QTest::newRow("data2")
@@ -935,8 +942,8 @@ void tst_QFileInfo::compare_data()
<< QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp")
<< true;
QTest::newRow("casesense1")
- << QFINDTESTDATA("tst_qfileinfo.cpp").replace("info", "Info")
- << QFINDTESTDATA("tst_qfileinfo.cpp")
+ << caseChangedSource
+ << m_sourceFile
#if defined(Q_OS_WIN)
<< true;
#elif defined(Q_OS_MAC)
@@ -1013,7 +1020,7 @@ void tst_QFileInfo::fileTimes()
QEXPECT_FAIL("longfile absolutepath", "No long filenames on WinCE", Abort);
#endif
QVERIFY(file.open(QFile::WriteOnly | QFile::Text));
-#ifdef Q_OS_UNIX
+#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
if (qIsLikelyToBeNfs(file.handle()))
QSKIP("This Test doesn't work on NFS");
#endif
@@ -1140,7 +1147,7 @@ void tst_QFileInfo::isSymLink_data()
QFile::remove("brokenlink.lnk");
QFile::remove("dummyfile");
- QFile file1(QFINDTESTDATA("tst_qfileinfo.cpp"));
+ QFile file1(m_sourceFile);
QVERIFY(file1.link("link.lnk"));
QFile file2("dummyfile");
@@ -1152,8 +1159,8 @@ void tst_QFileInfo::isSymLink_data()
QTest::addColumn<bool>("isSymLink");
QTest::addColumn<QString>("linkTarget");
- QTest::newRow("existent file") << QFINDTESTDATA("tst_qfileinfo.cpp") << false << "";
- QTest::newRow("link") << "link.lnk" << true << QFileInfo(QFINDTESTDATA("tst_qfileinfo.cpp")).absoluteFilePath();
+ QTest::newRow("existent file") << m_sourceFile << false << "";
+ QTest::newRow("link") << "link.lnk" << true << QFileInfo(m_sourceFile).absoluteFilePath();
QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath();
}
@@ -1390,7 +1397,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
}
{
//File symlinks
- QFileInfo target(QFINDTESTDATA("tst_qfileinfo.cpp"));
+ QFileInfo target(m_sourceFile);
QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath());
QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp");
QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath()));
@@ -1447,10 +1454,22 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks()
QFETCH(QString, canonicalFilePath);
QFileInfo fi(path);
- QCOMPARE(fi.isSymLink(), isSymLink);
+ const bool actualIsSymLink = fi.isSymLink();
+ const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString();
+ const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString();
+ // Ensure that junctions, mountpoints are removed. If this fails, do not remove
+ // temporary directory to prevent it from trashing the system.
+ if (fi.isDir()) {
+ if (!QDir().rmdir(fi.fileName())) {
+ qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.",
+ qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path())));
+ m_dir.setAutoRemove(false);
+ }
+ }
+ QCOMPARE(actualIsSymLink, isSymLink);
if (isSymLink) {
- QCOMPARE(fi.symLinkTarget(), linkTarget);
- QCOMPARE(fi.canonicalFilePath(), canonicalFilePath);
+ QCOMPARE(actualSymLinkTarget, linkTarget);
+ QCOMPARE(actualCanonicalFilePath, canonicalFilePath);
}
}
@@ -1499,7 +1518,7 @@ void tst_QFileInfo::isWritable()
#if defined (Q_OS_BLACKBERRY)
// The Blackberry filesystem is read-only
QVERIFY(!QFileInfo("/etc/passwd").isWritable());
-#elif defined (Q_OS_UNIX)
+#elif defined (Q_OS_UNIX) && !defined(Q_OS_VXWORKS) // VxWorks does not have users/groups
if (::getuid() == 0)
QVERIFY(QFileInfo("/etc/passwd").isWritable());
else
@@ -1698,7 +1717,7 @@ QT_END_NAMESPACE
void tst_QFileInfo::owner()
{
QString userName;
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
{
passwd *user = getpwuid(geteuid());
QVERIFY(user);
@@ -1761,7 +1780,7 @@ void tst_QFileInfo::owner()
void tst_QFileInfo::group()
{
QString expected;
-#if defined(Q_OS_UNIX)
+#if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS)
struct group *gr;
gid_t gid = getegid();
diff --git a/tests/auto/corelib/io/qlockfile/qlockfile.pro b/tests/auto/corelib/io/qlockfile/qlockfile.pro
new file mode 100644
index 0000000000..91f104305c
--- /dev/null
+++ b/tests/auto/corelib/io/qlockfile/qlockfile.pro
@@ -0,0 +1,3 @@
+TEMPLATE = subdirs
+
+SUBDIRS += tst_qlockfile.pro qlockfiletesthelper/qlockfile_test_helper.pro
diff --git a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp
new file mode 100644
index 0000000000..63f6291034
--- /dev/null
+++ b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QDebug>
+#include <QCoreApplication>
+#include <QLockFile>
+#include <QThread>
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication app(argc, argv);
+
+ if (argc <= 1)
+ return -1;
+
+ const QString lockName = QString::fromLocal8Bit(argv[1]);
+
+ QString option;
+ if (argc > 2)
+ option = QString::fromLocal8Bit(argv[2]);
+
+ if (option == "-crash") {
+ QLockFile *lockFile = new QLockFile(lockName);
+ lockFile->lock();
+ // leak the lockFile on purpose, so that the lock remains!
+ return 0;
+ } else if (option == "-busy") {
+ QLockFile lockFile(lockName);
+ lockFile.lock();
+ QThread::msleep(500);
+ return 0;
+ } else {
+ QLockFile lockFile(lockName);
+ if (lockFile.isLocked()) // cannot happen, before calling lock or tryLock
+ return QLockFile::UnknownError;
+
+ lockFile.tryLock();
+ return lockFile.error();
+ }
+}
diff --git a/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro
new file mode 100644
index 0000000000..3ac3be9c9b
--- /dev/null
+++ b/tests/auto/corelib/io/qlockfile/qlockfiletesthelper/qlockfile_test_helper.pro
@@ -0,0 +1,7 @@
+TARGET = qlockfile_test_helper
+SOURCES += qlockfile_test_helper.cpp
+
+CONFIG += console
+CONFIG -= app_bundle
+QT = core
+DESTDIR = ./
diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
new file mode 100644
index 0000000000..c0bf77cfb2
--- /dev/null
+++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.cpp
@@ -0,0 +1,379 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 David Faure <faure+bluesystems@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <QtConcurrentRun>
+#include <qlockfile.h>
+#include <qtemporarydir.h>
+
+class tst_QLockFile : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void initTestCase();
+ void lockUnlock();
+ void lockOutOtherProcess();
+ void lockOutOtherThread();
+ void waitForLock_data();
+ void waitForLock();
+ void staleLockFromCrashedProcess_data();
+ void staleLockFromCrashedProcess();
+ void staleShortLockFromBusyProcess();
+ void staleLongLockFromBusyProcess();
+ void staleLockRace();
+ void noPermissions();
+
+public:
+ QString m_helperApp;
+ QTemporaryDir dir;
+};
+
+void tst_QLockFile::initTestCase()
+{
+#ifdef QT_NO_PROCESS
+ QSKIP("This test requires QProcess support");
+#else
+ // chdir to our testdata path and execute helper apps relative to that.
+ QString testdata_dir = QFileInfo(QFINDTESTDATA("qlockfiletesthelper")).absolutePath();
+ QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir));
+ m_helperApp = "qlockfiletesthelper/qlockfile_test_helper";
+#endif
+}
+
+void tst_QLockFile::lockUnlock()
+{
+ const QString fileName = dir.path() + "/lock1";
+ QVERIFY(!QFile(fileName).exists());
+ QLockFile lockFile(fileName);
+ QVERIFY(lockFile.lock());
+ QVERIFY(lockFile.isLocked());
+ QCOMPARE(int(lockFile.error()), int(QLockFile::NoError));
+ QVERIFY(QFile::exists(fileName));
+
+ // Recursive locking is not allowed
+ // (can't test lock() here, it would wait forever)
+ QVERIFY(!lockFile.tryLock());
+ QCOMPARE(int(lockFile.error()), int(QLockFile::LockFailedError));
+ qint64 pid;
+ QString hostname, appname;
+ QVERIFY(lockFile.getLockInfo(&pid, &hostname, &appname));
+ QCOMPARE(pid, QCoreApplication::applicationPid());
+ QCOMPARE(appname, qAppName());
+ QVERIFY(!lockFile.tryLock(200));
+ QCOMPARE(int(lockFile.error()), int(QLockFile::LockFailedError));
+
+ // Unlock deletes the lock file
+ lockFile.unlock();
+ QCOMPARE(int(lockFile.error()), int(QLockFile::NoError));
+ QVERIFY(!lockFile.isLocked());
+ QVERIFY(!QFile::exists(fileName));
+}
+
+void tst_QLockFile::lockOutOtherProcess()
+{
+ // Lock
+ const QString fileName = dir.path() + "/lockOtherProcess";
+ QLockFile lockFile(fileName);
+ QVERIFY(lockFile.lock());
+
+ // Other process can't acquire lock
+ QProcess proc;
+ proc.start(m_helperApp, QStringList() << fileName);
+ QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
+ QVERIFY(proc.waitForFinished());
+ QCOMPARE(proc.exitCode(), int(QLockFile::LockFailedError));
+
+ // Unlock
+ lockFile.unlock();
+ QVERIFY(!QFile::exists(fileName));
+
+ // Other process can now acquire lock
+ int ret = QProcess::execute(m_helperApp, QStringList() << fileName);
+ QCOMPARE(ret, int(QLockFile::NoError));
+ // Lock doesn't survive process though (on clean exit)
+ QVERIFY(!QFile::exists(fileName));
+}
+
+static QLockFile::LockError tryLockFromThread(const QString &fileName)
+{
+ QLockFile lockInThread(fileName);
+ lockInThread.tryLock();
+ return lockInThread.error();
+}
+
+void tst_QLockFile::lockOutOtherThread()
+{
+ const QString fileName = dir.path() + "/lockOtherThread";
+ QLockFile lockFile(fileName);
+ QVERIFY(lockFile.lock());
+
+ // Other thread can't acquire lock
+ QFuture<QLockFile::LockError> ret = QtConcurrent::run<QLockFile::LockError>(tryLockFromThread, fileName);
+ QCOMPARE(ret.result(), QLockFile::LockFailedError);
+
+ lockFile.unlock();
+
+ // Now other thread can acquire lock
+ QFuture<QLockFile::LockError> ret2 = QtConcurrent::run<QLockFile::LockError>(tryLockFromThread, fileName);
+ QCOMPARE(ret2.result(), QLockFile::NoError);
+}
+
+static bool lockFromThread(const QString &fileName, int sleepMs, QSemaphore *semThreadReady, QSemaphore *semMainThreadDone)
+{
+ QLockFile lockFile(fileName);
+ if (!lockFile.lock()) {
+ qWarning() << "Locking failed" << lockFile.error();
+ return false;
+ }
+ semThreadReady->release();
+ QThread::msleep(sleepMs);
+ semMainThreadDone->acquire();
+ lockFile.unlock();
+ return true;
+}
+
+void tst_QLockFile::waitForLock_data()
+{
+ QTest::addColumn<int>("testNumber");
+ QTest::addColumn<int>("threadSleepMs");
+ QTest::addColumn<bool>("releaseEarly");
+ QTest::addColumn<int>("tryLockTimeout");
+ QTest::addColumn<bool>("expectedResult");
+
+ int tn = 0; // test number
+ QTest::newRow("wait_forever_succeeds") << ++tn << 500 << true << -1 << true;
+ QTest::newRow("wait_longer_succeeds") << ++tn << 500 << true << 1000 << true;
+ QTest::newRow("wait_zero_fails") << ++tn << 500 << false << 0 << false;
+ QTest::newRow("wait_not_enough_fails") << ++tn << 500 << false << 100 << false;
+}
+
+void tst_QLockFile::waitForLock()
+{
+ QFETCH(int, testNumber);
+ QFETCH(int, threadSleepMs);
+ QFETCH(bool, releaseEarly);
+ QFETCH(int, tryLockTimeout);
+ QFETCH(bool, expectedResult);
+
+ const QString fileName = dir.path() + "/waitForLock" + QString::number(testNumber);
+ QLockFile lockFile(fileName);
+ QSemaphore semThreadReady, semMainThreadDone;
+ // Lock file from a thread
+ QFuture<bool> ret = QtConcurrent::run<bool>(lockFromThread, fileName, threadSleepMs, &semThreadReady, &semMainThreadDone);
+ semThreadReady.acquire();
+
+ if (releaseEarly) // let the thread release the lock after threadSleepMs
+ semMainThreadDone.release();
+
+ QCOMPARE(lockFile.tryLock(tryLockTimeout), expectedResult);
+ if (expectedResult)
+ QCOMPARE(int(lockFile.error()), int(QLockFile::NoError));
+ else
+ QCOMPARE(int(lockFile.error()), int(QLockFile::LockFailedError));
+
+ if (!releaseEarly) // only let the thread release the lock now
+ semMainThreadDone.release();
+
+ QVERIFY(ret); // waits for the thread to finish
+}
+
+void tst_QLockFile::staleLockFromCrashedProcess_data()
+{
+ QTest::addColumn<int>("staleLockTime");
+
+ // Test both use cases for QLockFile, should make no difference here.
+ QTest::newRow("short") << 30000;
+ QTest::newRow("long") << 0;
+}
+
+void tst_QLockFile::staleLockFromCrashedProcess()
+{
+ QFETCH(int, staleLockTime);
+ const QString fileName = dir.path() + "/staleLockFromCrashedProcess";
+
+ int ret = QProcess::execute(m_helperApp, QStringList() << fileName << "-crash");
+ QCOMPARE(ret, int(QLockFile::NoError));
+ QTRY_VERIFY(QFile::exists(fileName));
+
+ QLockFile secondLock(fileName);
+ secondLock.setStaleLockTime(staleLockTime);
+ // tryLock detects and removes the stale lock (since the PID is dead)
+#ifdef Q_OS_WIN
+ // It can take a bit of time on Windows, though.
+ QVERIFY(secondLock.tryLock(30000));
+#else
+ QVERIFY(secondLock.tryLock());
+#endif
+ QCOMPARE(int(secondLock.error()), int(QLockFile::NoError));
+}
+
+void tst_QLockFile::staleShortLockFromBusyProcess()
+{
+ const QString fileName = dir.path() + "/staleLockFromBusyProcess";
+
+ QProcess proc;
+ proc.start(m_helperApp, QStringList() << fileName << "-busy");
+ QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
+ QTRY_VERIFY(QFile::exists(fileName));
+
+ QLockFile secondLock(fileName);
+ QVERIFY(!secondLock.tryLock()); // held by other process
+ QCOMPARE(int(secondLock.error()), int(QLockFile::LockFailedError));
+ qint64 pid;
+ QString hostname, appname;
+ QTRY_VERIFY(secondLock.getLockInfo(&pid, &hostname, &appname));
+#ifdef Q_OS_UNIX
+ QCOMPARE(pid, proc.pid());
+#endif
+
+ secondLock.setStaleLockTime(100);
+ QTest::qSleep(100); // make the lock stale
+ // We can't "steal" (delete+recreate) a lock file from a running process
+ // until the file descriptor is closed.
+ QVERIFY(!secondLock.tryLock());
+
+ proc.waitForFinished();
+ QVERIFY(secondLock.tryLock());
+}
+
+void tst_QLockFile::staleLongLockFromBusyProcess()
+{
+ const QString fileName = dir.path() + "/staleLockFromBusyProcess";
+
+ QProcess proc;
+ proc.start(m_helperApp, QStringList() << fileName << "-busy");
+ QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString()));
+ QTRY_VERIFY(QFile::exists(fileName));
+
+ QLockFile secondLock(fileName);
+ secondLock.setStaleLockTime(0);
+ QVERIFY(!secondLock.tryLock(100)); // never stale
+ QCOMPARE(int(secondLock.error()), int(QLockFile::LockFailedError));
+ qint64 pid;
+ QTRY_VERIFY(secondLock.getLockInfo(&pid, NULL, NULL));
+ QVERIFY(pid > 0);
+
+ // As long as the other process is running, we can't remove the lock file
+ QVERIFY(!secondLock.removeStaleLockFile());
+
+ proc.waitForFinished();
+}
+
+static QString tryStaleLockFromThread(const QString &fileName)
+{
+ QLockFile lockInThread(fileName + ".lock");
+ lockInThread.setStaleLockTime(1000);
+ if (!lockInThread.lock())
+ return "Error locking: " + QString::number(lockInThread.error());
+
+ // The concurrent use of the file below (write, read, delete) is protected by the lock file above.
+ // (provided that it doesn't become stale due to this operation taking too long)
+ QFile theFile(fileName);
+ if (!theFile.open(QIODevice::WriteOnly))
+ return "Couldn't open for write";
+ theFile.write("Hello world");
+ theFile.flush();
+ theFile.close();
+ QFile reader(fileName);
+ if (!reader.open(QIODevice::ReadOnly))
+ return "Couldn't open for read";
+ const QByteArray read = reader.readAll();
+ if (read != "Hello world")
+ return "File didn't have the expected contents:" + read;
+ reader.remove();
+ return QString();
+}
+
+void tst_QLockFile::staleLockRace()
+{
+ // Multiple threads notice a stale lock at the same time
+ // Only one thread should delete it, otherwise a race will ensue
+ const QString fileName = dir.path() + "/sharedFile";
+ const QString lockName = fileName + ".lock";
+ int ret = QProcess::execute(m_helperApp, QStringList() << lockName << "-crash");
+ QCOMPARE(ret, int(QLockFile::NoError));
+ QTRY_VERIFY(QFile::exists(lockName));
+
+ QThreadPool::globalInstance()->setMaxThreadCount(10);
+ QFutureSynchronizer<QString> synchronizer;
+ for (int i = 0; i < 8; ++i)
+ synchronizer.addFuture(QtConcurrent::run<QString>(tryStaleLockFromThread, fileName));
+ synchronizer.waitForFinished();
+ foreach (const QFuture<QString> &future, synchronizer.futures())
+ QVERIFY2(future.result().isEmpty(), qPrintable(future.result()));
+}
+
+void tst_QLockFile::noPermissions()
+{
+#ifdef Q_OS_WIN
+ // A readonly directory still allows us to create files, on Windows.
+ QSKIP("No permission testing on Windows");
+#endif
+ // Restore permissions so that the QTemporaryDir cleanup can happen
+ class PermissionRestorer
+ {
+ QString m_path;
+ public:
+ PermissionRestorer(const QString& path)
+ : m_path(path)
+ {}
+
+ ~PermissionRestorer()
+ {
+ QFile file(m_path);
+ file.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner));
+ }
+ };
+
+ const QString fileName = dir.path() + "/staleLock";
+ QFile dirAsFile(dir.path()); // I have to use QFile to change a dir's permissions...
+ QVERIFY2(dirAsFile.setPermissions(QFile::Permissions(0)), qPrintable(dir.path())); // no permissions
+ PermissionRestorer permissionRestorer(dir.path());
+
+ QLockFile lockFile(fileName);
+ QVERIFY(!lockFile.lock());
+ QCOMPARE(int(lockFile.error()), int(QLockFile::PermissionError));
+}
+
+QTEST_MAIN(tst_QLockFile)
+#include "tst_qlockfile.moc"
diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro
new file mode 100644
index 0000000000..2f7009b736
--- /dev/null
+++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro
@@ -0,0 +1,6 @@
+CONFIG += testcase
+CONFIG -= app_bundle
+TARGET = tst_qlockfile
+SOURCES += tst_qlockfile.cpp
+
+QT = core testlib concurrent
diff --git a/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro b/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro
index 271c7ead13..45b498c32a 100644
--- a/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro
+++ b/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro
@@ -2,3 +2,4 @@ SOURCES = main.cpp
CONFIG -= app_bundle
CONFIG += console
DESTDIR = ./
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp b/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp
index 270666deb6..df96e1cbf3 100644
--- a/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp
+++ b/tests/auto/corelib/io/qprocess/testProcessEchoGui/main_win.cpp
@@ -50,8 +50,8 @@ int APIENTRY WinMain(HINSTANCE /* hInstance */,
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
HANDLE hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
-
- HANDLE hStderr = GetStdHandle(STD_ERROR_HANDLE);
+
+ HANDLE hStderr = GetStdHandle(STD_ERROR_HANDLE);
for (;;) {
diff --git a/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro b/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro
index f7c57abc37..f7bb0985a3 100644
--- a/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro
+++ b/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro
@@ -4,3 +4,4 @@ CONFIG -= qt app_bundle
DESTDIR = ./
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro b/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro
index 3940ddbf98..2de4534896 100644
--- a/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro
+++ b/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro
@@ -3,3 +3,4 @@ CONFIG -= qt app_bundle
CONFIG += console
DESTDIR = ./
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro
index 43db95e675..8b16f65e34 100644
--- a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro
+++ b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro
@@ -6,3 +6,4 @@ OBJECTS_DIR = $${OBJECTS_DIR}-twospaces
TARGET = "two space s"
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro b/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro
index 86d26c2c4a..d425d5569e 100644
--- a/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro
+++ b/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro
@@ -3,3 +3,4 @@ CONFIG += console
CONFIG -= app_bundle
DESTDIR = ./
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/main_unix.cpp b/tests/auto/corelib/io/qprocess/testSoftExit/main_unix.cpp
index 02cc31168b..c7f5f88f9c 100644
--- a/tests/auto/corelib/io/qprocess/testSoftExit/main_unix.cpp
+++ b/tests/auto/corelib/io/qprocess/testSoftExit/main_unix.cpp
@@ -55,7 +55,7 @@ int main()
printf("Ready\n");
fflush(stdout);
-
+
for (int i = 0; i < 5; ++i)
sleep(1);
return 0;
diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/main_win.cpp b/tests/auto/corelib/io/qprocess/testSoftExit/main_win.cpp
index bed8d921b3..e478a18bd6 100644
--- a/tests/auto/corelib/io/qprocess/testSoftExit/main_win.cpp
+++ b/tests/auto/corelib/io/qprocess/testSoftExit/main_win.cpp
@@ -53,6 +53,6 @@ int main()
if (msg.message == WM_CLOSE)
PostQuitMessage(0);
}
-
+
return int(msg.wParam);
}
diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro
index c5fb286d0c..7f3b8ade3e 100644
--- a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro
+++ b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro
@@ -10,3 +10,4 @@ CONFIG -= qt app_bundle
CONFIG += console
DESTDIR = ./
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro b/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro
index d0848e3303..b7213ae507 100644
--- a/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro
+++ b/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro
@@ -7,3 +7,4 @@ mac {
CONFIG -= app_bundle
}
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
+QT = core
diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
index 7965d1d431..f01e319872 100644
--- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
+++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp
@@ -81,6 +81,7 @@ private slots:
void getSetCheck();
void constructing();
void simpleStart();
+ void startWithOpen();
void execute();
void startDetached();
void crashTest();
@@ -283,6 +284,25 @@ void tst_QProcess::simpleStart()
QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(1).at(0)), QProcess::Running);
QCOMPARE(qvariant_cast<QProcess::ProcessState>(spy.at(2).at(0)), QProcess::NotRunning);
}
+
+//-----------------------------------------------------------------------------
+void tst_QProcess::startWithOpen()
+{
+ QProcess p;
+ QTest::ignoreMessage(QtWarningMsg, "QProcess::start: program not set");
+ QCOMPARE(p.open(QIODevice::ReadOnly), false);
+
+ p.setProgram("testProcessNormal/testProcessNormal");
+ QCOMPARE(p.program(), QString("testProcessNormal/testProcessNormal"));
+
+ p.setArguments(QStringList() << "arg1" << "arg2");
+ QCOMPARE(p.arguments().size(), 2);
+
+ QVERIFY(p.open(QIODevice::ReadOnly));
+ QCOMPARE(p.openMode(), QIODevice::ReadOnly);
+ QVERIFY(p.waitForFinished(5000));
+}
+
//-----------------------------------------------------------------------------
void tst_QProcess::execute()
{
@@ -1256,7 +1276,6 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot()
process->start("testProcessEcho/testProcessEcho");
QVERIFY(process->waitForStarted(5000));
- qRegisterMetaType<qint64>("qint64");
QSignalSpy spy(process, SIGNAL(bytesWritten(qint64)));
QVERIFY(spy.isValid());
process->write("f");
diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
index 11dbc1e9c1..515a10426c 100644
--- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
+++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp
@@ -402,7 +402,7 @@ void tst_QResourceEngine::checkUnregisterResource_data()
QTest::addColumn<int>("size");
QTest::newRow("currentdir.txt") << QFINDTESTDATA("runtime_resource.rcc") << QString("/check_unregister/")
- << QString(":/check_unregister/runtime_resource/test/abc/123/+++/currentdir.txt")
+ << QString(":/check_unregister/runtime_resource/test/abc/123/+++/currentdir.txt")
<< (int)QFileInfo(QFINDTESTDATA("testqrc/currentdir.txt")).size();
}
diff --git a/tests/auto/corelib/io/qsavefile/qsavefile.pro b/tests/auto/corelib/io/qsavefile/qsavefile.pro
new file mode 100644
index 0000000000..36db000fa7
--- /dev/null
+++ b/tests/auto/corelib/io/qsavefile/qsavefile.pro
@@ -0,0 +1,5 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qsavefile
+QT = core testlib
+SOURCES = tst_qsavefile.cpp
+TESTDATA += tst_qsavefile.cpp
diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp
new file mode 100644
index 0000000000..5ef4b11e8a
--- /dev/null
+++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp
@@ -0,0 +1,272 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 David Faure <faure@kde.org>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the QtCore module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <qcoreapplication.h>
+#include <qstring.h>
+#include <qtemporaryfile.h>
+#include <qfile.h>
+#include <qdir.h>
+#include <qset.h>
+
+#if defined(Q_OS_UNIX)
+# include <unistd.h> // for geteuid
+# include <sys/types.h>
+#endif
+
+#if defined(Q_OS_WIN)
+# include <windows.h>
+#endif
+
+class tst_QSaveFile : public QObject
+{
+ Q_OBJECT
+public slots:
+
+private slots:
+ void transactionalWrite();
+ void textStreamManualFlush();
+ void textStreamAutoFlush();
+ void saveTwice();
+ void transactionalWriteNoPermissionsOnDir();
+ void transactionalWriteNoPermissionsOnFile();
+ void transactionalWriteCanceled();
+ void transactionalWriteErrorRenaming();
+};
+
+void tst_QSaveFile::transactionalWrite()
+{
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QFile::remove(targetFile);
+ QSaveFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ QVERIFY(file.isOpen());
+ QCOMPARE(file.fileName(), targetFile);
+ QVERIFY(!QFile::exists(targetFile));
+
+ QCOMPARE(file.write("Hello"), Q_INT64_C(5));
+ QCOMPARE(file.error(), QFile::NoError);
+ QVERIFY(!QFile::exists(targetFile));
+
+ QVERIFY(file.commit());
+ QVERIFY(QFile::exists(targetFile));
+ QCOMPARE(file.fileName(), targetFile);
+
+ QFile reader(targetFile);
+ QVERIFY(reader.open(QIODevice::ReadOnly));
+ QCOMPARE(QString::fromLatin1(reader.readAll()), QString::fromLatin1("Hello"));
+}
+
+void tst_QSaveFile::saveTwice()
+{
+ // Check that we can reuse a QSaveFile object
+ // (and test the case of an existing target file)
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QSaveFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ QCOMPARE(file.write("Hello"), Q_INT64_C(5));
+ QVERIFY2(file.commit(), qPrintable(file.errorString()));
+
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ QCOMPARE(file.write("World"), Q_INT64_C(5));
+ QVERIFY2(file.commit(), qPrintable(file.errorString()));
+
+ QFile reader(targetFile);
+ QVERIFY(reader.open(QIODevice::ReadOnly));
+ QCOMPARE(QString::fromLatin1(reader.readAll()), QString::fromLatin1("World"));
+}
+
+void tst_QSaveFile::textStreamManualFlush()
+{
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QSaveFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+
+ QTextStream ts(&file);
+ ts << "Manual flush";
+ ts.flush();
+ QCOMPARE(file.error(), QFile::NoError);
+ QVERIFY(!QFile::exists(targetFile));
+
+ QVERIFY(file.commit());
+ QFile reader(targetFile);
+ QVERIFY(reader.open(QIODevice::ReadOnly));
+ QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Manual flush"));
+ QFile::remove(targetFile);
+}
+
+void tst_QSaveFile::textStreamAutoFlush()
+{
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QSaveFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+
+ QTextStream ts(&file);
+ ts << "Auto-flush.";
+ // no flush
+ QVERIFY(file.commit()); // QIODevice::close will emit aboutToClose, which will flush the stream
+ QFile reader(targetFile);
+ QVERIFY(reader.open(QIODevice::ReadOnly));
+ QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Auto-flush."));
+ QFile::remove(targetFile);
+}
+
+void tst_QSaveFile::transactionalWriteNoPermissionsOnDir()
+{
+#ifdef Q_OS_UNIX
+ if (::geteuid() == 0)
+ QSKIP("not valid running this test as root");
+
+ // You can write into /dev/zero, but you can't create a /dev/zero.XXXXXX temp file.
+ QSaveFile file("/dev/zero");
+ if (!QDir("/dev").exists())
+ QSKIP("/dev doesn't exist on this system");
+
+ QVERIFY(!file.open(QIODevice::WriteOnly));
+ QCOMPARE((int)file.error(), (int)QFile::OpenError);
+ QVERIFY(!file.commit());
+#endif
+}
+
+void tst_QSaveFile::transactionalWriteNoPermissionsOnFile()
+{
+ // Setup an existing but readonly file
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ QCOMPARE(file.write("Hello"), Q_INT64_C(5));
+ file.close();
+ file.setPermissions(QFile::ReadOwner);
+ QVERIFY(!file.open(QIODevice::WriteOnly));
+
+ // Try saving into it
+ {
+ QSaveFile saveFile(targetFile);
+ QVERIFY(!saveFile.open(QIODevice::WriteOnly)); // just like QFile
+ }
+ QVERIFY(file.exists());
+}
+
+void tst_QSaveFile::transactionalWriteCanceled()
+{
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QFile::remove(targetFile);
+ QSaveFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+
+ QTextStream ts(&file);
+ ts << "This writing operation will soon be canceled.\n";
+ ts.flush();
+ QCOMPARE(file.error(), QFile::NoError);
+ QVERIFY(!QFile::exists(targetFile));
+
+ // We change our mind, let's abort writing
+ file.cancelWriting();
+
+ QVERIFY(!file.commit());
+
+ QVERIFY(!QFile::exists(targetFile)); // temp file was discarded
+ QCOMPARE(file.fileName(), targetFile);
+}
+
+void tst_QSaveFile::transactionalWriteErrorRenaming()
+{
+ QTemporaryDir dir;
+ const QString targetFile = dir.path() + QString::fromLatin1("/outfile");
+ QSaveFile file(targetFile);
+ QVERIFY(file.open(QIODevice::WriteOnly));
+ QCOMPARE(file.write("Hello"), qint64(5));
+ QVERIFY(!QFile::exists(targetFile));
+
+ // Restore permissions so that the QTemporaryDir cleanup can happen
+ class PermissionRestorer
+ {
+ public:
+ PermissionRestorer(const QString& path)
+ : m_path(path)
+ {}
+
+ ~PermissionRestorer()
+ {
+ QFile file(m_path);
+#ifdef Q_OS_UNIX
+ file.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner));
+#else
+ file.setPermissions(QFile::WriteOwner);
+ file.remove();
+#endif
+ }
+
+ private:
+ QString m_path;
+ };
+
+#ifdef Q_OS_UNIX
+ // Make rename() fail for lack of permissions in the directory
+ QFile dirAsFile(dir.path()); // yay, I have to use QFile to change a dir's permissions...
+ QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions
+ PermissionRestorer permissionRestorer(dir.path());
+#else
+ // Windows: Make rename() fail for lack of permissions on an existing target file
+ QFile existingTargetFile(targetFile);
+ QVERIFY(existingTargetFile.open(QIODevice::WriteOnly));
+ QCOMPARE(file.write("Target"), qint64(6));
+ existingTargetFile.close();
+ QVERIFY(existingTargetFile.setPermissions(QFile::ReadOwner));
+ PermissionRestorer permissionRestorer(targetFile);
+#endif
+
+ // The saving should fail.
+ QVERIFY(!file.commit());
+#ifdef Q_OS_UNIX
+ QVERIFY(!QFile::exists(targetFile)); // renaming failed
+#endif
+ QCOMPARE(file.error(), QFile::RenameError);
+}
+
+QTEST_MAIN(tst_QSaveFile)
+#include "tst_qsavefile.moc"
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index f152c48c7d..c2909cf7c5 100644
--- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
+++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
@@ -694,7 +694,9 @@ void tst_QSettings::testErrorHandling()
#ifdef Q_OS_WIN
QSKIP("Windows doesn't support most file modes, including read-only directories, so this test is moot.");
#elif defined(Q_OS_UNIX)
+#if !defined(Q_OS_VXWORKS) // VxWorks does not have users/groups
if (::getuid() == 0)
+#endif
QSKIP("Running this test as root doesn't work, since file perms do not bother him");
#else
QFETCH(int, filePerms);
diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
index c4453fd5f2..f94c8eac4f 100644
--- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
+++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp
@@ -45,6 +45,7 @@
#include <qstandardpaths.h>
#include <qfileinfo.h>
#include <qsysinfo.h>
+#include <qregexp.h>
#ifdef Q_OS_UNIX
#include <unistd.h>
@@ -72,6 +73,7 @@ private slots:
void testCustomRuntimeDirectory();
void testAllWritableLocations_data();
void testAllWritableLocations();
+ void testCleanPath();
private:
#ifdef Q_XDG_PLATFORM
@@ -430,6 +432,18 @@ void tst_qstandardpaths::testAllWritableLocations()
QCOMPARE(loc.endsWith(QLatin1Char('/')), false);
}
+void tst_qstandardpaths::testCleanPath()
+{
+ const QRegExp filter(QStringLiteral("\\\\"));
+ QVERIFY(filter.isValid());
+ for (int i = 0; i <= QStandardPaths::GenericCacheLocation; ++i) {
+ const QStringList paths = QStandardPaths::standardLocations(QStandardPaths::StandardLocation(i));
+ QVERIFY2(paths.filter(filter).isEmpty(),
+ qPrintable(QString::fromLatin1("Backslash found in %1 %2")
+ .arg(i).arg(paths.join(QLatin1Char(',')))));
+ }
+}
+
QTEST_MAIN(tst_qstandardpaths)
#include "tst_qstandardpaths.moc"
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 1f59336fc6..898aefffd3 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -79,6 +79,8 @@ private slots:
void toString();
void toString_constructed_data();
void toString_constructed();
+ void toAndFromStringList_data();
+ void toAndFromStringList();
void isParentOf_data();
void isParentOf();
void toLocalFile_data();
@@ -948,6 +950,25 @@ void tst_QUrl::toString()
QCOMPARE(url.toString(QUrl::FormattingOptions(options)), string);
}
+void tst_QUrl::toAndFromStringList_data()
+{
+ QTest::addColumn<QStringList>("strings");
+
+ QTest::newRow("empty") << QStringList();
+ QTest::newRow("local") << (QStringList() << "file:///tmp" << "file:///");
+ QTest::newRow("remote") << (QStringList() << "http://qt-project.org");
+}
+
+void tst_QUrl::toAndFromStringList()
+{
+ QFETCH(QStringList, strings);
+
+ const QList<QUrl> urls = QUrl::fromStringList(strings);
+ QCOMPARE(urls.count(), strings.count());
+ const QStringList converted = QUrl::toStringList(urls);
+ QCOMPARE(converted, strings);
+}
+
//### more tests ... what do we expect ...
void tst_QUrl::isParentOf_data()
{
@@ -2163,33 +2184,52 @@ void tst_QUrl::tldRestrictions_data()
// current whitelist
QTest::newRow("ac") << QString("ac") << true;
+ QTest::newRow("ar") << QString("ar") << true;
+ QTest::newRow("asia") << QString("asia") << true;
QTest::newRow("at") << QString("at") << true;
+ QTest::newRow("biz") << QString("biz") << true;
QTest::newRow("br") << QString("br") << true;
QTest::newRow("cat") << QString("cat") << true;
QTest::newRow("ch") << QString("ch") << true;
QTest::newRow("cl") << QString("cl") << true;
QTest::newRow("cn") << QString("cn") << true;
+ QTest::newRow("com") << QString("com") << true;
QTest::newRow("de") << QString("de") << true;
QTest::newRow("dk") << QString("dk") << true;
+ QTest::newRow("es") << QString("es") << true;
QTest::newRow("fi") << QString("fi") << true;
+ QTest::newRow("gr") << QString("gr") << true;
QTest::newRow("hu") << QString("hu") << true;
+ QTest::newRow("il") << QString("il") << true;
QTest::newRow("info") << QString("info") << true;
QTest::newRow("io") << QString("io") << true;
+ QTest::newRow("is") << QString("is") << true;
+ QTest::newRow("ir") << QString("ir") << true;
QTest::newRow("jp") << QString("jp") << true;
QTest::newRow("kr") << QString("kr") << true;
QTest::newRow("li") << QString("li") << true;
QTest::newRow("lt") << QString("lt") << true;
+ QTest::newRow("lu") << QString("lu") << true;
+ QTest::newRow("lv") << QString("lv") << true;
QTest::newRow("museum") << QString("museum") << true;
+ QTest::newRow("name") << QString("name") << true;
+ QTest::newRow("net") << QString("name") << true;
QTest::newRow("no") << QString("no") << true;
+ QTest::newRow("nu") << QString("nu") << true;
+ QTest::newRow("nz") << QString("nz") << true;
+ QTest::newRow("org") << QString("org") << true;
+ QTest::newRow("pl") << QString("pl") << true;
+ QTest::newRow("pr") << QString("pr") << true;
QTest::newRow("se") << QString("se") << true;
QTest::newRow("sh") << QString("sh") << true;
+ QTest::newRow("tel") << QString("tel") << true;
QTest::newRow("th") << QString("th") << true;
QTest::newRow("tm") << QString("tm") << true;
QTest::newRow("tw") << QString("tw") << true;
+ QTest::newRow("ua") << QString("ua") << true;
QTest::newRow("vn") << QString("vn") << true;
// known blacklists:
- QTest::newRow("com") << QString("com") << false;
QTest::newRow("foo") << QString("foo") << false;
}
@@ -2796,6 +2836,12 @@ void tst_QUrl::effectiveTLDs_data()
QTest::newRow("yes6") << QUrl::fromEncoded("http://www.com.com.cn") << ".com.cn";
QTest::newRow("yes7") << QUrl::fromEncoded("http://www.test.org.ws") << ".org.ws";
QTest::newRow("yes9") << QUrl::fromEncoded("http://www.com.co.uk.wallonie.museum") << ".wallonie.museum";
+ QTest::newRow("yes10") << QUrl::fromEncoded("http://www.com.evje-og-hornnes.no") << ".evje-og-hornnes.no";
+ QTest::newRow("yes11") << QUrl::fromEncoded("http://www.bla.kamijima.ehime.jp") << ".kamijima.ehime.jp";
+ QTest::newRow("yes12") << QUrl::fromEncoded("http://www.bla.kakuda.miyagi.jp") << ".kakuda.miyagi.jp";
+ QTest::newRow("yes13") << QUrl::fromEncoded("http://mypage.betainabox.com") << ".betainabox.com";
+ QTest::newRow("yes14") << QUrl::fromEncoded("http://mypage.rhcloud.com") << ".rhcloud.com";
+ QTest::newRow("yes15") << QUrl::fromEncoded("http://mypage.int.az") << ".int.az";
}
void tst_QUrl::effectiveTLDs()
diff --git a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp
index 6ba659856c..fa3dec620a 100644
--- a/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp
+++ b/tests/auto/corelib/io/qurlinternal/tst_qurlinternal.cpp
@@ -649,6 +649,20 @@ void tst_QUrlInternal::ace_testsuite_data()
<< "xn----rmckbbajlc6dj7bxne2c.xn--wgbh1c"
<< "."
<< egyptianIDN;
+
+ QString russianIDN = QString::fromUtf8("\321\217\320\275\320\264\320\265\320\272\321\201.\321\200\321\204");
+ QTest::newRow("russian-tld-ace")
+ << "xn--d1acpjx3f.xn--p1ai"
+ << "xn--d1acpjx3f.xn--p1ai"
+ << "."
+ << russianIDN;
+
+ QString taiwaneseIDN = QString::fromUtf8("\345\217\260\345\214\227\346\214\211\346\221\251.\345\217\260\347\201\243");
+ QTest::newRow("taiwanese-tld-ace")
+ << "xn--djrptm67aikb.xn--kpry57d"
+ << "xn--djrptm67aikb.xn--kpry57d"
+ << "."
+ << taiwaneseIDN;
}
void tst_QUrlInternal::ace_testsuite()
diff --git a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp
index 6e2eeced05..bad77b1e06 100644
--- a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp
+++ b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp
@@ -251,21 +251,24 @@ void tst_QWinOverlappedIoNotifier::multipleOperations()
// start async read on client
QByteArray clientReadBuffer(377, Qt::Uninitialized);
- OVERLAPPED clientReadOverlapped = {0};
+ OVERLAPPED clientReadOverlapped;
+ ZeroMemory(&clientReadOverlapped, sizeof(clientReadOverlapped));
BOOL readSuccess = ReadFile(hClient, clientReadBuffer.data(), clientReadBuffer.size(),
NULL, &clientReadOverlapped);
QVERIFY(readSuccess || GetLastError() == ERROR_IO_PENDING);
// start async write client -> server
QByteArray clientDataToWrite(233, 'B');
- OVERLAPPED clientWriteOverlapped = {0};
+ OVERLAPPED clientWriteOverlapped;
+ ZeroMemory(&clientWriteOverlapped, sizeof(clientWriteOverlapped));
BOOL writeSuccess = WriteFile(hClient, clientDataToWrite.data(), clientDataToWrite.size(),
NULL, &clientWriteOverlapped);
QVERIFY(writeSuccess || GetLastError() == ERROR_IO_PENDING);
// start async write server -> client
QByteArray serverDataToWrite(144, 'A');
- OVERLAPPED serverOverlapped = {0};
+ OVERLAPPED serverOverlapped;
+ ZeroMemory(&serverOverlapped, sizeof(serverOverlapped));
writeSuccess = WriteFile(hServer, serverDataToWrite.data(), serverDataToWrite.size(),
NULL, &serverOverlapped);
QVERIFY(writeSuccess || GetLastError() == ERROR_IO_PENDING);
@@ -284,9 +287,9 @@ void tst_QWinOverlappedIoNotifier::multipleOperations()
QTRY_COMPARE(sink.notifications.count(), 2);
foreach (const NotifierSink::IOResult &r, sink.notifications) {
QCOMPARE(r.errorCode, DWORD(ERROR_SUCCESS));
- if (r.bytes == serverDataToWrite.count())
+ if (r.bytes == DWORD(serverDataToWrite.count()))
QCOMPARE(r.overlapped, &clientReadOverlapped);
- else if (r.bytes == clientDataToWrite.count())
+ else if (r.bytes == DWORD(clientDataToWrite.count()))
QCOMPARE(r.overlapped, &clientWriteOverlapped);
else
QVERIFY2(false, "Unexpected number of bytes received.");
diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
index 20bd4fa433..d2fb56ce02 100644
--- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp
@@ -467,9 +467,6 @@ typedef QPair<int, int> Position;
typedef QVector<QPair<int, int> > Selection;
typedef QVector<QVector<QString> > StringTable;
typedef QVector<QString> StringTableRow;
-Q_DECLARE_METATYPE(Position)
-Q_DECLARE_METATYPE(Selection)
-Q_DECLARE_METATYPE(StringTable)
static StringTableRow qStringTableRow(const QString &s1, const QString &s2, const QString &s3)
{
@@ -1922,8 +1919,6 @@ public:
void tst_QAbstractItemModel::testDataChanged()
{
- qRegisterMetaType<QVector<int> >();
-
CustomRoleModel model;
QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
index c8cbacf76e..c385a02b9c 100644
--- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp
@@ -281,8 +281,6 @@ void tst_QAbstractProxyModel::revert()
// public void setSourceModel(QAbstractItemModel* sourceModel)
void tst_QAbstractProxyModel::setSourceModel()
{
- qRegisterMetaType<QAbstractItemModel*>();
-
SubQAbstractProxyModel model;
QCOMPARE(model.property("sourceModel"), QVariant::fromValue<QAbstractItemModel*>(0));
diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
index 02a4824c4b..4578bcdab6 100644
--- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
+++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp
@@ -54,6 +54,8 @@ typedef QList<int> IntList;
typedef QPair<int, int> IntPair;
typedef QList<IntPair> IntPairList;
+Q_DECLARE_METATYPE(QList<QPersistentModelIndex>)
+
class tst_QSortFilterProxyModel : public QObject
{
Q_OBJECT
@@ -134,6 +136,7 @@ private slots:
void testMultipleProxiesWithSelection();
void mapSelectionFromSource();
+ void testResetInternalData();
void filteredColumns();
void headerDataChanged();
@@ -143,6 +146,8 @@ private slots:
void hierarchyFilterInvalidation();
void simpleFilterInvalidation();
+ void chainedProxyModelRoleNames();
+
protected:
void buildHierarchy(const QStringList &data, QAbstractItemModel *model);
void checkHierarchy(const QStringList &data, const QAbstractItemModel *model);
@@ -174,9 +179,7 @@ tst_QSortFilterProxyModel::tst_QSortFilterProxyModel()
void tst_QSortFilterProxyModel::initTestCase()
{
- qRegisterMetaType<IntList>("IntList");
- qRegisterMetaType<IntPair>("IntPair");
- qRegisterMetaType<IntPairList>("IntPairList");
+ qRegisterMetaType<QList<QPersistentModelIndex> >();
m_model = new QStandardItemModel(0, 1);
m_proxy = new QSortFilterProxyModel();
m_proxy->setSourceModel(m_model);
@@ -3242,7 +3245,142 @@ void tst_QSortFilterProxyModel::resetInvalidate()
QCOMPARE(ok, works);
}
-Q_DECLARE_METATYPE(QList<QPersistentModelIndex>)
+/**
+ * A proxy which changes the background color for items ending in 'y' or 'r'
+ */
+class CustomDataProxy : public QSortFilterProxyModel
+{
+ Q_OBJECT
+
+public:
+ CustomDataProxy(QObject *parent = 0)
+ : QSortFilterProxyModel(parent)
+ {
+ setDynamicSortFilter(true);
+ }
+
+ void setSourceModel(QAbstractItemModel *sourceModel)
+ {
+ // It would be possible to use only the modelReset signal of the source model to clear
+ // the data in *this, however, this requires that the slot is connected
+ // before QSortFilterProxyModel::setSourceModel is called, and even then depends
+ // on the order of invocation of slots being the same as the order of connection.
+ // ie, not reliable.
+// connect(sourceModel, SIGNAL(modelReset()), SLOT(resetInternalData()));
+ QSortFilterProxyModel::setSourceModel(sourceModel);
+ // Making the connect after the setSourceModel call clears the data too late.
+// connect(sourceModel, SIGNAL(modelReset()), SLOT(resetInternalData()));
+
+ // This could be done in data(), but the point is to need to cache something in the proxy
+ // which needs to be cleared on reset.
+ for (int i = 0; i < sourceModel->rowCount(); ++i)
+ {
+ if (sourceModel->index(i, 0).data().toString().endsWith(QLatin1Char('y')))
+ {
+ m_backgroundColours.insert(i, Qt::blue);
+ } else if (sourceModel->index(i, 0).data().toString().endsWith(QLatin1Char('r')))
+ {
+ m_backgroundColours.insert(i, Qt::red);
+ }
+ }
+ }
+
+ QVariant data(const QModelIndex &index, int role) const
+ {
+ if (role != Qt::BackgroundRole)
+ return QSortFilterProxyModel::data(index, role);
+ return m_backgroundColours.value(index.row());
+ }
+
+private slots:
+ void resetInternalData()
+ {
+ m_backgroundColours.clear();
+ }
+
+private:
+ QHash<int, QColor> m_backgroundColours;
+};
+
+class ModelObserver : public QObject
+{
+ Q_OBJECT
+public:
+ ModelObserver(QAbstractItemModel *model, QObject *parent = 0)
+ : QObject(parent), m_model(model)
+ {
+ connect(m_model, SIGNAL(modelAboutToBeReset()), SLOT(modelAboutToBeReset()));
+ connect(m_model, SIGNAL(modelReset()), SLOT(modelReset()));
+ }
+
+public slots:
+ void modelAboutToBeReset()
+ {
+ int reds = 0, blues = 0;
+ for (int i = 0; i < m_model->rowCount(); ++i)
+ {
+ QColor color = m_model->index(i, 0).data(Qt::BackgroundRole).value<QColor>();
+ if (color == Qt::blue)
+ ++blues;
+ if (color == Qt::red)
+ ++reds;
+ }
+ QCOMPARE(blues, 11);
+ QCOMPARE(reds, 4);
+ }
+
+ void modelReset()
+ {
+ int reds = 0, blues = 0;
+ for (int i = 0; i < m_model->rowCount(); ++i)
+ {
+ QColor color = m_model->index(i, 0).data(Qt::BackgroundRole).value<QColor>();
+ if (color == Qt::blue)
+ ++blues;
+ if (color == Qt::red)
+ ++reds;
+ }
+ QCOMPARE(reds, 0);
+ QCOMPARE(blues, 0);
+ }
+
+private:
+ QAbstractItemModel * const m_model;
+
+};
+
+void tst_QSortFilterProxyModel::testResetInternalData()
+{
+
+ QStringListModel model(QStringList() << "Monday"
+ << "Tuesday"
+ << "Wednesday"
+ << "Thursday"
+ << "Friday"
+ << "January"
+ << "February"
+ << "March"
+ << "April"
+ << "May"
+ << "Saturday"
+ << "June"
+ << "Sunday"
+ << "July"
+ << "August"
+ << "September"
+ << "October"
+ << "November"
+ << "December");
+
+ CustomDataProxy proxy;
+ proxy.setSourceModel(&model);
+
+ ModelObserver observer(&proxy);
+
+ // Cause the source model to reset.
+ model.setStringList(QStringList() << "Spam" << "Eggs");
+
+}
void tst_QSortFilterProxyModel::testParentLayoutChanged()
{
@@ -3276,8 +3414,6 @@ void tst_QSortFilterProxyModel::testParentLayoutChanged()
proxy2.setSourceModel(&proxy);
proxy2.setObjectName("proxy2");
- qRegisterMetaType<QList<QPersistentModelIndex> >();
-
QSignalSpy dataChangedSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
QVERIFY(dataChangedSpy.isValid());
@@ -3411,8 +3547,6 @@ private:
void tst_QSortFilterProxyModel::moveSourceRows()
{
- qRegisterMetaType<QList<QPersistentModelIndex> >();
-
DynamicTreeModel model;
{
@@ -3635,6 +3769,45 @@ void tst_QSortFilterProxyModel::simpleFilterInvalidation()
model.insertRow(0, new QStandardItem("extra"));
}
+class CustomRoleNameModel : public QAbstractListModel
+{
+ Q_OBJECT
+public:
+ CustomRoleNameModel(QObject *parent = 0) : QAbstractListModel(parent) {}
+
+ QVariant data(const QModelIndex &index, int role) const
+ {
+ Q_UNUSED(index);
+ Q_UNUSED(role);
+ return QVariant();
+ }
+
+ int rowCount(const QModelIndex &parent = QModelIndex()) const
+ {
+ Q_UNUSED(parent);
+ return 0;
+ }
+
+ QHash<int, QByteArray> roleNames() const
+ {
+ QHash<int, QByteArray> rn = QAbstractListModel::roleNames();
+ rn[Qt::UserRole + 1] = "custom";
+ return rn;
+ }
+};
+
+void tst_QSortFilterProxyModel::chainedProxyModelRoleNames()
+{
+ QSortFilterProxyModel proxy1;
+ QSortFilterProxyModel proxy2;
+ CustomRoleNameModel customModel;
+
+ proxy2.setSourceModel(&proxy1);
+
+ // changing the sourceModel of proxy1 must also update roleNames of proxy2
+ proxy1.setSourceModel(&customModel);
+ QVERIFY(proxy2.roleNames().value(Qt::UserRole + 1) == "custom");
+}
QTEST_MAIN(tst_QSortFilterProxyModel)
#include "tst_qsortfilterproxymodel.moc"
diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp
index a692b79fe9..6811551769 100644
--- a/tests/auto/corelib/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/json/tst_qtjson.cpp
@@ -1003,49 +1003,81 @@ void tst_QtJson::toVariantList()
void tst_QtJson::toJson()
{
- QJsonObject object;
- object.insert("\\Key\n", QString("Value"));
- object.insert("null", QJsonValue());
- QJsonArray array;
- array.append(true);
- array.append(999.);
- array.append(QLatin1String("string"));
- array.append(QJsonValue());
- array.append(QLatin1String("\\\a\n\r\b\tabcABC\""));
- object.insert("Array", array);
+ // Test QJsonDocument::Indented format
+ {
+ QJsonObject object;
+ object.insert("\\Key\n", QString("Value"));
+ object.insert("null", QJsonValue());
+ QJsonArray array;
+ array.append(true);
+ array.append(999.);
+ array.append(QLatin1String("string"));
+ array.append(QJsonValue());
+ array.append(QLatin1String("\\\a\n\r\b\tabcABC\""));
+ object.insert("Array", array);
+
+ QByteArray json = QJsonDocument(object).toJson();
+
+ QByteArray expected =
+ "{\n"
+ " \"Array\": [\n"
+ " true,\n"
+ " 999,\n"
+ " \"string\",\n"
+ " null,\n"
+ " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n"
+ " ],\n"
+ " \"\\\\Key\\n\": \"Value\",\n"
+ " \"null\": null\n"
+ "}\n";
+ QCOMPARE(json, expected);
- QByteArray json = QJsonDocument(object).toJson();
-
- QByteArray expected =
- "{\n"
- " \"Array\": [\n"
- " true,\n"
- " 999,\n"
- " \"string\",\n"
- " null,\n"
- " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n"
- " ],\n"
- " \"\\\\Key\\n\": \"Value\",\n"
- " \"null\": null\n"
- "}\n";
- QCOMPARE(json, expected);
+ QJsonDocument doc;
+ doc.setObject(object);
+ json = doc.toJson();
+ QCOMPARE(json, expected);
- QJsonDocument doc;
- doc.setObject(object);
- json = doc.toJson();
- QCOMPARE(json, expected);
+ doc.setArray(array);
+ json = doc.toJson();
+ expected =
+ "[\n"
+ " true,\n"
+ " 999,\n"
+ " \"string\",\n"
+ " null,\n"
+ " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n"
+ "]\n";
+ QCOMPARE(json, expected);
+ }
- doc.setArray(array);
- json = doc.toJson();
- expected =
- "[\n"
- " true,\n"
- " 999,\n"
- " \"string\",\n"
- " null,\n"
- " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n"
- "]\n";
- QCOMPARE(json, expected);
+ // Test QJsonDocument::Compact format
+ {
+ QJsonObject object;
+ object.insert("\\Key\n", QString("Value"));
+ object.insert("null", QJsonValue());
+ QJsonArray array;
+ array.append(true);
+ array.append(999.);
+ array.append(QLatin1String("string"));
+ array.append(QJsonValue());
+ array.append(QLatin1String("\\\a\n\r\b\tabcABC\""));
+ object.insert("Array", array);
+
+ QByteArray json = QJsonDocument(object).toJson(QJsonDocument::Compact);
+ QByteArray expected =
+ "{\"Array\": [true,999,\"string\",null,\"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"],\"\\\\Key\\n\": \"Value\",\"null\": null}";
+ QCOMPARE(json, expected);
+
+ QJsonDocument doc;
+ doc.setObject(object);
+ json = doc.toJson(QJsonDocument::Compact);
+ QCOMPARE(json, expected);
+
+ doc.setArray(array);
+ json = doc.toJson(QJsonDocument::Compact);
+ expected = "[true,999,\"string\",null,\"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"]";
+ QCOMPARE(json, expected);
+ }
}
void tst_QtJson::fromJson()
@@ -1135,6 +1167,30 @@ void tst_QtJson::fromJson()
QCOMPARE(object.value("6").type(), QJsonValue::Object);
QCOMPARE(object.value("6").toObject().size(), 0);
}
+ {
+ QByteArray compactJson = "{\"Array\": [true,999,\"string\",null,\"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"],\"\\\\Key\\n\": \"Value\",\"null\": null}";
+ QJsonDocument doc = QJsonDocument::fromJson(compactJson);
+ QVERIFY(!doc.isEmpty());
+ QCOMPARE(doc.isArray(), false);
+ QCOMPARE(doc.isObject(), true);
+ QJsonObject object = doc.object();
+ QCOMPARE(object.size(), 3);
+ QCOMPARE(object.value("\\Key\n").isString(), true);
+ QCOMPARE(object.value("\\Key\n").toString(), QString("Value"));
+ QCOMPARE(object.value("null").isNull(), true);
+ QCOMPARE(object.value("Array").isArray(), true);
+ QJsonArray array = object.value("Array").toArray();
+ QCOMPARE(array.size(), 5);
+ QCOMPARE(array.at(0).isBool(), true);
+ QCOMPARE(array.at(0).toBool(), true);
+ QCOMPARE(array.at(1).isDouble(), true);
+ QCOMPARE(array.at(1).toDouble(), 999.);
+ QCOMPARE(array.at(2).isString(), true);
+ QCOMPARE(array.at(2).toString(), QLatin1String("string"));
+ QCOMPARE(array.at(3).isNull(), true);
+ QCOMPARE(array.at(4).isString(), true);
+ QCOMPARE(array.at(4).toString(), QLatin1String("\\\a\n\r\b\tabcABC\""));
+ }
}
void tst_QtJson::fromJsonErrors()
diff --git a/tests/auto/corelib/kernel/kernel.pro b/tests/auto/corelib/kernel/kernel.pro
index 839d652be1..a283f5343d 100644
--- a/tests/auto/corelib/kernel/kernel.pro
+++ b/tests/auto/corelib/kernel/kernel.pro
@@ -21,6 +21,11 @@ SUBDIRS=\
qvariant \
qwineventnotifier
+!qtHaveModule(network): SUBDIRS -= \
+ qeventloop \
+ qobject \
+ qsocketnotifier
+
!contains(QT_CONFIG, private_tests): SUBDIRS -= \
qsocketnotifier \
qsharedmemory
@@ -28,3 +33,4 @@ SUBDIRS=\
# This test is only applicable on Windows
!win32*:SUBDIRS -= qwineventnotifier
+android|qnx: SUBDIRS -= qsharedmemory qsystemsemaphore
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
index 42bf9eeca3..10c00e2a67 100644
--- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
+++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
@@ -769,6 +769,18 @@ void tst_QCoreApplication::testQuitLock()
app.exec();
}
+static void createQObjectOnDestruction()
+{
+ // Make sure that we can create a QObject after the last QObject has been
+ // destroyed (especially after QCoreApplication has).
+ //
+ // Before the fixes, this would cause a dangling pointer dereference. If
+ // the problem comes back, it's possible that the following causes no
+ // effect.
+ QObject obj;
+ obj.thread()->setProperty("testing", 1);
+}
+Q_DESTRUCTOR_FUNCTION(createQObjectOnDestruction)
QTEST_APPLESS_MAIN(tst_QCoreApplication)
#include "tst_qcoreapplication.moc"
diff --git a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp
index 0d977317ca..24934ac138 100644
--- a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp
+++ b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -42,13 +43,17 @@
#include <QtTest/QtTest>
#include <qmath.h>
-static const qreal PI = 3.14159265358979323846264338327950288;
+static const double PI = 3.14159265358979323846264338327950288;
class tst_QMath : public QObject
{
Q_OBJECT
private slots:
void fastSinCos();
+ void degreesToRadians_data();
+ void degreesToRadians();
+ void radiansToDegrees_data();
+ void radiansToDegrees();
};
void tst_QMath::fastSinCos()
@@ -62,6 +67,76 @@ void tst_QMath::fastSinCos()
}
}
+void tst_QMath::degreesToRadians_data()
+{
+ QTest::addColumn<float>("degreesFloat");
+ QTest::addColumn<float>("radiansFloat");
+ QTest::addColumn<double>("degreesDouble");
+ QTest::addColumn<double>("radiansDouble");
+
+ QTest::newRow( "pi" ) << 180.0f << float(M_PI) << 180.0 << PI;
+ QTest::newRow( "doublepi" ) << 360.0f << float(2*M_PI) << 360.0 << 2*PI;
+ QTest::newRow( "halfpi" ) << 90.0f << float(M_PI_2) << 90.0 << PI/2;
+
+ QTest::newRow( "random" ) << 123.1234567f << 2.1489097058516724f << 123.123456789123456789 << 2.148909707407169856192285627;
+ QTest::newRow( "bigrandom" ) << 987654321.9876543f << 17237819.79023679f << 987654321987654321.987654321987654321 << 17237819790236794.0;
+
+ QTest::newRow( "zero" ) << 0.0f << 0.0f << 0.0 << 0.0;
+
+ QTest::newRow( "minuspi" ) << -180.0f << float(-M_PI) << 180.0 << PI;
+ QTest::newRow( "minusdoublepi" ) << -360.0f << float(-2*M_PI) << -360.0 << -2*PI;
+ QTest::newRow( "minushalfpi" ) << -90.0f << float(-M_PI_2) << -90.0 << -PI/2;
+
+ QTest::newRow( "minusrandom" ) << -123.1234567f << -2.1489097058516724f << -123.123456789123456789 << -2.148909707407169856192285627;
+ QTest::newRow( "minusbigrandom" ) << -987654321.9876543f << -17237819.79023679f << -987654321987654321.987654321987654321 << -17237819790236794.0;
+}
+
+void tst_QMath::degreesToRadians()
+{
+ QFETCH(float, degreesFloat);
+ QFETCH(float, radiansFloat);
+ QFETCH(double, degreesDouble);
+ QFETCH(double, radiansDouble);
+
+ QCOMPARE(qDegreesToRadians(degreesFloat), radiansFloat);
+ QCOMPARE(qDegreesToRadians(degreesDouble), radiansDouble);
+}
+
+void tst_QMath::radiansToDegrees_data()
+{
+ QTest::addColumn<float>("radiansFloat");
+ QTest::addColumn<float>("degreesFloat");
+ QTest::addColumn<double>("radiansDouble");
+ QTest::addColumn<double>("degreesDouble");
+
+ QTest::newRow( "pi" ) << float(M_PI) << 180.0f << PI << 180.0;
+ QTest::newRow( "doublepi" ) << float(2*M_PI) << 360.0f << 2*PI << 360.0;
+ QTest::newRow( "halfpi" ) << float(M_PI_2) << 90.0f<< PI/2 << 90.0;
+
+ QTest::newRow( "random" ) << 123.1234567f << 7054.454427971739f << 123.123456789123456789 << 7054.4544330781363896676339209079742431640625;
+ QTest::newRow( "bigrandom" ) << 987654321.9876543f << 56588424267.74745f << 987654321987654321.987654321987654321 << 56588424267747450880.0;
+
+ QTest::newRow( "zero" ) << 0.0f << 0.0f << 0.0 << 0.0;
+
+ QTest::newRow( "minuspi" ) << float(-M_PI) << -180.0f << -PI << -180.0;
+ QTest::newRow( "minusdoublepi" ) << float(-2*M_PI) << -360.0f << -2*PI << -360.0;
+ QTest::newRow( "minushalfpi" ) << float(-M_PI_2) << -90.0f << -PI/2 << -90.0;
+
+ QTest::newRow( "minusrandom" ) << -123.1234567f << -7054.454427971739f << -123.123456789123456789 << -7054.4544330781363896676339209079742431640625;
+ QTest::newRow( "minusbigrandom" ) << -987654321.9876543f << -56588424267.74745f << -987654321987654321.987654321987654321 << -56588424267747450880.0;
+}
+
+void tst_QMath::radiansToDegrees()
+{
+ QFETCH(float, radiansFloat);
+ QFETCH(float, degreesFloat);
+ QFETCH(double, radiansDouble);
+ QFETCH(double, degreesDouble);
+
+ QCOMPARE(qRadiansToDegrees(radiansFloat), degreesFloat);
+ QCOMPARE(qRadiansToDegrees(radiansDouble), degreesDouble);
+}
+
QTEST_APPLESS_MAIN(tst_QMath)
#include "tst_qmath.moc"
diff --git a/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro b/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro
index e253702d56..8340bc06e3 100644
--- a/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro
+++ b/tests/auto/corelib/kernel/qmetamethod/qmetamethod.pro
@@ -3,5 +3,5 @@ CONFIG += parallel_test
TARGET = tst_qmetamethod
QT = core testlib
SOURCES = tst_qmetamethod.cpp
-macx:CONFIG -= app_bundle
+mac:CONFIG -= app_bundle
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/qmetaobjectbuilder.pro b/tests/auto/corelib/kernel/qmetaobjectbuilder/qmetaobjectbuilder.pro
index 008b596b72..9e2d3519e6 100644
--- a/tests/auto/corelib/kernel/qmetaobjectbuilder/qmetaobjectbuilder.pro
+++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/qmetaobjectbuilder.pro
@@ -2,5 +2,5 @@ CONFIG += testcase parallel_test
TARGET = tst_qmetaobjectbuilder
QT = core-private gui-private testlib
SOURCES = tst_qmetaobjectbuilder.cpp
-macx:CONFIG -= app_bundle
+mac:CONFIG -= app_bundle
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 7f7486ef4b..77ea39da53 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -110,6 +110,7 @@ private slots:
void saveAndLoadCustom();
void metaObject();
void constexprMetaTypeIds();
+ void constRefs();
};
struct Foo { int i; };
@@ -169,7 +170,7 @@ protected:
const QByteArray name = QString("Bar%1_%2").arg(i).arg((size_t)QThread::currentThreadId()).toLatin1();
const char *nm = name.constData();
int tp = qRegisterMetaType<Bar>(nm);
-#ifdef Q_OS_LINUX
+#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
pthread_yield();
#endif
QMetaType info(tp);
@@ -1762,6 +1763,17 @@ void tst_QMetaType::constexprMetaTypeIds()
#endif
}
+void tst_QMetaType::constRefs()
+{
+ QCOMPARE(::qMetaTypeId<const int &>(), ::qMetaTypeId<int>());
+ QCOMPARE(::qMetaTypeId<const QString &>(), ::qMetaTypeId<QString>());
+ QCOMPARE(::qMetaTypeId<const CustomMovable &>(), ::qMetaTypeId<CustomMovable>());
+ QCOMPARE(::qMetaTypeId<const QList<CustomMovable> &>(), ::qMetaTypeId<QList<CustomMovable> >());
+#if defined(Q_COMPILER_CONSTEXPR)
+ Q_STATIC_ASSERT(::qMetaTypeId<const int &>() == ::qMetaTypeId<int>());
+#endif
+}
+
// Compile-time test, it should be possible to register function pointer types
class Undefined;
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 865264c43a..06fc89f657 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2013 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -68,7 +69,7 @@ class tst_QObject : public QObject
private slots:
void initTestCase();
void disconnect();
- void connectByName();
+ void connectSlotsByName();
void connectSignalsToSignalsWithDefaultArguments();
void receivers();
void normalize();
@@ -140,10 +141,22 @@ private slots:
void returnValue2_data();
void returnValue2();
void connectVirtualSlots();
+ void connectPrivateSlots();
void connectFunctorArgDifference();
+ void connectFunctorOverloads();
void disconnectDoesNotLeakFunctor();
};
+struct QObjectCreatedOnShutdown
+{
+ QObjectCreatedOnShutdown() {}
+ ~QObjectCreatedOnShutdown()
+ {
+ QObject();
+ }
+};
+static QObjectCreatedOnShutdown s_qobjectCreatedOnShutdown;
+
class SenderObject : public QObject
{
Q_OBJECT
@@ -368,6 +381,7 @@ public:
void emitSignalWithParams(int i) { emit signalWithParams(i); }
void emitSignalWithParams(int i, QString string) { emit signalWithParams(i, string); }
void emitSignalManyParams(int i1, int i2, int i3, QString string, bool onoff) { emit signalManyParams(i1, i2, i3, string, onoff); }
+ void emitSignalManyParams(int i1, int i2, int i3, QString string, bool onoff, bool dummy) { emit signalManyParams(i1, i2, i3, string, onoff, dummy); }
void emitSignalManyParams2(int i1, int i2, int i3, QString string, bool onoff) { emit signalManyParams2(i1, i2, i3, string, onoff); }
void emitSignalLoopBack() { emit signalLoopBack(); }
@@ -386,158 +400,89 @@ class AutoConnectReceiver : public QObject
Q_OBJECT
public:
+ QList<int> called_slots;
+
AutoConnectReceiver()
{
- reset();
-
connect(this, SIGNAL(on_Sender_signalLoopBack()), this, SLOT(slotLoopBack()));
}
- void reset() {
- called_slot10 = 0;
- called_slot9 = 0;
- called_slot8 = 0;
- called_slot7 = 0;
- called_slot6 = 0;
- called_slot5 = 0;
- called_slot4 = 0;
- called_slot3 = 0;
- called_slot2 = 0;
- called_slot1 = 0;
- }
-
- int called_slot1;
- int called_slot2;
- int called_slot3;
- int called_slot4;
- int called_slot5;
- int called_slot6;
- int called_slot7;
- int called_slot8;
- int called_slot9;
- int called_slot10;
-
- bool called(int slot) {
- switch (slot) {
- case 1: return called_slot1;
- case 2: return called_slot2;
- case 3: return called_slot3;
- case 4: return called_slot4;
- case 5: return called_slot5;
- case 6: return called_slot6;
- case 7: return called_slot7;
- case 8: return called_slot8;
- case 9: return called_slot9;
- case 10: return called_slot10;
- default: return false;
- }
- }
+ void emitSignalNoParams() { emit signalNoParams(); }
+ void emit_signal_with_underscore() { emit signal_with_underscore(); }
public slots:
- void on_Sender_signalNoParams() { ++called_slot1; }
- void on_Sender_signalWithParams(int i = 0) { ++called_slot2; Q_UNUSED(i); }
- void on_Sender_signalWithParams(int i, QString string) { ++called_slot3; Q_UNUSED(i);Q_UNUSED(string); }
- void on_Sender_signalManyParams() { ++called_slot4; }
- void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff) { ++called_slot5; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); }
+ void on_Sender_signalNoParams() { called_slots << 1; }
+ void on_Sender_signalWithParams(int i = 0) { called_slots << 2; Q_UNUSED(i); }
+ void on_Sender_signalWithParams(int i, QString string) { called_slots << 3; Q_UNUSED(i);Q_UNUSED(string); }
+ void on_Sender_signalManyParams() { called_slots << 4; }
+ void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff)
+ { called_slots << 5; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); }
void on_Sender_signalManyParams(int i1, int i2, int i3, QString string, bool onoff, bool dummy)
- { ++called_slot6; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); Q_UNUSED(dummy);}
+ { called_slots << 6; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); Q_UNUSED(dummy);}
void on_Sender_signalManyParams2(int i1, int i2, int i3, QString string, bool onoff)
- { ++called_slot7; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); }
- void slotLoopBack() { ++called_slot8; }
+ { called_slots << 7; Q_UNUSED(i1);Q_UNUSED(i2);Q_UNUSED(i3);Q_UNUSED(string);Q_UNUSED(onoff); }
+ void slotLoopBack() { called_slots << 8; }
+ void on_Receiver_signalNoParams() { called_slots << 9; }
+ void on_Receiver_signal_with_underscore() { called_slots << 10; }
protected slots:
- void o() { ++called_slot9; }
- void on() { ++called_slot10; }
+ void o() { called_slots << -1; }
+ void on() { called_slots << -1; }
+ void on_() { called_slots << -1; }
+ void on_something() { called_slots << -1; }
+ void on_child_signal() { called_slots << -1; }
signals:
void on_Sender_signalLoopBack();
+ void signalNoParams();
+ void signal_with_underscore();
};
-void tst_QObject::connectByName()
+void tst_QObject::connectSlotsByName()
{
AutoConnectReceiver receiver;
+ receiver.setObjectName("Receiver");
AutoConnectSender sender(&receiver);
sender.setObjectName("Sender");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: No matching signal for on_child_signal()");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::connectSlotsByName: Connecting slot on_Sender_signalManyParams() with the first of the following compatible signals: (\"signalManyParams(int,int,int,QString,bool)\", \"signalManyParams(int,int,int,QString,bool,bool)\") ");
QMetaObject::connectSlotsByName(&receiver);
+ receiver.called_slots.clear();
sender.emitSignalNoParams();
- QCOMPARE(receiver.called(1), true);
- QCOMPARE(receiver.called(2), false);
- QCOMPARE(receiver.called(3), false);
- QCOMPARE(receiver.called(4), false);
- QCOMPARE(receiver.called(5), false);
- QCOMPARE(receiver.called(6), false);
- QCOMPARE(receiver.called(7), false);
- QCOMPARE(receiver.called(8), false);
- QCOMPARE(receiver.called(9), false);
- QCOMPARE(receiver.called(10), false);
- receiver.reset();
+ QCOMPARE(receiver.called_slots, QList<int>() << 1);
+ receiver.called_slots.clear();
sender.emitSignalWithParams(0);
- QCOMPARE(receiver.called(1), false);
- QCOMPARE(receiver.called(2), true);
- QCOMPARE(receiver.called(3), false);
- QCOMPARE(receiver.called(4), false);
- QCOMPARE(receiver.called(5), false);
- QCOMPARE(receiver.called(6), false);
- QCOMPARE(receiver.called(7), false);
- QCOMPARE(receiver.called(8), false);
- QCOMPARE(receiver.called(9), false);
- QCOMPARE(receiver.called(10), false);
- receiver.reset();
+ QCOMPARE(receiver.called_slots, QList<int>() << 2);
+ receiver.called_slots.clear();
sender.emitSignalWithParams(0, "string");
- QCOMPARE(receiver.called(1), false);
- QCOMPARE(receiver.called(2), false);
- QCOMPARE(receiver.called(3), true);
- QCOMPARE(receiver.called(4), false);
- QCOMPARE(receiver.called(5), false);
- QCOMPARE(receiver.called(6), false);
- QCOMPARE(receiver.called(7), false);
- QCOMPARE(receiver.called(8), false);
- QCOMPARE(receiver.called(9), false);
- QCOMPARE(receiver.called(10), false);
- receiver.reset();
+ QCOMPARE(receiver.called_slots, QList<int>() << 3);
+ receiver.called_slots.clear();
sender.emitSignalManyParams(1, 2, 3, "string", true);
- QCOMPARE(receiver.called(1), false);
- QCOMPARE(receiver.called(2), false);
- QCOMPARE(receiver.called(3), false);
- QCOMPARE(receiver.called(4), true);
- QCOMPARE(receiver.called(5), true);
- QCOMPARE(receiver.called(6), false);
- QCOMPARE(receiver.called(7), false);
- QCOMPARE(receiver.called(8), false);
- QCOMPARE(receiver.called(9), false);
- QCOMPARE(receiver.called(10), false);
- receiver.reset();
+ sender.emitSignalManyParams(1, 2, 3, "string", true, false);
+ // the slot '4' (signalManyParams()) will get connected
+ // to either of the two signalManyParams(...) overloads
+ QCOMPARE(receiver.called_slots, QList<int>() << 4 << 5 << 6);
+ receiver.called_slots.clear();
sender.emitSignalManyParams2(1, 2, 3, "string", true);
- QCOMPARE(receiver.called(1), false);
- QCOMPARE(receiver.called(2), false);
- QCOMPARE(receiver.called(3), false);
- QCOMPARE(receiver.called(4), false);
- QCOMPARE(receiver.called(5), false);
- QCOMPARE(receiver.called(6), false);
- QCOMPARE(receiver.called(7), true);
- QCOMPARE(receiver.called(8), false);
- QCOMPARE(receiver.called(9), false);
- QCOMPARE(receiver.called(10), false);
- receiver.reset();
+ QCOMPARE(receiver.called_slots, QList<int>() << 7);
+ receiver.called_slots.clear();
sender.emitSignalLoopBack();
- QCOMPARE(receiver.called(1), false);
- QCOMPARE(receiver.called(2), false);
- QCOMPARE(receiver.called(3), false);
- QCOMPARE(receiver.called(4), false);
- QCOMPARE(receiver.called(5), false);
- QCOMPARE(receiver.called(6), false);
- QCOMPARE(receiver.called(7), false);
- QCOMPARE(receiver.called(8), true);
- QCOMPARE(receiver.called(9), false);
- QCOMPARE(receiver.called(10), false);
- receiver.reset();
+ QCOMPARE(receiver.called_slots, QList<int>() << 8);
+
+ receiver.called_slots.clear();
+ receiver.emitSignalNoParams();
+ QCOMPARE(receiver.called_slots, QList<int>() << 9);
+
+ receiver.called_slots.clear();
+ receiver.emit_signal_with_underscore();
+ QCOMPARE(receiver.called_slots, QList<int>() << 10);
}
void tst_QObject::qobject_castTemplate()
@@ -1436,9 +1381,11 @@ public:
public slots:
void slot1(CustomType ct);
+ void slot2(const QList<CustomType> &ct);
signals:
void signal1(CustomType ct);
+ void signal2(const QList<CustomType> &ct);
public:
CustomType received;
@@ -1447,6 +1394,8 @@ public:
void QCustomTypeChecker::slot1(CustomType ct)
{ received = ct; }
+void QCustomTypeChecker::slot2(const QList< CustomType >& ct)
+{ received = ct[0]; }
void tst_QObject::customTypes()
{
@@ -4657,6 +4606,21 @@ void tst_QObject::customTypesPointer()
QCOMPARE(qRegisterMetaType<CustomType>("CustomType"), idx);
QCOMPARE(QMetaType::type("CustomType"), idx);
QVERIFY(QMetaType::isRegistered(idx));
+
+ // Test auto registered type (QList<CustomType>)
+ QList<CustomType> list;
+ QCOMPARE(instanceCount, 4);
+ list.append(t1);
+ QCOMPARE(instanceCount, 5);
+ QVERIFY(connect(&checker, &QCustomTypeChecker::signal2,
+ &checker, &QCustomTypeChecker::slot2, Qt::QueuedConnection));
+ emit checker.signal2(list);
+ QCOMPARE(instanceCount, 5); //because the list is implicitly shared.
+ list.clear();
+ QCOMPARE(instanceCount, 5);
+ QCoreApplication::processEvents();
+ QCOMPARE(checker.received.value(), t1.value());
+ QCOMPARE(instanceCount, 4);
}
QCOMPARE(instanceCount, 3);
}
@@ -5535,6 +5499,72 @@ void tst_QObject::connectVirtualSlots()
*/
}
+#ifndef QT_BUILD_INTERNAL
+void tst_QObject::connectPrivateSlots()
+{QSKIP("Needs QT_BUILD_INTERNAL");}
+#else
+class ConnectToPrivateSlotPrivate;
+
+class ConnectToPrivateSlot :public QObject {
+ Q_OBJECT
+public:
+ ConnectToPrivateSlot();
+ void test(SenderObject *obj1) ;
+ Q_DECLARE_PRIVATE(ConnectToPrivateSlot)
+};
+
+class ConnectToPrivateSlotPrivate : public QObjectPrivate {
+public:
+ Q_DECLARE_PUBLIC(ConnectToPrivateSlot)
+ int receivedCount;
+ QVariant receivedValue;
+
+ void thisIsAPrivateSlot() {
+ receivedCount++;
+ };
+
+ void thisIsAPrivateSlotWithArg(const QVariant &v) {
+ receivedCount++;
+ receivedValue = v;
+ };
+};
+
+ConnectToPrivateSlot::ConnectToPrivateSlot(): QObject(*new ConnectToPrivateSlotPrivate) {}
+
+void ConnectToPrivateSlot::test(SenderObject* obj1) {
+ Q_D(ConnectToPrivateSlot);
+ d->receivedCount = 0;
+ QVERIFY(QObjectPrivate::connect(obj1, &SenderObject::signal1, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot));
+ QVERIFY(QObjectPrivate::connect(obj1, &SenderObject::signal7, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlotWithArg));
+ QCOMPARE(d->receivedCount, 0);
+ obj1->signal1();
+ QCOMPARE(d->receivedCount, 1);
+ QCOMPARE(d->receivedValue, QVariant());
+ obj1->signal7(666, QLatin1Literal("_"));
+ QCOMPARE(d->receivedCount, 2);
+ QCOMPARE(d->receivedValue, QVariant(666));
+ QVERIFY(QObjectPrivate::connect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot, Qt::UniqueConnection));
+ QVERIFY(!QObjectPrivate::connect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot, Qt::UniqueConnection));
+ obj1->signal2();
+ QCOMPARE(d->receivedCount, 3);
+ QVERIFY(QObjectPrivate::disconnect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot));
+ obj1->signal2();
+ QCOMPARE(d->receivedCount, 3);
+ QVERIFY(!QObjectPrivate::disconnect(obj1, &SenderObject::signal2, d, &ConnectToPrivateSlotPrivate::thisIsAPrivateSlot));
+}
+
+void tst_QObject::connectPrivateSlots()
+{
+ SenderObject sender;
+ {
+ ConnectToPrivateSlot o;
+ o.test(&sender);
+ }
+ sender.signal7(777, QLatin1String("check that deleting the object properly disconnected"));
+ sender.signal1();
+}
+#endif
+
struct SlotFunctor
{
void operator()() {}
@@ -5570,6 +5600,131 @@ void tst_QObject::connectFunctorArgDifference()
QVERIFY(true);
}
+struct ComplexFunctor {
+ ComplexFunctor(int &overload, QList<QVariant> &result) : overload(overload), result(result) {}
+ void operator()(int a, int b) {
+ overload = 1;
+ result << a << b;
+ }
+ void operator()(double a, double b) {
+ overload = 2;
+ result << a << b;
+ }
+ void operator()(const QString &s) {
+ overload = 3;
+ result << s;
+ }
+ void operator()(const QString &) const {
+ Q_ASSERT(!"Should not be called because the non-const one should");
+ overload = -1;
+ }
+ template<typename T1, typename T2, typename T3, typename T4>
+ void operator()(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) {
+ overload = 4;
+ result << QVariant::fromValue(t1) << QVariant::fromValue(t2) << QVariant::fromValue(t3) << QVariant::fromValue(t4);
+ }
+ int &overload;
+ QList<QVariant> &result;
+protected:
+ void operator()() const {
+ Q_ASSERT(!"Should not be called because it is protected");
+ overload = -1;
+ }
+};
+
+struct ComplexFunctorDeriv : ComplexFunctor {
+ ComplexFunctorDeriv(int &overload, QList<QVariant> &result) : ComplexFunctor(overload, result) {}
+
+ void operator()() const {
+ overload = 10;
+ }
+ void operator()(int a, int b) {
+ overload = 11;
+ result << a << b;
+ }
+ using ComplexFunctor::operator();
+private:
+ void operator()(int) {
+ Q_ASSERT(!"Should not be called because it is private");
+ overload = -1;
+ }
+};
+
+class FunctorArgDifferenceObject : public QObject
+{
+ Q_OBJECT
+signals:
+ void signal_ii(int,int);
+ void signal_iiS(int,int, const QString &);
+ void signal_dd(double,double);
+ void signal_ddS(double,double, const QString &);
+ void signal_S(const QString &);
+ void signal_SSSS(const QString &, const QString &, const QString &, const QString &);
+ void signal_iiSS(int, int, const QString &, const QString &);
+ void signal_VV(const QVariant &, const QVariant &);
+};
+
+template<typename Functor, typename Signal>
+void connectFunctorOverload_impl(Signal signal, int expOverload, QList<QVariant> expResult)
+{
+ FunctorArgDifferenceObject obj;
+ int overload;
+ QList<QVariant> result;
+ QVERIFY(QObject::connect(&obj, signal, Functor(overload, result)));
+
+ obj.signal_ii(1,2);
+ obj.signal_iiS(3,4,"5");
+ obj.signal_dd(6.6,7.7);
+ obj.signal_ddS(8.8,9.9,"10");
+ obj.signal_S("11");
+ obj.signal_SSSS("12", "13", "14", "15");
+ obj.signal_iiSS(16, 17, "18", "19");
+ obj.signal_VV(20,21);
+
+ QCOMPARE(overload, expOverload);
+ QCOMPARE(result, expResult);
+}
+
+void tst_QObject::connectFunctorOverloads()
+{
+#if defined (Q_COMPILER_DECLTYPE) && defined (Q_COMPILER_VARIADIC_TEMPLATES)
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_ii, 1,
+ (QList<QVariant>() << 1 << 2));
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_iiS, 1,
+ (QList<QVariant>() << 3 << 4));
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_dd, 2,
+ (QList<QVariant>() << 6.6 << 7.7));
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_ddS, 2,
+ (QList<QVariant>() << 8.8 << 9.9));
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_S, 3,
+ (QList<QVariant>() << QString("11")));
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_SSSS, 4,
+ (QList<QVariant>() << QString("12") << QString("13") << QString("14") << QString("15")));
+ connectFunctorOverload_impl<ComplexFunctor>(&FunctorArgDifferenceObject::signal_iiSS, 4,
+ (QList<QVariant>() << 16 << 17 << QString("18") << QString("19")));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_ii, 11,
+ (QList<QVariant>() << 1 << 2));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_iiS, 11,
+ (QList<QVariant>() << 3 << 4));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_dd, 2,
+ (QList<QVariant>() << 6.6 << 7.7));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_ddS, 2,
+ (QList<QVariant>() << 8.8 << 9.9));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_S, 3,
+ (QList<QVariant>() << QString("11")));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_SSSS, 4,
+ (QList<QVariant>() << QString("12") << QString("13") << QString("14") << QString("15")));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_iiSS, 4,
+ (QList<QVariant>() << 16 << 17 << QString("18") << QString("19")));
+ connectFunctorOverload_impl<ComplexFunctorDeriv>(&FunctorArgDifferenceObject::signal_VV, 10,
+ (QList<QVariant>()));
+
+
+#else
+ QSKIP("Does not compile without C++11 variadic template");
+#endif
+}
+
static int countedStructObjectsCount = 0;
struct CountedStruct
{
diff --git a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
index 7c6549364f..609b4b7dce 100644
--- a/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
+++ b/tests/auto/corelib/kernel/qpointer/tst_qpointer.cpp
@@ -65,6 +65,7 @@ private slots:
void threadSafety();
void qvariantCast();
+ void constPointer();
};
void tst_QPointer::constructors()
@@ -384,6 +385,12 @@ void tst_QPointer::qvariantCast()
// QPointer<int> sop = qPointerFromVariant<int>(v);
}
+void tst_QPointer::constPointer()
+{
+ // Compile-time test that QPointer<const T> works.
+ QPointer<const QFile> fp = new QFile;
+ delete fp.data();
+}
QTEST_MAIN(tst_QPointer)
diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
index 3583c1cab3..ce5e83288f 100644
--- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
+++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
@@ -748,6 +748,8 @@ void tst_QSharedMemory::simpleProcessProducerConsumer()
{
QFETCH(int, processes);
+ QSKIP("This test is unstable: QTBUG-25655");
+
rememberKey("market");
QProcess producer;
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 79d8b3dfe4..a90bfadd73 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -442,6 +442,8 @@ void tst_QMimeDatabase::mimeTypeForFileWithContent()
txtTempFile.close();
mime = db.mimeTypeForFile(txtTempFileName);
QCOMPARE(mime.name(), QString::fromLatin1("text/plain"));
+ mime = db.mimeTypeForFile(txtTempFileName, QMimeDatabase::MatchContent);
+ QCOMPARE(mime.name(), QString::fromLatin1("application/smil"));
}
// Test what happens with an incorrect path
@@ -714,6 +716,8 @@ void tst_QMimeDatabase::findByData()
QFileInfo info(filePath);
QString mimeForInfo = database.mimeTypeForFile(info, QMimeDatabase::MatchContent).name();
QCOMPARE(mimeForInfo, resultMimeTypeName);
+ QString mimeForFile = database.mimeTypeForFile(filePath, QMimeDatabase::MatchContent).name();
+ QCOMPARE(mimeForFile, resultMimeTypeName);
}
void tst_QMimeDatabase::findByFile_data()
diff --git a/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c b/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
index 324dce5b0c..a9abe471b1 100644
--- a/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
+++ b/tests/auto/corelib/plugin/qpluginloader/lib/mylib.c
@@ -53,6 +53,12 @@
# define BORLAND_STDCALL
#endif
+static int pluginVariable = 0xc0ffee;
+LIB_EXPORT int *pointerAddress()
+{
+ return &pluginVariable;
+}
+
LIB_EXPORT int BORLAND_STDCALL version()
{
return 1;
diff --git a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro
index 5aa7b4805b..0cba19887e 100644
--- a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro
+++ b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro
@@ -4,7 +4,7 @@ CONFIG += ordered
SUBDIRS = lib \
theplugin \
tst
-!win32: !macx-*: SUBDIRS += almostplugin
+!win32: !mac: SUBDIRS += almostplugin
TARGET = tst_qpluginloader
# no special install rule for subdir
diff --git a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
index 6abb9b6c20..b26b24f454 100644
--- a/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/theplugin/theplugin.cpp
@@ -46,3 +46,9 @@ QString ThePlugin::pluginName() const
{
return QLatin1String("Plugin ok");
}
+
+static int pluginVariable = 0xc0ffee;
+extern "C" Q_DECL_EXPORT int *pointerAddress()
+{
+ return &pluginVariable;
+}
diff --git a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
index f0be8cf6f1..cef4f53101 100644
--- a/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
+++ b/tests/auto/corelib/plugin/qpluginloader/tst_qpluginloader.cpp
@@ -99,13 +99,19 @@
static QString sys_qualifiedLibraryName(const QString &fileName)
{
- return QFINDTESTDATA(QString("bin/%1%2%3").arg(PREFIX).arg(fileName).arg(SUFFIX));
+ QString libname = QFINDTESTDATA(QString("bin/%1%2%3").arg(PREFIX).arg(fileName).arg(SUFFIX));
+ QFileInfo fi(libname);
+ if (fi.exists())
+ return fi.canonicalFilePath();
+ return libname;
}
QT_FORWARD_DECLARE_CLASS(QPluginLoader)
class tst_QPluginLoader : public QObject
{
Q_OBJECT
+public slots:
+ void cleanup();
private slots:
void errorString();
void loadHints();
@@ -117,8 +123,25 @@ private slots:
#endif
void relativePath();
void reloadPlugin();
+ void preloadedPlugin_data();
+ void preloadedPlugin();
};
+void tst_QPluginLoader::cleanup()
+{
+ // check if the library/plugin was leaked
+ // we can't use QPluginLoader::isLoaded here because on some platforms the plugin is always loaded by QPluginLoader.
+ // Also, if this test fails once, it will keep on failing because we can't force the unload,
+ // so we report it only once.
+ static bool failedAlready = false;
+ if (!failedAlready) {
+ QLibrary lib(sys_qualifiedLibraryName("theplugin"));
+ failedAlready = true;
+ QVERIFY2(!lib.isLoaded(), "Plugin was leaked - will not check again");
+ failedAlready = false;
+ }
+}
+
void tst_QPluginLoader::errorString()
{
#if defined(Q_OS_WINCE)
@@ -334,6 +357,50 @@ void tst_QPluginLoader::reloadPlugin()
PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader.instance());
QVERIFY(instance2);
QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));
+
+ QVERIFY(loader.unload());
+}
+
+void tst_QPluginLoader::preloadedPlugin_data()
+{
+ QTest::addColumn<bool>("doLoad");
+ QTest::addColumn<QString>("libname");
+ QTest::newRow("create-plugin") << false << sys_qualifiedLibraryName("theplugin");
+ QTest::newRow("load-plugin") << true << sys_qualifiedLibraryName("theplugin");
+ QTest::newRow("create-non-plugin") << false << sys_qualifiedLibraryName("tst_qpluginloaderlib");
+ QTest::newRow("load-non-plugin") << true << sys_qualifiedLibraryName("tst_qpluginloaderlib");
+}
+
+void tst_QPluginLoader::preloadedPlugin()
+{
+ // check that using QPluginLoader does not interfere with QLibrary
+ QFETCH(QString, libname);
+ QLibrary lib(libname);
+ QVERIFY(lib.load());
+
+ typedef int *(*pf_t)();
+ pf_t pf = (pf_t)lib.resolve("pointerAddress");
+ QVERIFY(pf);
+
+ int *pluginVariable = pf();
+ QVERIFY(pluginVariable);
+ QCOMPARE(*pluginVariable, 0xc0ffee);
+
+ {
+ // load the plugin
+ QPluginLoader loader(libname);
+ QFETCH(bool, doLoad);
+ if (doLoad && loader.load()) {
+ // unload() returns false because QLibrary has it loaded
+ QVERIFY(!loader.unload());
+ }
+ }
+
+ QVERIFY(lib.isLoaded());
+
+ // if the library was unloaded behind our backs, the following will crash:
+ QCOMPARE(*pluginVariable, 0xc0ffee);
+ QVERIFY(lib.unload());
}
QTEST_MAIN(tst_QPluginLoader)
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
index 651fa3b1db..21e067bc73 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
@@ -47,7 +47,7 @@ int main(int argc, char **argv)
{
Q_UNUSED(argc)
Q_UNUSED(argv)
-
+
// First, break QUuid.
qrand();
diff --git a/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp b/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp
index 9d7bbd4f5c..ae32731cbc 100644
--- a/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp
+++ b/tests/auto/corelib/statemachine/qstate/tst_qstate.cpp
@@ -77,7 +77,7 @@ public:
public slots:
void slot() { called = true; }
-
+
};
void tst_QState::assignProperty()
@@ -89,7 +89,7 @@ void tst_QState::assignProperty()
QState *s1 = new QState(&machine);
s1->assignProperty(object, "fooBar", 20);
-
+
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
@@ -107,7 +107,7 @@ void tst_QState::assignPropertyTwice()
QState *s1 = new QState(&machine);
s1->assignProperty(object, "fooBar", 20);
s1->assignProperty(object, "fooBar", 30);
-
+
machine.setInitialState(s1);
machine.start();
QCoreApplication::processEvents();
@@ -118,7 +118,7 @@ void tst_QState::assignPropertyTwice()
class EventTestTransition: public QAbstractTransition
{
public:
- EventTestTransition(QEvent::Type type, QState *targetState)
+ EventTestTransition(QEvent::Type type, QState *targetState)
: QAbstractTransition(), m_type(type)
{
setTargetState(targetState);
@@ -134,18 +134,18 @@ protected:
private:
QEvent::Type m_type;
-
+
};
-void tst_QState::historyInitialState()
+void tst_QState::historyInitialState()
{
QStateMachine machine;
QState *s1 = new QState(&machine);
-
+
QState *s2 = new QState(&machine);
QHistoryState *h1 = new QHistoryState(s2);
-
+
s2->setInitialState(h1);
QState *s3 = new QState(s2);
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
index c9a41b29f8..c86befdf1b 100644
--- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
+++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
@@ -243,13 +243,13 @@ void tst_QFuture::resultStore()
store.addResult(2, &int2); // add result at index 2
QCOMPARE(store.contains(2), false); // but 1 is missing, so this 2 won't be reported yet.
- store.addResult(1, &int1);
+ store.addResult(1, &int1);
QCOMPARE(store.contains(1), true);
QCOMPARE(store.contains(2), true); // 2 should be visible now.
- store.addResult(4, &int0);
- store.addResult(5, &int0);
- store.addResult(7, &int0);
+ store.addResult(4, &int0);
+ store.addResult(5, &int0);
+ store.addResult(7, &int0);
QCOMPARE(store.contains(4), false);
QCOMPARE(store.contains(5), false);
QCOMPARE(store.contains(7), false);
@@ -273,9 +273,9 @@ void tst_QFuture::resultStore()
store.addResult(0, &int0);
QCOMPARE(store.contains(0), true);
-
+
store.addResult(2, &int0);
- QCOMPARE(store.contains(2), false);
+ QCOMPARE(store.contains(2), false);
store.addCanceledResult(1); // report no result at 1
@@ -289,7 +289,7 @@ void tst_QFuture::resultStore()
store.addResult(6, &int0);
store.addResult(7, &int0);
QCOMPARE(store.contains(3), false);
-
+
store.addCanceledResult(4);
store.addCanceledResult(5);
@@ -311,10 +311,10 @@ void tst_QFuture::resultStore()
store.addResult(0, &int0);
QCOMPARE(store.count(), 1); // result 0 becomes available
QCOMPARE(store.contains(0), true);
-
+
store.addResult(2, &int0);
QCOMPARE(store.count(), 1);
- QCOMPARE(store.contains(2), false);
+ QCOMPARE(store.contains(2), false);
store.addCanceledResult(1);
QCOMPARE(store.count(), 2); // result 2 is renamed to 1 and becomes available
@@ -332,7 +332,7 @@ void tst_QFuture::resultStore()
store.addResult(7, &int0);
QCOMPARE(store.count(), 3);
QCOMPARE(store.contains(3), false);
-
+
store.addCanceledResult(4);
store.addCanceledResult(5);
QCOMPARE(store.count(), 5); // 6 and 7 is renamed to 3 and 4 and becomes available
@@ -347,13 +347,13 @@ void tst_QFuture::resultStore()
QCOMPARE(store.contains(6), false);
QCOMPARE(store.contains(7), false);
}
-
+
{
// test resultCount in non-filtered mode. It should always be possible
// to iterate through the results 0 to resultCount.
QtPrivate::ResultStore<int> store;
store.addResult(0, &int0);
-
+
QCOMPARE(store.count(), 1);
store.addResult(2, &int0);
@@ -440,7 +440,7 @@ void tst_QFuture::resultStore()
store.addCanceledResults(0, 3);
QCOMPARE(store.count(), 2); // results at 3 and 4 become available at index 0, 1
- store.addResult(5, &int0);
+ store.addResult(5, &int0);
QCOMPARE(store.count(), 3);// result 5 becomes available at index 2
}
@@ -1112,9 +1112,9 @@ void tst_QFuture::iterators()
for (int i = 0; i < resultCount; ++i) {
e.reportResult(i);
}
-
+
e.reportFinished();
-
+
{
QFutureIterator<int> it(f);
QFutureIterator<int> it2(it);
@@ -1122,7 +1122,7 @@ void tst_QFuture::iterators()
{
QFutureIterator<int> it(f);
-
+
for (int i = 0; i < resultCount - 1; ++i) {
QVERIFY(it.hasNext());
QCOMPARE(it.peekNext(), i);
diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
index 467dd4b348..b2b0eace34 100644
--- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
+++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp
@@ -797,7 +797,7 @@ public:
ResultReadyTester(QFutureWatcher<int> *watcher)
:m_watcher(watcher), filter(false), ok(true), count(0)
{
-
+
}
public slots:
void resultReadyAt(int index)
@@ -834,7 +834,7 @@ void tst_QFutureWatcher::incrementalMapResults()
connect(&watcher, SIGNAL(resultReadyAt(int)), &resultReadyTester, SLOT(resultReadyAt(int)));
const int count = 10000;
- QList<int> ints;
+ QList<int> ints;
for (int i = 0; i < count; ++i)
ints << i;
@@ -846,7 +846,7 @@ void tst_QFutureWatcher::incrementalMapResults()
QCOMPARE(resultReadyTester.count, count);
QVERIFY(resultReadyTester.ok);
QVERIFY(watcher.isFinished());
- future.waitForFinished();
+ future.waitForFinished();
}
bool filterer(int i)
@@ -873,7 +873,7 @@ void tst_QFutureWatcher::incrementalFilterResults()
connect(&watcher, SIGNAL(resultReadyAt(int)), &resultReadyTester, SLOT(resultReadyAt(int)));
const int count = 10000;
- QList<int> ints;
+ QList<int> ints;
for (int i = 0; i < count; ++i)
ints << i;
@@ -885,12 +885,12 @@ void tst_QFutureWatcher::incrementalFilterResults()
QCOMPARE(resultReadyTester.count, count / 2);
QVERIFY(resultReadyTester.ok);
QVERIFY(watcher.isFinished());
- future.waitForFinished();
+ future.waitForFinished();
}
void tst_QFutureWatcher::qfutureSynchronizer()
{
- int taskCount = 1000;
+ int taskCount = 1000;
QTime t;
t.start();
diff --git a/tests/auto/corelib/thread/qthread/tst_qthread.cpp b/tests/auto/corelib/thread/qthread/tst_qthread.cpp
index e6d824be96..7fbb5e9f5f 100644
--- a/tests/auto/corelib/thread/qthread/tst_qthread.cpp
+++ b/tests/auto/corelib/thread/qthread/tst_qthread.cpp
@@ -1026,7 +1026,7 @@ void tst_QThread::exitAndExec()
thread.sem2.acquire();
int v = thread.value;
QCOMPARE(v, 556);
-
+
//test that the thread is running by executing queued connected signal there
Syncronizer sync1;
sync1.moveToThread(&thread);
diff --git a/tests/auto/corelib/thread/qthreadonce/qthreadonce.h b/tests/auto/corelib/thread/qthreadonce/qthreadonce.h
index eff7924410..5e04a16bb9 100644
--- a/tests/auto/corelib/thread/qthreadonce/qthreadonce.h
+++ b/tests/auto/corelib/thread/qthreadonce/qthreadonce.h
@@ -46,8 +46,6 @@
#include <QtCore/qglobal.h>
#include <QtCore/qatomic.h>
-QT_BEGIN_HEADER
-
#ifndef QT_NO_THREAD
@@ -108,6 +106,4 @@ public:
#endif // QT_NO_THREAD
-QT_END_HEADER
-
#endif
diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
index a586f81ccc..a93a94a470 100644
--- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
+++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp
@@ -64,6 +64,12 @@ QRunnable *createTask(FunctionPointer pointer)
class tst_QThreadPool : public QObject
{
Q_OBJECT
+public:
+ tst_QThreadPool();
+ ~tst_QThreadPool();
+
+ static QMutex *functionTestMutex;
+
private slots:
void runFunction();
void createThreadRunFunction();
@@ -92,8 +98,24 @@ private slots:
void waitForDoneTimeout();
void destroyingWaitsForTasksToFinish();
void stressTest();
+
+private:
+ QMutex m_functionTestMutex;
};
+
+QMutex *tst_QThreadPool::functionTestMutex = 0;
+
+tst_QThreadPool::tst_QThreadPool()
+{
+ tst_QThreadPool::functionTestMutex = &m_functionTestMutex;
+}
+
+tst_QThreadPool::~tst_QThreadPool()
+{
+ tst_QThreadPool::functionTestMutex = 0;
+}
+
int testFunctionCount;
void sleepTestFunction()
@@ -114,19 +136,19 @@ void noSleepTestFunction()
void sleepTestFunctionMutex()
{
- static QMutex testMutex;
+ Q_ASSERT(tst_QThreadPool::functionTestMutex);
QTest::qSleep(1000);
- testMutex.lock();
+ tst_QThreadPool::functionTestMutex->lock();
++testFunctionCount;
- testMutex.unlock();
+ tst_QThreadPool::functionTestMutex->unlock();
}
void noSleepTestFunctionMutex()
{
- static QMutex testMutex;
- testMutex.lock();
+ Q_ASSERT(tst_QThreadPool::functionTestMutex);
+ tst_QThreadPool::functionTestMutex->lock();
++testFunctionCount;
- testMutex.unlock();
+ tst_QThreadPool::functionTestMutex->unlock();
}
void tst_QThreadPool::runFunction()
@@ -761,7 +783,7 @@ void tst_QThreadPool::waitForDoneTimeout()
public:
QMutex mutex;
BlockedTask() { setAutoDelete(false); }
-
+
void run()
{
mutex.lock();
diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
index 478747bf15..c89d553112 100644
--- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp
+++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp
@@ -709,40 +709,40 @@ void tst_QChar::lineBreakClass()
void tst_QChar::script()
{
- QVERIFY(QUnicodeTables::script(0x0020u) == QUnicodeTables::Common);
- QVERIFY(QUnicodeTables::script(0x0041u) == QUnicodeTables::Common); // ### Latin
- QVERIFY(QUnicodeTables::script(0x0375u) == QUnicodeTables::Greek);
- QVERIFY(QUnicodeTables::script(0x0400u) == QUnicodeTables::Cyrillic);
- QVERIFY(QUnicodeTables::script(0x0531u) == QUnicodeTables::Armenian);
- QVERIFY(QUnicodeTables::script(0x0591u) == QUnicodeTables::Hebrew);
- QVERIFY(QUnicodeTables::script(0x0600u) == QUnicodeTables::Arabic);
- QVERIFY(QUnicodeTables::script(0x0700u) == QUnicodeTables::Syriac);
- QVERIFY(QUnicodeTables::script(0x0780u) == QUnicodeTables::Thaana);
- QVERIFY(QUnicodeTables::script(0x07c0u) == QUnicodeTables::Nko);
- QVERIFY(QUnicodeTables::script(0x0900u) == QUnicodeTables::Devanagari);
- QVERIFY(QUnicodeTables::script(0x0981u) == QUnicodeTables::Bengali);
- QVERIFY(QUnicodeTables::script(0x0a01u) == QUnicodeTables::Gurmukhi);
- QVERIFY(QUnicodeTables::script(0x0a81u) == QUnicodeTables::Gujarati);
- QVERIFY(QUnicodeTables::script(0x0b01u) == QUnicodeTables::Oriya);
- QVERIFY(QUnicodeTables::script(0x0b82u) == QUnicodeTables::Tamil);
- QVERIFY(QUnicodeTables::script(0x0c01u) == QUnicodeTables::Telugu);
- QVERIFY(QUnicodeTables::script(0x0c82u) == QUnicodeTables::Kannada);
- QVERIFY(QUnicodeTables::script(0x0d02u) == QUnicodeTables::Malayalam);
- QVERIFY(QUnicodeTables::script(0x0d82u) == QUnicodeTables::Sinhala);
- QVERIFY(QUnicodeTables::script(0x0e01u) == QUnicodeTables::Thai);
- QVERIFY(QUnicodeTables::script(0x0e81u) == QUnicodeTables::Lao);
- QVERIFY(QUnicodeTables::script(0x0f00u) == QUnicodeTables::Tibetan);
- QVERIFY(QUnicodeTables::script(0x1000u) == QUnicodeTables::Myanmar);
- QVERIFY(QUnicodeTables::script(0x10a0u) == QUnicodeTables::Georgian);
- QVERIFY(QUnicodeTables::script(0x1100u) == QUnicodeTables::Hangul);
- QVERIFY(QUnicodeTables::script(0x1680u) == QUnicodeTables::Ogham);
- QVERIFY(QUnicodeTables::script(0x16a0u) == QUnicodeTables::Runic);
- QVERIFY(QUnicodeTables::script(0x1780u) == QUnicodeTables::Khmer);
- QVERIFY(QUnicodeTables::script(0x200cu) == QUnicodeTables::Inherited);
- QVERIFY(QUnicodeTables::script(0x200du) == QUnicodeTables::Inherited);
- QVERIFY(QUnicodeTables::script(0x1018au) == QUnicodeTables::Greek);
- QVERIFY(QUnicodeTables::script(0x1f130u) == QUnicodeTables::Common);
- QVERIFY(QUnicodeTables::script(0xe0100u) == QUnicodeTables::Inherited);
+ QVERIFY(QChar::script(0x0020u) == QChar::Script_Common);
+ QVERIFY(QChar::script(0x0041u) == QChar::Script_Latin);
+ QVERIFY(QChar::script(0x0375u) == QChar::Script_Greek);
+ QVERIFY(QChar::script(0x0400u) == QChar::Script_Cyrillic);
+ QVERIFY(QChar::script(0x0531u) == QChar::Script_Armenian);
+ QVERIFY(QChar::script(0x0591u) == QChar::Script_Hebrew);
+ QVERIFY(QChar::script(0x0600u) == QChar::Script_Arabic);
+ QVERIFY(QChar::script(0x0700u) == QChar::Script_Syriac);
+ QVERIFY(QChar::script(0x0780u) == QChar::Script_Thaana);
+ QVERIFY(QChar::script(0x07c0u) == QChar::Script_Nko);
+ QVERIFY(QChar::script(0x0900u) == QChar::Script_Devanagari);
+ QVERIFY(QChar::script(0x0981u) == QChar::Script_Bengali);
+ QVERIFY(QChar::script(0x0a01u) == QChar::Script_Gurmukhi);
+ QVERIFY(QChar::script(0x0a81u) == QChar::Script_Gujarati);
+ QVERIFY(QChar::script(0x0b01u) == QChar::Script_Oriya);
+ QVERIFY(QChar::script(0x0b82u) == QChar::Script_Tamil);
+ QVERIFY(QChar::script(0x0c01u) == QChar::Script_Telugu);
+ QVERIFY(QChar::script(0x0c82u) == QChar::Script_Kannada);
+ QVERIFY(QChar::script(0x0d02u) == QChar::Script_Malayalam);
+ QVERIFY(QChar::script(0x0d82u) == QChar::Script_Sinhala);
+ QVERIFY(QChar::script(0x0e01u) == QChar::Script_Thai);
+ QVERIFY(QChar::script(0x0e81u) == QChar::Script_Lao);
+ QVERIFY(QChar::script(0x0f00u) == QChar::Script_Tibetan);
+ QVERIFY(QChar::script(0x1000u) == QChar::Script_Myanmar);
+ QVERIFY(QChar::script(0x10a0u) == QChar::Script_Georgian);
+ QVERIFY(QChar::script(0x1100u) == QChar::Script_Hangul);
+ QVERIFY(QChar::script(0x1680u) == QChar::Script_Ogham);
+ QVERIFY(QChar::script(0x16a0u) == QChar::Script_Runic);
+ QVERIFY(QChar::script(0x1780u) == QChar::Script_Khmer);
+ QVERIFY(QChar::script(0x200cu) == QChar::Script_Inherited);
+ QVERIFY(QChar::script(0x200du) == QChar::Script_Inherited);
+ QVERIFY(QChar::script(0x1018au) == QChar::Script_Greek);
+ QVERIFY(QChar::script(0x1f130u) == QChar::Script_Common);
+ QVERIFY(QChar::script(0xe0100u) == QChar::Script_Inherited);
}
void tst_QChar::normalization_data()
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
index 5ba2f2920a..de252a5d5e 100644
--- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
+++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
@@ -52,6 +52,7 @@ private slots:
void intermediary_result_data();
void intermediary_result();
void sha1();
+ void sha3();
void files_data();
void files();
};
@@ -118,6 +119,23 @@ void tst_QCryptographicHash::intermediary_result_data()
<< QByteArray("abc") << QByteArray("abc")
<< QByteArray::fromHex("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F")
<< QByteArray::fromHex("F3C41E7B63EE869596FC28BAD64120612C520F65928AB4D126C72C6998B551B8FF1CEDDFED4373E6717554DC89D1EEE6F0AB22FD3675E561ABA9AE26A3EEC53B");
+
+ QTest::newRow("sha3_224") << int(QCryptographicHash::Sha3_224)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("C30411768506EBE1C2871B1EE2E87D38DF342317300A9B97A95EC6A8")
+ << QByteArray::fromHex("048330E7C7C8B4A41AB713B3A6F958D77B8CF3EE969930F1584DD550");
+ QTest::newRow("sha3_256") << int(QCryptographicHash::Sha3_256)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("4E03657AEA45A94FC7D47BA826C8D667C0D1E6E33A64A036EC44F58FA12D6C45")
+ << QByteArray::fromHex("9F0ADAD0A59B05D2E04A1373342B10B9EB16C57C164C8A3BFCBF46DCCEE39A21");
+ QTest::newRow("sha3_384") << int(QCryptographicHash::Sha3_384)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("F7DF1165F033337BE098E7D288AD6A2F74409D7A60B49C36642218DE161B1F99F8C681E4AFAF31A34DB29FB763E3C28E")
+ << QByteArray::fromHex("D733B87D392D270889D3DA23AE113F349E25574B445F319CDE4CD3F877C753E9E3C65980421339B3A131457FF393939F");
+ QTest::newRow("sha3_512") << int(QCryptographicHash::Sha3_512)
+ << QByteArray("abc") << QByteArray("abc")
+ << QByteArray::fromHex("18587DC2EA106B9A1563E32B3312421CA164C7F1F07BC922A9C83D77CEA3A1E5D0C69910739025372DC14AC9642629379540C17E2A65B19D77AA511A9D00BB96")
+ << QByteArray::fromHex("A7C392D2A42155761CA76BDDDE1C47D55486B007EDF465397BFB9DFA74D11C8F0D7C86CD29415283F1B5E7F655CEC25B869C9E9C33A8986F0B38542FB12BFB93");
}
void tst_QCryptographicHash::intermediary_result()
@@ -151,22 +169,71 @@ void tst_QCryptographicHash::sha1()
// A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
QCOMPARE(QCryptographicHash::hash("abc", QCryptographicHash::Sha1).toHex().toUpper(),
QByteArray("A9993E364706816ABA3E25717850C26C9CD0D89D"));
-
+
// SHA1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") =
// 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
QCOMPARE(QCryptographicHash::hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
QCryptographicHash::Sha1).toHex().toUpper(),
QByteArray("84983E441C3BD26EBAAE4AA1F95129E5E54670F1"));
-
+
// SHA1(A million repetitions of "a") =
// 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
QByteArray as;
for (int i = 0; i < 1000000; ++i)
as += 'a';
- QCOMPARE(QCryptographicHash::hash(as, QCryptographicHash::Sha1).toHex().toUpper(),
+ QCOMPARE(QCryptographicHash::hash(as, QCryptographicHash::Sha1).toHex().toUpper(),
QByteArray("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F"));
}
+void tst_QCryptographicHash::sha3()
+{
+ // SHA3-224("The quick brown fox jumps over the lazy dog")
+ // 10aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_224).toHex(),
+ QByteArray("310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe"));
+ // SHA3-224("The quick brown fox jumps over the lazy dog.")
+ // c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_224).toHex(),
+ QByteArray("c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab"));
+
+ // SHA3-256("The quick brown fox jumps over the lazy dog")
+ // 4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_256).toHex(),
+ QByteArray("4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15"));
+
+ // SHA3-256("The quick brown fox jumps over the lazy dog.")
+ // 578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_256).toHex(),
+ QByteArray("578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d"));
+
+ // SHA3-384("The quick brown fox jumps over the lazy dog")
+ // 283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_384).toHex(),
+ QByteArray("283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3"));
+
+ // SHA3-384("The quick brown fox jumps over the lazy dog.")
+ // 9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_384).toHex(),
+ QByteArray("9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b"));
+
+ // SHA3-512("The quick brown fox jumps over the lazy dog")
+ // d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog",
+ QCryptographicHash::Sha3_512).toHex(),
+ QByteArray("d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609"));
+
+ // SHA3-512("The quick brown fox jumps over the lazy dog.")
+ // ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760
+ QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.",
+ QCryptographicHash::Sha3_512).toHex(),
+ QByteArray("ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760"));
+}
Q_DECLARE_METATYPE(QCryptographicHash::Algorithm);
diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
index b1874131d7..b84039f557 100644
--- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp
@@ -145,6 +145,8 @@ private:
QDateTime invalidDateTime() const { return QDateTime(invalidDate(), invalidTime()); }
QDate invalidDate() const { return QDate(); }
QTime invalidTime() const { return QTime(-1, -1, -1); }
+ qint64 minJd() const { return QDateTimePrivate::minJd(); }
+ qint64 maxJd() const { return QDateTimePrivate::maxJd(); }
};
Q_DECLARE_METATYPE(Qt::TimeSpec)
@@ -462,14 +464,25 @@ void tst_QDateTime::setMSecsSinceEpoch_data()
<< (Q_INT64_C(123456) << 32)
<< QDateTime(QDate(18772, 8, 15), QTime(1, 8, 14, 976), Qt::UTC)
<< QDateTime(QDate(18772, 8, 15), QTime(3, 8, 14, 976));
- QTest::newRow("min_date") // julian day 0 is an invalid date for QDate
+ QTest::newRow("old min (Tue Nov 25 00:00:00 -4714)")
<< Q_INT64_C(-210866716800000)
<< QDateTime(QDate::fromJulianDay(1), QTime(), Qt::UTC)
<< QDateTime(QDate::fromJulianDay(1), QTime(1, 0));
- QTest::newRow("max_date") // technically jd is unsigned, but fromJulianDay takes int
+ QTest::newRow("old max (Tue Jun 3 21:59:59 5874898)")
<< Q_INT64_C(185331720376799999)
<< QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(21, 59, 59, 999), Qt::UTC)
<< QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(23, 59, 59, 999));
+ QTest::newRow("min")
+ // + 1 because, in the reference check below, calling addMSecs(qint64min)
+ // will internally apply unary minus to -qint64min, resulting in a
+ // positive value 1 too big for qint64max, causing an overflow.
+ << std::numeric_limits<qint64>::min() + 1
+ << QDateTime(QDate(-292275056, 5, 16), QTime(16, 47, 4, 193), Qt::UTC)
+ << QDateTime(QDate(-292275056, 5, 16), QTime(17, 47, 4, 193), Qt::LocalTime);
+ QTest::newRow("max")
+ << std::numeric_limits<qint64>::max()
+ << QDateTime(QDate(292278994, 8, 17), QTime(7, 12, 55, 807), Qt::UTC)
+ << QDateTime(QDate(292278994, 8, 17), QTime(9, 12, 55, 807), Qt::LocalTime);
}
void tst_QDateTime::setMSecsSinceEpoch()
@@ -821,6 +834,29 @@ void tst_QDateTime::toTimeSpec_data()
QTest::newRow("winter4") << QDateTime(QDate(6000, 2, 29), utcTime, Qt::UTC)
<< QDateTime(QDate(6000, 2, 29), localStandardTime, Qt::LocalTime);
+ // Test mktime boundaries (1970 - 2038) and adjustDate().
+ QTest::newRow("1969/12/31 23:00 UTC")
+ << QDateTime(QDate(1969, 12, 31), QTime(23, 0, 0), Qt::UTC)
+ << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::LocalTime);
+ QTest::newRow("2037/12/31 23:00 UTC")
+ << QDateTime(QDate(2037, 12, 31), QTime(23, 0, 0), Qt::UTC)
+ << QDateTime(QDate(2038, 1, 1), QTime(0, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("-271821/4/20 00:00 UTC (JavaScript min date, start of day)")
+ << QDateTime(QDate(-271821, 4, 20), QTime(0, 0, 0), Qt::UTC)
+ << QDateTime(QDate(-271821, 4, 20), QTime(1, 0, 0), Qt::LocalTime);
+ QTest::newRow("-271821/4/20 23:00 UTC (JavaScript min date, end of day)")
+ << QDateTime(QDate(-271821, 4, 20), QTime(23, 0, 0), Qt::UTC)
+ << QDateTime(QDate(-271821, 4, 21), QTime(0, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("QDate min")
+ << QDateTime(QDate::fromJulianDay(minJd()), QTime(0, 0, 0), Qt::UTC)
+ << QDateTime(QDate::fromJulianDay(minJd()), QTime(1, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("QDate max")
+ << QDateTime(QDate::fromJulianDay(maxJd()), QTime(22, 59, 59), Qt::UTC)
+ << QDateTime(QDate::fromJulianDay(maxJd()), QTime(23, 59, 59), Qt::LocalTime);
+
if (europeanTimeZone) {
QTest::newRow("summer1") << QDateTime(QDate(2004, 6, 30), utcTime, Qt::UTC)
<< QDateTime(QDate(2004, 6, 30), localDaylightTime, Qt::LocalTime);
@@ -835,6 +871,14 @@ void tst_QDateTime::toTimeSpec_data()
#endif
QTest::newRow("summer3") << QDateTime(QDate(4000, 6, 30), utcTime, Qt::UTC)
<< QDateTime(QDate(4000, 6, 30), localDaylightTime, Qt::LocalTime);
+
+ QTest::newRow("275760/9/23 00:00 UTC (JavaScript max date, start of day)")
+ << QDateTime(QDate(275760, 9, 23), QTime(0, 0, 0), Qt::UTC)
+ << QDateTime(QDate(275760, 9, 23), QTime(2, 0, 0), Qt::LocalTime);
+
+ QTest::newRow("275760/9/23 22:00 UTC (JavaScript max date, end of day)")
+ << QDateTime(QDate(275760, 9, 23), QTime(22, 0, 0), Qt::UTC)
+ << QDateTime(QDate(275760, 9, 24), QTime(0, 0, 0), Qt::LocalTime);
}
QTest::newRow("msec") << QDateTime(QDate(4000, 6, 30), utcTime.addMSecs(1), Qt::UTC)
diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
index 6df84e6363..1cbf181286 100644
--- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp
+++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp
@@ -74,6 +74,7 @@ private slots:
void const_shared_null();
void twoArguments_qHash();
+ void initializerList();
};
struct Foo {
@@ -844,7 +845,7 @@ void tst_QHash::iterators()
//STL-Style iterators
QHash<int, QString>::iterator stlIt = hash.begin();
- for(stlIt = hash.begin(), i = 1; stlIt != hash.end(), i < 100; ++stlIt, ++i) {
+ for (stlIt = hash.begin(), i = 1; stlIt != hash.end() && i < 100; ++stlIt, ++i) {
testMap.insert(i,stlIt.value());
//QVERIFY(stlIt.value() == hash.value(
}
@@ -869,7 +870,7 @@ void tst_QHash::iterators()
//STL-Style const-iterators
QHash<int, QString>::const_iterator cstlIt = hash.constBegin();
- for(cstlIt = hash.constBegin(), i = 1; cstlIt != hash.constEnd(), i < 100; ++cstlIt, ++i) {
+ for (cstlIt = hash.constBegin(), i = 1; cstlIt != hash.constEnd() && i < 100; ++cstlIt, ++i) {
testMap.insert(i,cstlIt.value());
//QVERIFY(stlIt.value() == hash.value(
}
@@ -1300,5 +1301,34 @@ void tst_QHash::twoArguments_qHash()
QCOMPARE(wrongqHashOverload, 0);
}
+void tst_QHash::initializerList()
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QHash<int, QString> hash{{1, "hello"}, {2, "initializer_list"}};
+ QCOMPARE(hash.count(), 2);
+ QVERIFY(hash[1] == "hello");
+ QVERIFY(hash[2] == "initializer_list");
+
+ QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}};
+ QCOMPARE(multiHash.count(), 3);
+ QList<int> values = multiHash.values("il");
+ QCOMPARE(values.count(), 3);
+
+ QHash<int, int> emptyHash{};
+ QVERIFY(emptyHash.isEmpty());
+
+ QHash<int, char> emptyPairs{{}, {}};
+ QVERIFY(!emptyPairs.isEmpty());
+
+ QMultiHash<QString, double> emptyMultiHash{};
+ QVERIFY(emptyMultiHash.isEmpty());
+
+ QMultiHash<int, float> emptyPairs2{{}, {}};
+ QVERIFY(!emptyPairs2.isEmpty());
+#else
+ QSKIP("Compiler doesn't support initializer lists");
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QHash)
#include "tst_qhash.moc"
diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
index d58d207546..ed74c939f7 100644
--- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp
@@ -42,7 +42,7 @@
#include <QtTest/QtTest>
#include <math.h>
-#include <qglobal.h>
+#include <qdebug.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <QScopedArrayPointer>
@@ -712,6 +712,7 @@ void tst_QLocale::double_conversion()
QFETCH(QString, num_str);
QFETCH(bool, good);
QFETCH(double, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
QLocale locale(locale_name);
QCOMPARE(locale.name(), locale_name);
@@ -726,6 +727,16 @@ void tst_QLocale::double_conversion()
diff = -diff;
QVERIFY(diff <= MY_DOUBLE_EPSILON);
}
+
+ d = locale.toDouble(num_strRef, &ok);
+ QCOMPARE(ok, good);
+
+ if (ok) {
+ double diff = d - num;
+ if (diff < 0)
+ diff = -diff;
+ QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ }
}
void tst_QLocale::long_long_conversion_data()
@@ -787,6 +798,7 @@ void tst_QLocale::long_long_conversion()
QFETCH(QString, num_str);
QFETCH(bool, good);
QFETCH(qlonglong, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
QLocale locale(locale_name);
QCOMPARE(locale.name(), locale_name);
@@ -795,9 +807,14 @@ void tst_QLocale::long_long_conversion()
qlonglong l = locale.toLongLong(num_str, &ok);
QCOMPARE(ok, good);
- if (ok) {
+ if (ok)
+ QCOMPARE(l, num);
+
+ l = locale.toLongLong(num_strRef, &ok);
+ QCOMPARE(ok, good);
+
+ if (ok)
QCOMPARE(l, num);
- }
}
void tst_QLocale::long_long_conversion_extra()
@@ -1281,7 +1298,7 @@ static QString getWinLocaleInfo(LCTYPE type)
int cnt = GetLocaleInfo(id, type, 0, 0) * 2;
if (cnt == 0) {
- qWarning("QLocale: empty windows locale info (%d)", type);
+ qWarning().nospace() << "QLocale: empty windows locale info (" << type << ')';
return QString();
}
cnt /= sizeof(wchar_t);
@@ -1289,7 +1306,7 @@ static QString getWinLocaleInfo(LCTYPE type)
cnt = GetLocaleInfo(id, type, buf.data(), cnt);
if (cnt == 0) {
- qWarning("QLocale: empty windows locale info (%d)", type);
+ qWarning().nospace() << "QLocale: empty windows locale info (" << type << ')';
return QString();
}
return QString::fromWCharArray(buf.data());
@@ -1680,6 +1697,9 @@ void tst_QLocale::dateFormat()
const QLocale ja("ja_JP");
QCOMPARE(ja.dateFormat(QLocale::ShortFormat), QLatin1String("yyyy/MM/dd"));
+
+ const QLocale ir("ga_IE");
+ QCOMPARE(ir.dateFormat(QLocale::ShortFormat), QLatin1String("dd/MM/yyyy"));
}
void tst_QLocale::timeFormat()
diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
index 5069b805bf..0742f19a5e 100644
--- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp
+++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp
@@ -84,6 +84,9 @@ private slots:
void insert();
void checkMostLeftNode();
+ void initializerList();
+ void testInsertWithHint();
+ void testInsertMultiWithHint();
};
typedef QMap<QString, QString> StringMap;
@@ -937,6 +940,18 @@ void tst_QMap::qmultimap_specific()
QVERIFY(map2.remove(42,5));
QVERIFY(map1 == map2);
}
+
+ map1.insert(map1.constBegin(), -1, -1);
+ QCOMPARE(map1.size(), 45);
+ map1.insert(map1.constBegin(), -1, -1);
+ QCOMPARE(map1.size(), 46);
+ map1.insert(map1.constBegin(), -2, -2);
+ QCOMPARE(map1.size(), 47);
+ map1.insert(map1.constBegin(), 5, 5); // Invald hint
+ QCOMPARE(map1.size(), 48);
+ map1.insert(map1.constBegin(), 5, 5); // Invald hint
+ QCOMPARE(map1.size(), 49);
+ sanityCheckTree(map1, __LINE__);
}
void tst_QMap::const_shared_null()
@@ -1129,5 +1144,151 @@ void tst_QMap::checkMostLeftNode()
sanityCheckTree(map, __LINE__);
}
+void tst_QMap::initializerList()
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QMap<int, QString> map{{1, "hello"}, {2, "initializer_list"}};
+ QCOMPARE(map.count(), 2);
+ QVERIFY(map[1] == "hello");
+ QVERIFY(map[2] == "initializer_list");
+
+ QMultiMap<QString, int> multiMap{{"il", 1}, {"il", 2}, {"il", 3}};
+ QCOMPARE(multiMap.count(), 3);
+ QList<int> values = multiMap.values("il");
+ QCOMPARE(values.count(), 3);
+
+ QMap<int, int> emptyMap{};
+ QVERIFY(emptyMap.isEmpty());
+
+ QMap<char, char> emptyPairs{{}, {}};
+ QVERIFY(!emptyPairs.isEmpty());
+
+ QMultiMap<double, double> emptyMultiMap{};
+ QVERIFY(emptyMultiMap.isEmpty());
+
+ QMultiMap<float, float> emptyPairs2{{}, {}};
+ QVERIFY(!emptyPairs2.isEmpty());
+#else
+ QSKIP("Compiler doesn't support initializer lists");
+#endif
+}
+
+void tst_QMap::testInsertWithHint()
+{
+ QMap<int, int> map;
+ map.setSharable(false);
+
+ // Check with end hint();
+ map.insert(map.constEnd(), 3, 1); // size == 1
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 5, 1); // size = 2
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 50, 1); // size = 3
+ sanityCheckTree(map, __LINE__);
+ QMap<int, int>::const_iterator key75(map.insert(map.constEnd(), 75, 1)); // size = 4
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 100, 1); // size = 5
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 105, 1); // size = 6
+ sanityCheckTree(map, __LINE__);
+ map.insert(map.constEnd(), 10, 5); // invalid hint and size = 7
+ sanityCheckTree(map, __LINE__);
+ QMap<int, int>::iterator lastkey = map.insert(map.constEnd(), 105, 12); // overwrite
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(lastkey.value(), 12);
+ QCOMPARE(lastkey.key(), 105);
+ QCOMPARE(map.size(), 7);
+
+ // With regular hint
+ map.insert(key75, 75, 100); // overwrite current key
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 7);
+ QCOMPARE(key75.key(), 75);
+ QCOMPARE(key75.value(), 100);
+
+ map.insert(key75, 50, 101); // overwrite previous value
+ QMap<int, int>::const_iterator key50(key75);
+ --key50;
+ QCOMPARE(map.size(), 7);
+ QCOMPARE(key50.key(), 50);
+ QCOMPARE(key50.value(), 101);
+
+ map.insert(key75, 17, 125); // invalid hint - size 8
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 8);
+
+ // begin
+ map.insert(map.constBegin(), 1, 1); // size 9
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 9);
+
+ map.insert(map.constBegin(), 1, 10); // overwrite existing (leftmost) value
+ QCOMPARE(map.constBegin().value(), 10);
+
+ map.insert(map.constBegin(), 47, 47); // wrong hint - size 10
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 10);
+
+ // insert with right == 0
+ QMap<int, int>::const_iterator i1 (map.insert(key75, 70, 12)); // overwrite
+ map.insert(i1, 69, 12); // size 12
+
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 12);
+}
+
+void tst_QMap::testInsertMultiWithHint()
+{
+ QMap<int, int> map;
+ map.setSharable(false);
+
+ typedef QMap<int, int>::const_iterator cite; // Hack since we define QT_STRICT_ITERATORS
+ map.insertMulti(cite(map.end()), 64, 65);
+ map[128] = 129;
+ map[256] = 257;
+ sanityCheckTree(map, __LINE__);
+
+ map.insertMulti(cite(map.end()), 512, 513);
+ map.insertMulti(cite(map.end()), 512, 513 * 2);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 5);
+ map.insertMulti(cite(map.end()), 256, 258); // wrong hint
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 6);
+
+ QMap<int, int>::iterator i = map.insertMulti(map.constBegin(), 256, 259); // wrong hint
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 7);
+
+ QMap<int, int>::iterator j = map.insertMulti(map.constBegin(), 69, 66);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 8);
+
+ j = map.insertMulti(cite(j), 68, 259);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 9);
+
+ j = map.insertMulti(cite(j), 67, 67);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 10);
+
+ i = map.insertMulti(cite(i), 256, 259);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 11);
+
+ i = map.insertMulti(cite(i), 256, 260);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 12);
+
+ map.insertMulti(cite(i), 64, 67);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 13);
+
+ map.insertMulti(map.constBegin(), 20, 20);
+ sanityCheckTree(map, __LINE__);
+ QCOMPARE(map.size(), 14);
+}
+
+
QTEST_APPLESS_MAIN(tst_QMap)
#include "tst_qmap.moc"
diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
index 9700f91128..d22e771b79 100644
--- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
+++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp
@@ -50,6 +50,7 @@ class tst_QMargins : public QObject
private slots:
void getSetCheck();
void dataStreamCheck();
+ void operators();
};
// Testing get/set functions
@@ -73,7 +74,50 @@ void tst_QMargins::getSetCheck()
margins.setRight(5);
QVERIFY(!margins.isNull());
QCOMPARE(margins, QMargins(5, 0, 5, 0));
-}
+}
+
+void tst_QMargins::operators()
+{
+ const QMargins m1(12, 14, 16, 18);
+ const QMargins m2(2, 3, 4, 5);
+
+ const QMargins added = m1 + m2;
+ QCOMPARE(added, QMargins(14, 17, 20, 23));
+ QMargins a = m1;
+ a += m2;
+ QCOMPARE(a, added);
+
+ const QMargins subtracted = m1 - m2;
+ QCOMPARE(subtracted, QMargins(10, 11, 12, 13));
+ a = m1;
+ a -= m2;
+ QCOMPARE(a, subtracted);
+
+ const QMargins doubled = m1 * 2;
+ QCOMPARE(doubled, QMargins(24, 28, 32, 36));
+ QCOMPARE(2 * m1, doubled);
+ QCOMPARE(qreal(2) * m1, doubled);
+ QCOMPARE(m1 * qreal(2), doubled);
+
+ a = m1;
+ a *= 2;
+ QCOMPARE(a, doubled);
+ a = m1;
+ a *= qreal(2);
+ QCOMPARE(a, doubled);
+
+ const QMargins halved = m1 / 2;
+ QCOMPARE(halved, QMargins(6, 7, 8, 9));
+
+ a = m1;
+ a /= 2;
+ QCOMPARE(a, halved);
+ a = m1;
+ a /= qreal(2);
+ QCOMPARE(a, halved);
+
+ QCOMPARE(m1 + (-m1), QMargins());
+}
// Testing QDataStream operators
void tst_QMargins::dataStreamCheck()
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore
new file mode 100644
index 0000000000..bfd53f437b
--- /dev/null
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore
@@ -0,0 +1 @@
+tst_qmessageauthenticationcode
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro
new file mode 100644
index 0000000000..1ea23915b7
--- /dev/null
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro
@@ -0,0 +1,7 @@
+CONFIG += testcase parallel_test
+TARGET = tst_qmessageauthenticationcode
+QT = core testlib
+SOURCES = tst_qmessageauthenticationcode.cpp
+
+TESTDATA += data/*
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
new file mode 100644
index 0000000000..0e243988e2
--- /dev/null
+++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp
@@ -0,0 +1,151 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** 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 Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtCore/QCoreApplication>
+#include <QtTest/QtTest>
+
+class tst_QMessageAuthenticationCode : public QObject
+{
+ Q_OBJECT
+private slots:
+ void result_data();
+ void result();
+ void result_incremental_data();
+ void result_incremental();
+};
+
+Q_DECLARE_METATYPE(QCryptographicHash::Algorithm)
+
+void tst_QMessageAuthenticationCode::result_data()
+{
+ QTest::addColumn<QCryptographicHash::Algorithm>("algo");
+ QTest::addColumn<QByteArray>("key");
+ QTest::addColumn<QByteArray>("message");
+ QTest::addColumn<QByteArray>("code");
+
+ // Empty values
+ QTest::newRow("md5-empty") << QCryptographicHash::Md5
+ << QByteArray()
+ << QByteArray()
+ << QByteArray::fromHex("74e6f7298a9c2d168935f58c001bad88");
+ QTest::newRow("sha1-empty") << QCryptographicHash::Sha1
+ << QByteArray()
+ << QByteArray()
+ << QByteArray::fromHex("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d");
+ QTest::newRow("sha256-empty") << QCryptographicHash::Sha256
+ << QByteArray()
+ << QByteArray()
+ << QByteArray::fromHex("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad");
+
+ // Some not-empty
+ QTest::newRow("md5") << QCryptographicHash::Md5
+ << QByteArray("key")
+ << QByteArray("The quick brown fox jumps over the lazy dog")
+ << QByteArray::fromHex("80070713463e7749b90c2dc24911e275");
+ QTest::newRow("sha1") << QCryptographicHash::Sha1
+ << QByteArray("key")
+ << QByteArray("The quick brown fox jumps over the lazy dog")
+ << QByteArray::fromHex("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9");
+ QTest::newRow("sha256") << QCryptographicHash::Sha256
+ << QByteArray("key")
+ << QByteArray("The quick brown fox jumps over the lazy dog")
+ << QByteArray::fromHex("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8");
+
+ // Some from rfc-2104
+ QTest::newRow("rfc-md5-1") << QCryptographicHash::Md5
+ << QByteArray::fromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b")
+ << QByteArray("Hi There")
+ << QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d");
+ QTest::newRow("rfc-md5-2") << QCryptographicHash::Md5
+ << QByteArray("Jefe")
+ << QByteArray("what do ya want for nothing?")
+ << QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738");
+ QTest::newRow("rfc-md5-3") << QCryptographicHash::Md5
+ << QByteArray::fromHex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
+ << QByteArray(50, 0xdd)
+ << QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6");
+}
+
+void tst_QMessageAuthenticationCode::result()
+{
+ QFETCH(QCryptographicHash::Algorithm, algo);
+ QFETCH(QByteArray, key);
+ QFETCH(QByteArray, message);
+ QFETCH(QByteArray, code);
+
+ QMessageAuthenticationCode mac(algo);
+ mac.setKey(key);
+ mac.addData(message);
+ QByteArray result = mac.result();
+
+ QCOMPARE(result, code);
+}
+
+void tst_QMessageAuthenticationCode::result_incremental_data()
+{
+ result_data();
+}
+
+void tst_QMessageAuthenticationCode::result_incremental()
+{
+ QFETCH(QCryptographicHash::Algorithm, algo);
+ QFETCH(QByteArray, key);
+ QFETCH(QByteArray, message);
+ QFETCH(QByteArray, code);
+
+ int index = message.length() / 2;
+ QByteArray leftPart(message.mid(0, index));
+ QByteArray rightPart(message.mid(index));
+
+ QCOMPARE(leftPart + rightPart, message);
+
+ QMessageAuthenticationCode mac(algo);
+ mac.setKey(key);
+ mac.addData(leftPart);
+ mac.addData(rightPart);
+ QByteArray result = mac.result();
+
+ QCOMPARE(result, code);
+}
+
+QTEST_MAIN(tst_QMessageAuthenticationCode)
+#include "tst_qmessageauthenticationcode.moc"
diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
index 924cac292e..3231469261 100644
--- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
+++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp
@@ -70,6 +70,9 @@ private slots:
void operator_divide_data();
void operator_divide();
+ void dotProduct_data();
+ void dotProduct();
+
void operator_unary_plus_data();
void operator_unary_plus();
@@ -271,6 +274,28 @@ void tst_QPoint::operator_divide()
QCOMPARE(point, expected);
}
+void tst_QPoint::dotProduct_data()
+{
+ QTest::addColumn<QPoint>("point1");
+ QTest::addColumn<QPoint>("point2");
+ QTest::addColumn<int>("expected");
+
+ QTest::newRow("(0, 0) dot (0, 0)") << QPoint(0, 0) << QPoint(0, 0)<< 0;
+ QTest::newRow("(10, 0) dot (0, 10)") << QPoint(10, 0) << QPoint(0, 10) << 0;
+ QTest::newRow("(0, 10) dot (10, 0)") << QPoint(0, 10) << QPoint(10, 0) << 0;
+ QTest::newRow("(10, 20) dot (-10, -20)") << QPoint(10, 20) << QPoint(-10, -20) << -500;
+ QTest::newRow("(-10, -20) dot (10, 20)") << QPoint(-10, -20) << QPoint(10, 20) << -500;
+}
+
+void tst_QPoint::dotProduct()
+{
+ QFETCH(QPoint, point1);
+ QFETCH(QPoint, point2);
+ QFETCH(int, expected);
+
+ QCOMPARE(QPoint::dotProduct(point1, point2), expected);
+}
+
void tst_QPoint::operator_unary_plus_data()
{
operator_unary_minus_data();
diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
index 0f2e74e68e..fc79b40a18 100644
--- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
+++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp
@@ -75,6 +75,9 @@ private slots:
void operator_divide();
void division();
+ void dotProduct_data();
+ void dotProduct();
+
void operator_unary_plus_data();
void operator_unary_plus();
@@ -290,6 +293,29 @@ void tst_QPointF::division()
}
}
+void tst_QPointF::dotProduct_data()
+{
+ QTest::addColumn<QPointF>("point1");
+ QTest::addColumn<QPointF>("point2");
+ QTest::addColumn<qreal>("expected");
+
+ QTest::newRow("(0, 0) dot (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << qreal(0);
+ QTest::newRow("(10, 0) dot (0, 10)") << QPointF(10, 0) << QPointF(0, 10)<< qreal(0);
+ QTest::newRow("(0, 10) dot (10, 0)") << QPointF(0, 10) << QPointF(10, 0) << qreal(0);
+ QTest::newRow("(10, 20) dot (-10, -20)") << QPointF(10, 20) << QPointF(-10, -20) << qreal(-500);
+ QTest::newRow("(10.1, 20.2) dot (-10.1, -20.2)") << QPointF(10.1, 20.2) << QPointF(-10.1, -20.2) << qreal(-510.05);
+ QTest::newRow("(-10.1, -20.2) dot (10.1, 20.2)") << QPointF(-10.1, -20.2) << QPointF(10.1, 20.2) << qreal(-510.05);
+}
+
+void tst_QPointF::dotProduct()
+{
+ QFETCH(QPointF, point1);
+ QFETCH(QPointF, point2);
+ QFETCH(qreal, expected);
+
+ QCOMPARE(QPointF::dotProduct(point1, point2), expected);
+}
+
void tst_QPointF::operator_unary_plus_data()
{
operator_unary_minus_data();
diff --git a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
index 88de03e4bf..2fdde3c613 100644
--- a/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
+++ b/tests/auto/corelib/tools/qqueue/tst_qqueue.cpp
@@ -63,15 +63,15 @@ void tst_QQueue::enqueue_dequeue_data()
void tst_QQueue::enqueue_dequeue()
{
- QFETCH(int, num_items);
-
- int *values = new int[num_items];
- QQueue<int> queue_v;
- QQueue<int*> queue_p;
+ QFETCH(int, num_items);
+
+ int *values = new int[num_items];
+ QQueue<int> queue_v;
+ QQueue<int*> queue_p;
QVERIFY(queue_v.empty());
QVERIFY(queue_p.empty());
-
+
for (int i = 0; i < num_items; i++ ) {
values[i] = i;
queue_p.enqueue(values + i);
@@ -84,11 +84,11 @@ void tst_QQueue::enqueue_dequeue()
v = queue_v.head();
p = queue_p.head();
QCOMPARE(*p, v);
- QCOMPARE(v, i);
+ QCOMPARE(v, i);
v = queue_v.dequeue();
p = queue_p.dequeue();
- QCOMPARE(*p, v);
- QCOMPARE(v, values[i]);
+ QCOMPARE(*p, v);
+ QCOMPARE(v, values[i]);
}
QVERIFY(queue_v.empty());
QVERIFY(queue_p.empty());
diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
index b3fc8b0759..1b11673bd1 100644
--- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp
+++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp
@@ -41,6 +41,7 @@
#include <QtTest/QtTest>
#include <qrect.h>
+#include <qmargins.h>
#include <limits.h>
#include <qdebug.h>
@@ -133,6 +134,7 @@ private slots:
void newMoveTopLeft();
void newMoveBottomRight_data();
void newMoveBottomRight();
+ void margins();
void translate_data();
void translate();
@@ -3484,6 +3486,25 @@ void tst_QRect::newMoveBottomRight()
QCOMPARE(r,nr);
}
+void tst_QRect::margins()
+{
+ const QRect rectangle = QRect(QPoint(10, 10), QSize(50 ,50));
+ const QMargins margins = QMargins(2, 3, 4, 5);
+
+ const QRect added = rectangle + margins;
+ QCOMPARE(added, QRect(QPoint(8, 7), QSize(56, 58)));
+ QCOMPARE(added, margins + rectangle);
+ QCOMPARE(added, rectangle.marginsAdded(margins));
+
+ QRect a = rectangle;
+ a += margins;
+ QCOMPARE(added, a);
+
+ a = rectangle;
+ a -= margins;
+ QCOMPARE(a, QRect(QPoint(12, 13), QSize(44, 42)));
+ QCOMPARE(a, rectangle.marginsRemoved(margins));
+}
void tst_QRect::translate_data()
{
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
index 7073805db4..909725f4b8 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>.
+** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -126,8 +127,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem)
bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList)
{
QRegularExpressionMatchIterator i = iterator;
- if (i.isValid() != (!expectedMatchList.isEmpty()))
- return false;
foreach (const Match &expectedMatch, expectedMatchList)
{
@@ -293,6 +292,31 @@ void tst_QRegularExpression::provideRegularExpressions()
| QRegularExpression::InvertedGreedinessOption);
}
+void tst_QRegularExpression::defaultConstructors()
+{
+ QRegularExpression re;
+ QCOMPARE(re.pattern(), QString());
+ QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption);
+
+ QRegularExpressionMatch match;
+ QCOMPARE(match.regularExpression(), QRegularExpression());
+ QCOMPARE(match.regularExpression(), re);
+ QCOMPARE(match.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(match.matchOptions(), QRegularExpression::NoMatchOption);
+ QCOMPARE(match.hasMatch(), false);
+ QCOMPARE(match.hasPartialMatch(), false);
+ QCOMPARE(match.isValid(), true);
+ QCOMPARE(match.lastCapturedIndex(), -1);
+
+ QRegularExpressionMatchIterator iterator;
+ QCOMPARE(iterator.regularExpression(), QRegularExpression());
+ QCOMPARE(iterator.regularExpression(), re);
+ QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(iterator.matchOptions(), QRegularExpression::NoMatchOption);
+ QCOMPARE(iterator.isValid(), true);
+ QCOMPARE(iterator.hasNext(), false);
+}
+
void tst_QRegularExpression::gettersSetters_data()
{
provideRegularExpressions();
@@ -693,12 +717,31 @@ void tst_QRegularExpression::normalMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
+ {
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NormalMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Match realMatch;
+ realMatch.clear();
+ realMatch.isValid = match.isValid;
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
}
-
void tst_QRegularExpression::partialMatch_data()
{
QTest::addColumn<QRegularExpression>("regexp");
@@ -952,9 +995,29 @@ void tst_QRegularExpression::partialMatch()
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(Match, match);
- QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
- consistencyCheck(m);
- QVERIFY(m == match);
+ {
+ QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == match);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), matchType);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ Match realMatch;
+ realMatch.clear();
+ realMatch.isValid = match.isValid;
+
+ QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(m);
+ QVERIFY(m == realMatch);
+ QCOMPARE(m.regularExpression(), regexp);
+ QCOMPARE(m.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(m.matchOptions(), matchOptions);
+ }
}
void tst_QRegularExpression::globalMatch_data()
@@ -1223,10 +1286,28 @@ void tst_QRegularExpression::globalMatch()
QFETCH(QRegularExpression::MatchType, matchType);
QFETCH(QRegularExpression::MatchOptions, matchOptions);
QFETCH(QList<Match>, matchList);
+ {
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == matchList);
+ QCOMPARE(iterator.regularExpression(), regexp);
+ QCOMPARE(iterator.matchType(), matchType);
+ QCOMPARE(iterator.matchOptions(), matchOptions);
+ }
+ {
+ // ignore the expected results provided by the match object --
+ // we'll never get any result when testing the NoMatch type.
+ // Just check the validity of the match here.
+ QList<Match> realMatchList;
+
+ QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions);
+ consistencyCheck(iterator);
+ QVERIFY(iterator == realMatchList);
+ QCOMPARE(iterator.regularExpression(), regexp);
+ QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch);
+ QCOMPARE(iterator.matchOptions(), matchOptions);
+ }
- QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions);
- consistencyCheck(iterator);
- QVERIFY(iterator == matchList);
}
void tst_QRegularExpression::serialize_data()
@@ -1338,6 +1419,86 @@ void tst_QRegularExpression::captureCount()
QCOMPARE(re.captureCount(), -1);
}
+// the comma in the template breaks QFETCH...
+typedef QMultiHash<QString, int> StringToIntMap;
+Q_DECLARE_METATYPE(StringToIntMap)
+
+void tst_QRegularExpression::captureNames_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<StringToIntMap>("namedCapturesIndexMap");
+ StringToIntMap map;
+
+ QTest::newRow("captureNames01") << "a pattern" << map;
+ QTest::newRow("captureNames02") << "a.*pattern" << map;
+ QTest::newRow("captureNames03") << "(a) pattern" << map;
+ QTest::newRow("captureNames04") << "(a).*(pattern)" << map;
+
+ map.clear();
+ map.replace("named", 1);
+ QTest::newRow("captureNames05") << "a.*(?<named>pattern)" << map;
+
+ map.clear();
+ map.replace("named", 2);
+ QTest::newRow("captureNames06") << "(a).*(?<named>pattern)" << map;
+
+ map.clear();
+ map.replace("name1", 1);
+ map.replace("name2", 2);
+ QTest::newRow("captureNames07") << "(?<name1>a).*(?<name2>pattern)" << map;
+
+ map.clear();
+ map.replace("name1", 2);
+ map.replace("name2", 1);
+ QTest::newRow("captureNames08") << "(?<name2>a).*(?<name1>pattern)" << map;
+
+ map.clear();
+ map.replace("date", 1);
+ map.replace("month", 2);
+ map.replace("year", 3);
+ QTest::newRow("captureNames09") << "^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$" << map;
+
+ map.clear();
+ map.replace("date", 2);
+ map.replace("month", 1);
+ map.replace("year", 3);
+ QTest::newRow("captureNames10") << "^(?<month>\\d\\d)/(?<date>\\d\\d)/(?<year>\\d\\d\\d\\d)$" << map;
+
+ map.clear();
+ map.replace("noun", 2);
+ QTest::newRow("captureNames11") << "(a)(?|(?<noun>b)|(?<noun>c))(d)" << map;
+
+ map.clear();
+ QTest::newRow("captureNames_invalid01") << "(.*" << map;
+ QTest::newRow("captureNames_invalid02") << "\\" << map;
+ QTest::newRow("captureNames_invalid03") << "(?<noun)" << map;
+ QTest::newRow("captureNames_invalid04") << "(?|(?<noun1>a)|(?<noun2>b))" << map;
+}
+
+void tst_QRegularExpression::captureNames()
+{
+ QFETCH(QString, pattern);
+ QFETCH(StringToIntMap, namedCapturesIndexMap);
+
+ const QRegularExpression re(pattern);
+ QStringList namedCaptureGroups = re.namedCaptureGroups();
+ int namedCaptureGroupsCount = namedCaptureGroups.size();
+
+ QCOMPARE(namedCaptureGroupsCount, re.captureCount() + 1);
+
+ for (int i = 0; i < namedCaptureGroupsCount; ++i) {
+ const QString &name = namedCaptureGroups.at(i);
+
+ if (name.isEmpty()) {
+ QVERIFY(!namedCapturesIndexMap.contains(name));
+ } else {
+ QVERIFY(namedCapturesIndexMap.contains(name));
+ QCOMPARE(i, namedCapturesIndexMap.value(name));
+ }
+ }
+
+}
+
void tst_QRegularExpression::pcreJitStackUsage_data()
{
QTest::addColumn<QString>("pattern");
@@ -1389,3 +1550,35 @@ void tst_QRegularExpression::regularExpressionMatch()
QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed");
QCOMPARE(match.captured(QString()).isNull(), true);
}
+
+void tst_QRegularExpression::JOptionUsage_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<bool>("isValid");
+ QTest::addColumn<bool>("JOptionUsed");
+
+ QTest::newRow("joption-notused-01") << "a.*b" << true << false;
+ QTest::newRow("joption-notused-02") << "^a(b)(c)$" << true << false;
+ QTest::newRow("joption-notused-03") << "a(b)(?<c>d)|e" << true << false;
+ QTest::newRow("joption-notused-04") << "(?<a>.)(?<a>.)" << false << false;
+
+ QTest::newRow("joption-used-01") << "(?J)a.*b" << true << true;
+ QTest::newRow("joption-used-02") << "(?-J)a.*b" << true << true;
+ QTest::newRow("joption-used-03") << "(?J)(?<a>.)(?<a>.)" << true << true;
+ QTest::newRow("joption-used-04") << "(?-J)(?<a>.)(?<a>.)" << false << true;
+
+}
+
+void tst_QRegularExpression::JOptionUsage()
+{
+ QFETCH(QString, pattern);
+ QFETCH(bool, isValid);
+ QFETCH(bool, JOptionUsed);
+
+ const QString warningMessage = QStringLiteral("QRegularExpressionPrivate::getPatternInfo(): the pattern '%1'\n is using the (?J) option; duplicate capturing group names are not supported by Qt");
+
+ QRegularExpression re(pattern);
+ if (isValid && JOptionUsed)
+ QTest::ignoreMessage(QtWarningMsg, qPrintable(warningMessage.arg(pattern)));
+ QCOMPARE(re.isValid(), isValid);
+}
diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
index d6f9312411..0f62570114 100644
--- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
+++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h
@@ -51,6 +51,7 @@ class tst_QRegularExpression : public QObject
Q_OBJECT
private slots:
+ void defaultConstructors();
void gettersSetters_data();
void gettersSetters();
void escape_data();
@@ -71,10 +72,14 @@ private slots:
void operatoreq();
void captureCount_data();
void captureCount();
+ void captureNames_data();
+ void captureNames();
void pcreJitStackUsage_data();
void pcreJitStackUsage();
void regularExpressionMatch_data();
void regularExpressionMatch();
+ void JOptionUsage_data();
+ void JOptionUsage();
private:
void provideRegularExpressions();
diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp
index a3232d05c3..eaa1c018ba 100644
--- a/tests/auto/corelib/tools/qset/tst_qset.cpp
+++ b/tests/auto/corelib/tools/qset/tst_qset.cpp
@@ -79,6 +79,7 @@ private slots:
void javaIterator();
void javaMutableIterator();
void makeSureTheComfortFunctionsCompile();
+ void initializerList();
};
void tst_QSet::operator_eq()
@@ -918,6 +919,27 @@ void tst_QSet::makeSureTheComfortFunctionsCompile()
set1 = set2 - set3;
}
+void tst_QSet::initializerList()
+{
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ QSet<int> set{1, 2, 3, 4, 5};
+ QCOMPARE(set.count(), 5);
+ QVERIFY(set.contains(1));
+ QVERIFY(set.contains(2));
+ QVERIFY(set.contains(3));
+ QVERIFY(set.contains(4));
+ QVERIFY(set.contains(5));
+
+ QSet<int> emptySet{};
+ QVERIFY(emptySet.isEmpty());
+
+ QSet<int> set3{{}, {}, {}};
+ QVERIFY(!set3.isEmpty());
+#else
+ QSKIP("Compiler doesn't support initializer lists");
+#endif
+}
+
QTEST_APPLESS_MAIN(tst_QSet)
#include "tst_qset.moc"
diff --git a/tests/auto/corelib/tools/qsharedpointer/externaltests.pri b/tests/auto/corelib/tools/qsharedpointer/externaltests.pri
index 10d30e3c76..b3a01f7990 100644
--- a/tests/auto/corelib/tools/qsharedpointer/externaltests.pri
+++ b/tests/auto/corelib/tools/qsharedpointer/externaltests.pri
@@ -4,4 +4,4 @@ cleanedQMAKESPEC = $$replace(QMAKESPEC, \\\\, /)
DEFINES += DEFAULT_MAKESPEC=\\\"$$cleanedQMAKESPEC\\\"
cross_compile:DEFINES += QTEST_NO_RTTI QTEST_CROSS_COMPILED
-wince*:DEFINES += QTEST_CROSS_COMPILED QTEST_NO_RTTI
+wince*:DEFINES += QTEST_CROSS_COMPILED QTEST_NO_RTTI
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index 8e10b757c8..5b1a2cf076 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -97,6 +97,7 @@ private slots:
void lambdaCustomDeleter();
#endif
void creating();
+ void creatingVariadic();
void creatingQObject();
void mixTrackingPointerCode();
void reentrancyWhileDestructing();
@@ -176,6 +177,49 @@ public:
int Data::generationCounter = 0;
int Data::destructorCounter = 0;
+struct NoDefaultConstructor1
+{
+ int i;
+ NoDefaultConstructor1(int i) : i(i) {}
+ NoDefaultConstructor1(uint j) : i(j + 42) {}
+};
+
+struct NoDefaultConstructorRef1
+{
+ int &i;
+ NoDefaultConstructorRef1(int &i) : i(i) {}
+};
+
+struct NoDefaultConstructor2
+{
+ void *ptr;
+ int i;
+ NoDefaultConstructor2(void *ptr, int i) : ptr(ptr), i(i) {}
+};
+
+struct NoDefaultConstructorRef2
+{
+ QString str;
+ int i;
+ NoDefaultConstructorRef2(QString &str, int i) : str(str), i(i) {}
+};
+
+struct NoDefaultConstructorConstRef2
+{
+ QString str;
+ int i;
+ NoDefaultConstructorConstRef2(const QString &str, int i) : str(str), i(i) {}
+ NoDefaultConstructorConstRef2(const QByteArray &ba, int i = 42) : str(QString::fromLatin1(ba)), i(i) {}
+};
+
+#ifdef Q_COMPILER_RVALUE_REFS
+struct NoDefaultConstructorRRef1
+{
+ int &i;
+ NoDefaultConstructorRRef1(int &&i) : i(i) {}
+};
+#endif
+
void tst_QSharedPointer::basics_data()
{
QTest::addColumn<bool>("isNull");
@@ -1436,6 +1480,82 @@ void tst_QSharedPointer::creating()
safetyCheck();
}
+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;
+
+ {
+ NoDefaultConstructor1(1); // control check
+ QSharedPointer<NoDefaultConstructor1> ptr = QSharedPointer<NoDefaultConstructor1>::create(1);
+ QCOMPARE(ptr->i, 1);
+
+ NoDefaultConstructor1(0u); // control check
+ ptr = QSharedPointer<NoDefaultConstructor1>::create(0u);
+ QCOMPARE(ptr->i, 42);
+
+ NoDefaultConstructor1 x(i); // control check
+ ptr = QSharedPointer<NoDefaultConstructor1>::create(i);
+ QCOMPARE(ptr->i, i);
+ }
+ {
+ NoDefaultConstructor2((void*)0, 1); // control check
+ QSharedPointer<NoDefaultConstructor2> ptr = QSharedPointer<NoDefaultConstructor2>::create((void*)0, 1);
+ QCOMPARE(ptr->i, 1);
+ QCOMPARE(ptr->ptr, (void*)0);
+
+ int *null = 0;
+ NoDefaultConstructor2(null, 2); // control check
+ ptr = QSharedPointer<NoDefaultConstructor2>::create(null, 2);
+ 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
+ QSharedPointer<NoDefaultConstructorRef1> ptr = QSharedPointer<NoDefaultConstructorRef1>::create(i);
+ QCOMPARE(ptr->i, i);
+ QCOMPARE(&ptr->i, &i);
+ }
+ {
+ NoDefaultConstructorRRef1(1); // control check
+ QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1);
+ QCOMPARE(ptr->i, 1);
+
+ NoDefaultConstructorRRef1(std::move(i)); // control check
+ ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i));
+ QCOMPARE(ptr->i, i);
+ }
+ {
+ QString text("Hello, World");
+ NoDefaultConstructorRef2(text, 1); // control check
+ QSharedPointer<NoDefaultConstructorRef2> ptr = QSharedPointer<NoDefaultConstructorRef2>::create(text, 1);
+ QCOMPARE(ptr->str, text);
+ QCOMPARE(ptr->i, 1);
+ }
+ {
+ QSharedPointer<NoDefaultConstructorConstRef2> ptr;
+ NoDefaultConstructorConstRef2(QLatin1String("string"), 1); // control check
+ ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QLatin1String("string"), 1);
+ QCOMPARE(ptr->str, QString("string"));
+ QCOMPARE(ptr->i, 1);
+
+ NoDefaultConstructorConstRef2(QByteArray("bytearray")); // control check
+ ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QByteArray("bytearray"));
+ QCOMPARE(ptr->str, QString("bytearray"));
+ QCOMPARE(ptr->i, 42);
+ }
+#endif
+}
+
void tst_QSharedPointer::creatingQObject()
{
{
@@ -1876,7 +1996,7 @@ void tst_QSharedPointer::invalidConstructs()
QByteArray body = code.toLatin1();
bool result = (test.*testFunction)(body);
- if (qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) {
+ if (!result || qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) {
qDebug("External test output:");
#ifdef Q_CC_MSVC
// MSVC prints errors to stdout
diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
index 7b7869d033..91293ffc21 100644
--- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp
+++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp
@@ -196,6 +196,8 @@ private slots:
void stringRef_local8Bit();
void fromLatin1();
void fromAscii();
+ void fromUcs4();
+ void toUcs4();
void arg();
void number();
void arg_fillChar_data();
@@ -239,7 +241,7 @@ private slots:
#ifdef QT_USE_ICU
void toUpperLower_icu();
#endif
-#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA)
void literals();
#endif
void eightBitLiterals_data();
@@ -1005,10 +1007,12 @@ void tst_QString::sprintf()
a.sprintf("%s%n%s", "hello", &n1, "goodbye");
QCOMPARE(n1, 5);
QCOMPARE(a, QString("hellogoodbye"));
+#ifndef Q_CC_MINGW // does not know %ll
qlonglong n2;
a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz");
QCOMPARE((int)n2, 6);
QCOMPARE(a, QString("foobarwhiz"));
+#endif
}
/*
@@ -1434,6 +1438,55 @@ void tst_QString::contains()
QVERIFY(a.contains(QRegularExpression("[FG][HI]")));
QVERIFY(a.contains(QRegularExpression("[G][HE]")));
+ {
+ QRegularExpressionMatch match;
+ QVERIFY(!match.hasMatch());
+
+ QVERIFY(a.contains(QRegularExpression("[FG][HI]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 6);
+ QCOMPARE(match.capturedEnd(), 8);
+ QCOMPARE(match.captured(), QStringLiteral("GH"));
+
+ QVERIFY(a.contains(QRegularExpression("[G][HE]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 6);
+ QCOMPARE(match.capturedEnd(), 8);
+ QCOMPARE(match.captured(), QStringLiteral("GH"));
+
+ QVERIFY(a.contains(QRegularExpression("[f](.*)[FG]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 10);
+ QCOMPARE(match.capturedEnd(), 15);
+ QCOMPARE(match.captured(), QString("fGEFG"));
+ QCOMPARE(match.capturedStart(1), 11);
+ QCOMPARE(match.capturedEnd(1), 14);
+ QCOMPARE(match.captured(1), QStringLiteral("GEF"));
+
+ QVERIFY(a.contains(QRegularExpression("[f](.*)[F]"), &match));
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 10);
+ QCOMPARE(match.capturedEnd(), 14);
+ QCOMPARE(match.captured(), QString("fGEF"));
+ QCOMPARE(match.capturedStart(1), 11);
+ QCOMPARE(match.capturedEnd(1), 13);
+ QCOMPARE(match.captured(1), QStringLiteral("GE"));
+
+ QVERIFY(!a.contains(QRegularExpression("ZZZ"), &match));
+ // doesn't match, but ensure match didn't change
+ QVERIFY(match.hasMatch());
+ QCOMPARE(match.capturedStart(), 10);
+ QCOMPARE(match.capturedEnd(), 14);
+ QCOMPARE(match.captured(), QStringLiteral("fGEF"));
+ QCOMPARE(match.capturedStart(1), 11);
+ QCOMPARE(match.capturedEnd(1), 13);
+ QCOMPARE(match.captured(1), QStringLiteral("GE"));
+
+ // don't crash with a null pointer
+ QVERIFY(a.contains(QRegularExpression("[FG][HI]"), 0));
+ QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0));
+ }
+
CREATE_REF(QLatin1String("FG"));
QVERIFY(a.contains(ref));
QVERIFY(a.contains(ref, Qt::CaseInsensitive));
@@ -3894,6 +3947,52 @@ void tst_QString::fromAscii()
QVERIFY(a.size() == 5);
}
+void tst_QString::fromUcs4()
+{
+ QString s;
+ s = QString::fromUcs4( 0 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( 0, 0 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( 0, 5 );
+ QVERIFY( s.isNull() );
+ QCOMPARE( s.size(), 0 );
+
+ uint nil = '\0';
+ s = QString::fromUcs4( &nil );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 0 );
+ s = QString::fromUcs4( &nil, 0 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 0 );
+
+ uint bmp = 'a';
+ s = QString::fromUcs4( &bmp, 1 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 1 );
+
+ uint smp = 0x10000;
+ s = QString::fromUcs4( &smp, 1 );
+ QVERIFY( !s.isNull() );
+ QCOMPARE( s.size(), 2 );
+}
+
+void tst_QString::toUcs4()
+{
+ QString s;
+ QCOMPARE( s.toUcs4().size(), 0 );
+
+ QChar bmp = QLatin1Char('a');
+ s = QString(&bmp, 1);
+ QCOMPARE( s.toUcs4().size(), 1 );
+
+ QChar smp[] = { QChar::highSurrogate(0x10000), QChar::lowSurrogate(0x10000) };
+ s = QString(smp, 2);
+ QCOMPARE( s.toUcs4().size(), 1 );
+}
+
void tst_QString::arg()
{
/*
@@ -5201,6 +5300,9 @@ void tst_QString::QCharRefDetaching() const
void tst_QString::sprintfZU() const
{
+#ifdef Q_CC_MINGW
+ QSKIP("MinGW does not support '%zu'.");
+#else
{
QString string;
size_t s = 6;
@@ -5229,6 +5331,7 @@ void tst_QString::sprintfZU() const
string.sprintf("%zu %s\n", s, "foo");
QCOMPARE(string, QString::fromLatin1("6 foo\n"));
}
+#endif // !Q_CC_MINGW
}
void tst_QString::repeatedSignature() const
@@ -5396,7 +5499,7 @@ void tst_QString::toUpperLower_icu()
}
#endif
-#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU))
+#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA)
// Only tested on c++0x compliant compiler or gcc
void tst_QString::literals()
{
diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
index 66f40e05cb..1045d5929f 100644
--- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
+++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp
@@ -69,6 +69,25 @@ private slots:
void compare_data();
void compare();
void operator_eqeq_nullstring();
+ void toNum();
+ void toDouble_data();
+ void toDouble();
+ void toFloat();
+ void toLong_data();
+ void toLong();
+ void toULong_data();
+ void toULong();
+ void toLongLong();
+ void toULongLong();
+ void toUInt();
+ void toInt();
+ void toShort();
+ void toUShort();
+ void double_conversion_data();
+ void double_conversion();
+ void integer_conversion_data();
+ void integer_conversion();
+ void trimmed();
};
static QStringRef emptyRef()
@@ -840,6 +859,941 @@ void tst_QStringRef::compare()
}
}
+void tst_QStringRef::toNum()
+{
+#define TEST_TO_INT(num, func, type) \
+ a = #num; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.func(&ok), type(Q_INT64_C(num))); \
+ QVERIFY2(ok, "Failed: num=" #num);
+
+ QString a;
+ QStringRef b;
+ bool ok = false;
+
+ TEST_TO_INT(0, toInt, int)
+ TEST_TO_INT(-1, toInt, int)
+ TEST_TO_INT(1, toInt, int)
+ TEST_TO_INT(2147483647, toInt, int)
+ TEST_TO_INT(-2147483648, toInt, int)
+
+ TEST_TO_INT(0, toShort, short)
+ TEST_TO_INT(-1, toShort, short)
+ TEST_TO_INT(1, toShort, short)
+ TEST_TO_INT(32767, toShort, short)
+ TEST_TO_INT(-32768, toShort, short)
+
+ TEST_TO_INT(0, toLong, long)
+ TEST_TO_INT(-1, toLong, long)
+ TEST_TO_INT(1, toLong, long)
+ TEST_TO_INT(2147483647, toLong, long)
+ TEST_TO_INT(-2147483648, toLong, long)
+ TEST_TO_INT(0, toLongLong, (long long))
+ TEST_TO_INT(-1, toLongLong, (long long))
+ TEST_TO_INT(1, toLongLong, (long long))
+ TEST_TO_INT(9223372036854775807, toLongLong, (long long))
+ TEST_TO_INT(-9223372036854775807, toLongLong, (long long))
+
+#undef TEST_TO_INT
+
+#define TEST_TO_UINT(num, func, type) \
+ a = #num; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.func(&ok), type(Q_UINT64_C(num))); \
+ QVERIFY2(ok, "Failed: num=" #num);
+
+ TEST_TO_UINT(0, toUInt, (unsigned int))
+ TEST_TO_UINT(1, toUInt, (unsigned int))
+ TEST_TO_UINT(4294967295, toUInt, (unsigned int))
+
+ TEST_TO_UINT(0, toUShort, (unsigned short))
+ TEST_TO_UINT(1, toUShort, (unsigned short))
+ TEST_TO_UINT(65535, toUShort, (unsigned short))
+
+ TEST_TO_UINT(0, toULong, (unsigned long))
+ TEST_TO_UINT(1, toULong, (unsigned long))
+ TEST_TO_UINT(4294967295, toULong, (unsigned long))
+
+ TEST_TO_UINT(0, toULongLong, (unsigned long long))
+ TEST_TO_UINT(1, toULongLong, (unsigned long long))
+ TEST_TO_UINT(18446744073709551615, toULongLong, (unsigned long long))
+
+#undef TEST_TO_UINT
+
+#define TEST_BASE(str, base, num) \
+ a = str; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.toInt(&ok,base), int(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toInt"); \
+ QCOMPARE(b.toUInt(&ok, base), (unsigned int)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toUInt"); \
+ QCOMPARE(b.toShort(&ok, base), short(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toShort"); \
+ QCOMPARE(b.toUShort(&ok, base), (unsigned short)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toUShort"); \
+ QCOMPARE(b.toLong(&ok, base), long(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toLong"); \
+ QCOMPARE(b.toULong(&ok, base), (unsigned long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toULong"); \
+ QCOMPARE(b.toLongLong(&ok, base), (long long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toLongLong"); \
+ QCOMPARE(b.toULongLong(&ok, base), (unsigned long long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= " #base " num=" #num ", func=toULongLong");
+
+ TEST_BASE("FF", 16, 255)
+ TEST_BASE("0xFF", 16, 255)
+ TEST_BASE("77", 8, 63)
+ TEST_BASE("077", 8, 63)
+
+ TEST_BASE("0xFF", 0, 255)
+ TEST_BASE("077", 0, 63)
+ TEST_BASE("255", 0, 255)
+
+ TEST_BASE(" FF", 16, 255)
+ TEST_BASE(" 0xFF", 16, 255)
+ TEST_BASE(" 77", 8, 63)
+ TEST_BASE(" 077", 8, 63)
+
+ TEST_BASE(" 0xFF", 0, 255)
+ TEST_BASE(" 077", 0, 63)
+ TEST_BASE(" 255", 0, 255)
+
+ TEST_BASE("\tFF\t", 16, 255)
+ TEST_BASE("\t0xFF ", 16, 255)
+ TEST_BASE(" 77 ", 8, 63)
+ TEST_BASE("77 ", 8, 63)
+
+#undef TEST_BASE
+
+#define TEST_NEG_BASE(str, base, num) \
+ a = str; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.toInt(&ok, base), int(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toInt"); \
+ QCOMPARE(b.toShort(&ok,base), short(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toShort"); \
+ QCOMPARE(b.toLong(&ok, base), long(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLong"); \
+ QCOMPARE(b.toLongLong(&ok, base), (long long)(num)); \
+ QVERIFY2(ok, "Failed: str=" #str " base= "#base " num=" #num ", func=toLongLong");
+
+ TEST_NEG_BASE("-FE", 16, -254)
+ TEST_NEG_BASE("-0xFE", 16, -254)
+ TEST_NEG_BASE("-77", 8, -63)
+ TEST_NEG_BASE("-077", 8, -63)
+
+ TEST_NEG_BASE("-0xFE", 0, -254)
+ TEST_NEG_BASE("-077", 0, -63)
+ TEST_NEG_BASE("-254", 0, -254)
+
+#undef TEST_NEG_BASE
+
+#define TEST_DOUBLE(num, str) \
+ a = str; \
+ b = a.leftRef(-1); \
+ QCOMPARE(b.toDouble(&ok), num); \
+ QVERIFY(ok);
+
+ TEST_DOUBLE(1.2345, "1.2345")
+ TEST_DOUBLE(12.345, "1.2345e+01")
+ TEST_DOUBLE(12.345, "1.2345E+01")
+ TEST_DOUBLE(12345.6, "12345.6")
+
+#undef TEST_DOUBLE
+
+#define TEST_BAD(str, func) \
+ a = str; \
+ b = a.leftRef(-1); \
+ b.func(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str " func=" #func);
+
+ TEST_BAD("32768", toShort)
+ TEST_BAD("-32769", toShort)
+ TEST_BAD("65536", toUShort)
+ TEST_BAD("2147483648", toInt)
+ TEST_BAD("-2147483649", toInt)
+ TEST_BAD("4294967296", toUInt)
+ if (sizeof(long) == 4) {
+ TEST_BAD("2147483648", toLong)
+ TEST_BAD("-2147483649", toLong)
+ TEST_BAD("4294967296", toULong)
+ }
+ TEST_BAD("9223372036854775808", toLongLong)
+ TEST_BAD("-9223372036854775809", toLongLong)
+ TEST_BAD("18446744073709551616", toULongLong)
+ TEST_BAD("-1", toUShort)
+ TEST_BAD("-1", toUInt)
+ TEST_BAD("-1", toULong)
+ TEST_BAD("-1", toULongLong)
+
+#undef TEST_BAD
+
+#define TEST_BAD_ALL(str) \
+ a = str; \
+ b = a.leftRef(-1); \
+ b.toShort(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toUShort(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toInt(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toUInt(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toLong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toULong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toLongLong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toULongLong(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toFloat(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str); \
+ b.toDouble(&ok); \
+ QVERIFY2(!ok, "Failed: str=" #str);
+
+ TEST_BAD_ALL((const char*)0);
+ TEST_BAD_ALL("");
+ TEST_BAD_ALL(" ");
+ TEST_BAD_ALL(".");
+ TEST_BAD_ALL("-");
+ TEST_BAD_ALL("hello");
+ TEST_BAD_ALL("1.2.3");
+ TEST_BAD_ALL("0x0x0x");
+ TEST_BAD_ALL("123-^~<");
+ TEST_BAD_ALL("123ThisIsNotANumber");
+
+#undef TEST_BAD_ALL
+
+ a = "FF";
+ b = a.leftRef(-1);
+ b.toULongLong(&ok, 10);
+ QVERIFY(!ok);
+
+ a = "FF";
+ b = a.leftRef(-1);
+ b.toULongLong(&ok, 0);
+ QVERIFY(!ok);
+
+#ifdef QT_NO_FPU
+ double d = 3.40282346638528e+38; // slightly off FLT_MAX when using hardfloats
+#else
+ double d = 3.4028234663852886e+38; // FLT_MAX
+#endif
+ QString::number(d, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(ok);
+ QString::number(d + 1e32, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(!ok);
+ a = QString::number(-d, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(ok);
+ QString::number(-d - 1e32, 'e', 17).leftRef(-1).toFloat(&ok);
+ QVERIFY(!ok);
+ QString::number(d + 1e32, 'e', 17).leftRef(-1).toDouble(&ok);
+ QVERIFY(ok);
+ QString::number(-d - 1e32, 'e', 17).leftRef(-1).toDouble(&ok);
+ QVERIFY(ok);
+}
+
+void tst_QStringRef::toUShort()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "COMPARE";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(123));
+ QCOMPARE(b.toUShort(&ok), ushort(123));
+ QVERIFY(ok);
+
+ a = "123A";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "1234567";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "aaa123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "aaa123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(32767));
+ QCOMPARE(b.toUShort(&ok), ushort(32767));
+ QVERIFY(ok);
+
+ a = "-32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "65535";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(65535));
+ QCOMPARE(b.toUShort(&ok), ushort(65535));
+ QVERIFY(ok);
+
+ if (sizeof(short) == 2) {
+ a = "65536";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+
+ a = "123456";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUShort(), ushort(0));
+ QCOMPARE(b.toUShort(&ok), ushort(0));
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::toShort()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "COMPARE";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(123));
+ QCOMPARE(b.toShort(&ok), short(123));
+ QVERIFY(ok);
+
+ a = "123A";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "1234567";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "aaa123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "aaa123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "123aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(32767));
+ QCOMPARE(b.toShort(&ok), short(32767));
+ QVERIFY(ok);
+
+ a = "-32767";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(-32767));
+ QCOMPARE(b.toShort(&ok), short(-32767));
+ QVERIFY(ok);
+
+ a = "-32768";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(-32768));
+ QCOMPARE(b.toShort(&ok), short(-32768));
+ QVERIFY(ok);
+
+ if (sizeof(short) == 2) {
+ a = "32768";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+
+ a = "-32769";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toShort(), short(0));
+ QCOMPARE(b.toShort(&ok), short(0));
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::toInt()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "COMPARE";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "123";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 123);
+ QCOMPARE(b.toInt(&ok), 123);
+ QVERIFY(ok);
+
+ a = "123A";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "1234567";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 1234567);
+ QCOMPARE(b.toInt(&ok), 1234567);
+ QVERIFY(ok);
+
+ a = "12345678901234";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "3234567890";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "aaa12345aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "aaa12345";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "12345aaa";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "2147483647"; // 2**31 - 1
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 2147483647);
+ QCOMPARE(b.toInt(&ok), 2147483647);
+ QVERIFY(ok);
+
+ if (sizeof(int) == 4) {
+ a = "-2147483647"; // -(2**31 - 1)
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), -2147483647);
+ QCOMPARE(b.toInt(&ok), -2147483647);
+ QVERIFY(ok);
+
+ a = "2147483648"; // 2**31
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+
+ a = "-2147483648"; // -2**31
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), -2147483647 - 1);
+ QCOMPARE(b.toInt(&ok), -2147483647 - 1);
+ QVERIFY(ok);
+
+ a = "2147483649"; // 2**31 + 1
+ b = a.leftRef(-1);
+ QCOMPARE(b.toInt(), 0);
+ QCOMPARE(b.toInt(&ok), 0);
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::toUInt()
+{
+ bool ok;
+ QString a;
+ QStringRef b;
+ a = "3234567890";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(&ok), 3234567890u);
+ QVERIFY(ok);
+
+ a = "-50";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(), 0u);
+ QCOMPARE(b.toUInt(&ok), 0u);
+ QVERIFY(!ok);
+
+ a = "4294967295"; // 2**32 - 1
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(), 4294967295u);
+ QCOMPARE(b.toUInt(&ok), 4294967295u);
+ QVERIFY(ok);
+
+ if (sizeof(int) == 4) {
+ a = "4294967296"; // 2**32
+ b = a.leftRef(-1);
+ QCOMPARE(b.toUInt(), 0u);
+ QCOMPARE(b.toUInt(&ok), 0u);
+ QVERIFY(!ok);
+ }
+}
+
+///////////////////////////// to*Long //////////////////////////////////////
+
+void tst_QStringRef::toULong_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<int>("base");
+ QTest::addColumn<ulong>("result");
+ QTest::addColumn<bool>("ok");
+
+ QTest::newRow("default") << QString() << 10 << 0UL << false;
+ QTest::newRow("empty") << QString("") << 10 << 0UL << false;
+ QTest::newRow("ulong1") << QString("3234567890") << 10 << 3234567890UL << true;
+ QTest::newRow("ulong2") << QString("fFFfFfFf") << 16 << 0xFFFFFFFFUL << true;
+}
+
+void tst_QStringRef::toULong()
+{
+ QFETCH(QString, str);
+ QFETCH(int, base);
+ QFETCH(ulong, result);
+ QFETCH(bool, ok);
+ QStringRef strRef = str.leftRef(-1);
+
+ bool b;
+ QCOMPARE(strRef.toULong(0, base), result);
+ QCOMPARE(strRef.toULong(&b, base), result);
+ QCOMPARE(b, ok);
+}
+
+void tst_QStringRef::toLong_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<int>("base");
+ QTest::addColumn<long>("result");
+ QTest::addColumn<bool>("ok");
+
+ QTest::newRow("default") << QString() << 10 << 0L << false;
+ QTest::newRow("empty") << QString("") << 10 << 0L << false;
+ QTest::newRow("normal") << QString("7fFFfFFf") << 16 << 0x7fFFfFFfL << true;
+ QTest::newRow("long_max") << QString("2147483647") << 10 << 2147483647L << true;
+ if (sizeof(long) == 4) {
+ QTest::newRow("long_max+1") << QString("2147483648") << 10 << 0L << false;
+ QTest::newRow("long_min-1") << QString("-80000001") << 16 << 0L << false;
+ }
+ QTest::newRow("negative") << QString("-7fffffff") << 16 << -0x7fffffffL << true;
+// QTest::newRow("long_min") << QString("-80000000") << 16 << 0x80000000uL << true;
+}
+
+void tst_QStringRef::toLong()
+{
+ QFETCH(QString, str);
+ QFETCH(int, base);
+ QFETCH(long, result);
+ QFETCH(bool, ok);
+ QStringRef strRef = str.leftRef(-1);
+
+ bool b;
+ QCOMPARE(strRef.toLong(0, base), result);
+ QCOMPARE(strRef.toLong(&b, base), result);
+ QCOMPARE(b, ok);
+}
+
+
+////////////////////////// to*LongLong //////////////////////////////////////
+
+void tst_QStringRef::toULongLong()
+{
+ QString str;
+ QStringRef strRef;
+ bool ok;
+ str = "18446744073709551615"; // ULLONG_MAX
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(18446744073709551615));
+ QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(18446744073709551615));
+ QVERIFY(ok);
+
+ str = "18446744073709551616"; // ULLONG_MAX + 1
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(0));
+ QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(0));
+ QVERIFY(!ok);
+
+ str = "-150";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toULongLong(0), Q_UINT64_C(0));
+ QCOMPARE(strRef.toULongLong(&ok), Q_UINT64_C(0));
+ QVERIFY(!ok);
+}
+
+void tst_QStringRef::toLongLong()
+{
+ QString str;
+ QStringRef strRef;
+ bool ok;
+
+ str = "9223372036854775807"; // LLONG_MAX
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(9223372036854775807));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(9223372036854775807));
+ QVERIFY(ok);
+
+ str = "-9223372036854775808"; // LLONG_MIN
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0),
+ -Q_INT64_C(9223372036854775807) - Q_INT64_C(1));
+ QCOMPARE(strRef.toLongLong(&ok),
+ -Q_INT64_C(9223372036854775807) - Q_INT64_C(1));
+ QVERIFY(ok);
+
+ str = "aaaa9223372036854775807aaaa";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0));
+ QVERIFY(!ok);
+
+ str = "9223372036854775807aaaa";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0));
+ QVERIFY(!ok);
+
+ str = "aaaa9223372036854775807";
+ strRef = str.leftRef(-1);
+ QCOMPARE(strRef.toLongLong(0), Q_INT64_C(0));
+ QCOMPARE(strRef.toLongLong(&ok), Q_INT64_C(0));
+ QVERIFY(!ok);
+
+ static char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ for (int i = 0; i < 36; ++i) {
+ for (int j = 0; j < 36; ++j) {
+ for (int k = 0; k < 36; ++k) {
+ QString str;
+ str += QChar(digits[i]);
+ str += QChar(digits[j]);
+ str += QChar(digits[k]);
+ strRef = str.leftRef(-1);
+ qlonglong value = (((i * 36) + j) * 36) + k;
+ QVERIFY(strRef.toLongLong(0, 36) == value);
+ }
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////
+
+void tst_QStringRef::toFloat()
+{
+ QString a;
+ QStringRef b;
+ bool ok;
+ a = "0.000000000931322574615478515625";
+ b = a.leftRef(-1);
+ QCOMPARE(b.toFloat(&ok), float(0.000000000931322574615478515625));
+ QVERIFY(ok);
+}
+
+void tst_QStringRef::toDouble_data()
+{
+ QTest::addColumn<QString>("str");
+ QTest::addColumn<double>("result");
+ QTest::addColumn<bool>("result_ok");
+
+ QTest::newRow("ok00") << QString("0.000000000931322574615478515625") << 0.000000000931322574615478515625 << true;
+ QTest::newRow("ok01") << QString(" 123.45") << 123.45 << true;
+
+ QTest::newRow("ok02") << QString("0.1e10") << 0.1e10 << true;
+ QTest::newRow("ok03") << QString("0.1e-10") << 0.1e-10 << true;
+
+ QTest::newRow("ok04") << QString("1e10") << 1.0e10 << true;
+ QTest::newRow("ok05") << QString("1e+10") << 1.0e10 << true;
+ QTest::newRow("ok06") << QString("1e-10") << 1.0e-10 << true;
+
+ QTest::newRow("ok07") << QString(" 1e10") << 1.0e10 << true;
+ QTest::newRow("ok08") << QString(" 1e+10") << 1.0e10 << true;
+ QTest::newRow("ok09") << QString(" 1e-10") << 1.0e-10 << true;
+
+ QTest::newRow("ok10") << QString("1.") << 1.0 << true;
+ QTest::newRow("ok11") << QString(".1") << 0.1 << true;
+
+ QTest::newRow("wrong00") << QString("123.45 ") << 123.45 << true;
+ QTest::newRow("wrong01") << QString(" 123.45 ") << 123.45 << true;
+
+ QTest::newRow("wrong02") << QString("aa123.45aa") << 0.0 << false;
+ QTest::newRow("wrong03") << QString("123.45aa") << 0.0 << false;
+ QTest::newRow("wrong04") << QString("123erf") << 0.0 << false;
+
+ QTest::newRow("wrong05") << QString("abc") << 0.0 << false;
+ QTest::newRow("wrong06") << QString() << 0.0 << false;
+ QTest::newRow("wrong07") << QString("") << 0.0 << false;
+}
+
+void tst_QStringRef::toDouble()
+{
+ QFETCH(QString, str);
+ QFETCH(bool, result_ok);
+ QStringRef strRef = str.leftRef(-1);
+ bool ok;
+ double d = strRef.toDouble(&ok);
+ if (result_ok) {
+ QTEST(d, "result");
+ QVERIFY(ok);
+ } else {
+ QVERIFY(!ok);
+ }
+}
+
+void tst_QStringRef::integer_conversion_data()
+{
+ QTest::addColumn<QString>("num_str");
+ QTest::addColumn<int>("base");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<qlonglong>("num");
+
+ QTest::newRow("C empty 0") << QString("") << 0 << false << (qlonglong)0;
+ QTest::newRow("C empty 8") << QString("") << 8 << false << (qlonglong)0;
+ QTest::newRow("C empty 10") << QString("") << 10 << false << (qlonglong)0;
+ QTest::newRow("C empty 16") << QString("") << 16 << false << (qlonglong)0;
+
+ QTest::newRow("C null 0") << QString() << 0 << false << (qlonglong)0;
+ QTest::newRow("C null 8") << QString() << 8 << false << (qlonglong)0;
+ QTest::newRow("C null 10") << QString() << 10 << false << (qlonglong)0;
+ QTest::newRow("C null 16") << QString() << 16 << false << (qlonglong)0;
+
+ QTest::newRow("C -0xf 0") << QString(" -0xf") << 0 << true << (qlonglong)-15;
+ QTest::newRow("C -0xf 0") << QString("-0xf ") << 0 << true << (qlonglong)-15;
+ QTest::newRow("C \t0xf\t 0") << QString("\t0xf\t") << 0 << true << (qlonglong)15;
+ QTest::newRow("C -010 0") << QString(" -010") << 0 << true << (qlonglong)-8;
+ QTest::newRow("C 010 0") << QString("010 ") << 0 << true << (qlonglong)8;
+ QTest::newRow("C \t-010\t 0") << QString("\t-010\t") << 0 << true << (qlonglong)-8;
+ QTest::newRow("C 123 10") << QString(" 123") << 10 << true << (qlonglong)123;
+ QTest::newRow("C 123 10") << QString("123 ") << 10 << true << (qlonglong)123;
+ QTest::newRow("C \t123\t 10") << QString("\t123\t") << 10 << true << (qlonglong)123;
+ QTest::newRow("C -0xf 16") << QString(" -0xf") << 16 << true << (qlonglong)-15;
+ QTest::newRow("C -0xf 16") << QString("-0xf ") << 16 << true << (qlonglong)-15;
+ QTest::newRow("C \t0xf\t 16") << QString("\t0xf\t") << 16 << true << (qlonglong)15;
+
+ QTest::newRow("C -0 0") << QString("-0") << 0 << true << (qlonglong)0;
+ QTest::newRow("C -0 8") << QString("-0") << 8 << true << (qlonglong)0;
+ QTest::newRow("C -0 10") << QString("-0") << 10 << true << (qlonglong)0;
+ QTest::newRow("C -0 16") << QString("-0") << 16 << true << (qlonglong)0;
+
+ QTest::newRow("C 1.234 10") << QString("1.234") << 10 << false << (qlonglong)0;
+ QTest::newRow("C 1,234 10") << QString("1,234") << 10 << false << (qlonglong)0;
+
+ QTest::newRow("C 0x 0") << QString("0x") << 0 << false << (qlonglong)0;
+ QTest::newRow("C 0x 16") << QString("0x") << 16 << false << (qlonglong)0;
+
+ QTest::newRow("C 10 0") << QString("10") << 0 << true << (qlonglong)10;
+ QTest::newRow("C 010 0") << QString("010") << 0 << true << (qlonglong)8;
+ QTest::newRow("C 0x10 0") << QString("0x10") << 0 << true << (qlonglong)16;
+ QTest::newRow("C 10 8") << QString("10") << 8 << true << (qlonglong)8;
+ QTest::newRow("C 010 8") << QString("010") << 8 << true << (qlonglong)8;
+ QTest::newRow("C 0x10 8") << QString("0x10") << 8 << false << (qlonglong)0;
+ QTest::newRow("C 10 10") << QString("10") << 10 << true << (qlonglong)10;
+ QTest::newRow("C 010 10") << QString("010") << 10 << true << (qlonglong)10;
+ QTest::newRow("C 0x10 10") << QString("0x10") << 10 << false << (qlonglong)0;
+ QTest::newRow("C 10 16") << QString("10") << 16 << true << (qlonglong)16;
+ QTest::newRow("C 010 16") << QString("010") << 16 << true << (qlonglong)16;
+ QTest::newRow("C 0x10 16") << QString("0x10") << 16 << true << (qlonglong)16;
+
+ QTest::newRow("C -10 0") << QString("-10") << 0 << true << (qlonglong)-10;
+ QTest::newRow("C -010 0") << QString("-010") << 0 << true << (qlonglong)-8;
+ QTest::newRow("C -0x10 0") << QString("-0x10") << 0 << true << (qlonglong)-16;
+ QTest::newRow("C -10 8") << QString("-10") << 8 << true << (qlonglong)-8;
+ QTest::newRow("C -010 8") << QString("-010") << 8 << true << (qlonglong)-8;
+ QTest::newRow("C -0x10 8") << QString("-0x10") << 8 << false << (qlonglong)0;
+ QTest::newRow("C -10 10") << QString("-10") << 10 << true << (qlonglong)-10;
+ QTest::newRow("C -010 10") << QString("-010") << 10 << true << (qlonglong)-10;
+ QTest::newRow("C -0x10 10") << QString("-0x10") << 10 << false << (qlonglong)0;
+ QTest::newRow("C -10 16") << QString("-10") << 16 << true << (qlonglong)-16;
+ QTest::newRow("C -010 16") << QString("-010") << 16 << true << (qlonglong)-16;
+ QTest::newRow("C -0x10 16") << QString("-0x10") << 16 << true << (qlonglong)-16;
+
+ // Let's try some Arabic
+ const quint16 arabic_str[] = { 0x0661, 0x0662, 0x0663, 0x0664, 0x0000 }; // "1234"
+ QTest::newRow("ar_SA 1234 0") << QString::fromUtf16(arabic_str) << 0 << false << (qlonglong)0;
+}
+
+void tst_QStringRef::integer_conversion()
+{
+ QFETCH(QString, num_str);
+ QFETCH(int, base);
+ QFETCH(bool, good);
+ QFETCH(qlonglong, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
+
+ bool ok;
+ qlonglong d = num_strRef.toLongLong(&ok, base);
+ QCOMPARE(ok, good);
+
+ if (ok) {
+ QCOMPARE(d, num);
+ }
+}
+
+void tst_QStringRef::double_conversion_data()
+{
+ QTest::addColumn<QString>("num_str");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<double>("num");
+
+ // The good...
+
+ QTest::newRow("C 1") << QString("1") << true << 1.0;
+ QTest::newRow("C 1.0") << QString("1.0") << true << 1.0;
+ QTest::newRow("C 1.234") << QString("1.234") << true << 1.234;
+ QTest::newRow("C 1.234e-10") << QString("1.234e-10") << true << 1.234e-10;
+ QTest::newRow("C 1.234E10") << QString("1.234E10") << true << 1.234e10;
+ QTest::newRow("C 1e10") << QString("1e10") << true << 1.0e10;
+
+ // The bad...
+
+ QTest::newRow("C empty") << QString("") << false << 0.0;
+ QTest::newRow("C null") << QString() << false << 0.0;
+ QTest::newRow("C .") << QString(".") << false << 0.0;
+ QTest::newRow("C 1e") << QString("1e") << false << 0.0;
+ QTest::newRow("C 1,") << QString("1,") << false << 0.0;
+ QTest::newRow("C 1,0") << QString("1,0") << false << 0.0;
+ QTest::newRow("C 1,000") << QString("1,000") << false << 0.0;
+ QTest::newRow("C 1e1.0") << QString("1e1.0") << false << 0.0;
+ QTest::newRow("C 1e+") << QString("1e+") << false << 0.0;
+ QTest::newRow("C 1e-") << QString("1e-") << false << 0.0;
+ QTest::newRow("de_DE 1,0") << QString("1,0") << false << 0.0;
+ QTest::newRow("de_DE 1,234") << QString("1,234") << false << 0.0;
+ QTest::newRow("de_DE 1,234e-10") << QString("1,234e-10") << false << 0.0;
+ QTest::newRow("de_DE 1,234E10") << QString("1,234E10") << false << 0.0;
+
+ // And the ugly...
+
+ QTest::newRow("C .1") << QString(".1") << true << 0.1;
+ QTest::newRow("C -.1") << QString("-.1") << true << -0.1;
+ QTest::newRow("C 1.") << QString("1.") << true << 1.0;
+ QTest::newRow("C 1.E10") << QString("1.E10") << true << 1.0e10;
+ QTest::newRow("C 1e+10") << QString("1e+10") << true << 1.0e+10;
+ QTest::newRow("C 1") << QString(" 1") << true << 1.0;
+ QTest::newRow("C 1 ") << QString("1 ") << true << 1.0;
+
+ // Let's try some Arabic
+ const quint16 arabic_str[] = { 0x0660, 0x066B, 0x0661, 0x0662,
+ 0x0663, 0x0664, 0x0065, 0x0662,
+ 0x0000 }; // "0.1234e2"
+ QTest::newRow("ar_SA") << QString::fromUtf16(arabic_str) << false << 0.0;
+}
+
+void tst_QStringRef::double_conversion()
+{
+#define MY_DOUBLE_EPSILON (2.22045e-16)
+
+ QFETCH(QString, num_str);
+ QFETCH(bool, good);
+ QFETCH(double, num);
+ QStringRef num_strRef = num_str.leftRef(-1);
+
+ bool ok;
+ double d = num_strRef.toDouble(&ok);
+ QCOMPARE(ok, good);
+
+ if (ok) {
+ double diff = d - num;
+ if (diff < 0)
+ diff = -diff;
+ QVERIFY(diff <= MY_DOUBLE_EPSILON);
+ }
+}
+
+void tst_QStringRef::trimmed()
+{
+ QString a;
+ QStringRef b;
+ a = "Text";
+ b = a.leftRef(-1);
+ QCOMPARE(b.compare(QStringLiteral("Text")), 0);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("Text")), 0);
+ a = " ";
+ b = a.leftRef(-1);
+ QCOMPARE(b.compare(QStringLiteral(" ")), 0);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("")), 0);
+ a = " a ";
+ b = a.leftRef(-1);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0);
+ a = "Text a ";
+ b = a.midRef(4);
+ QCOMPARE(b.compare(QStringLiteral(" a ")), 0);
+ QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0);
+}
+
QTEST_APPLESS_MAIN(tst_QStringRef)
#include "tst_qstringref.moc"
diff --git a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
index 4d05f45252..e6629301f9 100644
--- a/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
+++ b/tests/auto/corelib/tools/qtimeline/tst_qtimeline.cpp
@@ -69,6 +69,7 @@ private slots:
void stateInFinishedSignal();
void resume();
void restart();
+ void setPaused();
protected slots:
void finishedSlot();
@@ -681,6 +682,28 @@ void tst_QTimeLine::restart()
QCOMPARE(timeLine.currentTime(), 0);
}
+void tst_QTimeLine::setPaused()
+{
+ QTimeLine timeLine(1000);
+ {
+ QCOMPARE(timeLine.currentTime(), 0);
+ timeLine.start();
+ QTest::qWait(250);
+ timeLine.setPaused(true);
+ int oldCurrentTime = timeLine.currentTime();
+ QVERIFY(oldCurrentTime > 0);
+ QVERIFY(oldCurrentTime < 1000);
+ QTest::qWait(1000);
+ timeLine.setPaused(false);
+ QTest::qWait(250);
+ int currentTime = timeLine.currentTime();
+ QVERIFY(currentTime > 0);
+ QVERIFY(currentTime > oldCurrentTime);
+ QVERIFY(currentTime < 1000);
+ timeLine.stop();
+ }
+}
+
QTEST_MAIN(tst_QTimeLine)
#include "tst_qtimeline.moc"
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index bda3a2596f..c19080e345 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -58,6 +58,7 @@ private slots:
void count();
void first();
void last();
+ void squeeze();
};
int fooCtor = 0;
@@ -653,5 +654,28 @@ void tst_QVarLengthArray::last()
QCOMPARE(list.length(), 1);
}
+void tst_QVarLengthArray::squeeze()
+{
+ QVarLengthArray<int> list;
+ int sizeOnStack = list.capacity();
+ int sizeOnHeap = sizeOnStack * 2;
+ list.resize(0);
+ QCOMPARE(list.capacity(), sizeOnStack);
+ list.resize(sizeOnHeap);
+ QCOMPARE(list.capacity(), sizeOnHeap);
+ list.resize(sizeOnStack);
+ QCOMPARE(list.capacity(), sizeOnHeap);
+ list.resize(0);
+ QCOMPARE(list.capacity(), sizeOnHeap);
+ list.squeeze();
+ QCOMPARE(list.capacity(), sizeOnStack);
+ list.resize(sizeOnStack);
+ list.squeeze();
+ QCOMPARE(list.capacity(), sizeOnStack);
+ list.resize(sizeOnHeap);
+ list.squeeze();
+ QCOMPARE(list.capacity(), sizeOnHeap);
+}
+
QTEST_APPLESS_MAIN(tst_QVarLengthArray)
#include "tst_qvarlengtharray.moc"
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index 7738a2c797..53caec4a64 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -236,6 +236,7 @@ private slots:
void removeInt() const;
void removeMovable() const;
void removeCustom() const;
+ void removeFirstLast() const;
void resizePOD_data() const;
void resizePOD() const;
void resizeComplexMovable_data() const;
@@ -1393,6 +1394,103 @@ void tst_QVector::removeCustom() const
QCOMPARE(instancesCount, Custom::counter.loadAcquire());
}
+struct RemoveLastTestClass
+{
+ RemoveLastTestClass() { other = 0; deleted = false; }
+ RemoveLastTestClass *other;
+ bool deleted;
+ ~RemoveLastTestClass()
+ {
+ deleted = true;
+ if (other)
+ other->other = 0;
+ }
+};
+
+void tst_QVector::removeFirstLast() const
+{
+ // pop_pack - pop_front
+ QVector<int> t, t2;
+ t.append(1);
+ t.append(2);
+ t.append(3);
+ t.append(4);
+ t2 = t;
+ t.pop_front();
+ QCOMPARE(t.size(), 3);
+ QCOMPARE(t.at(0), 2);
+ t.pop_back();
+ QCOMPARE(t.size(), 2);
+ QCOMPARE(t.at(0), 2);
+ QCOMPARE(t.at(1), 3);
+
+ // takefirst - takeLast
+ int n1 = t2.takeLast();
+ QCOMPARE(t2.size(), 3);
+ QCOMPARE(n1, 4);
+ QCOMPARE(t2.at(0), 1);
+ QCOMPARE(t2.at(2), 3);
+ n1 = t2.takeFirst();
+ QCOMPARE(t2.size(), 2);
+ QCOMPARE(n1, 1);
+ QCOMPARE(t2.at(0), 2);
+ QCOMPARE(t2.at(1), 3);
+
+ // remove first
+ QVector<int> x, y;
+ x.append(1);
+ x.append(2);
+ y = x;
+ x.removeFirst();
+ QCOMPARE(x.size(), 1);
+ QCOMPARE(y.size(), 2);
+ QCOMPARE(x.at(0), 2);
+
+ // remove Last
+ QVector<RemoveLastTestClass> v;
+ v.resize(2);
+ v[0].other = &(v[1]);
+ v[1].other = &(v[0]);
+ // Check dtor - complex type
+ QVERIFY(v.at(0).other != 0);
+ v.removeLast();
+ QVERIFY(v.at(0).other == 0);
+ QCOMPARE(v.at(0).deleted, false);
+ // check iterator
+ int count = 0;
+ for (QVector<RemoveLastTestClass>::const_iterator i = v.constBegin(); i != v.constEnd(); ++i) {
+ ++count;
+ QVERIFY(i->other == 0);
+ QCOMPARE(i->deleted, false);
+ }
+ // Check size
+ QCOMPARE(count, 1);
+ QCOMPARE(v.size(), 1);
+ v.removeLast();
+ QCOMPARE(v.size(), 0);
+ // Check if we do correct realloc
+ QVector<int> v2, v3;
+ v2.append(1);
+ v2.append(2);
+ v3 = v2; // shared
+ v2.removeLast();
+ QCOMPARE(v2.size(), 1);
+ QCOMPARE(v3.size(), 2);
+ QCOMPARE(v2.at(0), 1);
+ QCOMPARE(v3.at(0), 1);
+ QCOMPARE(v3.at(1), 2);
+
+ // Remove last with shared
+ QVector<int> z1, z2;
+ z1.append(9);
+ z2 = z1;
+ z1.removeLast();
+ QCOMPARE(z1.size(), 0);
+ QCOMPARE(z2.size(), 1);
+ QCOMPARE(z2.at(0), 9);
+}
+
+
void tst_QVector::resizePOD_data() const
{
QTest::addColumn<QVector<int> >("vector");
diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro
index 100409e58b..f8b2437d35 100644
--- a/tests/auto/corelib/tools/tools.pro
+++ b/tests/auto/corelib/tools/tools.pro
@@ -22,6 +22,7 @@ SUBDIRS=\
qlocale \
qmap \
qmargins \
+ qmessageauthenticationcode \
qpair \
qpoint \
qpointf \
diff --git a/tests/auto/corelib/xml/xml.pro b/tests/auto/corelib/xml/xml.pro
index 53836cb7f0..20519edf1b 100644
--- a/tests/auto/corelib/xml/xml.pro
+++ b/tests/auto/corelib/xml/xml.pro
@@ -1,3 +1,3 @@
TEMPLATE=subdirs
-SUBDIRS=\
+qtHaveModule(network): SUBDIRS= \
qxmlstream