summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@theqtcompany.com>2015-10-14 15:45:35 +0200
committerLiang Qi <liang.qi@theqtcompany.com>2015-10-14 15:45:35 +0200
commit4456984da780b14572e1ec0f079a4d349ab299bd (patch)
treef586a281a81c57c91c49e83a5d3ec6c7eece0578 /tests/auto/corelib/kernel
parente824abd987d77efaa085fe1f9fb514d270798d55 (diff)
parent281121697340084f7d385eab530f41916789b94d (diff)
Merge remote-tracking branch 'origin/5.6' into dev
Conflicts: tests/auto/corelib/io/qfile/tst_qfile.cpp tests/auto/corelib/io/qprocess/tst_qprocess.cpp tests/auto/corelib/tools/qversionnumber/qversionnumber.pro Change-Id: Ia93ce500349d96a2fbf0b4a37b73f088cc505c6e
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp5
-rw-r--r--tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp57
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp4
-rw-r--r--tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp73
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp24
5 files changed, 155 insertions, 8 deletions
diff --git a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
index a0cadc9a2f..b889d61786 100644
--- a/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
+++ b/tests/auto/corelib/kernel/qcoreapplication/tst_qcoreapplication.cpp
@@ -41,12 +41,7 @@
#include <private/qeventloop_p.h>
#include <private/qthread_p.h>
-#ifdef QT_GUI_LIB
-#include <QtGui/QGuiApplication>
-typedef QGuiApplication TestApplication;
-#else
typedef QCoreApplication TestApplication;
-#endif
class EventSpy : public QObject
{
diff --git a/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp b/tests/auto/corelib/kernel/qmetaproperty/tst_qmetaproperty.cpp
index 4d54aa4dc8..22c78f8e48 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 <ogoffart@woboq.com>
+** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -38,15 +38,29 @@
#include <qobject.h>
#include <qmetaobject.h>
+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 RESET resetValue7)
Q_PROPERTY(int value8 READ value8)
Q_PROPERTY(int value9 READ value9 CONSTANT)
Q_PROPERTY(int value10 READ value10 FINAL)
Q_PROPERTY(QMap<int, int> 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 };
@@ -64,11 +79,14 @@ 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; }
+ QString value7;
QMap<int, int> map;
+ CustomType custom;
};
void tst_QMetaProperty::hasStdCppSet()
@@ -195,5 +213,42 @@ void tst_QMetaProperty::mapProperty()
QCOMPARE(map, (v.value<QMap<int,int> >()));
}
+void tst_QMetaProperty::conversion()
+{
+ QMetaType::registerConverter<QString, CustomType>();
+ QMetaType::registerConverter<CustomType, QString>();
+
+ 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<QObject*>(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)
#include "tst_qmetaproperty.moc"
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 3661db071b..90f7780344 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()
diff --git a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
index d0eb10d3aa..30ce65849d 100644
--- a/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
+++ b/tests/auto/corelib/kernel/qsocketnotifier/tst_qsocketnotifier.cpp
@@ -40,6 +40,7 @@
#include <QtCore/QSocketNotifier>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
+#include <QtNetwork/QUdpSocket>
#ifndef Q_OS_WINRT
#include <private/qnativesocketengine_p.h>
#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 <tst_qsocketnotifier.moc>
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index 064f780546..c17d81ea9e 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"