[Libreoffice-commits] core.git: include/svx sc/qa svx/source vcl/source

Shiko (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 10 14:09:13 UTC 2020


 include/svx/SvxColorValueSet.hxx                       |    2 
 include/svx/uiobject.hxx                               |   24 +
 sc/qa/uitest/calc_tests/cellBackgroundColorSelector.py |  209 +++++++++++++++++
 svx/source/tbxctrls/SvxColorValueSet.cxx               |    7 
 svx/source/uitest/sdrobject.cxx                        |   56 ++++
 vcl/source/uitest/uiobject.cxx                         |    7 
 6 files changed, 304 insertions(+), 1 deletion(-)

New commits:
commit c36ac492c2413bdd894715dd8c89127d3498e45e
Author:     Shiko <aelshreif7 at gmail.com>
AuthorDate: Sun Jun 7 14:23:37 2020 +0200
Commit:     Ahmed ElShreif <aelshreif7 at gmail.com>
CommitDate: Wed Jun 10 16:08:33 2020 +0200

    uitest: Add support for Calc / Format cell /  background color selector
    
    - Add wrapper for the color-win set
    - Add the factory function in the correct class
    - Add a demo for cell background color and recent color selector
    - Extend the ability of ComboBoxUIObject to be able to select with text
    
    Change-Id: Ie84ba7fff2f84c3fec7f5adbb5b1cdc6c80729f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95667
    Tested-by: Jenkins
    Reviewed-by: Ahmed ElShreif <aelshreif7 at gmail.com>

diff --git a/include/svx/SvxColorValueSet.hxx b/include/svx/SvxColorValueSet.hxx
index 143627ffedb1..82792acf64f4 100644
--- a/include/svx/SvxColorValueSet.hxx
+++ b/include/svx/SvxColorValueSet.hxx
@@ -40,6 +40,8 @@ public:
     void addEntriesForColorSet(const std::set<Color>& rColorSet, const OUString& rNamePrefix);
     Size layoutAllVisible(sal_uInt32 nEntryCount);
     Size layoutToGivenHeight(sal_uInt32 nHeight, sal_uInt32 nEntryCount);
+
+    virtual FactoryFunction GetUITestFactory() const override;
 };
 
 #endif // INCLUDED_SVX_SVXCOLORVALUESET_HXX
diff --git a/include/svx/uiobject.hxx b/include/svx/uiobject.hxx
index ea40c2a6b9e7..de47586f74c9 100644
--- a/include/svx/uiobject.hxx
+++ b/include/svx/uiobject.hxx
@@ -12,9 +12,12 @@
 
 #include <svx/svxdllapi.h>
 
+#include <svx/SvxColorValueSet.hxx>
+
 #include <vcl/uitest/uiobject.hxx>
 
 class SdrObject;
+class SvxColorValueSet;
 
 class SVXCORE_DLLPUBLIC SdrUIObject : public UIObject
 {
@@ -32,6 +35,27 @@ public:
     virtual SdrObject* get_object() = 0;
 };
 
+class SvxColorValueSetUIObject final : public WindowUIObject
+{
+    SvxColorValueSet* mpColorSet;
+
+public:
+
+    SvxColorValueSetUIObject(vcl::Window*  xColorSetWin, SvxColorValueSet* pColorSet);
+
+    virtual void execute(const OUString& rAction,
+            const StringMap& rParameters) override;
+
+    static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
+
+    virtual StringMap get_state() override;
+
+private:
+
+    OUString get_name() const override;
+};
+
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/uitest/calc_tests/cellBackgroundColorSelector.py b/sc/qa/uitest/calc_tests/cellBackgroundColorSelector.py
new file mode 100644
index 000000000000..04675dac9cfd
--- /dev/null
+++ b/sc/qa/uitest/calc_tests/cellBackgroundColorSelector.py
@@ -0,0 +1,209 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# 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/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from uitest.uihelper.common import select_pos
+from libreoffice.calc.document import get_cell_by_position
+from libreoffice.uno.propertyvalue import mkPropertyValues
+
+class CalcCellBackgroundColorSelector(UITestCase):
+
+    def test_color_selector(self):
+
+        #This is to test color selection
+        calc_doc = self.ui_test.create_doc_in_start_center("calc")
+        xCalcDoc = self.xUITest.getTopFocusWindow()
+        gridwin = xCalcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+        #select cell A1
+        gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A1"}))
+        #format - cell
+        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
+        xDialog = self.xUITest.getTopFocusWindow()
+        xTabs = xDialog.getChild("tabcontrol")
+        select_pos(xTabs, "6")  #tab Numbers
+        # click on color btn
+        xbtncolor = xDialog.getChild("btncolor")
+        xbtncolor.executeAction("CLICK",tuple())
+        xpaletteselector = xDialog.getChild("paletteselector")
+
+        # Now we have the ColorPage that we can get the color selector from it
+        xColorpage = xDialog.getChild("ColorPage")
+        color_selector = xColorpage.getChild("colorset")
+
+        # For chart-palettes colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "chart-palettes"}))
+        # Select Color with id 2
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "2"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "2")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "1")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Chart 2")
+        self.assertEqual(get_state_as_dict(color_selector)["RGB"], "(255,66,14)")
+
+        # Select Color with id 5
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "5"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "5")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "4")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Chart 5")
+        self.assertEqual(get_state_as_dict(color_selector)["RGB"], "(126,0,33)")
+
+        # For libreoffice colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "libreoffice"}))
+        # Select Color with id 6
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "6"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "6")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "5")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "32")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Green Accent")
+        self.assertEqual(get_state_as_dict(color_selector)["RGB"], "(44,238,14)")
+
+        # Select Color with id 30
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "30"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "30")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "29")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Yellow Accent")
+        self.assertEqual(get_state_as_dict(color_selector)["RGB"], "(255,215,76)")
+
+        # For html colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "html"}))
+        # Select Color with id 1
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "1"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "1")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "0")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "138")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "White")
+        # Select Color with id 120
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "120"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "120")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "119")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Navy")
+
+        # For freecolour-hlc colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "freecolour-hlc"}))
+        # Select Color with id 988
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "988"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "988")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "987")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "1032")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "HLC 350 60 10")
+        # Select Color with id 575
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "575"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "575")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "574")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "HLC 190 50 20")
+
+        # For tonal colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "tonal"}))
+        # Select Color with id 17
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "17"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "17")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "16")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "120")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Cyan 82%")
+        # Select Color with id 13
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "13"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "13")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Magenta 82%")
+
+        # For material colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "material"}))
+        # Select Color with id 9
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "9"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "9")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "8")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "228")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Gray 800")
+
+        # For standard colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "standard"}))
+        # Select Color with id 3
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "3"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "3")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "2")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "120")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Dark Gray 3")
+
+        xOk = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOk)
+
+        self.ui_test.close_doc()
+
+    def test_recent_color_selector(self):
+
+        #This is to test recent color selection
+        calc_doc = self.ui_test.create_doc_in_start_center("calc")
+        xCalcDoc = self.xUITest.getTopFocusWindow()
+        gridwin = xCalcDoc.getChild("grid_window")
+        document = self.ui_test.get_component()
+        #select cell A5
+        gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "A5"}))
+        #format - cell
+        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
+        xDialog = self.xUITest.getTopFocusWindow()
+        xTabs = xDialog.getChild("tabcontrol")
+        select_pos(xTabs, "6")  #tab Numbers
+        # click on color btn
+        xbtncolor = xDialog.getChild("btncolor")
+        xbtncolor.executeAction("CLICK",tuple())
+
+        # we will select color for cell A5 to be able to predict the latest color in
+        # recent color selector
+        xpaletteselector = xDialog.getChild("paletteselector")
+        xColorpage = xDialog.getChild("ColorPage")
+        color_selector = xColorpage.getChild("colorset")
+
+        # For chart-palettes colors
+        xpaletteselector.executeAction("SELECT", mkPropertyValues({"TEXT": "chart-palettes"}))
+        # Select Color with id 2
+        color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "2"}))
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorId"], "2")
+        self.assertEqual(get_state_as_dict(color_selector)["CurrColorPos"], "1")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorsCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColCount"], "12")
+        self.assertEqual(get_state_as_dict(color_selector)["ColorText"], "Chart 2")
+        xrgb = get_state_as_dict(color_selector)["RGB"]
+
+        # close the dialog after selection of the color
+        xOk = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOk)
+
+        #select cell D3
+        gridwin.executeAction("SELECT", mkPropertyValues({"CELL": "D3"}))
+        #format - cell
+        self.ui_test.execute_dialog_through_command(".uno:FormatCellDialog")
+        xDialog = self.xUITest.getTopFocusWindow()
+        xTabs = xDialog.getChild("tabcontrol")
+        select_pos(xTabs, "6")  #tab Numbers
+        # click on color btn
+        xbtncolor = xDialog.getChild("btncolor")
+        xbtncolor.executeAction("CLICK",tuple())
+
+        xColorpage = xDialog.getChild("ColorPage")
+        recent_color_selector = xColorpage.getChild("recentcolorset")
+
+        # Select Color with id 1
+        recent_color_selector.executeAction("CHOOSE", mkPropertyValues({"POS": "1"}))
+        self.assertEqual(get_state_as_dict(recent_color_selector)["CurrColorId"], "1")
+        self.assertEqual(get_state_as_dict(recent_color_selector)["CurrColorPos"], "0")
+        self.assertEqual(get_state_as_dict(recent_color_selector)["ColorText"], "Chart 2")
+        self.assertEqual(get_state_as_dict(recent_color_selector)["RGB"], xrgb)
+
+        xOk = xDialog.getChild("ok")
+        self.ui_test.close_dialog_through_button(xOk)
+
+        self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
\ No newline at end of file
diff --git a/svx/source/tbxctrls/SvxColorValueSet.cxx b/svx/source/tbxctrls/SvxColorValueSet.cxx
index c9423cb84e5f..e349083e34aa 100644
--- a/svx/source/tbxctrls/SvxColorValueSet.cxx
+++ b/svx/source/tbxctrls/SvxColorValueSet.cxx
@@ -23,12 +23,19 @@
 #include <vcl/settings.hxx>
 #include <osl/diagnose.h>
 
+#include <svx/uiobject.hxx>
+
 SvxColorValueSet::SvxColorValueSet(std::unique_ptr<weld::ScrolledWindow> pWindow)
     : ValueSet(std::move(pWindow))
 {
     SetEdgeBlending(true);
 }
 
+FactoryFunction SvxColorValueSet::GetUITestFactory() const
+{
+    return SvxColorValueSetUIObject::create;
+}
+
 sal_uInt32 SvxColorValueSet::getMaxRowCount()
 {
     return StyleSettings::GetColorValueSetMaximumRowCount();
diff --git a/svx/source/uitest/sdrobject.cxx b/svx/source/uitest/sdrobject.cxx
index 3ceb01591e8e..b93223acc319 100644
--- a/svx/source/uitest/sdrobject.cxx
+++ b/svx/source/uitest/sdrobject.cxx
@@ -13,6 +13,10 @@
 
 #include <tools/fract.hxx>
 
+#include <memory>
+#include <svx/SvxColorValueSet.hxx>
+#include <vcl/layout.hxx>
+
 SdrUIObject::~SdrUIObject()
 {
 }
@@ -161,4 +165,56 @@ OUString SdrUIObject::get_type() const
     return "SdrUIObject";
 }
 
+
+SvxColorValueSetUIObject::SvxColorValueSetUIObject(vcl::Window*  xColorSetWin, SvxColorValueSet* pColorSet):
+    WindowUIObject(xColorSetWin),
+    mpColorSet(pColorSet)
+{
+}
+
+void SvxColorValueSetUIObject::execute(const OUString& rAction,
+        const StringMap& rParameters)
+{
+    if (rAction == "CHOOSE")
+    {
+        if (rParameters.find("POS") != rParameters.end())
+        {
+            OUString aIndexStr = rParameters.find("POS")->second;
+            sal_Int32 nIndex = aIndexStr.toInt32();
+            mpColorSet->SelectItem(nIndex);
+            mpColorSet->Select();
+        }
+    }
+    else
+       WindowUIObject::execute(rAction, rParameters);
+}
+
+std::unique_ptr<UIObject> SvxColorValueSetUIObject::create(vcl::Window* pWindow)
+{
+    VclDrawingArea* pColorSetWin = dynamic_cast<VclDrawingArea*>(pWindow);
+    assert(pColorSetWin);
+    return std::unique_ptr<UIObject>(new SvxColorValueSetUIObject(pColorSetWin, static_cast<SvxColorValueSet*>(pColorSetWin->GetUserData())));
+}
+
+OUString SvxColorValueSetUIObject::get_name() const
+{
+    return "SvxColorValueSetUIObject";
+}
+
+StringMap SvxColorValueSetUIObject::get_state()
+{
+    StringMap aMap = WindowUIObject::get_state();
+    aMap["CurrColorId"] = OUString::number( mpColorSet->GetSelectedItemId() );
+    aMap["CurrColorPos"] = OUString::number( mpColorSet->GetSelectItemPos() );
+    aMap["ColorsCount"] = OUString::number(mpColorSet->GetItemCount());
+    aMap["ColCount"] = OUString::number(mpColorSet->GetColCount());
+    aMap["ColorText"] = mpColorSet->GetItemText(mpColorSet->GetSelectedItemId());
+    Color currColor = mpColorSet->GetItemColor(mpColorSet->GetSelectedItemId());
+    aMap["R"] = OUString::number(currColor.GetRed());
+    aMap["G"] = OUString::number(currColor.GetGreen());
+    aMap["B"] = OUString::number(currColor.GetBlue());
+    aMap["RGB"] = "("+OUString::number(currColor.GetRed())+","+OUString::number(currColor.GetGreen())+","+OUString::number(currColor.GetBlue())+")";
+    return aMap;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index 5fb0a5c0174e..13ced0da3102 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -1107,6 +1107,12 @@ void ComboBoxUIObject::execute(const OUString& rAction,
             sal_Int32 nPos = aVal.toInt32();
             mxComboBox->SelectEntryPos(nPos);
         }
+        else if(rParameters.find("TEXT") != rParameters.end()){
+            auto itr = rParameters.find("TEXT");
+            OUString aVal = itr->second;
+            sal_Int32 nPos = mxComboBox->GetEntryPos(aVal);
+            mxComboBox->SelectEntryPos(nPos);
+        }
         mxComboBox->Select();
     }
     else if (rAction == "TYPE")
@@ -1127,7 +1133,6 @@ void ComboBoxUIObject::execute(const OUString& rAction,
 StringMap ComboBoxUIObject::get_state()
 {
     StringMap aMap = WindowUIObject::get_state();
-
     return aMap;
 }
 


More information about the Libreoffice-commits mailing list