Add self-tests for QTest::keyPress() and QTest::keyRelease()
They didn't exist up until now, and future patches rely on them, so add them. Change-Id: I8afdb9417263b45d43355c688a813bdf99ea5fc8 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
This commit is contained in:
parent
b9835aef1a
commit
630b06f86c
18
tests/auto/testlib/selftests/expected_keyboard.lightxml
Normal file
18
tests/auto/testlib/selftests/expected_keyboard.lightxml
Normal file
@ -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"/>
|
9
tests/auto/testlib/selftests/expected_keyboard.tap
Normal file
9
tests/auto/testlib/selftests/expected_keyboard.tap
Normal file
@ -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
|
8
tests/auto/testlib/selftests/expected_keyboard.teamcity
Normal file
8
tests/auto/testlib/selftests/expected_keyboard.teamcity
Normal file
@ -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']
|
7
tests/auto/testlib/selftests/expected_keyboard.txt
Normal file
7
tests/auto/testlib/selftests/expected_keyboard.txt
Normal file
@ -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 *********
|
21
tests/auto/testlib/selftests/expected_keyboard.xml
Normal file
21
tests/auto/testlib/selftests/expected_keyboard.xml
Normal file
@ -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>
|
12
tests/auto/testlib/selftests/expected_keyboard.xunitxml
Normal file
12
tests/auto/testlib/selftests/expected_keyboard.xunitxml
Normal file
@ -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>
|
7
tests/auto/testlib/selftests/keyboard/keyboard.pro
Normal file
7
tests/auto/testlib/selftests/keyboard/keyboard.pro
Normal file
@ -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
|
88
tests/auto/testlib/selftests/keyboard/tst_keyboard.cpp
Normal file
88
tests/auto/testlib/selftests/keyboard/tst_keyboard.cpp
Normal file
@ -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"
|
@ -27,6 +27,7 @@ SUBPROGRAMS = \
|
||||
findtestdata \
|
||||
float \
|
||||
globaldata \
|
||||
keyboard \
|
||||
longstring \
|
||||
maxwarnings \
|
||||
multiexec \
|
||||
|
@ -477,6 +477,7 @@ void tst_Selftests::runSubTest_data()
|
||||
<< "findtestdata"
|
||||
<< "float"
|
||||
<< "globaldata"
|
||||
<< "keyboard"
|
||||
<< "longstring"
|
||||
<< "maxwarnings"
|
||||
<< "multiexec"
|
||||
|
Loading…
Reference in New Issue
Block a user