[Libreoffice-commits] core.git: 5 commits - starmath/inc starmath/Library_sm.mk starmath/source uitest/math_tests vcl/source

Markus Mohrhard markus.mohrhard at googlemail.com
Sun Jul 17 15:22:24 UTC 2016


 starmath/Library_sm.mk                    |    1 
 starmath/inc/ElementsDockingWindow.hxx    |    6 +
 starmath/source/ElementsDockingWindow.cxx |    8 +-
 starmath/source/uiobject.cxx              |  115 ++++++++++++++++++++++++++++++
 starmath/source/uiobject.hxx              |   65 ++++++++++++++++
 uitest/math_tests/start.py                |   40 +++++++++-
 vcl/source/uitest/uiobject.cxx            |   35 ++++++++-
 7 files changed, 266 insertions(+), 4 deletions(-)

New commits:
commit 9a067900cccebe092e71d2dc540aaf0da3c7f091
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 17:12:56 2016 +0200

    uitest: add a complex math test
    
    Change-Id: Ib246c3041f066ecedd1ebbe564566a1824d293bc

diff --git a/uitest/math_tests/start.py b/uitest/math_tests/start.py
index 5b11ae7..6626207 100644
--- a/uitest/math_tests/start.py
+++ b/uitest/math_tests/start.py
@@ -11,8 +11,7 @@ from libreoffice.uno.propertyvalue import mkPropertyValues
 
 from uitest.framework import UITestCase
 
-import time
-import unittest
+from uitest.debug import sleep
 
 class SimpleMathTest(UITestCase):
 
@@ -62,4 +61,29 @@ class SimpleMathTest(UITestCase):
 
         self.ui_test.close_doc()
 
+    def test_complete_math(self):
+        self.ui_test.create_doc_in_start_center("math")
+
+        xMathDoc = self.xUITest.getTopFocusWindow()
+
+        xList = xMathDoc.getChild("listbox")
+        state = get_state_as_dict(xList)
+        self.assertEqual(state["SelectEntryText"], "Unary/Binary Operators")
+        xList.executeAction("SELECT", mkPropertyValues({"POS": "1"}))
+
+        xMathSelector = xMathDoc.getChild("element_selector")
+
+        xElement = xMathSelector.getChild("1")
+        xElement.executeAction("SELECT", tuple())
+
+        xMathEdit = xMathDoc.getChild("math_edit")
+        xMathEdit.executeAction("TYPE", mkPropertyValues({"TEXT":"1"}))
+        xMathEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE":"F4"}))
+        xMathEdit.executeAction("TYPE", mkPropertyValues({"TEXT":"2"}))
+
+        edit_state = get_state_as_dict(xMathEdit)
+        self.assertEqual("1 <> 2 ", edit_state["Text"])
+
+        self.ui_test.close_doc()
+
 # vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 91e05f1631e530b2eaf71deed0a83265e086abd6
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 17:12:32 2016 +0200

    uitest: recognize function keys in keycodes
    
    Change-Id: I0246b21d88aa43e36728c556b22372a8c04299fe

diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index 7ded8dc..bd36cc6 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -128,12 +128,39 @@ sal_uInt16 get_key(sal_Unicode cChar, bool& bShift)
     return cChar;
 }
 
+bool isFunctionKey(const OUString& rStr, sal_uInt16& rKeyCode)
+{
+    std::map<OUString, sal_uInt16> aFunctionKeyMap = {
+        {"F1", KEY_F1},
+        {"F2", KEY_F2},
+        {"F3", KEY_F3},
+        {"F4", KEY_F4},
+        {"F5", KEY_F5},
+        {"F6", KEY_F6},
+        {"F7", KEY_F7},
+        {"F8", KEY_F8},
+        {"F9", KEY_F9},
+        {"F10", KEY_F10},
+        {"F11", KEY_F11},
+        {"F12", KEY_F12}
+    };
+
+    rKeyCode = 0;
+    auto itr = aFunctionKeyMap.find(rStr);
+    if (itr == aFunctionKeyMap.end())
+        return false;
+
+    rKeyCode = itr->second;
+    return true;
+}
+
 std::vector<KeyEvent> generate_key_events_from_keycode(const OUString& rStr)
 {
     std::vector<KeyEvent> aEvents;
 
     std::map<OUString, sal_uInt16> aKeyMap = {
         {"ESC", KEY_ESCAPE},
+        {"TAB", KEY_TAB},
         {"DOWN", KEY_DOWN},
         {"UP", KEY_UP},
         {"LEFT", KEY_LEFT},
@@ -175,7 +202,13 @@ std::vector<KeyEvent> generate_key_events_from_keycode(const OUString& rStr)
             aRemainingText = aToken;
     }
 
-    if (aKeyMap.find(aRemainingText) != aKeyMap.end())
+    sal_uInt16 nFunctionKey = 0;
+    if (isFunctionKey(aRemainingText, nFunctionKey))
+    {
+        vcl::KeyCode aCode(nFunctionKey, bShift, bMod1, bMod2, false);
+        aEvents.push_back(KeyEvent(0, aCode));
+    }
+    else if (aKeyMap.find(aRemainingText) != aKeyMap.end())
     {
         sal_uInt16 nKey = aKeyMap[aRemainingText];
         vcl::KeyCode aCode(nKey, bShift, bMod1, bMod2, false);
commit b2f6f4f38a219ea3968517812300df8d24e23bcd
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 16:44:24 2016 +0200

    uitest: add demo for new element selector math wrapper
    
    Change-Id: I64c98254c5d5ae1cc6c9729654028201f1773c90

diff --git a/uitest/math_tests/start.py b/uitest/math_tests/start.py
index 39b3111..5b11ae7 100644
--- a/uitest/math_tests/start.py
+++ b/uitest/math_tests/start.py
@@ -50,4 +50,16 @@ class SimpleMathTest(UITestCase):
 
         self.ui_test.close_doc()
 
+    def test_math_selector(self):
+        self.ui_test.create_doc_in_start_center("math")
+
+        xMathDoc = self.xUITest.getTopFocusWindow()
+
+        xMathSelector = xMathDoc.getChild("element_selector")
+
+        xElement = xMathSelector.getChild("1")
+        xElement.executeAction("SELECT", tuple())
+
+        self.ui_test.close_doc()
+
 # vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit c1bfdddb51bf2fe22a7c935a797bf7f7221b0202
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 16:43:40 2016 +0200

    uitest: add wrapper for element selector
    
    Change-Id: I641a290b3a9cf46ba484a9a851a27456cc68678c

diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index 0b05af9..08a4b50 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -88,6 +88,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
         starmath/source/symbol \
         starmath/source/tmpdevice \
         starmath/source/typemap \
+        starmath/source/uiobject \
         starmath/source/unodoc \
         starmath/source/unofilter \
         starmath/source/unomodel \
diff --git a/starmath/inc/ElementsDockingWindow.hxx b/starmath/inc/ElementsDockingWindow.hxx
index 5c0f228..cbc4bed 100644
--- a/starmath/inc/ElementsDockingWindow.hxx
+++ b/starmath/inc/ElementsDockingWindow.hxx
@@ -29,6 +29,7 @@
 
 class SmDocShell;
 class SmNode;
+class ElementSelectorUIObject;
 
 class SmElement
 {
@@ -72,6 +73,9 @@ public:
 
 class SmElementsControl : public Control
 {
+    friend class ElementSelectorUIObject;
+    friend class ElementUIObject;
+
     static const sal_uInt16 aUnaryBinaryOperatorsList[][2];
     static const sal_uInt16 aRelationsList[][2];
     static const sal_uInt16 aSetOperations[][2];
@@ -125,6 +129,8 @@ public:
     void DoScroll(long nDelta);
 
     void SetSelectHdl(const Link<SmElement&,void>& rLink) { maSelectHdlLink = rLink; }
+
+    virtual FactoryFunction GetUITestFactory() const override;
 };
 
 class SmElementsDockingWindow : public SfxDockingWindow
diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx
index b66c37d..adba7e1 100644
--- a/starmath/source/ElementsDockingWindow.cxx
+++ b/starmath/source/ElementsDockingWindow.cxx
@@ -25,6 +25,7 @@
 #include <visitors.hxx>
 #include "document.hxx"
 #include "node.hxx"
+#include "uiobject.hxx"
 
 #include <o3tl/make_unique.hxx>
 #include <svl/stritem.hxx>
@@ -227,6 +228,7 @@ SmElementsControl::SmElementsControl(vcl::Window *pParent)
     , mbVerticalMode(true)
     , mxScroll(VclPtr<ScrollBar>::Create(this, WB_VERT))
 {
+    set_id("element_selector");
     SetMapMode( MapMode(MAP_100TH_MM) );
     SetDrawMode( DrawModeFlags::Default );
     SetLayoutMode( ComplexTextLayoutFlags::Default );
@@ -683,6 +685,11 @@ Size SmElementsControl::GetOptimalSize() const
     return LogicToPixel(Size(100, 100), MapMode(MAP_APPFONT));
 }
 
+FactoryFunction SmElementsControl::GetUITestFactory() const
+{
+    return ElementSelectorUIObject::create;
+}
+
 const sal_uInt16 SmElementsDockingWindow::aCategories[] = {
     RID_CATEGORY_UNARY_BINARY_OPERATORS,
     RID_CATEGORY_RELATIONS,
diff --git a/starmath/source/uiobject.cxx b/starmath/source/uiobject.cxx
new file mode 100644
index 0000000..6350975
--- /dev/null
+++ b/starmath/source/uiobject.cxx
@@ -0,0 +1,115 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "uiobject.hxx"
+
+#include "ElementsDockingWindow.hxx"
+
+ElementUIObject::ElementUIObject(VclPtr<SmElementsControl> xElementSelector,
+        const OUString& rID):
+    mxElementsSelector(xElementSelector),
+    maID(rID)
+{
+}
+
+SmElement* ElementUIObject::get_element()
+{
+    sal_uInt32 nID = maID.toUInt32();
+    size_t n = mxElementsSelector->maElementList.size();
+    if (nID >= n)
+        return nullptr;
+
+    return mxElementsSelector->maElementList[nID].get();
+}
+
+StringMap ElementUIObject::get_state()
+{
+    StringMap aMap;
+    aMap["ID"] = maID;
+
+    SmElement* pElement = get_element();
+    if (pElement)
+        aMap["Text"] = pElement->getText();
+
+    return aMap;
+}
+
+void ElementUIObject::execute(const OUString& rAction,
+        const StringMap& /*rParameters*/)
+{
+    if (rAction == "SELECT")
+    {
+        SmElement* pElement = get_element();
+        if (pElement)
+            mxElementsSelector->maSelectHdlLink.Call(*pElement);
+    }
+}
+
+ElementSelectorUIObject::ElementSelectorUIObject(VclPtr<SmElementsControl> xElementSelector):
+    WindowUIObject(xElementSelector),
+    mxElementsSelector(xElementSelector)
+{
+}
+
+StringMap ElementSelectorUIObject::get_state()
+{
+    StringMap aMap = WindowUIObject::get_state();
+
+    SmElement* pElement = mxElementsSelector->mpCurrentElement;
+    if (pElement)
+        aMap["CurrentEntry"] = pElement->getText();
+
+    aMap["CurrentSelection"] = OUString::number(mxElementsSelector->maCurrentSetId);
+
+    return aMap;
+}
+
+void ElementSelectorUIObject::execute(const OUString& rAction,
+        const StringMap& rParameters)
+{
+    WindowUIObject::execute(rAction, rParameters);
+}
+
+std::unique_ptr<UIObject> ElementSelectorUIObject::get_child(const OUString& rID)
+{
+    size_t nID = rID.toInt32();
+    size_t n = mxElementsSelector->maElementList.size();
+    if (nID >= n)
+        throw css::uno::RuntimeException("invalid id");
+
+    return std::unique_ptr<UIObject>(new ElementUIObject(mxElementsSelector, rID));
+}
+
+std::set<OUString> ElementSelectorUIObject::get_children() const
+{
+    std::set<OUString> aChildren;
+
+    size_t n = mxElementsSelector->maElementList.size();
+    for (size_t i = 0; i < n; ++i)
+    {
+        aChildren.insert(OUString::number(i));
+    }
+
+    return aChildren;
+}
+
+std::unique_ptr<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
+{
+    SmElementsControl* pElementsControl = dynamic_cast<SmElementsControl*>(pWindow);
+    assert(pElementsControl);
+
+    return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pElementsControl));
+}
+
+OUString ElementSelectorUIObject::get_name() const
+{
+    return OUString("SmElementSelector");
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/uiobject.hxx b/starmath/source/uiobject.hxx
new file mode 100644
index 0000000..1ecdf48
--- /dev/null
+++ b/starmath/source/uiobject.hxx
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_STARMATH_SOURCE_UIOBJECT_HXX
+#define INCLUDED_STARMATH_SOURCE_UIOBJECT_HXX
+
+#include <vcl/uitest/uiobject.hxx>
+
+class SmElementsControl;
+class SmElement;
+
+class ElementUIObject : public UIObject
+{
+private:
+    VclPtr<SmElementsControl> mxElementsSelector;
+    OUString maID;
+
+public:
+
+    ElementUIObject(VclPtr<SmElementsControl> xElementSelector,
+            const OUString& rID);
+
+    virtual StringMap get_state() override;
+
+    virtual void execute(const OUString& rAction,
+            const StringMap& rParameters);
+
+private:
+    SmElement* get_element();
+};
+
+class ElementSelectorUIObject : public WindowUIObject
+{
+private:
+    VclPtr<SmElementsControl> mxElementsSelector;
+
+public:
+
+    ElementSelectorUIObject(VclPtr<SmElementsControl> xElementSelector);
+
+    virtual StringMap get_state() override;
+
+    virtual void execute(const OUString& rAction,
+            const StringMap& rParameters) override;
+
+    static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
+
+    virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override;
+
+    virtual std::set<OUString> get_children() const override;
+
+protected:
+
+    virtual OUString get_name() const;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit d03d7a79406c4bd25a776a4f7247588662b121b0
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Sun Jul 17 16:42:30 2016 +0200

    remove wrong outdated comment
    
    Change-Id: I3fe6957b73776152b90c34ac411167f6f4e9e4f5

diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx
index 82c1ca6..b66c37d 100644
--- a/starmath/source/ElementsDockingWindow.cxx
+++ b/starmath/source/ElementsDockingWindow.cxx
@@ -632,7 +632,6 @@ void SmElementsControl::build()
 
     switch(maCurrentSetId)
     {
-        // we need to divide by 2 because of the matrix of two dimensions
         case RID_CATEGORY_UNARY_BINARY_OPERATORS:
             addElements(aUnaryBinaryOperatorsList, SAL_N_ELEMENTS(aUnaryBinaryOperatorsList));
         break;


More information about the Libreoffice-commits mailing list