diff options
Diffstat (limited to 'tests/auto/testlib')
10 files changed, 172 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/expected_keyboard.lightxml b/tests/auto/testlib/selftests/expected_keyboard.lightxml new file mode 100644 index 0000000000..5699fba3bf --- /dev/null +++ b/tests/auto/testlib/selftests/expected_keyboard.lightxml @@ -0,0 +1,18 @@ +<Environment> + <QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion> + <QtBuild/> + <QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion> +</Environment> +<TestFunction name="initTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="keyPressAndRelease"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="cleanupTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<Duration msecs="0"/> diff --git a/tests/auto/testlib/selftests/expected_keyboard.tap b/tests/auto/testlib/selftests/expected_keyboard.tap new file mode 100644 index 0000000000..0725434f8c --- /dev/null +++ b/tests/auto/testlib/selftests/expected_keyboard.tap @@ -0,0 +1,9 @@ +TAP version 13 +# tst_Keyboard +ok 1 - initTestCase() +ok 2 - keyPressAndRelease() +ok 3 - cleanupTestCase() +1..3 +# tests 3 +# pass 3 +# fail 0 diff --git a/tests/auto/testlib/selftests/expected_keyboard.teamcity b/tests/auto/testlib/selftests/expected_keyboard.teamcity new file mode 100644 index 0000000000..dc01f86ff0 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_keyboard.teamcity @@ -0,0 +1,8 @@ +##teamcity[testSuiteStarted name='tst_Keyboard' flowId='tst_Keyboard'] +##teamcity[testStarted name='initTestCase()' flowId='tst_Keyboard'] +##teamcity[testFinished name='initTestCase()' flowId='tst_Keyboard'] +##teamcity[testStarted name='keyPressAndRelease()' flowId='tst_Keyboard'] +##teamcity[testFinished name='keyPressAndRelease()' flowId='tst_Keyboard'] +##teamcity[testStarted name='cleanupTestCase()' flowId='tst_Keyboard'] +##teamcity[testFinished name='cleanupTestCase()' flowId='tst_Keyboard'] +##teamcity[testSuiteFinished name='tst_Keyboard' flowId='tst_Keyboard'] diff --git a/tests/auto/testlib/selftests/expected_keyboard.txt b/tests/auto/testlib/selftests/expected_keyboard.txt new file mode 100644 index 0000000000..13b7c70672 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_keyboard.txt @@ -0,0 +1,7 @@ +********* Start testing of tst_Keyboard ********* +Config: Using QtTest library +PASS : tst_Keyboard::initTestCase() +PASS : tst_Keyboard::keyPressAndRelease() +PASS : tst_Keyboard::cleanupTestCase() +Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms +********* Finished testing of tst_Keyboard ********* diff --git a/tests/auto/testlib/selftests/expected_keyboard.xml b/tests/auto/testlib/selftests/expected_keyboard.xml new file mode 100644 index 0000000000..f5ad1b2287 --- /dev/null +++ b/tests/auto/testlib/selftests/expected_keyboard.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<TestCase name="tst_Keyboard"> +<Environment> + <QtVersion>@INSERT_QT_VERSION_HERE@</QtVersion> + <QtBuild/> + <QTestVersion>@INSERT_QT_VERSION_HERE@</QTestVersion> +</Environment> +<TestFunction name="initTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="keyPressAndRelease"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<TestFunction name="cleanupTestCase"> +<Incident type="pass" file="" line="0" /> + <Duration msecs="0"/> +</TestFunction> +<Duration msecs="0"/> +</TestCase> diff --git a/tests/auto/testlib/selftests/expected_keyboard.xunitxml b/tests/auto/testlib/selftests/expected_keyboard.xunitxml new file mode 100644 index 0000000000..93b5f7bfff --- /dev/null +++ b/tests/auto/testlib/selftests/expected_keyboard.xunitxml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<testsuite errors="0" failures="0" tests="3" name="tst_Keyboard"> + <properties> + <property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/> + <property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/> + <property value="" name="QtBuild"/> + </properties> + <testcase result="pass" name="initTestCase"/> + <testcase result="pass" name="keyPressAndRelease"/> + <testcase result="pass" name="cleanupTestCase"/> + <system-err/> +</testsuite> diff --git a/tests/auto/testlib/selftests/keyboard/keyboard.pro b/tests/auto/testlib/selftests/keyboard/keyboard.pro new file mode 100644 index 0000000000..0097318797 --- /dev/null +++ b/tests/auto/testlib/selftests/keyboard/keyboard.pro @@ -0,0 +1,7 @@ +SOURCES += tst_keyboard.cpp +QT += testlib testlib-private gui gui-private + +macos:CONFIG -= app_bundle +CONFIG -= debug_and_release_target + +TARGET = keyboard diff --git a/tests/auto/testlib/selftests/keyboard/tst_keyboard.cpp b/tests/auto/testlib/selftests/keyboard/tst_keyboard.cpp new file mode 100644 index 0000000000..e185be8532 --- /dev/null +++ b/tests/auto/testlib/selftests/keyboard/tst_keyboard.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/qtest.h> +#include <QtGui/qwindow.h> + +class tst_Keyboard : public QObject +{ + Q_OBJECT + +private slots: + void keyPressAndRelease(); +}; + +class KeyWindow : public QWindow +{ +public: + void keyPressEvent(QKeyEvent *event) override + { + QSharedPointer<QKeyEvent> copiedEvent(new QKeyEvent(event->type(), event->key(), + event->modifiers(), event->text(), event->isAutoRepeat(), event->count())); + mEventOrder.append(copiedEvent); + } + + void keyReleaseEvent(QKeyEvent *event) override + { + QSharedPointer<QKeyEvent> copiedEvent(new QKeyEvent(event->type(), event->key(), + event->modifiers(), event->text(), event->isAutoRepeat(), event->count())); + mEventOrder.append(copiedEvent); + } + + QVector<QSharedPointer<QKeyEvent>> mEventOrder; +}; + +void tst_Keyboard::keyPressAndRelease() +{ + KeyWindow window; + window.show(); + window.setGeometry(100, 100, 200, 200); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + QTest::keyPress(&window, Qt::Key_A); + QTest::keyRelease(&window, Qt::Key_A); + QCOMPARE(window.mEventOrder.size(), 2); + + const auto pressEvent = window.mEventOrder.at(0); + QCOMPARE(pressEvent->type(), QEvent::KeyPress); + QCOMPARE(pressEvent->key(), Qt::Key_A); + QCOMPARE(pressEvent->modifiers(), Qt::NoModifier); + QCOMPARE(pressEvent->text(), "a"); + QCOMPARE(pressEvent->isAutoRepeat(), false); + + const auto releaseEvent = window.mEventOrder.at(1); + QCOMPARE(releaseEvent->type(), QEvent::KeyRelease); + QCOMPARE(releaseEvent->key(), Qt::Key_A); + QCOMPARE(releaseEvent->modifiers(), Qt::NoModifier); + QCOMPARE(releaseEvent->text(), "a"); + QCOMPARE(releaseEvent->isAutoRepeat(), false); +} + +QTEST_MAIN(tst_Keyboard) +#include "tst_keyboard.moc" diff --git a/tests/auto/testlib/selftests/selftests.pri b/tests/auto/testlib/selftests/selftests.pri index 079f3f7959..ec77cb2049 100644 --- a/tests/auto/testlib/selftests/selftests.pri +++ b/tests/auto/testlib/selftests/selftests.pri @@ -27,6 +27,7 @@ SUBPROGRAMS = \ findtestdata \ float \ globaldata \ + keyboard \ longstring \ maxwarnings \ multiexec \ diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 423f33c90e..ac20b12433 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -477,6 +477,7 @@ void tst_Selftests::runSubTest_data() << "findtestdata" << "float" << "globaldata" + << "keyboard" << "longstring" << "maxwarnings" << "multiexec" |