aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2018-08-07 12:01:39 +0300
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2018-08-16 13:31:39 +0000
commite803aec1ea21fd00e13b9535a4b536cc43c26ee4 (patch)
tree7cdcfcebb4de0cf3651aeea56637e335b46f9a18 /tests
parentcf69f8603e3a1fee24f79d1b446b5ea717e2cf7d (diff)
Add user dictionary and learning for Hunspell
This change adds user dictionary and learning function for Hunspell. Learning happens when the user selects the first candidate from the word candidate list (or presses the space key while the first candidate is selected) and the word does not exist in the default dictionary. User can remove a word from user dictionary by long pressing an item on the word candidate list (and selecting from the menu). This also allows the user to block words originating from the system dictionary. The Hunspell user dictionary is hard limited to 100 words. However, when user enters a word again (which exists in the user dictionary), it will be prioritized in the dictionary, so the most frequent words stay in the dictionary. The dictionaries are language and locale specific and are stored in: QStandardPaths::GenericConfigLocation + "/qtvirtualkeyboard/hunspell" The dictionaries are UTF-8 encoded text files and contain one word per line. The same directory also contains the blacklist files (which also exist per language and locale). These files contain words which are blacklisted from the default dictionary. [ChangeLog] Added user dictionary and learning for Hunspell Change-Id: Ib0fc70f7eaa14ec49b74000144a75c59313ac0fb Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/inputpanel/data/inputpanel/inputpanel.qml57
-rw-r--r--tests/auto/inputpanel/data/tst_inputpanel.qml73
-rw-r--r--tests/auto/inputpanel/tst_inputpanel.cpp15
3 files changed, 137 insertions, 8 deletions
diff --git a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml
index a467fb15..c3682b8a 100644
--- a/tests/auto/inputpanel/data/inputpanel/inputpanel.qml
+++ b/tests/auto/inputpanel/data/inputpanel/inputpanel.qml
@@ -67,6 +67,7 @@ InputPanel {
naviationHighlight.widthAnimation.running ||
naviationHighlight.heightAnimation.running
readonly property var wordCandidateView: Utils.findChildByProperty(keyboard, "objectName", "wordCandidateView", null)
+ readonly property var wordCandidateContextMenu: Utils.findChildByProperty(keyboard, "objectName", "wordCandidateContextMenu", null)
readonly property var shadowInputControl: Utils.findChildByProperty(keyboard, "objectName", "shadowInputControl", null)
readonly property var shadowInput: Utils.findChildByProperty(keyboard, "objectName", "shadowInput", null)
readonly property var selectionControl: Utils.findChildByProperty(inputPanel, "objectName", "selectionControl", null)
@@ -178,6 +179,12 @@ InputPanel {
}
SignalSpy {
+ id: wordCandidateContextMenuActiveSpy
+ target: wordCandidateContextMenu
+ signalName: "onActiveChanged"
+ }
+
+ SignalSpy {
id: shiftStateSpy
target: InputContext
signalName: "onShiftChanged"
@@ -530,6 +537,14 @@ InputPanel {
InputContext.shiftHandler.toggleShift()
}
+ function setShift(shift) {
+ InputContext.shift = shift
+ }
+
+ function setCapsLock(capsLock) {
+ InputContext.capsLock = capsLock
+ }
+
function style() {
return VirtualKeyboardSettings.styleName
}
@@ -583,6 +598,48 @@ InputPanel {
return true
}
+ function selectionListCurrentIndex() {
+ return inputPanel.wordCandidateView.currentIndex
+ }
+
+ function selectionListSuggestionIsFromUserDictionary() {
+ if (!inputPanel.wordCandidateView.currentItem)
+ return false
+ var dictionaryType = inputPanel.wordCandidateView.model.dataAt(inputPanel.wordCandidateView.currentIndex, SelectionListModel.DictionaryTypeRole)
+ return dictionaryType !== undefined && dictionaryType === SelectionListModel.UserDictionary
+ }
+
+ function openWordCandidateContextMenu() {
+ if (!inputPanel.wordCandidateView.currentItem)
+ return false
+ testcase.wait(200)
+ wordCandidateContextMenuActiveSpy.clear()
+ testcase.mousePress(inputPanel.wordCandidateView.currentItem)
+ wordCandidateContextMenuActiveSpy.wait()
+ testcase.mouseRelease(inputPanel.wordCandidateView.currentItem)
+ return wordCandidateContextMenu.active
+ }
+
+ function selectItemFromWordCandidateContextMenu(index) {
+ if (!inputPanel.wordCandidateView.currentItem)
+ return false
+ if (!wordCandidateContextMenu.active)
+ return false
+ var wordCandidateContextMenuList = Utils.findChildByProperty(keyboard, "objectName", "wordCandidateContextMenuList", null)
+ if (wordCandidateContextMenuList.currentIndex !== index) {
+ wordCandidateContextMenuList.currentIndex = index
+ testcase.waitForRendering(inputPanel)
+ }
+ if (!wordCandidateContextMenuList.currentItem)
+ return false
+ var itemPos = inputPanel.mapFromItem(wordCandidateContextMenuList.currentItem,
+ wordCandidateContextMenuList.currentItem.width / 2,
+ wordCandidateContextMenuList.currentItem.height / 2)
+ testcase.mouseClick(inputPanel, itemPos.x, itemPos.y, Qt.LeftButton, 0, 20)
+ testcase.waitForRendering(inputPanel)
+ return true
+ }
+
function setHandwritingMode(enabled) {
if (inputPanel.keyboard.handwritingMode !== enabled) {
if (!enabled || inputPanel.keyboard.isHandwritingAvailable())
diff --git a/tests/auto/inputpanel/data/tst_inputpanel.qml b/tests/auto/inputpanel/data/tst_inputpanel.qml
index 83c97593..e2efe8b0 100644
--- a/tests/auto/inputpanel/data/tst_inputpanel.qml
+++ b/tests/auto/inputpanel/data/tst_inputpanel.qml
@@ -1820,19 +1820,14 @@ Rectangle {
skip("Prediction/spell correction not enabled")
for (var len = 1; len <= 5; ++len) {
- inputPanel.wordCandidateListChangedSpy.clear()
inputPanel.virtualKeyClick("z")
- waitForRendering(inputPanel)
- if (len >= 3) {
- if (data.wclAutoCommitWord)
- tryVerify(function() { return inputPanel.wordCandidateView.model.count === 0 }, 500)
- else
- wait(500)
+ if (len >= 2) {
+ inputPanel.wordCandidateListChangedSpy.clear()
+ inputPanel.wordCandidateListChangedSpy.wait()
if (inputPanel.wordCandidateView.model.count <= 1)
break
}
}
- waitForRendering(inputPanel)
if (data.wclAutoCommitWord)
compare(inputPanel.wordCandidateView.model.count, 0)
@@ -2018,5 +2013,67 @@ Rectangle {
compare(inputPanel.shadowInput.text, "")
}
+ function test_userDictionary_data() {
+ return [
+ { inputSequence: ['a','s','d','f'], initShift: false },
+ { inputSequence: ['a','s','d'], initShift: false, expectedSuggestion: "asdf", suggestionIsFromUserDictionary: true },
+ { inputSequence: ['a','s','d'], initShift: true, expectedSuggestion: "Asdf", suggestionIsFromUserDictionary: true },
+ //
+ { inputSequence: ['s','d','f','a'], initShift: true },
+ { inputSequence: ['s','d','f'], initShift: true, expectedSuggestion: "Sdfa", suggestionIsFromUserDictionary: true },
+ { inputSequence: ['s','d','f'], initShift: false, expectedSuggestion: "sdfa", suggestionIsFromUserDictionary: true, removeSuggestion: true },
+ //
+ { inputSequence: ['d','f','a','s'], initCapsLock: true },
+ { inputSequence: ['d','f','a'], initCapsLock: true, expectedSuggestion: "DFAS", suggestionIsFromUserDictionary: true },
+ { inputSequence: ['d','f','a'], initShift: false, unexpectedSuggestion: "dfas", suggestionIsFromUserDictionary: true },
+ //
+ { inputSequence: ['f','a','s','d'], initShift: false, initInputMethodHints: Qt.ImhSensitiveData },
+ { inputSequence: ['f','a','s'], initShift: false, unexpectedSuggestion: "fasd" },
+ { inputSequence: ['f','a','s'], initShift: true, unexpectedSuggestion: "Fasd"},
+ //
+ { initLocale: "en_GB", inputSequence: "windo", expectedSuggestion: "Window", suggestionIsFromUserDictionary: false, removeSuggestion: true },
+ { initLocale: "en_GB", inputSequence: "window", },
+ { initLocale: "en_GB", inputSequence: "windo", expectedSuggestion: "Window", suggestionIsFromUserDictionary: false },
+ ]
+ }
+
+ function test_userDictionary(data) {
+ prepareTest(data, true)
+
+ if (!inputPanel.wordCandidateListVisibleHint)
+ skip("Prediction/spell correction not enabled")
+
+ if (data.hasOwnProperty("initShift"))
+ inputPanel.setShift(data.initShift)
+ if (data.hasOwnProperty("initCapsLock"))
+ inputPanel.setCapsLock(data.initCapsLock)
+
+ for (var inputIndex in data.inputSequence)
+ inputPanel.virtualKeyClick(data.inputSequence[inputIndex])
+
+ if (data.hasOwnProperty("expectedSuggestion")) {
+ tryVerify(function() {return inputPanel.selectionListSearchSuggestion(data.expectedSuggestion)}, 1000, "The expected spell correction suggestion \"%1\" was not found".arg(data.expectedSuggestion))
+ verify(inputPanel.selectionListCurrentIndex() > 0)
+ if (data.hasOwnProperty("suggestionIsFromUserDictionary"))
+ compare(inputPanel.selectionListSuggestionIsFromUserDictionary(), data.suggestionIsFromUserDictionary)
+ if (data.hasOwnProperty("removeSuggestion") && data.removeSuggestion) {
+ verify(inputPanel.openWordCandidateContextMenu())
+ inputPanel.wordCandidateListChangedSpy.clear()
+ verify(inputPanel.selectItemFromWordCandidateContextMenu(0))
+ inputPanel.wordCandidateListChangedSpy.wait()
+ tryVerify(function() {return !inputPanel.selectionListSearchSuggestion(data.expectedSuggestion)}, 1000, "An unexpected spell correction suggestion \"%1\" was found".arg(data.unexpectedSuggestion))
+ } else {
+ inputPanel.selectionListSelectCurrentItem()
+ }
+ } else if (data.hasOwnProperty("unexpectedSuggestion")) {
+ var oldIndex = inputPanel.selectionListCurrentIndex()
+ tryVerify(function() {return !inputPanel.selectionListSearchSuggestion(data.unexpectedSuggestion)}, 1000, "An unexpected spell correction suggestion \"%1\" was found".arg(data.unexpectedSuggestion))
+ compare(inputPanel.selectionListCurrentIndex(), oldIndex)
+ } else {
+ inputPanel.selectionListSelectCurrentItem()
+ }
+
+ Qt.inputMethod.reset()
+ }
}
}
diff --git a/tests/auto/inputpanel/tst_inputpanel.cpp b/tests/auto/inputpanel/tst_inputpanel.cpp
index 8b84f67b..409383c7 100644
--- a/tests/auto/inputpanel/tst_inputpanel.cpp
+++ b/tests/auto/inputpanel/tst_inputpanel.cpp
@@ -29,7 +29,22 @@
#include <QtQuickTest/quicktest.h>
#include <QByteArray>
+#include <QStandardPaths>
+#include <QFileInfo>
+#include <QDir>
static bool s_configEnv = qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard"));
+static bool initStandardPaths() {
+ QStandardPaths::setTestModeEnabled(true);
+ auto configLocations = QStringList()
+ << QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/qtvirtualkeyboard"
+ << QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/qtvirtualkeyboard";
+ for (const QString &configLocation : configLocations) {
+ if (configLocation != "/qtvirtualkeyboard")
+ QDir(configLocation).removeRecursively();
+ }
+ return true;
+}
+static bool s_initStandardPaths = initStandardPaths();
QUICK_TEST_MAIN(inputpanel)