From 6d6074e04fa55a0e42c7d8970f6db1cc3913a26e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 9 Oct 2016 19:29:25 +0200 Subject: Plug leaks in tst_QXmlSimpleReader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QXmlInputSource objects were allocated on the heap, but never deleted. Fix by allocating them on the stack instead. Change-Id: Ifd8bd41d778c0634b7a426bbd22a367dfce511c9 Reviewed-by: David Faure Reviewed-by: Jędrzej Nowacki --- tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp index dc5d776f6d..5fe693dd14 100644 --- a/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp +++ b/tests/auto/xml/sax/qxmlsimplereader/tst_qxmlsimplereader.cpp @@ -765,22 +765,22 @@ void tst_QXmlSimpleReader::dtdRecursionLimit() QVERIFY(file.open(QIODevice::ReadOnly)); QXmlSimpleReader xmlReader; { - QXmlInputSource *source = new QXmlInputSource(&file); + QXmlInputSource source(&file); TestHandler handler; xmlReader.setDeclHandler(&handler); xmlReader.setErrorHandler(&handler); - QVERIFY(!xmlReader.parse(source)); + QVERIFY(!xmlReader.parse(&source)); } file.close(); file.setFileName("xmldocs/1-levels-nested-dtd.xml"); QVERIFY(file.open(QIODevice::ReadOnly)); { - QXmlInputSource *source = new QXmlInputSource(&file); + QXmlInputSource source(&file); TestHandler handler; xmlReader.setDeclHandler(&handler); xmlReader.setErrorHandler(&handler); - QVERIFY(!xmlReader.parse(source)); + QVERIFY(!xmlReader.parse(&source)); // The error wasn't because of the recursion limit being reached, // it was because the document is not valid. QVERIFY(handler.recursionCount < 2); @@ -790,11 +790,11 @@ void tst_QXmlSimpleReader::dtdRecursionLimit() file.setFileName("xmldocs/internal-entity-polynomial-attribute.xml"); QVERIFY(file.open(QIODevice::ReadOnly)); { - QXmlInputSource *source = new QXmlInputSource(&file); + QXmlInputSource source(&file); TestHandler handler; xmlReader.setDeclHandler(&handler); xmlReader.setErrorHandler(&handler); - QVERIFY(!xmlReader.parse(source)); + QVERIFY(!xmlReader.parse(&source)); QCOMPARE(handler.recursionCount, 2); } } -- cgit v1.2.3 From f6498fd6776b08b6bd33395e3f716b6d5d79a8b8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 30 Sep 2016 22:21:37 +0200 Subject: Plug more than 4k leaks in tst_QGraphicsView The vast majority is due to leaking styles in a data-driven test with almost 100 rows (scrollBarRanges()). Fix by creating the style into a QScopedPointer. The remaining ~500 leaks were due to leaked QGraphicsScenes. They had no parent, and QGraphicsView::addScene() does not adopt them. Fix those by passing the resp. view as their (QObject) parent. Change-Id: I4316798019114ea3d7504d72cd83d534a21149c0 Reviewed-by: Allan Sandfeld Jensen --- .../graphicsview/qgraphicsview/tst_qgraphicsview.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index f5083795c7..da2606c160 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -2938,6 +2938,9 @@ void tst_QGraphicsView::scrollBarRanges() if (useStyledPanel && style == QStringLiteral("Macintosh") && platformName == QStringLiteral("cocoa")) QSKIP("Insignificant on OSX"); + + QScopedPointer stylePtr; + QGraphicsScene scene; QGraphicsView view(&scene); view.setRenderHint(QPainter::Antialiasing); @@ -2945,9 +2948,10 @@ void tst_QGraphicsView::scrollBarRanges() view.setFrameStyle(useStyledPanel ? QFrame::StyledPanel : QFrame::NoFrame); if (style == QString("motif")) - view.setStyle(new FauxMotifStyle); + stylePtr.reset(new FauxMotifStyle); else - view.setStyle(QStyleFactory::create(style)); + stylePtr.reset(QStyleFactory::create(style)); + view.setStyle(stylePtr.data()); view.setStyleSheet(" "); // enables style propagation ;-) int adjust = 0; @@ -3514,7 +3518,7 @@ void tst_QGraphicsView::task245469_itemsAtPointWithClip() static QGraphicsView *createSimpleViewAndScene() { QGraphicsView *view = new QGraphicsView; - QGraphicsScene *scene = new QGraphicsScene; + QGraphicsScene *scene = new QGraphicsScene(view); view->setScene(scene); view->setBackgroundBrush(Qt::blue); @@ -3642,7 +3646,7 @@ void tst_QGraphicsView::moveItemWhileScrolling() MoveItemScrollView() { setWindowFlags(Qt::X11BypassWindowManagerHint); - setScene(new QGraphicsScene(0, 0, 1000, 1000)); + setScene(new QGraphicsScene(0, 0, 1000, 1000, this)); rect = scene()->addRect(0, 0, 10, 10); rect->setPos(50, 50); rect->setPen(QPen(Qt::black, 0)); @@ -3708,7 +3712,7 @@ void tst_QGraphicsView::centerOnDirtyItem() toplevel.setWindowFlags(view.windowFlags() | Qt::WindowStaysOnTopHint); view.resize(200, 200); - QGraphicsScene *scene = new QGraphicsScene; + QGraphicsScene *scene = new QGraphicsScene(&view); view.setScene(scene); view.setSceneRect(-1000, -1000, 2000, 2000); -- cgit v1.2.3 From afe5bcdbd1dbf8c8a229d75d16b614f5e645d32f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Sep 2016 11:25:10 +0200 Subject: tst_QWidget: Fix UB (invalid member access) in EnterTestMainDialog::eventFilter() Found by UBSan: tst_qwidget.cpp:10207:29: runtime error: member access within address 0x6060000e8880 which does not point to an object of type 'EnterTestModalDialog' 0x6060000e8880: note: object is of type 'QWidget' eb 00 80 45 10 4b 32 ab 11 2b 00 00 80 df 08 00 60 61 00 00 c0 4c 32 ab 11 2b 00 00 00 00 be be ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'QWidget' #0 0x6ca13f in EnterTestMainDialog::eventFilter(QObject*, QEvent*) tst_qwidget.cpp:10207 #1 0x2b11b8bc90c3 in QCoreApplicationPrivate::sendThroughApplicationEventFilters(QObject*, QEvent*) qcoreapplication.cpp:1081 #2 0x2b11a3c49b4a in QApplicationPrivate::notify_helper(QObject*, QEvent*) qapplication.cpp:3716 #3 0x2b11a3c8ec72 in QApplication::notify(QObject*, QEvent*) qapplication.cpp:3704 #4 0x2b11b8bccd0f in QCoreApplication::notifyInternal2(QObject*, QEvent*) qcoreapplication.cpp:988 #5 0x2b11aea5c34d in QCoreApplication::sendEvent(QObject*, QEvent*) qcoreapplication.h:231 #6 0x2b11aea5c34d in QGuiApplicationPrivate::_q_updateFocusObject(QObject*) qguiapplication.cpp:3690 #7 0x2b11aea61360 in QGuiApplication::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) .moc/moc_qguiapplication.cpp:177 #8 0x2b11b8d1dc86 in QMetaObject::activate(QObject*, int, int, void**) qobject.cpp:3787 #9 0x2b11aea784a3 in QWindow::focusObjectChanged(QObject*) .moc/moc_qwindow.cpp:760 #10 0x2b11a3fb24f2 in QWidget::clearFocus() qwidget.cpp:6705 #11 0x2b11a3fc87b1 in QWidget::~QWidget() qwidget.cpp:1608 #12 0x2b11a526688c in QDialog::~QDialog() qdialog.cpp:352 #13 0x6c43e2 in EnterTestModalDialog::~EnterTestModalDialog() tst_qwidget.cpp:10160 #14 0x6c43e2 in EnterTestModalDialog::~EnterTestModalDialog() tst_qwidget.cpp:10160 #15 0x492be3 in EnterTestMainDialog::buttonPressed() tst_qwidget.cpp:10188 #16 0x492be3 in EnterTestMainDialog::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) .moc/tst_qwidget.moc:2056 #17 0x2b11b8d1dc86 in QMetaObject::activate(QObject*, int, int, void**) qobject.cpp:3787 #18 0x2b11a45cb833 in QAbstractButton::clicked(bool) .moc/moc_qabstractbutton.cpp:307 #19 0x2b11a45cd54b in QAbstractButtonPrivate::emitClicked() qabstractbutton.cpp:411 #20 0x2b11a45df73a in QAbstractButtonPrivate::click() qabstractbutton.cpp:404 [...] #41 0x6bb2cf in tst_QWidget::taskQTBUG_27643_enterEvents() tst_qwidget.cpp:10249 [...] Fix by checking the event type first, and accessing modal->button only if it's QEvent::Enter. Change-Id: I2c7df3a1f43ecbfe14741b5861729078a91a32d6 Reviewed-by: Friedemann Kleint --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index e00e575c36..cc1aaa7d51 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -10430,14 +10430,13 @@ public slots: bool eventFilter(QObject *o, QEvent *e) { - if (modal && modal->button && o == modal->button) { - switch (e->type()) { - case QEvent::Enter: + switch (e->type()) { + case QEvent::Enter: + if (modal && modal->button && o == modal->button) enters++; - break; - default: - break; - } + break; + default: + break; } return QDialog::eventFilter(o, e); } -- cgit v1.2.3 From 00304a3d57b9ba33b6a253b8736cf7e15aeac5c3 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 12 Oct 2016 09:50:42 +0200 Subject: Blacklist tst_MacNativeEvents::testMouseEnter It is already blacklisted for 10.8 and 10.9, and is now failing on 10.11 blocking integration. Change-Id: I71b8119ab32ec64096bfc53d5e521714ad4ae11b Reviewed-by: Lars Knoll --- tests/auto/other/macnativeevents/BLACKLIST | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/other/macnativeevents/BLACKLIST b/tests/auto/other/macnativeevents/BLACKLIST index 4129868022..3e68ba0cf0 100644 --- a/tests/auto/other/macnativeevents/BLACKLIST +++ b/tests/auto/other/macnativeevents/BLACKLIST @@ -2,8 +2,7 @@ [testDragWindow] osx [testMouseEnter] -osx-10.9 -osx-10.8 +osx [testChildDialogInFrontOfModalParent] osx [testChildWindowInFrontOfStaysOnTopParentWindow] -- cgit v1.2.3 From f3ce959de6c682bdb7e71f7b82742f28a5be1e9c Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 5 Oct 2016 15:45:55 +0200 Subject: Fix illegal memory access on simple image rotates Clip the transformed and rounded sourceClip to the source rectangle, so we don't try to rotate pixels outside the source. Task-number: QTBUG-56252 Change-Id: Ib9cb80f9856724118867aea37ead0b02a6c71495 Reviewed-by: Shawn Rutledge Reviewed-by: Gunnar Sletta --- tests/auto/gui/painting/qpainter/tst_qpainter.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp index 8c72532122..2c0012497d 100644 --- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp @@ -307,6 +307,8 @@ private slots: void QTBUG50153_drawImage_assert(); + void QTBUG56252(); + private: void fillData(); void setPenColor(QPainter& p); @@ -5078,6 +5080,23 @@ void tst_QPainter::QTBUG50153_drawImage_assert() } } +void tst_QPainter::QTBUG56252() +{ + QImage sourceImage(1770, 1477, QImage::Format_RGB32); + QImage rotatedImage(1478, 1771, QImage::Format_RGB32); + QTransform transformCenter; + transformCenter.translate(739.0, 885.5); + transformCenter.rotate(270.0); + transformCenter.translate(-885.0, -738.5); + QPainter painter; + painter.begin(&rotatedImage); + painter.setTransform(transformCenter); + painter.drawImage(QPoint(0, 0),sourceImage); + painter.end(); + + // If no crash or illegal memory read, all is fine +} + QTEST_MAIN(tst_QPainter) #include "tst_qpainter.moc" -- cgit v1.2.3 From cd1d11414021288729cd85a32a7a1160756aeeab Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 30 Sep 2016 18:36:15 +0200 Subject: Unset qgl_current_fbo when the default FBO is bound Previously when a new QOpenGLFramebufferObject was bound, the QOpenGLContextPrivate::qgl_current_fbo member was also updated to point to this new object. But if a user called QOpenGLFramebufferObject::bindDefault(), qgl_current_fbo was not unset, meaning that if the FBO object would be deleted at some point, qgl_current_fbo would be a dangling pointer. This patch makes sure to clear the value of qgl_current_fbo when bindDefault() is called. It is cleared, and not set to point to another object because the default platform OpenGL FBO is not backed by a QOpenGLFramebufferObject. Task-number: QTBUG-56296 Change-Id: I68b53d8b446660accdf5841df3d168ee2f133a90 Reviewed-by: Simon Hausmann Reviewed-by: Laszlo Agocs --- tests/auto/gui/qopengl/tst_qopengl.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests') diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index e2ad502a52..00b5da92a8 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -114,6 +114,7 @@ private slots: void vaoCreate(); void bufferCreate(); void bufferMapRange(); + void defaultQGLCurrentBuffer(); }; struct SharedResourceTracker @@ -1525,6 +1526,33 @@ void tst_QOpenGL::bufferMapRange() ctx->doneCurrent(); } +void tst_QOpenGL::defaultQGLCurrentBuffer() +{ + QScopedPointer surface(createSurface(QSurface::Window)); + QScopedPointer ctx(new QOpenGLContext); + ctx->create(); + ctx->makeCurrent(surface.data()); + + // Bind default FBO on the current context, and record what's the current QGL FBO. It should + // be Q_NULLPTR because the default platform OpenGL FBO is not backed by a + // QOpenGLFramebufferObject. + QOpenGLFramebufferObject::bindDefault(); + QOpenGLFramebufferObject *defaultQFBO = QOpenGLContextPrivate::get(ctx.data())->qgl_current_fbo; + + // Create new FBO, bind it, and see that the QGL FBO points to the newly created FBO. + QScopedPointer obj(new QOpenGLFramebufferObject(128, 128)); + obj->bind(); + QOpenGLFramebufferObject *customQFBO = QOpenGLContextPrivate::get(ctx.data())->qgl_current_fbo; + QVERIFY(defaultQFBO != customQFBO); + + // Bind the default FBO, and check that the QGL FBO points to the original FBO object. + QOpenGLFramebufferObject::bindDefault(); + QOpenGLFramebufferObject *finalQFBO = QOpenGLContextPrivate::get(ctx.data())->qgl_current_fbo; + QCOMPARE(defaultQFBO, finalQFBO); + + ctx->doneCurrent(); +} + void tst_QOpenGL::nullTextureInitializtion() { QScopedPointer surface(createSurface(QSurface::Window)); -- cgit v1.2.3 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 From 0e888ae1a10750c7f5e644da8f774376f0c8da6a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 7 Oct 2016 10:49:18 +0200 Subject: tst_QGraphicsItem: plug remaining leaks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Store QGraphicsItems that are either not added to a scene or removed from it again and that are also not children of other items - iow: those that were leaked, even on successful runs of the tests, in either a QScopedPointer, or, where that'd cause too much churn due to adding of .data() calls, back the pointer by a stack-allocated object. This fixes the remaining leaks reported by GCC 6.2.1's ASan on successful runs of tests/auto/widgets/graphicsview/qgraphicsitem. Change-Id: I61c3a1cd39b9e96e83c5d7b8cf392e0b26ecbaf0 Reviewed-by: Edward Welbourne Reviewed-by: Sérgio Martins --- .../qgraphicsitem/tst_qgraphicsitem.cpp | 40 ++++++++++++---------- 1 file changed, 21 insertions(+), 19 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 8ee9ffe294..4a5a66dd05 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -848,14 +848,14 @@ void tst_QGraphicsItem::parentItem() void tst_QGraphicsItem::setParentItem() { QGraphicsScene scene; - QGraphicsItem *item = scene.addRect(QRectF(0, 0, 10, 10)); + const QScopedPointer item(scene.addRect(QRectF(0, 0, 10, 10))); QCOMPARE(item->scene(), &scene); - QGraphicsRectItem *child = new QGraphicsRectItem; + const QScopedPointer child(new QGraphicsRectItem); QCOMPARE(child->scene(), (QGraphicsScene *)0); // This implicitly adds the item to the parent's scene - child->setParentItem(item); + child->setParentItem(item.data()); QCOMPARE(child->scene(), &scene); // This just makes it a toplevel @@ -863,8 +863,8 @@ void tst_QGraphicsItem::setParentItem() QCOMPARE(child->scene(), &scene); // Add the child back to the parent, then remove the parent from the scene - child->setParentItem(item); - scene.removeItem(item); + child->setParentItem(item.data()); + scene.removeItem(item.data()); QCOMPARE(child->scene(), (QGraphicsScene *)0); } @@ -962,19 +962,19 @@ void tst_QGraphicsItem::flags() QCOMPARE(item->pos(), QPointF(10, 10)); } { - QGraphicsItem* clippingParent = new QGraphicsRectItem; + const QScopedPointer clippingParent(new QGraphicsRectItem); clippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); - QGraphicsItem* nonClippingParent = new QGraphicsRectItem; + const QScopedPointer nonClippingParent(new QGraphicsRectItem); nonClippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); - QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent); + QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent.data()); QVERIFY(!child->isClipped()); - child->setParentItem(clippingParent); + child->setParentItem(clippingParent.data()); QVERIFY(child->isClipped()); - child->setParentItem(nonClippingParent); + child->setParentItem(nonClippingParent.data()); QVERIFY(!child->isClipped()); } } @@ -3133,7 +3133,8 @@ void tst_QGraphicsItem::isAncestorOf() void tst_QGraphicsItem::commonAncestorItem() { - QGraphicsItem *ancestor = new QGraphicsRectItem; + QGraphicsRectItem ancestorItem; + QGraphicsItem *ancestor = &ancestorItem; QGraphicsItem *grandMa = new QGraphicsRectItem; QGraphicsItem *grandPa = new QGraphicsRectItem; QGraphicsItem *brotherInLaw = new QGraphicsRectItem; @@ -3633,7 +3634,7 @@ void tst_QGraphicsItem::setGroup() QGraphicsItemGroup group1; QGraphicsItemGroup group2; - QGraphicsRectItem *rect = new QGraphicsRectItem; + const QScopedPointer rect(new QGraphicsRectItem); QCOMPARE(rect->group(), (QGraphicsItemGroup *)0); QCOMPARE(rect->parentItem(), (QGraphicsItem *)0); rect->setGroup(&group1); @@ -6831,8 +6832,8 @@ void tst_QGraphicsItem::opacity() QFETCH(qreal, c2_effectiveOpacity); QFETCH(qreal, c3_effectiveOpacity); - QGraphicsRectItem *p = new QGraphicsRectItem; - QGraphicsRectItem *c1 = new QGraphicsRectItem(p); + const QScopedPointer p(new QGraphicsRectItem); + QGraphicsRectItem *c1 = new QGraphicsRectItem(p.data()); QGraphicsRectItem *c2 = new QGraphicsRectItem(c1); QGraphicsRectItem *c3 = new QGraphicsRectItem(c2); @@ -7219,11 +7220,12 @@ void tst_QGraphicsItem::sceneTransformCache() // Test that an item's scene transform is updated correctly when the // parent is transformed. QGraphicsScene scene; - QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); + + const QScopedPointer rect(scene.addRect(0, 0, 100, 100)); rect->setPen(QPen(Qt::black, 0)); QGraphicsRectItem *rect2 = scene.addRect(0, 0, 100, 100); rect2->setPen(QPen(Qt::black, 0)); - rect2->setParentItem(rect); + rect2->setParentItem(rect.data()); rect2->rotate(90); rect->translate(0, 50); QGraphicsView view(&scene); @@ -7235,7 +7237,7 @@ void tst_QGraphicsItem::sceneTransformCache() x.rotate(90); QCOMPARE(rect2->sceneTransform(), x); - scene.removeItem(rect); + scene.removeItem(rect.data()); //Crazy use case : rect4 child of rect3 so the transformation of rect4 will be cached.Good! //We remove rect4 from the scene, then the validTransform bit flag is set to 0 and the index of the cache @@ -10688,7 +10690,7 @@ void tst_QGraphicsItem::scenePosChange() { ScenePosChangeTester* root = new ScenePosChangeTester; ScenePosChangeTester* child1 = new ScenePosChangeTester(root); - ScenePosChangeTester* grandChild1 = new ScenePosChangeTester(child1); + const QScopedPointer grandChild1(new ScenePosChangeTester(child1)); ScenePosChangeTester* child2 = new ScenePosChangeTester(root); ScenePosChangeTester* grandChild2 = new ScenePosChangeTester(child2); @@ -10740,7 +10742,7 @@ void tst_QGraphicsItem::scenePosChange() QCOMPARE(grandChild2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 3); // remove - scene.removeItem(grandChild1); + scene.removeItem(grandChild1.data()); delete grandChild2; grandChild2 = 0; QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants() root->moveBy(1.0, 1.0); -- cgit v1.2.3 From e70e168abb4b75dc8d00e2cba12efa1a111d429d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 29 Sep 2016 09:06:12 +0200 Subject: Plug leaks in tst_QWizard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This completely over-engineered piece of code has a hierarchy of Operation subclasses encapsulating but three actual operations on a QWizard. Because these operations and their containers were all allocated on the heap, but never deleted, asan went crazy and reported over 50 leaks (not the record so far, but a (distant) second). Since these collections are passed through addColumn/QFETCH, too, it's nearly impossible to track their lifetimes. So instead of trying, delegate that to the runtime, ie. pack the Operation objects into QSharedPointer and pass around those instead. Change-Id: I8a0fe7a60cd30aed618667affaa030e80cf2b1ac Reviewed-by: Edward Welbourne Reviewed-by: Sérgio Martins --- tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp | 106 ++++++++++++--------- 1 file changed, 60 insertions(+), 46 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp index b2bdbac79a..5789f0ca42 100644 --- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp +++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp @@ -1626,28 +1626,44 @@ class SetPage : public Operation wizard->next(); } QString describe() const { return QString("set page %1").arg(page); } - const int page; + int page; public: - SetPage(int page) : page(page) {} + static QSharedPointer create(int page) + { + QSharedPointer o = QSharedPointer::create(); + o->page = page; + return o; + } }; class SetStyle : public Operation { void apply(QWizard *wizard) const { wizard->setWizardStyle(style); } QString describe() const { return QString("set style %1").arg(style); } - const QWizard::WizardStyle style; + QWizard::WizardStyle style; public: - SetStyle(QWizard::WizardStyle style) : style(style) {} + static QSharedPointer create(QWizard::WizardStyle style) + { + QSharedPointer o = QSharedPointer::create(); + o->style = style; + return o; + } }; class SetOption : public Operation { void apply(QWizard *wizard) const { wizard->setOption(option, on); } QString describe() const; - const QWizard::WizardOption option; - const bool on; + QWizard::WizardOption option; + bool on; public: - SetOption(QWizard::WizardOption option, bool on) : option(option), on(on) {} + static QSharedPointer create(QWizard::WizardOption option, bool on) + { + QSharedPointer o = QSharedPointer::create(); + o->option = option; + o->on = on; + return o; + } }; class OptionInfo @@ -1672,16 +1688,16 @@ class OptionInfo tags[QWizard::HaveCustomButton3] = "15/CB3"; for (int i = 0; i < 2; ++i) { - QMap operations_; + QMap > operations_; foreach (QWizard::WizardOption option, tags.keys()) - operations_[option] = new SetOption(option, i == 1); + operations_[option] = SetOption::create(option, i == 1); operations << operations_; } } OptionInfo(OptionInfo const&); OptionInfo& operator=(OptionInfo const&); QMap tags; - QList > operations; + QList > > operations; public: static OptionInfo &instance() { @@ -1690,7 +1706,7 @@ public: } QString tag(QWizard::WizardOption option) const { return tags.value(option); } - Operation * operation(QWizard::WizardOption option, bool on) const + QSharedPointer operation(QWizard::WizardOption option, bool on) const { return operations.at(on).value(option); } QList options() const { return tags.keys(); } }; @@ -1700,10 +1716,7 @@ QString SetOption::describe() const return QString("set opt %1 %2").arg(OptionInfo::instance().tag(option)).arg(on); } -Q_DECLARE_METATYPE(Operation *) -Q_DECLARE_METATYPE(SetPage *) -Q_DECLARE_METATYPE(SetStyle *) -Q_DECLARE_METATYPE(SetOption *) +Q_DECLARE_METATYPE(QVector >) class TestGroup { @@ -1720,14 +1733,17 @@ public: combinations.clear(); } - QList &add() - { combinations << new QList; return *(combinations.last()); } + QVector > &add() + { + combinations.resize(combinations.size() + 1); + return combinations.last(); + } void createTestRows() { for (int i = 0; i < combinations.count(); ++i) { QTest::newRow((name + QString(", row %1").arg(i)).toLatin1().data()) - << (i == 0) << (type == Equality) << *(combinations.at(i)); + << (i == 0) << (type == Equality) << combinations.at(i); ++nRows_; } } @@ -1738,7 +1754,7 @@ private: QString name; Type type; int nRows_; - QList *> combinations; + QVector > > combinations; }; class IntroPage : public QWizardPage @@ -1822,9 +1838,9 @@ public: } } - void applyOperations(const QList &operations) + void applyOperations(const QVector > &operations) { - foreach (Operation * op, operations) { + foreach (const QSharedPointer &op, operations) { if (op) { op->apply(this); opsDescr += QString("(%1) ").arg(op->describe()); @@ -1844,31 +1860,29 @@ public: class CombinationsTestData { TestGroup testGroup; - QList pageOps; - QList styleOps; - QMap *> setAllOptions; + QVector > pageOps; + QVector > styleOps; + QMap > > setAllOptions; public: CombinationsTestData() { QTest::addColumn("ref"); QTest::addColumn("testEquality"); - QTest::addColumn >("operations"); - pageOps << new SetPage(0) << new SetPage(1) << new SetPage(2); - styleOps << new SetStyle(QWizard::ClassicStyle) << new SetStyle(QWizard::ModernStyle) - << new SetStyle(QWizard::MacStyle); + QTest::addColumn > >("operations"); + pageOps << SetPage::create(0) << SetPage::create(1) << SetPage::create(2); + styleOps << SetStyle::create(QWizard::ClassicStyle) << SetStyle::create(QWizard::ModernStyle) + << SetStyle::create(QWizard::MacStyle); #define SETPAGE(page) pageOps.at(page) #define SETSTYLE(style) styleOps.at(style) #define OPT(option, on) OptionInfo::instance().operation(option, on) #define CLROPT(option) OPT(option, false) #define SETOPT(option) OPT(option, true) - setAllOptions[false] = new QList; - setAllOptions[true] = new QList; foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - *setAllOptions.value(false) << CLROPT(option); - *setAllOptions.value(true) << SETOPT(option); + setAllOptions[false] << CLROPT(option); + setAllOptions[true] << SETOPT(option); } -#define CLRALLOPTS *setAllOptions.value(false) -#define SETALLOPTS *setAllOptions.value(true) +#define CLRALLOPTS setAllOptions.value(false) +#define SETALLOPTS setAllOptions.value(true) } int nRows() const { return testGroup.nRows(); } @@ -1920,7 +1934,7 @@ public: testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList setOptions = *setAllOptions.value(i == 1); + QVector > setOptions = setAllOptions.value(i == 1); testGroup.reset("testAll 3.1"); testGroup.add() << setOptions; @@ -1937,21 +1951,21 @@ public: testGroup.createTestRows(); } - foreach (Operation *pageOp, pageOps) { + foreach (const QSharedPointer &pageOp, pageOps) { testGroup.reset("testAll 4.1"); testGroup.add() << pageOp; testGroup.add() << pageOp << pageOp; testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList optionOps = *setAllOptions.value(i == 1); + QVector > optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 4.2"); testGroup.add() << optionOps << pageOp; testGroup.add() << pageOp << optionOps; testGroup.createTestRows(); foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - Operation *optionOp = OPT(option, i == 1); + QSharedPointer optionOp = OPT(option, i == 1); testGroup.reset("testAll 4.3"); testGroup.add() << optionOp << pageOp; testGroup.add() << pageOp << optionOp; @@ -1960,21 +1974,21 @@ public: } } - foreach (Operation *styleOp, styleOps) { + foreach (const QSharedPointer &styleOp, styleOps) { testGroup.reset("testAll 5.1"); testGroup.add() << styleOp; testGroup.add() << styleOp << styleOp; testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList optionOps = *setAllOptions.value(i == 1); + QVector > optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 5.2"); testGroup.add() << optionOps << styleOp; testGroup.add() << styleOp << optionOps; testGroup.createTestRows(); foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - Operation *optionOp = OPT(option, i == 1); + QSharedPointer optionOp = OPT(option, i == 1); testGroup.reset("testAll 5.3"); testGroup.add() << optionOp << styleOp; testGroup.add() << styleOp << optionOp; @@ -1983,8 +1997,8 @@ public: } } - foreach (Operation *pageOp, pageOps) { - foreach (Operation *styleOp, styleOps) { + foreach (const QSharedPointer &pageOp, pageOps) { + foreach (const QSharedPointer &styleOp, styleOps) { testGroup.reset("testAll 6.1"); testGroup.add() << pageOp; @@ -2002,7 +2016,7 @@ public: testGroup.createTestRows(); for (int i = 0; i < 2; ++i) { - QList optionOps = *setAllOptions.value(i == 1); + QVector > optionOps = setAllOptions.value(i == 1); testGroup.reset("testAll 6.4"); testGroup.add() << optionOps << pageOp << styleOp; testGroup.add() << pageOp << optionOps << styleOp; @@ -2013,7 +2027,7 @@ public: testGroup.createTestRows(); foreach (QWizard::WizardOption option, OptionInfo::instance().options()) { - Operation *optionOp = OPT(option, i == 1); + QSharedPointer optionOp = OPT(option, i == 1); testGroup.reset("testAll 6.5"); testGroup.add() << optionOp << pageOp << styleOp; testGroup.add() << pageOp << optionOp << styleOp; @@ -2079,7 +2093,7 @@ void tst_QWizard::combinations() QFETCH(bool, ref); QFETCH(bool, testEquality); - QFETCH(QList, operations); + QFETCH(QVector >, operations); TestWizard wizard; #if !defined(QT_NO_STYLE_WINDOWSVISTA) -- cgit v1.2.3 From f6eb570c7dee2ec92383607c614db91f31804707 Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Thu, 29 Sep 2016 11:59:01 +0200 Subject: Darwin: normalize all watched paths to composed from MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be done by all POSIX APIs for strings coming in that way, but because other code (like NSWhateverViews) will most likely return decomposed form, we make sure that those are in composed form too. Task-number: QTBUG-55896 Change-Id: I065e11cee6b59706d4346ed20d4b59b9b95163b8 Reviewed-by: Morten Johan Sørvig --- .../qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 026743257c..4ede1e69f3 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -78,6 +78,8 @@ private slots: void signalsEmittedAfterFileMoved(); + void watchUnicodeCharacters(); + private: QString m_tempDirPattern; #endif // QT_NO_FILESYSTEMWATCHER @@ -763,6 +765,25 @@ void tst_QFileSystemWatcher::signalsEmittedAfterFileMoved() QVERIFY2(changedSpy.count() <= fileCount, changedSpy.receivedFilesMessage()); QTRY_COMPARE(changedSpy.count(), fileCount); } + +void tst_QFileSystemWatcher::watchUnicodeCharacters() +{ + QTemporaryDir temporaryDirectory(m_tempDirPattern); + QVERIFY2(temporaryDirectory.isValid(), qPrintable(temporaryDirectory.errorString())); + + QDir testDir(temporaryDirectory.path()); + const QString subDir(QString::fromLatin1("caf\xe9")); + QVERIFY(testDir.mkdir(subDir)); + testDir = QDir(temporaryDirectory.path() + QDir::separator() + subDir); + + QFileSystemWatcher watcher; + QVERIFY(watcher.addPath(testDir.path())); + + FileSystemWatcherSpy changedSpy(&watcher, FileSystemWatcherSpy::SpyOnDirectoryChanged); + QCOMPARE(changedSpy.count(), 0); + QVERIFY(testDir.mkdir("creme")); + QTRY_COMPARE(changedSpy.count(), 1); +} #endif // QT_NO_FILESYSTEMWATCHER QTEST_MAIN(tst_QFileSystemWatcher) -- cgit v1.2.3 From 9c83d7f871f95b1cc03fb404bd602df32056b9cb Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Fri, 30 Sep 2016 15:39:03 -0700 Subject: QCocoaMenuBar: Update even if no window is attached Then we need to check if the current active (or focused) window has any menubar associated. In case there isn't, and the menubar has no window associated, then we should update immediately. The previous condition is still valid. Change-Id: I4532ccc87354d91c76b53f5433dc3944b9e29584 Task-number: QTBUG-56275 Reviewed-by: Erik Verbruggen --- tests/auto/widgets/widgets/qmenubar/qmenubar.pro | 5 +++ .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 24 ++++++++++++ .../widgets/widgets/qmenubar/tst_qmenubar_mac.mm | 44 ++++++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro index 3fb6ae61a8..e680cf4d7d 100644 --- a/tests/auto/widgets/widgets/qmenubar/qmenubar.pro +++ b/tests/auto/widgets/widgets/qmenubar/qmenubar.pro @@ -2,3 +2,8 @@ CONFIG += testcase TARGET = tst_qmenubar QT += widgets testlib SOURCES += tst_qmenubar.cpp + +macos: { + OBJECTIVE_SOURCES += tst_qmenubar_mac.mm + LIBS += -framework AppKit +} diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index b2d15fffef..45eae18240 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -133,6 +133,9 @@ private slots: void cornerWidgets_data(); void cornerWidgets(); void taskQTBUG53205_crashReparentNested(); +#ifdef Q_OS_MACOS + void taskQTBUG56275_reinsertMenuInParentlessQMenuBar(); +#endif protected slots: void onSimpleActivated( QAction*); @@ -1495,7 +1498,28 @@ void tst_QMenuBar::slotForTaskQTBUG53205() taskQTBUG53205MenuBar->setParent(parent); } +#ifdef Q_OS_MACOS +extern bool tst_qmenubar_taskQTBUG56275(QMenuBar *); + +void tst_QMenuBar::taskQTBUG56275_reinsertMenuInParentlessQMenuBar() +{ + QMenuBar menubar; + QMenu *menu = new QMenu("menu", &menubar); + QMenu* submenu = menu->addMenu("submenu"); + submenu->addAction("action1"); + submenu->addAction("action2"); + menu->addAction("action3"); + menubar.addMenu(menu); + + QTest::qWait(100); + menubar.clear(); + menubar.addMenu(menu); + QTest::qWait(100); + + QVERIFY(tst_qmenubar_taskQTBUG56275(&menubar)); +} +#endif // Q_OS_MACOS QTEST_MAIN(tst_QMenuBar) #include "tst_qmenubar.moc" diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm new file mode 100644 index 0000000000..4645de4d7a --- /dev/null +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar_mac.mm @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#import + +#include +#include + +bool tst_qmenubar_taskQTBUG56275(QMenuBar *menubar) +{ + NSMenu *mainMenu = menubar->toNSMenu(); + return mainMenu.numberOfItems == 2 + && [[mainMenu itemAtIndex:1].title isEqualToString:@"menu"]; +} -- cgit v1.2.3 From 047e3f8f046ac9267cc27d47a48189ae2cbfe0ef Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 29 Sep 2016 15:14:22 -0700 Subject: Autotest: fix silly mistake in assigning where a comparison was intended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The file descriptor has been closed and this test is checking if we get EBADF. Change-Id: I33dc971f005a4848bb8ffffd1478eaffd99aa2e9 Reviewed-by: Jake Petroules Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index b38620fcbb..b26db788de 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -3446,7 +3446,7 @@ void tst_QFile::autocloseHandle() //file is closed, read should fail char buf; QCOMPARE((int)QT_READ(fd, &buf, 1), -1); - QVERIFY(errno = EBADF); + QVERIFY(errno == EBADF); } { -- cgit v1.2.3 From 4c00246fea63c348a2992f5a54499f2928bf0605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Somers?= Date: Tue, 25 Oct 2016 16:27:58 +0200 Subject: Fixed crash taking null central widget When no central widget has been set, calling takeCentralWidget should just return a null pointer instead of crashing. [ChangeLog][QtWidgets][QMainWindow] Fixed crash using takeCentralWidget when the central widget was not set. Task-number: QTBUG-56628 Change-Id: I240ccf4caa41d2716a78851571fbfbf444a4922e Reviewed-by: Giuseppe D'Angelo --- tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index 6282028746..ece011d145 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -864,6 +864,10 @@ void tst_QMainWindow::takeCentralWidget() { QVERIFY(!mw.centralWidget()); + // verify that we don't crash when trying to take a non-set + // central widget but just return a null pointer instead + QVERIFY(!mw.takeCentralWidget()); + mw.setCentralWidget(w1); QWidget *oldCentralWidget = mw.takeCentralWidget(); -- cgit v1.2.3