summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp47
-rw-r--r--tests/auto/corelib/serialization/json/tst_qtjson.cpp22
-rw-r--r--tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp26
-rw-r--r--tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp79
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp63
-rw-r--r--tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp99
6 files changed, 207 insertions, 129 deletions
diff --git a/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp b/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp
index 593cae6ddfc..29b78415924 100644
--- a/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp
+++ b/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp
@@ -92,8 +92,8 @@ private slots:
void uncPaths();
#endif
#ifndef Q_OS_WIN
- void hiddenFiles();
- void hiddenDirs();
+ void hidden_data();
+ void hidden();
#endif
void withStdAlgorithms();
@@ -871,45 +871,46 @@ void tst_QDirListing::uncPaths()
// anything starting by a '.' is a hidden file.
// For that reason these two tests aren't run on Windows.
-void tst_QDirListing::hiddenFiles()
+void tst_QDirListing::hidden_data()
{
- QStringList expected = {
+ QTest::addColumn<QDirListing::IteratorFlags>("flags");
+ QTest::addColumn<QStringList>("expected");
+
+ using F = QDirListing::IteratorFlag;
+
+ QTest::newRow("Recursive-ExcludeDirs")
+ << (F::ExcludeDirs | F::IncludeHidden | F::Recursive)
+ << QStringList{
"hiddenDirs_hiddenFiles/.hiddenDirectory/.hiddenFile"_L1,
"hiddenDirs_hiddenFiles/.hiddenDirectory/normalFile"_L1,
"hiddenDirs_hiddenFiles/.hiddenFile"_L1,
"hiddenDirs_hiddenFiles/normalDirectory/.hiddenFile"_L1,
"hiddenDirs_hiddenFiles/normalDirectory/normalFile"_L1,
"hiddenDirs_hiddenFiles/normalFile"_L1,
- };
-
- constexpr auto flags = ItFlag::ExcludeDirs | ItFlag::IncludeHidden | ItFlag::Recursive;
- QStringList list;
- list.reserve(expected.size());
- for (const auto &dirEntry : QDirListing(u"hiddenDirs_hiddenFiles"_s, flags)) {
- QVERIFY(dirEntry.isFile());
- list.emplace_back(dirEntry.filePath());
- }
- list.sort();
-
- QCOMPARE_EQ(list, expected);
-}
+ };
-void tst_QDirListing::hiddenDirs()
-{
- QStringList expected = {
+ QTest::newRow("Recursive-ExcludeFiles")
+ << (F::ExcludeFiles | F::IncludeHidden | F::Recursive)
+ << QStringList{
"hiddenDirs_hiddenFiles/.hiddenDirectory"_L1,
"hiddenDirs_hiddenFiles/.hiddenDirectory/.hidden-subdir"_L1,
"hiddenDirs_hiddenFiles/.hiddenDirectory/subdir"_L1,
"hiddenDirs_hiddenFiles/normalDirectory"_L1,
"hiddenDirs_hiddenFiles/normalDirectory/.hidden-subdir"_L1,
"hiddenDirs_hiddenFiles/normalDirectory/subdir"_L1,
- };
+ };
+}
+
+void tst_QDirListing::hidden()
+{
+ QFETCH(QDirListing::IteratorFlags, flags);
+ QFETCH(QStringList, expected);
- constexpr auto flags = ItFlag::ExcludeFiles | ItFlag::IncludeHidden | ItFlag::Recursive;
QStringList list;
list.reserve(expected.size());
+ bool isDir = flags.testFlags(ItFlag::ExcludeFiles);
for (const auto &dirEntry : QDirListing(u"hiddenDirs_hiddenFiles"_s, flags)) {
- QVERIFY(dirEntry.isDir());
+ QVERIFY(isDir ? dirEntry.isDir() : dirEntry.isFile());
list.emplace_back(dirEntry.filePath());
}
list.sort();
diff --git a/tests/auto/corelib/serialization/json/tst_qtjson.cpp b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
index 2e0d8dd7be2..dbaf6873af2 100644
--- a/tests/auto/corelib/serialization/json/tst_qtjson.cpp
+++ b/tests/auto/corelib/serialization/json/tst_qtjson.cpp
@@ -3595,7 +3595,7 @@ void tst_QtJson::bom()
QCOMPARE(error.error, QJsonParseError::NoError);
}
-void tst_QtJson::nesting()
+static void nesting_test()
{
// check that we abort parsing too deeply nested json documents.
// this is to make sure we don't crash because the parser exhausts the
@@ -3654,6 +3654,26 @@ void tst_QtJson::nesting()
}
+void tst_QtJson::nesting()
+{
+#if defined(Q_OS_QNX) || defined(Q_OS_VXWORKS) || defined(Q_OS_WASM)
+ // This test misbehaving probably indicates a stack overflow due to the
+ // recursive parser in qjsonparser.cpp. The recursion prevention limit may
+ // be too high for this platform. Someone should investigate.
+ QSKIP("Test freezes or crashes - probably a stack overflow");
+#endif
+
+ QThread *thr = QThread::create(nesting_test);
+#if defined(__SANITIZE_ADDRESS__) || __has_feature(address_sanitizer) || \
+ defined(__SANITIZE_THREAD__) || __has_feature(thread_sanitizer)
+ // force a larger stack size - 8 MB seems sufficient
+ thr->setStackSize(8192 * 1024);
+#endif
+ thr->start();
+ thr->wait();
+ delete thr;
+}
+
void tst_QtJson::longStrings()
{
// test around 15 and 16 bit boundaries, as these are limits
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
index bd9e00fc376..7b4193e3749 100644
--- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
@@ -86,6 +86,9 @@ private slots:
void intersectionPointOnEdge();
void boundsAtStartPoint();
+
+ void percentAtEmptyPath_data();
+ void percentAtEmptyPath();
};
void tst_QPainterPath::cleanupTestCase()
@@ -1637,6 +1640,29 @@ void tst_QPainterPath::boundsAtStartPoint()
QCOMPARE(constructedPath.controlPointRect(), defaultPath.controlPointRect());
}
+void tst_QPainterPath::percentAtEmptyPath_data()
+{
+ const QPointF qpf(2., 2.);
+ QTest::addColumn<QPainterPath>("path");
+
+ QTest::newRow("defaultConstructed") << QPainterPath();
+ QTest::newRow("withStartPoint") << QPainterPath(qpf);
+ QPainterPath pp(qpf);
+ pp.lineTo(qpf);
+ QTest::newRow("equalPoints") << pp;
+}
+
+void tst_QPainterPath::percentAtEmptyPath()
+{
+ QFETCH(QPainterPath, path);
+
+ path.angleAtPercent(0.5);
+ path.pointAtPercent(0.5);
+ path.slopeAtPercent(0.5);
+
+ path.percentAtLength(0);
+}
+
QTEST_APPLESS_MAIN(tst_QPainterPath)
#include "tst_qpainterpath.moc"
diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
index 4814206cd75..40292f0c44d 100644
--- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
+++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp
@@ -132,6 +132,7 @@ private:
bool m_skipUnsupportedIPv6Tests;
bool m_workaroundLinuxKernelBug;
+ int loopbackInterface = 0; // unknown by default
QList<QHostAddress> allAddresses;
QHostAddress multicastGroup4, multicastGroup6;
QList<QHostAddress> linklocalMulticastGroups;
@@ -140,6 +141,16 @@ private:
QUdpSocket *m_asyncReceiver;
};
+// Unlike for IPv6 with IPV6_PKTINFO, IPv4 has no standardized way of obtaining
+// the packet's destination addresses. This means the destinationAddress() be
+// empty, so whitelist the OSes for which we know we have an implementation.
+// That's currently all of them, which means there probably is code in this
+// test that assumes this works without checking this variable.
+//
+// Note: this applies to single-stack operations; dual stack implementations
+// appear to be buggy or not present at all in some OSes.
+static constexpr bool HasWorkingIPv4DestinationAddress = true;
+
#ifdef SHOULD_CHECK_SYSCALL_SUPPORT
bool tst_QUdpSocket::ipv6SetsockoptionMissing(int level, int optname)
{
@@ -246,7 +257,23 @@ void tst_QUdpSocket::initTestCase()
if (!QtNetworkSettings::verifyTestNetworkSettings())
QSKIP("No network test server available");
#endif
- allAddresses = QNetworkInterface::allAddresses();
+
+ allAddresses.clear();
+ for (const QNetworkInterface &iface : QNetworkInterface::allInterfaces()) {
+ if (!iface.flags().testAnyFlags(QNetworkInterface::IsUp))
+ continue;
+ if (iface.flags().testAnyFlags(QNetworkInterface::IsLoopBack))
+ loopbackInterface = iface.index();
+
+ // add this interface's addresses
+ const QList<QNetworkAddressEntry> addresses = iface.addressEntries();
+ for (const QNetworkAddressEntry &entry : addresses) {
+ allAddresses += entry.ip();
+ if (!loopbackInterface && entry.ip().isLoopback())
+ loopbackInterface = iface.index();
+ }
+ }
+
m_skipUnsupportedIPv6Tests = shouldSkipIpv6TestsForBrokenSetsockopt();
// Create a pair of random multicast groups so we avoid clashing with any
@@ -568,12 +595,12 @@ void tst_QUdpSocket::broadcasting()
QVERIFY2(allAddresses.contains(dgram.senderAddress()),
dgram.senderAddress().toString().toLatin1());
QCOMPARE(dgram.senderPort(), int(broadcastSocket.localPort()));
- if (!dgram.destinationAddress().isNull()) {
+ if (HasWorkingIPv4DestinationAddress) {
QVERIFY2(dgram.destinationAddress() == QHostAddress::Broadcast
|| broadcastAddresses.contains(dgram.destinationAddress()),
dgram.destinationAddress().toString().toLatin1());
- QCOMPARE(dgram.destinationPort(), int(serverSocket.localPort()));
}
+ QCOMPARE(dgram.destinationPort(), int(serverSocket.localPort()));
int ttl = dgram.hopLimit();
if (ttl != -1)
@@ -738,15 +765,7 @@ void tst_QUdpSocket::loop()
QCOMPARE(paulDatagram.senderPort(), int(peter.localPort()));
QCOMPARE(peterDatagram.senderPort(), int(paul.localPort()));
- // Unlike for IPv6 with IPV6_PKTINFO, IPv4 has no standardized way of
- // obtaining the packet's destination addresses. The destinationAddress and
- // destinationPort calls could fail, so whitelist the OSes for which we
- // know we have an implementation.
-#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) || defined(Q_OS_WIN)
- QVERIFY(peterDatagram.destinationPort() != -1);
- QVERIFY(paulDatagram.destinationPort() != -1);
-#endif
- if (peterDatagram.destinationPort() == -1) {
+ if (!HasWorkingIPv4DestinationAddress) {
QCOMPARE(peterDatagram.destinationAddress().protocol(), QAbstractSocket::UnknownNetworkLayerProtocol);
QCOMPARE(paulDatagram.destinationAddress().protocol(), QAbstractSocket::UnknownNetworkLayerProtocol);
} else {
@@ -754,6 +773,11 @@ void tst_QUdpSocket::loop()
QCOMPARE(paulDatagram.destinationAddress(), makeNonAny(paul.localAddress()));
QVERIFY(peterDatagram.destinationAddress().isEqual(makeNonAny(peter.localAddress())));
QVERIFY(paulDatagram.destinationAddress().isEqual(makeNonAny(paul.localAddress())));
+
+ if (loopbackInterface) {
+ QCOMPARE(peterDatagram.interfaceIndex(), loopbackInterface);
+ QCOMPARE(paulDatagram.interfaceIndex(), loopbackInterface);
+ }
}
}
@@ -820,6 +844,11 @@ void tst_QUdpSocket::ipv6Loop()
QCOMPARE(paulDatagram.destinationAddress(), makeNonAny(paul.localAddress()));
QCOMPARE(peterDatagram.destinationPort(), peterPort);
QCOMPARE(paulDatagram.destinationPort(), paulPort);
+
+ if (loopbackInterface) {
+ QCOMPARE(peterDatagram.interfaceIndex(), loopbackInterface);
+ QCOMPARE(paulDatagram.interfaceIndex(), loopbackInterface);
+ }
}
void tst_QUdpSocket::dualStack()
@@ -850,6 +879,8 @@ void tst_QUdpSocket::dualStack()
QCOMPARE(dgram.destinationPort(), int(dualSock.localPort()));
QVERIFY(dgram.destinationAddress().isEqual(makeNonAny(dualSock.localAddress(), QHostAddress::LocalHost)));
} else {
+ // Observed on QNX: the IPV6_PKTINFO ancillary data appears to be
+ // missing if the sender is IPv4.
qInfo("Getting IPv4 destination address failed.");
}
@@ -889,12 +920,11 @@ void tst_QUdpSocket::dualStack()
QCOMPARE(dgram.data(), dualData);
QCOMPARE(dgram.senderPort(), int(dualSock.localPort()));
QCOMPARE(dgram.senderAddress(), makeNonAny(dualSock.localAddress(), QHostAddress::LocalHost));
-#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) || defined(Q_OS_WIN)
- QVERIFY(dgram.destinationPort() != -1);
-#endif
- if (dgram.destinationPort() != -1) {
- QCOMPARE(dgram.destinationPort(), int(v4Sock.localPort()));
+ QCOMPARE(dgram.destinationPort(), int(v4Sock.localPort()));
+ if (HasWorkingIPv4DestinationAddress) {
QCOMPARE(dgram.destinationAddress(), makeNonAny(v4Sock.localAddress(), QHostAddress::LocalHost));
+ if (loopbackInterface)
+ QCOMPARE(dgram.interfaceIndex(), loopbackInterface);
}
}
@@ -1748,10 +1778,10 @@ void tst_QUdpSocket::multicast()
QVERIFY2(allAddresses.contains(dgram.senderAddress()),
dgram.senderAddress().toString().toLatin1());
QCOMPARE(dgram.senderPort(), int(sender.localPort()));
- if (!dgram.destinationAddress().isNull()) {
+ if (HasWorkingIPv4DestinationAddress) {
QCOMPARE(dgram.destinationAddress(), groupAddress);
- QCOMPARE(dgram.destinationPort(), int(receiver.localPort()));
}
+ QCOMPARE(dgram.destinationPort(), int(receiver.localPort()));
int ttl = dgram.hopLimit();
if (ttl != -1)
@@ -1962,19 +1992,12 @@ void tst_QUdpSocket::linkLocalIPv4()
QCOMPARE(dgram.data().size(), testData.size());
QCOMPARE(dgram.data(), testData);
- // Unlike for IPv6 with IPV6_PKTINFO, IPv4 has no standardized way of
- // obtaining the packet's destination addresses. The destinationAddress
- // and destinationPort calls could fail, so whitelist the OSes we know
- // we have an implementation.
-#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4) || defined(Q_OS_WIN)
- QVERIFY(dgram.destinationPort() != -1);
-#endif
- if (dgram.destinationPort() == -1) {
+ if (!HasWorkingIPv4DestinationAddress) {
QCOMPARE(dgram.destinationAddress().protocol(), QAbstractSocket::UnknownNetworkLayerProtocol);
} else {
QCOMPARE(dgram.destinationAddress(), s->localAddress());
- QCOMPARE(dgram.destinationPort(), int(neutral.localPort()));
}
+ QCOMPARE(dgram.destinationPort(), int(neutral.localPort()));
QVERIFY(neutral.writeDatagram(dgram.makeReply(testData)));
QVERIFY2(s->waitForReadyRead(10000), QtNetworkSettings::msgSocketError(*s).constData());
diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index 17acdea014e..2f0cbf78b25 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -25,6 +25,7 @@
#include <QtWidgets/qtablewidget.h>
#include <QtGui/qevent.h>
+#include <QtGui/qstylehints.h>
#include <QtGui/private/qhighdpiscaling_p.h>
#include <QtCore/qmimedata.h>
@@ -3333,7 +3334,7 @@ void tst_QGraphicsProxyWidget::clickFocus()
EventSpy proxySpy(proxy);
EventSpy widgetSpy(proxy->widget());
- view.setFrameStyle(0);
+ view.setFrameStyle(QFrame::NoFrame);
view.resize(300, 300);
view.show();
QVERIFY(QTest::qWaitForWindowFocused(&view));
@@ -3469,10 +3470,12 @@ void tst_QGraphicsProxyWidget::QTBUG_6986_sendMouseEventToAlienWidget()
auto *hoverButton = new HoverButton(background);
hoverButton->setText("Second button"_L1);
hoverButton->setGeometry(10, 10, 200, 50);
+ hoverButton->setAttribute(Qt::WA_Hover, true);
scene.addWidget(background);
auto *hideButton = new QPushButton("I'm a button with a very very long text"_L1);
hideButton->setGeometry(10, 10, 400, 50);
+ hideButton->setAttribute(Qt::WA_Hover, true);
QGraphicsProxyWidget *topButton = scene.addWidget(hideButton);
connect(hideButton, &QPushButton::clicked, &scene, [&]() { topButton->hide(); });
topButton->setFocus();
@@ -3659,6 +3662,11 @@ public:
return QWidget::event(event);
}
+ void paintEvent(QPaintEvent *) override
+ {
+ QPainter p(this);
+ p.fillRect(rect(), Qt::green);
+ }
};
#if QT_CONFIG(wheelevent)
@@ -3676,6 +3684,11 @@ public:
*/
void tst_QGraphicsProxyWidget::wheelEventPropagation()
{
+ qApp->styleHints()->setWheelScrollLines(3);
+ const auto guard = qScopeGuard([&]() {
+ qApp->styleHints()->setWheelScrollLines(-1);
+ });
+
QGraphicsScene scene(0, 0, 600, 600);
auto *label = new QLabel("Direct"_L1);
@@ -3697,6 +3710,11 @@ void tst_QGraphicsProxyWidget::wheelEventPropagation()
int wheelEventCount = 0;
protected:
+ void paintEvent(QPaintEvent *) override
+ {
+ QPainter p(this);
+ p.fillRect(rect(), Qt::green);
+ }
void wheelEvent(QWheelEvent *) override
{
++wheelEventCount;
@@ -3710,10 +3728,13 @@ void tst_QGraphicsProxyWidget::wheelEventPropagation()
QGraphicsView view(&scene);
view.setFixedHeight(200);
+ view.setFixedWidth(700);
+ view.setFrameStyle(QFrame::NoFrame);
view.show();
QVERIFY(QTest::qWaitForWindowActive(&view));
QVERIFY(view.verticalScrollBar()->isVisible());
+ QVERIFY(!view.horizontalScrollBar()->isVisible());
view.verticalScrollBar()->setValue(0);
QSignalSpy scrollSpy(view.verticalScrollBar(), &QScrollBar::valueChanged);
@@ -3729,6 +3750,8 @@ void tst_QGraphicsProxyWidget::wheelEventPropagation()
phase);
QCoreApplication::processEvents();
};
+ auto vs = view.verticalScrollBar();
+ vs->setSingleStep(9); // each wheel event: wheelScrollLines() * 9 = 27px
qsizetype scrollCount = 0;
// test non-kinetic events; they are not grabbed, and should scroll the view unless
@@ -3816,6 +3839,7 @@ void tst_QGraphicsProxyWidget::forwardTouchEvent()
QGraphicsView view(&scene);
view.show();
+ view.setFrameStyle(QFrame::NoFrame);
QVERIFY(QTest::qWaitForWindowActive(&view));
EventSpy eventSpy(widget);
@@ -3832,16 +3856,14 @@ void tst_QGraphicsProxyWidget::forwardTouchEvent()
QTest::touchEvent(&view, device.get()).move(0, QPoint(16, 16), &view);
QTest::touchEvent(&view, device.get()).release(0, QPoint(15, 15), &view);
- QApplication::processEvents();
-
- QCOMPARE(eventSpy.counts[QEvent::TouchBegin], 1);
- QCOMPARE(eventSpy.counts[QEvent::TouchUpdate], 2);
- QCOMPARE(eventSpy.counts[QEvent::TouchEnd], 1);
+ QTRY_COMPARE(eventSpy.counts[QEvent::TouchBegin], 1);
+ QTRY_COMPARE(eventSpy.counts[QEvent::TouchUpdate], 2);
+ QTRY_COMPARE(eventSpy.counts[QEvent::TouchEnd], 1);
}
void tst_QGraphicsProxyWidget::touchEventPropagation()
{
- QGraphicsScene scene(0, 0, 300, 200);
+ QGraphicsScene scene;
auto *simpleWidget = new QWidget;
simpleWidget->setObjectName("simpleWidget");
simpleWidget->setAttribute(Qt::WA_AcceptTouchEvents, true);
@@ -3873,15 +3895,26 @@ void tst_QGraphicsProxyWidget::touchEventPropagation()
vbox->addWidget(touchWidget2);
QGraphicsProxyWidget *formProxy = scene.addWidget(formWidget);
formProxy->setAcceptTouchEvents(true);
- formProxy->setGeometry(QRectF(50, 50, 200, 160));
+ const auto minSize = formWidget->minimumSize();
+ formProxy->setGeometry(QRectF(50, 50, minSize.width(), minSize.height()));
+
+ // topLeft must be 0/0
+ const auto sceneRect = scene.sceneRect();
+ scene.setSceneRect(QRectF(0, 0, sceneRect.width(), sceneRect.height()));
QGraphicsView view(&scene);
+ // by setting NoFrame, view and view.viewport() have the same
+ // coordinate system
+ view.setFrameStyle(QFrame::NoFrame);
+ // make sure to not have scrollbars
view.setFixedSize(scene.width(), scene.height());
view.verticalScrollBar()->setValue(0);
view.horizontalScrollBar()->setValue(0);
view.viewport()->setObjectName("GraphicsView's Viewport");
view.show();
QVERIFY(QTest::qWaitForWindowExposed(&view));
+ QVERIFY(!view.horizontalScrollBar()->isVisible());
+ QVERIFY(!view.verticalScrollBar()->isVisible());
class TouchEventSpy : public QObject
{
@@ -3913,8 +3946,12 @@ void tst_QGraphicsProxyWidget::touchEventPropagation()
case QEvent::TouchEnd: {
auto *touchEvent = static_cast<QTouchEvent *>(event);
// instead of detaching each QEventPoint, just store the relative positions
- for (const auto &touchPoint : touchEvent->points())
- records[touchPoint.id()] << TouchRecord{receiver, event->type(), touchPoint.position()};
+ for (const auto& touchPoint : touchEvent->points()) {
+ records[touchPoint.id()]
+ << TouchRecord{ receiver, event->type(), touchPoint.position() };
+ qCDebug(lcTests) << touchPoint.id() << "recv:" << receiver << "type"
+ << event->type() << "pos" << touchPoint.position();
+ }
qCDebug(lcTests) << "Recording" << event << receiver;
break;
}
@@ -3944,9 +3981,9 @@ void tst_QGraphicsProxyWidget::touchEventPropagation()
};
// verify that the embedded widget gets the correctly translated event
- QTest::touchEvent(&view, touchDevice.get()).press(0, simpleCenter.toPoint());
+ QTest::touchEvent(&view, touchDevice.get()).press(0, view.mapFromScene(simpleCenter));
// window, viewport, scene, simpleProxy, simpleWidget
- QCOMPARE(eventSpy.count(), 5);
+ QTRY_COMPARE(eventSpy.count(), 5);
QCOMPARE(eventSpy.at(0).receiver, view.windowHandle());
QCOMPARE(eventSpy.at(1).receiver, view.viewport());
QCOMPARE(eventSpy.at(2).receiver, &scene);
@@ -3969,7 +4006,7 @@ void tst_QGraphicsProxyWidget::touchEventPropagation()
QCOMPARE(formWidget->childAt(touchWidget2->pos() + tw2Center), touchWidget2);
// touch events are sent to the view, in view coordinates
- const QPoint formProxyPox = view.mapFromScene(formProxy->pos().toPoint());
+ const QPoint formProxyPox = view.mapFromScene(formProxy->pos());
const QPoint pb1TouchPos = pushButton1->pos() + pb1Center + formProxyPox;
const QPoint pb2TouchPos = pushButton2->pos() + pb2Center + formProxyPox;
const QPoint tw1TouchPos = touchWidget1->pos() + tw1Center + formProxyPox;
diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
index df19ea1568e..48310996c46 100644
--- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
+++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp
@@ -2058,28 +2058,21 @@ void tst_QGraphicsView::mapFromSceneRect()
QWidget topLevel;
QGraphicsView view(&scene,&topLevel);
view.rotate(90);
- view.setFixedSize(200, 200);
- view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ const auto fw = view.frameWidth() * 2;
+ view.setFixedSize(200 + fw, 200 + fw);
topLevel.show();
- QVERIFY(QTest::qWaitForWindowActive(&view));
+ QVERIFY(QTest::qWaitForWindowActive(&topLevel));
+ QVERIFY(!view.horizontalScrollBar()->isVisible());
+ QVERIFY(!view.verticalScrollBar()->isVisible());
- QPolygon polygon;
- polygon << QPoint(98, 98);
- polygon << QPoint(98, 108);
- polygon << QPoint(88, 108);
- polygon << QPoint(88, 98);
-
-
- QPolygon viewPolygon = view.mapFromScene(0, 0, 10, 10);
- for (int i = 0; i < 4; ++i) {
- QVERIFY(qAbs(viewPolygon[i].x() - polygon[i].x()) < 3);
- QVERIFY(qAbs(viewPolygon[i].y() - polygon[i].y()) < 3);
- }
+ const QRectF input(0, 0, 10, 10);
+ // fixed size is 200x200 so center is 100x100
+ const QPolygon polygon{ QPoint(100, 100), QPoint(100, 110), QPoint(90, 110), QPoint(90, 100) };
+ const QPolygon viewPolygon = view.mapFromScene(input);
+ QCOMPARE(viewPolygon, polygon);
QPoint pt = view.mapFromScene(QPointF());
- QPolygon p;
- p << pt << pt << pt << pt;
+ QPolygon p{ pt, pt, pt, pt };
QCOMPARE(view.mapFromScene(QRectF()), p);
}
@@ -2088,28 +2081,18 @@ void tst_QGraphicsView::mapFromScenePoly()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.rotate(90);
- view.setFixedSize(200, 200);
- view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ const auto fw = view.frameWidth() * 2;
+ view.setFixedSize(200 + fw, 200 + fw);
view.show();
-
- QPolygonF polygon;
- polygon << QPoint(0, 0);
- polygon << QPoint(10, 0);
- polygon << QPoint(10, 10);
- polygon << QPoint(0, 10);
-
- QPolygon polygon2;
- polygon2 << QPoint(98, 98);
- polygon2 << QPoint(98, 108);
- polygon2 << QPoint(88, 108);
- polygon2 << QPoint(88, 98);
-
- QPolygon viewPolygon = view.mapFromScene(polygon);
- for (int i = 0; i < 4; ++i) {
- QVERIFY(qAbs(viewPolygon[i].x() - polygon2[i].x()) < 3);
- QVERIFY(qAbs(viewPolygon[i].y() - polygon2[i].y()) < 3);
- }
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+ QVERIFY(!view.horizontalScrollBar()->isVisible());
+ QVERIFY(!view.verticalScrollBar()->isVisible());
+
+ const QPolygonF input{ QPoint(0, 0), QPoint(10, 0), QPoint(10, 10), QPoint(0, 10) };
+ // fixed size is 200x200 so center is 100x100
+ const QPolygon polygon{ QPoint(100, 100), QPoint(100, 110), QPoint(90, 110), QPoint(90, 100) };
+ const QPolygon viewPolygon = view.mapFromScene(input);
+ QCOMPARE(viewPolygon, polygon);
}
void tst_QGraphicsView::mapFromScenePath()
@@ -2117,34 +2100,22 @@ void tst_QGraphicsView::mapFromScenePath()
QGraphicsScene scene;
QGraphicsView view(&scene);
view.rotate(90);
- view.setFixedSize(200, 200);
- view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+ const auto fw = view.frameWidth() * 2;
+ view.setFixedSize(200 + fw, 200 + fw);
view.show();
-
- QPolygonF polygon;
- polygon << QPoint(0, 0);
- polygon << QPoint(10, 0);
- polygon << QPoint(10, 10);
- polygon << QPoint(0, 10);
+ QVERIFY(QTest::qWaitForWindowActive(&view));
+ QVERIFY(!view.horizontalScrollBar()->isVisible());
+ QVERIFY(!view.verticalScrollBar()->isVisible());
+
+ const QPolygonF input{ QPoint(0, 0), QPoint(10, 0), QPoint(10, 10), QPoint(0, 10) };
+ QPainterPath inputPath;
+ inputPath.addPolygon(input);
+ // fixed size is 200x200 so center is 100x100
+ const QPolygon polygon{ QPoint(100, 100), QPoint(100, 110), QPoint(90, 110), QPoint(90, 100) };
QPainterPath path;
path.addPolygon(polygon);
-
- QPolygon polygon2;
- polygon2 << QPoint(98, 98);
- polygon2 << QPoint(98, 108);
- polygon2 << QPoint(88, 108);
- polygon2 << QPoint(88, 98);
- QPainterPath path2;
- path2.addPolygon(polygon2);
-
- QPolygonF pathPoly = view.mapFromScene(path).toFillPolygon();
- QPolygonF path2Poly = path2.toFillPolygon();
-
- for (int i = 0; i < pathPoly.size(); ++i) {
- QVERIFY(qAbs(pathPoly[i].x() - path2Poly[i].x()) < 3);
- QVERIFY(qAbs(pathPoly[i].y() - path2Poly[i].y()) < 3);
- }
+ QPainterPath viewPath = view.mapFromScene(inputPath);
+ QCOMPARE(viewPath, path);
}
void tst_QGraphicsView::sendEvent()