diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2009-03-23 09:18:55 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-03-23 09:18:55 (GMT) |
commit | e5fcad302d86d316390c6b0f62759a067313e8a9 (patch) | |
tree | c2afbf6f1066b6ce261f14341cf6d310e5595bc1 /tests/auto/qsizegrip | |
download | Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2 |
Long live Qt 4.5!
Diffstat (limited to 'tests/auto/qsizegrip')
-rw-r--r-- | tests/auto/qsizegrip/.gitignore | 1 | ||||
-rw-r--r-- | tests/auto/qsizegrip/qsizegrip.pro | 5 | ||||
-rw-r--r-- | tests/auto/qsizegrip/tst_qsizegrip.cpp | 201 |
3 files changed, 207 insertions, 0 deletions
diff --git a/tests/auto/qsizegrip/.gitignore b/tests/auto/qsizegrip/.gitignore new file mode 100644 index 0000000..ec480bc --- /dev/null +++ b/tests/auto/qsizegrip/.gitignore @@ -0,0 +1 @@ +tst_qsizegrip diff --git a/tests/auto/qsizegrip/qsizegrip.pro b/tests/auto/qsizegrip/qsizegrip.pro new file mode 100644 index 0000000..7bc43d5 --- /dev/null +++ b/tests/auto/qsizegrip/qsizegrip.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +INCLUDEPATH += . +SOURCES += tst_qsizegrip.cpp + + diff --git a/tests/auto/qsizegrip/tst_qsizegrip.cpp b/tests/auto/qsizegrip/tst_qsizegrip.cpp new file mode 100644 index 0000000..5b050e8 --- /dev/null +++ b/tests/auto/qsizegrip/tst_qsizegrip.cpp @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> +#include <QSizeGrip> +#include <QEvent> +#include <QLineEdit> +#include <QVBoxLayout> +#include <QLabel> + +static inline Qt::Corner sizeGripCorner(QWidget *parent, QSizeGrip *sizeGrip) +{ + if (!parent || !sizeGrip) + return Qt::TopLeftCorner; + + const QPoint sizeGripPos = sizeGrip->mapTo(parent, QPoint(0, 0)); + bool isAtBottom = sizeGripPos.y() >= parent->height() / 2; + bool isAtLeft = sizeGripPos.x() <= parent->width() / 2; + if (isAtLeft) + return isAtBottom ? Qt::BottomLeftCorner : Qt::TopLeftCorner; + else + return isAtBottom ? Qt::BottomRightCorner : Qt::TopRightCorner; + +} + +//TESTED_CLASS= +//TESTED_FILES= + +Q_DECLARE_METATYPE(Qt::WindowType); + +class tst_QSizeGrip : public QObject +{ + Q_OBJECT +public slots: + void initTestCase(); + void cleanupTestCase(); + +private slots: + void hideAndShowOnWindowStateChange_data(); + void hideAndShowOnWindowStateChange(); + void orientation(); + +private: + QLineEdit *dummyWidget; +}; + +class TestWidget : public QWidget +{ +public: + TestWidget(QWidget *parent = 0, Qt::WindowFlags flags = 0) : QWidget(parent, flags) {} + QSize sizeHint() const { return QSize(300, 200); } + void changeEvent(QEvent *event) + { + QWidget::changeEvent(event); + if (isWindow() && event->type() == QEvent::WindowStateChange) { +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(this); +#endif + } + } +}; + +void tst_QSizeGrip::initTestCase() +{ + dummyWidget = new QLineEdit; + dummyWidget->show(); +} + +void tst_QSizeGrip::cleanupTestCase() +{ + delete dummyWidget; + dummyWidget = 0; +} + +void tst_QSizeGrip::hideAndShowOnWindowStateChange_data() +{ + QTest::addColumn<Qt::WindowType>("windowType"); + QTest::newRow("Qt::Window") << Qt::Window; + QTest::newRow("Qt::SubWindow") << Qt::SubWindow; +} + +void tst_QSizeGrip::hideAndShowOnWindowStateChange() +{ + QFETCH(Qt::WindowType, windowType); + + QWidget *parentWidget = windowType == Qt::Window ? 0 : new QWidget; + TestWidget *widget = new TestWidget(parentWidget, Qt::WindowFlags(windowType)); + QSizeGrip *sizeGrip = new QSizeGrip(widget); + + // Normal. + if (parentWidget) + parentWidget->show(); + else + widget->show(); + QVERIFY(sizeGrip->isVisible()); + + widget->showFullScreen(); + QVERIFY(!sizeGrip->isVisible()); + + widget->showNormal(); + QVERIFY(sizeGrip->isVisible()); + + widget->showMaximized(); +#ifndef Q_WS_MAC + QVERIFY(!sizeGrip->isVisible()); +#else + QVERIFY(sizeGrip->isVisible()); +#endif + + widget->showNormal(); + QVERIFY(sizeGrip->isVisible()); + + sizeGrip->hide(); + QVERIFY(!sizeGrip->isVisible()); + + widget->showFullScreen(); + widget->showNormal(); + QVERIFY(!sizeGrip->isVisible()); + widget->showMaximized(); + widget->showNormal(); + QVERIFY(!sizeGrip->isVisible()); + + delete widget; + delete parentWidget; +} + +void tst_QSizeGrip::orientation() +{ + TestWidget widget; + widget.setLayout(new QVBoxLayout); + QSizeGrip *sizeGrip = new QSizeGrip(&widget); + sizeGrip->setFixedSize(sizeGrip->sizeHint()); + widget.layout()->addWidget(sizeGrip); + widget.layout()->setAlignment(sizeGrip, Qt::AlignBottom | Qt::AlignRight); + + widget.show(); + QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::BottomRightCorner); + + widget.setLayoutDirection(Qt::RightToLeft); + qApp->processEvents(); + QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::BottomLeftCorner); + + widget.unsetLayoutDirection(); + qApp->processEvents(); + QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::BottomRightCorner); + + widget.layout()->setAlignment(sizeGrip, Qt::AlignTop | Qt::AlignRight); + qApp->processEvents(); + QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::TopRightCorner); + + widget.setLayoutDirection(Qt::RightToLeft); + qApp->processEvents(); + QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::TopLeftCorner); + + widget.unsetLayoutDirection(); + qApp->processEvents(); + QCOMPARE(sizeGripCorner(&widget, sizeGrip), Qt::TopRightCorner); +} + +QTEST_MAIN(tst_QSizeGrip) +#include "tst_qsizegrip.moc" + |