diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp | 159 |
1 files changed, 126 insertions, 33 deletions
diff --git a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp index 270e5168f7..6282028746 100644 --- a/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp +++ b/tests/auto/widgets/widgets/qmainwindow/tst_qmainwindow.cpp @@ -149,6 +149,8 @@ private slots: void toggleUnifiedTitleAndToolBarOnMac(); #endif void QTBUG21378_animationFinished(); + void resizeDocks(); + void resizeDocks_data(); }; @@ -211,15 +213,15 @@ tst_QMainWindow::tst_QMainWindow() void tst_QMainWindow::constructor() { QMainWindow mw; - QVERIFY(mw.parentWidget() == 0); + QVERIFY(!mw.parentWidget()); QVERIFY(mw.isWindow()); QMainWindow mw2(&mw); - QVERIFY(mw2.parentWidget() == &mw); + QCOMPARE(mw2.parentWidget(), &mw); QVERIFY(mw2.isWindow()); QMainWindow mw3(&mw, Qt::FramelessWindowHint); - QVERIFY(mw3.parentWidget() == &mw); + QCOMPARE(mw3.parentWidget(), &mw); QVERIFY(mw3.isWindow()); } @@ -607,7 +609,7 @@ void tst_QMainWindow::menuBar() QVERIFY(mw.menuBar() != 0); //we now call deleteLater on the previous menubar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mb1 == 0); + QVERIFY(mb1.isNull()); mw.setMenuBar(mb2); QVERIFY(mw.menuBar() != 0); @@ -618,7 +620,7 @@ void tst_QMainWindow::menuBar() QVERIFY(mw.menuBar() != 0); //we now call deleteLater on the previous menubar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mb2 == 0); + QVERIFY(mb2.isNull()); mb1 = new QMenuBar; mw.setMenuBar(mb1); @@ -631,7 +633,7 @@ void tst_QMainWindow::menuBar() QCOMPARE(mw.menuBar(), (QMenuBar *)mb2); //we now call deleteLater on the previous menubar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mb1 == 0); + QVERIFY(mb1.isNull()); mb1 = new QMenuBar; mw.setMenuBar(mb1); @@ -639,7 +641,7 @@ void tst_QMainWindow::menuBar() QCOMPARE(mw.menuBar(), (QMenuBar *)mb1); //we now call deleteLater on the previous menubar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mb2 == 0); + QVERIFY(mb2.isNull()); QPointer<QWidget> topLeftCornerWidget = new QWidget; mb1->setCornerWidget(topLeftCornerWidget, Qt::TopLeftCorner); @@ -652,7 +654,7 @@ void tst_QMainWindow::menuBar() QCOMPARE(mw.menuBar(), (QMenuBar *)mb2); //we now call deleteLater on the previous menubar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mb1 == 0); + QVERIFY(mb1.isNull()); QVERIFY(topLeftCornerWidget); QCOMPARE(mb2->cornerWidget(Qt::TopLeftCorner), static_cast<QWidget *>(topLeftCornerWidget)); @@ -663,8 +665,8 @@ void tst_QMainWindow::menuBar() QVERIFY(mw.menuBar() != 0); //we now call deleteLater on the previous menubar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mb2 == 0); + QVERIFY(mb2.isNull()); QVERIFY(!topLeftCornerWidget); QVERIFY(!topRightCornerWidget); } @@ -692,7 +694,7 @@ void tst_QMainWindow::statusBar() QVERIFY(mw.statusBar() != 0); //we now call deleteLater on the previous statusbar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(sb1 == 0); + QVERIFY(sb1.isNull()); mw.setStatusBar(sb2); QVERIFY(mw.statusBar() != 0); @@ -703,7 +705,7 @@ void tst_QMainWindow::statusBar() QVERIFY(mw.statusBar() != 0); //we now call deleteLater on the previous statusbar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(sb2 == 0); + QVERIFY(sb2.isNull()); sb1 = new QStatusBar; mw.setStatusBar(sb1); @@ -718,7 +720,7 @@ void tst_QMainWindow::statusBar() QCOMPARE(sb2->parentWidget(), (QWidget *)&mw); //we now call deleteLater on the previous statusbar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(sb1 == 0); + QVERIFY(sb1.isNull()); sb1 = new QStatusBar; mw.setStatusBar(sb1); @@ -727,7 +729,7 @@ void tst_QMainWindow::statusBar() QCOMPARE(sb1->parentWidget(), (QWidget *)&mw); //we now call deleteLater on the previous statusbar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(sb2 == 0); + QVERIFY(sb2.isNull()); sb2 = new QStatusBar; mw.setStatusBar(sb2); @@ -736,7 +738,7 @@ void tst_QMainWindow::statusBar() QCOMPARE(sb2->parentWidget(), (QWidget *)&mw); //we now call deleteLater on the previous statusbar QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(sb1 == 0); + QVERIFY(sb1.isNull()); } { @@ -749,7 +751,7 @@ void tst_QMainWindow::statusBar() QVERIFY(indexOfSb != -1); delete sb; indexOfSb = l->indexOf(sb); - QVERIFY(indexOfSb == -1); + QCOMPARE(indexOfSb, -1); } } @@ -791,7 +793,7 @@ void tst_QMainWindow::centralWidget() { { QMainWindow mw; - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); } { @@ -799,7 +801,7 @@ void tst_QMainWindow::centralWidget() QPointer<QWidget> w1 = new QWidget; QPointer<QWidget> w2 = new QWidget; - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); mw.setCentralWidget(w1); QVERIFY(mw.centralWidget() != 0); @@ -812,12 +814,12 @@ void tst_QMainWindow::centralWidget() QCOMPARE(w2->parentWidget(), (QWidget *)&mw); mw.setCentralWidget(0); - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); //we now call deleteLater on the previous central widgets QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(w1 == 0); - QVERIFY(w2 == 0); + QVERIFY(w1.isNull()); + QVERIFY(w2.isNull()); } { @@ -831,7 +833,7 @@ void tst_QMainWindow::centralWidget() QPointer<QWidget> w1 = new QWidget; QPointer<QWidget> w2 = new QWidget; - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); mw.setCentralWidget(w1); QVERIFY(mw.centralWidget() != 0); @@ -844,12 +846,12 @@ void tst_QMainWindow::centralWidget() QCOMPARE(w2->parentWidget(), (QWidget *)&mw); mw.setCentralWidget(0); - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); //we now call deleteLater on the previous central widgets QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(w1 == 0); - QVERIFY(w2 == 0); + QVERIFY(w1.isNull()); + QVERIFY(w2.isNull()); } } @@ -860,25 +862,25 @@ void tst_QMainWindow::takeCentralWidget() { QPointer<QWidget> w1 = new QWidget; - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); mw.setCentralWidget(w1); QWidget *oldCentralWidget = mw.takeCentralWidget(); - QVERIFY(oldCentralWidget == w1.data()); + QCOMPARE(oldCentralWidget, w1.data()); // ensure that takeCentralWidget doesn't end up calling deleteLater // on the central widget QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); QVERIFY(!w1.isNull()); - QVERIFY(w1->parent() == 0); + QVERIFY(!w1->parent()); mw.setCentralWidget(w1); // ensure that the deleteLater called by setCentralWidget // gets executed QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); - QVERIFY(mw.centralWidget() == w1.data()); + QCOMPARE(mw.centralWidget(), w1.data()); QPointer<QWidget> w2 = new QWidget; @@ -887,10 +889,10 @@ void tst_QMainWindow::takeCentralWidget() { QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); QVERIFY(w1.isNull()); - QVERIFY(mw.centralWidget() == w2.data()); + QCOMPARE(mw.centralWidget(), w2.data()); QWidget *hopefullyW2 = mw.takeCentralWidget(); - QVERIFY(mw.centralWidget() == 0); + QVERIFY(!mw.centralWidget()); // ensure that takeCentralWidget doesn't end up calling deleteLater // on the central widget QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete); @@ -1928,9 +1930,9 @@ void tst_QMainWindow::toggleUnifiedTitleAndToolBarOnMac() mw.show(); QRect frameGeometry = mw.frameGeometry(); mw.setUnifiedTitleAndToolBarOnMac(false); - QVERIFY(frameGeometry.topLeft() == mw.frameGeometry().topLeft()); + QCOMPARE(frameGeometry.topLeft(), mw.frameGeometry().topLeft()); mw.setUnifiedTitleAndToolBarOnMac(true); - QVERIFY(frameGeometry.topLeft() == mw.frameGeometry().topLeft()); + QCOMPARE(frameGeometry.topLeft(), mw.frameGeometry().topLeft()); } #endif @@ -1950,5 +1952,96 @@ void tst_QMainWindow::QTBUG21378_animationFinished() delete mwClickTimer; QVERIFY(true); } + +Q_DECLARE_METATYPE(Qt::Orientation) + +void tst_QMainWindow::resizeDocks_data() +{ + QTest::addColumn<Qt::Orientation>("orientation"); + QTest::addColumn<QStringList>("docks"); + QTest::addColumn<QList<int> >("sizes"); + + QTest::newRow("1") << Qt::Horizontal + << (QStringList() << "blue" << "orange" << "green" << "gray") + << (QList<int>() << 190 << 190 << 320 << 160); + + QTest::newRow("2") << Qt::Vertical + << (QStringList() << "yellow" << "orange") + << (QList<int>() << 147 << 133 ); + + + QTest::newRow("3") << Qt::Horizontal + << (QStringList() << "blue" << "yellow") + << (QList<int>() << 190 << 600); +} + +void tst_QMainWindow::resizeDocks() +{ + AddList addList; + addList + << AddDockWidget("blue", Qt::LeftDockWidgetArea) + << AddDockWidget("red", Qt::TopDockWidgetArea) + << AddDockWidget("pink", "red") + << AddDockWidget("yellow", Qt::RightDockWidgetArea) + << AddDockWidget("orange", Qt::RightDockWidgetArea) + << AddDockWidget("green", "orange", Qt::Horizontal) + << AddDockWidget("gray", "orange", Qt::Horizontal); + /* + +--------------------------------+ + | red/pink | + +------+-+-----------------------+ + | | | yellow | + | blue + +--------+------+-------+ + | | | orange | gray | green | + +------+-+--------+------+-------+ + + */ + + QMainWindow mw(0, Qt::BypassWindowManagerHint); + mw.setDockNestingEnabled(true); + mw.resize(1800, 600); + + foreach (const AddDockWidget &i, addList) + i.apply(&mw); + + foreach (QDockWidget *dw, mw.findChildren<QDockWidget *>()) + dw->setStyleSheet( "* { background-color: " + dw->objectName() +" }"); + + mw.setCentralWidget(new QTextEdit); + + mw.show(); + QTest::qWaitForWindowExposed(&mw); + + QFETCH(Qt::Orientation, orientation); + QFETCH(QStringList, docks); + QFETCH(QList<int>, sizes); + + QList<QDockWidget *> list; + foreach (const QString &name, docks) { + QDockWidget *d = mw.findChild<QDockWidget *>(name); + QVERIFY(d); + list << d; + } + + mw.resizeDocks(list, sizes, orientation); + + qApp->processEvents(); + + int totalFromList = 0; + int actualTotal = 0; + for (int i = 0; i < docks.count(); ++i) { + totalFromList += sizes[i]; + QSize s = list[i]->size(); + actualTotal += (orientation == Qt::Horizontal) ? s.width() : s.height(); +// qDebug() << list[i] << list[i]->size() << sizes[i]; + } + + for (int i = 0; i < docks.count(); ++i) { + QSize s = list[i]->size(); + int value = (orientation == Qt::Horizontal) ? s.width() : s.height(); + QCOMPARE(value, qRound(sizes[i]*actualTotal/double(totalFromList))); + } +} + QTEST_MAIN(tst_QMainWindow) #include "tst_qmainwindow.moc" |