From 285596ee199ae1767fc48a0d0c2d12b178c0234d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 9 Nov 2017 21:13:43 +0100 Subject: Special-case parsing of Zulu time-zone in date-times When parsing a date-time's zone, a stray Z denotes UTC (a.k.a. Zulu time), despite not being a valid name for the zone. Clients parsing such date strings had to treat the Z as a literal, rather than a zone-ID, but then they got back a LocalTime instead of the UTC the string actually described. So teach QTimeZoneParser to handle this special case and adapt an existing test (that used a time ending in Z, but had to treat it as a local time) to check this works. [ChangeLog][QtCore][QDateTime] When parsing a time-zone, "Z" is now recognized as an alias for UTC. Change-Id: Ib6aa2d8ea2dc6b2da526b39aec74dbc007f90fd8 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index c0ed88e154..7a047c67de 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -2396,8 +2396,8 @@ void tst_QDateTime::fromStringStringFormat_data() QTest::newRow("data14") << QString("32.01.2004") << QString("dd.MM.yyyy") << invalidDateTime(); QTest::newRow("data15") << QString("Thu January 2004") << QString("ddd MMMM yyyy") << QDateTime(QDate(2004, 1, 1), QTime()); QTest::newRow("data16") << QString("2005-06-28T07:57:30.001Z") - << QString("yyyy-MM-ddThh:mm:ss.zZ") - << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1)); + << QString("yyyy-MM-ddThh:mm:ss.zt") + << QDateTime(QDate(2005, 06, 28), QTime(07, 57, 30, 1), Qt::UTC); } void tst_QDateTime::fromStringStringFormat() -- cgit v1.2.3 From 4be50ecafd3cc63469504aaae8ac28ff0736989d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 7 Nov 2017 14:08:54 -0800 Subject: QTemporaryFile: fix issues with removing a file twice The assertion in isUnnamedFile() we had was incorrect after the file was removed, since we cleared the name and possibly reset back to the template. Since ~QTemporaryFile() calls remove(), this was easy to trigger if you attempted to remove the temp file and leave QTemporaryFile like that. Take this opportunity to add to the docs of setAutoRemove() explaining the possibility of unnamed files. #7 0x00007f69bcc2b50e in qt_assert ( assertion=assertion@entry=0x7f69bcf194a0 "unnamedFile == d_func()->fileEntry.isEmpty()", file=file@entry=0x7f69bcf19458 "io/qtemporaryfile.cpp", line=line@entry=514) at global/qglobal.cpp:3123 #8 0x00007f69bcd672cf in QTemporaryFileEngine::isUnnamedFile (this=this@entry=0x55cd60644df0) at io/qtemporaryfile.cpp:514 #9 0x00007f69bcd683f7 in QTemporaryFileEngine::remove (this=0x55cd60644df0) at io/qtemporaryfile.cpp:396 #10 0x00007f69bcd48654 in QFile::remove (this=this@entry=0x7fffb393f7e0) at io/qfile.cpp:513 #11 0x00007f69bcd6653b in QTemporaryFile::~QTemporaryFile (this=0x7fffb393f7e0, __in_chrg=) at io/qtemporaryfile.cpp:719 Change-Id: I57a1bd6e0c194530b732fffd14f4ed28ca8185b2 Reviewed-by: Andreas Hartmetz Reviewed-by: Thiago Macieira --- .../corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index f3ce902bbd..2d87c2193b 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -70,6 +70,7 @@ private slots: void io(); void openCloseOpenClose(); void removeAndReOpen(); + void removeUnnamed(); void size(); void resize(); void openOnRootDrives(); @@ -442,11 +443,13 @@ void tst_QTemporaryFile::removeAndReOpen() { QTemporaryFile file; file.open(); - fileName = file.fileName(); + fileName = file.fileName(); // materializes any unnamed file QVERIFY(QFile::exists(fileName)); - file.remove(); + QVERIFY(file.remove()); + QVERIFY(file.fileName().isEmpty()); QVERIFY(!QFile::exists(fileName)); + QVERIFY(!file.remove()); QVERIFY(file.open()); QCOMPARE(QFileInfo(file.fileName()).path(), QFileInfo(fileName).path()); @@ -456,6 +459,19 @@ void tst_QTemporaryFile::removeAndReOpen() QVERIFY(!QFile::exists(fileName)); } +void tst_QTemporaryFile::removeUnnamed() +{ + QTemporaryFile file; + file.open(); + + // we did not call fileName(), so the file name may not have a name + QVERIFY(file.remove()); + QVERIFY(file.fileName().isEmpty()); + + // if it was unnamed, this will succeed again, so we can't check the result + file.remove(); +} + void tst_QTemporaryFile::size() { QTemporaryFile file; -- cgit v1.2.3 From 150e5055251ae9a5c40d821d377e72b14e38868d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 26 Nov 2017 23:01:57 -0800 Subject: Stop depending on test.macieira.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have had test.qt-project.org for close to 3 years now. Change-Id: I71488efd29b645f7b228fffd14fadf4627288243 Reviewed-by: Jędrzej Nowacki (cherry picked from commit 5f66f871816d083da9795d71f746413d6f6118f7) Reviewed-by: Frederik Gladhorn --- .../auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp | 4 ++-- tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp b/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp index 7874221da9..e302fe8c74 100644 --- a/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp +++ b/tests/auto/network/kernel/qdnslookup_appless/tst_qdnslookup_appless.cpp @@ -43,7 +43,7 @@ private slots: void tst_QDnsLookup_Appless::noApplication() { QTest::ignoreMessage(QtWarningMsg, "QDnsLookup requires a QCoreApplication"); - QDnsLookup dns(QDnsLookup::A, "a-single.test.macieira.org"); + QDnsLookup dns(QDnsLookup::A, "a-single.test.qt-project.org"); dns.lookup(); } @@ -53,7 +53,7 @@ void tst_QDnsLookup_Appless::recreateApplication() char **argv = 0; for (int i = 0; i < 10; ++i) { QCoreApplication app(argc, argv); - QDnsLookup dns(QDnsLookup::A, "a-single.test.macieira.org"); + QDnsLookup dns(QDnsLookup::A, "a-single.test.qt-project.org"); dns.lookup(); if (!dns.isFinished()) { QObject::connect(&dns, SIGNAL(finished()), diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp index f5f5146eb5..82825f608c 100644 --- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp +++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp @@ -72,7 +72,7 @@ #include "../../../network-settings.h" -#define TEST_DOMAIN ".test.macieira.org" +#define TEST_DOMAIN ".test.qt-project.org" class tst_QHostInfo : public QObject -- cgit v1.2.3 From 275c748ada9d869d803d5f446b48b915d686ab33 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 28 Aug 2017 16:28:03 +0200 Subject: Fix naming of new property QSortFilterProxyModel::recursiveFiltering Add "Enabled" to match Qt API naming rules. + fix \since tag. Change-Id: Iaf312648f7385cd7e8d3d101b561fbd4e955df25 Reviewed-by: Friedemann Kleint Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira Reviewed-by: Lars Knoll --- .../tst_qsortfilterproxymodel_recursive.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_recursive/tst_qsortfilterproxymodel_recursive.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_recursive/tst_qsortfilterproxymodel_recursive.cpp index 54c79e0893..9cf005af01 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel_recursive/tst_qsortfilterproxymodel_recursive.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel_recursive/tst_qsortfilterproxymodel_recursive.cpp @@ -100,7 +100,7 @@ public: TestModel(QAbstractItemModel *sourceModel) : QSortFilterProxyModel() { - setRecursiveFiltering(true); + setRecursiveFilteringEnabled(true); setSourceModel(sourceModel); } @@ -213,6 +213,7 @@ private Q_SLOTS: QCOMPARE(treeAsString(model), sourceStr); TestModel proxy(&model); + QVERIFY(proxy.isRecursiveFilteringEnabled()); QCOMPARE(treeAsString(proxy), proxyStr); } -- cgit v1.2.3 From 984ad6124992c9831f57c2776aa2ed0a760149e6 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 10 Oct 2017 09:42:41 +0200 Subject: Improve readability of code that uses the Qt signed size type During the container BoF session at the Qt Contributor Summit 2017 the name of the signed size type became a subject of discussion in the context of readability of code using this type and the intention of using it for all length, size and count properties throughout the entire framework in future versions of Qt. This change proposes qsizetype as new name for qssize_t to emphasize the readability of code over POSIX compatibility, the former being potentially more relevant than the latter to the majority of users of Qt. Change-Id: Idb99cb4a8782703c054fa463a9e5af23a918e7f3 Reviewed-by: Samuel Gaist Reviewed-by: David Faure --- tests/auto/corelib/tools/qstringview/tst_qstringview.cpp | 4 ++-- tests/auto/gui/image/qimage/tst_qimage.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp index 4174b85f4c..8a8aa8c6e1 100644 --- a/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp +++ b/tests/auto/corelib/tools/qstringview/tst_qstringview.cpp @@ -461,9 +461,9 @@ void tst_QStringView::fromLiteral(const Char *arg) const const Char *null = nullptr; const Char empty[] = { 0 }; - QCOMPARE(QStringView(null).size(), qssize_t(0)); + QCOMPARE(QStringView(null).size(), qsizetype(0)); QCOMPARE(QStringView(null).data(), nullptr); - QCOMPARE(QStringView(empty).size(), qssize_t(0)); + QCOMPARE(QStringView(empty).size(), qsizetype(0)); QCOMPARE(static_cast(QStringView(empty).data()), static_cast(empty)); diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 54eb8ab99c..7ad4a9e9bb 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -3441,10 +3441,10 @@ void tst_QImage::hugeQImage() QVERIFY(!image.isNull()); QCOMPARE(image.height(), 25000); QCOMPARE(image.width(), 25000); - QCOMPARE(image.sizeInBytes(), qssize_t(25000)*25000*4); + QCOMPARE(image.sizeInBytes(), qsizetype(25000)*25000*4); QCOMPARE(image.bytesPerLine(), 25000 * 4); - QCOMPARE(image.constScanLine(24990), image.constBits() + qssize_t(25000)*24990*4); + QCOMPARE(image.constScanLine(24990), image.constBits() + qsizetype(25000)*24990*4); image.setPixel(20000, 24990, 0xffaabbcc); QCOMPARE(image.pixel(20000, 24990), 0xffaabbcc); -- cgit v1.2.3 From 67391f0a572ddc9c53bdff35dac893b07a862fe5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 22 Nov 2017 01:05:52 +0100 Subject: Fix aliasing problem in QVector::removeAll() Since removeAll() takes its argument by cref, if passing a reference to an element of the container to removeAll(), the element may be deleted (overwritten) by anyother value, leading to UB. Add a test that actually happens to fail for me without the patch, even though that might not be guaranteed (we may invoke UB). Change-Id: If8c795113aeb515f4a9bdf1e072395b932295667 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qvector/tst_qvector.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp index 374fec221e..6975452d76 100644 --- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp +++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp @@ -245,6 +245,7 @@ private slots: void qhashInt() const { qhash(); } void qhashMovable() const { qhash(); } void qhashCustom() const { qhash(); } + void removeAllWithAlias() const; void removeInt() const; void removeMovable() const; void removeCustom() const; @@ -1722,6 +1723,13 @@ void tst_QVector::prependCustom() const QCOMPARE(instancesCount, Custom::counter.loadAcquire()); } +void tst_QVector::removeAllWithAlias() const +{ + QVector strings; + strings << "One" << "Two" << "Three" << "One" /* must be distinct, but equal */; + QCOMPARE(strings.removeAll(strings.front()), 2); // will trigger asan/ubsan +} + template void tst_QVector::remove() const { -- cgit v1.2.3 From bc9941db42172b7f55c69bad27a7b6ae378f4e4a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 29 Nov 2017 14:17:58 +0100 Subject: tst_QNetworkReply: Blacklist putToFtpWithInvalidCredentials for Windows Task-number: QTBUG-62860 Change-Id: Ibf4d7de9eedc2236375ad10ca4bea08055c7ae00 Reviewed-by: Timur Pocheptsov --- tests/auto/network/access/qnetworkreply/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkreply/BLACKLIST b/tests/auto/network/access/qnetworkreply/BLACKLIST index 57f33d5863..d4c83bc40b 100644 --- a/tests/auto/network/access/qnetworkreply/BLACKLIST +++ b/tests/auto/network/access/qnetworkreply/BLACKLIST @@ -32,6 +32,8 @@ linux windows [putToFtp] windows ci +[putToFtpWithInvalidCredentials] +windows ci [putWithServerClosingConnectionImmediately] windows [qtbug28035browserDoesNotLoadQtProjectOrgCorrectly] -- cgit v1.2.3 From 58b70c2f1acedad0df6b4de1acf3dea2011e369c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 20 Nov 2017 16:16:55 +0100 Subject: tst_QFileSystemModel: Stabilize readOnly(), sortPersistentIndex() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The tests start to show flakyness on Linux in 5.10 (rowCount() check failing). This seems to point to a race condition between the files showing up and the file system watchers of QFileSystemModel starting. To fix this, close the file and wait until it shows up in the directory before pointing the QFileSystemModel to it. The tests then no longer rely on the file system watchers. Change-Id: I39cffb4cacf6843e8e4180efb405345307c78dd8 Reviewed-by: Jędrzej Nowacki --- .../dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index 31df66e312..979d5c632e 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -239,13 +239,18 @@ void tst_QFileSystemModel::readOnly() QCOMPARE(model->isReadOnly(), true); QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); QVERIFY2(file.open(), qPrintable(file.errorString())); + const QString fileName = file.fileName(); + file.close(); + + const QFileInfo fileInfo(fileName); + QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo)); QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); - QVERIFY(!(model->flags(model->index(file.fileName())) & Qt::ItemIsEditable)); + QVERIFY(!(model->flags(model->index(fileName)) & Qt::ItemIsEditable)); model->setReadOnly(false); QCOMPARE(model->isReadOnly(), false); - QVERIFY(model->flags(model->index(file.fileName())) & Qt::ItemIsEditable); + QVERIFY(model->flags(model->index(fileName)) & Qt::ItemIsEditable); } class CustomFileIconProvider : public QFileIconProvider @@ -729,6 +734,9 @@ void tst_QFileSystemModel::sortPersistentIndex() { QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); QVERIFY2(file.open(), qPrintable(file.errorString())); + const QFileInfo fileInfo(file.fileName()); + file.close(); + QTRY_VERIFY(QDir(flatDirTestPath).entryInfoList().contains(fileInfo)); QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); -- cgit v1.2.3 From 0ebf0cfb6f2e21ceef4f95b54a4a02abd7214dc1 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 21 Nov 2017 08:54:03 +0100 Subject: Blacklist tst_QSplitter::replaceWidget(visible, not collapsed) for Linux The test is flaky on Linux. Task-number: QTBUG-64639 Change-Id: Iec56ebce4f656f52187b34c8f655b137e41c3d17 Reviewed-by: Richard Moe Gustavsen Reviewed-by: Gabriel de Dietrich --- tests/auto/widgets/widgets/qsplitter/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 tests/auto/widgets/widgets/qsplitter/BLACKLIST (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qsplitter/BLACKLIST b/tests/auto/widgets/widgets/qsplitter/BLACKLIST new file mode 100644 index 0000000000..1352805cd7 --- /dev/null +++ b/tests/auto/widgets/widgets/qsplitter/BLACKLIST @@ -0,0 +1,2 @@ +[replaceWidget:visible, not collapsed] +xcb -- cgit v1.2.3 From bfef7d12249717555f6d81b54f748d9df10974e9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 23 Nov 2017 09:48:43 +0100 Subject: tests/auto/auto.pro: Use correct null device for DBUS check A mysterious file c:\dev\null appeared when running the auto tests on Windows. Fix by using QMAKE_SYSTEM_NULL_DEVICE. Amends 5f3529be32df3cce81e77c3dbb76cfda7feb320c. Change-Id: I0224a9ccd61c4f10b2ddb8f8d690e1849aa88d8a Reviewed-by: Oswald Buddenhagen --- tests/auto/auto.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index a1ffe5b3ce..fbd89e4045 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -35,7 +35,7 @@ else:!qtConfig(process): SUBDIRS -= tools # Disable the QtDBus tests if we can't connect to the session bus !cross_compile:qtHaveModule(dbus) { - !system("dbus-send --session --type=signal / local.AutotestCheck.Hello >/dev/null 2>&1") { + !system("dbus-send --session --type=signal / local.AutotestCheck.Hello >$$QMAKE_SYSTEM_NULL_DEVICE 2>&1") { qtConfig(dbus-linked): \ error("QtDBus is enabled but session bus is not available. Please check the installation.") else: \ -- cgit v1.2.3 From 6d09db53f7b5161d865f0fe8f832aa3757d66f74 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 30 Oct 2017 09:13:32 +0100 Subject: macOS: Blacklist tst_QPauseAnimation::noTimerUpdates() Task-number: QTBUG-64107 Change-Id: Ie77d2d2525e79fb7e17f1a69d15ef40982f9242d Reviewed-by: Jesus Fernandez --- tests/auto/corelib/animation/qpauseanimation/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qpauseanimation/BLACKLIST b/tests/auto/corelib/animation/qpauseanimation/BLACKLIST index 8fc1b07502..a49ed2a617 100644 --- a/tests/auto/corelib/animation/qpauseanimation/BLACKLIST +++ b/tests/auto/corelib/animation/qpauseanimation/BLACKLIST @@ -4,3 +4,5 @@ osx-10.9 * [multipleSequentialGroups] osx +[noTimerUpdates] +osx -- cgit v1.2.3 From 92cd3bfa2ebe133651b3d9f4e0c3394bbe79ba6a Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 30 Oct 2017 09:14:27 +0100 Subject: macOS: Blacklist: tst_QPropertyAnimation::startWithoutStartValue() Task-number: QTBUG-64108 Change-Id: Id60a9a1bfede9cbe90f378d131a331d726acfdae Reviewed-by: Jesus Fernandez --- tests/auto/corelib/animation/qpropertyanimation/BLACKLIST | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST b/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST index a7e95b1e97..a8719b241a 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST +++ b/tests/auto/corelib/animation/qpropertyanimation/BLACKLIST @@ -2,3 +2,5 @@ windows [startBackwardWithoutEndValue] windows +[startWithoutStartValue] +osx -- cgit v1.2.3 From 0c9e379dd8c57fab9d8e6ba8d35a0dca8ac05a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Arve=20S=C3=A6ther?= Date: Fri, 1 Dec 2017 11:19:28 +0100 Subject: Use a custom QAnimationDriver to take control over time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should reduce flakyness of tests. Change-Id: I26e0a97f7cd3e7cee2ffb44188300c37578cddd7 Reviewed-by: Jędrzej Nowacki --- .../qpropertyanimation/qpropertyanimation.pro | 2 +- .../qpropertyanimation/tst_qpropertyanimation.cpp | 235 ++++++++++++++------- 2 files changed, 163 insertions(+), 74 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro b/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro index bfeb183abf..72a36876b7 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro +++ b/tests/auto/corelib/animation/qpropertyanimation/qpropertyanimation.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qpropertyanimation -QT = core gui widgets testlib +QT = core gui widgets testlib core-private SOURCES = tst_qpropertyanimation.cpp diff --git a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp index cf4c4e1bdb..41a051a719 100644 --- a/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp +++ b/tests/auto/corelib/animation/qpropertyanimation/tst_qpropertyanimation.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,80 @@ public: MyObject o; }; +class TestAnimationDriver : public QAnimationDriver +{ +public: + TestAnimationDriver() + : QAnimationDriver() + , m_elapsed(0) + { + QUnifiedTimer::instance()->installAnimationDriver(this); + } + + ~TestAnimationDriver() + { + // This is to ensure that running animations are removed from the list of actual running + // animations. + QCoreApplication::sendPostedEvents(); + QUnifiedTimer::instance()->uninstallAnimationDriver(this); + } + + void wait(qint64 ms) + { + /* + * When QAbstractAnimation::start() is called it will end up calling + * QAnimationTimer::registerAnimation(). This will do + * + * QMetaObject::invokeMethod(inst, "startAnimations", Qt::QueuedConnection); // typeof(inst) == QAnimationTimer + * + * startAnimations() will again fire a queued connection to actually add the animation + * to the list of running animations: + * + * QMetaObject::invokeMethod(inst, "startTimers", Qt::QueuedConnection); // typeof(inst) == QUnifiedTimer + * + * We therefore have to call QCoreApplication::sendPostedEvents() twice here. + */ + QCoreApplication::sendPostedEvents(); + QCoreApplication::sendPostedEvents(); + + // Simulates the ideal animation update freqency (approx. 60Hz) + static const int interval = 1000/60; + qint64 until = m_elapsed + ms; + while (m_elapsed < until) { + advanceAnimation(m_elapsed); + m_elapsed += interval; + } + advanceAnimation(m_elapsed); + // This is to make sure that animations that were started with DeleteWhenStopped + // will actually delete themselves within the test function. + // Normally, they won't be deleted until the main event loop is processed. + // Therefore, have to explicitly say that we want to process DeferredDelete events. Same + // trick is used by QTest::qWait(). + QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); + } + + qint64 elapsed() const override + { + return m_elapsed; + } + + void start() override + { + d_func()->running = true; + m_elapsed = 0; + emit started(); + } + + void stop() override + { + d_func()->running = false; + emit stopped(); + } + +private: + qint64 m_elapsed; + Q_DECLARE_PRIVATE(QAnimationDriver) +}; class tst_QPropertyAnimation : public QObject { @@ -261,40 +336,44 @@ void tst_QPropertyAnimation::statesAndSignals() QCOMPARE(currentLoopSpy.count(), 2); runningSpy.clear(); - anim->start(); - QTest::qWait(1000); - QTRY_COMPARE(anim->state(), QAnimationGroup::Stopped); - QCOMPARE(runningSpy.count(), 2); //started and stopped again - runningSpy.clear(); - QCOMPARE(finishedSpy.count(), 1); - QCOMPARE(anim->currentLoopTime(), 100); - QCOMPARE(anim->currentLoop(), 2); - QCOMPARE(currentLoopSpy.count(), 4); - - anim->start(); // auto-rewinds - QCOMPARE(anim->state(), QAnimationGroup::Running); - QCOMPARE(anim->currentTime(), 0); - QCOMPARE(anim->currentLoop(), 0); - QCOMPARE(currentLoopSpy.count(), 5); - QCOMPARE(runningSpy.count(), 1); // anim has started - QCOMPARE(finishedSpy.count(), 1); - QCOMPARE(anim->currentLoop(), 0); - runningSpy.clear(); - - QTest::qWait(1000); - - QCOMPARE(currentLoopSpy.count(), 7); - QCOMPARE(anim->state(), QAnimationGroup::Stopped); - QCOMPARE(anim->currentLoop(), 2); - QCOMPARE(runningSpy.count(), 1); // anim has stopped - QCOMPARE(finishedSpy.count(), 2); - QCOMPARE(anim->currentLoopTime(), 100); - - delete anim; + { + TestAnimationDriver timeDriver; + anim->start(); + timeDriver.wait(1000); + QCOMPARE(anim->state(), QAnimationGroup::Stopped); + QCOMPARE(runningSpy.count(), 2); //started and stopped again + runningSpy.clear(); + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(anim->currentLoopTime(), 100); + QCOMPARE(anim->currentLoop(), 2); + QCOMPARE(currentLoopSpy.count(), 4); + + anim->start(); // auto-rewinds + QCOMPARE(anim->state(), QAnimationGroup::Running); + QCOMPARE(anim->currentTime(), 0); + QCOMPARE(anim->currentLoop(), 0); + QCOMPARE(currentLoopSpy.count(), 5); + QCOMPARE(runningSpy.count(), 1); // anim has started + QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(anim->currentLoop(), 0); + runningSpy.clear(); + + timeDriver.wait(1000); + + QCOMPARE(currentLoopSpy.count(), 7); + QCOMPARE(anim->state(), QAnimationGroup::Stopped); + QCOMPARE(anim->currentLoop(), 2); + QCOMPARE(runningSpy.count(), 1); // anim has stopped + QCOMPARE(finishedSpy.count(), 2); + QCOMPARE(anim->currentLoopTime(), 100); + + delete anim; + } } void tst_QPropertyAnimation::deletion1() { + TestAnimationDriver timeDriver; QObject *object = new QWidget; QPointer anim = new QPropertyAnimation(object, "minimumWidth"); @@ -312,23 +391,23 @@ void tst_QPropertyAnimation::deletion1() QVERIFY(anim); QCOMPARE(anim->state(), QAnimationGroup::Running); - QTest::qWait(100); + timeDriver.wait(100); QVERIFY(anim); QCOMPARE(anim->state(), QAnimationGroup::Running); - QTest::qWait(150); + timeDriver.wait(150); QVERIFY(anim); //The animation should not have been deleted - QTRY_COMPARE(anim->state(), QAnimationGroup::Stopped); + QCOMPARE(anim->state(), QAnimationGroup::Stopped); QCOMPARE(runningSpy.count(), 2); QCOMPARE(finishedSpy.count(), 1); anim->start(QVariantAnimation::DeleteWhenStopped); QVERIFY(anim); QCOMPARE(anim->state(), QAnimationGroup::Running); - QTest::qWait(100); + timeDriver.wait(100); QVERIFY(anim); QCOMPARE(anim->state(), QAnimationGroup::Running); - QTest::qWait(150); - QTRY_COMPARE(runningSpy.count(), 4); + timeDriver.wait(150); + QCOMPARE(runningSpy.count(), 4); QCOMPARE(finishedSpy.count(), 2); QVERIFY(!anim); //The animation must have been deleted delete object; @@ -336,6 +415,7 @@ void tst_QPropertyAnimation::deletion1() void tst_QPropertyAnimation::deletion2() { + TestAnimationDriver timeDriver; //test that the animation get deleted if the object is deleted QObject *object = new QWidget; QPointer anim = new QPropertyAnimation(object,"minimumWidth"); @@ -354,7 +434,7 @@ void tst_QPropertyAnimation::deletion2() anim->setDuration(200); anim->start(); - QTest::qWait(50); + timeDriver.wait(50); QVERIFY(anim); QCOMPARE(anim->state(), QAnimationGroup::Running); @@ -363,7 +443,7 @@ void tst_QPropertyAnimation::deletion2() //we can't call deletaLater directly because the delete would only happen in the next loop of _this_ event loop QTimer::singleShot(0, object, SLOT(deleteLater())); - QTest::qWait(50); + timeDriver.wait(50); QVERIFY(!anim->targetObject()); } @@ -371,6 +451,7 @@ void tst_QPropertyAnimation::deletion2() void tst_QPropertyAnimation::deletion3() { //test that the stopped signal is emit when the animation is destroyed + TestAnimationDriver timeDriver; QObject *object = new QWidget; QPropertyAnimation *anim = new QPropertyAnimation(object,"minimumWidth"); anim->setStartValue(10); @@ -385,7 +466,7 @@ void tst_QPropertyAnimation::deletion3() anim->start(); - QTest::qWait(50); + timeDriver.wait(50); QCOMPARE(anim->state(), QAnimationGroup::Running); QCOMPARE(runningSpy.count(), 1); QCOMPARE(finishedSpy.count(), 0); @@ -432,6 +513,7 @@ public: void tst_QPropertyAnimation::noStartValue() { + TestAnimationDriver timeDriver; StartValueTester o; o.setProperty("ole", 42); o.values.clear(); @@ -441,7 +523,8 @@ void tst_QPropertyAnimation::noStartValue() a.setDuration(250); a.start(); - QTRY_COMPARE(o.values.value(o.values.size() - 1, -1), 420); + timeDriver.wait(a.duration()); + QCOMPARE(o.values.value(o.values.size() - 1, -1), 420); QCOMPARE(o.values.first(), 42); } @@ -471,6 +554,7 @@ void tst_QPropertyAnimation::startWhenAnotherIsRunning() StartValueTester o; o.setProperty("ole", 42); o.values.clear(); + TestAnimationDriver timeDriver; { //normal case: the animation finishes and is deleted @@ -479,18 +563,17 @@ void tst_QPropertyAnimation::startWhenAnotherIsRunning() QSignalSpy runningSpy(anim.data(), &QVariantAnimation::stateChanged); QVERIFY(runningSpy.isValid()); anim->start(QVariantAnimation::DeleteWhenStopped); - QTest::qWait(anim->duration() + 100); - QTRY_COMPARE(runningSpy.count(), 2); //started and then stopped + timeDriver.wait(anim->duration()); + QCOMPARE(runningSpy.count(), 2); //started and then stopped QVERIFY(!anim); } - { QPointer anim = new QPropertyAnimation(&o, "ole"); anim->setEndValue(100); QSignalSpy runningSpy(anim.data(), &QVariantAnimation::stateChanged); QVERIFY(runningSpy.isValid()); anim->start(QVariantAnimation::DeleteWhenStopped); - QTest::qWait(anim->duration()/2); + timeDriver.wait(anim->duration()/2); QPointer anim2 = new QPropertyAnimation(&o, "ole"); anim2->setEndValue(100); QCOMPARE(runningSpy.count(), 1); @@ -498,11 +581,11 @@ void tst_QPropertyAnimation::startWhenAnotherIsRunning() //anim2 will interrupt anim1 QMetaObject::invokeMethod(anim2, "start", Qt::QueuedConnection, Q_ARG(QAbstractAnimation::DeletionPolicy, QVariantAnimation::DeleteWhenStopped)); - QTest::qWait(50); + timeDriver.wait(50); QVERIFY(!anim); //anim should have been deleted QVERIFY(anim2); - QTest::qWait(anim2->duration()); - QTRY_VERIFY(!anim2); //anim2 is finished: it should have been deleted by now + timeDriver.wait(anim2->duration()); + QVERIFY(!anim2); //anim2 is finished: it should have been deleted by now QVERIFY(!anim); } @@ -559,6 +642,7 @@ void tst_QPropertyAnimation::easingcurve() void tst_QPropertyAnimation::startWithoutStartValue() { + TestAnimationDriver timeDriver; QObject o; o.setProperty("ole", 42); QCOMPARE(o.property("ole").toInt(), 42); @@ -568,14 +652,14 @@ void tst_QPropertyAnimation::startWithoutStartValue() anim.start(); - QTest::qWait(100); + timeDriver.wait(100); int current = anim.currentValue().toInt(); //it is somewhere in the animation QVERIFY(current > 42); QVERIFY(current < 100); - QTest::qWait(200); - QTRY_COMPARE(anim.state(), QVariantAnimation::Stopped); + timeDriver.wait(200); + QCOMPARE(anim.state(), QVariantAnimation::Stopped); current = anim.currentValue().toInt(); QCOMPARE(current, 100); QCOMPARE(o.property("ole").toInt(), current); @@ -586,7 +670,7 @@ void tst_QPropertyAnimation::startWithoutStartValue() // the default start value will reevaluate the current property // and set it to the end value of the last iteration QCOMPARE(current, 100); - QTest::qWait(100); + timeDriver.wait(100); current = anim.currentValue().toInt(); //it is somewhere in the animation QVERIFY(current >= 100); @@ -595,6 +679,7 @@ void tst_QPropertyAnimation::startWithoutStartValue() void tst_QPropertyAnimation::startBackwardWithoutEndValue() { + TestAnimationDriver timeDriver; QObject o; o.setProperty("ole", 42); QCOMPARE(o.property("ole").toInt(), 42); @@ -608,14 +693,14 @@ void tst_QPropertyAnimation::startBackwardWithoutEndValue() QCOMPARE(anim.state(), QAbstractAnimation::Running); QCOMPARE(o.property("ole").toInt(), 42); //the initial value - QTest::qWait(100); + timeDriver.wait(100); int current = anim.currentValue().toInt(); //it is somewhere in the animation QVERIFY(current > 42); QVERIFY(current < 100); - QTest::qWait(200); - QTRY_COMPARE(anim.state(), QVariantAnimation::Stopped); + timeDriver.wait(200); + QCOMPARE(anim.state(), QVariantAnimation::Stopped); current = anim.currentValue().toInt(); QCOMPARE(current, 100); QCOMPARE(o.property("ole").toInt(), current); @@ -626,7 +711,7 @@ void tst_QPropertyAnimation::startBackwardWithoutEndValue() // the default start value will reevaluate the current property // and set it to the end value of the last iteration QCOMPARE(current, 100); - QTest::qWait(100); + timeDriver.wait(100); current = anim.currentValue().toInt(); //it is somewhere in the animation QVERIFY(current >= 100); @@ -636,6 +721,7 @@ void tst_QPropertyAnimation::startBackwardWithoutEndValue() void tst_QPropertyAnimation::playForwardBackward() { + TestAnimationDriver timeDriver; QObject o; o.setProperty("ole", 0); QCOMPARE(o.property("ole").toInt(), 0); @@ -644,16 +730,16 @@ void tst_QPropertyAnimation::playForwardBackward() anim.setStartValue(0); anim.setEndValue(100); anim.start(); - QTest::qWait(anim.duration() + 100); - QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); + timeDriver.wait(anim.duration()); + QCOMPARE(anim.state(), QAbstractAnimation::Stopped); QCOMPARE(anim.currentTime(), anim.duration()); //the animation is at the end anim.setDirection(QVariantAnimation::Backward); anim.start(); QCOMPARE(anim.state(), QAbstractAnimation::Running); - QTest::qWait(anim.duration() + 100); - QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); + timeDriver.wait(anim.duration()); + QCOMPARE(anim.state(), QAbstractAnimation::Stopped); QCOMPARE(anim.currentTime(), 0); //the direction is backward @@ -661,8 +747,8 @@ void tst_QPropertyAnimation::playForwardBackward() anim.start(); QCOMPARE(anim.state(), QAbstractAnimation::Running); QCOMPARE(anim.currentTime(), anim.duration()); - QTest::qWait(anim.duration() + 100); - QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); + timeDriver.wait(anim.duration()); + QCOMPARE(anim.state(), QAbstractAnimation::Stopped); QCOMPARE(anim.currentTime(), 0); } @@ -1106,21 +1192,21 @@ void tst_QPropertyAnimation::restart() void tst_QPropertyAnimation::valueChanged() { - + TestAnimationDriver timeDriver; //we check that we receive the valueChanged signal MyErrorObject o; o.setOle(0); QCOMPARE(o.property("ole").toInt(), 0); QPropertyAnimation anim(&o, "ole"); anim.setEndValue(5); - anim.setDuration(1000); + anim.setDuration(200); QSignalSpy spy(&anim, &QPropertyAnimation::valueChanged); QVERIFY(spy.isValid()); anim.start(); + // Drive animation forward to its end + timeDriver.wait(anim.duration()); - QTest::qWait(anim.duration() + 100); - - QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); + QCOMPARE(anim.state(), QAbstractAnimation::Stopped); QCOMPARE(anim.currentTime(), anim.duration()); //let's check that the values go forward @@ -1153,6 +1239,7 @@ public: void tst_QPropertyAnimation::twoAnimations() { + TestAnimationDriver timeDriver; MySyncObject o1, o2; o1.setOle(0); o2.setOle(0); @@ -1169,8 +1256,8 @@ void tst_QPropertyAnimation::twoAnimations() o1.anim.start(); o2.anim.start(); - QTest::qWait(o1.anim.duration() + 100); - QTRY_COMPARE(o1.anim.state(), QAbstractAnimation::Stopped); + timeDriver.wait(o1.anim.duration()); + QCOMPARE(o1.anim.state(), QAbstractAnimation::Stopped); QCOMPARE(o2.anim.state(), QAbstractAnimation::Stopped); QCOMPARE(o1.ole(), 1000); @@ -1209,6 +1296,7 @@ public: void tst_QPropertyAnimation::deletedInUpdateCurrentTime() { + TestAnimationDriver timeDriver; // this test case reproduces an animation being deleted in the updateCurrentTime of // another animation(was causing segfault). // the deleted animation must have been started after the animation that is deleting. @@ -1219,9 +1307,9 @@ void tst_QPropertyAnimation::deletedInUpdateCurrentTime() MyComposedAnimation composedAnimation(&o, "value", "realValue"); composedAnimation.start(); QCOMPARE(composedAnimation.state(), QAbstractAnimation::Running); - QTest::qWait(composedAnimation.duration() + 100); + timeDriver.wait(composedAnimation.duration()); - QTRY_COMPARE(composedAnimation.state(), QAbstractAnimation::Stopped); + QCOMPARE(composedAnimation.state(), QAbstractAnimation::Stopped); QCOMPARE(o.value(), 1000); } @@ -1293,6 +1381,7 @@ public: void tst_QPropertyAnimation::recursiveAnimations() { + TestAnimationDriver timeDriver; RecursiveObject o; QPropertyAnimation anim; anim.setTargetObject(&o); @@ -1301,9 +1390,9 @@ void tst_QPropertyAnimation::recursiveAnimations() anim.setEndValue(4000); anim.start(); - QTest::qWait(anim.duration() + o.animation.duration()); - QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); - QTRY_COMPARE(o.animation.state(), QAbstractAnimation::Stopped); + timeDriver.wait(anim.duration() + o.animation.duration()); + QCOMPARE(anim.state(), QAbstractAnimation::Stopped); + QCOMPARE(o.animation.state(), QAbstractAnimation::Stopped); QCOMPARE(o.y(), qreal(4000)); } -- cgit v1.2.3 From 637e8ebcc3c2394d01827043d1a410866234fd0c Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 13:35:58 -0800 Subject: tst_QUdpSocket: Don't test for .bytesAvailable on untrusted platforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FreeBSD, for example, does not have SO_NREAD and its FIONREAD returns the full socket buffer size, including IP and UDP headers. Change-Id: Ifb5969bf206e4cd7b14efffd14fb5d8ca778d16a Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 0f46caa7c2..aa71f7e94d 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -60,6 +60,13 @@ #include #endif +#ifdef Q_OS_UNIX +# include +#endif +#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(SO_NREAD) +# define RELIABLE_BYTES_AVAILABLE +#endif + Q_DECLARE_METATYPE(QHostAddress) QT_FORWARD_DECLARE_CLASS(QUdpSocket) @@ -1806,7 +1813,9 @@ void tst_QUdpSocket::readyRead() // make sure only one signal was emitted QCOMPARE(spy.count(), 1); QVERIFY(receiver.hasPendingDatagrams()); +#ifdef RELIABLE_BYTES_AVAILABLE QCOMPARE(receiver.bytesAvailable(), qint64(2)); +#endif QCOMPARE(receiver.pendingDatagramSize(), qint64(2)); // write another datagram @@ -1828,7 +1837,9 @@ void tst_QUdpSocket::readyRead() QTest::qWait(100); QCOMPARE(spy.count(), 2); QVERIFY(receiver.hasPendingDatagrams()); +#ifdef RELIABLE_BYTES_AVAILABLE QCOMPARE(receiver.bytesAvailable(), qint64(3)); +#endif QCOMPARE(receiver.pendingDatagramSize(), qint64(3)); } @@ -1860,7 +1871,9 @@ void tst_QUdpSocket::readyReadForEmptyDatagram() char buf[1]; QVERIFY(receiver.hasPendingDatagrams()); QCOMPARE(receiver.pendingDatagramSize(), qint64(0)); +#ifdef RELIABLE_BYTES_AVAILABLE QCOMPARE(receiver.bytesAvailable(), qint64(0)); +#endif QCOMPARE(receiver.readDatagram(buf, sizeof buf), qint64(0)); } @@ -1869,7 +1882,9 @@ void tst_QUdpSocket::async_readDatagramSlot() char buf[1]; QVERIFY(m_asyncReceiver->hasPendingDatagrams()); QCOMPARE(m_asyncReceiver->pendingDatagramSize(), qint64(1)); +#ifdef RELIABLE_BYTES_AVAILABLE QCOMPARE(m_asyncReceiver->bytesAvailable(), qint64(1)); +#endif QCOMPARE(m_asyncReceiver->readDatagram(buf, sizeof(buf)), qint64(1)); if (buf[0] == '2') { -- cgit v1.2.3 From 81a88639acf8e7dfe4312733635c138abe51b828 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 14:59:12 -0800 Subject: tst_QUdpSocket: fix linkLocalIPv4 test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I broke it in commit 4da2dda2aa1f710177157dc1cf841e0bf0b9d829. It wasn't flaky or anything: it was plain broken and would never pass. That indicates no node in the CI has an IPv4 link-local address (and apparently neither did I at the time). Change-Id: Ifb5969bf206e4cd7b14efffd14fb62176546916e Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index aa71f7e94d..5c5dfc881d 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -1723,7 +1723,7 @@ void tst_QUdpSocket::linkLocalIPv4() foreach (QNetworkAddressEntry addr, iface.addressEntries()) { if (addr.ip().isInSubnet(localMask, 16)) { addresses << addr.ip(); - qDebug() << addr.ip(); + qDebug() << "Found IPv4 link local address" << addr.ip(); } } } @@ -1748,7 +1748,6 @@ void tst_QUdpSocket::linkLocalIPv4() QVERIFY(s->writeDatagram(testData, s->localAddress(), neutral.localPort())); QVERIFY2(neutral.waitForReadyRead(10000), QtNetworkSettings::msgSocketError(neutral).constData()); - QVERIFY2(s->waitForReadyRead(10000), QtNetworkSettings::msgSocketError(*s).constData()); QNetworkDatagram dgram = neutral.receiveDatagram(testData.length() * 2); QVERIFY(dgram.isValid()); QCOMPARE(dgram.senderAddress(), s->localAddress()); @@ -1771,7 +1770,7 @@ void tst_QUdpSocket::linkLocalIPv4() } QVERIFY(neutral.writeDatagram(dgram.makeReply(testData))); - + QVERIFY2(s->waitForReadyRead(10000), QtNetworkSettings::msgSocketError(*s).constData()); dgram = s->receiveDatagram(testData.length() * 2); QVERIFY(dgram.isValid()); QCOMPARE(dgram.data(), testData); -- cgit v1.2.3 From 1853aeb50a41062d8585065c97edd3e58db1fba7 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 11:28:59 -0800 Subject: tst_QUdpSocket: remove Bearer portions of the test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test fails to start on FreeBSD: FAIL! : tst_QUdpSocket::initTestCase() 'networkSession->waitForOpened(30000)' returned FALSE. () Loc: [/usr/home/tjmaciei/src/qt/qt5/qtbase/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp(234)] This commit is basically a revert of the Qt 4.8 commit a951fb79139498774d021759d0466b4b2ff50e68. FORCE_SESSION was only used by manual testing, as the commit message said > 8. For manual testing, added the FORCE_SESSION macro to test behaviour > of UDP sockets when they have an explicit network session associated So I doubt it has been tested recently. Change-Id: Ifb5969bf206e4cd7b14efffd14fb569ebf53497b Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov --- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 122 --------------------- 1 file changed, 122 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 0f46caa7c2..6dff9f3420 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -47,12 +47,6 @@ #include "../../../network-settings.h" #include "emulationdetector.h" -#ifndef QT_NO_BEARERMANAGEMENT -#include -#include -#include -#endif - #if defined(Q_OS_LINUX) #define SHOULD_CHECK_SYSCALL_SUPPORT #include @@ -130,11 +124,6 @@ private: bool m_skipUnsupportedIPv6Tests; QList allAddresses; -#ifndef QT_NO_BEARERMANAGEMENT - QNetworkConfigurationManager *netConfMan; - QNetworkConfiguration networkConfiguration; - QSharedPointer networkSession; -#endif QUdpSocket *m_asyncSender; QUdpSocket *m_asyncReceiver; }; @@ -210,16 +199,6 @@ void tst_QUdpSocket::initTestCase_data() if (!newTestServer) QTest::newRow("WithSocks5Proxy") << true << int(QNetworkProxy::Socks5Proxy); #endif - -#ifndef QT_NO_BEARERMANAGEMENT - netConfMan = new QNetworkConfigurationManager(this); - networkConfiguration = netConfMan->defaultConfiguration(); - networkSession = QSharedPointer::create(networkConfiguration); - if (!networkSession->isOpen()) { - networkSession->open(); - QVERIFY(networkSession->waitForOpened(30000)); - } -#endif } void tst_QUdpSocket::initTestCase() @@ -261,9 +240,6 @@ void tst_QUdpSocket::cleanup() void tst_QUdpSocket::constructing() { QUdpSocket socket; -#ifdef FORCE_SESSION - socket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(socket.isSequential()); QVERIFY(!socket.isOpen()); @@ -281,9 +257,6 @@ void tst_QUdpSocket::constructing() void tst_QUdpSocket::unconnectedServerAndClientTest() { QUdpSocket serverSocket; -#ifdef FORCE_SESSION - serverSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif qRegisterMetaType("QAbstractSocket::SocketState"); @@ -296,9 +269,6 @@ void tst_QUdpSocket::unconnectedServerAndClientTest() QHostAddress serverAddress = makeNonAny(serverSocket.localAddress()); for (int i = 0; i < 3; ++i) { QUdpSocket clientSocket; -#ifdef FORCE_SESSION - clientSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QCOMPARE(int(clientSocket.writeDatagram(message[i], strlen(message[i]), serverAddress, serverSocket.localPort())), int(strlen(message[i]))); @@ -352,9 +322,6 @@ void tst_QUdpSocket::broadcasting() QSKIP("No interface can broadcast"); for (int i = 0; i < 4; ++i) { QUdpSocket serverSocket; -#ifdef FORCE_SESSION - serverSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY2(serverSocket.bind(QHostAddress(QHostAddress::AnyIPv4), 0), serverSocket.errorString().toLatin1().constData()); quint16 serverPort = serverSocket.localPort(); @@ -363,9 +330,6 @@ void tst_QUdpSocket::broadcasting() connect(&serverSocket, SIGNAL(readyRead()), SLOT(empty_readyReadSlot())); QUdpSocket broadcastSocket; -#ifdef FORCE_SESSION - broadcastSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif broadcastSocket.bind(QHostAddress(QHostAddress::AnyIPv4), 0); for (int j = 0; j < 10; ++j) { @@ -444,10 +408,6 @@ void tst_QUdpSocket::loop() QUdpSocket peter; QUdpSocket paul; -#ifdef FORCE_SESSION - peter.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - paul.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif // make sure we bind to IPv4 QHostAddress localhost = QHostAddress::LocalHost; @@ -518,10 +478,6 @@ void tst_QUdpSocket::ipv6Loop() QUdpSocket peter; QUdpSocket paul; -#ifdef FORCE_SESSION - peter.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - paul.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif int peterPort; int paulPort; @@ -745,10 +701,6 @@ void tst_QUdpSocket::connectToHost() { QUdpSocket socket1; QUdpSocket socket2; -#ifdef FORCE_SESSION - socket1.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - socket2.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY2(socket1.bind(), socket1.errorString().toLatin1().constData()); @@ -763,11 +715,6 @@ void tst_QUdpSocket::bindAndConnectToHost() QUdpSocket socket1; QUdpSocket socket2; QUdpSocket dummysocket; -#ifdef FORCE_SESSION - socket1.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - socket2.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - dummysocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif // we use the dummy socket to use up a file descriptor dummysocket.bind(); @@ -791,16 +738,10 @@ void tst_QUdpSocket::bindAndConnectToHost() void tst_QUdpSocket::pendingDatagramSize() { QUdpSocket server; -#ifdef FORCE_SESSION - server.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY2(server.bind(), server.errorString().toLatin1().constData()); QHostAddress serverAddress = makeNonAny(server.localAddress()); QUdpSocket client; -#ifdef FORCE_SESSION - client.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(client.writeDatagram("this is", 7, serverAddress, server.localPort()) == 7); QVERIFY(client.writeDatagram(0, 0, serverAddress, server.localPort()) == 0); QVERIFY(client.writeDatagram("3 messages", 10, serverAddress, server.localPort()) == 10); @@ -839,16 +780,10 @@ void tst_QUdpSocket::pendingDatagramSize() void tst_QUdpSocket::writeDatagram() { QUdpSocket server; -#ifdef FORCE_SESSION - server.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY2(server.bind(), server.errorString().toLatin1().constData()); QHostAddress serverAddress = makeNonAny(server.localAddress()); QUdpSocket client; -#ifdef FORCE_SESSION - client.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif qRegisterMetaType("QAbstractSocket::SocketError"); @@ -886,16 +821,10 @@ void tst_QUdpSocket::performance() QByteArray arr(8192, '@'); QUdpSocket server; -#ifdef FORCE_SESSION - server.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY2(server.bind(), server.errorString().toLatin1().constData()); QHostAddress serverAddress = makeNonAny(server.localAddress()); QUdpSocket client; -#ifdef FORCE_SESSION - client.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif client.connectToHost(serverAddress, server.localPort()); QVERIFY(client.waitForConnected(10000)); @@ -932,14 +861,8 @@ void tst_QUdpSocket::bindMode() } QUdpSocket socket; -#ifdef FORCE_SESSION - socket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY2(socket.bind(), socket.errorString().toLatin1().constData()); QUdpSocket socket2; -#ifdef FORCE_SESSION - socket2.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(!socket2.bind(socket.localPort())); #if defined(Q_OS_UNIX) QVERIFY(!socket2.bind(socket.localPort(), QUdpSocket::ReuseAddressHint)); @@ -991,9 +914,6 @@ void tst_QUdpSocket::writeDatagramToNonExistingPeer() quint16 peerPort = 33533 + int(bind); QUdpSocket sUdp; -#ifdef FORCE_SESSION - sUdp.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QSignalSpy sReadyReadSpy(&sUdp, SIGNAL(readyRead())); if (bind) QVERIFY(sUdp.bind()); @@ -1026,9 +946,6 @@ void tst_QUdpSocket::writeToNonExistingPeer() qRegisterMetaType("QAbstractSocket::SocketError"); QUdpSocket sConnected; -#ifdef FORCE_SESSION - sConnected.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QSignalSpy sConnectedReadyReadSpy(&sConnected, SIGNAL(readyRead())); QSignalSpy sConnectedErrorSpy(&sConnected, SIGNAL(error(QAbstractSocket::SocketError))); sConnected.connectToHost(peerAddress, peerPort, QIODevice::ReadWrite); @@ -1198,18 +1115,12 @@ void tst_QUdpSocket::zeroLengthDatagram() return; QUdpSocket receiver; -#ifdef FORCE_SESSION - receiver.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(receiver.bind()); QVERIFY(!receiver.waitForReadyRead(100)); QVERIFY(!receiver.hasPendingDatagrams()); QUdpSocket sender; -#ifdef FORCE_SESSION - sender.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QCOMPARE(sender.writeDatagram(QNetworkDatagram(QByteArray(), QHostAddress::LocalHost, receiver.localPort())), qint64(0)); QVERIFY2(receiver.waitForReadyRead(1000), QtNetworkSettings::msgSocketError(receiver).constData()); @@ -1262,9 +1173,6 @@ void tst_QUdpSocket::multicastTtlOption() } QUdpSocket udpSocket; -#ifdef FORCE_SESSION - udpSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif // bind, but ignore the result, we are only interested in initializing the socket (void) udpSocket.bind(bindAddress, 0); udpSocket.setSocketOption(QUdpSocket::MulticastTtlOption, ttl); @@ -1315,9 +1223,6 @@ void tst_QUdpSocket::multicastLoopbackOption() } QUdpSocket udpSocket; -#ifdef FORCE_SESSION - udpSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif // bind, but ignore the result, we are only interested in initializing the socket (void) udpSocket.bind(bindAddress, 0); udpSocket.setSocketOption(QUdpSocket::MulticastLoopbackOption, loopback); @@ -1341,9 +1246,6 @@ void tst_QUdpSocket::multicastJoinBeforeBind() QFETCH(QHostAddress, groupAddress); QUdpSocket udpSocket; -#ifdef FORCE_SESSION - udpSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif // cannot join group before binding QTest::ignoreMessage(QtWarningMsg, "QUdpSocket::joinMulticastGroup() called on a QUdpSocket when not in QUdpSocket::BoundState"); QVERIFY(!udpSocket.joinMulticastGroup(groupAddress)); @@ -1376,9 +1278,6 @@ void tst_QUdpSocket::multicastLeaveAfterClose() } QUdpSocket udpSocket; -#ifdef FORCE_SESSION - udpSocket.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QHostAddress bindAddress = QHostAddress::AnyIPv4; if (groupAddress.protocol() == QAbstractSocket::IPv6Protocol) bindAddress = QHostAddress::AnyIPv6; @@ -1487,9 +1386,6 @@ void tst_QUdpSocket::multicast() } QUdpSocket receiver; -#ifdef FORCE_SESSION - receiver.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif // bind first, then verify that we can join the multicast group QVERIFY2(receiver.bind(bindAddress, 0) == bindResult, @@ -1515,9 +1411,6 @@ void tst_QUdpSocket::multicast() << QByteArray("cdef"); QUdpSocket sender; -#ifdef FORCE_SESSION - sender.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif sender.bind(); foreach (const QByteArray &datagram, datagrams) { QCOMPARE(int(sender.writeDatagram(datagram, groupAddress, receiver.localPort())), @@ -1563,9 +1456,6 @@ void tst_QUdpSocket::echo() QHostAddress remote = info.addresses().first(); QUdpSocket sock; -#ifdef FORCE_SESSION - sock.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif if (connect) { sock.connectToHost(remote, 7); QVERIFY(sock.waitForConnected(10000)); @@ -1785,10 +1675,6 @@ void tst_QUdpSocket::readyRead() char buf[1]; QUdpSocket sender, receiver; -#ifdef FORCE_SESSION - sender.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - receiver.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(receiver.bind(QHostAddress(QHostAddress::AnyIPv4), 0)); quint16 port = receiver.localPort(); @@ -1839,10 +1725,6 @@ void tst_QUdpSocket::readyReadForEmptyDatagram() return; QUdpSocket sender, receiver; -#ifdef FORCE_SESSION - sender.setProperty("_q_networksession", QVariant::fromValue(networkSession)); - receiver.setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(receiver.bind(QHostAddress(QHostAddress::AnyIPv4), 0)); quint16 port = receiver.localPort(); @@ -1891,10 +1773,6 @@ void tst_QUdpSocket::asyncReadDatagram() m_asyncSender = new QUdpSocket; m_asyncReceiver = new QUdpSocket; -#ifdef FORCE_SESSION - m_asyncSender->setProperty("_q_networksession", QVariant::fromValue(networkSession)); - m_asyncReceiver->setProperty("_q_networksession", QVariant::fromValue(networkSession)); -#endif QVERIFY(m_asyncReceiver->bind(QHostAddress(QHostAddress::AnyIPv4), 0)); quint16 port = m_asyncReceiver->localPort(); -- cgit v1.2.3 From 7257862fb2edfab0219d6cd45c83677049404f7d Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 11 Dec 2017 16:55:02 +0100 Subject: Set sharedPainter correctly for QGraphicsEffect Autotest is taken from the previously reverted 8b1377fde16a2049a1c27f6d005bff84a8f85f28. Task-number: QTBUG-60231 Change-Id: I44dd79cba22b6baefdd6d95c176790bef0b7eafe Reviewed-by: Andy Nichols --- .../effects/qgraphicseffect/tst_qgraphicseffect.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp index a1cb729849..dfe5baba71 100644 --- a/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/widgets/effects/qgraphicseffect/tst_qgraphicseffect.cpp @@ -52,6 +52,7 @@ private slots: void boundingRect2(); void draw(); void opacity(); + void nestedOpaqueOpacity(); void grayscale(); void colorize(); void drawPixmapItem(); @@ -407,6 +408,26 @@ void tst_QGraphicsEffect::opacity() QCOMPARE(effect->m_opacity, qreal(0.5)); } +void tst_QGraphicsEffect::nestedOpaqueOpacity() +{ + // QTBUG-60231: Nesting widgets with a QGraphicsEffect on a toplevel with + // QGraphicsOpacityEffect caused crashes due to constructing several + // QPainter instances on a device in the fast path for + // QGraphicsOpacityEffect::opacity=1 + QWidget topLevel; + topLevel.setWindowTitle(QTest::currentTestFunction()); + topLevel.resize(320, 200); + QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect; + opacityEffect->setOpacity(1); + topLevel.setGraphicsEffect(opacityEffect); + QWidget *child = new QWidget(&topLevel); + child->resize(topLevel.size() / 2); + QGraphicsDropShadowEffect *childEffect = new QGraphicsDropShadowEffect; + child->setGraphicsEffect(childEffect); + topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); +} + void tst_QGraphicsEffect::grayscale() { if (qApp->desktop()->depth() < 24) -- cgit v1.2.3 From 27c840f5d45747da7f4d989afba172805ce1fb51 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Wed, 13 Dec 2017 10:57:46 +0100 Subject: Fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: If6111c59b958ba03f6ec5966af5cf443cae5cf9b Reviewed-by: Tor Arne Vestbø --- tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp index 15c63d4acd..a74ea3a89e 100644 --- a/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp +++ b/tests/auto/corelib/io/qloggingregistry/tst_qloggingregistry.cpp @@ -212,7 +212,7 @@ private slots: qunsetenv("QT_LOGGING_RULES"); qputenv("QT_LOGGING_CONF", QFINDTESTDATA("qtlogging.ini").toLocal8Bit()); - registry.initalizeRules(); + registry.initializeRules(); QCOMPARE(registry.ruleSets[QLoggingRegistry::ApiRules].size(), 0); QCOMPARE(registry.ruleSets[QLoggingRegistry::ConfigRules].size(), 0); @@ -220,7 +220,7 @@ private slots: // check that QT_LOGGING_RULES take precedence qputenv("QT_LOGGING_RULES", "Digia.*=true"); - registry.initalizeRules(); + registry.initializeRules(); QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].size(), 2); QCOMPARE(registry.ruleSets[QLoggingRegistry::EnvironmentRules].at(1).enabled, true); } @@ -246,7 +246,7 @@ private slots: file.close(); QLoggingRegistry registry; - registry.initalizeRules(); + registry.initializeRules(); QCOMPARE(registry.ruleSets[QLoggingRegistry::ConfigRules].size(), 1); // remove file again -- cgit v1.2.3 From 345be581007c05164052e27f90fcfaf27a41c743 Mon Sep 17 00:00:00 2001 From: Jesus Fernandez Date: Wed, 6 Dec 2017 19:46:31 +0100 Subject: Fix assert when emitting a signal from a different thread If a signal is emitted more than once in a multithreaded application the QSignalEventGenerator::execute function asserts in the check for a valid signal index. It happens after abandoning the state and all the connections are disconnected. If we have pending signal to be processed the QObject::sender() won't be able to resolve the sender object. Task-number: QTBUG-61463 Change-Id: I9d4b7266c6dddc9ff2e7453b05a6989876ccb332 Reviewed-by: Edward Welbourne --- .../qstatemachine/tst_qstatemachine.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 8f0d83ce32..7ea467b6ef 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -101,6 +101,7 @@ Q_OBJECT public: SignalEmitter(QObject *parent = 0) : QObject(parent) {} +public Q_SLOTS: void emitSignalWithNoArg() { emit signalWithNoArg(); } void emitSignalWithIntArg(int arg) @@ -251,6 +252,7 @@ private slots: void qtbug_46059(); void qtbug_46703(); void postEventFromBeginSelectTransitions(); + void dontProcessSlotsWhenMachineIsNotRunning(); }; class TestState : public QState @@ -6658,5 +6660,35 @@ void tst_QStateMachine::postEventFromBeginSelectTransitions() QVERIFY(machine.isRunning()); } +void tst_QStateMachine::dontProcessSlotsWhenMachineIsNotRunning() +{ + QStateMachine machine; + QState initialState; + QFinalState finalState; + + struct Emitter : SignalEmitter + { + QThread thread; + Emitter(QObject *parent = nullptr) : SignalEmitter(parent) + { + moveToThread(&thread); + thread.start(); + } + } emitter; + + initialState.addTransition(&emitter, &Emitter::signalWithNoArg, &finalState); + QTimer::singleShot(0, [&]() { + metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg"); + metaObject()->invokeMethod(&emitter, "emitSignalWithNoArg"); + }); + machine.addState(&initialState); + machine.addState(&finalState); + machine.setInitialState(&initialState); + machine.start(); + connect(&machine, &QStateMachine::finished, &emitter.thread, &QThread::quit); + QSignalSpy signalSpy(&machine, &QStateMachine::finished); + QTRY_COMPARE_WITH_TIMEOUT(signalSpy.count(), 1, 100); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" -- cgit v1.2.3 From 93dabeba9dc5f6cbab60e65b3cc8df5fe48745a9 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 17 Nov 2017 20:57:00 +0100 Subject: QTreeView: Make sure QHeaderView is notified on layoutChanged() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QHeaderViewPrivate::_q_layoutChanged() was not called when used in a QTreeView because it was explicitly disconnected in setModel(). The disconnect was added sometime prio to Qt 4.3, but there the signal was connected to the doItemsLayout() slot. This was correct since QTreeView::doItemsLayout() is calling header->doItemsLayout(). In Qt 4.3.0 _q_layoutChanged() was introduced and the disconnect was adjusted. But since _q_layoutChanged() is doing much more than doItemsLayout() (e.g. restoring hidden sections), functionality was lost. The problem was already observed for Qt 4.6 (QTBUG-18196) but only partially fixed. Task-number: QTBUG-41124 Task-number: QTBUG-54610 Change-Id: Id13a9930d0163812e12a0287016bab9c3aa02068 Reviewed-by: Thorbjørn Lund Martsum --- .../widgets/itemviews/qtreeview/tst_qtreeview.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index dfcaa9b5b9..5de0ca6c22 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -313,6 +313,17 @@ public: endRemoveColumns(); } + void removeAddLastColumnLayoutChanged() // for taskQTBUG_41124 + { + // make sure QHeaderView::_q_layoutChanged() is called + emit layoutAboutToBeChanged(); + --cols; + emit layoutChanged(); + emit layoutAboutToBeChanged(); + ++cols; + emit layoutChanged(); + } + void removeAllColumns() { beginRemoveColumns(QModelIndex(), 0, cols - 1); @@ -1306,6 +1317,19 @@ void tst_QTreeView::columnHidden() for (int c = 0; c < model.columnCount(); ++c) QCOMPARE(view.isColumnHidden(c), true); view.update(); + + // QTBUG_41124: + // QHeaderViewPrivate::_q_layoutChanged was not called because it was + // disconnected in QTreeView::setModel(). _q_layoutChanged restores + // the hidden sections which is tested here + view.setColumnHidden(model.cols - 1, true); + model.removeAddLastColumnLayoutChanged(); + // we removed the last column and added a new one + // (with layoutToBeChanged/layoutChanged() for both) so column + // 1 is a new column and therefore must not be hidden when + // _q_layoutChanged() is called and is doing the right stuff + QCOMPARE(view.isColumnHidden(model.cols - 1), false); + } void tst_QTreeView::rowHidden() -- cgit v1.2.3 From 17d231039b53c03e67d025f1f72bbd529e98fcbd Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 13 Dec 2017 21:29:21 +0000 Subject: Don't crash with null receiver/context in new-style connects old style connects have protection against null sender and null receiver, but new style only had against null sender. Change-Id: Ie555ac078412918e60c3b60830fe1f3abfb7f5af Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 642d48d721..f1e58921c0 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -150,6 +150,7 @@ private slots: void deleteLaterInAboutToBlockHandler(); void mutableFunctor(); void checkArgumentsForNarrowing(); + void nullReceiver(); }; struct QObjectCreatedOnShutdown @@ -7380,6 +7381,16 @@ void tst_QObject::checkArgumentsForNarrowing() #undef FITS } +void tst_QObject::nullReceiver() +{ + QObject o; + QObject *nullObj = nullptr; // Passing nullptr directly doesn't compile with gcc 4.8 + QVERIFY(!connect(&o, &QObject::destroyed, nullObj, &QObject::deleteLater)); + QVERIFY(!connect(&o, &QObject::destroyed, nullObj, [] {})); + QVERIFY(!connect(&o, &QObject::destroyed, nullObj, Functor_noexcept())); + QVERIFY(!connect(&o, SIGNAL(destroyed()), nullObj, SLOT(deleteLater()))); +} + // Test for QtPrivate::HasQ_OBJECT_Macro Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro::Value); Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro::Value); -- cgit v1.2.3 From ffc8409aa58c04c1dd140001976b55925ac959f6 Mon Sep 17 00:00:00 2001 From: Dyami Caliri Date: Mon, 15 Sep 2014 14:09:22 -0700 Subject: Use AccessCheck for current user effective file permissions On Windows, QFileInfo.isWritable() was returning true in situations where the file would only be writable with elevated privileges. Using AccessCheck instead of GetEffectiveRightsFromAcl to get the correct results. Done-with: Friedemann Kleint Done-with: Edward Welbourne Task-number: QTBUG-30148 Change-Id: I7a3468ac069bf782ca312078e3a84107b6cd468c Reviewed-by: Friedemann Kleint --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 25 +++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) mode change 100644 => 100755 tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp (limited to 'tests') diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp old mode 100644 new mode 100755 index f35dab2cad..efb261ce7e --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -64,6 +64,14 @@ #define Q_NO_SYMLINKS #endif +#if defined(Q_OS_WIN) +QT_BEGIN_NAMESPACE +extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; +QT_END_NAMESPACE +# ifndef Q_OS_WINRT +bool IsUserAdmin(); +# endif +#endif #if defined(Q_OS_UNIX) && !defined(Q_OS_VXWORKS) inline bool qt_isEvilFsTypeName(const char *name) @@ -1634,6 +1642,15 @@ void tst_QFileInfo::isWritable() QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData()); QVERIFY(!fi.isWritable()); #endif + +#if defined (Q_OS_WIN) && !defined(Q_OS_WINRT) + QScopedValueRollback ntfsMode(qt_ntfs_permission_lookup); + qt_ntfs_permission_lookup = 1; + QFileInfo fi2(QFile::decodeName(qgetenv("SystemRoot") + "/system.ini")); + QVERIFY(fi2.exists()); + QCOMPARE(fi2.isWritable(), IsUserAdmin()); +#endif + #if defined (Q_OS_QNX) // On QNX /etc is usually on a read-only filesystem QVERIFY(!QFileInfo("/etc/passwd").isWritable()); #elif defined (Q_OS_UNIX) && !defined(Q_OS_VXWORKS) // VxWorks does not have users/groups @@ -1807,7 +1824,7 @@ void tst_QFileInfo::detachingOperations() } #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -BOOL IsUserAdmin() +bool IsUserAdmin() { BOOL b; SID_IDENTIFIER_AUTHORITY NtAuthority = SECURITY_NT_AUTHORITY; @@ -1825,13 +1842,9 @@ BOOL IsUserAdmin() FreeSid(AdministratorsGroup); } - return(b); + return b != FALSE; } -QT_BEGIN_NAMESPACE -extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; -QT_END_NAMESPACE - #endif // Q_OS_WIN && !Q_OS_WINRT #ifndef Q_OS_WINRT -- cgit v1.2.3 From bbcd4533889b3f3ae45917d638e06bedc9e5c536 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 16:49:40 -0800 Subject: tst_QUdpSocket: stop trying to bind to multicast addresses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is not an official feature of the networking stacks and does not work portably across operating systems. So just stop trying to do that. This was failing reliably (not flaky!) with IPv6 on FreeBSD and Windows. For IPv4, Windows apparently accepts 239.255.0.0/16 but not other addresses, so remove IPv4 too. Change-Id: Ifb5969bf206e4cd7b14efffd14fb682c2839e95d Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- tests/auto/network/socket/qudpsocket/BLACKLIST | 2 -- tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp | 2 -- 2 files changed, 4 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/BLACKLIST b/tests/auto/network/socket/qudpsocket/BLACKLIST index 5adb05d3f2..dcb5f87628 100644 --- a/tests/auto/network/socket/qudpsocket/BLACKLIST +++ b/tests/auto/network/socket/qudpsocket/BLACKLIST @@ -1,5 +1,3 @@ -[multicast:same bind, group ipv6 address] -* [multicast] osx [writeDatagramToNonExistingPeer] diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 6dff9f3420..9050bbbc93 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -1353,10 +1353,8 @@ void tst_QUdpSocket::multicast_data() QTest::addColumn("joinResult"); QTest::newRow("valid bind, group ipv4 address") << anyAddress << true << groupAddress << true; QTest::newRow("valid bind, invalid group ipv4 address") << anyAddress << true << anyAddress << false; - QTest::newRow("same bind, group ipv4 address") << groupAddress << true << groupAddress << true; QTest::newRow("valid bind, group ipv6 address") << any6Address << true << group6Address << true; QTest::newRow("valid bind, invalid group ipv6 address") << any6Address << true << any6Address << false; - QTest::newRow("same bind, group ipv6 address") << group6Address << false << group6Address << false; QTest::newRow("dual bind, group ipv4 address") << dualAddress << true << groupAddress << false; QTest::newRow("dual bind, group ipv6 address") << dualAddress << true << group6Address << true; } -- cgit v1.2.3 From c4f397ee11fc3cea1fc132ebe1db24e3970bb477 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 12:15:37 -0800 Subject: tst_QUdpSocket: Don't use interface-local IPv6 multicast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The FreeBSD kernel treats them specially, just like link-local (that's probably why it calls them "interface-local" instead of "node-local"). So instead let's use a random address, which will avoid multiple tst_qudpsocket, when run on the same network at the same time, receiving each other's datagrams. It could happen, considering this test has an 800-second timeout limit. Change-Id: Ifb5969bf206e4cd7b14efffd14fb592a3166547e Reviewed-by: Edward Welbourne Reviewed-by: Mårten Nordheim --- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 9050bbbc93..69d549d738 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,7 @@ private: bool m_skipUnsupportedIPv6Tests; QList allAddresses; + QHostAddress multicastGroup4, multicastGroup6; QUdpSocket *m_asyncSender; QUdpSocket *m_asyncReceiver; }; @@ -208,6 +210,20 @@ void tst_QUdpSocket::initTestCase() allAddresses = QNetworkInterface::allAddresses(); m_skipUnsupportedIPv6Tests = shouldSkipIpv6TestsForBrokenSetsockopt(); + // Create a pair of random multicast groups so we avoid clashing with any + // other tst_qudpsocket running on the same network at the same time. + quint64 r[2] = { + // ff14:: is temporary, not prefix-based, admin-local + qToBigEndian(Q_UINT64_C(0xff14) << 48), + QRandomGenerator64::global()->generate64() + }; + multicastGroup6.setAddress(*reinterpret_cast(&r)); + + // 239.0.0.0/8 is "Organization-Local Scope" + multicastGroup4.setAddress((239U << 24) | (r[1] & 0xffffff)); + + qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6; + if (EmulationDetector::isRunningArmOnX86()) QSKIP("This test is unreliable due to QEMU emulation shortcomings."); } @@ -1232,9 +1248,9 @@ void tst_QUdpSocket::multicastLoopbackOption() void tst_QUdpSocket::multicastJoinBeforeBind_data() { QTest::addColumn("groupAddress"); - QTest::newRow("valid ipv4 group address") << QHostAddress("239.255.118.62"); + QTest::newRow("valid ipv4 group address") << multicastGroup4; QTest::newRow("invalid ipv4 group address") << QHostAddress(QHostAddress::Broadcast); - QTest::newRow("valid ipv6 group address") << QHostAddress("FF01::114"); + QTest::newRow("valid ipv6 group address") << multicastGroup6; QTest::newRow("invalid ipv6 group address") << QHostAddress(QHostAddress::AnyIPv6); } @@ -1254,8 +1270,8 @@ void tst_QUdpSocket::multicastJoinBeforeBind() void tst_QUdpSocket::multicastLeaveAfterClose_data() { QTest::addColumn("groupAddress"); - QTest::newRow("ipv4") << QHostAddress("239.255.118.62"); - QTest::newRow("ipv6") << QHostAddress("FF01::114"); + QTest::newRow("ipv4") << multicastGroup4; + QTest::newRow("ipv6") << multicastGroup6; } void tst_QUdpSocket::multicastLeaveAfterClose() @@ -1342,9 +1358,9 @@ void tst_QUdpSocket::setMulticastInterface() void tst_QUdpSocket::multicast_data() { QHostAddress anyAddress = QHostAddress(QHostAddress::AnyIPv4); - QHostAddress groupAddress = QHostAddress("239.255.118.62"); + QHostAddress groupAddress = multicastGroup4; QHostAddress any6Address = QHostAddress(QHostAddress::AnyIPv6); - QHostAddress group6Address = QHostAddress("FF01::114"); + QHostAddress group6Address = multicastGroup6; QHostAddress dualAddress = QHostAddress(QHostAddress::Any); QTest::addColumn("bindAddress"); -- cgit v1.2.3 From 3d7cdb64fca260b303b44263312af3eb65eb175e Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 22 Dec 2017 18:13:46 -0200 Subject: qfloat16: NaN is not infinite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I39332e0a867442d58082fffd1502b7010424f0f8 Reviewed-by: André Hartmann Reviewed-by: Allan Sandfeld Jensen --- tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp index 9bd87e3f21..6b98e3a823 100644 --- a/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp +++ b/tests/auto/corelib/global/qfloat16/tst_qfloat16.cpp @@ -158,12 +158,14 @@ void tst_qfloat16::qNan() qfloat16 nan = qQNaN(); QVERIFY(!(0. > nan)); QVERIFY(!(0. < nan)); + QVERIFY(!qIsInf(nan)); QVERIFY(qIsNaN(nan)); QVERIFY(qIsNaN(nan + 1.f)); QVERIFY(qIsNaN(-nan)); qfloat16 inf = qInf(); QVERIFY(inf > qfloat16(0)); QVERIFY(-inf < qfloat16(0)); + QVERIFY(!qIsNaN(inf)); QVERIFY(qIsInf(inf)); QVERIFY(qIsInf(-inf)); QVERIFY(qIsInf(2.f*inf)); -- cgit v1.2.3 From 597b96b8fa2fc8b9331db8ecc85d742be83fbec5 Mon Sep 17 00:00:00 2001 From: Joni Jantti Date: Fri, 22 Dec 2017 09:39:06 +0200 Subject: Blacklist tst_QDateTime::operator_eqeq MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This autotest fails on the new Ubuntu 16.04 template with UTC timezone in the system settings. Task-number: QTBUG-65435 Change-Id: I397f01ab3fed354a4eeec8b05415226a75fce5a1 Reviewed-by: Tony Sarajärvi --- tests/auto/corelib/tools/qdatetime/BLACKLIST | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/auto/corelib/tools/qdatetime/BLACKLIST (limited to 'tests') diff --git a/tests/auto/corelib/tools/qdatetime/BLACKLIST b/tests/auto/corelib/tools/qdatetime/BLACKLIST new file mode 100644 index 0000000000..e78f5cfd87 --- /dev/null +++ b/tests/auto/corelib/tools/qdatetime/BLACKLIST @@ -0,0 +1,3 @@ +[operator_eqeq] +ubuntu-16.04 +b2qt -- cgit v1.2.3 From e548406d2820b066bdc66c1080976c7710353ae8 Mon Sep 17 00:00:00 2001 From: Joni Jantti Date: Fri, 22 Dec 2017 12:07:13 +0200 Subject: Blacklist tst_QUdpSocket on Ubuntu 16.04 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tst_QUdpSocket::broadcasting and tst_QUdpSocket::pendingDatagramSize fail on the new Ubuntu 16.04 clean template. Task-number: QTBUG-65440 Change-Id: I0e973b9c90b7c5827406bac8138370b61992a115 Reviewed-by: Tony Sarajärvi --- tests/auto/network/socket/qudpsocket/BLACKLIST | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/BLACKLIST b/tests/auto/network/socket/qudpsocket/BLACKLIST index 5adb05d3f2..3951be16ab 100644 --- a/tests/auto/network/socket/qudpsocket/BLACKLIST +++ b/tests/auto/network/socket/qudpsocket/BLACKLIST @@ -22,7 +22,12 @@ osx osx [broadcasting] osx +ubuntu-16.04 [zeroLengthDatagram] osx [linkLocalIPv6] redhatenterpriselinuxworkstation-6.6 +[pendingDatagramSize] +ubuntu-16.04 +[readyReadForEmptyDatagram] +ubuntu-16.04 -- cgit v1.2.3 From 198c59dbce63e97ef0fa8f75236ee8b2887997c2 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 28 Nov 2017 16:49:00 -0800 Subject: tst_QUdpSocket: always use an interface when binding to IPv6 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Binding without an interface and expecting the OS to select something is not supported in all OSes. On FreeBSD, I keep getting EADDRNOTAVAIL. So modify our test to only join, leave and send to multicast groups with an interface selection. With this, all tests either pass or are skipped for me on Linux, FreeBSD, and macOS. On Windows, this revealed an inconsistency in behavior, which this commit adds a workaround for. Change-Id: Ifb5969bf206e4cd7b14efffd14fb6815456494d2 Reviewed-by: Mårten Nordheim Reviewed-by: Timur Pocheptsov --- tests/auto/network/socket/qudpsocket/BLACKLIST | 2 -- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 39 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/BLACKLIST b/tests/auto/network/socket/qudpsocket/BLACKLIST index dcb5f87628..5b8d4f1e34 100644 --- a/tests/auto/network/socket/qudpsocket/BLACKLIST +++ b/tests/auto/network/socket/qudpsocket/BLACKLIST @@ -1,5 +1,3 @@ -[multicast] -osx [writeDatagramToNonExistingPeer] windows osx diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 69d549d738..5fdf014fc6 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -122,6 +122,7 @@ private: #ifdef SHOULD_CHECK_SYSCALL_SUPPORT bool ipv6SetsockoptionMissing(int level, int optname); #endif + QNetworkInterface interfaceForGroup(const QHostAddress &multicastGroup); bool m_skipUnsupportedIPv6Tests; QList allAddresses; @@ -167,6 +168,33 @@ bool tst_QUdpSocket::shouldSkipIpv6TestsForBrokenSetsockopt() return false; } +QNetworkInterface tst_QUdpSocket::interfaceForGroup(const QHostAddress &multicastGroup) +{ + if (multicastGroup.protocol() == QAbstractSocket::IPv4Protocol) + return QNetworkInterface(); + + static QNetworkInterface ipv6if = [=]() { + // find any link local address in the allAddress list + for (const QHostAddress &addr: qAsConst(allAddresses)) { + if (addr.isLoopback()) + continue; + + QString scope = addr.scopeId(); + if (!scope.isEmpty()) { + QNetworkInterface iface = QNetworkInterface::interfaceFromName(scope); + qDebug() << "Will bind IPv6 sockets to" << iface; + return iface; + } + } + + qWarning("interfaceForGroup(%s) could not find any link-local IPv6 address! " + "Make sure this test is behind a check of QtNetworkSettings::hasIPv6().", + qUtf8Printable(multicastGroup.toString())); + return QNetworkInterface(); + }(); + return ipv6if; +} + static QHostAddress makeNonAny(const QHostAddress &address, QHostAddress::SpecialAddress preferForAny = QHostAddress::LocalHost) { if (address == QHostAddress::Any) @@ -1299,7 +1327,7 @@ void tst_QUdpSocket::multicastLeaveAfterClose() bindAddress = QHostAddress::AnyIPv6; QVERIFY2(udpSocket.bind(bindAddress, 0), qPrintable(udpSocket.errorString())); - QVERIFY2(udpSocket.joinMulticastGroup(groupAddress), + QVERIFY2(udpSocket.joinMulticastGroup(groupAddress, interfaceForGroup(groupAddress)), qPrintable(udpSocket.errorString())); udpSocket.close(); QTest::ignoreMessage(QtWarningMsg, "QUdpSocket::leaveMulticastGroup() called on a QUdpSocket when not in QUdpSocket::BoundState"); @@ -1413,7 +1441,7 @@ void tst_QUdpSocket::multicast() "QAbstractSocket: cannot bind to QHostAddress::Any (or an IPv6 address) and join an IPv4 multicast group;" " bind to QHostAddress::AnyIPv4 instead if you want to do this"); } - QVERIFY2(receiver.joinMulticastGroup(groupAddress) == joinResult, + QVERIFY2(receiver.joinMulticastGroup(groupAddress, interfaceForGroup(groupAddress)) == joinResult, qPrintable(receiver.errorString())); if (!joinResult) return; @@ -1427,7 +1455,9 @@ void tst_QUdpSocket::multicast() QUdpSocket sender; sender.bind(); foreach (const QByteArray &datagram, datagrams) { - QCOMPARE(int(sender.writeDatagram(datagram, groupAddress, receiver.localPort())), + QNetworkDatagram dgram(datagram, groupAddress, receiver.localPort()); + dgram.setInterfaceIndex(interfaceForGroup(groupAddress).index()); + QCOMPARE(int(sender.writeDatagram(dgram)), int(datagram.size())); } @@ -1452,7 +1482,8 @@ void tst_QUdpSocket::multicast() } QCOMPARE(receivedDatagrams, datagrams); - QVERIFY2(receiver.leaveMulticastGroup(groupAddress), qPrintable(receiver.errorString())); + QVERIFY2(receiver.leaveMulticastGroup(groupAddress, interfaceForGroup(groupAddress)), + qPrintable(receiver.errorString())); } void tst_QUdpSocket::echo_data() -- cgit v1.2.3 From dd61a1d98ea9fbffeaf0e2adcd0ddd58105f6a75 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 29 Nov 2017 10:18:01 -0800 Subject: tst_QUdpSocket: add some tests for link-local IPv6 multicasting Unlike higher scopes (like scope 4, admin-local, which the last commit used), scopes 1 and 2 require a scope in order to bind, even if some operating systems are lenient. So test that we are able to bind to them and do bind properly. Change-Id: Ifb5969bf206e4cd7b14efffd14fba153eab965b9 Reviewed-by: Edward Welbourne Reviewed-by: Timur Pocheptsov --- .../network/socket/qudpsocket/tst_qudpsocket.cpp | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 5fdf014fc6..4e800dfd63 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -127,6 +127,7 @@ private: bool m_skipUnsupportedIPv6Tests; QList allAddresses; QHostAddress multicastGroup4, multicastGroup6; + QVector linklocalMulticastGroups; QUdpSocket *m_asyncSender; QUdpSocket *m_asyncReceiver; }; @@ -173,6 +174,10 @@ QNetworkInterface tst_QUdpSocket::interfaceForGroup(const QHostAddress &multicas if (multicastGroup.protocol() == QAbstractSocket::IPv4Protocol) return QNetworkInterface(); + QString scope = multicastGroup.scopeId(); + if (!scope.isEmpty()) + return QNetworkInterface::interfaceFromName(scope); + static QNetworkInterface ipv6if = [=]() { // find any link local address in the allAddress list for (const QHostAddress &addr: qAsConst(allAddresses)) { @@ -250,7 +255,19 @@ void tst_QUdpSocket::initTestCase() // 239.0.0.0/8 is "Organization-Local Scope" multicastGroup4.setAddress((239U << 24) | (r[1] & 0xffffff)); - qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6; + // figure out some link-local IPv6 multicast groups + // ff12:: is temporary, not prefix-based, link-local + r[0] = qToBigEndian(Q_UINT64_C(0xff12) << 48); + QHostAddress llbase(*reinterpret_cast(&r)); + for (const QHostAddress &a : qAsConst(allAddresses)) { + QString scope = a.scopeId(); + if (scope.isEmpty()) + continue; + llbase.setScopeId(scope); + linklocalMulticastGroups << llbase; + } + + qDebug() << "Will use multicast groups" << multicastGroup4 << multicastGroup6 << linklocalMulticastGroups; if (EmulationDetector::isRunningArmOnX86()) QSKIP("This test is unreliable due to QEMU emulation shortcomings."); @@ -1279,6 +1296,8 @@ void tst_QUdpSocket::multicastJoinBeforeBind_data() QTest::newRow("valid ipv4 group address") << multicastGroup4; QTest::newRow("invalid ipv4 group address") << QHostAddress(QHostAddress::Broadcast); QTest::newRow("valid ipv6 group address") << multicastGroup6; + for (const QHostAddress &a : qAsConst(linklocalMulticastGroups)) + QTest::addRow("valid ipv6 %s-link group address", a.scopeId().toLatin1().constData()) << a; QTest::newRow("invalid ipv6 group address") << QHostAddress(QHostAddress::AnyIPv6); } @@ -1300,6 +1319,8 @@ void tst_QUdpSocket::multicastLeaveAfterClose_data() QTest::addColumn("groupAddress"); QTest::newRow("ipv4") << multicastGroup4; QTest::newRow("ipv6") << multicastGroup6; + for (const QHostAddress &a : qAsConst(linklocalMulticastGroups)) + QTest::addRow("ipv6-link-%s", a.scopeId().toLatin1().constData()) << a; } void tst_QUdpSocket::multicastLeaveAfterClose() @@ -1398,9 +1419,15 @@ void tst_QUdpSocket::multicast_data() QTest::newRow("valid bind, group ipv4 address") << anyAddress << true << groupAddress << true; QTest::newRow("valid bind, invalid group ipv4 address") << anyAddress << true << anyAddress << false; QTest::newRow("valid bind, group ipv6 address") << any6Address << true << group6Address << true; + for (const QHostAddress &a : qAsConst(linklocalMulticastGroups)) + QTest::addRow("valid bind, %s-link group ipv6 address", a.scopeId().toLatin1().constData()) + << any6Address << true << a << true; QTest::newRow("valid bind, invalid group ipv6 address") << any6Address << true << any6Address << false; QTest::newRow("dual bind, group ipv4 address") << dualAddress << true << groupAddress << false; QTest::newRow("dual bind, group ipv6 address") << dualAddress << true << group6Address << true; + for (const QHostAddress &a : qAsConst(linklocalMulticastGroups)) + QTest::addRow("dual bind, %s-link group ipv6 address", a.scopeId().toLatin1().constData()) + << dualAddress << true << a << true; } void tst_QUdpSocket::multicast() -- cgit v1.2.3