From 7cf8c993c7d8702032a1d17425b2a261c9a56d6f Mon Sep 17 00:00:00 2001 From: Dimitrios Apostolou Date: Tue, 3 Dec 2019 17:42:14 +0100 Subject: Fix flaky test tst_QFiledialog::clearLineEdit() Task-number: QTBUG-76989 Change-Id: I3ec7f65500476346e1a8f1017c6452517a660860 Reviewed-by: Friedemann Kleint --- tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index 2131e45f29..26cf3c63f3 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -1377,6 +1377,7 @@ void tst_QFiledialog::clearLineEdit() fd.setFileMode(QFileDialog::AnyFile); fd.show(); + QVERIFY(QTest::qWaitForWindowExposed(&fd)); QLineEdit *lineEdit = fd.findChild("fileNameEdit"); QVERIFY(lineEdit); QCOMPARE(lineEdit->text(), QLatin1String("foo")); -- cgit v1.2.3 From 1f592da7f175aa75726eece2fab8f5c1edde193f Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 26 Nov 2019 07:21:55 -0800 Subject: QCborValue: fix replacing of elements with byte data with ones without We forgot to reset the flags when replacing the element, so we ended up with an integer with HasByteData after: testMap[0] = QStringLiteral("value"); testMap[0] = 42; Fixes: QTBUG-80342 Change-Id: Ia2aa807ffa8a4c798425fffd15dabfa066ea84b0 Reviewed-by: Ulf Hermann --- .../serialization/qcborvalue/tst_qcborvalue.cpp | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 47ad328d64..8deb780dd0 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -821,9 +821,37 @@ void tst_QCborValue::mapMutation() QVERIFY(v.isUndefined()); // now mutate the list + // simple -> HasByteData + const QString strValue = QStringLiteral("value"); + v = strValue; + QVERIFY(v.isString()); + QCOMPARE(v, QCborValue(strValue)); + QCOMPARE(m, QCborMap({{42, strValue}})); + + // HasByteData -> HasByteData + const QLatin1String otherStrValue("othervalue"); + v = otherStrValue; + QVERIFY(v.isString()); + QCOMPARE(v, QCborValue(otherStrValue)); + QCOMPARE(m, QCborMap({{42, otherStrValue}})); + + // HasByteData -> simple + v = 42; + QVERIFY(v.isInteger()); + QCOMPARE(v, QCborValue(42)); + QCOMPARE(m, QCborMap({{42, 42}})); + + // simple -> container + v = QCborArray{1, 2, 3}; + QVERIFY(v.isArray()); + QCOMPARE(v, QCborArray({1, 2, 3})); + QCOMPARE(m, QCborMap({{42, QCborArray{1, 2, 3}}})); + + // container -> simple v = true; QVERIFY(v.isBool()); QVERIFY(v.isTrue()); + QCOMPARE(m, QCborMap({{42, true}})); QVERIFY(m.begin()->isTrue()); QVERIFY(m.begin().value() == v); QVERIFY(v == m.begin().value()); -- cgit v1.2.3 From 81459dd9c05f057981ddf2db0c2302030a73cb01 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Wed, 4 Dec 2019 10:57:08 +0100 Subject: Copy formatting attributes when cloning an empty QTextDocument When cloning a QTextDocument, the text fragment of the original document is copied into the new one, which results into copying also the formatting attributes. However, when the text document is empty, the corresponding text fragment is also empty, so nothing is copied. If we want to transfer the formatting attributes for an empty document, we need to set them explicitly. Fixes: QTBUG-80399 Change-Id: I382cd0821723436120af47c06ec7bfa849636307 Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Eirik Aavitsland --- .../gui/text/qtextdocument/tst_qtextdocument.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 52e56feb5a..33d4976b2a 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -125,6 +125,7 @@ private slots: void clonePreservesResources(); void clonePreservesUserStates(); void clonePreservesIndentWidth(); + void clonePreservesFormatsWhenEmpty(); void blockCount(); void defaultStyleSheet(); @@ -2342,6 +2343,32 @@ void tst_QTextDocument::clonePreservesIndentWidth() delete clone; } +void tst_QTextDocument::clonePreservesFormatsWhenEmpty() +{ + QTextDocument document; + QTextCursor cursor(&document); + + // Change a few char format attributes + QTextCharFormat charFormat; + charFormat.setFontPointSize(charFormat.fontPointSize() + 1); + charFormat.setFontWeight(charFormat.fontWeight() + 1); + cursor.setBlockCharFormat(charFormat); + + // Change a few block format attributes + QTextBlockFormat blockFormat; + blockFormat.setAlignment(Qt::AlignRight); // The default is Qt::AlignLeft + blockFormat.setIndent(blockFormat.indent() + 1); + cursor.setBlockFormat(blockFormat); + + auto clone = document.clone(); + QTextCursor cloneCursor(clone); + + QCOMPARE(cloneCursor.blockCharFormat().fontPointSize(), charFormat.fontPointSize()); + QCOMPARE(cloneCursor.blockCharFormat().fontWeight(), charFormat.fontWeight()); + QCOMPARE(cloneCursor.blockFormat().alignment(), blockFormat.alignment()); + QCOMPARE(cloneCursor.blockFormat().indent(), blockFormat.indent()); +} + void tst_QTextDocument::blockCount() { QCOMPARE(doc->blockCount(), 1); -- cgit v1.2.3 From 49063c34d6314c59ec9529550e0639832796372e Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 18 Nov 2019 13:51:01 +0100 Subject: Fix crash when a date-time has an invalid time-zone QDateTime is a friend of QTimeZone, so can access its internals; but it must check the zone is valid before doing so. Expanded tst_QDateTime::invalid() and made it data-driven to catch the failure cases. Commented on a test-case that caught a mistake in my first attempt at this, and on QDateTimeParser's surprising reliance on a quirk of QDateTime::toMSecsSinceEpoch()'s behavior. Fixes: QTBUG-80146 Change-Id: I24856e19ff9bf402152d17d71f83be84e366faad Reviewed-by: Alex Blasche --- .../auto/corelib/time/qdatetime/tst_qdatetime.cpp | 52 ++++++++++++++++------ 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 7f13fd0aa5..c628d2b241 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -150,6 +150,7 @@ private slots: void timeZones() const; void systemTimeZoneChange() const; + void invalid_data() const; void invalid() const; void range() const; @@ -2458,6 +2459,7 @@ void tst_QDateTime::fromStringStringFormat_data() if (southBrazil.isValid()) { QTest::newRow("spring-forward-midnight") << QString("2008-10-19 23:45.678 America/Sao_Paulo") << QString("yyyy-MM-dd mm:ss.zzz t") + // That's in the hour skipped - expect the matching time after the spring-forward, in DST: << QDateTime(QDate(2008, 10, 19), QTime(1, 23, 45, 678), southBrazil); } #endif @@ -3359,6 +3361,9 @@ void tst_QDateTime::timeZones() const QCOMPARE(utc.date(), utcDst.date()); QCOMPARE(utc.time(), utcDst.time()); + // Crash test, QTBUG-80146: + QVERIFY(!nzStd.toTimeZone(QTimeZone()).isValid()); + // Sydney is 2 hours behind New Zealand QTimeZone ausTz = QTimeZone("Australia/Sydney"); QDateTime aus = nzStd.toTimeZone(ausTz); @@ -3528,23 +3533,42 @@ void tst_QDateTime::systemTimeZoneChange() const QCOMPARE(tzDate.toMSecsSinceEpoch(), tzMsecs); } -void tst_QDateTime::invalid() const +void tst_QDateTime::invalid_data() const { - QDateTime invalidDate = QDateTime(QDate(0, 0, 0), QTime(-1, -1, -1)); - QCOMPARE(invalidDate.isValid(), false); - QCOMPARE(invalidDate.timeSpec(), Qt::LocalTime); - - QDateTime utcDate = invalidDate.toUTC(); - QCOMPARE(utcDate.isValid(), false); - QCOMPARE(utcDate.timeSpec(), Qt::UTC); + QTest::addColumn("when"); + QTest::addColumn("spec"); + QTest::addColumn("goodZone"); + QTest::newRow("default") << QDateTime() << Qt::LocalTime << true; - QDateTime offsetDate = invalidDate.toOffsetFromUtc(3600); - QCOMPARE(offsetDate.isValid(), false); - QCOMPARE(offsetDate.timeSpec(), Qt::OffsetFromUTC); + QDateTime invalidDate = QDateTime(QDate(0, 0, 0), QTime(-1, -1, -1)); + QTest::newRow("simple") << invalidDate << Qt::LocalTime << true; + QTest::newRow("UTC") << invalidDate.toUTC() << Qt::UTC << true; + QTest::newRow("offset") + << invalidDate.toOffsetFromUtc(3600) << Qt::OffsetFromUTC << true; + QTest::newRow("CET") + << invalidDate.toTimeZone(QTimeZone("Europe/Oslo")) << Qt::TimeZone << true; + + // Crash tests, QTBUG-80146: + QTest::newRow("nozone+construct") + << QDateTime(QDate(1970, 1, 1), QTime(12, 0), QTimeZone()) << Qt::TimeZone << false; + QTest::newRow("nozone+fromMSecs") + << QDateTime::fromMSecsSinceEpoch(42, QTimeZone()) << Qt::TimeZone << false; + QDateTime valid(QDate(1970, 1, 1), QTime(12, 0), Qt::UTC); + QTest::newRow("tonozone") << valid.toTimeZone(QTimeZone()) << Qt::TimeZone << false; +} - QDateTime tzDate = invalidDate.toTimeZone(QTimeZone("Europe/Oslo")); - QCOMPARE(tzDate.isValid(), false); - QCOMPARE(tzDate.timeSpec(), Qt::TimeZone); +void tst_QDateTime::invalid() const +{ + QFETCH(QDateTime, when); + QFETCH(Qt::TimeSpec, spec); + QFETCH(bool, goodZone); + QVERIFY(!when.isValid()); + QCOMPARE(when.timeSpec(), spec); + QCOMPARE(when.timeZoneAbbreviation(), QString()); + if (!goodZone) + QCOMPARE(when.toMSecsSinceEpoch(), 0); + QVERIFY(!when.isDaylightTime()); + QCOMPARE(when.timeZone().isValid(), goodZone); } void tst_QDateTime::range() const -- cgit v1.2.3 From 653c1aab185fe59a523f16ffe0cf7b9173c2ff68 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 2 Dec 2019 12:55:31 +0100 Subject: Fix handling of trailing space at the end of an ISO date-time If milliseconds were followed by a space, the space was included in the count of "digits" read as the fractional part; since we read (up to) four digits (so that we round correctly if extras are given), a harmless apce could cause scaling down by too large a power of ten. Since QString::toInt() ignores leading space, we were also allowing interior space at the start of the milliseconds, which we should not, so catch that at the same time. Added tests, including one for the rounding that's the reason for reading the extra digit, when present. Fixes: QTBUG-80445 Change-Id: I606b29a94818a101f45c8b59a0f5d1f78893d78f Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index c628d2b241..029ca0aabd 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2210,6 +2210,13 @@ void tst_QDateTime::fromStringDateFormat_data() << Qt::TextDate << QDateTime(QDate(2013, 5, 6), QTime(1, 2, 3, 456)); // Test Qt::ISODate format. + QTest::newRow("trailing space") // QTBUG-80445 + << QString("2000-01-02 03:04:05.678 ") + << Qt::ISODate << QDateTime(QDate(2000, 1, 2), QTime(3, 4, 5, 678)); + QTest::newRow("space before millis") + << QString("2000-01-02 03:04:05. 678") << Qt::ISODate << QDateTime(); + + // Normal usage: QTest::newRow("ISO +01:00") << QString::fromLatin1("1987-02-13T13:24:51+01:00") << Qt::ISODate << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC); QTest::newRow("ISO +00:01") << QString::fromLatin1("1987-02-13T13:24:51+00:01") @@ -2233,8 +2240,12 @@ void tst_QDateTime::fromStringDateFormat_data() // No time specified - defaults to Qt::LocalTime. QTest::newRow("ISO data3") << QString::fromLatin1("2002-10-01") << Qt::ISODate << QDateTime(QDate(2002, 10, 1), QTime(0, 0, 0, 0), Qt::LocalTime); + // Excess digits in milliseconds, round correctly: QTest::newRow("ISO") << QString::fromLatin1("2005-06-28T07:57:30.0010000000Z") << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 1), Qt::UTC); + QTest::newRow("ISO rounding") << QString::fromLatin1("2005-06-28T07:57:30.0015Z") + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC); + // ... and accept comma as separator: QTest::newRow("ISO with comma 1") << QString::fromLatin1("2005-06-28T07:57:30,0040000000Z") << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 4), Qt::UTC); QTest::newRow("ISO with comma 2") << QString::fromLatin1("2005-06-28T07:57:30,0015Z") -- cgit v1.2.3 From 6b5f848ebd007e71f0ae5d81e834f5a2a5765aac Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 3 Dec 2019 11:17:31 +0100 Subject: Allow lower-case for the T and Z in ISO 8601 date format Cite RFC 3339 as basis for allowing a space in place of the T, too. The RFC mentions that ISO 8601 accepts t and z for T and Z, so test for them case-insensitively. Add a test for this. Change-Id: Iba700c8d74d485df154d27300aab7b1958e1ccef Reviewed-by: Thiago Macieira --- tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index 029ca0aabd..7778542736 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -2237,6 +2237,8 @@ void tst_QDateTime::fromStringDateFormat_data() << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9), Qt::UTC); QTest::newRow("ISO zzz-3") << QString::fromLatin1("2014-12-15T12:37:09.745-3") << Qt::ISODate << QDateTime(QDate(2014, 12, 15), QTime(15, 37, 9, 745), Qt::UTC); + QTest::newRow("ISO lower-case") << QString::fromLatin1("2005-06-28T07:57:30.002z") + << Qt::ISODate << QDateTime(QDate(2005, 6, 28), QTime(7, 57, 30, 2), Qt::UTC); // No time specified - defaults to Qt::LocalTime. QTest::newRow("ISO data3") << QString::fromLatin1("2002-10-01") << Qt::ISODate << QDateTime(QDate(2002, 10, 1), QTime(0, 0, 0, 0), Qt::LocalTime); -- cgit v1.2.3 From 29adc0eed9b9dc3cce92f8acaaeaed3ab1bc6414 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Thu, 5 Dec 2019 16:45:31 +0100 Subject: Fix updating the text cursor position after editing In some cases when editing the text (for example when removing the selected text, or pasting a text block) the text cursor position is updated, but its visual x position is not updated. This causes the next cursor movements to start from a wrong position. Force the update for those cases. Fixes: QTBUG-78479 Change-Id: Ia496be62beec58660f5e1695e5aafae09c79684e Reviewed-by: Christian Ehrlicher --- .../widgets/qplaintextedit/tst_qplaintextedit.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp index 2ce75620cf..2faa02e284 100644 --- a/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp +++ b/tests/auto/widgets/widgets/qplaintextedit/tst_qplaintextedit.cpp @@ -155,6 +155,7 @@ private slots: #if QT_CONFIG(scrollbar) void updateAfterChangeCenterOnScroll(); #endif + void updateCursorPositionAfterEdit(); private: void createSelection(); @@ -1789,5 +1790,50 @@ void tst_QPlainTextEdit::updateAfterChangeCenterOnScroll() #endif +void tst_QPlainTextEdit::updateCursorPositionAfterEdit() +{ + QPlainTextEdit plaintextEdit; + plaintextEdit.setPlainText("some text some text\nsome text some text"); + + const auto initialPosition = 1; + + // select some text + auto cursor = plaintextEdit.textCursor(); + cursor.setPosition(initialPosition, QTextCursor::MoveAnchor); + cursor.setPosition(initialPosition + 3, QTextCursor::KeepAnchor); + plaintextEdit.setTextCursor(cursor); + QVERIFY(plaintextEdit.textCursor().hasSelection()); + + QTest::keyClick(&plaintextEdit, Qt::Key_Delete); + QTest::keyClick(&plaintextEdit, Qt::Key_Down); + QTest::keyClick(&plaintextEdit, Qt::Key_Up); + + // Moving the cursor down and up should bring it to the initial position + QCOMPARE(plaintextEdit.textCursor().position(), initialPosition); + + // Test the same with backspace + cursor = plaintextEdit.textCursor(); + cursor.setPosition(initialPosition + 3, QTextCursor::KeepAnchor); + plaintextEdit.setTextCursor(cursor); + QVERIFY(plaintextEdit.textCursor().hasSelection()); + + QTest::keyClick(&plaintextEdit, Qt::Key_Backspace); + QTest::keyClick(&plaintextEdit, Qt::Key_Down); + QTest::keyClick(&plaintextEdit, Qt::Key_Up); + + // Moving the cursor down and up should bring it to the initial position + QCOMPARE(plaintextEdit.textCursor().position(), initialPosition); + + // Test insertion + const QString txt("txt"); + QApplication::clipboard()->setText(txt); + plaintextEdit.paste(); + QTest::keyClick(&plaintextEdit, Qt::Key_Down); + QTest::keyClick(&plaintextEdit, Qt::Key_Up); + + // The curser should move back to the end of the copied text + QCOMPARE(plaintextEdit.textCursor().position(), initialPosition + txt.length()); +} + QTEST_MAIN(tst_QPlainTextEdit) #include "tst_qplaintextedit.moc" -- cgit v1.2.3 From c4b0ff4855e81aa8017664a2f1a4353b274c27fd Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 5 Dec 2019 16:02:56 -0800 Subject: tst_QNetworkInterface: don't force an IPv4 link-local address Windows apparently has special code to deal with those addresses. If all your network interfaces are up and have acquired addresses, then the link-local network at 169.254.0.0/16 is unreachable. I had never caught this because both my Windows VM and my bare metal Windows have inactive interfaces (like the Bluetooth PAN one) and, when inactive, Windows assigns a link-local address. But in the CI, the interface(s) were all up and running, causing this issue. Unix systems don't treat IPv4 link-local any differently, so they always worked, so long as any interface was up and there had to be one to reach the network test server. This commit reworks the test to add test addresses based on the addresses found on up & running interfaces (see tst_qudpsocket.cpp). For IPv4, we flip the bits in the local portion of the address. For IPv6, we add a node with an address I generated randomly (non-universal), with the same scope. Fixes: QTBUG-65667 Change-Id: I568dea4813b448fe9ba6fffd15dd9f482db34991 Reviewed-by: Timur Pocheptsov --- .../network/kernel/qnetworkinterface/BLACKLIST | 4 -- .../qnetworkinterface/tst_qnetworkinterface.cpp | 48 ++++++++++++++-------- 2 files changed, 31 insertions(+), 21 deletions(-) delete mode 100644 tests/auto/network/kernel/qnetworkinterface/BLACKLIST (limited to 'tests/auto') diff --git a/tests/auto/network/kernel/qnetworkinterface/BLACKLIST b/tests/auto/network/kernel/qnetworkinterface/BLACKLIST deleted file mode 100644 index 33bdf540b6..0000000000 --- a/tests/auto/network/kernel/qnetworkinterface/BLACKLIST +++ /dev/null @@ -1,4 +0,0 @@ -# QTBUG-65667 -[localAddress:linklocal-ipv4] -msvc-2015 ci -msvc-2017 ci diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp index 0c7ba99be5..bc6e5435df 100644 --- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp +++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp @@ -215,31 +215,45 @@ void tst_QNetworkInterface::loopbackIPv6() } void tst_QNetworkInterface::localAddress_data() { + bool ipv6 = isIPv6Working(); QTest::addColumn("target"); QTest::newRow("localhost-ipv4") << QHostAddress(QHostAddress::LocalHost); - if (isIPv6Working()) + if (ipv6) QTest::newRow("localhost-ipv6") << QHostAddress(QHostAddress::LocalHostIPv6); QTest::newRow("test-server") << QtNetworkSettings::serverIP(); - // Since we don't actually transmit anything, we can list any IPv4 address - // and it should work. But we're using a linklocal address so that this - // test can pass even machines that failed to reach a DHCP server. - QTest::newRow("linklocal-ipv4") << QHostAddress("169.254.0.1"); - - if (isIPv6Working()) { - // On the other hand, we can't list just any IPv6 here. It's very - // likely that this machine has not received a route via ICMPv6-RA or - // DHCPv6, so it won't have a global route. On some OSes, IPv6 may be - // enabled per interface, so we need to know which ones work. - const QList addrs = QNetworkInterface::allAddresses(); - for (const QHostAddress &addr : addrs) { - QString scope = addr.scopeId(); - if (scope.isEmpty()) + QSet added; + const QList ifaces = QNetworkInterface::allInterfaces(); + for (const QNetworkInterface &iface : ifaces) { + if ((iface.flags() & QNetworkInterface::IsUp) == 0) + continue; + const QList addrs = iface.addressEntries(); + for (const QNetworkAddressEntry &entry : addrs) { + QHostAddress addr = entry.ip(); + if (addr.isLoopback()) + continue; // added above + + if (addr.protocol() == QAbstractSocket::IPv4Protocol) { + // add an IPv4 address with bits in the host portion of the address flipped + quint32 ip4 = entry.ip().toIPv4Address(); + addr.setAddress(ip4 ^ ~entry.netmask().toIPv4Address()); + } else if (!ipv6 || entry.prefixLength() != 64) { + continue; + } else { + // add a random node in this IPv6 network + quint64 randomid = qFromBigEndian(Q_UINT64_C(0x8f41f072e5733caa)); + QIPv6Address ip6 = addr.toIPv6Address(); + memcpy(&ip6[8], &randomid, sizeof(randomid)); + addr.setAddress(ip6); + } + + if (added.contains(addr)) continue; - QTest::addRow("linklocal-ipv6-%s", qPrintable(scope)) - << QHostAddress("fe80::1234%" + scope); + added.insert(addr); + + QTest::addRow("%s-%s", qPrintable(iface.name()), qPrintable(addr.toString())) << addr; } } } -- cgit v1.2.3 From 009abcd7b66738bece6cf354776dfb2ef401636b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 8 Nov 2019 11:03:14 +0100 Subject: QWidget: React to platform surface being created or destroyed The platform window may create or destroy its surface from other entry points than the QWidget API, in which case QWidget needs to sync up its own state to match. In particular WA_WState_Created and the winId needs to be recomputed. Fixes: QTBUG-69289 Fixes: QTBUG-77350 Change-Id: I769e58ead3c2efcf8c451c363108848feade9388 Reviewed-by: Volker Hilsheimer Reviewed-by: Paul Olav Tvete --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 67fdd13652..371738ad27 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -60,6 +60,7 @@ #include #include #include +#include #include #include #include @@ -227,6 +228,7 @@ private slots: void setFixedSize(); void ensureCreated(); + void createAndDestroy(); void winIdChangeEvent(); void persistentWinId(); void showNativeChild(); @@ -4220,6 +4222,58 @@ public: int winIdChangeEventCount() const { return m_winIdList.count(); } }; +class CreateDestroyWidget : public WinIdChangeWidget +{ +public: + void create() { QWidget::create(); } + void destroy() { QWidget::destroy(); } +}; + +void tst_QWidget::createAndDestroy() +{ + CreateDestroyWidget widget; + + // Create and destroy via QWidget + widget.create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 1); + QVERIFY(widget.internalWinId()); + + widget.destroy(); + QVERIFY(!widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 2); + QVERIFY(!widget.internalWinId()); + + // Create via QWidget, destroy via QWindow + widget.create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 3); + QVERIFY(widget.internalWinId()); + + widget.windowHandle()->destroy(); + QVERIFY(!widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 4); + QVERIFY(!widget.internalWinId()); + + // Create via QWidget again + widget.create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 5); + QVERIFY(widget.internalWinId()); + + // Destroy via QWindow, create via QWindow + widget.windowHandle()->destroy(); + QVERIFY(widget.windowHandle()); + QVERIFY(!widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 6); + QVERIFY(!widget.internalWinId()); + + widget.windowHandle()->create(); + QVERIFY(widget.testAttribute(Qt::WA_WState_Created)); + QCOMPARE(widget.winIdChangeEventCount(), 7); + QVERIFY(widget.internalWinId()); +} + void tst_QWidget::winIdChangeEvent() { { -- cgit v1.2.3 From c3bd5ffdc8a3b459f18ba6e35fca93e29f3b0ab0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 8 Dec 2019 23:47:10 +0100 Subject: Don't wrap feature detection macros with QT_HAS_FOO() variants Using wrappers for these macros is problematic when for example passing the -frewrite-includes flag to preprocess sources before shipping off to distcc or Icecream. It will also start producing warnings when compilers implement http://eel.is/c++draft/cpp.cond#7.sentence-2. See for example https://reviews.llvm.org/D49091 Both https://clang.llvm.org/docs/LanguageExtensions.html and the SD-6 document at https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations recommend defining '__has_foo(x) 0' as a fallback for compilers without the macros, so that's what we go for. Change-Id: I0298cd3b4a6ff6618821e34642a5ddd6728be767 Reviewed-by: Alex Richardson Reviewed-by: Thiago Macieira --- tests/auto/corelib/global/qglobal/qglobal.c | 2 +- .../corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp | 4 ++-- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 6 +++--- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 4 ++-- .../corelib/serialization/qcborvalue/tst_qcborvalue.cpp | 2 +- tests/auto/corelib/thread/qmutex/tst_qmutex.cpp | 14 +++++++------- .../containerapisymmetry/tst_containerapisymmetry.cpp | 2 +- 7 files changed, 17 insertions(+), 17 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/global/qglobal/qglobal.c b/tests/auto/corelib/global/qglobal/qglobal.c index c7124454d0..7a2266ae94 100644 --- a/tests/auto/corelib/global/qglobal/qglobal.c +++ b/tests/auto/corelib/global/qglobal/qglobal.c @@ -28,7 +28,7 @@ #include -#if QT_HAS_INCLUDE() || __STDC_VERSION__ >= 199901L +#if __has_include() || __STDC_VERSION__ >= 199901L # include #else # undef true diff --git a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp index 4ca68550b9..4e105d7dc7 100644 --- a/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp +++ b/tests/auto/corelib/kernel/qdeadlinetimer/tst_qdeadlinetimer.cpp @@ -32,7 +32,7 @@ #include #include -#if QT_HAS_INCLUDE() +#if __has_include() # include #endif @@ -519,7 +519,7 @@ void tst_QDeadlineTimer::expire() void tst_QDeadlineTimer::stdchrono() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("std::chrono not found on this system"); #else using namespace std::chrono; diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 8e0bdac520..1bd27cd0ce 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -223,7 +223,7 @@ void tst_QTimer::remainingTimeDuringActivation() namespace { -#if QT_HAS_INCLUDE() +#if __has_include() template std::chrono::milliseconds to_ms(T t) { return std::chrono::duration_cast(t); } @@ -233,7 +233,7 @@ namespace { void tst_QTimer::basic_chrono() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires C++11 support"); #else // duplicates zeroTimer, singleShotTimeout, interval and remainingTime @@ -871,7 +871,7 @@ void tst_QTimer::singleShotToFunctors() void tst_QTimer::singleShot_chrono() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires C++11 support"); #else // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 9e0881f1a6..edb15a8db2 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -45,7 +45,7 @@ #include #include #include -#if QT_HAS_INCLUDE() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L #include #endif #include @@ -4992,7 +4992,7 @@ void tst_QVariant::accessSequentialContainerKey() void tst_QVariant::fromStdVariant() { -#if QT_HAS_INCLUDE() && __cplusplus >= 201703L +#if __has_include() && __cplusplus >= 201703L { typedef std::variant intorbool_t; intorbool_t stdvar = 5; diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp index 8deb780dd0..d5a9012f9f 100644 --- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp +++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp @@ -384,7 +384,7 @@ void tst_QCborValue::copyCompare() QCOMPARE(v, other); QVERIFY(!(v != other)); QVERIFY(!(v < other)); -#if 0 && QT_HAS_INCLUDE() +#if 0 && __has_include() QVERIFY(v <= other); QVERIFY(v >= other); QVERIFY(!(v > other)); diff --git a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp index 749aa45916..11f34343ab 100644 --- a/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp +++ b/tests/auto/corelib/thread/qmutex/tst_qmutex.cpp @@ -89,7 +89,7 @@ enum { waitTime = 100 }; -#if QT_HAS_INCLUDE() +#if __has_include() static Q_CONSTEXPR std::chrono::milliseconds waitTimeAsDuration(waitTime); #endif @@ -100,7 +100,7 @@ void tst_QMutex::convertToMilliseconds_data() QTest::addColumn("intValue"); QTest::addColumn("expected"); -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #endif @@ -156,7 +156,7 @@ void tst_QMutex::convertToMilliseconds_data() void tst_QMutex::convertToMilliseconds() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else QFETCH(TimeUnit, unit); @@ -325,7 +325,7 @@ void tst_QMutex::tryLock_non_recursive() } void tst_QMutex::try_lock_for_non_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread @@ -454,7 +454,7 @@ void tst_QMutex::try_lock_for_non_recursive() { void tst_QMutex::try_lock_until_non_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread @@ -707,7 +707,7 @@ void tst_QMutex::tryLock_recursive() void tst_QMutex::try_lock_for_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread @@ -836,7 +836,7 @@ void tst_QMutex::try_lock_for_recursive() void tst_QMutex::try_lock_until_recursive() { -#if !QT_HAS_INCLUDE() +#if !__has_include() QSKIP("This test requires "); #else class Thread : public QThread diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 4b085d387d..88c0c5055c 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -51,7 +51,7 @@ #ifdef Q_CC_MSVC #define COMPILER_HAS_STDLIB_INCLUDE(x) 1 #else -#define COMPILER_HAS_STDLIB_INCLUDE(x) QT_HAS_INCLUDE(x) +#define COMPILER_HAS_STDLIB_INCLUDE(x) __has_include(x) #endif #if COMPILER_HAS_STDLIB_INCLUDE() -- cgit v1.2.3 From 5231c26a82a7056f98d99643850754d4e1ebe417 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Sat, 7 Dec 2019 20:39:12 +0100 Subject: tst_QSqlQuery: fix some tests Fix some tests in tst_QSqlQuery: - make sure to use QSql::HighPrecision in tst_QSqlQuery::precision() (needed for psql) - remove outdated stuff for mysql 3.x - psql_bindWithDoubleColonCastOperator: the placeholder are stored as named placeholders in psql - avoid some useless old-style casts Change-Id: I54d29a7e24f17d853cce6baa09a67d9278098810 Reviewed-by: Robert Szefner Reviewed-by: Andy Shaw --- tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp | 75 +++++++++++------------ 1 file changed, 36 insertions(+), 39 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index c75767a513..3b127b7e74 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -972,9 +972,7 @@ void tst_QSqlQuery::blob() //don' make it too big otherwise sybase and mysql will complain QByteArray ba( BLOBSIZE, 0 ); - int i; - - for ( i = 0; i < ( int )ba.size(); ++i ) + for (int i = 0; i < ba.size(); ++i) ba[i] = i % 256; QSqlQuery q( db ); @@ -987,7 +985,7 @@ void tst_QSqlQuery::blob() QVERIFY_SQL(q, prepare("insert into " + qTableName("qtest_blob", __FILE__, db) + " (id, t_blob) values (?, ?)")); - for ( i = 0; i < BLOBCOUNT; ++i ) { + for (int i = 0; i < BLOBCOUNT; ++i) { q.addBindValue( i ); q.addBindValue( ba ); QVERIFY_SQL( q, exec() ); @@ -995,13 +993,13 @@ void tst_QSqlQuery::blob() QVERIFY_SQL(q, exec("select * from " + qTableName("qtest_blob", __FILE__, db))); - for ( i = 0; i < BLOBCOUNT; ++i ) { + for (int i = 0; i < BLOBCOUNT; ++i) { QVERIFY( q.next() ); QByteArray res = q.value( 1 ).toByteArray(); QVERIFY2( res.size() >= ba.size(), QString( "array sizes differ, expected %1, got %2" ).arg( ba.size() ).arg( res.size() ).toLatin1() ); - for ( int i2 = 0; i2 < ( int )ba.size(); ++i2 ) { + for (int i2 = 0; i2 < ba.size(); ++i2) { if ( res[i2] != ba[i2] ) QFAIL( QString( "ByteArrays differ at position %1, expected %2, got %3" ).arg( i2 ).arg(( int )( unsigned char )ba[i2] ).arg(( int )( unsigned char )res[i2] ).toLatin1() ); @@ -1841,7 +1839,7 @@ void tst_QSqlQuery::oci_rawField() } // test whether we can fetch values with more than DOUBLE precision -// note that MySQL's 3.x highest precision is that of a double, although +// note that SQLite highest precision is that of a double, although // you can define field with higher precision void tst_QSqlQuery::precision() { @@ -1852,45 +1850,41 @@ void tst_QSqlQuery::precision() if (dbType == QSqlDriver::Interbase) QSKIP("DB unable to store high precision"); + const auto oldPrecision = db.driver()->numericalPrecisionPolicy(); + db.driver()->setNumericalPrecisionPolicy(QSql::HighPrecision); const QString qtest_precision(qTableName("qtest_precision", __FILE__, db)); - static const char* precStr = "1.2345678901234567891"; + static const QLatin1String precStr("1.2345678901234567891"); { // need a new scope for SQLITE QSqlQuery q( db ); q.exec("drop table " + qtest_precision); - if ( tst_Databases::isMSAccess( db ) ) - QVERIFY_SQL( q, exec( "create table " + qtest_precision + " (col1 number)" ) ); + if (tst_Databases::isMSAccess(db)) + QVERIFY_SQL(q, exec("CREATE TABLE " + qtest_precision + " (col1 number)")); else - QVERIFY_SQL( q, exec( "create table " + qtest_precision + " (col1 numeric(21, 20))" ) ); - - QVERIFY_SQL( q, exec( "insert into " + qtest_precision + " (col1) values (1.2345678901234567891)" ) ); - - QVERIFY_SQL( q, exec( "select * from " + qtest_precision ) ); - QVERIFY( q.next() ); + QVERIFY_SQL(q, exec("CREATE TABLE " + qtest_precision + " (col1 numeric(21, 20))")); - QString val = q.value( 0 ).toString(); - - if ( !val.startsWith( "1.2345678901234567891" ) ) { + QVERIFY_SQL(q, exec("INSERT INTO " + qtest_precision + " (col1) VALUES (" + precStr + ")")); + QVERIFY_SQL(q, exec("SELECT * FROM " + qtest_precision)); + QVERIFY(q.next()); + const QString val = q.value(0).toString(); + if (!val.startsWith(precStr)) { int i = 0; - - while ( precStr[i] != 0 && *( precStr + i ) == val[i].toLatin1() ) + while (i < val.size() && precStr[i] != 0 && precStr[i] == val[i].toLatin1()) i++; - // MySQL and TDS have crappy precisions by default - if (dbType == QSqlDriver::MySqlServer) { - if ( i < 17 ) - QWARN( "MySQL didn't return the right precision" ); - } else if (dbType == QSqlDriver::Sybase) { - if ( i < 18 ) - QWARN( "TDS didn't return the right precision" ); + // TDS has crappy precisions by default + if (dbType == QSqlDriver::Sybase) { + if (i < 18) + QWARN("TDS didn't return the right precision"); } else { - QWARN( QString( tst_Databases::dbToString( db ) + " didn't return the right precision (" + - QString::number( i ) + " out of 21), " + val ).toLatin1() ); + QWARN(QString(tst_Databases::dbToString(db) + " didn't return the right precision (" + + QString::number(i) + " out of 21), " + val).toUtf8()); } } } // SQLITE scope + db.driver()->setNumericalPrecisionPolicy(oldPrecision); } void tst_QSqlQuery::nullResult() @@ -2850,10 +2844,11 @@ void tst_QSqlQuery::psql_bindWithDoubleColonCastOperator() QVERIFY_SQL( q, exec() ); QVERIFY_SQL( q, next() ); - if ( db.driver()->hasFeature( QSqlDriver::PreparedQueries ) ) - QCOMPARE( q.executedQuery(), QString( "select sum((fld1 - fld2)::int) from " + tablename + " where id1 = ? and id2 =? and id3=?" ) ); + // the positional placeholders are converted to named placeholders in executedQuery() + if (db.driver()->hasFeature(QSqlDriver::PreparedQueries)) + QCOMPARE(q.executedQuery(), QString("select sum((fld1 - fld2)::int) from " + tablename + " where id1 = :myid1 and id2 =:myid2 and id3=:myid3")); else - QCOMPARE( q.executedQuery(), QString( "select sum((fld1 - fld2)::int) from " + tablename + " where id1 = 1 and id2 =2 and id3=3" ) ); + QCOMPARE(q.executedQuery(), QString("select sum((fld1 - fld2)::int) from " + tablename + " where id1 = 1 and id2 =2 and id3=3")); } void tst_QSqlQuery::psql_specialFloatValues() @@ -4023,8 +4018,8 @@ void tst_QSqlQuery::QTBUG_2192() // Check if retrieved value preserves reported precision int precision = qMax(0, q.record().field("dt").precision()); - int diff = qAbs(q.value(0).toDateTime().msecsTo(dt)); - int keep = qMin(1000, (int)qPow(10.0, precision)); + qint64 diff = qAbs(q.value(0).toDateTime().msecsTo(dt)); + qint64 keep = qMin(1000LL, qRound64(qPow(10.0, precision))); QVERIFY(diff <= 1000 - keep); } } @@ -4041,8 +4036,10 @@ void tst_QSqlQuery::QTBUG_36211() QSqlQuery q(db); QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (dtwtz timestamptz, dtwotz timestamp)").arg(tableName))); - QTimeZone l_tzBrazil("BRT"); - QTimeZone l_tzChina("CST"); + QTimeZone l_tzBrazil("America/Sao_Paulo"); + QTimeZone l_tzChina("Asia/Shanghai"); + QVERIFY(l_tzBrazil.isValid()); + QVERIFY(l_tzChina.isValid()); QDateTime dt = QDateTime(QDate(2014, 10, 30), QTime(14, 12, 02, 357)); QVERIFY_SQL(q, prepare("INSERT INTO " + tableName + " (dtwtz, dtwotz) VALUES (:dt, :dt)")); q.bindValue(":dt", dt); @@ -4060,8 +4057,8 @@ void tst_QSqlQuery::QTBUG_36211() for (int j = 0; j < 2; ++j) { // Check if retrieved value preserves reported precision int precision = qMax(0, q.record().field(j).precision()); - int diff = qAbs(q.value(j).toDateTime().msecsTo(dt)); - int keep = qMin(1000, (int)qPow(10.0, precision)); + qint64 diff = qAbs(q.value(j).toDateTime().msecsTo(dt)); + qint64 keep = qMin(1000LL, qRound64(qPow(10.0, precision))); QVERIFY(diff <= 1000 - keep); } } -- cgit v1.2.3