From 672f7dfdcd00d124cd0f973e04e3e2d6445d5483 Mon Sep 17 00:00:00 2001 From: Juha Turunen Date: Tue, 8 Dec 2015 00:51:54 -0800 Subject: Fix a crash when calling QOpenGLTexture::setData with a null QImage. Change-Id: Idf8ae00cff6929114b38dcb003c259c83a11dbaa Reviewed-by: Laszlo Agocs --- tests/auto/gui/qopengl/tst_qopengl.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 8c6c28b492..3e66bcbf70 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -97,8 +98,8 @@ private slots: void textureblitterFullTargetRectTransform(); void textureblitterPartTargetRectTransform(); void defaultSurfaceFormat(); - void imageFormatPainting(); + void nullTextureInitializtion(); #ifdef USE_GLX void glxContextWrap(); @@ -1367,6 +1368,18 @@ void tst_QOpenGL::bufferMapRange() ctx->doneCurrent(); } +void tst_QOpenGL::nullTextureInitializtion() +{ + QScopedPointer surface(createSurface(QSurface::Window)); + QOpenGLContext ctx; + ctx.create(); + ctx.makeCurrent(surface.data()); + + QImage i; + QOpenGLTexture t(i); + QVERIFY(!t.isCreated()); +} + QTEST_MAIN(tst_QOpenGL) #include "tst_qopengl.moc" -- cgit v1.2.3 From 1823c8f2ddd0a5c1b4301e7af7109796090a3c9a Mon Sep 17 00:00:00 2001 From: Erik Verbruggen Date: Wed, 16 Dec 2015 14:04:27 +0100 Subject: Fix utf8->utf16 BOM/ZWNBSP decoding. When the byte sequence for a BOM occurs in the middle of a utf8 stream, it is a ZWNBSP. When a ZWNBSP occurs in the middle of a utf8 character sequence, and the SIMD conversion does some work (meaning: the length is at least 16 characters long), it would not recognize the fact some charactes were already decoded. So the conversion would then strip the ZWNBSP out, thinking it's a BOM. The non-SIMD conversion did not have this problem: the very first character conversion would already set the headerdone flag. Change-Id: I39aacf607e2e068107106254021a8042d164f628 Reviewed-by: Thiago Macieira --- tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index 3aa06d237d..8a9ae0cd72 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -1588,10 +1588,17 @@ void tst_QTextCodec::utf8bom_data() << QString("a"); } - { + { // test the non-SIMD code-path static const ushort data[] = { 0x61, 0xfeff, 0x62 }; - QTest::newRow("middle-bom") - << QByteArray("a\357\273\277b", 5) + QTest::newRow("middle-bom (non SIMD)") + << QByteArray("a\357\273\277b") + << QString::fromUtf16(data, sizeof(data)/sizeof(short)); + } + + { // test the SIMD code-path + static const ushort data[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0xfeff, 0x6d }; + QTest::newRow("middle-bom (SIMD)") + << QByteArray("abcdefghijkl\357\273\277m") << QString::fromUtf16(data, sizeof(data)/sizeof(short)); } } -- cgit v1.2.3 From e96fa5a780665e24fe4710868e399b3216a5d3b3 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 21 Dec 2015 11:37:49 +0100 Subject: Fix timeout calculations using qt_subtract_from_timeout Commit ed0c0070 introduced qt_subtract_from_timeout but used it incorrectly in several places. Change-Id: I80ea16088707929a45d5a61ec6f3370f8e63d1cd Reviewed-by: Oswald Buddenhagen --- .../other/networkselftest/tst_networkselftest.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/other/networkselftest/tst_networkselftest.cpp b/tests/auto/other/networkselftest/tst_networkselftest.cpp index 5612260cca..ca321fb6fd 100644 --- a/tests/auto/other/networkselftest/tst_networkselftest.cpp +++ b/tests/auto/other/networkselftest/tst_networkselftest.cpp @@ -169,14 +169,16 @@ static bool doSocketRead(QTcpSocket *socket, int minBytesAvailable, int timeout { QElapsedTimer timer; timer.start(); + int t = timeout; forever { if (socket->bytesAvailable() >= minBytesAvailable) return true; - timeout = qt_subtract_from_timeout(timeout, timer.elapsed()); - if (socket->state() == QAbstractSocket::UnconnectedState - || timeout == 0) + if (socket->state() == QAbstractSocket::UnconnectedState) return false; - if (!socket->waitForReadyRead(timeout)) + if (!socket->waitForReadyRead(t)) + return false; + t = qt_subtract_from_timeout(timeout, timer.elapsed()); + if (t == 0) return false; } } @@ -197,6 +199,7 @@ static bool doSocketFlush(QTcpSocket *socket, int timeout = 4000) #endif QTime timer; timer.start(); + int t = timeout; forever { if (socket->bytesToWrite() == 0 #ifndef QT_NO_SSL @@ -204,11 +207,12 @@ static bool doSocketFlush(QTcpSocket *socket, int timeout = 4000) #endif ) return true; - timeout = qt_subtract_from_timeout(timeout, timer.elapsed()); - if (socket->state() == QAbstractSocket::UnconnectedState - || timeout == 0) + if (socket->state() == QAbstractSocket::UnconnectedState) + return false; + if (!socket->waitForBytesWritten(t)) return false; - if (!socket->waitForBytesWritten(timeout)) + t = qt_subtract_from_timeout(timeout, timer.elapsed()); + if (t == 0) return false; } } -- cgit v1.2.3 From 64481bcc671892cd140ce5415eaec7fef3e2a35d Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 9 Dec 2015 16:57:54 -0800 Subject: QWidgetWindow: The alien widget should be from the window's hierarchy This partially reverts commit 025d6a778ceb377e688f1. Change-Id: I7b964b0d598abe46137c22177fe2b5dcca5bb812 Task-number: QTBUG-49831 Reviewed-by: Gabriel de Dietrich Reviewed-by: Andy Shaw --- .../widgets/widgets/qcombobox/tst_qcombobox.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 21446de069..00636e50a8 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -165,6 +165,7 @@ private slots: void setCustomModelAndView(); void updateDelegateOnEditableChange(); void task_QTBUG_39088_inputMethodHints(); + void task_QTBUG_49831_scrollerNotActivated(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -3184,5 +3185,36 @@ void tst_QComboBox::task_QTBUG_39088_inputMethodHints() QCOMPARE(box.lineEdit()->inputMethodHints(), Qt::ImhNoPredictiveText); } +void tst_QComboBox::task_QTBUG_49831_scrollerNotActivated() +{ + QStringList modelData; + for (int i = 0; i < 1000; i++) + modelData << QStringLiteral("Item %1").arg(i); + QStringListModel model(modelData); + + QComboBox box; + box.setModel(&model); + box.setCurrentIndex(500); + box.show(); + QTest::qWaitForWindowShown(&box); + QTest::mouseMove(&box, QPoint(5, 5), 100); + box.showPopup(); + QFrame *container = box.findChild(); + QVERIFY(container); + QTest::qWaitForWindowShown(container); + + QList scrollers = container->findChildren(); + // Not all styles support scrollers. We rely only on those platforms that do to catch any regression. + if (!scrollers.isEmpty()) { + Q_FOREACH (QComboBoxPrivateScroller *scroller, scrollers) { + if (scroller->isVisible()) { + QSignalSpy doScrollSpy(scroller, SIGNAL(doScroll(int))); + QTest::mouseMove(scroller, QPoint(5, 5), 500); + QTRY_VERIFY(doScrollSpy.count() > 0); + } + } + } +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" -- cgit v1.2.3 From 6b6955c2ffdb23c461812ffcda12a2296ef58513 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Wed, 23 Dec 2015 13:10:30 +0200 Subject: QAbstractSocket: do not enable read notifications on TCP in bind() In bind+connect scenario, rejected connection can trigger a read notification while the socket is opened. But unlike UDP, reading from the socket engine or emitting a readyRead() signal is not allowed for the TCP socket in bound or connecting state. To make a bind+connect scenario work properly, disable the read notifications until a connection is established. Task-number: QTBUG-50124 Change-Id: I7b3d015b0f6021fb9ff9f83560478aa5545f41f5 Reviewed-by: Richard J. Moore --- .../network/socket/qtcpsocket/tst_qtcpsocket.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 0ba9b6a58c..e8a942e6c4 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -200,6 +200,7 @@ private slots: void setSocketOption(); void clientSendDataOnDelayedDisconnect(); + void readNotificationsAfterBind(); protected slots: void nonBlockingIMAP_hostFound(); @@ -2984,5 +2985,25 @@ void tst_QTcpSocket::clientSendDataOnDelayedDisconnect() delete socket; } +// Test that the socket does not enable the read notifications in bind() +void tst_QTcpSocket::readNotificationsAfterBind() +{ + QFETCH_GLOBAL(bool, setProxy); + if (setProxy) + return; + + QAbstractSocket socket(QAbstractSocket::TcpSocket, Q_NULLPTR); + QVERIFY2(socket.bind(), "Bind error!"); + + connect(&socket, SIGNAL(error(QAbstractSocket::SocketError)), &QTestEventLoop::instance(), SLOT(exitLoop())); + QSignalSpy spyReadyRead(&socket, SIGNAL(readyRead())); + socket.connectToHost(QtNetworkSettings::serverName(), 12346); + + QTestEventLoop::instance().enterLoop(10); + QVERIFY2(!QTestEventLoop::instance().timeout(), "Connection to closed port timed out instead of refusing, something is wrong"); + QVERIFY2(socket.state() == QAbstractSocket::UnconnectedState, "Socket connected unexpectedly!"); + QCOMPARE(spyReadyRead.count(), 0); +} + QTEST_MAIN(tst_QTcpSocket) #include "tst_qtcpsocket.moc" -- cgit v1.2.3 From 38c8af7231823429ca6cb9ea6418e2dcef3691a0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 22 Dec 2015 17:15:57 +0100 Subject: Revert "Fix global coordinate mapping for child widgets in QGraphicsView." This reverts commit 56aad2ad6074237537fecf10d0cda0f3872e7f71. QWidget::mapFromGlobal() does not work correctly when the widget is a child widget of another widget embedded into a QGraphicsView with a transformation (scaling/rotation). It starts applying offsets going up the widget tree (just as mapToGlobal) until it hits the embedded widget not taking into account the transformation. It would need to go in from to top to bottom or better be reimplemented such that a QTransform for mapping coordinates from/to global is determined which is then applied in reverse. Task-number: QTBUG-50030 Task-number: QTBUG-50136 Change-Id: Iadeb891d793be1938c64942bfbf38d541a281c33 Reviewed-by: Marc Mutz --- .../qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index cd40c5541c..f3a683fe8b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3684,6 +3684,7 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135 const QSize size = availableGeometry.size() / 5; QGraphicsScene scene; QGraphicsView view(&scene); + view.setTransform(QTransform::fromScale(2, 2)); // QTBUG-50136, use transform. view.setWindowTitle(QTest::currentTestFunction()); view.resize(size); view.move(availableGeometry.bottomRight() - QPoint(size.width(), size.height()) - QPoint(100, 100)); @@ -3706,10 +3707,15 @@ void tst_QGraphicsProxyWidget::mapToGlobal() // QTBUG-41135 QVERIFY2((viewCenter - embeddedCenterGlobal).manhattanLength() <= 2, msgPointMismatch(embeddedCenterGlobal, viewCenter).constData()); - // Same test with child centered on embeddedWidget + // Same test with child centered on embeddedWidget. The correct + // mapping is not implemented yet, but at least make sure + // the roundtrip maptoGlobal()/mapFromGlobal() returns the same + // point since that is important for mouse event handling (QTBUG-50030, + // QTBUG-50136). const QPoint childCenter = childWidget->rect().center(); const QPoint childCenterGlobal = childWidget->mapToGlobal(childCenter); QCOMPARE(childWidget->mapFromGlobal(childCenterGlobal), childCenter); + QEXPECT_FAIL("", "Not implemented for child widgets of embedded widgets", Continue); QVERIFY2((viewCenter - childCenterGlobal).manhattanLength() <= 4, msgPointMismatch(childCenterGlobal, viewCenter).constData()); } -- cgit v1.2.3 From e0a5f661e52fd09611f406ae82128b6ef81fe90e Mon Sep 17 00:00:00 2001 From: Masaru Ueki Date: Sat, 26 Dec 2015 16:01:25 +0900 Subject: QStateMachine: fix ignore high-priority events. When a high-priority event is posted in overrided 'QStateMachine::beginSelectTransitions', the event may be remained in event queue, and be not dispatched until another event posted. Change-Id: Ifda288d9c00ac7985e426b9cc02bda382ebaac35 Reviewed-by: Erik Verbruggen --- .../qstatemachine/tst_qstatemachine.cpp | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp index 1292c3b98f..e60b1c983c 100644 --- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp +++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp @@ -250,6 +250,7 @@ private slots: void internalTransition(); void conflictingTransition(); void qtbug_46059(); + void postEventFromBeginSelectTransitions(); }; class TestState : public QState @@ -6485,5 +6486,33 @@ void tst_QStateMachine::qtbug_46059() QVERIFY(machine.isRunning()); } +void tst_QStateMachine::postEventFromBeginSelectTransitions() +{ + class StateMachine : public QStateMachine { + protected: + void beginSelectTransitions(QEvent* e) Q_DECL_OVERRIDE { + if (e->type() == QEvent::Type(QEvent::User + 2)) + postEvent(new QEvent(QEvent::Type(QEvent::User + 1)), QStateMachine::HighPriority); + } + } machine; + QState a(&machine); + QState success(&machine); + + machine.setInitialState(&a); + a.addTransition(new EventTransition(QEvent::Type(QEvent::User + 1), &success)); + + machine.start(); + + QTRY_COMPARE(machine.configuration().contains(&a), true); + QTRY_COMPARE(machine.configuration().contains(&success), false); + + machine.postEvent(new QEvent(QEvent::Type(QEvent::User + 2)), QStateMachine::NormalPriority); + + QTRY_COMPARE(machine.configuration().contains(&a), false); + QTRY_COMPARE(machine.configuration().contains(&success), true); + + QVERIFY(machine.isRunning()); +} + QTEST_MAIN(tst_QStateMachine) #include "tst_qstatemachine.moc" -- cgit v1.2.3 From 02f70004c266f4c35f098f49cfb3ca0284e28cac Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Sat, 5 Dec 2015 23:55:17 +0200 Subject: Allow socket events processing with a foreign event loop on Windows While a native dialog is open, the application message queue is handled by the native event loop which is external to Qt. In this case, QEventDispatcherWin32::processEvents() does not run and socket notifiers will not be activated. So, this patch moves the notifier activation code into the window procedure, which enables socket event processing with native dialogs. Task-number: QTBUG-49782 Task-number: QTBUG-48901 Change-Id: Icbdd96b2e80c50b73505f4fe74957575b83d6cf1 Reviewed-by: Oswald Buddenhagen Reviewed-by: Kai Koehne Reviewed-by: Joerg Bornemann --- tests/auto/gui/kernel/kernel.pro | 2 +- .../gui/kernel/noqteventloop/noqteventloop.pro | 2 +- .../gui/kernel/noqteventloop/tst_noqteventloop.cpp | 34 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index b03a117f83..5254e755d4 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -24,7 +24,7 @@ SUBDIRS=\ qopenglwindow \ qrasterwindow -win32:!wince*:!winrt: SUBDIRS += noqteventloop +win32:!wince:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop !qtHaveModule(widgets): SUBDIRS -= \ qmouseevent_modal \ diff --git a/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro index de5715e147..a42b359f29 100644 --- a/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro +++ b/tests/auto/gui/kernel/noqteventloop/noqteventloop.pro @@ -1,7 +1,7 @@ CONFIG += testcase TARGET = tst_noqteventloop -QT += core-private gui-private testlib +QT += core-private network gui-private testlib SOURCES += tst_noqteventloop.cpp diff --git a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp index d21569dcc0..735d23b137 100644 --- a/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp +++ b/tests/auto/gui/kernel/noqteventloop/tst_noqteventloop.cpp @@ -36,6 +36,9 @@ #include #include #include +#include +#include +#include #include @@ -47,6 +50,7 @@ private slots: void initTestCase(); void cleanup(); void consumeMouseEvents(); + void consumeSocketEvents(); }; @@ -265,6 +269,36 @@ void tst_NoQtEventLoop::consumeMouseEvents() } +void tst_NoQtEventLoop::consumeSocketEvents() +{ + int argc = 1; + char *argv[] = { const_cast("test"), 0 }; + QGuiApplication app(argc, argv); + QTcpServer server; + QTcpSocket client; + + QVERIFY(server.listen(QHostAddress::LocalHost)); + client.connectToHost(server.serverAddress(), server.serverPort()); + QVERIFY(client.waitForConnected()); + + QElapsedTimer elapsedTimer; + elapsedTimer.start(); + + // Exec own message loop + MSG msg; + forever { + if (elapsedTimer.hasExpired(3000) || server.hasPendingConnections()) + break; + + if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + } + + QVERIFY(server.hasPendingConnections()); +} + #include QTEST_APPLESS_MAIN(tst_NoQtEventLoop) -- cgit v1.2.3 From 033205bb598fe49e6ca4c90fb4e046e996c20252 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Jan 2016 12:51:02 +0100 Subject: Fix UB in tst_QIODevice::getSetCheck() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reinterpret cast from a QTcpSocket → QAbstractSocket → QIODevice to MyIODevice → QIODevice was undefined. Fix by simply instantiating a MyIODevice, which must then inherit from QTcpSocket, of course. Instead of fixing the class name in the overridden setOpenMode() method, simply make the base class' implementation public with a using declaration. Found by UBSan: qtbase/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp:84:22: runtime error: member call on address 0x7ffcca2d23f0 which does not point to an object of type 'MyIODevice' 0x7ffcca2d23f0: note: object is of type 'QTcpSocket' Change-Id: I939b3548949b9b5765df4a6cc81875e169fd69dd Reviewed-by: Alex Trotsenko Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index 565ca18899..af79de06d5 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -74,16 +74,15 @@ void tst_QIODevice::getSetCheck() { // OpenMode QIODevice::openMode() // void QIODevice::setOpenMode(OpenMode) - class MyIODevice : public QIODevice { + class MyIODevice : public QTcpSocket { public: - void setOpenMode(OpenMode openMode) { QIODevice::setOpenMode(openMode); } + using QTcpSocket::setOpenMode; }; - QTcpSocket var1; - MyIODevice *obj1 = reinterpret_cast(&var1); - obj1->setOpenMode(QIODevice::OpenMode(QIODevice::NotOpen)); - QCOMPARE(QIODevice::OpenMode(QIODevice::NotOpen), obj1->openMode()); - obj1->setOpenMode(QIODevice::OpenMode(QIODevice::ReadWrite)); - QCOMPARE(QIODevice::OpenMode(QIODevice::ReadWrite), obj1->openMode()); + MyIODevice var1; + var1.setOpenMode(QIODevice::OpenMode(QIODevice::NotOpen)); + QCOMPARE(QIODevice::OpenMode(QIODevice::NotOpen), var1.openMode()); + var1.setOpenMode(QIODevice::OpenMode(QIODevice::ReadWrite)); + QCOMPARE(QIODevice::OpenMode(QIODevice::ReadWrite), var1.openMode()); } //---------------------------------------------------------------------------------- -- cgit v1.2.3 From bccbb70de548c5defcb2ab58a987ef2e966788bc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Jan 2016 16:56:26 +0100 Subject: Fix UB in tst_QMetaType Don't pass around meta-type IDs in QMetaType::Type variables. It leads to reading values from an enum variable that are invalid. Fix by passing the IDs around as int. Found by UBSan: tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp:408:5: runtime error: load of value 4028, which is not a valid value for type 'Type' Change-Id: Idd106ee3d7960fe3d8fefc0fc5830fc22d38a513 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 86 +++++++++++----------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 9cdb1f47f8..a4bfc8ac9b 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -369,40 +369,40 @@ void tst_QMetaType::normalizedTypes() } #define TYPENAME_DATA(MetaTypeName, MetaTypeId, RealType)\ - QTest::newRow(#RealType) << QMetaType::MetaTypeName << #RealType; + QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << #RealType; void tst_QMetaType::typeName_data() { - QTest::addColumn("aType"); + QTest::addColumn("aType"); QTest::addColumn("aTypeName"); QT_FOR_EACH_STATIC_TYPE(TYPENAME_DATA) - QTest::newRow("QMetaType::UnknownType") << QMetaType::UnknownType << static_cast(0); + QTest::newRow("QMetaType::UnknownType") << int(QMetaType::UnknownType) << static_cast(0); - QTest::newRow("Whity") << static_cast(::qMetaTypeId >()) << QString::fromLatin1("Whity"); - QTest::newRow("Whity") << static_cast(::qMetaTypeId >()) << QString::fromLatin1("Whity"); - QTest::newRow("Testspace::Foo") << static_cast(::qMetaTypeId()) << QString::fromLatin1("TestSpace::Foo"); + QTest::newRow("Whity") << ::qMetaTypeId >() << QString::fromLatin1("Whity"); + QTest::newRow("Whity") << ::qMetaTypeId >() << QString::fromLatin1("Whity"); + QTest::newRow("Testspace::Foo") << ::qMetaTypeId() << QString::fromLatin1("TestSpace::Foo"); - QTest::newRow("-1") << QMetaType::Type(-1) << QString(); - QTest::newRow("-124125534") << QMetaType::Type(-124125534) << QString(); - QTest::newRow("124125534") << QMetaType::Type(124125534) << QString(); + QTest::newRow("-1") << -1 << QString(); + QTest::newRow("-124125534") << -124125534 << QString(); + QTest::newRow("124125534") << 124125534 << QString(); // automatic registration - QTest::newRow("QList") << static_cast(::qMetaTypeId >()) << QString::fromLatin1("QList"); - QTest::newRow("QHash") << static_cast(::qMetaTypeId >()) << QString::fromLatin1("QHash"); - QTest::newRow("QMap") << static_cast(::qMetaTypeId >()) << QString::fromLatin1("QMap"); - QTest::newRow("QVector>") << static_cast(::qMetaTypeId > >()) << QString::fromLatin1("QVector >"); - QTest::newRow("QVector>") << static_cast(::qMetaTypeId > >()) << QString::fromLatin1("QVector >"); + QTest::newRow("QList") << ::qMetaTypeId >() << QString::fromLatin1("QList"); + QTest::newRow("QHash") << ::qMetaTypeId >() << QString::fromLatin1("QHash"); + QTest::newRow("QMap") << ::qMetaTypeId >() << QString::fromLatin1("QMap"); + QTest::newRow("QVector>") << ::qMetaTypeId > >() << QString::fromLatin1("QVector >"); + QTest::newRow("QVector>") << ::qMetaTypeId > >() << QString::fromLatin1("QVector >"); - QTest::newRow("CustomQObject*") << static_cast(::qMetaTypeId()) << QString::fromLatin1("CustomQObject*"); - QTest::newRow("CustomGadget") << static_cast(::qMetaTypeId()) << QString::fromLatin1("CustomGadget"); - QTest::newRow("CustomQObject::CustomQEnum") << static_cast(::qMetaTypeId()) << QString::fromLatin1("CustomQObject::CustomQEnum"); - QTest::newRow("Qt::ArrowType") << static_cast(::qMetaTypeId()) << QString::fromLatin1("Qt::ArrowType"); + QTest::newRow("CustomQObject*") << ::qMetaTypeId() << QString::fromLatin1("CustomQObject*"); + QTest::newRow("CustomGadget") << ::qMetaTypeId() << QString::fromLatin1("CustomGadget"); + QTest::newRow("CustomQObject::CustomQEnum") << ::qMetaTypeId() << QString::fromLatin1("CustomQObject::CustomQEnum"); + QTest::newRow("Qt::ArrowType") << ::qMetaTypeId() << QString::fromLatin1("Qt::ArrowType"); } void tst_QMetaType::typeName() { - QFETCH(QMetaType::Type, aType); + QFETCH(int, aType); QFETCH(QString, aTypeName); QString name = QString::fromLatin1(QMetaType::typeName(aType)); @@ -413,15 +413,15 @@ void tst_QMetaType::typeName() void tst_QMetaType::type_data() { - QTest::addColumn("aType"); + QTest::addColumn("aType"); QTest::addColumn("aTypeName"); #define TST_QMETATYPE_TYPE_DATA(MetaTypeName, MetaTypeId, RealType)\ - QTest::newRow(#RealType) << QMetaType::MetaTypeName << QByteArray( #RealType ); + QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << QByteArray( #RealType ); #define TST_QMETATYPE_TYPE_DATA_ALIAS(MetaTypeName, MetaTypeId, AliasType, RealTypeString)\ - QTest::newRow(RealTypeString) << QMetaType::MetaTypeName << QByteArray( #AliasType ); + QTest::newRow(RealTypeString) << int(QMetaType::MetaTypeName) << QByteArray( #AliasType ); - QTest::newRow("empty") << QMetaType::UnknownType << QByteArray(); + QTest::newRow("empty") << int(QMetaType::UnknownType) << QByteArray(); QT_FOR_EACH_STATIC_TYPE(TST_QMETATYPE_TYPE_DATA) QT_FOR_EACH_STATIC_ALIAS_TYPE(TST_QMETATYPE_TYPE_DATA_ALIAS) @@ -432,13 +432,13 @@ void tst_QMetaType::type_data() void tst_QMetaType::type() { - QFETCH(QMetaType::Type, aType); + QFETCH(int, aType); QFETCH(QByteArray, aTypeName); // QMetaType::type(QByteArray) - QCOMPARE(QMetaType::type(aTypeName), int(aType)); + QCOMPARE(QMetaType::type(aTypeName), aType); // QMetaType::type(const char *) - QCOMPARE(QMetaType::type(aTypeName.constData()), int(aType)); + QCOMPARE(QMetaType::type(aTypeName.constData()), aType); } void tst_QMetaType::type_fromSubString_data() @@ -727,9 +727,9 @@ template<> struct TestValueFactory { void tst_QMetaType::create_data() { - QTest::addColumn("type"); + QTest::addColumn("type"); #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ - QTest::newRow(QMetaType::typeName(QMetaType::MetaTypeName)) << QMetaType::MetaTypeName; + QTest::newRow(QMetaType::typeName(QMetaType::MetaTypeName)) << int(QMetaType::MetaTypeName); FOR_EACH_CORE_METATYPE(ADD_METATYPE_TEST_ROW) #undef ADD_METATYPE_TEST_ROW } @@ -781,7 +781,7 @@ FOR_EACH_CORE_METATYPE(RETURN_CREATE_FUNCTION) } }; - QFETCH(QMetaType::Type, type); + QFETCH(int, type); TypeTestFunctionGetter::get(type)(); } @@ -832,33 +832,33 @@ FOR_EACH_CORE_METATYPE(RETURN_CREATE_COPY_FUNCTION) } }; - QFETCH(QMetaType::Type, type); + QFETCH(int, type); TypeTestFunctionGetter::get(type)(); } void tst_QMetaType::sizeOf_data() { - QTest::addColumn("type"); + QTest::addColumn("type"); QTest::addColumn("size"); - QTest::newRow("QMetaType::UnknownType") << QMetaType::UnknownType << size_t(0); + QTest::newRow("QMetaType::UnknownType") << int(QMetaType::UnknownType) << size_t(0); #define ADD_METATYPE_TEST_ROW(MetaTypeName, MetaTypeId, RealType) \ - QTest::newRow(#RealType) << QMetaType::MetaTypeName << size_t(QTypeInfo::sizeOf); + QTest::newRow(#RealType) << int(QMetaType::MetaTypeName) << size_t(QTypeInfo::sizeOf); FOR_EACH_CORE_METATYPE(ADD_METATYPE_TEST_ROW) #undef ADD_METATYPE_TEST_ROW - QTest::newRow("Whity") << static_cast(::qMetaTypeId >()) << sizeof(Whity); -QTest::newRow("Whity") << static_cast(::qMetaTypeId >()) << sizeof(Whity); - QTest::newRow("Testspace::Foo") << static_cast(::qMetaTypeId()) << sizeof(TestSpace::Foo); + QTest::newRow("Whity") << ::qMetaTypeId >() << sizeof(Whity); + QTest::newRow("Whity") << ::qMetaTypeId >() << sizeof(Whity); + QTest::newRow("Testspace::Foo") << ::qMetaTypeId() << sizeof(TestSpace::Foo); - QTest::newRow("-1") << QMetaType::Type(-1) << size_t(0); - QTest::newRow("-124125534") << QMetaType::Type(-124125534) << size_t(0); - QTest::newRow("124125534") << QMetaType::Type(124125534) << size_t(0); + QTest::newRow("-1") << -1 << size_t(0); + QTest::newRow("-124125534") << -124125534 << size_t(0); + QTest::newRow("124125534") << 124125534 << size_t(0); } void tst_QMetaType::sizeOf() { - QFETCH(QMetaType::Type, type); + QFETCH(int, type); QFETCH(size_t, size); QCOMPARE(size_t(QMetaType::sizeOf(type)), size); } @@ -870,7 +870,7 @@ void tst_QMetaType::sizeOfStaticLess_data() void tst_QMetaType::sizeOfStaticLess() { - QFETCH(QMetaType::Type, type); + QFETCH(int, type); QFETCH(size_t, size); QCOMPARE(size_t(QMetaType(type).sizeOf()), size); } @@ -1126,7 +1126,7 @@ FOR_EACH_CORE_METATYPE(RETURN_CONSTRUCT_FUNCTION) } }; - QFETCH(QMetaType::Type, type); + QFETCH(int, type); TypeTestFunctionGetter::get(type)(); } @@ -1194,7 +1194,7 @@ FOR_EACH_CORE_METATYPE(RETURN_CONSTRUCT_COPY_FUNCTION) } }; - QFETCH(QMetaType::Type, type); + QFETCH(int, type); TypeTestFunctionGetter::get(type)(); } -- cgit v1.2.3 From f5291bf8b4f74e7dcaa4911594fae8c929e28229 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Jan 2016 17:46:11 +0100 Subject: Fix UB in tst_QObject::noDeclarativeParentChangedOnDestruction() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If QObjectPrivate::declarativeData is set, it is in various places in Qt expected to point to a QAbstractDeclarativeDataImpl, from which ownedByQml1 is unconditionally read. In noDeclarativeParentChangedOnDestruction(), the declarativeData pointer is, however, set to a local QAbstractDeclarativeData instance, which, being an empty class, has size 1 and alignment 1. Depending on the compiler's idea of bit field order, this code either read uninitialized data from the dummy object, or else some random stack memory outside any (valid) object. What caught UBSan's attention, though, was the difference in alignment between the two classes: src/corelib/kernel/qobject.cpp:917:9: runtime error: member access within misaligned address 0x7fffc9cf706f for type 'struct QAbstractDeclarativeDataImpl', which requires 4 byte alignment Fix by providing a properly initialized object of the correct type. Change-Id: Iae83a949ee5a7bc98df13e35ea614c063085fa13 Reviewed-by: Lars Knoll Reviewed-by: Jędrzej Nowacki Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 4617ce5e74..aa6ab31065 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -6396,7 +6396,8 @@ void tst_QObject::noDeclarativeParentChangedOnDestruction() QObject *parent = new QObject; QObject *child = new QObject; - QAbstractDeclarativeData dummy; + QAbstractDeclarativeDataImpl dummy; + dummy.ownedByQml1 = false; QObjectPrivate::get(child)->declarativeData = &dummy; parentChangeCalled = false; -- cgit v1.2.3 From 9c7be0a7ec92a28d5d489fb78c500dad3f01d9ec Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Jan 2016 23:10:12 +0100 Subject: Fix UB in tst_QDialog::showExtension() Don't cast a QDialog to a subclass it is not. Fix by creating it as the required subclass in the first place. Found by UBSan: tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp:203:20: runtime error: downcast of address 0x2b5f5000ad40 which does not point to an object of type 'DummyDialog' tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp:203:46: runtime error: member call on address 0x2b5f5000ad40 which does not point to an object of type 'DummyDialog' Change-Id: I63ae7e782bda6a78d11af5c2bc2f7d88aacd0ac0 Reviewed-by: David Faure Reviewed-by: Lars Knoll --- tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index e62ce3ceb5..a23938959b 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -49,6 +49,14 @@ QT_FORWARD_DECLARE_CLASS(QDialog) +// work around function being protected +class DummyDialog : public QDialog +{ +public: + DummyDialog(): QDialog(0, Qt::X11BypassWindowManagerHint) {} + using QDialog::showExtension; +}; + class tst_QDialog : public QObject { Q_OBJECT @@ -82,7 +90,7 @@ private slots: void transientParent(); private: - QDialog *testWidget; + DummyDialog *testWidget; }; // Testing get/set functions @@ -108,13 +116,6 @@ void tst_QDialog::getSetCheck() QCOMPARE(INT_MAX, obj1.result()); } -// work around function being protected -class DummyDialog : public QDialog { -public: - DummyDialog(): QDialog(0) {} - void showExtension( bool b ) { QDialog::showExtension( b ); } -}; - class ToolDialog : public QDialog { public: @@ -148,7 +149,7 @@ tst_QDialog::tst_QDialog() void tst_QDialog::initTestCase() { // Create the test class - testWidget = new QDialog(0, Qt::X11BypassWindowManagerHint); + testWidget = new DummyDialog; testWidget->resize(200,200); testWidget->show(); qApp->setActiveWindow(testWidget); @@ -193,7 +194,7 @@ void tst_QDialog::showExtension() QPoint oldPosition = testWidget->pos(); // show - ((DummyDialog*)testWidget)->showExtension( true ); + testWidget->showExtension( true ); // while ( testWidget->size() == dlgSize ) // qApp->processEvents(); @@ -202,7 +203,7 @@ void tst_QDialog::showExtension() QCOMPARE(testWidget->pos(), oldPosition); // hide extension. back to old size ? - ((DummyDialog*)testWidget)->showExtension( false ); + testWidget->showExtension( false ); QCOMPARE( testWidget->size(), dlgSize ); testWidget->setExtension( 0 ); -- cgit v1.2.3 From c38b14e2519a2bdbd835e52ee699ae9ac3f45d00 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Jan 2016 23:17:03 +0100 Subject: Fix UB in tst_QSharedPointer::basics() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Binding a reference to the nullptr is undefined behavior. Just skip that particular test when 'ptr' is null. Found by UBSan: tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp:258:32: runtime error: reference binding to null pointer of type 'struct Data' Change-Id: I125588b9d269a6f76716d660d03142f409513885 Reviewed-by: Jędrzej Nowacki Reviewed-by: Lars Knoll Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 7741803224..7538eaf378 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -246,8 +246,10 @@ void tst_QSharedPointer::basics() QCOMPARE(ptr.data(), aData); QCOMPARE(ptr.operator->(), aData); - Data &dataReference = *ptr; - QCOMPARE(&dataReference, aData); + if (!isNull) { + Data &dataReference = *ptr; + QCOMPARE(&dataReference, aData); + } QVERIFY(ptr == aData); QVERIFY(!(ptr != aData)); -- cgit v1.2.3 From 1e2b42523f3a04fc3403ef6864bbcba447e4362c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 6 Jan 2016 17:46:11 +0100 Subject: Fix UB in tst_QObject::disconnectDoesNotLeakFunctor() If CountedStruct is passed a GetSenderObject object, it will attempt to call a member on it from within its own destructor. That works usually quite well, but in this test case, which tests for function object leaks when a connection is torn down because the sender object is destroyed, the destruction of the CountedStruct happens when all connections are severed in ~QObject. At that point, what used to be a GetSenderObject instance no longer is one and the call into one of its member functions invokes undefined behavior. Fix by making QObject::sender() public by a using declaration instead of a wrapper function. Found by UBSan: tests/auto/corelib/kernel/qobject/tst_qobject.cpp:6007:104: runtime error: member call on address 0x7ffc6e7538b0 which does not point to an object of type 'GetSenderObject' 0x7ffc6e7538b0: note: object is of type 'QObject' Change-Id: Ia973140037b3c1b5a670a8a3949d09b956f40349 Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index aa6ab31065..5b1dad78cf 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -5987,7 +5987,7 @@ class GetSenderObject : public QObject { Q_OBJECT public: - QObject *accessSender() { return sender(); } + using QObject::sender; // make public public Q_SLOTS: void triggerSignal() { Q_EMIT aSignal(); } @@ -6003,8 +6003,8 @@ struct CountedStruct CountedStruct(GetSenderObject *sender) : sender(sender) { ++countedStructObjectsCount; } CountedStruct(const CountedStruct &o) : sender(o.sender) { ++countedStructObjectsCount; } CountedStruct &operator=(const CountedStruct &) { return *this; } - // accessSender here allows us to check if there's a deadlock - ~CountedStruct() { --countedStructObjectsCount; if (sender != Q_NULLPTR) (void)sender->accessSender(); } + // calling sender() here allows us to check if there's a deadlock + ~CountedStruct() { --countedStructObjectsCount; if (sender) (void)sender->sender(); } void operator()() const { } GetSenderObject *sender; -- cgit v1.2.3 From 08775e4bd745276bcc6a5a9fdc4bed7aca225112 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 Jan 2016 16:10:00 +0100 Subject: Revert "QString: preserve embedded NULs when converting from QByteArray" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This partially reverts commit e486d69133178ccce7c75cf48201ab28efb20e44. It broke too many users, even though all of them deserved to be broken. The new functionality will be provided by differently-named functions, where possible (problem: equality operators). I did not revert the fix for the off-by-one error in tst_qtextdocumentfragment.cpp. I also didn't revert the change in the inequality relational operators, since for all strings s1, s2 and s2' where s2' is s2 truncated at the first NUL, s1 < s2 ⟺ s1 < s2' (since NUL < c for any c != 0), and, trivially, for ≤, >, ≥, too. This does not hold for = and ≠, of course, since "foo\0bar" ≠ "foo". [ChangeLog][Important Behavior Changes][EDITORIAL] Reverted: All conversions from QByteArray to QString now preserve embedded NULs... Change-Id: If4b47048b39ae5be6ed08e6d91809626a67ea7f5 Reviewed-by: Thiago Macieira --- tests/auto/corelib/tools/qstring/tst_qstring.cpp | 39 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 907dcf17e1..a922e3ad27 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -1148,7 +1148,7 @@ void tst_QString::constructorQByteArray_data() ba1[5] = 'e'; ba1[6] = 'f'; - QTest::newRow( "2" ) << ba1 << QStringLiteral("abc\0def"); + QTest::newRow( "2" ) << ba1 << QString("abc"); QTest::newRow( "3" ) << QByteArray::fromRawData("abcd", 3) << QString("abc"); QTest::newRow( "4" ) << QByteArray("\xc3\xa9") << QString("\xc3\xa9"); @@ -1169,6 +1169,12 @@ void tst_QString::constructorQByteArray() QCOMPARE( strBA, expected ); // test operator= too + if (src.constData()[src.length()] == '\0') { + str1.clear(); + str1 = src.constData(); + QCOMPARE( str1, expected ); + } + strBA.clear(); strBA = src; QCOMPARE( strBA, expected ); @@ -2569,6 +2575,14 @@ void tst_QString::append_bytearray_special_cases() QTEST( str, "res" ); } + + QFETCH( QByteArray, ba ); + if (ba.constData()[ba.length()] == '\0') { + QFETCH( QString, str ); + + str.append(ba.constData()); + QTEST( str, "res" ); + } } void tst_QString::operator_pluseq_data(bool emptyIsNoop) @@ -2599,6 +2613,14 @@ void tst_QString::operator_pluseq_bytearray_special_cases() QTEST( str, "res" ); } + + QFETCH( QByteArray, ba ); + if (ba.constData()[ba.length()] == '\0') { + QFETCH( QString, str ); + + str += ba.constData(); + QTEST( str, "res" ); + } } void tst_QString::operator_eqeq_bytearray_data() @@ -2613,6 +2635,11 @@ void tst_QString::operator_eqeq_bytearray() QVERIFY(expected == src); QVERIFY(!(expected != src)); + + if (src.constData()[src.length()] == '\0') { + QVERIFY(expected == src.constData()); + QVERIFY(!(expected != src.constData())); + } } void tst_QString::swap() @@ -2670,7 +2697,7 @@ void tst_QString::prepend_bytearray_special_cases_data() // byte array with only a 0 ba.resize( 1 ); ba[0] = 0; - QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QStringLiteral("\0foobar "); + QTest::newRow( "emptyString" ) << QString("foobar ") << ba << QString("foobar "); // empty byte array ba.resize( 0 ); @@ -2700,6 +2727,14 @@ void tst_QString::prepend_bytearray_special_cases() QTEST( str, "res" ); } + + QFETCH( QByteArray, ba ); + if (ba.constData()[ba.length()] == '\0') { + QFETCH( QString, str ); + + str.prepend(ba.constData()); + QTEST( str, "res" ); + } } void tst_QString::replace_uint_uint() -- cgit v1.2.3 From 81858bf1722081d99fdea72f55e67c04c5bb3d92 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 4 Nov 2015 10:26:37 +0100 Subject: Don't pretend we know what DST to use for an offset date. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When QDateTime::addDate() and friends sanitize their end-state, they were using the DST status of their start-state (if known) to control it. This lead to misguided results and, in particular, inconsistent results given that a raw-constructed QDateTime comes into being ignorant of its DST, while a .toLocalTime() one knows its DST. Furthermore, the code to do this was triplicated, tricky and poorly explained. So pull it out into a local static function and explain what it's doing, and why, more clearly and only once. Task-number: QTBUG-49008 Change-Id: Ia4bb3c5e9267fff8bb963ea705267998218ed623 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 216c670aee..228ce73c6b 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1616,9 +1616,7 @@ void tst_QDateTime::springForward_data() if (europeanTimeZone) { QTest::newRow("Europe from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; -#if 0 // FIXME: fails QTest::newRow("Europe from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; -#endif // } else if (otherZone) { } else { QSKIP("No spring forward test data for this TZ"); -- cgit v1.2.3 From af45b352d7c29c42035196bb2d7c5c76a2f303da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 11 Jan 2016 19:25:05 +0100 Subject: Fix reentrancy regression in QShortcutMap after c7e5e1d9e When closing a popup dialog using a shortcut, when the popup was originally opened using a shortcut, the closing-shortcut would interfere with the state of the first shortcut, and we ended up sending a key event for the original shortcut. Task-number: QTBUG-50360 Change-Id: I62e5ddb9ca43b28519ede629775bc0d7598dccc4 Reviewed-by: Simon Hausmann --- .../widgets/kernel/qshortcut/tst_qshortcut.cpp | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp index f206a5fe9a..15aef8d503 100644 --- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -72,7 +72,8 @@ public: TriggerSlot4, TriggerSlot5, TriggerSlot6, - TriggerSlot7 + TriggerSlot7, + SendKeyEvent }; enum Result { @@ -84,6 +85,7 @@ public: Slot5Triggered, Slot6Triggered, Slot7Triggered, + SentKeyEvent, Ambiguous } currentResult; @@ -104,6 +106,7 @@ public slots: void ambigSlot7() { currentResult = Ambiguous; ambigResult = Slot7Triggered; } void statusMessage( const QString& message ) { sbText = message; } void shortcutDestroyed(QObject* obj); + void sendKeyEvent() { sendKeyEvents(edit, Qt::CTRL + Qt::Key_B, 0); currentResult = SentKeyEvent; } public slots: void initTestCase(); @@ -981,6 +984,19 @@ void tst_QShortcut::keypressConsumption() QVERIFY(edit->toPlainText().endsWith("a")); clearAllShortcuts(); + edit->clear(); + QCOMPARE(edit->toPlainText().size(), 0); + + setupShortcut(edit, "first", SendKeyEvent, "Ctrl+A"); + + // Verify reentrancy when a non-shortcut is triggered as part + // of shortcut processing. + currentResult = NoResult; + ambigResult = NoResult; + sendKeyEvents(edit, Qt::CTRL + Qt::Key_A, 0); + QCOMPARE(currentResult, SentKeyEvent); + QCOMPARE(ambigResult, NoResult); + QCOMPARE(edit->toPlainText(), QString(QString(""))); } // ------------------------------------------------------------------ @@ -1182,9 +1198,12 @@ QShortcut *tst_QShortcut::setupShortcut(QWidget *parent, const char *name, int t normal = SLOT(slotTrig7()); ambig = SLOT(ambigSlot7()); break; + case SendKeyEvent: + normal = SLOT(sendKeyEvent()); } connect(cut, SIGNAL(activated()), this, normal); - connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); + if (ambig) + connect(cut, SIGNAL(activatedAmbiguously()), this, ambig); connect(cut, SIGNAL(destroyed(QObject*)), this, SLOT(shortcutDestroyed(QObject*))); shortcuts.append(cut); return cut; -- cgit v1.2.3 From 8c89a8b1ef3e4ce549a5d0bbc4168c199e44f8cf Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 8 Jan 2016 13:45:44 +0100 Subject: [Android]: Java uses some deprecated locale codes so account for these There are three deprecated language codes that Java still uses for the locale so we need to account for these inside QLocale by mapping them to the right language. Task-number: QTBUG-49632 Change-Id: Ib66b3f2763e085f7384228f2490b048bb56be259 Reviewed-by: Lars Knoll --- tests/auto/corelib/tools/qlocale/tst_qlocale.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index 0466ced10a..5f046575c4 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -613,7 +613,8 @@ void tst_QLocale::legacyNames() TEST_CTOR("no", Norwegian, Norway) TEST_CTOR("sh_ME", Serbian, Montenegro) TEST_CTOR("tl", Filipino, Philippines) - + TEST_CTOR("iw", Hebrew, Israel) + TEST_CTOR("in", Indonesian, Indonesia) #undef TEST_CTOR } -- cgit v1.2.3 From 294111e25a4e3639a83a87f70ed33ac0b3985f33 Mon Sep 17 00:00:00 2001 From: Alex Trotsenko Date: Sat, 28 Nov 2015 15:27:43 +0200 Subject: QHttpSocketEngine: ensure pending EOF triggers a notification When the remote peer closed the connection, a read notification needs to always be emitted, otherwise the higher layer does not get the disconnected signal. From the other side, underlying QAbstractSocket object could temporarily disable notifications from the engine at any time. To avoid possible blocking of the socket, take a pending EOF into account when the read notifications are re-enabled. Change-Id: Iac9d4e2f790530be3500baf5a2000f1f63df5cc2 Reviewed-by: Ulf Hermann --- .../qhttpsocketengine/tst_qhttpsocketengine.cpp | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp index 179cdb76bc..f6662b6712 100644 --- a/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp +++ b/tests/auto/network/socket/qhttpsocketengine/tst_qhttpsocketengine.cpp @@ -72,6 +72,7 @@ private slots: void downloadBigFile(); // void tcpLoopbackPerformance(); void passwordAuth(); + void ensureEofTriggersNotification(); protected slots: void tcpSocketNonBlocking_hostFound(); @@ -739,5 +740,51 @@ void tst_QHttpSocketEngine::passwordAuth() //---------------------------------------------------------------------------------- +void tst_QHttpSocketEngine::ensureEofTriggersNotification() +{ + QList serverData; + // Set the handshake and server response data + serverData << "HTTP/1.0 200 Connection established\r\n\r\n" << "0"; + MiniHttpServer server(serverData); + + QTcpSocket socket; + connect(&socket, SIGNAL(connected()), SLOT(exitLoopSlot())); + socket.setProxy(QNetworkProxy(QNetworkProxy::HttpProxy, server.serverAddress().toString(), + server.serverPort())); + socket.connectToHost("0.1.2.3", 12345); + + QTestEventLoop::instance().enterLoop(5); + if (QTestEventLoop::instance().timeout()) + QFAIL("Connect timed out"); + + QCOMPARE(socket.state(), QTcpSocket::ConnectedState); + // Disable read notification on server response + socket.setReadBufferSize(1); + socket.putChar(0); + + // Wait for the response + connect(&socket, SIGNAL(readyRead()), SLOT(exitLoopSlot())); + QTestEventLoop::instance().enterLoop(5); + if (QTestEventLoop::instance().timeout()) + QFAIL("Read timed out"); + + QCOMPARE(socket.state(), QTcpSocket::ConnectedState); + QCOMPARE(socket.bytesAvailable(), 1); + // Trigger a read notification + socket.readAll(); + // Check for pending EOF at input + QCOMPARE(socket.bytesAvailable(), 0); + QCOMPARE(socket.state(), QTcpSocket::ConnectedState); + + // Try to read EOF + connect(&socket, SIGNAL(disconnected()), SLOT(exitLoopSlot())); + QTestEventLoop::instance().enterLoop(5); + if (QTestEventLoop::instance().timeout()) + QFAIL("Disconnect timed out"); + + // Check that it's closed + QCOMPARE(socket.state(), QTcpSocket::UnconnectedState); +} + QTEST_MAIN(tst_QHttpSocketEngine) #include "tst_qhttpsocketengine.moc" -- cgit v1.2.3 From 99e25dd7d8bfcb184852110c5f882b89cfb889df Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 Jan 2016 10:55:49 +0100 Subject: CMake: Don't attempt gui-tests if Qt is built with -no-gui Change-Id: I5f327fa1b0c7827535a4b00ca7d0d4281b1eec7b Reviewed-by: Simon Hausmann --- tests/auto/cmake/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 3a607983f9..5248f75a84 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -50,7 +50,9 @@ include("${_Qt5CTestMacros}") if(NOT ${CMAKE_VERSION} VERSION_LESS 2.8.9) # Requires INCLUDE_DIRECTORIES target property in CMake 2.8.8 # and POSITION_INDEPENDENT_CODE target property in 2.8.9 - expect_pass(test_use_modules_function) + if (NOT NO_GUI) + expect_pass(test_use_modules_function) + endif() expect_pass(test_umbrella_config) else() message("CMake version older than 2.8.9 (Found ${CMAKE_VERSION}). Not running test \"test_use_modules_function\" or \"test_umbrella_config\"") -- cgit v1.2.3 From b530ca770f54165cd2766ccebb7269ba45bccb51 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Thu, 7 Jan 2016 09:03:09 +0100 Subject: tst_qtextcocumentlayout::blockVisibility - make the test more robust MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test inserts strings "0" ... "9" into the text document, takes the half of resulting document's size, makes half of lines invisible and compares sizes. On OS X 10.11 after inserting "4" the width changes, so making "4" invisible also reduces the width and QCOMPARE(currentSize, previosHalfSize) fails. Instead of digits, insert the same string "A" 10 times. Change-Id: Ie88a0442703f98949cea9bcdb694cecee59695f3 Task-number: QTBUG-49848 Reviewed-by: Morten Johan Sørvig --- tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/auto') diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp index f59f542a2b..6a14928219 100644 --- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp +++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp @@ -319,7 +319,7 @@ void tst_QTextDocumentLayout::blockVisibility() for (int i = 0; i < 10; ++i) { if (!doc->isEmpty()) cursor.insertBlock(); - cursor.insertText(QString::number(i)); + cursor.insertText("A"); } qreal margin = doc->documentMargin(); -- cgit v1.2.3 From 8dad3bf2121e3ad5e405665fefa28c4d53192bf7 Mon Sep 17 00:00:00 2001 From: Kevin Funk Date: Thu, 14 Jan 2016 23:33:28 +0100 Subject: Fix toDisplayString(QUrl::PreferLocalFile) on Win When using QUrl::PreferLocalFile we do want to strip the leading slash, as toLocalFile() would do as well. Behavior change by means of an example: QUrl url(QUrl::fromLocalFile("C:/file.txt") url.toLocalFile() --> "C:/file.txt" Before: url.toDisplayString(QUrl::PreferLocalFile) --> "/C:/file.txt" After: url.toDisplayString(QUrl::PreferLocalFile) --> "C:/file.txt" Task-number: QTBUG-41729 Change-Id: I7d425541f6077ebcf3fcf46feeb7e0f03a0d7fe2 Reviewed-by: Dominik Haumann Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 031a35b380..519b05f492 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -69,6 +69,8 @@ private slots: void resolving(); void toString_data(); void toString(); + void toString_PreferLocalFile_data(); + void toString_PreferLocalFile(); void toString_constructed_data(); void toString_constructed(); void toAndFromStringList_data(); @@ -1050,6 +1052,29 @@ void tst_QUrl::toString() QCOMPARE(url.adjusted(opt).toString(), string); } +void tst_QUrl::toString_PreferLocalFile_data() +{ + QTest::addColumn("url"); + QTest::addColumn("string"); + +#ifdef Q_OS_WIN + QTest::newRow("win-drive") << QUrl(QString::fromLatin1("file:///c:/windows/regedit.exe")) + << QString::fromLatin1("c:/windows/regedit.exe"); + QTest::newRow("win-share") << QUrl(QString::fromLatin1("//Anarki/homes")) + << QString::fromLatin1("//anarki/homes"); +#else + QTest::newRow("unix-path") << QUrl(QString::fromLatin1("file:///tmp")) + << QString::fromLatin1("/tmp"); +#endif +} + +void tst_QUrl::toString_PreferLocalFile() +{ + QFETCH(QUrl, url); + QFETCH(QString, string); + + QCOMPARE(url.toString(QUrl::PreferLocalFile), string); +} void tst_QUrl::toAndFromStringList_data() { -- cgit v1.2.3 From 722df6e0a2c640f09903f9b4f3b686c5c70e82d9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 5 Nov 2015 15:13:48 +0100 Subject: Nomenclature corrections relating to CET. There are several European time zones; the only one relevant to the tests here is CET. They won't work with WET, GMT or EET. So name them and related variables for CET, not for Europe. CET's summer-time isn't called CST; and the (existing) spring forward test works only in CET/CEST, not elsewhere in Europe. Change-Id: I55c7544bf792de7495700b749b935ec534831d8b Reviewed-by: Thiago Macieira --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 228ce73c6b..d8934c1604 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -155,7 +155,7 @@ private slots: private: enum { LocalTimeIsUtc = 0, LocalTimeAheadOfUtc = 1, LocalTimeBehindUtc = -1} localTimeType; - bool europeanTimeZone; + bool zoneIsCET; QDate defDate() const { return QDate(1900, 1, 1); } QTime defTime() const { return QTime(0, 0, 0); } QDateTime defDateTime() const { return QDateTime(defDate(), defTime()); } @@ -173,7 +173,7 @@ tst_QDateTime::tst_QDateTime() { uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t(); uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t(); - europeanTimeZone = (x1 == 631148400 && x2 == 644191200); + zoneIsCET = (x1 == 631148400 && x2 == 644191200); QDateTime dt1 = QDateTime::fromTime_t(0); QDateTime dt2 = QDateTime::fromTime_t(181 * 86400); // six months later, Jul 1 @@ -201,7 +201,7 @@ void tst_QDateTime::initTestCase() break; case LocalTimeAheadOfUtc: typemsg1 = "ahead of"; - typemsg2 = europeanTimeZone ? "and is" : "but isn't"; + typemsg2 = zoneIsCET ? "and is" : "but isn't"; break; } @@ -245,7 +245,7 @@ void tst_QDateTime::ctor() QCOMPARE(dt3.timeSpec(), Qt::UTC); QVERIFY(dt1 == dt2); - if (europeanTimeZone) { + if (zoneIsCET) { QVERIFY(dt1 != dt3); QVERIFY(dt1 < dt3); QVERIFY(dt1.addSecs(3600).toUTC() == dt3); @@ -492,7 +492,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t(123456); QCOMPARE(dt1, QDateTime(QDate(1970, 1, 2), QTime(10, 17, 36), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t(123456); QCOMPARE(dt2, QDateTime(QDate(1970, 1, 2), QTime(11, 17, 36), Qt::LocalTime)); @@ -500,7 +500,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t((uint)(quint32)-123456); QCOMPARE(dt1, QDateTime(QDate(2106, 2, 5), QTime(20, 10, 40), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t((uint)(quint32)-123456); QCOMPARE(dt2, QDateTime(QDate(2106, 2, 5), QTime(21, 10, 40), Qt::LocalTime)); @@ -508,7 +508,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t(1214567890); QCOMPARE(dt1, QDateTime(QDate(2008, 6, 27), QTime(11, 58, 10), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t(1214567890); QCOMPARE(dt2, QDateTime(QDate(2008, 6, 27), QTime(13, 58, 10), Qt::LocalTime)); @@ -516,7 +516,7 @@ void tst_QDateTime::setTime_t() dt1.setTime_t(0x7FFFFFFF); QCOMPARE(dt1, QDateTime(QDate(2038, 1, 19), QTime(3, 14, 7), Qt::UTC)); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime dt2; dt2.setTime_t(0x7FFFFFFF); QCOMPARE(dt2, QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7), Qt::LocalTime)); @@ -533,7 +533,7 @@ void tst_QDateTime::setMSecsSinceEpoch_data() { QTest::addColumn("msecs"); QTest::addColumn("utc"); - QTest::addColumn("european"); + QTest::addColumn("cet"); QTest::newRow("zero") << Q_INT64_C(0) @@ -584,7 +584,7 @@ void tst_QDateTime::setMSecsSinceEpoch() { QFETCH(qint64, msecs); QFETCH(QDateTime, utc); - QFETCH(QDateTime, european); + QFETCH(QDateTime, cet); QDateTime dt; dt.setTimeSpec(Qt::UTC); @@ -595,8 +595,8 @@ void tst_QDateTime::setMSecsSinceEpoch() QCOMPARE(dt.time(), utc.time()); QCOMPARE(dt.timeSpec(), Qt::UTC); - if (europeanTimeZone) { - QCOMPARE(dt.toLocalTime(), european); + if (zoneIsCET) { + QCOMPARE(dt.toLocalTime(), cet); // Test converting from LocalTime to UTC back to LocalTime. QDateTime localDt; @@ -613,13 +613,13 @@ void tst_QDateTime::setMSecsSinceEpoch() QDateTime dt2; dt2.setTimeZone(europe); dt2.setMSecsSinceEpoch(msecs); - QCOMPARE(dt2.date(), european.date()); + QCOMPARE(dt2.date(), cet.date()); // don't compare the time if the date is too early or too late: prior // to 1916, timezones in Europe were not standardised and some OS APIs // have hard limits. Let's restrict it to the 32-bit Unix range if (dt2.date().year() >= 1970 && dt2.date().year() <= 2037) - QCOMPARE(dt2.time(), european.time()); + QCOMPARE(dt2.time(), cet.time()); QCOMPARE(dt2.timeSpec(), Qt::TimeZone); QCOMPARE(dt2.timeZone(), europe); } @@ -643,7 +643,7 @@ void tst_QDateTime::fromMSecsSinceEpoch() { QFETCH(qint64, msecs); QFETCH(QDateTime, utc); - QFETCH(QDateTime, european); + QFETCH(QDateTime, cet); QDateTime dtLocal = QDateTime::fromMSecsSinceEpoch(msecs, Qt::LocalTime); QDateTime dtUtc = QDateTime::fromMSecsSinceEpoch(msecs, Qt::UTC); @@ -665,10 +665,10 @@ void tst_QDateTime::fromMSecsSinceEpoch() if (msecs != std::numeric_limits::max()) QCOMPARE(dtOffset.time(), utc.time().addMSecs(60*60*1000)); - if (europeanTimeZone) { - QCOMPARE(dtLocal.toLocalTime(), european); - QCOMPARE(dtUtc.toLocalTime(), european); - QCOMPARE(dtOffset.toLocalTime(), european); + if (zoneIsCET) { + QCOMPARE(dtLocal.toLocalTime(), cet); + QCOMPARE(dtUtc.toLocalTime(), cet); + QCOMPARE(dtOffset.toLocalTime(), cet); } else { QSKIP("You must test using Central European (CET/CEST) time zone, e.g. TZ=Europe/Oslo"); } @@ -793,7 +793,7 @@ void tst_QDateTime::toString_rfcDate_data() QTest::addColumn("dt"); QTest::addColumn("formatted"); - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("localtime") << QDateTime(QDate(1978, 11, 9), QTime(13, 28, 34)) << QString("09 Nov 1978 13:28:34 +0100"); @@ -1050,7 +1050,7 @@ void tst_QDateTime::addSecs_data() QTest::newRow("utc9") << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC) << 0 << QDateTime(QDate(4000, 1, 1), standardTime, Qt::UTC); - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("cet0") << QDateTime(QDate(2004, 1, 1), standardTime, Qt::LocalTime) << 86400 << QDateTime(QDate(2004, 1, 2), standardTime, Qt::LocalTime); QTest::newRow("cet1") << QDateTime(QDate(2004, 1, 1), standardTime, Qt::LocalTime) << (86400 * 185) @@ -1162,7 +1162,7 @@ void tst_QDateTime::toTimeSpec_data() << QDateTime(QDate(-271821, 4, 20), QTime(23, 0, 0), Qt::UTC) << QDateTime(QDate(-271821, 4, 21), QTime(0, 0, 0), Qt::LocalTime); - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("summer1") << QDateTime(QDate(2004, 6, 30), utcTime, Qt::UTC) << QDateTime(QDate(2004, 6, 30), localDaylightTime, Qt::LocalTime); QTest::newRow("summer2") << QDateTime(QDate(1760, 6, 30), utcTime, Qt::UTC) @@ -1185,7 +1185,7 @@ void tst_QDateTime::toTimeSpec_data() void tst_QDateTime::toTimeSpec() { - if (europeanTimeZone) { + if (zoneIsCET) { QFETCH(QDateTime, fromUtc); QFETCH(QDateTime, fromLocal); @@ -1240,7 +1240,7 @@ void tst_QDateTime::toTimeSpec() QCOMPARE(localToOffset.time(), fromUtc.time()); QCOMPARE(localToOffset.timeSpec(), Qt::UTC); } else { - QSKIP("Not tested with timezone other than Central European (CET/CST)"); + QSKIP("Not tested with timezone other than Central European (CET/CEST)"); } } @@ -1251,7 +1251,7 @@ void tst_QDateTime::toLocalTime_data() void tst_QDateTime::toLocalTime() { - if (europeanTimeZone) { + if (zoneIsCET) { QFETCH(QDateTime, fromUtc); QFETCH(QDateTime, fromLocal); @@ -1262,7 +1262,7 @@ void tst_QDateTime::toLocalTime() QCOMPARE(fromUtc.toLocalTime(), fromLocal); QCOMPARE(fromUtc.toLocalTime(), fromLocal.toLocalTime()); } else { - QSKIP("Not tested with timezone other than Central European (CET/CST)"); + QSKIP("Not tested with timezone other than Central European (CET/CEST)"); } } @@ -1273,7 +1273,7 @@ void tst_QDateTime::toUTC_data() void tst_QDateTime::toUTC() { - if (europeanTimeZone) { + if (zoneIsCET) { QFETCH(QDateTime, fromUtc); QFETCH(QDateTime, fromLocal); @@ -1284,7 +1284,7 @@ void tst_QDateTime::toUTC() QCOMPARE(fromLocal.toUTC(), fromUtc); QCOMPARE(fromUtc.toUTC(), fromLocal.toUTC()); } else { - QSKIP("Not tested with timezone other than Central European (CET/CST)"); + QSKIP("Not tested with timezone other than Central European (CET/CEST)"); } QDateTime dt = QDateTime::currentDateTime(); @@ -1614,9 +1614,9 @@ void tst_QDateTime::springForward_data() QTest::addColumn("step"); // days to step; +ve from before, -ve from after QTest::addColumn("adjust"); // minutes ahead of UTC on day stepped from - if (europeanTimeZone) { - QTest::newRow("Europe from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; - QTest::newRow("Europe from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; + if (zoneIsCET) { + QTest::newRow("CET from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; + QTest::newRow("CET from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; // } else if (otherZone) { } else { QSKIP("No spring forward test data for this TZ"); @@ -1687,7 +1687,7 @@ void tst_QDateTime::operator_eqeq_data() QTest::newRow("invalid == invalid") << invalidDateTime() << invalidDateTime() << true << false; QTest::newRow("invalid == valid #1") << invalidDateTime() << dateTime1 << false << false; - if (europeanTimeZone) { + if (zoneIsCET) { QTest::newRow("data14") << QDateTime(QDate(2004, 1, 2), QTime(2, 2, 3), Qt::LocalTime) << QDateTime(QDate(2004, 1, 2), QTime(1, 2, 3), Qt::UTC) << true << true; } @@ -1719,7 +1719,7 @@ void tst_QDateTime::operator_eqeq() if (equal) QVERIFY(qHash(dt1) == qHash(dt2)); - if (checkEuro && europeanTimeZone) { + if (checkEuro && zoneIsCET) { QVERIFY(dt1.toUTC() == dt2); QVERIFY(dt1 == dt2.toLocalTime()); } @@ -2233,7 +2233,7 @@ void tst_QDateTime::offsetFromUtc() QCOMPARE(dt2.offsetFromUtc(), 0); // LocalTime should vary - if (europeanTimeZone) { + if (zoneIsCET) { // Time definitely in Standard Time so 1 hour ahead QDateTime dt3(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::LocalTime); QCOMPARE(dt3.offsetFromUtc(), 1 * 60 * 60); @@ -2358,7 +2358,7 @@ void tst_QDateTime::timeZoneAbbreviation() QCOMPARE(dt3.timeZoneAbbreviation(), QString("UTC")); // LocalTime should vary - if (europeanTimeZone) { + if (zoneIsCET) { // Time definitely in Standard Time QDateTime dt4(QDate(2013, 1, 1), QTime(0, 0, 0), Qt::LocalTime); #ifdef Q_OS_WIN @@ -2482,7 +2482,7 @@ void tst_QDateTime::isDaylightTime() const QDateTime offset2(QDate(2012, 6, 1), QTime(0, 0, 0), Qt::OffsetFromUTC, 1 * 60 * 60); QVERIFY(!offset2.isDaylightTime()); - if (europeanTimeZone) { + if (zoneIsCET) { QDateTime cet1(QDate(2012, 1, 1), QTime(0, 0, 0)); QVERIFY(!cet1.isDaylightTime()); QDateTime cet2(QDate(2012, 6, 1), QTime(0, 0, 0)); @@ -2494,7 +2494,7 @@ void tst_QDateTime::isDaylightTime() const void tst_QDateTime::daylightTransitions() const { - if (europeanTimeZone) { + if (zoneIsCET) { // CET transitions occur at 01:00:00 UTC on last Sunday in March and October // 2011-03-27 02:00:00 CET became 03:00:00 CEST at msecs = 1301187600000 // 2011-10-30 03:00:00 CEST became 02:00:00 CET at msecs = 1319936400000 -- cgit v1.2.3 From f7d9e34b96926cca9918608c23ead84bd0286db9 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 12 Jan 2016 15:16:25 +0100 Subject: Be fussier about setting tst_QDateTime's globals. Time zones change on the whim of politicians. Consequently, we can seem to be in CET/CEST or on UTC (because we tested sample dates when our zone coincided) when we aren't (i.e. we're in a materially different zone at the time probed by some particular test). Make the initialization of the globals that test this more robust against governmental meddling and document the unfixable problem with Algeria: a DST transition *on the epoch*. Change-Id: I17c5c81d339b80af12f4ffab367e28052dd6c2fa Reviewed-by: Thiago Macieira --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 77 ++++++++++++++++++---- 1 file changed, 63 insertions(+), 14 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index d8934c1604..e4572d7c2c 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -171,21 +171,70 @@ Q_DECLARE_METATYPE(Qt::DateFormat) tst_QDateTime::tst_QDateTime() { - uint x1 = QDateTime(QDate(1990, 1, 1), QTime()).toTime_t(); - uint x2 = QDateTime(QDate(1990, 6, 1), QTime()).toTime_t(); - zoneIsCET = (x1 == 631148400 && x2 == 644191200); - - QDateTime dt1 = QDateTime::fromTime_t(0); - QDateTime dt2 = QDateTime::fromTime_t(181 * 86400); // six months later, Jul 1 - if (dt1.date().year() < 1970 || dt2.date().month() < 7) { - localTimeType = LocalTimeBehindUtc; - } else if (dt1.time().hour() > 0 || dt1.date().day() > 1) { - localTimeType = LocalTimeAheadOfUtc; - } else if (dt2.time().hour() > 0 || dt2.date().day() > 1) { - localTimeType = LocalTimeAheadOfUtc; - } else { - localTimeType = LocalTimeIsUtc; + /* + Due to some jurisdictions changing their zones and rules, it's possible + for a non-CET zone to accidentally match CET at a few tested moments but + be different a few years later or earlier. This would lead to tests + failing if run in the partially-aliasing zone (e.g. Algeria, Lybia). So + test thoroughly; ideally at every mid-winter or mid-summer in whose + half-year any test below assumes zoneIsCET means what it says. (Tests at + or near a DST transition implicate both of the half-years that meet + there.) Years outside the 1970--2038 range, however, are likely not + properly handled by the TZ-database; and QDateTime explicitly handles them + differently, so don't probe them here. + */ + const uint day = 24 * 3600; // in seconds + zoneIsCET = (QDateTime(QDate(2038, 1, 19), QTime(4, 14, 7)).toTime_t() == 0x7fffffff + // Entries a year apart robustly differ by multiples of day. + && QDateTime(QDate(2015, 7, 1), QTime()).toTime_t() == 1435701600 + && QDateTime(QDate(2015, 1, 1), QTime()).toTime_t() == 1420066800 + && QDateTime(QDate(2013, 7, 1), QTime()).toTime_t() == 1372629600 + && QDateTime(QDate(2013, 1, 1), QTime()).toTime_t() == 1356994800 + && QDateTime(QDate(2012, 7, 1), QTime()).toTime_t() == 1341093600 + && QDateTime(QDate(2012, 1, 1), QTime()).toTime_t() == 1325372400 + && QDateTime(QDate(2008, 7, 1), QTime()).toTime_t() == 1214863200 + && QDateTime(QDate(2004, 1, 1), QTime()).toTime_t() == 1072911600 + && QDateTime(QDate(2000, 1, 1), QTime()).toTime_t() == 946681200 + && QDateTime(QDate(1990, 7, 1), QTime()).toTime_t() == 646783200 + && QDateTime(QDate(1990, 1, 1), QTime()).toTime_t() == 631148400 + && QDateTime(QDate(1979, 1, 1), QTime()).toTime_t() == 283993200 + // .toTime_t() returns -1 for everything before this: + && QDateTime(QDate(1970, 1, 1), QTime(1, 0, 0)).toTime_t() == 0); + // Use .toMSecsSinceEpoch() if you really need to test anything earlier. + + /* + Again, rule changes can cause a TZ to look like UTC at some sample dates + but deviate at some date relevant to a test using localTimeType. These + tests mostly use years outside the 1970--2038 range for which TZ data is + credible, so we can't helpfully be exhaustive. So scan a sample of years' + starts and middles. + */ + const int sampled = 3; + // UTC starts of months in 2004, 2038 and 1970: + uint jans[sampled] = { 12418 * day, 24837 * day, 0 }; + uint juls[sampled] = { 12600 * day, 25018 * day, 181 * day }; + localTimeType = LocalTimeIsUtc; + for (int i = sampled; i-- > 0; ) { + QDateTime jan = QDateTime::fromTime_t(jans[i]); + QDateTime jul = QDateTime::fromTime_t(juls[i]); + if (jan.date().year() < 1970 || jul.date().month() < 7) { + localTimeType = LocalTimeBehindUtc; + break; + } else if (jan.time().hour() > 0 || jul.time().hour() > 0 + || jan.date().day() > 1 || jul.date().day() > 1) { + localTimeType = LocalTimeAheadOfUtc; + break; + } } + /* + Even so, TZ=Africa/Algiers will fail fromMSecsSinceEpoch(-1) because it + switched from WET without DST (i.e. UTC) in the late 1960s to WET with DST + for all of 1970 - so they had a DST transition *on the epoch*. They've + since switched to CET with no DST, making life simple; but our tests for + mistakes around the epoch can't tell the difference between what Algeria + really did and the symptoms we can believe a bug might produce: there's + not much we can do about that, that wouldn't hide real bugs. + */ } void tst_QDateTime::initTestCase() -- cgit v1.2.3 From 1967accb64a110a1c84d8f37d413bcd36ab579a1 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Fri, 6 Nov 2015 14:55:11 +0100 Subject: Expand springForward_data() to cover a few more time-zones. The important one is EET, for the benefit of our CI system; but other European zones and the USA's coastal zones likely have enough hackers in them to make this worth checking. Change-Id: Idcc703bce29808e1a0a6279680cc8d3cbed38dac Reviewed-by: Thiago Macieira --- .../auto/corelib/tools/qdatetime/tst_qdatetime.cpp | 38 ++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'tests/auto') diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index e4572d7c2c..6d88b24eda 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -1663,12 +1663,44 @@ void tst_QDateTime::springForward_data() QTest::addColumn("step"); // days to step; +ve from before, -ve from after QTest::addColumn("adjust"); // minutes ahead of UTC on day stepped from - if (zoneIsCET) { + /* + Zone tests compare a summer and winter moment's time_t to known values. + This could in principle be flawed (two DST-using zones in the same + hemisphere with the same DST and standard times but different transition + times) but no actual example is known where this is a problem. Please + document any such conflicts, if discovered. + + See http://www.timeanddate.com/time/zones/ for data on more candidates to + test. + */ + + uint winter = QDateTime(QDate(2015, 1, 1), QTime()).toTime_t(); + uint summer = QDateTime(QDate(2015, 7, 1), QTime()).toTime_t(); + + if (winter == 1420066800 && summer == 1435701600) { QTest::newRow("CET from day before") << QDate(2015, 3, 29) << QTime(2, 30, 0) << 1 << 60; QTest::newRow("CET from day after") << QDate(2015, 3, 29) << QTime(2, 30, 0) << -1 << 120; - // } else if (otherZone) { + } else if (winter == 1420063200 && summer == 1435698000) { + // e.g. Finland, where our CI runs ... + QTest::newRow("EET from day before") << QDate(2015, 3, 29) << QTime(3, 30, 0) << 1 << 120; + QTest::newRow("EET from day after") << QDate(2015, 3, 29) << QTime(3, 30, 0) << -1 << 180; + } else if (winter == 1420070400 && summer == 1435705200) { + // Western European Time, WET/WEST; a.k.a. GMT/BST + QTest::newRow("WET from day before") << QDate(2015, 3, 29) << QTime(1, 30, 0) << 1 << 0; + QTest::newRow("WET from day after") << QDate(2015, 3, 29) << QTime(1, 30, 0) << -1 << 60; + } else if (winter == 1420099200 && summer == 1435734000) { + // Western USA, Canada: Pacific Time (e.g. US/Pacific) + QTest::newRow("PT from day before") << QDate(2015, 3, 8) << QTime(2, 30, 0) << 1 << -480; + QTest::newRow("PT from day after") << QDate(2015, 3, 8) << QTime(2, 30, 0) << -1 << -420; + } else if (winter == 1420088400 && summer == 1435723200) { + // Eastern USA, Canada: Eastern Time (e.g. US/Eastern) + QTest::newRow("ET from day before") << QDate(2015, 3, 8) << QTime(2, 30, 0) << 1 << -300; + QTest::newRow("ET from day after") << QDate(2015, 3, 8) << QTime(2, 30, 0) << -1 << -240; } else { - QSKIP("No spring forward test data for this TZ"); + // Includes the numbers you need to test for your zone, as above: + QString msg(QString::fromLatin1("No spring forward test data for this TZ (%1, %2)" + ).arg(winter).arg(summer)); + QSKIP(qPrintable(msg)); } } -- cgit v1.2.3