From 5cb6260a36d2e98e72c828b7e2559fa3e7a35361 Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Mon, 26 Aug 2013 16:22:24 +0200 Subject: QNetworkReply auto test: Skip tests failing due to Squid issues This test works with no Qt version (4 or 5) when testing with the Squid (HTTP proxy) version deployed on the new test server image. Task-number: QTBUG-33180 Change-Id: If244526a4baed9f3836dade007fe0f15649a8f86 Reviewed-by: Thiago Macieira --- tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index ce8293edbc..5d81367620 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -4387,6 +4387,10 @@ void tst_QNetworkReply::ioPostToHttpFromSocket_data() void tst_QNetworkReply::ioPostToHttpFromSocket() { + if (QTest::currentDataTag() == QByteArray("128k+1+proxyauth") + || QTest::currentDataTag() == QByteArray("128k+1+auth+proxyauth")) + QSKIP("Squid cannot handle authentication with POST data >= 64K (QTBUG-33180)"); + QFETCH(QByteArray, data); QFETCH(QUrl, url); QFETCH(QNetworkProxy, proxy); -- cgit v1.2.3 From 2109965a4e4e54a264c7bcb8a89a27194870a73a Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 27 Aug 2013 14:29:15 +0200 Subject: QTcpSocket auto test: rely on IMAP port, not SMTP port The new test server image will not have a SMTP service installed, and the network self test does not check for that either. Change-Id: I1063777832148e184de4ddf21d9154364f644e1e Reviewed-by: Richard J. Moore --- tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp index 2b9dfc5081..9135ec3d19 100644 --- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp +++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp @@ -1578,7 +1578,7 @@ void tst_QTcpSocket::recursiveReadyRead() QSignalSpy spy(testSocket, SIGNAL(readyRead())); - testSocket->connectToHost(QtNetworkSettings::serverName(), 25); + testSocket->connectToHost(QtNetworkSettings::serverName(), 143); enterLoop(30); QVERIFY2(!timeout(), "Timed out when connecting to QtNetworkSettings::serverName()."); -- cgit v1.2.3 From 5bb4817142f47326a320b316cd1967ecfd501c13 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 27 Aug 2013 14:10:53 +0200 Subject: Center widgets using UpdateWidgets in tst_qwidget. Try to stabilize doubleRepaint and others, try to get them away from taskbar areas. Change-Id: Icae8da575999afccb314edafd7deb16446e3d1c2 Reviewed-by: Frederik Gladhorn --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 0085b75299..227f61b0a3 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -164,6 +164,12 @@ static inline void setFrameless(QWidget *w) w->setWindowFlags(flags); } +static inline void centerOnScreen(QWidget *w) +{ + const QPoint offset = QPoint(w->width() / 2, w->height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + class tst_QWidget : public QObject { Q_OBJECT @@ -4004,7 +4010,8 @@ void tst_QWidget::update() Q_CHECK_PAINTEVENTS UpdateWidget w; - w.setGeometry(50, 50, 100, 100); + w.resize(100, 100); + centerOnScreen(&w); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); @@ -7647,6 +7654,7 @@ void tst_QWidget::doubleRepaint() QSKIP("QTBUG-30566 - Unstable auto-test"); #endif UpdateWidget widget; + centerOnScreen(&widget); widget.setFocusPolicy(Qt::StrongFocus); // Filter out activation change and focus events to avoid update() calls in QWidget. widget.updateOnActivationChangeAndFocusIn = false; @@ -7774,6 +7782,7 @@ void tst_QWidget::setMaskInResizeEvent() UpdateWidget w; w.reset(); w.resize(200, 200); + centerOnScreen(&w); w.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); w.raise(); @@ -7851,6 +7860,7 @@ void tst_QWidget::immediateRepaintAfterShow() QSKIP("We don't support immediate repaint right after show on other platforms."); UpdateWidget widget; + centerOnScreen(&widget); widget.show(); qApp->processEvents(); // On X11 in particular, we are now waiting for a MapNotify event before @@ -7867,6 +7877,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() QSKIP("We don't support immediate repaint right after show on other platforms."); QScopedPointer widget(new UpdateWidget); + centerOnScreen(widget.data()); widget->show(); QVERIFY(QTest::qWaitForWindowExposed(widget.data())); QTest::qWait(200); @@ -8282,6 +8293,7 @@ void tst_QWidget::setClearAndResizeMask() { UpdateWidget topLevel; topLevel.resize(160, 160); + centerOnScreen(&topLevel); topLevel.show(); qApp->setActiveWindow(&topLevel); QVERIFY(QTest::qWaitForWindowActive(&topLevel)); @@ -8434,6 +8446,7 @@ void tst_QWidget::maskedUpdate() { UpdateWidget topLevel; topLevel.resize(200, 200); + centerOnScreen(&topLevel); const QRegion topLevelMask(50, 50, 70, 70); topLevel.setMask(topLevelMask); @@ -8859,6 +8872,7 @@ void tst_QWidget::focusWidget_task254563() void tst_QWidget::destroyBackingStore() { UpdateWidget w; + centerOnScreen(&w); w.reset(); w.show(); -- cgit v1.2.3 From 78d7192338e2cbba0c9b53c429d35b9437b7e1cd Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 27 Aug 2013 11:58:34 +0200 Subject: Close menu on 2nd click on QMenuBar. Task-number: QTBUG-32807 Change-Id: I0c3c25c6acf92bc30c1bcfc09003209b572ec777 Reviewed-by: Joerg Bornemann --- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index e7450fdd2c..174753d8be 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -145,6 +146,7 @@ private slots: void taskQTBUG4965_escapeEaten(); #endif void taskQTBUG11823_crashwithInvisibleActions(); + void closeOnSecondClick(); protected slots: void onActivated( QAction*); @@ -1318,5 +1320,28 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions() QCOMPARE(menubar.activeAction(), m); //the active action shouldn't have changed } +void tst_QMenuBar::closeOnSecondClick() // QTBUG-32807, menu should close on 2nd click. +{ + QMainWindow mainWindow; + mainWindow.resize(300, 200); + mainWindow.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(150, 100)); +#ifndef QT_NO_CURSOR + QCursor::setPos(mainWindow.geometry().topLeft() - QPoint(100, 0)); +#endif + QMenuBar *menuBar = mainWindow.menuBar(); + menuBar->setNativeMenuBar(false); + QMenu *fileMenu = menuBar->addMenu(QStringLiteral("closeOnSecondClick")); + fileMenu->addAction(QStringLiteral("Quit")); + mainWindow.show(); + QApplication::setActiveWindow(&mainWindow); + QVERIFY(QTest::qWaitForWindowActive(&mainWindow)); + const QPoint center = menuBar->actionGeometry(fileMenu->menuAction()).center(); + QTest::mouseMove(menuBar, center); + QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); + QTRY_VERIFY(fileMenu->isVisible()); + QTest::mouseClick(menuBar, Qt::LeftButton, 0, center); + QTRY_VERIFY(!fileMenu->isVisible()); +} + QTEST_MAIN(tst_QMenuBar) #include "tst_qmenubar.moc" -- cgit v1.2.3 From 627a394fb7ba1507bd028f81522244e7e085ef8d Mon Sep 17 00:00:00 2001 From: Peter Hartmann Date: Tue, 27 Aug 2013 14:58:49 +0200 Subject: network test settings: support newer FTP server versions ... which are used by the new test server image. Change-Id: I72ffa73d3e254b278fb9063d32b633b156bd3ec0 Reviewed-by: Richard J. Moore --- tests/auto/network-settings.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/auto/network-settings.h b/tests/auto/network-settings.h index 2ffb89241c..ad51df9090 100644 --- a/tests/auto/network-settings.h +++ b/tests/auto/network-settings.h @@ -103,20 +103,9 @@ public: static bool compareReplyFtp(QByteArray const& actual) { - QList expected; - - // A few different vsFTPd versions. - // Feel free to add more as needed - expected << QByteArray( "220 (vsFTPd 2.0.5)\r\n221 Goodbye.\r\n" ); - expected << QByteArray( "220 (vsFTPd 2.2.2)\r\n221 Goodbye.\r\n" ); - - Q_FOREACH (QByteArray const& ba, expected) { - if (ba == actual) { - return true; - } - } - - return false; + // output would be e.g. "220 (vsFTPd 2.3.5)\r\n221 Goodbye.\r\n" + QRegExp ftpVersion(QStringLiteral("220 \\(vsFTPd \\d+\\.\\d+.\\d+\\)\\r\\n221 Goodbye.\\r\\n")); + return ftpVersion.exactMatch(actual); } static bool hasIPv6() -- cgit v1.2.3 From e9c771d6cce35746fceeb9a2bed9f522a8d7f34c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 28 Aug 2013 09:08:29 +0200 Subject: Stabilize tst_qmenubar. The test was re-using a main window and menu bars for all tests, clearing and repopulating them. Rewrite the code to be able to use menu bars and windows on the stack separately for each test. Change-Id: I13ab31b26b70bc8537e8d8ab164051b3197cd68e Reviewed-by: Frederik Gladhorn --- .../auto/widgets/widgets/qmenubar/tst_qmenubar.cpp | 816 ++++++++++----------- 1 file changed, 403 insertions(+), 413 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 174753d8be..2b8e735a0e 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -58,23 +58,6 @@ QT_FORWARD_DECLARE_CLASS(QMainWindow) #include -class QtTestSlot : public QObject -{ - Q_OBJECT - -public: - QtTestSlot( QObject* parent = 0 ): QObject( parent ) { clear(); }; - virtual ~QtTestSlot() {}; - - void clear() { sel_count = 0; }; - uint selCount() { return sel_count; }; - -public slots: - void selected() { sel_count++; }; - -private: - uint sel_count; -}; class Menu : public QMenu { @@ -88,20 +71,24 @@ class Menu : public QMenu } }; +static inline void centerOnScreen(QWidget *w) +{ + const QPoint offset = QPoint(w->width() / 2, w->height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + +struct TestMenu +{ + QList menus; + QList actions; +}; + class tst_QMenuBar : public QObject { Q_OBJECT public: tst_QMenuBar(); - virtual ~tst_QMenuBar(); - - void initSimpleMenubar(); - void initComplexMenubar(); -public slots: - void initTestCase(); - void cleanupTestCase(); - void init(); private slots: void getSetCheck(); @@ -149,37 +136,20 @@ private slots: void closeOnSecondClick(); protected slots: - void onActivated( QAction*); + void onSimpleActivated( QAction*); + void onComplexActionTriggered(); private: - QtTestSlot *menu1; - QtTestSlot *menu2; - QtTestSlot *menu3; - QtTestSlot *menu4; - - QtTestSlot *item1_A; - QtTestSlot *item1_B; - QtTestSlot *item2_C; - QtTestSlot *item2_D; - QtTestSlot *item2_E; - QtTestSlot *item2_F; - QtTestSlot *item2_G; - QtTestSlot *item2_H; - - void resetSlots(); - void resetCount(); - - void reset() { resetSlots(); resetCount(); }; - - QAction* last_accel_id; - int activated_count; - - QAction *action; - QAction *action1; - QMainWindow *mw; - QMenuBar *mb; - QMenu *pm1; - QMenu *pm2; + TestMenu initSimpleMenuBar(QMenuBar *mb); + TestMenu initWindowWithSimpleMenuBar(QMainWindow &w); + QAction *createCharacterAction(QMenu *menu, char lowerAscii); + QMenu *addNumberedMenu(QMenuBar *mb, int n); + TestMenu initComplexMenuBar(QMenuBar *mb); + TestMenu initWindowWithComplexMenuBar(QMainWindow &w); + + QAction* m_lastSimpleAcceleratorId; + int m_simpleActivatedCount; + int m_complexTriggerCount['k']; }; // Testing get/set functions @@ -222,116 +192,119 @@ const int RESET = 0; */ -tst_QMenuBar::tst_QMenuBar() - +tst_QMenuBar::tst_QMenuBar() : m_lastSimpleAcceleratorId(0), m_simpleActivatedCount(0) { QApplication::setEffectEnabled(Qt::UI_AnimateMenu, false); - - - activated_count = 0; - mb = 0; - pm1 = 0; - pm2 = 0; - last_accel_id = 0; } -tst_QMenuBar::~tst_QMenuBar() +void tst_QMenuBar::onSimpleActivated( QAction* action ) { - //delete mw; //#### cannot do that AFTER qapplication was destroyed! - mw = 0; + m_lastSimpleAcceleratorId = action; + m_simpleActivatedCount++; } -void tst_QMenuBar::initTestCase() +// Create a simple menu bar and connect its actions to onSimpleActivated(). + +TestMenu tst_QMenuBar::initSimpleMenuBar(QMenuBar *mb) { - // create a default mainwindow - // If you run a widget test, this will be replaced in the testcase by the - // widget under test - mw = new QMainWindow(0, Qt::X11BypassWindowManagerHint); - mb = new QMenuBar( mw ); - connect( mb, SIGNAL(triggered(QAction*)), this, SLOT(onActivated(QAction*)) ); - - initSimpleMenubar(); - mw->show(); - mw->activateWindow(); - QVERIFY(QTest::qWaitForWindowActive(mw)); - - menu1 = new QtTestSlot( mw ); - menu2 = new QtTestSlot( mw ); - menu3 = new QtTestSlot( mw ); - menu4 = new QtTestSlot( mw ); - item1_A = new QtTestSlot( mw ); - item1_B = new QtTestSlot( mw ); - item2_C = new QtTestSlot( mw ); - item2_D = new QtTestSlot( mw ); - item2_E = new QtTestSlot( mw ); - item2_F = new QtTestSlot( mw ); - item2_G = new QtTestSlot( mw ); - item2_H = new QtTestSlot( mw ); + TestMenu result; + connect(mb, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); + QMenu *menu = mb->addMenu(QStringLiteral("&accel")); + QAction *action = menu->addAction(QStringLiteral("menu1") ); + action->setShortcut(QKeySequence(Qt::ALT + Qt::Key_A)); + action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_A)); + connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); + result.menus << menu; + result.actions << action; + + menu = mb->addMenu(QStringLiteral("accel1")); + action = menu->addAction(QStringLiteral("&Open...") ); + action->setShortcut(Qt::Key_O); + result.menus << menu; + connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onSimpleActivated(QAction*))); + result.actions << action; + + m_lastSimpleAcceleratorId = 0; + m_simpleActivatedCount = 0; + + return result; } - -void tst_QMenuBar::cleanupTestCase() +inline TestMenu tst_QMenuBar::initWindowWithSimpleMenuBar(QMainWindow &w) { - delete mw; + w.resize(200, 200); + centerOnScreen(&w); + return initSimpleMenuBar(w.menuBar()); } -void tst_QMenuBar::initSimpleMenubar() +// add a menu with number n, set number as data. +QMenu *tst_QMenuBar::addNumberedMenu(QMenuBar *mb, int n) { - mb->hide(); - mb->clear(); - - delete pm1; - pm1 = mb->addMenu("&accel"); - action = pm1->addAction( "menu1" ); - action->setShortcut(QKeySequence("ALT+A")); - action->setShortcut(QKeySequence("CTRL+A")); - - connect( pm1, SIGNAL(triggered(QAction*)), this, SLOT(onActivated(QAction*))); - - delete pm2; - pm2 = mb->addMenu("accel1"); - - action1 = pm2->addAction( "&Open..." ); - action1->setShortcut(Qt::Key_O); - connect(pm2, SIGNAL(triggered(QAction*)), this, SLOT(onActivated(QAction*))); - - mb->show(); - qApp->processEvents(); + const QString text = QStringLiteral("Menu &") + QString::number(n); + QMenu *menu = mb->addMenu(text); + menu->setObjectName(text); + QAction *action = menu->menuAction(); + action->setObjectName(text + QStringLiteral("Action")); + action->setData(QVariant(n)); + connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); + return menu; } -void tst_QMenuBar::init() +// Create an action triggering on Ctrl+character, set number as data. +QAction *tst_QMenuBar::createCharacterAction(QMenu *menu, char lowerAscii) { - resetSlots(); - resetCount(); + const QString text = QStringLiteral("Item ") + QChar(QLatin1Char(lowerAscii)).toUpper(); + QAction *action = menu->addAction(text); + action->setObjectName(text); + action->setData(QVariant(int(lowerAscii))); + action->setShortcut(Qt::CTRL + (lowerAscii - 'a' + Qt::Key_A)); + connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); + return action; } -void tst_QMenuBar::resetSlots() +void tst_QMenuBar::onComplexActionTriggered() { - menu1->clear(); - menu2->clear(); - menu3->clear(); - menu4->clear(); - item1_A->clear(); - item1_B->clear(); - item2_C->clear(); - item2_D->clear(); - item2_E->clear(); - item2_F->clear(); - item2_G->clear(); - item2_H->clear(); + if (QAction *a = qobject_cast(sender())) + m_complexTriggerCount[a->data().toInt()]++; } -void tst_QMenuBar::resetCount() +// Create a complex menu bar and connect its actions to onComplexActionTriggered() +// for their invocations to be counted in m_complexTriggerCount. The index is the +// menu number (1..n) for the menu bar actions and the ASCII-code of the shortcut +// character for the actions in the menus. +TestMenu tst_QMenuBar::initComplexMenuBar(QMenuBar *mb) { - last_accel_id = 0; - activated_count = 0; + TestMenu result; + QMenu *menu = addNumberedMenu(mb, 1); + result.menus << menu; + for (char c = 'a'; c < 'c'; ++c) + result.actions << createCharacterAction(menu, c); + + menu = addNumberedMenu(mb, 2); + menu->menuAction()->setData(QVariant(2)); + result.menus << menu; + for (char c = 'c'; c < 'g'; ++c) + result.actions << createCharacterAction(menu, c); + menu->addSeparator(); + for (char c = 'g'; c < 'i'; ++c) + result.actions << createCharacterAction(menu, c); + + QAction *action = mb->addAction(QStringLiteral("M&enu 3")); + action->setData(QVariant(3)); + action->setShortcut(Qt::ALT + Qt::Key_J); + connect(action, SIGNAL(triggered()), this, SLOT(onComplexActionTriggered())); + result.actions << action; + + qFill(m_complexTriggerCount, m_complexTriggerCount + sizeof(m_complexTriggerCount) / sizeof(int), 0); + + return result; } -void tst_QMenuBar::onActivated( QAction* action ) +inline TestMenu tst_QMenuBar::initWindowWithComplexMenuBar(QMainWindow &w) { - last_accel_id = action; - activated_count++; -// printf( QString("acceleratorId: %1, count: %1\n").arg( i ).arg(activated_count) ); + w.resize(400, 200); + centerOnScreen(&w); + return initComplexMenuBar(w.menuBar()); } // On Mac/WinCE, native key events are needed to test menu action activation @@ -339,15 +312,16 @@ void tst_QMenuBar::onActivated( QAction* action ) void tst_QMenuBar::accel() { // create a popup menu with menu items set the accelerators later... - initSimpleMenubar(); - + QMainWindow w; + const TestMenu menu = initWindowWithSimpleMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // shortcuts won't work unless the window is active - QTRY_VERIFY( QApplication::activeWindow() ); -// QTest::keyClick(static_cast(0), Qt::Key_A, AltKey ); QTest::keyClick(static_cast(0), Qt::Key_A, Qt::ControlModifier ); QTest::qWait(300); - QCOMPARE( last_accel_id, action ); + QCOMPARE( m_lastSimpleAcceleratorId, menu.actions.front() ); } #endif @@ -356,40 +330,45 @@ void tst_QMenuBar::accel() void tst_QMenuBar::activatedCount() { // create a popup menu with menu items set the accelerators later... - initSimpleMenubar(); + QMainWindow w; + initWindowWithSimpleMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); QTest::keyClick(static_cast(0), Qt::Key_A, Qt::ControlModifier ); //wait(5000); - QCOMPARE( activated_count, 2 ); //1 from the popupmenu and 1 from the menubar + QCOMPARE( m_simpleActivatedCount, 2 ); //1 from the popupmenu and 1 from the menubar } #endif void tst_QMenuBar::clear() { - mb->clear(); - QVERIFY( (uint) mb->actions().size() == 0 ); - - mb->clear(); - for (uint i=0; i<10; i++) { - QMenu *menu = mb->addMenu( QString("Menu %1")); - for (uint k=0; kaddAction( QString("Item %1")); - QCOMPARE( (uint) mb->actions().size(), (uint)i+1 ); + QMenuBar menuBar; + initSimpleMenuBar(&menuBar); + menuBar.clear(); + QCOMPARE( menuBar.actions().size(), 0 ); + + menuBar.clear(); + for (int i = 0; i < 10; i++) { + QMenu *menu = menuBar.addMenu( QStringLiteral("Menu ") + QString::number(i)); + for (int k = 0; k < i; k++) + menu->addAction( QStringLiteral("Item ") + QString::number(k)); + QCOMPARE( menuBar.actions().size(), i + 1 ); } - QCOMPARE( (uint) mb->actions().size(), 10u ); - - mb->clear(); - QVERIFY( (uint) mb->actions().size() == 0 ); + QCOMPARE( menuBar.actions().size(), 10 ); + menuBar.clear(); + QCOMPARE( menuBar.actions().size(), 0 ); } void tst_QMenuBar::count() { - mb->clear(); - QVERIFY( mb->actions().size() == 0 ); + QMenuBar menuBar; + QCOMPARE( menuBar.actions().size(), 0 ); - for (uint i=0; i<10; i++) { - mb->addAction( QString("Menu %1")); - QCOMPARE( (uint) mb->actions().size(), (uint) i+1 ); + for (int i = 0; i < 10; i++) { + menuBar.addAction( QStringLiteral("Menu ") + QString::number(i)); + QCOMPARE( menuBar.actions().size(), i + 1 ); } } @@ -404,27 +383,26 @@ void tst_QMenuBar::removeItem_data() // Basically the same test as removeItemAt, except that we remember and remove id's. void tst_QMenuBar::removeItem() { - mb->clear(); + QMenuBar menuBar; - QMenu *pm; - pm = new QMenu( "stuff", mb ); + QMenu *pm = new QMenu( "stuff", &menuBar ); pm->setTitle("Menu 1"); pm->addAction( QString("Item 10") ); - QAction* action1 = mb->addMenu( pm ); + QAction* action1 = menuBar.addMenu( pm ); - pm = new QMenu( mb ); + pm = new QMenu( &menuBar ); pm->setTitle("Menu 2"); pm->addAction( QString("Item 20") ); pm->addAction( QString("Item 21") ); - QAction *action2 = mb->addMenu( pm ); + QAction *action2 = menuBar.addMenu( pm ); - pm = new QMenu( "Menu 3", mb ); + pm = new QMenu( "Menu 3", &menuBar ); pm->addAction( QString("Item 30") ); pm->addAction( QString("Item 31") ); pm->addAction( QString("Item 32") ); - QAction *action3 = mb->addMenu( pm ); + QAction *action3 = menuBar.addMenu( pm ); - QList menuBarActions = mb->actions(); + const QList menuBarActions = menuBar.actions(); QCOMPARE( action1->text(), QString("Menu 1") ); QCOMPARE( action2->text(), QString("Menu 2") ); @@ -439,28 +417,28 @@ void tst_QMenuBar::removeItem() switch (removeIndex ) { case 0: { - mb->removeAction(action1); - QList menuBarActions2 = mb->actions(); + menuBar.removeAction(action1); + const QList menuBarActions2 = menuBar.actions(); QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 2") ); QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 3") ); } break; case 1: { - mb->removeAction(action2); - QList menuBarActions2 = mb->actions(); + menuBar.removeAction(action2); + const QList menuBarActions2 = menuBar.actions(); QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 1") ); QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 3") ); } break; case 2: { - mb->removeAction(action3); - QList menuBarActions2 = mb->actions(); + menuBar.removeAction(action3); + const QList menuBarActions2 = menuBar.actions(); QCOMPARE( menuBarActions2.at(0)->text(), QString("Menu 1") ); QCOMPARE( menuBarActions2.at(1)->text(), QString("Menu 2") ); } break; } - QList menuBarActions2 = mb->actions(); + QList menuBarActions2 = menuBar.actions(); QVERIFY( menuBarActions2.size() == 2 ); } @@ -474,25 +452,23 @@ void tst_QMenuBar::removeItemAt_data() void tst_QMenuBar::removeItemAt() { - mb->clear(); - - QMenu *pm; - pm = new QMenu("Menu 1", mb); + QMenuBar menuBar; + QMenu *pm = new QMenu("Menu 1", &menuBar); pm->addAction( QString("Item 10") ); - mb->addMenu( pm ); + menuBar.addMenu( pm ); - pm = new QMenu( "Menu 2", mb ); + pm = new QMenu( "Menu 2", &menuBar); pm->addAction( QString("Item 20") ); pm->addAction( QString("Item 21") ); - mb->addMenu( pm ); + menuBar.addMenu( pm ); - pm = new QMenu( "Menu 3", mb ); + pm = new QMenu( "Menu 3", &menuBar); pm->addAction( QString("Item 30") ); pm->addAction( QString("Item 31") ); pm->addAction( QString("Item 32") ); - mb->addMenu( pm ); + menuBar.addMenu( pm ); - QList menuBarActions = mb->actions(); + QList menuBarActions = menuBar.actions(); QCOMPARE( menuBarActions.at(0)->text(), QString("Menu 1") ); QCOMPARE( menuBarActions.at(1)->text(), QString("Menu 2") ); @@ -500,8 +476,8 @@ void tst_QMenuBar::removeItemAt() // Ok, now that we know we have created the menu we expect, lets remove an item... QFETCH( int, removeIndex ); - mb->removeAction(menuBarActions.at(removeIndex)); - QList menuBarActions2 = mb->actions(); + menuBar.removeAction(menuBarActions.at(removeIndex)); + const QList menuBarActions2 = menuBar.actions(); switch (removeIndex ) { case 0: @@ -521,32 +497,6 @@ void tst_QMenuBar::removeItemAt() QVERIFY( menuBarActions2.size() == 2 ); } -void tst_QMenuBar::initComplexMenubar() // well, complex.... -{ - mb->hide(); - mb->clear(); - - delete pm1; - pm1 = mb->addMenu("Menu &1"); - pm1->addAction( QString("Item A"), item1_A, SLOT(selected()), Qt::CTRL+Qt::Key_A ); - pm1->addAction( QString("Item B"), item1_B, SLOT(selected()), Qt::CTRL+Qt::Key_B ); - - delete pm2; - pm2 = mb->addMenu("Menu &2"); - pm2->addAction( QString("Item C"), item2_C, SLOT(selected()), Qt::CTRL+Qt::Key_C ); - pm2->addAction( QString("Item D"), item2_D, SLOT(selected()), Qt::CTRL+Qt::Key_D ); - pm2->addAction( QString("Item E"), item2_E, SLOT(selected()), Qt::CTRL+Qt::Key_E ); - pm2->addAction( QString("Item F"), item2_F, SLOT(selected()), Qt::CTRL+Qt::Key_F ); - pm2->addSeparator(); - pm2->addAction( QString("Item G"), item2_G, SLOT(selected()), Qt::CTRL+Qt::Key_G ); - pm2->addAction( QString("Item H"), item2_H, SLOT(selected()), Qt::CTRL+Qt::Key_H ); - - QAction *ac = mb->addAction( QString("M&enu 3"), menu3, SLOT(selected())); - ac->setShortcut(Qt::ALT+Qt::Key_J); - mb->show(); -} - - /* Check the insert functions that create menu items. For the moment i only check the strings and pixmaps. The rest are special cases which are @@ -555,9 +505,10 @@ void tst_QMenuBar::initComplexMenubar() // well, complex.... void tst_QMenuBar::insertItem_QString_QObject() { - initComplexMenubar(); + QMenuBar menuBar; + initComplexMenuBar(&menuBar); - QList actions = mb->actions(); + const QList actions = menuBar.actions(); QCOMPARE(actions.at(0)->text(), QString("Menu &1") ); QCOMPARE(actions.at(1)->text(), QString("Menu &2") ); @@ -569,68 +520,72 @@ void tst_QMenuBar::insertItem_QString_QObject() #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_accelKeys() { - initComplexMenubar(); + QMainWindow w; + initWindowWithComplexMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // start with a bogus key that shouldn't trigger anything QTest::keyClick(static_cast(0), Qt::Key_I, Qt::ControlModifier); - QCOMPARE(menu1->selCount(), 0u); - QCOMPARE(menu2->selCount(), 0u); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); - QCOMPARE(item1_B->selCount(), 0u); - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[1], 0); + QCOMPARE(m_complexTriggerCount[2], 0); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); + QCOMPARE(m_complexTriggerCount['b'], 0); + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); QTest::keyClick(static_cast(0), Qt::Key_A, Qt::ControlModifier); - QCOMPARE(menu1->selCount(), 0u); - QCOMPARE(menu2->selCount(), 0u); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 1u); - QCOMPARE(item1_B->selCount(), 0u); - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[1], 0); + QCOMPARE(m_complexTriggerCount[2], 0); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 1); + QCOMPARE(m_complexTriggerCount['b'], 0); + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); QTest::keyClick(static_cast(0), Qt::Key_C, Qt::ControlModifier); - QCOMPARE(menu1->selCount(), 0u); - QCOMPARE(menu2->selCount(), 0u); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 1u); - QCOMPARE(item1_B->selCount(), 0u); - QCOMPARE(item2_C->selCount(), 1u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[1], 0); + QCOMPARE(m_complexTriggerCount[2], 0); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 1); + QCOMPARE(m_complexTriggerCount['b'], 0); + QCOMPARE(m_complexTriggerCount['c'], 1); + QCOMPARE(m_complexTriggerCount['d'], 0); QTest::keyClick(static_cast(0), Qt::Key_B, Qt::ControlModifier); - QCOMPARE(menu1->selCount(), 0u); - QCOMPARE(menu2->selCount(), 0u); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 1u); - QCOMPARE(item1_B->selCount(), 1u); - QCOMPARE(item2_C->selCount(), 1u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[1], 0); + QCOMPARE(m_complexTriggerCount[2], 0); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 1); + QCOMPARE(m_complexTriggerCount['b'], 1); + QCOMPARE(m_complexTriggerCount['c'], 1); + QCOMPARE(m_complexTriggerCount['d'], 0); QTest::keyClick(static_cast(0), Qt::Key_D, Qt::ControlModifier); - QCOMPARE(menu1->selCount(), 0u); - QCOMPARE(menu2->selCount(), 0u); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 1u); - QCOMPARE(item1_B->selCount(), 1u); - QCOMPARE(item2_C->selCount(), 1u); - QCOMPARE(item2_D->selCount(), 1u); + QCOMPARE(m_complexTriggerCount[1], 0); + QCOMPARE(m_complexTriggerCount[2], 0); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 1); + QCOMPARE(m_complexTriggerCount['b'], 1); + QCOMPARE(m_complexTriggerCount['c'], 1); + QCOMPARE(m_complexTriggerCount['d'], 1); QTest::keyClick(static_cast(0), Qt::Key_J, Qt::AltModifier); - QCOMPARE(menu1->selCount(), 0u); - QCOMPARE(menu2->selCount(), 0u); - QCOMPARE(menu3->selCount(), 1u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 1u); - QCOMPARE(item1_B->selCount(), 1u); - QCOMPARE(item2_C->selCount(), 1u); - QCOMPARE(item2_D->selCount(), 1u); + QCOMPARE(m_complexTriggerCount[1], 0); + QCOMPARE(m_complexTriggerCount[2], 0); + QCOMPARE(m_complexTriggerCount[3], 1); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 1); + QCOMPARE(m_complexTriggerCount['b'], 1); + QCOMPARE(m_complexTriggerCount['c'], 1); + QCOMPARE(m_complexTriggerCount['d'], 1); } #endif @@ -638,29 +593,33 @@ void tst_QMenuBar::check_accelKeys() #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_cursorKeys1() { - initComplexMenubar(); + QMainWindow w; + initWindowWithComplexMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // start with a ALT + 1 that activates the first popupmenu QTest::keyClick(static_cast(0), Qt::Key_1, Qt::AltModifier ); // the Popupmenu should be visible now - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); - QCOMPARE(item1_B->selCount(), 0u); - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); + QCOMPARE(m_complexTriggerCount['b'], 0); + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); // Simulate a cursor key down click QTest::keyClick(static_cast(0), Qt::Key_Down ); // and an Enter key QTest::keyClick(static_cast(0), Qt::Key_Enter ); // Let's see if the correct slot is called... - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); // this shouldn't have been called - QCOMPARE(item1_B->selCount(), 1u); // and this should have been called by a signal now - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); // this shouldn't have been called + QCOMPARE(m_complexTriggerCount['b'], 1); // and this should have been called by a signal now + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); } #endif @@ -668,7 +627,11 @@ void tst_QMenuBar::check_cursorKeys1() #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_cursorKeys2() { - initComplexMenubar(); + QMainWindow w; + initWindowWithComplexMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // select popupmenu2 QTest::keyClick(static_cast(0), Qt::Key_2, Qt::AltModifier ); @@ -681,12 +644,12 @@ void tst_QMenuBar::check_cursorKeys2() // and an Enter key QTest::keyClick(static_cast(0), Qt::Key_Enter ); // Let's see if the correct slot is called... - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); // this shouldn't have been caled - QCOMPARE(item1_B->selCount(), 0u); // and this should have been called by a signal ow - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 1u); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); // this shouldn't have been caled + QCOMPARE(m_complexTriggerCount['b'], 0); // and this should have been called by a signal ow + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 1); } #endif @@ -697,7 +660,11 @@ void tst_QMenuBar::check_cursorKeys2() #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_cursorKeys3() { - initComplexMenubar(); + QMainWindow w; + initWindowWithComplexMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // select Popupmenu 2 QTest::keyClick(static_cast(0), Qt::Key_2, Qt::AltModifier ); @@ -708,12 +675,12 @@ void tst_QMenuBar::check_cursorKeys3() // and press ENTER QTest::keyClick(static_cast(0), Qt::Key_Enter ); // Let's see if the correct slot is called... - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); // this shouldn't have been called - QCOMPARE(item1_B->selCount(), 1u); // and this should have been called by a signal now - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); // this shouldn't have been called + QCOMPARE(m_complexTriggerCount['b'], 1); // and this should have been called by a signal now + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); } #endif @@ -729,7 +696,11 @@ void tst_QMenuBar::check_homeKey() QEXPECT_FAIL( "0", "Popupmenu should respond to a Home key", Abort ); - initComplexMenubar(); + QMainWindow w; + initWindowWithComplexMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // select Popupmenu 2 QTest::keyClick(static_cast(0), Qt::Key_2, Qt::AltModifier ); @@ -742,17 +713,17 @@ void tst_QMenuBar::check_homeKey() // and press ENTER QTest::keyClick(static_cast(0), Qt::Key_Enter ); // Let's see if the correct slot is called... -// QVERIFY2( item2_C->selCount() == 1, "Popupmenu should respond to a Home key" ); - QCOMPARE(item2_C->selCount(), 1u); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); - QCOMPARE(item1_B->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); - QCOMPARE(item2_E->selCount(), 0u); - QCOMPARE(item2_F->selCount(), 0u); - QCOMPARE(item2_G->selCount(), 0u); - QCOMPARE(item2_H->selCount(), 0u); +// QVERIFY2( m_complexActionTriggerCount['c'] == 1, "Popupmenu should respond to a Home key" ); + QCOMPARE(m_complexTriggerCount['c'], 1); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); + QCOMPARE(m_complexTriggerCount['b'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); + QCOMPARE(m_complexTriggerCount['e'], 0); + QCOMPARE(m_complexTriggerCount['f'], 0); + QCOMPARE(m_complexTriggerCount['g'], 0); + QCOMPARE(m_complexTriggerCount['h'], 0); } /*! @@ -767,7 +738,11 @@ void tst_QMenuBar::check_endKey() QEXPECT_FAIL( "0", "Popupmenu should respond to an End key", Abort ); - initComplexMenubar(); + QMainWindow w; + initWindowWithComplexMenuBar(w); + w.show(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); // select Popupmenu 2 QTest::keyClick(static_cast(0), Qt::Key_2, Qt::AltModifier ); @@ -777,17 +752,17 @@ void tst_QMenuBar::check_endKey() // and press ENTER QTest::keyClick(static_cast(0), Qt::Key_Enter ); // Let's see if the correct slot is called... -// QVERIFY2( item2_H->selCount() == 1, "Popupmenu should respond to an End key" ); - QCOMPARE(item2_H->selCount(), 1u);//, "Popupmenu should respond to an End key"); - QCOMPARE(menu3->selCount(), 0u); - QCOMPARE(menu4->selCount(), 0u); - QCOMPARE(item1_A->selCount(), 0u); - QCOMPARE(item1_B->selCount(), 0u); - QCOMPARE(item2_C->selCount(), 0u); - QCOMPARE(item2_D->selCount(), 0u); - QCOMPARE(item2_E->selCount(), 0u); - QCOMPARE(item2_F->selCount(), 0u); - QCOMPARE(item2_G->selCount(), 0u); +// QVERIFY2( m_complexActionTriggerCount['h'] == 1, "Popupmenu should respond to an End key" ); + QCOMPARE(m_complexTriggerCount['h'], 1);//, "Popupmenu should respond to an End key"); + QCOMPARE(m_complexTriggerCount[3], 0); + QCOMPARE(m_complexTriggerCount[4], 0); + QCOMPARE(m_complexTriggerCount['a'], 0); + QCOMPARE(m_complexTriggerCount['b'], 0); + QCOMPARE(m_complexTriggerCount['c'], 0); + QCOMPARE(m_complexTriggerCount['d'], 0); + QCOMPARE(m_complexTriggerCount['e'], 0); + QCOMPARE(m_complexTriggerCount['f'], 0); + QCOMPARE(m_complexTriggerCount['g'], 0); } /*! @@ -800,33 +775,38 @@ void tst_QMenuBar::check_endKey() #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_escKey() { - initComplexMenubar(); + QMainWindow w; + const TestMenu menu = initWindowWithComplexMenuBar(w); + w.show(); + w.setFocus(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); - QVERIFY( !pm1->isActiveWindow() ); - QVERIFY( !pm2->isActiveWindow() ); + QVERIFY( !menu.menus.at(0)->isActiveWindow() ); + QVERIFY( !menu.menus.at(1)->isActiveWindow() ); // select Popupmenu 2 QTest::keyClick(static_cast(0), Qt::Key_2, Qt::AltModifier ); - QVERIFY( !pm1->isActiveWindow() ); - QVERIFY( pm2->isActiveWindow() ); + QVERIFY( !menu.menus.at(0)->isActiveWindow() ); + QVERIFY( menu.menus.at(1)->isActiveWindow() ); // If we press ESC, the popup should disappear QTest::keyClick(static_cast(0), Qt::Key_Escape ); - QVERIFY( !pm1->isActiveWindow() ); - QVERIFY( !pm2->isActiveWindow() ); + QVERIFY( !menu.menus.at(0)->isActiveWindow() ); + QVERIFY( !menu.menus.at(1)->isActiveWindow() ); if (!QApplication::style()->inherits("QWindowsStyle")) return; // If we press Down the popupmenu should be active again QTest::keyClick(static_cast(0), Qt::Key_Down ); - QVERIFY( !pm1->isActiveWindow() ); - QVERIFY( pm2->isActiveWindow() ); + QVERIFY( !menu.menus.at(0)->isActiveWindow() ); + QVERIFY( menu.menus.at(1)->isActiveWindow() ); // and press ENTER - QTest::keyClick( pm2, Qt::Key_Enter ); + QTest::keyClick( menu.menus.at(1), Qt::Key_Enter ); // Let's see if the correct slot is called... - QVERIFY2( item2_C->selCount() == 1, "Expected item 2C to be selected" ); + QVERIFY2( m_complexTriggerCount['c'] == 1, "Expected item 2C to be selected" ); } #endif @@ -852,7 +832,7 @@ void tst_QMenuBar::check_escKey() // QFETCH( int, itemA_count ); // QFETCH( int, itemB_count ); -// initComplexMenubar(); +// // initComplexMenubar(); // QVERIFY( !pm1->isActiveWindow() ); // QVERIFY( !pm2->isActiveWindow() ); @@ -866,15 +846,15 @@ void tst_QMenuBar::check_escKey() // QTest::qWait(1000); // mouse.mouseEvent( QtTestMouse::MouseClick, pm1, popup_item, Qt::LeftButton ); -// QCOMPARE(menu3->selCount(), 0u); -// QCOMPARE(menu4->selCount(), 0u); -// QCOMPARE(item1_A->selCount(), (uint)itemA_count); // this option should have fired -// QCOMPARE(item1_B->selCount(), (uint)itemB_count); -// QCOMPARE(item2_C->selCount(), 0u); -// QCOMPARE(item2_D->selCount(), 0u); -// QCOMPARE(item2_E->selCount(), 0u); -// QCOMPARE(item2_F->selCount(), 0u); -// QCOMPARE(item2_G->selCount(), 0u); +// QCOMPARE(m_complexActionTriggerCount[3], 0); +// QCOMPARE(m_complexActionTriggerCount[4], 0); +// QCOMPARE(m_complexActionTriggerCount['a'], (uint)itemA_count); // this option should have fired +// QCOMPARE(m_complexActionTriggerCount['b'], (uint)itemB_count); +// QCOMPARE(m_complexActionTriggerCount['c'], 0); +// QCOMPARE(m_complexActionTriggerCount['d'], 0); +// QCOMPARE(m_complexActionTriggerCount['e'], 0); +// QCOMPARE(m_complexActionTriggerCount['f'], 0); +// QCOMPARE(m_complexActionTriggerCount['g'], 0); // } // void tst_QMenuBar::check_mouse2_data() @@ -920,28 +900,27 @@ void tst_QMenuBar::check_escKey() // QFETCH( int, itemH_count ); // QFETCH( int, menu3_count ); -// initComplexMenubar(); +// // initComplexMenubar(); // QtTestMouse mouse; // mouse.click( QtTestMouse::Menu, label, Qt::LeftButton ); // // check if the correct signals have fired -// QCOMPARE(menu3->selCount(), (uint)menu3_count); -// QCOMPARE(menu4->selCount(), 0u); -// QCOMPARE(item1_A->selCount(), (uint)itemA_count); -// QCOMPARE(item1_B->selCount(), (uint)itemB_count); -// QCOMPARE(item2_C->selCount(), (uint)itemC_count); -// QCOMPARE(item2_D->selCount(), (uint)itemD_count); -// QCOMPARE(item2_E->selCount(), (uint)itemE_count); -// QCOMPARE(item2_F->selCount(), (uint)itemF_count); -// QCOMPARE(item2_G->selCount(), (uint)itemG_count); -// QCOMPARE(item2_H->selCount(), (uint)itemH_count); +// QCOMPARE(m_complexActionTriggerCount[3], (uint)menu3_count); +// QCOMPARE(m_complexActionTriggerCount[4], 0); +// QCOMPARE(m_complexActionTriggerCount['a'], (uint)itemA_count); +// QCOMPARE(m_complexActionTriggerCount['b'], (uint)itemB_count); +// QCOMPARE(m_complexActionTriggerCount['c'], (uint)itemC_count); +// QCOMPARE(m_complexActionTriggerCount['d'], (uint)itemD_count); +// QCOMPARE(m_complexActionTriggerCount['e'], (uint)itemE_count); +// QCOMPARE(m_complexActionTriggerCount['f'], (uint)itemF_count); +// QCOMPARE(m_complexActionTriggerCount['g'], (uint)itemG_count); +// QCOMPARE(m_complexActionTriggerCount['h'], (uint)itemH_count); // } #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::allowActiveAndDisabled() { - mb->hide(); - mb->clear(); + QMenuBar menuBar; // Task 241043 : check that second menu is activated if only // disabled menu items are added @@ -952,31 +931,30 @@ void tst_QMenuBar::allowActiveAndDisabled() QAction *act = fileMenu.addAction("Disabled"); act->setEnabled(false); - mb->addMenu(&fileMenu); + menuBar.addMenu(&fileMenu); QMenu disabledMenu("Disabled"); disabledMenu.setEnabled(false); QMenu activeMenu("Active"); - mb->addMenu(&disabledMenu); - mb->addMenu(&activeMenu); - mb->show(); - + menuBar.addMenu(&disabledMenu); + menuBar.addMenu(&activeMenu); + centerOnScreen(&menuBar); + menuBar.show(); + QVERIFY(QTest::qWaitForWindowExposed(&menuBar)); // Here we verify that AllowActiveAndDisabled correctly skips // the disabled menu entry - QTest::keyClick(mb, Qt::Key_F, Qt::AltModifier ); + QTest::keyClick(&menuBar, Qt::Key_F, Qt::AltModifier ); QTest::keyClick(&fileMenu, (Qt::Key_Right)); if (qApp->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) - QCOMPARE(mb->activeAction()->text(), disabledMenu.title()); + QCOMPARE(menuBar.activeAction()->text(), disabledMenu.title()); else - QCOMPARE(mb->activeAction()->text(), activeMenu.title()); + QCOMPARE(menuBar.activeAction()->text(), activeMenu.title()); - QTest::keyClick(mb, (Qt::Key_Left)); + QTest::keyClick(&menuBar, (Qt::Key_Left)); if (qApp->style()->styleHint(QStyle::SH_Menu_AllowActiveAndDisabled)) - QCOMPARE(mb->activeAction()->text(), fileMenu.title()); + QCOMPARE(menuBar.activeAction()->text(), fileMenu.title()); else - QCOMPARE(mb->activeAction()->text(), fileMenu.title()); - - mb->hide(); + QCOMPARE(menuBar.activeAction()->text(), fileMenu.title()); } #endif @@ -987,33 +965,38 @@ void tst_QMenuBar::check_altPress() arg( qApp->style()->objectName() ).toLatin1()); } - initSimpleMenubar(); - - qApp->setActiveWindow(mw); - mw->setFocus(); + QMainWindow w; + initWindowWithSimpleMenuBar(w); + w.show(); + w.setFocus(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); - QTest::keyClick( mw, Qt::Key_Alt ); - - QVERIFY( ::qobject_cast(qApp->focusWidget()) ); + QTest::keyClick( &w, Qt::Key_Alt ); + QTRY_VERIFY( ::qobject_cast(qApp->focusWidget()) ); } // Qt/Mac,WinCE does not use the native popups/menubar #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_shortcutPress() { - initComplexMenubar(); - - qApp->setActiveWindow(mw); - QCOMPARE(menu3->selCount(), 0u); - QTest::keyClick(mw, Qt::Key_E, Qt::AltModifier); + QMainWindow w; + const TestMenu menu = initWindowWithComplexMenuBar(w); + w.show(); + w.setFocus(); + QApplication::setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); + + QCOMPARE(m_complexTriggerCount[3], 0); + QTest::keyClick(&w, Qt::Key_E, Qt::AltModifier); QTest::qWait(200); - QCOMPARE(menu3->selCount(), 1u); - QVERIFY(!mb->activeAction()); + QCOMPARE(m_complexTriggerCount[3], 1); + QVERIFY(!w.menuBar()->activeAction()); - QTest::keyClick(mw, Qt::Key_1, Qt::AltModifier ); - QVERIFY(pm1->isActiveWindow()); - QTest::keyClick(mb, Qt::Key_2); - QVERIFY(pm1->isActiveWindow()); + QTest::keyClick(&w, Qt::Key_1, Qt::AltModifier ); + QVERIFY(menu.menus.at(0)->isActiveWindow()); + QTest::keyClick(&w, Qt::Key_2); + QVERIFY(menu.menus.at(0)->isActiveWindow()); } #endif @@ -1040,27 +1023,29 @@ private: #if !defined(Q_OS_MAC) && !defined(Q_OS_WINCE) void tst_QMenuBar::check_menuPosition() { + QMainWindow w; + Menu menu; - initComplexMenubar(); menu.setTitle("&menu"); - QRect availRect = QApplication::desktop()->availableGeometry(mw); - QRect screenRect = QApplication::desktop()->screenGeometry(mw); + QRect availRect = QApplication::desktop()->availableGeometry(&w); + QRect screenRect = QApplication::desktop()->screenGeometry(&w); while(menu.sizeHint().height() < (screenRect.height()*2/3)) { menu.addAction("item"); } - QAction *menu_action = mw->menuBar()->addMenu(&menu); - - qApp->setActiveWindow(mw); - qApp->processEvents(); + QAction *menu_action = w.menuBar()->addMenu(&menu); + centerOnScreen(&w); + w.show(); + qApp->setActiveWindow(&w); + QVERIFY(QTest::qWaitForWindowActive(&w)); //the menu should be below the menubar item { - mw->move(availRect.topLeft()); - QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); - mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); - QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); + w.move(availRect.topLeft()); + QRect mbItemRect = w.menuBar()->actionGeometry(menu_action); + mbItemRect.moveTo(w.menuBar()->mapToGlobal(mbItemRect.topLeft())); + QTest::keyClick(&w, Qt::Key_M, Qt::AltModifier ); QVERIFY(menu.isActiveWindow()); QCOMPARE(menu.pos(), QPoint(mbItemRect.x(), mbItemRect.bottom() + 1)); menu.close(); @@ -1068,10 +1053,10 @@ void tst_QMenuBar::check_menuPosition() //the menu should be above the menubar item { - mw->move(0,screenRect.bottom() - screenRect.height()/4); //just leave some place for the menubar - QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); - mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); - QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); + w.move(0,screenRect.bottom() - screenRect.height()/4); //just leave some place for the menubar + QRect mbItemRect = w.menuBar()->actionGeometry(menu_action); + mbItemRect.moveTo(w.menuBar()->mapToGlobal(mbItemRect.topLeft())); + QTest::keyClick(&w, Qt::Key_M, Qt::AltModifier ); QVERIFY(menu.isActiveWindow()); QCOMPARE(menu.pos(), QPoint(mbItemRect.x(), mbItemRect.top() - menu.height())); menu.close(); @@ -1079,10 +1064,10 @@ void tst_QMenuBar::check_menuPosition() //the menu should be on the side of the menubar item and should be "stuck" to the bottom of the screen { - mw->move(0,screenRect.y() + screenRect.height()/2); //put it in the middle - QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); - mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); - QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); + w.move(0,screenRect.y() + screenRect.height()/2); //put it in the middle + QRect mbItemRect = w.menuBar()->actionGeometry(menu_action); + mbItemRect.moveTo(w.menuBar()->mapToGlobal(mbItemRect.topLeft())); + QTest::keyClick(&w, Qt::Key_M, Qt::AltModifier ); QVERIFY(menu.isActiveWindow()); QPoint firstPoint = QPoint(mbItemRect.right()+1, screenRect.bottom() - menu.height() + 1); QPoint secondPoint = QPoint(mbItemRect.right()+1, availRect.bottom() - menu.height() + 1); @@ -1095,9 +1080,9 @@ void tst_QMenuBar::check_menuPosition() LayoutDirectionSaver directionSaver(Qt::RightToLeft); menu.clear(); QObject::connect(&menu, SIGNAL(aboutToShow()), &menu, SLOT(addActions())); - QRect mbItemRect = mw->menuBar()->actionGeometry(menu_action); - mbItemRect.moveTo(mw->menuBar()->mapToGlobal(mbItemRect.topLeft())); - QTest::keyClick(mw, Qt::Key_M, Qt::AltModifier ); + QRect mbItemRect = w.menuBar()->actionGeometry(menu_action); + mbItemRect.moveTo(w.menuBar()->mapToGlobal(mbItemRect.topLeft())); + QTest::keyClick(&w, Qt::Key_M, Qt::AltModifier ); QVERIFY(menu.isActiveWindow()); QCOMPARE(menu.geometry().right(), mbItemRect.right()); menu.close(); @@ -1106,9 +1091,9 @@ void tst_QMenuBar::check_menuPosition() # ifndef QTEST_NO_CURSOR // QTBUG-28031: Click at bottom-right corner. { - mw->move(400, 200); + w.move(400, 200); LayoutDirectionSaver directionSaver(Qt::RightToLeft); - QMenuBar *mb = mw->menuBar(); + QMenuBar *mb = w.menuBar(); const QPoint localPos = mb->actionGeometry(menu.menuAction()).bottomRight() - QPoint(1, 1); const QPoint globalPos = mb->mapToGlobal(localPos); QCursor::setPos(globalPos); @@ -1125,6 +1110,7 @@ void tst_QMenuBar::task223138_triggered() { //we create a window with submenus and we check that both menubar and menus get the triggered signal QMainWindow win; + centerOnScreen(&win); QMenu *menu = win.menuBar()->addMenu("test"); QAction *top = menu->addAction("toplevelaction"); QMenu *submenu = menu->addMenu("nested menu"); @@ -1164,8 +1150,10 @@ void tst_QMenuBar::task256322_highlight() file2->setText("file2"); QAction *nothing = win.menuBar()->addAction("nothing"); + centerOnScreen(&win); win.show(); - QTest::qWait(200); + QApplication::setActiveWindow(&win); + QVERIFY(QTest::qWaitForWindowActive(&win)); QTest::mousePress(win.menuBar(), Qt::LeftButton, 0, win.menuBar()->actionGeometry(file).center()); QTest::mouseMove(win.menuBar(), win.menuBar()->actionGeometry(file).center()); @@ -1186,12 +1174,11 @@ void tst_QMenuBar::task256322_highlight() QTest::mouseMove(win.menuBar(), nothingCenter); QTRY_VERIFY(!menu2.isVisible()); QVERIFY(!menu.isVisible()); - QAction *activeAction = win.menuBar()->activeAction(); #ifdef Q_OS_MAC - if ((QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) && (activeAction != nothing)) + if ((QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) && (win.menuBar()->activeAction() != nothing)) QEXPECT_FAIL("", "QTBUG-30565: Unstable test", Continue); #endif - QCOMPARE(activeAction, nothing); + QTRY_COMPARE(win.menuBar()->activeAction(), nothing); QTest::mouseRelease(win.menuBar(), Qt::LeftButton, 0, nothingCenter); } @@ -1234,6 +1221,7 @@ void tst_QMenuBar::menubarSizeHint() const int vmargin = style.pixelMetric(QStyle::PM_MenuBarVMargin); const int spacing = style.pixelMetric(QStyle::PM_MenuBarItemSpacing); + centerOnScreen(&mb); mb.show(); QRect result; foreach(QAction *action, mb.actions()) { @@ -1274,6 +1262,7 @@ void tst_QMenuBar::taskQTBUG4965_escapeEaten() QMenu menu("menu1"); QAction *first = menubar.addMenu(&menu); menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC")); + centerOnScreen(&menubar); menubar.show(); QApplication::setActiveWindow(&menubar); QVERIFY(QTest::qWaitForWindowExposed(&menubar)); @@ -1301,6 +1290,7 @@ void tst_QMenuBar::taskQTBUG11823_crashwithInvisibleActions() QAction * m = menubar.addAction( "&m" ); QAction * a = menubar.addAction( "&a" ); + centerOnScreen(&menubar); menubar.show(); QApplication::setActiveWindow(&menubar); QVERIFY(QTest::qWaitForWindowActive(&menubar)); @@ -1324,7 +1314,7 @@ void tst_QMenuBar::closeOnSecondClick() // QTBUG-32807, menu should close on 2nd { QMainWindow mainWindow; mainWindow.resize(300, 200); - mainWindow.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(150, 100)); + centerOnScreen(&mainWindow); #ifndef QT_NO_CURSOR QCursor::setPos(mainWindow.geometry().topLeft() - QPoint(100, 0)); #endif -- cgit v1.2.3 From b49327145eb984c2051585d89f0826c58d35c116 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 29 Aug 2013 12:53:18 +0200 Subject: QMetaMethod::invoke: compare the QMetaType id of the return types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since Qt5, the QMetaObject do not contains the string name of the builtin types, but only the QMetaType id. QMetaMethod::typeName convert back from the id to the string. But if the type is aliased, the string of the main type is returned. This was the case for example for qint64 which is transformed to "qlonglong". This causes a regression in QMetaType::invoke when trying to invoke a method which return an aliased type, since the string comparison would fail. Fix the problem by also comparing the metatype id. Changelog: QMetaMethod::invoke: Fix return of aliased meta type Task-number: QTBUG-33222 Change-Id: Iec7b99dcbf7b23eb818de74f413e4451ce510ac4 Reviewed-by: Jędrzej Nowacki --- tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp index ca80c8926f..4f1320e375 100644 --- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp +++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp @@ -328,6 +328,7 @@ public slots: QObject *sl11(); const char *sl12(); QList sl13(QList l1); + qint64 sl14(); void testSender(); void testReference(QString &str); @@ -395,6 +396,9 @@ const char *QtTestObject::sl12() { slotResult = "sl12"; return "foo"; } QList QtTestObject::sl13(QList l1) { slotResult = "sl13"; return l1; } +qint64 QtTestObject::sl14() +{ slotResult = "sl14"; return Q_INT64_C(123456789)*123456789; } + void QtTestObject::testReference(QString &str) { slotResult = "testReference:" + str; str = "gotcha"; } @@ -513,6 +517,13 @@ void tst_QMetaObject::invokeMetaMember() QCOMPARE(returnValue, argument); QCOMPARE(obj.slotResult, QString("sl13")); + // return qint64 + qint64 return64; + QVERIFY(QMetaObject::invokeMethod(&obj, "sl14", + Q_RETURN_ARG(qint64, return64))); + QCOMPARE(return64, Q_INT64_C(123456789)*123456789); + QCOMPARE(obj.slotResult, QString("sl14")); + //test signals QVERIFY(QMetaObject::invokeMethod(&obj, "sig0")); QCOMPARE(obj.slotResult, QString("sl0")); -- cgit v1.2.3 From 239fe290ad241aac3d6b86ce598f679a0a72fd11 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 5 Sep 2013 14:36:59 +0200 Subject: Center the QColumnView on-screen, in case that helps avoid the test failure. Task-number: QTBUG-32927 Change-Id: Icf0301d583b2ca6e2e099a19eb1f91feac1fb975 Reviewed-by: Friedemann Kleint --- tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp index d3191b2206..6c04e5b39a 100644 --- a/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp +++ b/tests/auto/widgets/itemviews/qcolumnview/tst_qcolumnview.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #define ANIMATION_DELAY 300 @@ -387,6 +388,12 @@ void tst_QColumnView::scrollTo_data() QTest::newRow("reverse") << true << false; } +static inline void centerOnScreen(QWidget *w) +{ + const QPoint offset = QPoint(w->width() / 2, w->height() / 2); + w->move(QGuiApplication::primaryScreen()->availableGeometry().center() - offset); +} + void tst_QColumnView::scrollTo() { QFETCH(bool, reverse); @@ -397,6 +404,7 @@ void tst_QColumnView::scrollTo() ColumnView view(&topLevel); view.resize(200, 200); topLevel.show(); + centerOnScreen(&topLevel); view.scrollTo(QModelIndex(), QAbstractItemView::EnsureVisible); QCOMPARE(view.HorizontalOffset(), 0); -- cgit v1.2.3 From 730bc064a070e886e10950ccfd59780e8976f5fd Mon Sep 17 00:00:00 2001 From: Marcel Krems Date: Sat, 31 Aug 2013 16:42:43 +0200 Subject: Forward QGraphicsView::mouseDoubleClickEvent Do the same as in mousePressEvent. Otherwise it is not possible to handle the event in one of the graphics views parents. Task-number: QTBUG-8061 Change-Id: I67c7635361a9ed595c513c28ea016e6253fa2101 Reviewed-by: Andreas Aardal Hanssen --- .../qgraphicsview/tst_qgraphicsview.cpp | 114 ++++++++++++++++++++- 1 file changed, 109 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 9e06435ca7..7a0ba50ff0 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -221,6 +221,9 @@ private slots: void scrollBarRanges_data(); void scrollBarRanges(); void acceptMousePressEvent(); + void acceptMouseDoubleClickEvent(); + void forwardMousePress(); + void forwardMouseDoubleClick(); void replayMouseMove(); void itemsUnderMouse(); void embeddedViews(); @@ -2832,16 +2835,22 @@ class TestView : public QGraphicsView { public: TestView(QGraphicsScene *scene) - : QGraphicsView(scene), accepted(false) + : QGraphicsView(scene), pressAccepted(false), doubleClickAccepted(false) { } - bool accepted; + bool pressAccepted; + bool doubleClickAccepted; protected: void mousePressEvent(QMouseEvent *event) { QGraphicsView::mousePressEvent(event); - accepted = event->isAccepted(); + pressAccepted = event->isAccepted(); + } + void mouseDoubleClickEvent(QMouseEvent *event) + { + QGraphicsView::mouseDoubleClickEvent(event); + doubleClickAccepted = event->isAccepted(); } }; @@ -2859,14 +2868,109 @@ void tst_QGraphicsView::acceptMousePressEvent() Qt::LeftButton, 0, 0); event.setAccepted(false); QApplication::sendEvent(view.viewport(), &event); - QVERIFY(!view.accepted); + QVERIFY(!view.pressAccepted); scene.addRect(0, 0, 2000, 2000)->setFlag(QGraphicsItem::ItemIsMovable); qApp->processEvents(); // ensure scene rect is updated QApplication::sendEvent(view.viewport(), &event); - QVERIFY(view.accepted); + QVERIFY(view.pressAccepted); +} + +void tst_QGraphicsView::acceptMouseDoubleClickEvent() +{ + QGraphicsScene scene; + + TestView view(&scene); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QMouseEvent event(QEvent::MouseButtonDblClick, + view.viewport()->rect().center(), + view.viewport()->mapToGlobal(view.viewport()->rect().center()), + Qt::LeftButton, 0, 0); + event.setAccepted(false); + QApplication::sendEvent(view.viewport(), &event); + QVERIFY(!view.doubleClickAccepted); + + scene.addRect(0, 0, 2000, 2000)->setFlag(QGraphicsItem::ItemIsMovable); + + qApp->processEvents(); // ensure scene rect is updated + + QApplication::sendEvent(view.viewport(), &event); + QVERIFY(view.doubleClickAccepted); +} + +class TestWidget : public QWidget +{ +public: + TestWidget() + : QWidget(), pressForwarded(false), doubleClickForwarded(false) + { } + + bool pressForwarded; + bool doubleClickForwarded; + +protected: + void mousePressEvent(QMouseEvent *event) + { + QWidget::mousePressEvent(event); + pressForwarded = true; + } + void mouseDoubleClickEvent(QMouseEvent *event) + { + QWidget::mouseDoubleClickEvent(event); + doubleClickForwarded = true; + } +}; + +void tst_QGraphicsView::forwardMousePress() +{ + TestWidget widget; + QGraphicsScene scene; + QGraphicsView view(&scene); + QHBoxLayout layout; + widget.setLayout(&layout); + layout.addWidget(&view); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + + widget.pressForwarded = false; + QTest::mouseClick(view.viewport(), Qt::LeftButton); + QVERIFY(widget.pressForwarded); + + scene.addRect(0, 0, 2000, 2000); + + qApp->processEvents(); // ensure scene rect is updated + + widget.pressForwarded = false; + QTest::mouseClick(view.viewport(), Qt::LeftButton); + QVERIFY(widget.pressForwarded); +} + +void tst_QGraphicsView::forwardMouseDoubleClick() +{ + TestWidget widget; + QGraphicsScene scene; + QGraphicsView view(&scene); + QHBoxLayout layout; + widget.setLayout(&layout); + layout.addWidget(&view); + widget.show(); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); + + widget.doubleClickForwarded = false; + QTest::mouseDClick(view.viewport(), Qt::LeftButton); + QVERIFY(widget.doubleClickForwarded); + + scene.addRect(0, 0, 2000, 2000); + + qApp->processEvents(); // ensure scene rect is updated + + widget.doubleClickForwarded = false; + QTest::mouseDClick(view.viewport(), Qt::LeftButton); + QVERIFY(widget.doubleClickForwarded); } void tst_QGraphicsView::replayMouseMove() -- cgit v1.2.3