summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp10
-rw-r--r--tests/auto/corelib/kernel/qmath/tst_qmath.cpp119
-rw-r--r--tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp14
-rw-r--r--tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp4
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp19
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp33
-rw-r--r--tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp20
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp6
-rw-r--r--tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp25
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp99
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp6
11 files changed, 303 insertions, 52 deletions
diff --git a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
index a7833aa835..ce9577e0ed 100644
--- a/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
+++ b/tests/auto/corelib/kernel/qeventloop/tst_qeventloop.cpp
@@ -195,8 +195,8 @@ protected:
void tst_QEventLoop::processEvents()
{
- QSignalSpy aboutToBlockSpy(QAbstractEventDispatcher::instance(), SIGNAL(aboutToBlock()));
- QSignalSpy awakeSpy(QAbstractEventDispatcher::instance(), SIGNAL(awake()));
+ QSignalSpy aboutToBlockSpy(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::aboutToBlock);
+ QSignalSpy awakeSpy(QAbstractEventDispatcher::instance(), &QAbstractEventDispatcher::awake);
QVERIFY(aboutToBlockSpy.isValid());
QVERIFY(awakeSpy.isValid());
@@ -282,7 +282,7 @@ void tst_QEventLoop::exec()
thread.cond.wait(&thread.mutex);
// make sure the eventloop runs
- QSignalSpy spy(QAbstractEventDispatcher::instance(&thread), SIGNAL(awake()));
+ QSignalSpy spy(QAbstractEventDispatcher::instance(&thread), &QAbstractEventDispatcher::awake);
QVERIFY(spy.isValid());
thread.cond.wakeOne();
thread.cond.wait(&thread.mutex);
@@ -345,7 +345,7 @@ void tst_QEventLoop::wakeUp()
thread.start();
(void) eventLoop.exec();
- QSignalSpy spy(QAbstractEventDispatcher::instance(&thread), SIGNAL(awake()));
+ QSignalSpy spy(QAbstractEventDispatcher::instance(&thread), &QAbstractEventDispatcher::awake);
QVERIFY(spy.isValid());
thread.eventLoop->wakeUp();
@@ -633,7 +633,7 @@ void tst_QEventLoop::testQuitLock()
QTimer timer;
timer.setInterval(100);
- QSignalSpy timerSpy(&timer, SIGNAL(timeout()));
+ QSignalSpy timerSpy(&timer, &QTimer::timeout);
timer.start();
QEventLoopPrivate* privateClass = static_cast<QEventLoopPrivate*>(QObjectPrivate::get(&eventLoop));
diff --git a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp
index 24934ac138..8d6964cbcd 100644
--- a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp
+++ b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp
@@ -54,6 +54,14 @@ private slots:
void degreesToRadians();
void radiansToDegrees_data();
void radiansToDegrees();
+ void qNextPowerOfTwo32S_data();
+ void qNextPowerOfTwo32S();
+ void qNextPowerOfTwo64S_data();
+ void qNextPowerOfTwo64S();
+ void qNextPowerOfTwo32U_data();
+ void qNextPowerOfTwo32U();
+ void qNextPowerOfTwo64U_data();
+ void qNextPowerOfTwo64U();
};
void tst_QMath::fastSinCos()
@@ -137,6 +145,117 @@ void tst_QMath::radiansToDegrees()
QCOMPARE(qRadiansToDegrees(radiansDouble), degreesDouble);
}
+
+void tst_QMath::qNextPowerOfTwo32S_data()
+{
+ QTest::addColumn<qint32>("input");
+ QTest::addColumn<quint32>("output");
+
+ QTest::newRow("0") << 0 << 1U;
+ QTest::newRow("1") << 1 << 2U;
+ QTest::newRow("2") << 2 << 4U;
+ QTest::newRow("17") << 17 << 32U;
+ QTest::newRow("128") << 128 << 256U;
+ QTest::newRow("65535") << 65535 << 65536U;
+ QTest::newRow("65536") << 65536 << 131072U;
+ QTest::newRow("2^30") << (1 << 30) << (1U << 31);
+ QTest::newRow("2^30 + 1") << (1 << 30) + 1 << (1U << 31);
+ QTest::newRow("2^31 - 1") << 0x7FFFFFFF << (1U<<31);
+ QTest::newRow("-1") << -1 << 0U;
+ QTest::newRow("-128") << -128 << 0U;
+ QTest::newRow("-(2^31)") << int(0x80000000) << 0U;
+}
+
+void tst_QMath::qNextPowerOfTwo32S()
+{
+ QFETCH(qint32, input);
+ QFETCH(quint32, output);
+
+ QCOMPARE(qNextPowerOfTwo(input), output);
+}
+
+void tst_QMath::qNextPowerOfTwo32U_data()
+{
+ QTest::addColumn<quint32>("input");
+ QTest::addColumn<quint32>("output");
+
+ QTest::newRow("0") << 0U << 1U;
+ QTest::newRow("1") << 1U << 2U;
+ QTest::newRow("2") << 2U << 4U;
+ QTest::newRow("17") << 17U << 32U;
+ QTest::newRow("128") << 128U << 256U;
+ QTest::newRow("65535") << 65535U << 65536U;
+ QTest::newRow("65536") << 65536U << 131072U;
+ QTest::newRow("2^30") << (1U << 30) << (1U << 31);
+ QTest::newRow("2^30 + 1") << (1U << 30) + 1 << (1U << 31);
+ QTest::newRow("2^31 - 1") << 2147483647U << 2147483648U;
+ QTest::newRow("2^31") << 2147483648U << 0U;
+ QTest::newRow("2^31 + 1") << 2147483649U << 0U;
+}
+
+void tst_QMath::qNextPowerOfTwo32U()
+{
+ QFETCH(quint32, input);
+ QFETCH(quint32, output);
+
+ QCOMPARE(qNextPowerOfTwo(input), output);
+}
+
+void tst_QMath::qNextPowerOfTwo64S_data()
+{
+ QTest::addColumn<qint64>("input");
+ QTest::addColumn<quint64>("output");
+
+ QTest::newRow("0") << Q_INT64_C(0) << Q_UINT64_C(1);
+ QTest::newRow("1") << Q_INT64_C(1) << Q_UINT64_C(2);
+ QTest::newRow("2") << Q_INT64_C(2) << Q_UINT64_C(4);
+ QTest::newRow("17") << Q_INT64_C(17) << Q_UINT64_C(32);
+ QTest::newRow("128") << Q_INT64_C(128) << Q_UINT64_C(256);
+ QTest::newRow("65535") << Q_INT64_C(65535) << Q_UINT64_C(65536);
+ QTest::newRow("65536") << Q_INT64_C(65536) << Q_UINT64_C(131072);
+ QTest::newRow("2^31 - 1") << Q_INT64_C(2147483647) << Q_UINT64_C(0x80000000);
+ QTest::newRow("2^31") << Q_INT64_C(2147483648) << Q_UINT64_C(0x100000000);
+ QTest::newRow("2^31 + 1") << Q_INT64_C(2147483649) << Q_UINT64_C(0x100000000);
+ QTest::newRow("2^63 - 1") << Q_INT64_C(0x7FFFFFFFFFFFFFFF) << Q_UINT64_C(0x8000000000000000);
+ QTest::newRow("-1") << Q_INT64_C(-1) << Q_UINT64_C(0);
+ QTest::newRow("-128") << Q_INT64_C(-128) << Q_UINT64_C(0);
+ QTest::newRow("-(2^31)") << -Q_INT64_C(0x80000000) << Q_UINT64_C(0);
+ QTest::newRow("-(2^63)") << (qint64)Q_INT64_C(0x8000000000000000) << Q_UINT64_C(0);
+}
+
+void tst_QMath::qNextPowerOfTwo64S()
+{
+ QFETCH(qint64, input);
+ QFETCH(quint64, output);
+
+ QCOMPARE(qNextPowerOfTwo(input), output);
+}
+
+void tst_QMath::qNextPowerOfTwo64U_data()
+{
+ QTest::addColumn<quint64>("input");
+ QTest::addColumn<quint64>("output");
+
+ QTest::newRow("0") << Q_UINT64_C(0) << Q_UINT64_C(1);
+ QTest::newRow("1") << Q_UINT64_C(1) << Q_UINT64_C(2);
+ QTest::newRow("2") << Q_UINT64_C(2) << Q_UINT64_C(4);
+ QTest::newRow("17") << Q_UINT64_C(17) << Q_UINT64_C(32);
+ QTest::newRow("128") << Q_UINT64_C(128) << Q_UINT64_C(256);
+ QTest::newRow("65535") << Q_UINT64_C(65535) << Q_UINT64_C(65536);
+ QTest::newRow("65536") << Q_UINT64_C(65536) << Q_UINT64_C(131072);
+ QTest::newRow("2^63 - 1") << Q_UINT64_C(0x7FFFFFFFFFFFFFFF) << Q_UINT64_C(0x8000000000000000);
+ QTest::newRow("2^63") << Q_UINT64_C(0x8000000000000000) << Q_UINT64_C(0);
+ QTest::newRow("2^63 + 1") << Q_UINT64_C(0x8000000000000001) << Q_UINT64_C(0);
+}
+
+void tst_QMath::qNextPowerOfTwo64U()
+{
+ QFETCH(quint64, input);
+ QFETCH(quint64, output);
+
+ QCOMPARE(qNextPowerOfTwo(input), output);
+}
+
QTEST_APPLESS_MAIN(tst_QMath)
#include "tst_qmath.moc"
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
index 3afc2bc574..a920ea7a01 100644
--- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
@@ -561,9 +561,11 @@ void tst_QMetaObject::invokeMetaMember()
QVERIFY(!QMetaObject::invokeMethod(&obj, "doesNotExist"));
QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString)(QString)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1(QString)", Q_ARG(QString, "arg")));
- QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl3(QString)");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl3(QString)\n"
+ "Candidates are:\n sl3(QString,QString,QString)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl3", Q_ARG(QString, "arg")));
- QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString,QString,QString)");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString,QString,QString)\n"
+ "Candidates are:\n sl1(QString)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1", Q_ARG(QString, "arg"), Q_ARG(QString, "arg"), Q_ARG(QString, "arg")));
//should not have changed since last test.
@@ -747,9 +749,11 @@ void tst_QMetaObject::invokeBlockingQueuedMetaMember()
QVERIFY(!QMetaObject::invokeMethod(&obj, "doesNotExist", Qt::BlockingQueuedConnection));
QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString)(QString)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1(QString)", Qt::BlockingQueuedConnection, Q_ARG(QString, "arg")));
- QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl3(QString)");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl3(QString)\n"
+ "Candidates are:\n sl3(QString,QString,QString)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl3", Qt::BlockingQueuedConnection, Q_ARG(QString, "arg")));
- QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString,QString,QString)");
+ QTest::ignoreMessage(QtWarningMsg, "QMetaObject::invokeMethod: No such method QtTestObject::sl1(QString,QString,QString)\n"
+ "Candidates are:\n sl1(QString)");
QVERIFY(!QMetaObject::invokeMethod(&obj, "sl1", Qt::BlockingQueuedConnection, Q_ARG(QString, "arg"), Q_ARG(QString, "arg"), Q_ARG(QString, "arg")));
//should not have changed since last test.
@@ -857,7 +861,7 @@ void tst_QMetaObject::invokeTypedefTypes()
{
qRegisterMetaType<CustomString>("CustomString");
QtTestCustomObject obj;
- QSignalSpy spy(&obj, SIGNAL(sig_custom(CustomString)));
+ QSignalSpy spy(&obj, &QtTestCustomObject::sig_custom);
QVERIFY(spy.isValid());
QCOMPARE(spy.count(), 0);
diff --git a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
index 0e7005799e..62e41a96c5 100644
--- a/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
+++ b/tests/auto/corelib/kernel/qmetaobjectbuilder/tst_qmetaobjectbuilder.cpp
@@ -1593,7 +1593,7 @@ void tst_QMetaObjectBuilder::usage_signal()
{
QScopedPointer<TestObject> testObject(new TestObject);
- QSignalSpy propChangedSpy(testObject.data(), SIGNAL(intPropChanged(int)));
+ QSignalSpy propChangedSpy(testObject.data(), &TestObject::intPropChanged);
testObject->emitIntPropChanged();
QCOMPARE(propChangedSpy.count(), 1);
QCOMPARE(propChangedSpy.at(0).count(), 1);
@@ -1608,7 +1608,7 @@ void tst_QMetaObjectBuilder::usage_property()
QCOMPARE(prop.type(), QVariant::Int);
QCOMPARE(prop.toInt(), testObject->intProp());
- QSignalSpy propChangedSpy(testObject.data(), SIGNAL(intPropChanged(int)));
+ QSignalSpy propChangedSpy(testObject.data(), &TestObject::intPropChanged);
QVERIFY(testObject->intProp() != 123);
testObject->setProperty("intProp", 123);
QCOMPARE(propChangedSpy.count(), 1);
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 959c79ed60..9a86dc03e5 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -1341,6 +1341,8 @@ static QByteArray createTypeName(const char *begin, const char *va)
}
#endif
+Q_DECLARE_METATYPE(const void*)
+
void tst_QMetaType::automaticTemplateRegistration()
{
#define TEST_SEQUENTIAL_CONTAINER(CONTAINER, VALUE_TYPE) \
@@ -1358,6 +1360,17 @@ void tst_QMetaType::automaticTemplateRegistration()
TEST_SEQUENTIAL_CONTAINER(std::list, int)
{
+ std::vector<bool> vecbool;
+ vecbool.push_back(true);
+ vecbool.push_back(false);
+ vecbool.push_back(true);
+ QVERIFY(QVariant::fromValue(vecbool).value<std::vector<bool> >().front() == true);
+ QVector<std::vector<bool> > vectorList;
+ vectorList << vecbool;
+ QVERIFY(QVariant::fromValue(vectorList).value<QVector<std::vector<bool> > >().first().front() == true);
+ }
+
+ {
QList<QByteArray> bytearrayList;
bytearrayList << QByteArray("foo");
QVERIFY(QVariant::fromValue(bytearrayList).value<QList<QByteArray> >().first() == QByteArray("foo"));
@@ -1577,6 +1590,12 @@ void tst_QMetaType::automaticTemplateRegistration()
)
CREATE_AND_VERIFY_CONTAINER(QList, QList<QMap<int, QHash<char, QVariantList> > >)
+ CREATE_AND_VERIFY_CONTAINER(QVector, void*)
+ CREATE_AND_VERIFY_CONTAINER(QVector, const void*)
+ CREATE_AND_VERIFY_CONTAINER(QList, void*)
+ CREATE_AND_VERIFY_CONTAINER(QPair, void*, void*)
+ CREATE_AND_VERIFY_CONTAINER(QHash, void*, void*)
+ CREATE_AND_VERIFY_CONTAINER(QHash, const void*, const void*)
#endif // Q_COMPILER_VARIADIC_MACROS
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 46f034ac84..647ddf1b96 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -270,6 +270,21 @@ public slots:
int ReceiverObject::sequence = 0;
+static void playWithObjects()
+{
+ // Do operations that will lock the internal signalSlotLock mutex on many QObjects.
+ // The more QObjects, the higher the chance that the signalSlotLock mutex used
+ // is already in use. If the number of objects is higher than the number of mutexes in
+ // the pool (currently 131), the deadlock should always trigger. Use an even higher number
+ // to be on the safe side.
+ const int objectCount = 1024;
+ SenderObject lotsOfObjects[objectCount];
+ for (int i = 0; i < objectCount; ++i) {
+ QObject::connect(&lotsOfObjects[i], &SenderObject::signal1,
+ &lotsOfObjects[i], &SenderObject::aPublicSlot);
+ }
+}
+
void tst_QObject::initTestCase()
{
const QString testDataDir = QFileInfo(QFINDTESTDATA("signalbug")).absolutePath();
@@ -1368,10 +1383,10 @@ struct CheckInstanceCount
struct CustomType
{
CustomType(int l1 = 0, int l2 = 0, int l3 = 0): i1(l1), i2(l2), i3(l3)
- { ++instanceCount; }
+ { ++instanceCount; playWithObjects(); }
CustomType(const CustomType &other): i1(other.i1), i2(other.i2), i3(other.i3)
- { ++instanceCount; }
- ~CustomType() { --instanceCount; }
+ { ++instanceCount; playWithObjects(); }
+ ~CustomType() { --instanceCount; playWithObjects(); }
int i1, i2, i3;
int value() { return i1 + i2 + i3; }
@@ -5749,17 +5764,7 @@ public:
{}
~MyFunctor() {
- // Do operations that will lock the internal signalSlotLock mutex on many QObjects.
- // The more QObjects, the higher the chance that the signalSlotLock mutex used
- // is already in use. If the number of objects is higher than the number of mutexes in
- // the pool (currently 131), the deadlock should always trigger. Use an even higher number
- // to be on the safe side.
- const int objectCount = 1024;
- SenderObject lotsOfObjects[objectCount];
- for (int i = 0; i < objectCount; ++i) {
- QObject::connect(&lotsOfObjects[i], &SenderObject::signal1,
- &lotsOfObjects[i], &SenderObject::aPublicSlot);
- }
+ playWithObjects();
}
void operator()() {
diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
index ce5e83288f..82f0a846bc 100644
--- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
+++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -114,7 +114,7 @@ private slots:
void uniqueKey();
protected:
- QString helperBinary();
+ static QString helperBinary();
int remove(const QString &key);
QString rememberKey(const QString &key)
@@ -131,10 +131,14 @@ protected:
QStringList keys;
QList<QSharedMemory*> jail;
QSharedMemory *existingSharedMemory;
+
+private:
+ const QString m_helperBinary;
};
-tst_QSharedMemory::tst_QSharedMemory() :
- existingSharedMemory(0)
+tst_QSharedMemory::tst_QSharedMemory()
+ : existingSharedMemory(0)
+ , m_helperBinary(tst_QSharedMemory::helperBinary())
{
}
@@ -144,7 +148,7 @@ tst_QSharedMemory::~tst_QSharedMemory()
void tst_QSharedMemory::initTestCase()
{
- QVERIFY2(!helperBinary().isEmpty(), "Could not find helper binary");
+ QVERIFY2(!m_helperBinary.isEmpty(), "Could not find helper binary");
}
void tst_QSharedMemory::init()
@@ -455,7 +459,7 @@ void tst_QSharedMemory::readOnly()
rememberKey("readonly_segfault");
// ### on windows disable the popup somehow
QProcess p;
- p.start(helperBinary(), QStringList("readonly_segfault"));
+ p.start(m_helperBinary, QStringList("readonly_segfault"));
p.setProcessChannelMode(QProcess::ForwardedChannels);
p.waitForFinished();
QCOMPARE(p.error(), QProcess::Crashed);
@@ -753,7 +757,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer()
rememberKey("market");
QProcess producer;
- producer.start(helperBinary(), QStringList("producer"));
+ producer.start(m_helperBinary, QStringList("producer"));
QVERIFY2(producer.waitForStarted(), "Could not start helper binary");
QVERIFY2(producer.waitForReadyRead(), "Helper process failed to create shared memory segment: " +
producer.readAllStandardError());
@@ -764,7 +768,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer()
for (int i = 0; i < processes; ++i) {
QProcess *p = new QProcess;
p->setProcessChannelMode(QProcess::ForwardedChannels);
- p->start(helperBinary(), consumerArguments);
+ p->start(m_helperBinary, consumerArguments);
if (p->waitForStarted(2000))
consumers.append(p);
else
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
index 5632bcacc4..c650041e1e 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
+++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
@@ -267,12 +267,12 @@ void tst_QSocketNotifier::posixSockets()
{
QSocketNotifier rn(posixSocket, QSocketNotifier::Read);
connect(&rn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QSignalSpy readSpy(&rn, SIGNAL(activated(int)));
+ QSignalSpy readSpy(&rn, &QSocketNotifier::activated);
QVERIFY(readSpy.isValid());
// No write notifier, some systems trigger write notification on socket creation, but not all
QSocketNotifier en(posixSocket, QSocketNotifier::Exception);
connect(&en, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QSignalSpy errorSpy(&en, SIGNAL(activated(int)));
+ QSignalSpy errorSpy(&en, &QSocketNotifier::activated);
QVERIFY(errorSpy.isValid());
passive->write("hello",6);
@@ -289,7 +289,7 @@ void tst_QSocketNotifier::posixSockets()
QSocketNotifier wn(posixSocket, QSocketNotifier::Write);
connect(&wn, SIGNAL(activated(int)), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QSignalSpy writeSpy(&wn, SIGNAL(activated(int)));
+ QSignalSpy writeSpy(&wn, &QSocketNotifier::activated);
QVERIFY(writeSpy.isValid());
qt_safe_write(posixSocket, "goodbye", 8);
diff --git a/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp b/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp
index 9e33f56a34..42f2709384 100644
--- a/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp
+++ b/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the test suite of the Qt Toolkit.
@@ -80,17 +80,20 @@ private slots:
#endif // QT_NO_PROCESS
private:
- QString helperBinary();
+ static QString helperBinary();
QSystemSemaphore *existingLock;
+
+ const QString m_helperBinary;
};
tst_QSystemSemaphore::tst_QSystemSemaphore()
+ : m_helperBinary(helperBinary())
{
}
void tst_QSystemSemaphore::initTestCase()
{
- QVERIFY2(!helperBinary().isEmpty(), "Could not find helper binary");
+ QVERIFY2(!m_helperBinary.isEmpty(), "Could not find helper binary");
}
void tst_QSystemSemaphore::init()
@@ -193,12 +196,12 @@ void tst_QSystemSemaphore::basicProcesses()
QProcess release;
release.setProcessChannelMode(QProcess::ForwardedChannels);
- acquire.start(helperBinary(), QStringList("acquire"));
+ acquire.start(m_helperBinary, QStringList("acquire"));
QVERIFY2(acquire.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
QVERIFY(acquire.state() == QProcess::Running);
acquire.kill();
- release.start(helperBinary(), QStringList("release"));
+ release.start(m_helperBinary, QStringList("release"));
QVERIFY2(release.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
release.waitForFinished(HELPERWAITTIME);
@@ -227,7 +230,7 @@ void tst_QSystemSemaphore::processes()
QProcess *p = new QProcess;
p->setProcessChannelMode(QProcess::ForwardedChannels);
consumers.append(p);
- p->start(helperBinary(), QStringList(scripts.at(i)));
+ p->start(m_helperBinary, QStringList(scripts.at(i)));
}
while (!consumers.isEmpty()) {
@@ -247,14 +250,14 @@ void tst_QSystemSemaphore::undo()
QStringList acquireArguments = QStringList("acquire");
QProcess acquire;
acquire.setProcessChannelMode(QProcess::ForwardedChannels);
- acquire.start(helperBinary(), acquireArguments);
+ acquire.start(m_helperBinary, acquireArguments);
QVERIFY2(acquire.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
QVERIFY(acquire.state()== QProcess::NotRunning);
// At process exit the kernel should auto undo
- acquire.start(helperBinary(), acquireArguments);
+ acquire.start(m_helperBinary, acquireArguments);
QVERIFY2(acquire.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
QVERIFY(acquire.state()== QProcess::NotRunning);
@@ -273,18 +276,18 @@ void tst_QSystemSemaphore::initialValue()
QProcess release;
release.setProcessChannelMode(QProcess::ForwardedChannels);
- acquire.start(helperBinary(), acquireArguments);
+ acquire.start(m_helperBinary, acquireArguments);
QVERIFY2(acquire.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
QVERIFY(acquire.state()== QProcess::NotRunning);
- acquire.start(helperBinary(), acquireArguments << QLatin1String("2"));
+ acquire.start(m_helperBinary, acquireArguments << QLatin1String("2"));
QVERIFY2(acquire.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
QVERIFY(acquire.state()== QProcess::Running);
acquire.kill();
- release.start(helperBinary(), releaseArguments);
+ release.start(m_helperBinary, releaseArguments);
QVERIFY2(release.waitForStarted(), "Could not start helper binary");
acquire.waitForFinished(HELPERWAITTIME);
release.waitForFinished(HELPERWAITTIME);
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index 27ea3faf81..31c627afcb 100644
--- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
+++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
@@ -77,6 +77,7 @@ private slots:
void cancelLongTimer();
void singleShotStaticFunctionZeroTimeout();
void recurseOnTimeoutAndStopTimer();
+ void singleShotToFunctors();
void dontBlockEvents();
void postedEventsShouldNotStarveTimers();
@@ -586,6 +587,14 @@ void tst_QTimer::singleShotStaticFunctionZeroTimeout()
QCOMPARE(helper.count, 1);
QTest::qWait(500);
QCOMPARE(helper.count, 1);
+
+ TimerHelper nhelper;
+
+ QTimer::singleShot(0, &nhelper, &TimerHelper::timeout);
+ QCoreApplication::processEvents();
+ QCOMPARE(nhelper.count, 1);
+ QCoreApplication::processEvents();
+ QCOMPARE(nhelper.count, 1);
}
class RecursOnTimeoutAndStopTimerTimer : public QObject
@@ -631,6 +640,96 @@ void tst_QTimer::recurseOnTimeoutAndStopTimer()
QVERIFY(!t.two->isActive());
}
+struct CountedStruct
+{
+ CountedStruct(int *count, QThread *t = Q_NULLPTR) : count(count), thread(t) { }
+ ~CountedStruct() { }
+ void operator()() const { ++(*count); if (thread) QCOMPARE(QThread::currentThread(), thread); }
+
+ int *count;
+ QThread *thread;
+};
+
+static QEventLoop _e;
+static QThread *_t = Q_NULLPTR;
+
+class StaticEventLoop
+{
+public:
+ static void quitEventLoop() { _e.quit(); if (_t) QCOMPARE(QThread::currentThread(), _t); }
+};
+
+void tst_QTimer::singleShotToFunctors()
+{
+ int count = 0;
+ QEventLoop e;
+
+ QTimer::singleShot(0, CountedStruct(&count));
+ QCoreApplication::processEvents();
+ QCOMPARE(count, 1);
+
+ QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
+ QCOMPARE(_e.exec(), 0);
+
+ QThread t1;
+ QObject c1;
+ c1.moveToThread(&t1);
+
+ QObject::connect(&t1, SIGNAL(started()), &e, SLOT(quit()));
+ t1.start();
+ QCOMPARE(e.exec(), 0);
+
+ QTimer::singleShot(0, &c1, CountedStruct(&count, &t1));
+ QTest::qWait(500);
+ QCOMPARE(count, 2);
+
+ t1.quit();
+ t1.wait();
+
+ _t = new QThread;
+ QObject c2;
+ c2.moveToThread(_t);
+
+ QObject::connect(_t, SIGNAL(started()), &e, SLOT(quit()));
+ _t->start();
+ QCOMPARE(e.exec(), 0);
+
+ QTimer::singleShot(0, &c2, &StaticEventLoop::quitEventLoop);
+ QCOMPARE(_e.exec(), 0);
+
+ _t->quit();
+ _t->wait();
+ _t->deleteLater();
+ _t = Q_NULLPTR;
+
+ {
+ QObject c3;
+ QTimer::singleShot(500, &c3, CountedStruct(&count));
+ }
+ QTest::qWait(800);
+ QCOMPARE(count, 2);
+
+#if defined(Q_COMPILER_LAMBDA)
+ QTimer::singleShot(0, [&count] { ++count; });
+ QCoreApplication::processEvents();
+ QCOMPARE(count, 3);
+
+ QObject context;
+ QThread thread;
+
+ context.moveToThread(&thread);
+ QObject::connect(&thread, SIGNAL(started()), &e, SLOT(quit()));
+ thread.start();
+ QCOMPARE(e.exec(), 0);
+
+ QTimer::singleShot(0, &context, [&count, &thread] { ++count; QCOMPARE(QThread::currentThread(), &thread); });
+ QTest::qWait(500);
+ QCOMPARE(count, 4);
+
+ thread.quit();
+ thread.wait();
+#endif
+}
class DontBlockEvents : public QObject
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index aef79e0c2f..660d0f804e 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -318,18 +318,16 @@ void tst_QVariant::constructor_invalid()
QFETCH(uint, typeId);
{
- MessageHandlerInvalidType msg;
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:"));
QVariant variant(static_cast<QVariant::Type>(typeId));
QVERIFY(!variant.isValid());
QVERIFY(variant.userType() == QMetaType::UnknownType);
- QVERIFY(msg.ok);
}
{
- MessageHandlerInvalidType msg;
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression("^Trying to construct an instance of an invalid type, type id:"));
QVariant variant(typeId, /* copy */ 0);
QVERIFY(!variant.isValid());
QVERIFY(variant.userType() == QMetaType::UnknownType);
- QVERIFY(msg.ok);
}
}