From 4cb614c7abdaa2c5e2d0a75201d51aae01e6f8c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 3 Oct 2016 18:41:30 +0200 Subject: Apple OS: Handle QSetting strings with embedded zero-bytes Saving strings with embedded zero-bytes (\0) as CFStrings would sometimes fail, and only write the part of the string leading up to the first zero-byte, instead of all the way to the final zero-terminator. This bug was revealed by the code-path that falls back to storing e.g. QTime as strings, via the helper method QSettingsPrivate::variantToString(). We now use the same approach as on platforms such as Windows and WinRT, where the string produced by variantToString() is checked for null-bytes, and if so, stored using a binary representation instead of as a string. For our case that means we fall back to CFData when detecting the null-byte. To separate strings from regular byte arrays, new logic has been added to variantToString() that wraps the null-byte strings in @String(). That way we can implement a fast-path when converting back from CFData, that doesn't go via the slow and lossy conversion via UTF8, and the resulting QVariant will be of type QVariant::ByteArray. The reason for using UTF-8 as the binary representation of the string is that in the case of storing a QByteArray("@foo") we need to still be able to convert it back to the same byte array, which doesn't work if the on-disk format is UTF-16. Task-number: QTBUG-56124 Change-Id: Iab2f71cf96cf3225de48dc5e71870d74b6dde1e8 Cherry-picked: 764f5bf48cc87f4c72550b853ab93b815454cd48 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 50 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 19155cc3ad..f489b9b1d3 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -162,6 +162,8 @@ private slots: void testByteArray(); void iniCodec(); void bom(); + void embeddedZeroByte_data(); + void embeddedZeroByte(); private: void cleanupTestFiles(); @@ -655,7 +657,6 @@ void tst_QSettings::testByteArray_data() #ifndef QT_NO_COMPRESS QTest::newRow("compressed") << qCompress(bytes); #endif - QTest::newRow("with \\0") << bytes + '\0' + bytes; } void tst_QSettings::testByteArray() @@ -706,6 +707,53 @@ void tst_QSettings::bom() QVERIFY(allkeys.contains("section2/foo2")); } +void tst_QSettings::embeddedZeroByte_data() +{ + QTest::addColumn("value"); + + QByteArray bytes("hello\0world", 11); + + QTest::newRow("bytearray\\0") << QVariant(bytes); + QTest::newRow("string\\0") << QVariant(QString::fromLatin1(bytes.data(), bytes.size())); + + bytes = QByteArray("@String("); + + QTest::newRow("@bytearray") << QVariant(bytes); + QTest::newRow("@string") << QVariant(QString(bytes)); + + bytes = QByteArray("@String(\0test", 13); + + QTest::newRow("@bytearray\\0") << QVariant(bytes); + QTest::newRow("@string\\0") << QVariant(QString::fromLatin1(bytes.data(), bytes.size())); +} + +void tst_QSettings::embeddedZeroByte() +{ + QFETCH(QVariant, value); + { + QSettings settings("QtProject", "tst_qsettings"); + settings.setValue(QTest::currentDataTag(), value); + } + { + QSettings settings("QtProject", "tst_qsettings"); + QVariant outValue = settings.value(QTest::currentDataTag()); + + switch (value.type()) { + case QVariant::ByteArray: + QCOMPARE(outValue.toByteArray(), value.toByteArray()); + break; + case QVariant::String: + QCOMPARE(outValue.toString(), value.toString()); + break; + default: + Q_UNREACHABLE(); + } + + if (value.toByteArray().contains(QChar::Null)) + QVERIFY(outValue.toByteArray().contains(QChar::Null)); + } +} + void tst_QSettings::testErrorHandling_data() { QTest::addColumn("filePerms"); // -1 means file should not exist -- cgit v1.2.3 From ee22c6505a1f7cf52a862b1bd9219511db893417 Mon Sep 17 00:00:00 2001 From: Clinton Stimpson Date: Tue, 30 Aug 2016 07:52:17 -0600 Subject: xcb: fix passing of focus from child to its top level QWindow With the client message _NET_ACTIVE_WINDOW, not all window managers will pass focus from a child window to its root window, Detect this child-to-root case, and use xcb_set_input_focus() instead. Task-number: QTBUG-39362 Change-Id: Ib32193018e3b725b323f87d7306c9ae9493d78a7 Reviewed-by: Shawn Rutledge Reviewed-by: Edward Welbourne Reviewed-by: Frederik Gladhorn --- tests/auto/gui/kernel/qwindow/tst_qwindow.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 0cce5a072c..d904d48376 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -601,6 +601,24 @@ void tst_QWindow::isActive() // child has focus QVERIFY(window.isActive()); + // test focus back to parent and then back to child (QTBUG-39362) + // also verify the cumulative FocusOut and FocusIn counts + // activate parent + window.requestActivate(); + QTRY_COMPARE(QGuiApplication::focusWindow(), &window); + QVERIFY(window.isActive()); + QCoreApplication::processEvents(); + QTRY_COMPARE(child.received(QEvent::FocusOut), 1); + QTRY_COMPARE(window.received(QEvent::FocusIn), 2); + + // activate child again + child.requestActivate(); + QTRY_COMPARE(QGuiApplication::focusWindow(), &child); + QVERIFY(child.isActive()); + QCoreApplication::processEvents(); + QTRY_COMPARE(window.received(QEvent::FocusOut), 2); + QTRY_COMPARE(child.received(QEvent::FocusIn), 2); + Window dialog; dialog.setTransientParent(&window); dialog.setGeometry(QRect(m_availableTopLeft + QPoint(110, 100), m_testWindowSize)); @@ -625,7 +643,7 @@ void tst_QWindow::isActive() QTRY_COMPARE(QGuiApplication::focusWindow(), &window); QCoreApplication::processEvents(); QTRY_COMPARE(dialog.received(QEvent::FocusOut), 1); - QTRY_COMPARE(window.received(QEvent::FocusIn), 2); + QTRY_COMPARE(window.received(QEvent::FocusIn), 3); QVERIFY(window.isActive()); -- cgit v1.2.3 From 6cfdfad7d41a7e452fa53495d9843c5d67e74946 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Martins?= Date: Mon, 17 Oct 2016 23:16:15 +0100 Subject: Don't crash while parsing malformed CSS Task-Id: QTBUG-53919 Change-Id: I31a0e218e4e41ee217f8f87164f115450d69d42c Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/gui/text/qcssparser/tst_qcssparser.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp index b1beb0ffd0..d283f7d9cc 100644 --- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp +++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp @@ -847,6 +847,7 @@ void tst_QCssParser::colorValue_data() QTest::newRow("hsla") << "color: hsva(10, 20, 30, 40)" << QColor::fromHsv(10, 20, 30, 40); QTest::newRow("invalid1") << "color: rgb(why, does, it, always, rain, on, me)" << QColor(); QTest::newRow("invalid2") << "color: rgba(i, meant, norway)" << QColor(); + QTest::newRow("invalid3") << "color: rgb(21)" << QColor(); QTest::newRow("role") << "color: palette(base)" << qApp->palette().color(QPalette::Base); QTest::newRow("role2") << "color: palette( window-text ) " << qApp->palette().color(QPalette::WindowText); QTest::newRow("transparent") << "color: transparent" << QColor(Qt::transparent); -- cgit v1.2.3 From 557abfc3275f74d3dd537d7bca86e15860d072e9 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Thu, 20 Oct 2016 08:50:42 +0200 Subject: QUrl effective TLDs: update table There are more than 1000 new entries since the table has been generated the last time. The autotest needs to be tweaked because the rules for the .mz domains have changed; use the .ck domain instead. Change-Id: Ife692afd46ac41a66604e966e5e8cb57c7aa649c Reviewed-by: Thiago Macieira --- .../access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 12ac1e519d..7af057da65 100644 --- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -192,16 +192,16 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data() result += cookie; QTest::newRow("effective-tld1-accepted") << preset << cookie << "http://something.co.uk" << result << true; - // 2. anything .mz is an effective TLD ('*.mz'), but 'teledata.mz' is an exception + // 2. anything .ck is an effective TLD ('*.ck'), but 'www.ck' is an exception result.clear(); preset.clear(); - cookie.setDomain(".farmacia.mz"); - QTest::newRow("effective-tld2-denied") << preset << cookie << "http://farmacia.mz" << result << false; - QTest::newRow("effective-tld2-denied2") << preset << cookie << "http://www.farmacia.mz" << result << false; - QTest::newRow("effective-tld2-denied3") << preset << cookie << "http://www.anything.farmacia.mz" << result << false; - cookie.setDomain(".teledata.mz"); + cookie.setDomain(".foo.ck"); + QTest::newRow("effective-tld2-denied") << preset << cookie << "http://foo.ck" << result << false; + QTest::newRow("effective-tld2-denied2") << preset << cookie << "http://www.foo.ck" << result << false; + QTest::newRow("effective-tld2-denied3") << preset << cookie << "http://www.anything.foo.ck" << result << false; + cookie.setDomain(".www.ck"); result += cookie; - QTest::newRow("effective-tld2-accepted") << preset << cookie << "http://www.teledata.mz" << result << true; + QTest::newRow("effective-tld2-accepted") << preset << cookie << "http://www.www.ck" << result << true; result.clear(); preset.clear(); -- cgit v1.2.3 From 49d3bb005889b9fb5a06d6aadac23ebd5b2f9f2d Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 6 Oct 2016 11:24:38 +0200 Subject: Normalize realpath(3) output to composed form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All strings coming out of POSIX API calls are converted to composed form by QFile::decodeName. Do the same for realpath(3) output. This is especially important for HFS+, which will store file names in decomposed form, and APIs will therefore return strings in decomposed form. Task-number: QTBUG-55896 Change-Id: I5e51f4e5712ff26bf9644cbcf9a9603995748892 Reviewed-by: Morten Johan Sørvig --- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index d2c43f79d6..10921ea0a3 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -770,6 +770,19 @@ void tst_QFileInfo::canonicalFilePath() QDir::current().rmdir(linkTarget); } #endif + +#ifdef Q_OS_DARWIN + { + // Check if canonicalFilePath's result is in Composed normalization form. + QString path = QString::fromLatin1("caf\xe9"); + QDir dir(QDir::tempPath()); + dir.mkdir(path); + QString canonical = QFileInfo(dir.filePath(path)).canonicalFilePath(); + QString roundtrip = QFile::decodeName(QFile::encodeName(canonical)); + QCOMPARE(canonical, roundtrip); + dir.rmdir(path); + } +#endif } void tst_QFileInfo::fileName_data() -- cgit v1.2.3 From 686c44a69b13f6e884dd2b6d9991f4cd94597c5a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 28 Sep 2016 10:49:57 +0200 Subject: Plug remaining leaks in tests/auto/widgets/kernel The usual: - delete return values of QLayout::takeAt(), replaceWidget() - delete styles - delete top-level widgets - delete actions Either by naked delete, QScopedPointer or allocation on the stack instead of the heap. This fixes the remaining errors in GCC 6.1 Linux ASan runs of tests/auto/widgets/kernel. Change-Id: I8cc217be114b2e0edf34ad8d60dbf722f900bb7f Reviewed-by: Thiago Macieira --- tests/auto/widgets/kernel/qaction/tst_qaction.cpp | 6 +++--- .../auto/widgets/kernel/qapplication/tst_qapplication.cpp | 12 ++++++------ tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp | 15 +++++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp index 71b55d71ea..b496550f85 100644 --- a/tests/auto/widgets/kernel/qaction/tst_qaction.cpp +++ b/tests/auto/widgets/kernel/qaction/tst_qaction.cpp @@ -329,7 +329,7 @@ void tst_QAction::enabledVisibleInteraction() void tst_QAction::task200823_tooltip() { - QAction *action = new QAction("foo", 0); + const QScopedPointer action(new QAction("foo", Q_NULLPTR)); QString shortcut("ctrl+o"); action->setShortcut(shortcut); @@ -343,8 +343,8 @@ void tst_QAction::task200823_tooltip() void tst_QAction::task229128TriggeredSignalWithoutActiongroup() { // test without a group - QAction *actionWithoutGroup = new QAction("Test", qApp); - QSignalSpy spyWithoutGroup(actionWithoutGroup, SIGNAL(triggered(bool))); + const QScopedPointer actionWithoutGroup(new QAction("Test", Q_NULLPTR)); + QSignalSpy spyWithoutGroup(actionWithoutGroup.data(), SIGNAL(triggered(bool))); QCOMPARE(spyWithoutGroup.count(), 0); actionWithoutGroup->trigger(); // signal should be emitted diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp index 87a189fc87..424069c8ae 100644 --- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp +++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp @@ -2211,8 +2211,8 @@ void tst_QApplication::noQuitOnHide() { int argc = 0; QApplication app(argc, 0); - QWidget *window1 = new NoQuitOnHideWidget; - window1->show(); + NoQuitOnHideWidget window1; + window1.show(); QCOMPARE(app.exec(), 1); } @@ -2246,12 +2246,12 @@ void tst_QApplication::abortQuitOnShow() { int argc = 0; QApplication app(argc, 0); - QWidget *window1 = new ShowCloseShowWidget(false); - window1->show(); + ShowCloseShowWidget window1(false); + window1.show(); QCOMPARE(app.exec(), 0); - QWidget *window2 = new ShowCloseShowWidget(true); - window2->show(); + ShowCloseShowWidget window2(true); + window2.show(); QCOMPARE(app.exec(), 1); } diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index e1b494c9f1..5703d7e114 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -395,7 +395,8 @@ void tst_QFormLayout::setFormStyle() QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows); #endif - widget.setStyle(QStyleFactory::create("windows")); + const QScopedPointer windowsStyle(QStyleFactory::create("windows")); + widget.setStyle(windowsStyle.data()); QCOMPARE(layout.labelAlignment(), Qt::AlignLeft); QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop)); @@ -406,14 +407,16 @@ void tst_QFormLayout::setFormStyle() this test is cross platform.. so create dummy styles that return all the right stylehints. */ - widget.setStyle(new DummyMacStyle()); + DummyMacStyle macStyle; + widget.setStyle(&macStyle); QCOMPARE(layout.labelAlignment(), Qt::AlignRight); QVERIFY(layout.formAlignment() == (Qt::AlignHCenter | Qt::AlignTop)); QCOMPARE(layout.fieldGrowthPolicy(), QFormLayout::FieldsStayAtSizeHint); QCOMPARE(layout.rowWrapPolicy(), QFormLayout::DontWrapRows); - widget.setStyle(new DummyQtopiaStyle()); + DummyQtopiaStyle qtopiaStyle; + widget.setStyle(&qtopiaStyle); QCOMPARE(layout.labelAlignment(), Qt::AlignRight); QVERIFY(layout.formAlignment() == (Qt::AlignLeft | Qt::AlignTop)); @@ -891,7 +894,7 @@ void tst_QFormLayout::takeAt() QCOMPARE(layout->count(), 7); for (int i = 6; i >= 0; --i) { - layout->takeAt(0); + delete layout->takeAt(0); QCOMPARE(layout->count(), i); } } @@ -983,7 +986,7 @@ void tst_QFormLayout::replaceWidget() QFormLayout::ItemRole role; // replace editor - layout->replaceWidget(edit1, edit3); + delete layout->replaceWidget(edit1, edit3); edit1->hide(); // Not strictly needed for the test, but for normal usage it is. QCOMPARE(layout->indexOf(edit1), -1); QCOMPARE(layout->indexOf(edit3), editIndex); @@ -994,7 +997,7 @@ void tst_QFormLayout::replaceWidget() QCOMPARE(rownum, 0); QCOMPARE(role, QFormLayout::FieldRole); - layout->replaceWidget(label1, label2); + delete layout->replaceWidget(label1, label2); label1->hide(); QCOMPARE(layout->indexOf(label1), -1); QCOMPARE(layout->indexOf(label2), labelIndex); -- cgit v1.2.3