summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGunnar Sletta <gunnar.sletta@digia.com>2012-12-03 12:31:18 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-01-25 14:11:07 +0100
commit64134181db034055dbcd7dfacff087abdb29d591 (patch)
treebb0de5a10de5e4b991311f6974d0f43f8bd1adde /tests
parent9a5ab30d52257f88931d6d09a376b4d75da69c5a (diff)
Introducing QWidget::createWindowContainer()
A QWidget that can embed a QWindow. This can be used to embed a QWindow/QOpenGLContext based window or a full QQuickView. Change-Id: I8415b5ae38562fc00b46150fa70b56fd9b19a80c Reviewed-by: Jørgen Lind <jorgen.lind@gmail.com> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/widgets/kernel/kernel.pro1
-rw-r--r--tests/auto/widgets/kernel/qwindowcontainer/.gitignore1
-rw-r--r--tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro6
-rw-r--r--tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp226
4 files changed, 234 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro
index b280f44f05..20720dc928 100644
--- a/tests/auto/widgets/kernel/kernel.pro
+++ b/tests/auto/widgets/kernel/kernel.pro
@@ -15,6 +15,7 @@ SUBDIRS=\
qwidgetaction \
qwidgetmetatype \
qwidgetsvariant \
+ qwindowcontainer \
qshortcut \
qsizepolicy
diff --git a/tests/auto/widgets/kernel/qwindowcontainer/.gitignore b/tests/auto/widgets/kernel/qwindowcontainer/.gitignore
new file mode 100644
index 0000000000..038f477220
--- /dev/null
+++ b/tests/auto/widgets/kernel/qwindowcontainer/.gitignore
@@ -0,0 +1 @@
+tst_qwindowcontainer
diff --git a/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro b/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro
new file mode 100644
index 0000000000..4ff05eb04a
--- /dev/null
+++ b/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro
@@ -0,0 +1,6 @@
+CONFIG += testcase
+mac:CONFIG -= app_bundle
+# CONFIG += parallel_test // Cannot be parallel due to the activation test
+TARGET = tst_qwindowcontainer
+QT += widgets testlib
+SOURCES += tst_qwindowcontainer.cpp
diff --git a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
new file mode 100644
index 0000000000..440639cd49
--- /dev/null
+++ b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp
@@ -0,0 +1,226 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+#include <qapplication.h>
+#include <qwindow.h>
+#include <qwidget.h>
+
+
+
+class Window : public QWindow
+{
+public:
+ Window()
+ : numberOfExposes(0)
+ , numberOfObscures(0)
+ {
+ }
+
+ void exposeEvent(QExposeEvent *) {
+ if (isExposed())
+ ++numberOfExposes;
+ else
+ ++numberOfObscures;
+ }
+
+ int numberOfExposes;
+ int numberOfObscures;
+};
+
+
+
+class tst_QWindowContainer: public QObject
+{
+ Q_OBJECT
+private slots:
+ void testShow();
+ void testPositionAndSize();
+ void testExposeObscure();
+ void testOwnership();
+ void testBehindTheScenesDeletion();
+ void testUnparenting();
+ void testActivation();
+};
+
+
+
+void tst_QWindowContainer::testShow()
+{
+ QWidget root;
+ root.setGeometry(100, 100, 400, 400);
+
+ Window *window = new Window();
+ QWidget *container = QWidget::createWindowContainer(window, &root);
+
+ container->setGeometry(50, 50, 200, 200);
+
+ root.show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+}
+
+
+
+void tst_QWindowContainer::testPositionAndSize()
+{
+ QWindow *window = new QWindow();
+ window->setGeometry(300, 400, 500, 600);
+
+ QWidget *container = QWidget::createWindowContainer(window);
+ container->setGeometry(50, 50, 200, 200);
+
+
+ container->show();
+ QVERIFY(QTest::qWaitForWindowExposed(container));
+
+ QCOMPARE(window->x(), 0);
+ QCOMPARE(window->y(), 0);
+ QCOMPARE(window->width(), container->width());
+ QCOMPARE(window->height(), container->height());
+}
+
+
+
+void tst_QWindowContainer::testExposeObscure()
+{
+ Window *window = new Window();
+
+ QWidget *container = QWidget::createWindowContainer(window);
+ container->setGeometry(50, 50, 200, 200);
+
+ container->show();
+ QVERIFY(QTest::qWaitForWindowExposed(container));
+ QVERIFY(QTest::qWaitForWindowExposed(window));
+
+ QVERIFY(window->numberOfExposes > 0);
+
+ container->hide();
+
+ QElapsedTimer timer;
+ timer.start();
+ while (window->numberOfObscures == 0 && timer.elapsed() < 5000) {
+ QTest::qWait(10);
+ }
+
+ QVERIFY(window->numberOfObscures > 0);
+}
+
+
+
+void tst_QWindowContainer::testOwnership()
+{
+ QPointer<QWindow> window(new QWindow());
+ QWidget *container = QWidget::createWindowContainer(window);
+
+ delete container;
+
+ QCOMPARE(window.data(), (QWindow *) 0);
+}
+
+
+
+void tst_QWindowContainer::testBehindTheScenesDeletion()
+{
+ QWindow *window = new QWindow();
+ QWidget *container = QWidget::createWindowContainer(window);
+
+ delete window;
+
+ // The child got removed, showing not should not have any side effects,
+ // such as for instance, crashing...
+ container->show();
+ QVERIFY(QTest::qWaitForWindowExposed(container));
+ delete container;
+}
+
+
+
+void tst_QWindowContainer::testActivation()
+{
+ QWidget root;
+
+ QWindow *window = new QWindow();
+ QWidget *container = QWidget::createWindowContainer(window, &root);
+
+ container->setGeometry(100, 100, 200, 100);
+ root.setGeometry(100, 100, 400, 300);
+
+ root.show();
+ root.activateWindow();
+
+ QVERIFY(QTest::qWaitForWindowActive(root.windowHandle()));
+ QVERIFY(QGuiApplication::focusWindow() == root.windowHandle());
+
+ // Under KDE (ubuntu 12.10), we experience that doing two activateWindow in a row
+ // does not work. The second gets ignored by the window manager, even though the
+ // timestamp in the xcb connection is unique for both.
+ if (QGuiApplication::platformName() == "xcb")
+ QTest::qWait(100);
+
+ window->requestActivate();
+ QVERIFY(QTest::qWaitForWindowActive(window));
+ QVERIFY(QGuiApplication::focusWindow() == window);
+}
+
+
+
+void tst_QWindowContainer::testUnparenting()
+{
+ QWindow *window = new QWindow();
+ QWidget *container = QWidget::createWindowContainer(window);
+ container->setGeometry(100, 100, 200, 100);
+
+ window->setParent(0);
+
+ container->show();
+
+ QVERIFY(QTest::qWaitForWindowExposed(container));
+
+ // Window should not be made visible by container..
+ QVERIFY(!window->isVisible());
+}
+
+QTEST_MAIN(tst_QWindowContainer)
+
+#include "tst_qwindowcontainer.moc"