From 4b2db07b42dc0be28beafbd20d005cc0b7b11fc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pasi=20Pet=C3=A4j=C3=A4j=C3=A4rvi?= Date: Wed, 9 Sep 2015 15:45:18 +0300 Subject: Fix tst_QGuiApplication for embedded platforms using eglfs QPA Disable input and cursor for QGuiApplication instances used in autotest to initialize it properly. Change-Id: I78dc9b776269c082c20f244a51f858289129275d Reviewed-by: Laszlo Agocs --- tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp | 5 ----- 1 file changed, 5 deletions(-) (limited to 'tests/auto/corelib/kernel') diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp index efecf31d66..60e358232e 100644 --- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp +++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp @@ -41,12 +41,7 @@ #include #include -#ifdef QT_GUI_LIB -#include -typedef QGuiApplication TestApplication; -#else typedef QCoreApplication TestApplication; -#endif class EventSpy : public QObject { -- cgit v1.2.3 From a6ec869211d67fed94e3513dc453a96717155121 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Tue, 11 Aug 2015 13:23:32 +0300 Subject: Fix the spurious socket notifications under Windows To handle network events, QEventDispatcherWin32 uses I/O model based on notifications through the window message queue. Having successfully posted notification of a particular event to an application window, no further messages for that network event will be posted to the application window until the application makes the function call that implicitly re-enables notification of that network event. With these semantics, an application need not read all available data in response to an FD_READ message: a single recv in response to each FD_READ message is appropriate. If an application issues multiple recv calls in response to a single FD_READ, it can receive multiple FD_READ messages (including spurious). To solve this issue, this patch always disables the notifier after getting a notification, and re-enables it only when the message queue is empty. Task-number: QTBUG-46552 Change-Id: I05df67032911cd1f5927fa7912f7864bfbf8711e Reviewed-by: Joerg Bornemann --- .../kernel/qsocketnotifier/tst_qsocketnotifier.cpp | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'tests/auto/corelib/kernel') diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp index 930a17c3a9..f49da1f5a8 100644 --- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp +++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifndef Q_OS_WINRT #include #else @@ -66,8 +67,29 @@ private slots: #ifdef Q_OS_UNIX void posixSockets(); #endif + void asyncMultipleDatagram(); + +protected slots: + void async_readDatagramSlot(); + void async_writeDatagramSlot(); + +private: + QUdpSocket *m_asyncSender; + QUdpSocket *m_asyncReceiver; }; +static QHostAddress makeNonAny(const QHostAddress &address, + QHostAddress::SpecialAddress preferForAny = QHostAddress::LocalHost) +{ + if (address == QHostAddress::Any) + return preferForAny; + if (address == QHostAddress::AnyIPv4) + return QHostAddress::LocalHost; + if (address == QHostAddress::AnyIPv6) + return QHostAddress::LocalHostIPv6; + return address; +} + class UnexpectedDisconnectTester : public QObject { Q_OBJECT @@ -299,5 +321,56 @@ void tst_QSocketNotifier::posixSockets() } #endif +void tst_QSocketNotifier::async_readDatagramSlot() +{ + char buf[1]; + QVERIFY(m_asyncReceiver->hasPendingDatagrams()); + do { + QCOMPARE(m_asyncReceiver->pendingDatagramSize(), qint64(1)); + QCOMPARE(m_asyncReceiver->readDatagram(buf, sizeof(buf)), qint64(1)); + if (buf[0] == '1') { + // wait for the second datagram message. + QTest::qSleep(100); + } + } while (m_asyncReceiver->hasPendingDatagrams()); + + if (buf[0] == '3') + QTestEventLoop::instance().exitLoop(); +} + +void tst_QSocketNotifier::async_writeDatagramSlot() +{ + m_asyncSender->writeDatagram("3", makeNonAny(m_asyncReceiver->localAddress()), + m_asyncReceiver->localPort()); +} + +void tst_QSocketNotifier::asyncMultipleDatagram() +{ + m_asyncSender = new QUdpSocket; + m_asyncReceiver = new QUdpSocket; + + QVERIFY(m_asyncReceiver->bind(QHostAddress(QHostAddress::AnyIPv4), 0)); + quint16 port = m_asyncReceiver->localPort(); + QVERIFY(port != 0); + + QSignalSpy spy(m_asyncReceiver, &QIODevice::readyRead); + connect(m_asyncReceiver, &QIODevice::readyRead, this, + &tst_QSocketNotifier::async_readDatagramSlot); + m_asyncSender->writeDatagram("1", makeNonAny(m_asyncReceiver->localAddress()), port); + m_asyncSender->writeDatagram("2", makeNonAny(m_asyncReceiver->localAddress()), port); + // wait a little to ensure that the datagrams we've just sent + // will be delivered on receiver side. + QTest::qSleep(100); + + QTimer::singleShot(500, this, &tst_QSocketNotifier::async_writeDatagramSlot); + + QTestEventLoop::instance().enterLoop(1); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(spy.count(), 2); + + delete m_asyncSender; + delete m_asyncReceiver; +} + QTEST_MAIN(tst_QSocketNotifier) #include -- cgit v1.2.3 From a3a7d485fa2d572225c7050badf28784316aec37 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 30 Sep 2015 23:27:20 +0200 Subject: Fix crash in QMetaProperty::write for custom types and conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if t >= QMetaType::User, we would not return false nor call convert. We would then pass a pointer to whatever is in the QVariant to the qt_metacall that is expecting a pointer to an object of a different type. Since we have custom converters, we can call QVarent::convert even for custom types anyway. [ChangeLog][QtCore] Fixed crash when setting a QVariant of a different type to a property of a custom type. Attempt to do a conversion instead. Task-number: QTBUG-40644 Change-Id: Ib6fbd7e7ddcf25c5ee247ea04177e079f6d7de35 Reviewed-by: Jędrzej Nowacki --- .../kernel/qmetaproperty/tst_qmetaproperty.cpp | 45 +++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/kernel') diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index 4d54aa4dc8..10656a0dcd 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2015 The Qt Company Ltd. -** Copyright (C) 2014 Olivier Goffart +** Copyright (C) 2015 Olivier Goffart ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -38,15 +38,29 @@ #include #include +struct CustomType +{ + int padding; + QString str; + CustomType(const QString &str = QString()) : str(str) {} + operator QString() const { return str; } + friend bool operator!=(const CustomType &a, const CustomType &b) + { return a.str != b.str; } +}; + +Q_DECLARE_METATYPE(CustomType) + class tst_QMetaProperty : public QObject { Q_OBJECT Q_PROPERTY(EnumType value WRITE setValue READ getValue) Q_PROPERTY(EnumType value2 WRITE set_value READ get_value) + Q_PROPERTY(QString value7 MEMBER value7) Q_PROPERTY(int value8 READ value8) Q_PROPERTY(int value9 READ value9 CONSTANT) Q_PROPERTY(int value10 READ value10 FINAL) Q_PROPERTY(QMap map MEMBER map) + Q_PROPERTY(CustomType custom MEMBER custom) private slots: void hasStdCppSet(); @@ -55,6 +69,7 @@ private slots: void gadget(); void readAndWriteWithLazyRegistration(); void mapProperty(); + void conversion(); public: enum EnumType { EnumType1 }; @@ -68,7 +83,9 @@ public: int value9() const { return 1; } int value10() const { return 1; } + QString value7; QMap map; + CustomType custom; }; void tst_QMetaProperty::hasStdCppSet() @@ -195,5 +212,31 @@ void tst_QMetaProperty::mapProperty() QCOMPARE(map, (v.value >())); } +void tst_QMetaProperty::conversion() +{ + QMetaType::registerConverter(); + QMetaType::registerConverter(); + + QString hello = QStringLiteral("Hello"); + + // Write to a QString property using a CustomType in a QVariant + QMetaProperty value7P = metaObject()->property(metaObject()->indexOfProperty("value7")); + QVERIFY(value7P.isValid()); + QVERIFY(value7P.write(this, QVariant::fromValue(CustomType(hello)))); + QCOMPARE(value7, hello); + + // Write to a CustomType property using a QString in a QVariant + QMetaProperty customP = metaObject()->property(metaObject()->indexOfProperty("custom")); + QVERIFY(customP.isValid()); + QVERIFY(customP.write(this, hello)); + QCOMPARE(custom.str, hello); + + // Something that cannot be converted should fail + QVERIFY(!customP.write(this, 45)); + QVERIFY(!customP.write(this, QVariant::fromValue(this))); + QVERIFY(!value7P.write(this, QVariant::fromValue(this))); + QVERIFY(!value7P.write(this, QVariant::fromValue(this))); +} + QTEST_MAIN(tst_QMetaProperty) #include "tst_qmetaproperty.moc" -- cgit v1.2.3 From de70798859e0363c8ca3133a4ed1a1092cfe47f5 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 6 Oct 2015 10:14:26 +0200 Subject: QMetaProperty::write should reset the property if an empty QVariant is given MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [ChangeLog][QtCore][QMetaProperty] write() now resets the property if an empty QVariant is given, or set a default constructed object if the property is not resettable Change-Id: I9f9b57114e740f03ec4db6f223c1e8280a3d5209 Reviewed-by: Jędrzej Nowacki Reviewed-by: Oswald Buddenhagen --- .../corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp | 14 +++++++++++++- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'tests/auto/corelib/kernel') diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp index 10656a0dcd..22c78f8e48 100644 --- a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp +++ b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp @@ -55,7 +55,7 @@ class tst_QMetaProperty : public QObject Q_OBJECT Q_PROPERTY(EnumType value WRITE setValue READ getValue) Q_PROPERTY(EnumType value2 WRITE set_value READ get_value) - Q_PROPERTY(QString value7 MEMBER value7) + Q_PROPERTY(QString value7 MEMBER value7 RESET resetValue7) Q_PROPERTY(int value8 READ value8) Q_PROPERTY(int value9 READ value9 CONSTANT) Q_PROPERTY(int value10 READ value10 FINAL) @@ -79,6 +79,7 @@ public: void set_value(EnumType) {} EnumType get_value() const { return EnumType1; } + void resetValue7() { value7 = QStringLiteral("reset"); } int value8() const { return 1; } int value9() const { return 1; } int value10() const { return 1; } @@ -236,6 +237,17 @@ void tst_QMetaProperty::conversion() QVERIFY(!customP.write(this, QVariant::fromValue(this))); QVERIFY(!value7P.write(this, QVariant::fromValue(this))); QVERIFY(!value7P.write(this, QVariant::fromValue(this))); + + // none of this should have changed the values + QCOMPARE(value7, hello); + QCOMPARE(custom.str, hello); + + // Empty variant should be converted to default object + QVERIFY(customP.write(this, QVariant())); + QCOMPARE(custom.str, QString()); + // or reset resetable + QVERIFY(value7P.write(this, QVariant())); + QCOMPARE(value7, QLatin1Literal("reset")); } QTEST_MAIN(tst_QMetaProperty) diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 4617ce5e74..a3c6d8e9df 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -1925,7 +1925,7 @@ void tst_QObject::property() QCOMPARE(object.property("string"), QVariant("String1")); QVERIFY(object.setProperty("string", "String2")); QCOMPARE(object.property("string"), QVariant("String2")); - QVERIFY(!object.setProperty("string", QVariant())); + QVERIFY(object.setProperty("string", QVariant())); const int idx = mo->indexOfProperty("variant"); QVERIFY(idx != -1); @@ -2027,7 +2027,7 @@ void tst_QObject::property() QCOMPARE(object.property("customString"), QVariant("String1")); QVERIFY(object.setProperty("customString", "String2")); QCOMPARE(object.property("customString"), QVariant("String2")); - QVERIFY(!object.setProperty("customString", QVariant())); + QVERIFY(object.setProperty("customString", QVariant())); } void tst_QObject::metamethod() -- cgit v1.2.3 From a623fe8d2a60ff333d5779f877e3b20f0e141ff1 Mon Sep 17 00:00:00 2001 From: Juha Turunen Date: Sun, 11 Oct 2015 20:29:51 -0700 Subject: Fixed a QTimer::singleShot() crash when a functor callback is used If QTimer::singleShot() is used with a functor callback and a context object with different thread affinity than the caller, a crash can occur. If the context object's thread is scheduled before connecting to QCoreApplication::aboutToQuit(), the timer has a change to fire and QSingleShotTimer::timerEvent() will delete the QSingleShotTimer object making the this pointer used in the connection invalid. This can occur relatively often if an interval of 0 is used. Making the moveToThread() call the last thing in the constructor ensures that the constructor gets to run to completion before the timer has a chance to fire. Task-number: QTBUG-48700 Change-Id: Iab73d02933635821b8d1ca1ff3d53e92eca85834 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/auto/corelib/kernel') diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 1dc358bd97..b34a3a6beb 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -72,6 +72,7 @@ private slots: void singleShotStaticFunctionZeroTimeout(); void recurseOnTimeoutAndStopTimer(); void singleShotToFunctors(); + void crossThreadSingleShotToFunctor(); void dontBlockEvents(); void postedEventsShouldNotStarveTimers(); @@ -877,5 +878,28 @@ void tst_QTimer::postedEventsShouldNotStarveTimers() QVERIFY(timerHelper.count > 5); } +struct DummyFunctor { + void operator()() {} +}; + +void tst_QTimer::crossThreadSingleShotToFunctor() +{ + // We're testing for crashes here, so the test simply running to + // completion is considered a success + QThread t; + t.start(); + + QObject* o = new QObject(); + o->moveToThread(&t); + + for (int i = 0; i < 10000; i++) { + QTimer::singleShot(0, o, DummyFunctor()); + } + + t.quit(); + t.wait(); + delete o; +} + QTEST_MAIN(tst_QTimer) #include "tst_qtimer.moc" -- cgit v1.2.3