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

Ahmed ElShreif (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 14 13:29:25 UTC 2020


 include/vcl/toolbox.hxx                        |    4 +
 include/vcl/uitest/uiobject.hxx                |   23 +++++++++++
 svx/source/tbxctrls/tbunosearchcontrollers.cxx |    1 
 vcl/source/uitest/uiobject.cxx                 |   52 +++++++++++++++++++++++++
 vcl/source/window/toolbox2.cxx                 |    7 +++
 5 files changed, 87 insertions(+)

New commits:
commit d17227830438f7a7e0d5de82b5a447771dfe8f25
Author:     Ahmed ElShreif <aelshreif7 at gmail.com>
AuthorDate: Fri Jul 10 23:45:51 2020 +0200
Commit:     Ahmed ElShreif <aelshreif7 at gmail.com>
CommitDate: Tue Jul 14 15:28:47 2020 +0200

    uitest : Add support for "ToolBox" Objects for example" "bottom find bar"
    
    This patch will help us in testing any ToolBox Objects by this lines :
    
            >> variable_name = MainWindow.getChild(Bar_name)
            >> variable_name.executeAction("CLICK", mkPropertyValues({"POS": poition_x }))
    
    for position_x you just put the id of which entry in the ToolBox do you want to press on it .
    
    Also This patch set the ID of the bottom find bar to be "FindBar" to be able to select it in UITests .
    
    Change-Id: I360cdbde47be188c49c6d61bf5df4df5caa6a23e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98549
    Tested-by: Jenkins
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx
index 6987f777b00a..8383662129f8 100644
--- a/include/vcl/toolbox.hxx
+++ b/include/vcl/toolbox.hxx
@@ -78,6 +78,10 @@ class VCL_DLLPUBLIC ToolBox : public DockingWindow
 public:
     using ImplToolItems = std::vector<ImplToolItem>;
 
+    virtual FactoryFunction GetUITestFactory() const override;
+
+    void SetCurItemId( sal_uInt16 CurID )   { mnCurItemId=CurID; }
+
     static constexpr auto APPEND
         = std::numeric_limits<ImplToolItems::size_type>::max();
 
diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx
index 15686e406904..36dd5488ce7a 100644
--- a/include/vcl/uitest/uiobject.hxx
+++ b/include/vcl/uitest/uiobject.hxx
@@ -34,6 +34,7 @@ class SpinButton;
 class SpinField;
 class VerticalTabControl;
 class VclMultiLineEdit;
+class ToolBox;
 
 typedef std::map<const OUString, OUString> StringMap;
 
@@ -480,6 +481,28 @@ private:
     SvTreeListEntry* const mpEntry;
 };
 
+class ToolBoxUIObject final : public WindowUIObject
+{
+private:
+    VclPtr<ToolBox> mxToolBox;
+
+public:
+
+    ToolBoxUIObject(const VclPtr<ToolBox>& mxToolBox);
+    virtual ~ToolBoxUIObject() override;
+
+    virtual void execute(const OUString& rAction,
+            const StringMap& rParameters) override;
+
+    virtual StringMap get_state() override;
+
+    static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
+
+private:
+
+    virtual OUString get_name() const override;
+};
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
index 4305e95d1c9f..730acf5dece1 100644
--- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx
+++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx
@@ -1544,6 +1544,7 @@ void SAL_CALL FindbarDispatcher::dispatch( const css::util::URL& aURL, const css
     css::uno::Reference< css::awt::XWindow > xWindow(xUIElement->getRealInterface(), css::uno::UNO_QUERY);
     VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
     ToolBox* pToolBox = static_cast<ToolBox*>(pWindow.get());
+    pToolBox->set_id("FindBar");
     if ( pToolBox )
     {
         ToolBox::ImplToolItems::size_type nItemCount = pToolBox->GetItemCount();
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index 477f1ff06af9..9e58f594b158 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -30,6 +30,7 @@
 #include <vcl/uitest/logger.hxx>
 #include <uiobject-internal.hxx>
 #include <verticaltabctrl.hxx>
+#include <vcl/toolbox.hxx>
 
 #include <comphelper/string.hxx>
 #include <comphelper/lok.hxx>
@@ -1561,4 +1562,55 @@ std::unique_ptr<UIObject> VerticalTabControlUIObject::create(vcl::Window* pWindo
     return std::unique_ptr<UIObject>(new VerticalTabControlUIObject(pTabControl));
 }
 
+
+ToolBoxUIObject::ToolBoxUIObject(const VclPtr<ToolBox>& xToolBox):
+    WindowUIObject(xToolBox),
+    mxToolBox(xToolBox)
+{
+}
+
+ToolBoxUIObject::~ToolBoxUIObject()
+{
+}
+
+void ToolBoxUIObject::execute(const OUString& rAction,
+        const StringMap& rParameters)
+{
+    if (rAction == "CLICK")
+    {
+        if (rParameters.find("POS") != rParameters.end())
+        {
+            auto itr = rParameters.find("POS");
+            sal_uInt16 nPos = itr->second.toUInt32();
+            mxToolBox->SetCurItemId(nPos);
+            mxToolBox->Click();
+            mxToolBox->Select();
+        }
+    }
+    else
+        WindowUIObject::execute(rAction, rParameters);
+}
+
+StringMap ToolBoxUIObject::get_state()
+{
+    StringMap aMap = WindowUIObject::get_state();
+    aMap["CurrSelectedItemID"] = OUString::number(mxToolBox->GetCurItemId());
+    aMap["CurrSelectedItemText"] = mxToolBox->GetItemText(mxToolBox->GetCurItemId());
+    aMap["CurrSelectedItemCommand"] = mxToolBox->GetItemCommand(mxToolBox->GetCurItemId());
+    aMap["ItemCount"] = OUString::number(mxToolBox->GetItemCount());
+    return aMap;
+}
+
+OUString ToolBoxUIObject::get_name() const
+{
+    return "ToolBoxUIObject";
+}
+
+std::unique_ptr<UIObject> ToolBoxUIObject::create(vcl::Window* pWindow)
+{
+    ToolBox* pToolBox = dynamic_cast<ToolBox*>(pWindow);
+    assert(pToolBox);
+    return std::unique_ptr<UIObject>(new ToolBoxUIObject(pToolBox));
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx
index 6ee94e7b0ae5..b15e97f14dcf 100644
--- a/vcl/source/window/toolbox2.cxx
+++ b/vcl/source/window/toolbox2.cxx
@@ -41,6 +41,8 @@
 #include <unotools/confignode.hxx>
 #include <tools/json_writer.hxx>
 
+#include <vcl/uitest/uiobject.hxx>
+
 using namespace vcl;
 
 #define TB_SEP_SIZE     8  // Separator size
@@ -350,6 +352,11 @@ void ToolBox::Highlight()
     CallEventListeners( VclEventId::ToolboxHighlight );
 }
 
+FactoryFunction ToolBox::GetUITestFactory() const
+{
+    return ToolBoxUIObject::create;
+}
+
 void ToolBox::Select()
 {
     VclPtr<vcl::Window> xWindow = this;


More information about the Libreoffice-commits mailing list