diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-03-20 02:50:50 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-03-20 20:36:00 +0000 |
commit | dd5f85910e6103ffa3ffbc70e9c60a0f8dc4b427 (patch) | |
tree | 0620cd0dc83eeeb6e40fede2ae0416f56b12551c /vcl/source/uitest/logger.cxx | |
parent | 231070fc9c94411e5a5feacc7b375886b8a904a2 (diff) |
uitest: start to log key input
We need to disable this part in release builds.
Change-Id: Ica57f8aca1ffb5f7938ab82ef8b888a8d6d6101a
Reviewed-on: https://gerrit.libreoffice.org/35450
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'vcl/source/uitest/logger.cxx')
-rw-r--r-- | vcl/source/uitest/logger.cxx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/vcl/source/uitest/logger.cxx b/vcl/source/uitest/logger.cxx index d24efeb5d0a8..2549b7dd9a44 100644 --- a/vcl/source/uitest/logger.cxx +++ b/vcl/source/uitest/logger.cxx @@ -67,6 +67,76 @@ void UITestLogger::log(const OUString& rString) maStream.WriteLine(OUStringToOString(rString, RTL_TEXTENCODING_UTF8)); } +void UITestLogger::logKeyInput(VclPtr<vcl::Window>& xUIElement, const KeyEvent& rEvent) +{ + if (!mbValid) + return; + + const OUString& rID = xUIElement->get_id(); + if (rID.isEmpty()) + return; + + sal_Unicode nChar = rEvent.GetCharCode(); + sal_uInt16 nKeyCode = rEvent.GetKeyCode().GetCode(); + bool bShift = rEvent.GetKeyCode().IsShift(); + bool bMod1 = rEvent.GetKeyCode().IsMod1(); + bool bMod2 = rEvent.GetKeyCode().IsMod1(); + bool bMod3 = rEvent.GetKeyCode().IsMod1(); + + std::map<OUString, sal_uInt16> aKeyMap = { + {"ESC", KEY_ESCAPE}, + {"TAB", KEY_TAB}, + {"DOWN", KEY_DOWN}, + {"UP", KEY_UP}, + {"LEFT", KEY_LEFT}, + {"RIGHT", KEY_RIGHT}, + {"DELETE", KEY_DELETE}, + {"INSERT", KEY_INSERT}, + {"BACKSPACE", KEY_BACKSPACE}, + {"RETURN", KEY_RETURN}, + {"HOME", KEY_HOME}, + {"END", KEY_END}, + {"PAGEUP", KEY_PAGEUP}, + {"PAGEDOWN", KEY_PAGEDOWN} + }; + + OUString aFound; + for (auto& itr : aKeyMap) + { + if (itr.second == nKeyCode) + { + aFound = itr.first; + break; + } + } + + OUString aKeyCode; + if (!aFound.isEmpty() || bShift || bMod1 || bMod2 || bMod3) + { + aKeyCode = "{\"KEYCODE\": \""; + if (bShift) + aKeyCode += "SHIFT+"; + + if (bMod1) + aKeyCode += "CTRL+"; + + if (bMod2) + aKeyCode += "ALT+"; + + if (aFound.isEmpty()) + aKeyCode += OUStringLiteral1(nChar) + "\"}"; + else + aKeyCode += aFound + "\"}"; + } + else + { + aKeyCode = "{\"TEXT\": \"" + OUStringLiteral1(nChar) + "\"}"; + } + + OUString aContent = "Action on element: " + rID + " with action: TYPE and content: " + aKeyCode; + maStream.WriteLine(OUStringToOString(aContent, RTL_TEXTENCODING_UTF8)); +} + UITestLogger& UITestLogger::getInstance() { static UITestLogger aInstance; |