2
* This file is part of Maliit Plugins
4
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
6
* Contact: Mohammad Anwari <Mohammad.Anwari@nokia.com>
8
* Redistribution and use in source and binary forms, with or without modification,
9
* are permitted provided that the following conditions are met:
11
* Redistributions of source code must retain the above copyright notice, this list
12
* of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright notice, this list
14
* of conditions and the following disclaimer in the documentation and/or other materials
15
* provided with the distribution.
16
* Neither the name of Nokia Corporation nor the names of its contributors may be
17
* used to endorse or promote products derived from this software without specific
18
* prior written permission.
20
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
21
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
22
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
23
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
#include "models/key.h"
34
#include "models/text.h"
35
#include "logic/languagefeatures.h"
36
#include "logic/wordengine.h"
37
#include "plugin/editor.h"
39
#include <inputmethodhostprobe.h>
44
using namespace MaliitKeyboard;
46
typedef void (Editor::*Method)(const Key &key);
48
Q_DECLARE_METATYPE(Method);
50
// This test suite verifies how Editor implements auto-repeat for backspace key
51
class TestRepeatBackspace
57
QScopedPointer<Editor> editor;
58
QScopedPointer<InputMethodHostProbe> host;
59
EditorOptions options;
62
Q_SLOT void initTestCase()
64
options.backspace_auto_repeat_delay = 50;
65
options.backspace_auto_repeat_interval = 20;
67
delay = qMax(options.backspace_auto_repeat_delay, options.backspace_auto_repeat_interval) + 10;
72
editor.reset(new Editor(options, new Model::Text, new Logic::WordEngine, new Logic::LanguageFeatures));
73
host.reset(new InputMethodHostProbe);
74
editor->setHost(host.data());
84
* testClick verifies following scenario:
85
* 1) press (or move finger into) backspace key
86
* 2) release key without delay
87
* At this point we should send exactly one key event
88
* and auto-repeat should not be triggered
90
Q_SLOT void testClick_data()
92
QTest::addColumn<Method>("initiate");
94
Method enter = &Editor::onKeyEntered;
95
Method press = &Editor::onKeyPressed;
97
QTest::newRow("enter") << enter;
98
QTest::newRow("press") << press;
101
Q_SLOT void testClick()
103
QFETCH(Method, initiate);
106
backspace.setAction(Key::ActionBackspace);
108
(editor.data()->*initiate)(backspace);
109
editor->onKeyReleased(backspace);
111
QCOMPARE(host->keyEventCount(), 1);
112
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyPress);
113
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));
117
QCOMPARE(host->keyEventCount(), 1);
121
* testFastMove verifies following scenario:
122
* 1) press (or move finger into) backspace key
123
* 2) move finger to another key without delay
124
* At this point we should not send key events at all.
126
Q_SLOT void testFastMove_data()
128
QTest::addColumn<Method>("initiate");
130
Method enter = &Editor::onKeyEntered;
131
Method press = &Editor::onKeyPressed;
133
QTest::newRow("enter") << enter;
134
QTest::newRow("press") << press;
137
Q_SLOT void testFastMove()
139
QFETCH(Method, initiate);
142
backspace.setAction(Key::ActionBackspace);
144
(editor.data()->*initiate)(backspace);
145
editor->onKeyExited(backspace);
147
QCOMPARE(host->keyEventCount(), 0);
151
QCOMPARE(host->keyEventCount(), 0);
155
* testRepeat verifies main scenario for auto repeat:
156
* 1) press (or move finger into) backspace key
157
* 2) wait a bit, so autorepeat starts
158
* 3) we should send first key event now
160
* 5) auto-repeat send second event with different delay
161
* 3) release (or move finger away from) backspace key
162
* Auto-repeat should be stopped now and no new events will be sent
165
Q_SLOT void testRepeat_data()
167
QTest::addColumn<Method>("initiate");
168
QTest::addColumn<Method>("finalize");
170
Method enter = &Editor::onKeyEntered;
171
Method exit = &Editor::onKeyExited;
172
Method press = &Editor::onKeyPressed;
173
Method release = &Editor::onKeyReleased;
175
QTest::newRow("enter-exit") << enter << exit;
176
QTest::newRow("enter-release") << enter << release;
177
QTest::newRow("press-release") << press << release;
178
QTest::newRow("press-exit") << press << exit;
181
Q_SLOT void testRepeat()
183
QFETCH(Method, initiate);
184
QFETCH(Method, finalize);
187
backspace.setAction(Key::ActionBackspace);
189
(editor.data()->*initiate)(backspace);
191
QCOMPARE(host->keyEventCount(), 0);
193
TestUtils::waitForSignal(host.data(), SIGNAL(keyEventSent(QKeyEvent)));
194
QCOMPARE(host->keyEventCount(), 1);
195
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyPress);
196
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));
198
TestUtils::waitForSignal(host.data(), SIGNAL(keyEventSent(QKeyEvent)));
199
QCOMPARE(host->keyEventCount(), 2);
200
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyPress);
201
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));
203
(editor.data()->*finalize)(backspace);
207
QCOMPARE(host->keyEventCount(), 2);
212
QTEST_MAIN(TestRepeatBackspace)