From d345783e4dacffc870c944f88e9323407eb63a07 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 24 Feb 2016 14:30:21 +0100 Subject: Remove superfluous Windows CE special cases from tst_qprocess.cpp Use default timeouts for wait functions. The increased timeouts will only have an effect if the tests fail. Print process errors if the process could not be started, while we're at it. Contract consecutive "#ifndef Q_OS_WINCE" blocks. Change-Id: I6324e4c5b91b89ebb2580635b88705bbda922907 Reviewed-by: Oliver Wolff --- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 35 +++++-------------------- 1 file changed, 6 insertions(+), 29 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 8b311921e2..8b8c731987 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -689,11 +689,7 @@ void tst_QProcess::waitForFinished() process.start("testProcessOutput/testProcessOutput"); -#if !defined(Q_OS_WINCE) - QVERIFY(process.waitForFinished(5000)); -#else - QVERIFY(process.waitForFinished(30000)); -#endif + QVERIFY(process.waitForFinished()); QCOMPARE(process.exitStatus(), QProcess::NormalExit); #if defined (Q_OS_WINCE) @@ -917,12 +913,7 @@ void tst_QProcess::hardExit() proc.start("testProcessEcho/testProcessEcho"); #endif -#ifndef Q_OS_WINCE - QVERIFY(proc.waitForStarted(5000)); -#else - QVERIFY(proc.waitForStarted(10000)); -#endif - + QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString())); proc.kill(); QVERIFY(proc.waitForFinished(5000)); @@ -1415,24 +1406,17 @@ void tst_QProcess::spaceArgsTest() QString program = programs.at(i); process.start(program, args); -#if defined(Q_OS_WINCE) - const int timeOutMS = 10000; -#else - const int timeOutMS = 5000; -#endif QByteArray errorMessage; - bool started = process.waitForStarted(timeOutMS); + bool started = process.waitForStarted(); if (!started) errorMessage = startFailMessage(program, process); QVERIFY2(started, errorMessage.constData()); - QVERIFY(process.waitForFinished(timeOutMS)); + QVERIFY(process.waitForFinished()); QCOMPARE(process.exitStatus(), QProcess::NormalExit); QCOMPARE(process.exitCode(), 0); #if !defined(Q_OS_WINCE) QStringList actual = QString::fromLatin1(process.readAll()).split("|"); -#endif -#if !defined(Q_OS_WINCE) QVERIFY(!actual.isEmpty()); // not interested in the program name, it might be different. actual.removeFirst(); @@ -1457,8 +1441,6 @@ void tst_QProcess::spaceArgsTest() #if !defined(Q_OS_WINCE) actual = QString::fromLatin1(process.readAll()).split("|"); -#endif -#if !defined(Q_OS_WINCE) QVERIFY(!actual.isEmpty()); // not interested in the program name, it might be different. actual.removeFirst(); @@ -1480,13 +1462,8 @@ void tst_QProcess::nativeArguments() proc.start(QString::fromLatin1("testProcessSpacesArgs/nospace"), QStringList()); -#if !defined(Q_OS_WINCE) - QVERIFY(proc.waitForStarted(5000)); - QVERIFY(proc.waitForFinished(5000)); -#else - QVERIFY(proc.waitForStarted(10000)); - QVERIFY(proc.waitForFinished(10000)); -#endif + QVERIFY2(proc.waitForStarted(), qPrintable(proc.errorString())); + QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitStatus(), QProcess::NormalExit); QCOMPARE(proc.exitCode(), 0); -- cgit v1.2.3 From c7e213334bb70fb023e2bdc3a590dfd4605b73ba Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 29 Feb 2016 10:42:58 +0100 Subject: tst_QDialog: Instantiate test dialog on the stack. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the member variable and instantiate only where needed on the stack to prevent it from interfering with windows created by other tests. Remove flag Qt::X11BypassWindowManagerHint as it does not seem to have any effect. Task-number: QTBUG-51516 Change-Id: I3bf88bf148f365c57aaf989671f8b9c3c3f0d8e2 Reviewed-by: Tony Sarajärvi Reviewed-by: Simon Hausmann --- tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp | 89 ++++++++++------------ 1 file changed, 41 insertions(+), 48 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp index 438884df33..dc796dbd73 100644 --- a/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp +++ b/tests/auto/widgets/dialogs/qdialog/tst_qdialog.cpp @@ -55,7 +55,7 @@ QT_FORWARD_DECLARE_CLASS(QDialog) class DummyDialog : public QDialog { public: - DummyDialog(): QDialog(0, Qt::X11BypassWindowManagerHint) {} + DummyDialog(): QDialog() {} using QDialog::showExtension; }; @@ -65,10 +65,8 @@ class tst_QDialog : public QObject public: tst_QDialog(); -public slots: - void initTestCase(); - void cleanupTestCase(); private slots: + void cleanup(); void getSetCheck(); void showExtension_data(); void showExtension(); @@ -91,9 +89,6 @@ private slots: void transientParent_data(); void transientParent(); void dialogInGraphicsView(); - -private: - DummyDialog *testWidget; }; // Testing get/set functions @@ -149,25 +144,12 @@ private: }; tst_QDialog::tst_QDialog() - { } -void tst_QDialog::initTestCase() +void tst_QDialog::cleanup() { - // Create the test class - testWidget = new DummyDialog; - testWidget->resize(200,200); - testWidget->show(); - qApp->setActiveWindow(testWidget); -} - -void tst_QDialog::cleanupTestCase() -{ - if (testWidget) { - delete testWidget; - testWidget = 0; - } + QVERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QDialog::showExtension_data() @@ -190,44 +172,52 @@ void tst_QDialog::showExtension() QFETCH( QSize, extSize ); QFETCH( bool, horizontal ); - // set geometry of main dialog and extension widget - testWidget->setFixedSize( dlgSize ); - QWidget *ext = new QWidget( testWidget ); + DummyDialog testWidget; + testWidget.resize(200, 200); + testWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1Char(':') + + QLatin1String(QTest::currentDataTag())); + testWidget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&testWidget)); + + testWidget.setFixedSize( dlgSize ); + QWidget *ext = new QWidget( &testWidget ); ext->setFixedSize( extSize ); - testWidget->setExtension( ext ); - testWidget->setOrientation( horizontal ? Qt::Horizontal : Qt::Vertical ); + testWidget.setExtension( ext ); + testWidget.setOrientation( horizontal ? Qt::Horizontal : Qt::Vertical ); - QCOMPARE( testWidget->size(), dlgSize ); - QPoint oldPosition = testWidget->pos(); + QCOMPARE( testWidget.size(), dlgSize ); + QPoint oldPosition = testWidget.pos(); // show - testWidget->showExtension( true ); + testWidget.showExtension( true ); // while ( testWidget->size() == dlgSize ) // qApp->processEvents(); - QTEST( testWidget->size(), "result" ); + QTEST( testWidget.size(), "result" ); - QCOMPARE(testWidget->pos(), oldPosition); + QCOMPARE(testWidget.pos(), oldPosition); // hide extension. back to old size ? - testWidget->showExtension( false ); - QCOMPARE( testWidget->size(), dlgSize ); + testWidget.showExtension( false ); + QCOMPARE( testWidget.size(), dlgSize ); - testWidget->setExtension( 0 ); + testWidget.setExtension( 0 ); } void tst_QDialog::defaultButtons() { - QLineEdit *lineEdit = new QLineEdit(testWidget); - QPushButton *push = new QPushButton("Button 1", testWidget); - QPushButton *pushTwo = new QPushButton("Button 2", testWidget); - QPushButton *pushThree = new QPushButton("Button 3", testWidget); + DummyDialog testWidget; + testWidget.resize(200, 200); + testWidget.setWindowTitle(QTest::currentTestFunction()); + QLineEdit *lineEdit = new QLineEdit(&testWidget); + QPushButton *push = new QPushButton("Button 1", &testWidget); + QPushButton *pushTwo = new QPushButton("Button 2", &testWidget); + QPushButton *pushThree = new QPushButton("Button 3", &testWidget); pushThree->setAutoDefault(false); - //we need to show the buttons. Otherwise they won't get the focus - push->show(); - pushTwo->show(); - pushThree->show(); + testWidget.show(); + QApplication::setActiveWindow(&testWidget); + QVERIFY(QTest::qWaitForWindowActive(&testWidget)); push->setDefault(true); QVERIFY(push->isDefault()); @@ -380,11 +370,15 @@ void tst_QDialog::showAsTool() #if defined(Q_OS_UNIX) QSKIP("Qt/X11: Skipped since activeWindow() is not respected by all window managers"); #endif - ToolDialog dialog(testWidget); - testWidget->activateWindow(); + DummyDialog testWidget; + testWidget.resize(200, 200); + testWidget.setWindowTitle(QTest::currentTestFunction()); + ToolDialog dialog(&testWidget); + testWidget.show(); + testWidget.activateWindow(); + QVERIFY(QTest::qWaitForWindowActive(&testWidget)); dialog.exec(); - QTest::qWait(100); - if (testWidget->style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, testWidget)) { + if (testWidget.style()->styleHint(QStyle::SH_Widget_ShareActivation, 0, &testWidget)) { QCOMPARE(dialog.wasActive(), true); } else { QCOMPARE(dialog.wasActive(), false); @@ -607,7 +601,6 @@ void tst_QDialog::transientParent_data() void tst_QDialog::transientParent() { QFETCH(bool, nativewidgets); - testWidget->hide(); QWidget topLevel; topLevel.resize(200, 200); topLevel.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100)); -- cgit v1.2.3 From 6f75c189e1e5651b716afb316c801d080001c155 Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 24 Feb 2016 12:36:36 +0100 Subject: Fix crash in QProcess::waitForFinished on Windows Suppose the user connects QProcess::readyReadStandardOutput with a slot that calls QCoreApplication::processEvents. Assume the event loop did not handle events between QProcess::start and QProcess::waitForFinished. The process writes to stdout and exits. QProcessPrivate::waitForFinished calls drainOutputPipes which calls QWindowsPipeWriter::waitForReadyRead. This in turn will trigger _q_processDied via the readyRead signal and processEvents. _q_processDied will delete the pid object and set pid to null. After drainOutputPipes returns, _q_processDied is called again but it must not be called if pid is already destroyed. Prevent calling _q_processDied if pid is null. Task-number: QTBUG-48697 Change-Id: Iee047938ee1529057a1a43d71f4e882750903c7e Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 8b8c731987..46bf1a19e8 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -145,6 +145,8 @@ private slots: void startStopStartStop(); void startStopStartStopBuffers_data(); void startStopStartStopBuffers(); + void processEventsInAReadyReadSlot_data(); + void processEventsInAReadyReadSlot(); // keep these at the end, since they use lots of processes and sometimes // caused obscure failures to occur in tests that followed them (esp. on the Mac) @@ -157,6 +159,7 @@ private slots: protected slots: void readFromProcess(); void exitLoopSlot(); + void processApplicationEvents(); #ifndef Q_OS_WINCE void restartProcess(); void waitForReadyReadInAReadyReadSlotSlot(); @@ -475,6 +478,11 @@ void tst_QProcess::exitLoopSlot() QTestEventLoop::instance().exitLoop(); } +void tst_QProcess::processApplicationEvents() +{ + QCoreApplication::processEvents(); +} + #ifndef Q_OS_WINCE // Reading and writing to a process is not supported on Qt/CE void tst_QProcess::echoTest2() @@ -2499,6 +2507,31 @@ void tst_QProcess::startStopStartStopBuffers() } } +void tst_QProcess::processEventsInAReadyReadSlot_data() +{ + QTest::addColumn("callWaitForReadyRead"); + + QTest::newRow("no waitForReadyRead") << false; + QTest::newRow("waitForReadyRead") << true; +} + +void tst_QProcess::processEventsInAReadyReadSlot() +{ + // Test whether processing events in a readyReadXXX slot crashes. (QTBUG-48697) + QFETCH(bool, callWaitForReadyRead); + QProcess process; + QObject::connect(&process, &QProcess::readyReadStandardOutput, + this, &tst_QProcess::processApplicationEvents); + process.start("testProcessEcho/testProcessEcho"); + QVERIFY(process.waitForStarted()); + const QByteArray data(156, 'x'); + process.write(data.constData(), data.size() + 1); + if (callWaitForReadyRead) + QVERIFY(process.waitForReadyRead()); + if (process.state() == QProcess::Running) + QVERIFY(process.waitForFinished()); +} + #endif //QT_NO_PROCESS QTEST_MAIN(tst_QProcess) -- cgit v1.2.3 From cb6d751efa2199746cd3c19e6639f8c23891e283 Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Tue, 16 Feb 2016 08:46:56 +0100 Subject: Fix tests for platforms without process support Change-Id: I2d1cefdb5ff574635a75b54499efc392aba84434 Reviewed-by: Oliver Wolff --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 2 ++ tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro | 4 +++- tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 0d43b09d6b..f3334b1222 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -279,8 +279,10 @@ static void playWithObjects() void tst_QObject::initTestCase() { +#ifndef QT_NO_PROCESS const QString testDataDir = QFileInfo(QFINDTESTDATA("signalbug")).absolutePath(); QVERIFY2(QDir::setCurrent(testDataDir), qPrintable("Could not chdir to " + testDataDir)); +#endif } void tst_QObject::disconnect() diff --git a/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro b/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro index a36b15c906..69062a9741 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro +++ b/tests/auto/corelib/kernel/qsharedmemory/qsharedmemory.pro @@ -1,3 +1,5 @@ TEMPLATE = subdirs -SUBDIRS = sharedmemoryhelper test +!winrt: SUBDIRS = sharedmemoryhelper + +SUBDIRS += test diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp index 26bb70fc66..43e25743d7 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp @@ -138,7 +138,9 @@ tst_QSharedMemory::~tst_QSharedMemory() void tst_QSharedMemory::initTestCase() { +#ifndef QT_NO_PROCESS QVERIFY2(!m_helperBinary.isEmpty(), "Could not find helper binary"); +#endif } void tst_QSharedMemory::init() -- cgit v1.2.3 From 0aed4fd941c610517a68447cafa474a0c26ff2d2 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 1 Mar 2016 15:31:39 +0100 Subject: tst_qimagewriter: Fix leaking temporary files. Add missing slash to the prefix pointing to the temporary directory. Change-Id: I0d00f706af58214a9922758a60d097cab7d6bc9d Reviewed-by: Frederik Gladhorn --- tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp index 1dd4d69ea8..b3fdd00eb6 100644 --- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp @@ -117,7 +117,7 @@ void tst_QImageWriter::initTestCase() prefix = QFINDTESTDATA("images/"); if (prefix.isEmpty()) QFAIL("Can't find images directory!"); - writePrefix = m_temporaryDir.path(); + writePrefix = m_temporaryDir.path() + QLatin1Char('/'); } // Testing get/set functions -- cgit v1.2.3 From 2b2232b5ea8e952310f9b7e09c9691080dfb778e Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 2 Mar 2016 16:09:38 +0100 Subject: Speed up tst_QLocalSocket::sendData The data function for this test re-used listenAndConnect_data that has an additional column "connections" which was never used in sendData. Thus sendData executed three times the same code which is just uselessly burned CI time. Copied the actually needed code of listenAndConnect_data to sendData_data. Change-Id: I6cdb1c1b72cb4ce7be7c13e90eea30ac09a14914 Reviewed-by: Friedemann Kleint --- tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp index d7480a4109..0505544a29 100644 --- a/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp +++ b/tests/auto/network/socket/qlocalsocket/tst_qlocalsocket.cpp @@ -498,7 +498,11 @@ void tst_QLocalSocket::connectWithOldOpen() void tst_QLocalSocket::sendData_data() { - listenAndConnect_data(); + QTest::addColumn("name"); + QTest::addColumn("canListen"); + + QTest::newRow("null") << QString() << false; + QTest::newRow("tst_localsocket") << "tst_localsocket" << true; } void tst_QLocalSocket::sendData() -- cgit v1.2.3 From 43e535dd6f23ee5660dad58bee2ee7e368e67866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tony=20Saraj=C3=A4rvi?= Date: Mon, 29 Feb 2016 12:56:54 +0200 Subject: Blacklist tst_qnetworkreply tests that fail in RHEL 7.1 Task-number: QTBUG-51545 Change-Id: I0f5fdef315f87401ca5e638bce5dd2dbe85bcb83 Reviewed-by: Akseli Salovaara --- tests/auto/network/access/qnetworkreply/BLACKLIST | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkreply/BLACKLIST b/tests/auto/network/access/qnetworkreply/BLACKLIST index 3ec580ddde..0605677e29 100644 --- a/tests/auto/network/access/qnetworkreply/BLACKLIST +++ b/tests/auto/network/access/qnetworkreply/BLACKLIST @@ -7,3 +7,7 @@ ubuntu-14.04 * [backgroundRequestInterruption:ftp, bg, nobg] * +[authenticationCacheAfterCancel:http+socksauth] +rhel-7.1 +[authenticationCacheAfterCancel:https+socksauth] +rhel-7.1 -- cgit v1.2.3 From 559152d911ceff8af5020355b35d7a1da100398c Mon Sep 17 00:00:00 2001 From: Alexander Volkov Date: Thu, 18 Sep 2014 13:13:21 +0400 Subject: Make an implicit grab on TouchBegin for a widget subscribed to a gesture A receiver of TouchUpdate and TouchEnd events is determined either as a widget which has an implicit grab for the touch point or as a visible widget if there are no implicit grabs. The events are sent if the receiver has accepted TouchBegin event or if it is subscribed to a gesture. Before sending the events to the widget they are delivered to the gesture manager. Thus, in order to detect gestures for the widget, it must own an implicit grab or be a visible widget. It can happen that the parent widget is subscribed to a gesture, but doesn't accept TouchBegin event, as in the case of QScrollArea. Then it will not get an implicit grab and gesture detection will be impossible. Activate an implicit grab for such widgets. Also don't send TouchUpdate and TouchEnd to them, because it's against the documentation. Task-number: QTBUG-43277 Change-Id: Id767583991def6d76c48ad15eb39af822cad115d Reviewed-by: Shawn Rutledge --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 48 +++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 293689bff3..fb3e644a5c 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -447,6 +447,7 @@ private slots: void touchEventSynthesizedMouseEvent(); void touchUpdateOnNewTouch(); + void touchEventsForGesturePendingWidgets(); void styleSheetPropagation(); @@ -9788,6 +9789,7 @@ public: m_touchUpdateCount(0), m_touchEndCount(0), m_touchEventCount(0), + m_gestureEventCount(0), m_acceptTouch(false), m_mouseEventCount(0), m_acceptMouse(true) @@ -9825,6 +9827,9 @@ protected: else e->ignore(); return true; + case QEvent::Gesture: + ++m_gestureEventCount; + return true; case QEvent::MouseButtonPress: case QEvent::MouseMove: @@ -9847,6 +9852,7 @@ public: int m_touchUpdateCount; int m_touchEndCount; int m_touchEventCount; + int m_gestureEventCount; bool m_acceptTouch; int m_mouseEventCount; bool m_acceptMouse; @@ -10002,6 +10008,48 @@ void tst_QWidget::touchUpdateOnNewTouch() QCOMPARE(widget.m_touchEndCount, 1); } +void tst_QWidget::touchEventsForGesturePendingWidgets() +{ + QTouchDevice *device = new QTouchDevice; + device->setType(QTouchDevice::TouchScreen); + QWindowSystemInterface::registerTouchDevice(device); + + TouchMouseWidget parent; + TouchMouseWidget child(&parent); + parent.grabGesture(Qt::TapAndHoldGesture); + parent.show(); + + QWindow* window = parent.windowHandle(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + QTest::qWait(500); // needed for QApplication::topLevelAt(), which is used by QGestureManager + QCOMPARE(child.m_touchEventCount, 0); + QCOMPARE(child.m_gestureEventCount, 0); + QCOMPARE(parent.m_touchEventCount, 0); + QCOMPARE(parent.m_gestureEventCount, 0); + QTest::touchEvent(window, device).press(0, QPoint(20, 20), window); + QCOMPARE(child.m_touchEventCount, 0); + QCOMPARE(child.m_gestureEventCount, 0); + QCOMPARE(parent.m_touchBeginCount, 1); // QTapAndHoldGestureRecognizer::create() sets Qt::WA_AcceptTouchEvents + QCOMPARE(parent.m_touchUpdateCount, 0); + QCOMPARE(parent.m_touchEndCount, 0); + QCOMPARE(parent.m_gestureEventCount, 0); + QTest::touchEvent(window, device).move(0, QPoint(25, 25), window); + QCOMPARE(child.m_touchEventCount, 0); + QCOMPARE(child.m_gestureEventCount, 0); + QCOMPARE(parent.m_touchBeginCount, 1); + QCOMPARE(parent.m_touchUpdateCount, 0); + QCOMPARE(parent.m_touchEndCount, 0); + QCOMPARE(parent.m_gestureEventCount, 0); + QTest::qWait(1000); + QTest::touchEvent(window, device).release(0, QPoint(25, 25), window); + QCOMPARE(child.m_touchEventCount, 0); + QCOMPARE(child.m_gestureEventCount, 0); + QCOMPARE(parent.m_touchBeginCount, 1); + QCOMPARE(parent.m_touchUpdateCount, 0); + QCOMPARE(parent.m_touchEndCount, 0); + QVERIFY(parent.m_gestureEventCount > 0); +} + void tst_QWidget::styleSheetPropagation() { QTableView tw; -- cgit v1.2.3 From d0b54cede8d8ea0b8431c64abb51d0cd1a71327b Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 27 Nov 2015 13:28:45 +0100 Subject: Ensure QTextStream doesn't modify the Text flag on the underlying iodevice An empty read or a failed write on the underlying QIODevice of the text stream would lead to an early return where we wouldn't correctly restore the QIODevice::Text flag of the io device. Change-Id: I5b632f45dea6ede3f408113556c3dad1b96574e2 Task-number: QTBUG-47176 Reviewed-by: Marc Mutz Reviewed-by: Simon Hausmann --- tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 3ab53848d8..a0348f3c54 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -228,6 +228,8 @@ private slots: void alignAccountingStyle(); void setCodec(); + void textModeOnEmptyRead(); + private: void generateLineData(bool for_QString); void generateAllData(bool for_QString); @@ -3045,6 +3047,21 @@ void tst_QTextStream::int_write_with_locale() QCOMPARE(result, output); } +void tst_QTextStream::textModeOnEmptyRead() +{ + const QString filename("textmodetest.txt"); + QFile::remove(filename); // Remove file if exists + + + QFile file(filename); + QVERIFY(file.open(QIODevice::ReadWrite | QIODevice::Text)); + QTextStream stream(&file); + QVERIFY(file.isTextModeEnabled()); + QString emptyLine = stream.readLine(); // Text mode flag cleared here + QVERIFY(file.isTextModeEnabled()); +} + + // ------------------------------------------------------------------------------ QTEST_MAIN(tst_QTextStream) -- cgit v1.2.3 From 4ef990ce4a15959c5eabc8f9731b5b5155db5b07 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 8 Mar 2016 09:19:01 +0100 Subject: tst_QKeyEvent: Fix MSVC warning about 64bit shift. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit tst_qkeyevent.cpp(140): warning C4334: '<<': result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?) Change-Id: Id3e0eea125f7f7ec13f9b9428e034b922d2ce204 Reviewed-by: Tor Arne Vestbø --- tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp index bd68400047..db0bfaf622 100644 --- a/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp +++ b/tests/auto/gui/kernel/qkeyevent/tst_qkeyevent.cpp @@ -137,7 +137,7 @@ void tst_QKeyEvent::modifiers_data() for (quint64 bitmask = 1; bitmask < (1 << kNumModifiers) ; ++bitmask) { QVector modifierCombination; for (quint64 modifier = 0; modifier < kNumModifiers; ++modifier) { - if (bitmask & (1 << modifier)) + if (bitmask & (quint64(1) << modifier)) modifierCombination.append(modifier); } modifierCombinations.append(modifierCombination); -- cgit v1.2.3 From 62e89f474551d6de025cc9d53950199df181de16 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 8 Mar 2016 22:41:39 +0100 Subject: tst_QMetaType: fix misleading indention MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As found by GCC 6: tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp:1476:9: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation] tn += ">"; ^~ tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp:1474:5: note: ...this ‘if’ clause, but it is not if (tn.endsWith('>')) ^~ Fix += argument from char[2] to char as a drive-by. Change-Id: I814dc58830934cac7fcf81eb7fd7564b2abeb631 Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index c74a43b682..e35790351d 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -1475,7 +1475,7 @@ static QByteArray createTypeName(const char *begin, const char *va) } if (tn.endsWith('>')) tn += ' '; - tn += ">"; + tn += '>'; return tn; } #endif -- cgit v1.2.3 From cb24903ef4df0571f8498fca6bc58f5df6dd68af Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 9 Mar 2016 10:22:43 +0100 Subject: Generate QVariant::fromValue(enum_value) for enum values Instead of just QVariant(enum_value). Task-number: QTBUG-49383 Change-Id: Id57c65b68d4328816046bc35301dc6afba47b727 Reviewed-by: Friedemann Kleint --- tests/auto/tools/uic/baseline/enumnostdset.ui | 39 ++++++++++++++++++ tests/auto/tools/uic/baseline/enumnostdset.ui.h | 55 +++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/auto/tools/uic/baseline/enumnostdset.ui create mode 100644 tests/auto/tools/uic/baseline/enumnostdset.ui.h (limited to 'tests') diff --git a/tests/auto/tools/uic/baseline/enumnostdset.ui b/tests/auto/tools/uic/baseline/enumnostdset.ui new file mode 100644 index 0000000000..59e27b1be3 --- /dev/null +++ b/tests/auto/tools/uic/baseline/enumnostdset.ui @@ -0,0 +1,39 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 100 + 100 + 100 + 100 + + + + Qt::DashDotLine + + + + + + WorldTimeClock + QWidget +
worldtimeclock.h
+
+
+ + +
diff --git a/tests/auto/tools/uic/baseline/enumnostdset.ui.h b/tests/auto/tools/uic/baseline/enumnostdset.ui.h new file mode 100644 index 0000000000..89a8411b4a --- /dev/null +++ b/tests/auto/tools/uic/baseline/enumnostdset.ui.h @@ -0,0 +1,55 @@ +/******************************************************************************** +** Form generated from reading UI file 'enumnostdset.ui' +** +** Created by: Qt User Interface Compiler version 5.6.1 +** +** WARNING! All changes made in this file will be lost when recompiling UI file! +********************************************************************************/ + +#ifndef ENUMNOSTDSET_H +#define ENUMNOSTDSET_H + +#include +#include +#include +#include +#include +#include +#include "worldtimeclock.h" + +QT_BEGIN_NAMESPACE + +class Ui_Form +{ +public: + WorldTimeClock *worldTimeClock; + + void setupUi(QWidget *Form) + { + if (Form->objectName().isEmpty()) + Form->setObjectName(QStringLiteral("Form")); + Form->resize(400, 300); + worldTimeClock = new WorldTimeClock(Form); + worldTimeClock->setObjectName(QStringLiteral("worldTimeClock")); + worldTimeClock->setGeometry(QRect(100, 100, 100, 100)); + worldTimeClock->setProperty("penStyle", QVariant::fromValue(Qt::DashDotLine)); + + retranslateUi(Form); + + QMetaObject::connectSlotsByName(Form); + } // setupUi + + void retranslateUi(QWidget *Form) + { + Form->setWindowTitle(QApplication::translate("Form", "Form", 0)); + } // retranslateUi + +}; + +namespace Ui { + class Form: public Ui_Form {}; +} // namespace Ui + +QT_END_NAMESPACE + +#endif // ENUMNOSTDSET_H -- cgit v1.2.3 From d29443c9c88d2b15c9a4735cf4d001c65b103a9b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 19 Oct 2015 14:08:28 +0200 Subject: Manual touch test: Remove QDebug operator for QTouchDevice. It now exists in QtGui. Task-number: QTBUG-48849 Change-Id: I9107c96e0010252bc50bcb02ef006cb46bd942df Reviewed-by: Friedemann Kleint --- tests/manual/touch/main.cpp | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'tests') diff --git a/tests/manual/touch/main.cpp b/tests/manual/touch/main.cpp index b7029767c9..2a5c2b508e 100644 --- a/tests/manual/touch/main.cpp +++ b/tests/manual/touch/main.cpp @@ -91,24 +91,6 @@ static void drawArrow(const QPointF ¢er, qreal length, qreal angleDegrees, painter.restore(); } -QDebug operator<<(QDebug debug, const QTouchDevice *d) -{ - QDebugStateSaver saver(debug); - debug.nospace(); - debug << "QTouchDevice(" << d->name() << ','; - switch (d->type()) { - case QTouchDevice::TouchScreen: - debug << "TouchScreen"; - break; - case QTouchDevice::TouchPad: - debug << "TouchPad"; - break; - } - debug << ", capabilities=" << d->capabilities() - << ", maximumTouchPoints=" << d->maximumTouchPoints() << ')'; - return debug; -} - // Hierarchy of classes containing gesture parameters and drawing functionality. class Gesture { Q_DISABLE_COPY(Gesture) -- cgit v1.2.3 From f8f1bac3f0df29e9a3103d385a0c5f9153a9eb66 Mon Sep 17 00:00:00 2001 From: Dyami Caliri Date: Mon, 7 Mar 2016 20:27:09 -0800 Subject: Accept LFCRLF to mark end of HTTP Headers Some embedded servers use LF to mark the end of an individual header, but use CRLF to mark the end of all the headers. The GoPro WiFi interface does this, as an example. Change-Id: I227ab73622c84f439a6cf8703d020393c4d8bf69 Reviewed-by: Marc Mutz Reviewed-by: Markus Goetz (Woboq GmbH) --- .../qhttpnetworkreply/tst_qhttpnetworkreply.cpp | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/access/qhttpnetworkreply/tst_qhttpnetworkreply.cpp b/tests/auto/network/access/qhttpnetworkreply/tst_qhttpnetworkreply.cpp index 16faee9705..231c2de4cb 100644 --- a/tests/auto/network/access/qhttpnetworkreply/tst_qhttpnetworkreply.cpp +++ b/tests/auto/network/access/qhttpnetworkreply/tst_qhttpnetworkreply.cpp @@ -33,6 +33,9 @@ #include +#include +#include + #include "private/qhttpnetworkconnection_p.h" class tst_QHttpNetworkReply: public QObject @@ -46,6 +49,9 @@ private Q_SLOTS: void parseHeader_data(); void parseHeader(); + + void parseEndOfHeader_data(); + void parseEndOfHeader(); }; @@ -122,5 +128,66 @@ void tst_QHttpNetworkReply::parseHeader() } } +class TestHeaderSocket : public QAbstractSocket +{ +public: + explicit TestHeaderSocket(const QByteArray &input) : QAbstractSocket(QAbstractSocket::TcpSocket, Q_NULLPTR) + { + inputBuffer.setData(input); + inputBuffer.open(QIODevice::ReadOnly | QIODevice::Unbuffered); + open(QIODevice::ReadOnly | QIODevice::Unbuffered); + } + + qint64 readData(char *data, qint64 maxlen) { return inputBuffer.read(data, maxlen); } + + QBuffer inputBuffer; +}; + +class TestHeaderReply : public QHttpNetworkReply +{ +public: + QHttpNetworkReplyPrivate *replyPrivate() { return static_cast(d_ptr.data()); } +}; + +void tst_QHttpNetworkReply::parseEndOfHeader_data() +{ + QTest::addColumn("headers"); + QTest::addColumn("lengths"); + + QTest::newRow("CRLFCRLF") << QByteArray("Content-Type: text/html; charset=utf-8\r\n" + "Content-Length:\r\n 1024\r\n" + "Content-Encoding: gzip\r\n\r\nHTTPBODY") + << qint64(90); + + QTest::newRow("CRLFLF") << QByteArray("Content-Type: text/html; charset=utf-8\r\n" + "Content-Length:\r\n 1024\r\n" + "Content-Encoding: gzip\r\n\nHTTPBODY") + << qint64(89); + + QTest::newRow("LFCRLF") << QByteArray("Content-Type: text/html; charset=utf-8\r\n" + "Content-Length:\r\n 1024\r\n" + "Content-Encoding: gzip\n\r\nHTTPBODY") + << qint64(89); + + QTest::newRow("LFLF") << QByteArray("Content-Type: text/html; charset=utf-8\r\n" + "Content-Length:\r\n 1024\r\n" + "Content-Encoding: gzip\n\nHTTPBODY") + << qint64(88); +} + +void tst_QHttpNetworkReply::parseEndOfHeader() +{ + QFETCH(QByteArray, headers); + QFETCH(qint64, lengths); + + TestHeaderSocket socket(headers); + + TestHeaderReply reply; + + QHttpNetworkReplyPrivate *replyPrivate = reply.replyPrivate(); + qint64 headerBytes = replyPrivate->readHeader(&socket); + QCOMPARE(headerBytes, lengths); +} + QTEST_MAIN(tst_QHttpNetworkReply) #include "tst_qhttpnetworkreply.moc" -- cgit v1.2.3 From 2020d2cb63b851723e188c002acbe25b5f066525 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 4 Mar 2016 15:19:50 -0800 Subject: QObject: fix GCC 6 warning about qt_static_metacall's 'hidden' attribute use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This warning is triggered when we try to apply the Q_DECL_HIDDEN attribute to a class in an unnamed namespace. Such classes are already not exported. qobjectdefs.h:175:108: warning: ‘visibility’ attribute ignored [-Wattributes] qobjectdefs.h:198:108: warning: ‘visibility’ attribute ignored [-Wattributes] Added a test on gadgets (and QObjects) in unnamed namespaces, because qtbase currently does not contain such Q_GADGETs. Done-with: Thiago Macieira Change-Id: Ic747cc2ab45e4dc6bb70ffff1438c747b05c5672 Reviewed-by: Lars Knoll Reviewed-by: Olivier Goffart (Woboq GmbH) --- tests/auto/tools/moc/tst_moc.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests') diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index c113b7cd60..5c16c7a48f 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -131,6 +131,33 @@ typedef struct { int doNotConfuseMoc; } OldStyleCStruct; +namespace { + + class GadgetInUnnamedNS + { + Q_GADGET + Q_PROPERTY(int x READ x WRITE setX) + Q_PROPERTY(int y READ y WRITE setY) + public: + explicit GadgetInUnnamedNS(int x, int y) : m_x(x), m_y(y) {} + int x() const { return m_x; } + int y() const { return m_y; } + void setX(int x) { m_x = x; } + void setY(int y) { m_y = y; } + + private: + int m_x, m_y; + }; + + class ObjectInUnnamedNS : public QObject + { + Q_OBJECT + public: + explicit ObjectInUnnamedNS(QObject *parent = Q_NULLPTR) : QObject(parent) {} + }; + +} + class Sender : public QObject { Q_OBJECT @@ -597,6 +624,7 @@ private slots: void relatedMetaObjectsNameConflict_data(); void relatedMetaObjectsNameConflict(); void strignLiteralsInMacroExtension(); + void unnamedNamespaceObjectsAndGadgets(); void veryLongStringData(); void gadgetHierarchy(); @@ -3421,6 +3449,28 @@ class VeryLongStringData : public QObject #undef repeat65534 }; +void tst_Moc::unnamedNamespaceObjectsAndGadgets() +{ + // these just test very basic functionality of gadgets and objects + // defined in unnamed namespaces. + { + GadgetInUnnamedNS gadget(21, 42); + QCOMPARE(gadget.x(), 21); + QCOMPARE(gadget.y(), 42); + gadget.staticMetaObject.property(0).writeOnGadget(&gadget, 12); + gadget.staticMetaObject.property(1).writeOnGadget(&gadget, 24); + QCOMPARE(gadget.x(), 12); + QCOMPARE(gadget.y(), 24); + } + + { + ObjectInUnnamedNS object; + QObject *qObject = &object; + QCOMPARE(static_cast(qObject), + qobject_cast(qObject)); + } +} + void tst_Moc::veryLongStringData() { const QMetaObject *mobj = &VeryLongStringData::staticMetaObject; -- cgit v1.2.3 From f64737527559e22783b57d30ce8bab9ee517974d Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 9 Mar 2016 16:27:47 +0100 Subject: Fix signed integer overflows in tst_QAtomicInteger Signed integer overflows and underflows are undefined behavior. A test that invokes UB tests nothing, because the standard permits any outcome. Fix by guarding the respective operations so they are not executed if they would overflow or underflow. Change-Id: I40354ee88f40e4b47b70eac7790dc3a79ac70a57 Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../thread/qatomicinteger/tst_qatomicinteger.cpp | 88 ++++++++++++++++++++-- 1 file changed, 80 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp index d3c85c54a7..ff41ccf26b 100644 --- a/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp +++ b/tests/auto/corelib/thread/qatomicinteger/tst_qatomicinteger.cpp @@ -362,28 +362,46 @@ void tst_QAtomicIntegerXX::loadAcquireStoreRelease() void tst_QAtomicIntegerXX::refDeref() { QFETCH(LargeInt, value); - T nextValue = T(value + 1); - T prevValue = T(value - 1); + const bool needToPreventOverflow = TypeIsSigned && value == std::numeric_limits::max(); + const bool needToPreventUnderflow = TypeIsSigned && value == std::numeric_limits::min(); + T nextValue = T(value); + if (!needToPreventOverflow) + ++nextValue; + T prevValue = T(value); + if (!needToPreventUnderflow) + --prevValue; QAtomicInteger atomic(value); + if (!needToPreventOverflow) { QCOMPARE(atomic.ref(), (nextValue != 0)); QCOMPARE(atomic.load(), nextValue); QCOMPARE(atomic.deref(), (value != 0)); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.deref(), (prevValue != 0)); QCOMPARE(atomic.load(), prevValue); QCOMPARE(atomic.ref(), (value != 0)); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(++atomic, nextValue); QCOMPARE(--atomic, T(value)); + } + if (!needToPreventUnderflow) { QCOMPARE(--atomic, prevValue); QCOMPARE(++atomic, T(value)); + } + if (!needToPreventOverflow) { QCOMPARE(atomic++, T(value)); QCOMPARE(atomic--, nextValue); + } + if (!needToPreventUnderflow) { QCOMPARE(atomic--, T(value)); QCOMPARE(atomic++, prevValue); + } QCOMPARE(atomic.load(), T(value)); } @@ -486,53 +504,80 @@ void tst_QAtomicIntegerXX::fetchAndAdd() QFETCH(LargeInt, value); QAtomicInteger atomic(value); - // note: this test has undefined behavior for signed max and min T parcel1 = 42; T parcel2 = T(0-parcel1); - T newValue1 = T(value) + parcel1; - T newValue2 = T(value) + parcel2; + const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits::max() + parcel2; + const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits::min() + parcel1; + + T newValue1 = T(value); + if (!needToPreventOverflow) + newValue1 += parcel1; + T newValue2 = T(value); + if (!needToPreventUnderflow) + newValue2 += parcel2; + + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), T(value)); QCOMPARE(atomic.load(), newValue1); QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), newValue1); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddRelaxed(parcel2), T(value)); QCOMPARE(atomic.load(), newValue2); QCOMPARE(atomic.fetchAndAddRelaxed(parcel1), newValue2); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddAcquire(parcel1), T(value)); QCOMPARE(atomic.load(), newValue1); QCOMPARE(atomic.fetchAndAddAcquire(parcel2), newValue1); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddAcquire(parcel2), T(value)); QCOMPARE(atomic.load(), newValue2); QCOMPARE(atomic.fetchAndAddAcquire(parcel1), newValue2); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddRelease(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndAddRelease(parcel2), newValue1); + } QCOMPARE(atomic.loadAcquire(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddRelease(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndAddRelease(parcel1), newValue2); + } QCOMPARE(atomic.loadAcquire(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndAddOrdered(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndAddOrdered(parcel2), newValue1); + } QCOMPARE(atomic.loadAcquire(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndAddOrdered(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndAddOrdered(parcel1), newValue2); + } QCOMPARE(atomic.loadAcquire(), T(value)); // operator+= + if (!needToPreventOverflow) { QCOMPARE(atomic += parcel1, newValue1); QCOMPARE(atomic += parcel2, T(value)); + } + if (!needToPreventUnderflow) { QCOMPARE(atomic += parcel2, newValue2); QCOMPARE(atomic += parcel1, T(value)); + } } void tst_QAtomicIntegerXX::fetchAndSub() @@ -540,53 +585,80 @@ void tst_QAtomicIntegerXX::fetchAndSub() QFETCH(LargeInt, value); QAtomicInteger atomic(value); - // note: this test has undefined behavior for signed max and min T parcel1 = 42; T parcel2 = T(0-parcel1); - T newValue1 = T(value) - parcel1; - T newValue2 = T(value) - parcel2; + const bool needToPreventOverflow = TypeIsSigned && value > std::numeric_limits::max() - parcel1; + const bool needToPreventUnderflow = TypeIsSigned && value < std::numeric_limits::min() - parcel2; + + T newValue1 = T(value); + if (!needToPreventUnderflow) + newValue1 -= parcel1; + T newValue2 = T(value); + if (!needToPreventOverflow) + newValue2 -= parcel2; + + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), T(value)); QCOMPARE(atomic.load(), newValue1); QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), newValue1); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubRelaxed(parcel2), T(value)); QCOMPARE(atomic.load(), newValue2); QCOMPARE(atomic.fetchAndSubRelaxed(parcel1), newValue2); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubAcquire(parcel1), T(value)); QCOMPARE(atomic.load(), newValue1); QCOMPARE(atomic.fetchAndSubAcquire(parcel2), newValue1); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubAcquire(parcel2), T(value)); QCOMPARE(atomic.load(), newValue2); QCOMPARE(atomic.fetchAndSubAcquire(parcel1), newValue2); + } QCOMPARE(atomic.load(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubRelease(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndSubRelease(parcel2), newValue1); + } QCOMPARE(atomic.loadAcquire(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubRelease(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndSubRelease(parcel1), newValue2); + } QCOMPARE(atomic.loadAcquire(), T(value)); + if (!needToPreventUnderflow) { QCOMPARE(atomic.fetchAndSubOrdered(parcel1), T(value)); QCOMPARE(atomic.loadAcquire(), newValue1); QCOMPARE(atomic.fetchAndSubOrdered(parcel2), newValue1); + } QCOMPARE(atomic.loadAcquire(), T(value)); + if (!needToPreventOverflow) { QCOMPARE(atomic.fetchAndSubOrdered(parcel2), T(value)); QCOMPARE(atomic.loadAcquire(), newValue2); QCOMPARE(atomic.fetchAndSubOrdered(parcel1), newValue2); + } QCOMPARE(atomic.loadAcquire(), T(value)); // operator-= + if (!needToPreventUnderflow) { QCOMPARE(atomic -= parcel1, newValue1); QCOMPARE(atomic -= parcel2, T(value)); + } + if (!needToPreventOverflow) { QCOMPARE(atomic -= parcel2, newValue2); QCOMPARE(atomic -= parcel1, T(value)); + } } void tst_QAtomicIntegerXX::addSub() -- cgit v1.2.3 From 45dc347a95fd674cefcf5d1ac63b01557fcb2fef Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 10 Mar 2016 09:44:03 +0100 Subject: tst_QStaticText: Output verbose message for test failures. Factor out function to check on the pixel color that outputs a verbose message on failure. Change-Id: I2331fe45f35327d1ff8ae547a58d93a2e6fe9184 Reviewed-by: Simon Hausmann --- .../auto/gui/text/qstatictext/tst_qstatictext.cpp | 55 +++++++++++++--------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'tests') diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index b8134291af..4b322efa7c 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -610,6 +610,29 @@ void tst_QStaticText::plainTextVsRichText() QCOMPARE(imagePlainText, imageRichText); } +static bool checkPixels(const QImage &image, + Qt::GlobalColor expectedColor1, Qt::GlobalColor expectedColor2, + QByteArray *errorMessage) +{ + const QRgb expectedRgb1 = QColor(expectedColor1).rgba(); + const QRgb expectedRgb2 = QColor(expectedColor2).rgba(); + + for (int x = 0, w = image.width(); x < w; ++x) { + for (int y = 0, h = image.height(); y < h; ++y) { + const QRgb pixel = image.pixel(x, y); + if (pixel != expectedRgb1 && pixel != expectedRgb2) { + QString message; + QDebug(&message) << "Color mismatch in image" << image + << "at" << x << ',' << y << ':' << showbase << hex << pixel + << "(expected: " << expectedRgb1 << ',' << expectedRgb2 << ')'; + *errorMessage = message.toLocal8Bit(); + return false; + } + } + } + return true; +} + void tst_QStaticText::setPenPlainText_data() { QTest::addColumn("format"); @@ -640,13 +663,9 @@ void tst_QStaticText::setPenPlainText() p.drawStaticText(0, 0, staticText); } - for (int x=0; x