[Libreoffice-commits] core.git: include/svx sd/source svx/Library_svxcore.mk svx/source

Markus Mohrhard markus.mohrhard at googlemail.com
Sat Oct 1 14:41:06 UTC 2016


 include/svx/uiobject.hxx         |   37 ++++++++++++
 sd/source/ui/inc/uiobject.hxx    |    6 -
 sd/source/ui/uitest/uiobject.cxx |  120 ++++++++++++++++++++++++---------------
 svx/Library_svxcore.mk           |    1 
 svx/source/uitest/sdrobject.cxx  |  113 ++++++++++++++++++++++++++++++++++++
 5 files changed, 229 insertions(+), 48 deletions(-)

New commits:
commit 786971a13adba78072c0ec03101c6c63d76a432f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date:   Fri Sep 30 21:25:37 2016 +0200

    add initial drawinglayer support to UI testing framework
    
    Change-Id: Id0450cdf655accb6bd1a50871e83d5c8ecdaab5f
    Reviewed-on: https://gerrit.libreoffice.org/29417
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/include/svx/uiobject.hxx b/include/svx/uiobject.hxx
new file mode 100644
index 0000000..ef03a3b
--- /dev/null
+++ b/include/svx/uiobject.hxx
@@ -0,0 +1,37 @@
+/* -*- 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_SVX_UIOBJECT_HXX
+#define INCLUDED_SVX_UIOBJECT_HXX
+
+#include <svx/svxdllapi.h>
+
+#include <vcl/uitest/uiobject.hxx>
+
+class SdrObject;
+
+class SVX_DLLPUBLIC SdrUIObject : public UIObject
+{
+public:
+
+    virtual ~SdrUIObject() override;
+
+    virtual StringMap get_state() override;
+
+    virtual void execute(const OUString& rAction,
+            const StringMap& rParameters) override;
+
+    virtual OUString get_type() const override;
+
+    virtual SdrObject* get_object() = 0;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/uiobject.hxx b/sd/source/ui/inc/uiobject.hxx
index 8e3d479..66ca027 100644
--- a/sd/source/ui/inc/uiobject.hxx
+++ b/sd/source/ui/inc/uiobject.hxx
@@ -30,6 +30,8 @@ public:
     virtual void execute(const OUString& rAction,
             const StringMap& rParameters) override;
 
+    virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override;
+
     virtual std::set<OUString> get_children() const override;
 
     static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
@@ -42,10 +44,6 @@ private:
 
     VclPtr<sd::Window> mxWindow;
 
-    sd::DrawViewShell* getViewShell() const;
-
-    SdrObject* getObject(const OUString& rName);
-
     SdrPageView* getPageView();
 };
 
diff --git a/sd/source/ui/uitest/uiobject.cxx b/sd/source/ui/uitest/uiobject.cxx
index c4be758..b665abc 100644
--- a/sd/source/ui/uitest/uiobject.cxx
+++ b/sd/source/ui/uitest/uiobject.cxx
@@ -13,6 +13,71 @@
 #include "DrawViewShell.hxx"
 #include "sdpage.hxx"
 
+#include <svx/uiobject.hxx>
+
+class ImpressSdrObject : public SdrUIObject
+{
+public:
+    ImpressSdrObject(VclPtr<sd::Window> xImpressWin, const OUString& rName);
+
+    SdrObject* get_object() override;
+
+private:
+    VclPtr<sd::Window> mxWindow;
+
+    OUString maName;
+};
+
+namespace {
+
+sd::DrawViewShell* getViewShell(VclPtr<sd::Window> xWindow)
+{
+    sd::DrawViewShell* pViewShell = dynamic_cast<sd::DrawViewShell*>(xWindow->GetViewShell());
+    assert(pViewShell);
+
+    return pViewShell;
+}
+
+OUString getObjectName(SdrObject* pObject)
+{
+    if (pObject->GetName().isEmpty())
+        return "Unnamed Drawinglayer object " + OUString::number(pObject->GetOrdNum());
+    else
+        return pObject->GetName();
+}
+
+SdrObject* getObject(VclPtr<sd::Window> xWindow, const OUString& rName)
+{
+    SdrPage* pPage = getViewShell(xWindow)->getCurrentPage();
+
+    if (!pPage)
+        return nullptr;
+
+    size_t nObjs = pPage->GetObjCount();
+    for (size_t i = 0; i < nObjs; ++i)
+    {
+        SdrObject* pObj = pPage->GetObj(i);
+        if (rName == getObjectName(pObj))
+            return pObj;
+    }
+
+    return nullptr;
+}
+
+
+}
+
+ImpressSdrObject::ImpressSdrObject(VclPtr<sd::Window> xImpressWin, const OUString& rName):
+    mxWindow(xImpressWin),
+    maName(rName)
+{
+}
+
+SdrObject* ImpressSdrObject::get_object()
+{
+    return getObject(mxWindow, maName);
+}
+
 ImpressWindowUIObject::ImpressWindowUIObject(VclPtr<sd::Window> xWindow):
     WindowUIObject(xWindow),
     mxWindow(xWindow)
@@ -23,8 +88,8 @@ StringMap ImpressWindowUIObject::get_state()
 {
     StringMap aMap = WindowUIObject::get_state();
 
-    aMap["SelectedText"] = getViewShell()->GetSelectionText(false);
-    aMap["CurrentSlide"] = OUString::number(getViewShell()->GetCurPageId());
+    aMap["SelectedText"] = getViewShell(mxWindow)->GetSelectionText(false);
+    aMap["CurrentSlide"] = OUString::number(getViewShell(mxWindow)->GetCurPageId());
 
     return aMap;
 }
@@ -39,7 +104,7 @@ void ImpressWindowUIObject::execute(const OUString& rAction,
             auto itr = rParameters.find("ZOOM");
             OUString aVal = itr->second;
             sal_Int32 nVal = aVal.toInt32();
-            getViewShell()->SetZoom(nVal);
+            getViewShell(mxWindow)->SetZoom(nVal);
         }
     }
     else if (rAction == "GOTO")
@@ -49,7 +114,7 @@ void ImpressWindowUIObject::execute(const OUString& rAction,
             auto itr = rParameters.find("PAGE");
             OUString aVal = itr->second;
             sal_Int32 nVal = aVal.toInt32();
-            getViewShell()->SwitchPage(nVal);
+            getViewShell(mxWindow)->SwitchPage(nVal);
         }
     }
     else if (rAction == "SELECT")
@@ -58,34 +123,27 @@ void ImpressWindowUIObject::execute(const OUString& rAction,
         {
             auto itr = rParameters.find("OBJECT");
             OUString aName = itr->second;
-            SdrObject* pObj = getObject(aName);
+            SdrObject* pObj = getObject(mxWindow, aName);
             SdrPageView* pPageView = getPageView();
-            getViewShell()->GetView()->MarkObj(pObj, pPageView);
+            getViewShell(mxWindow)->GetView()->MarkObj(pObj, pPageView);
         }
     }
     else if (rAction == "DESELECT")
     {
-        getViewShell()->GetView()->UnMarkAll();
+        getViewShell(mxWindow)->GetView()->UnMarkAll();
     }
     else
         WindowUIObject::execute(rAction, rParameters);
 }
 
-namespace {
-
-OUString getObjectName(SdrObject* pObject)
+std::unique_ptr<UIObject> ImpressWindowUIObject::get_child(const OUString& rID)
 {
-    if (pObject->GetName().isEmpty())
-        return "Unnamed Drawinglayer object " + OUString::number(pObject->GetOrdNum());
-    else
-        return pObject->GetName();
-}
-
+    return std::unique_ptr<UIObject>(new ImpressSdrObject(mxWindow, rID));
 }
 
 std::set<OUString> ImpressWindowUIObject::get_children() const
 {
-    SdrPage* pPage = getViewShell()->getCurrentPage();
+    SdrPage* pPage = getViewShell(mxWindow)->getCurrentPage();
 
     std::set<OUString> aRet;
     if (!pPage)
@@ -113,35 +171,9 @@ std::unique_ptr<UIObject> ImpressWindowUIObject::create(vcl::Window* pWindow)
     return std::unique_ptr<UIObject>(new ImpressWindowUIObject(pWin));
 }
 
-sd::DrawViewShell* ImpressWindowUIObject::getViewShell() const
-{
-    sd::DrawViewShell* pViewShell = dynamic_cast<sd::DrawViewShell*>(mxWindow->GetViewShell());
-    assert(pViewShell);
-
-    return pViewShell;
-}
-
-SdrObject* ImpressWindowUIObject::getObject(const OUString& rName)
-{
-    SdrPage* pPage = getViewShell()->getCurrentPage();
-
-    if (!pPage)
-        return nullptr;
-
-    size_t nObjs = pPage->GetObjCount();
-    for (size_t i = 0; i < nObjs; ++i)
-    {
-        SdrObject* pObj = pPage->GetObj(i);
-        if (rName == getObjectName(pObj))
-            return pObj;
-    }
-
-    return nullptr;
-}
-
 SdrPageView* ImpressWindowUIObject::getPageView()
 {
-    return getViewShell()->GetView()->GetSdrPageView();
+    return getViewShell(mxWindow)->GetView()->GetSdrPageView();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index a3fdf02..00ebc04 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -474,6 +474,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\
     svx/source/form/stringlistresource \
     svx/source/form/typemap \
     svx/source/form/xfm_addcondition \
+    svx/source/uitest/sdrobject \
 ))
 
 $(eval $(call gb_SdiTarget_SdiTarget,svx/sdi/svxslots,svx/sdi/svx))
diff --git a/svx/source/uitest/sdrobject.cxx b/svx/source/uitest/sdrobject.cxx
new file mode 100644
index 0000000..9142cfd
--- /dev/null
+++ b/svx/source/uitest/sdrobject.cxx
@@ -0,0 +1,113 @@
+/* -*- 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 <svx/uiobject.hxx>
+
+#include <svx/svdobj.hxx>
+
+#include <tools/fract.hxx>
+
+SdrUIObject::~SdrUIObject()
+{
+}
+
+StringMap SdrUIObject::get_state()
+{
+    StringMap aMap;
+    SdrObject* pObject = get_object();
+
+    if (!pObject)
+        return aMap;
+
+    aMap["Name"] = pObject->GetName();
+    aMap["Description"] = pObject->GetDescription();
+    aMap["Title"] = pObject->GetTitle();
+    aMap["Z-Order"] = OUString::number(pObject->GetOrdNum());
+    aMap["Layer"] = OUString::number(pObject->GetLayer());
+    aMap["IsGroupObject"] = OUString::boolean(pObject->IsGroupObject());
+    aMap["IsPolyObject"] = OUString::boolean(pObject->IsPolyObj());
+    aMap["PointCount"] = OUString::number(pObject->GetPointCount());
+    aMap["HasTextEdit"] = OUString::boolean(pObject->HasTextEdit());
+    aMap["HasMacro"] = OUString::boolean(pObject->HasMacro());
+    aMap["IsClosed"] = OUString::boolean(pObject->IsClosedObj());
+    aMap["IsEdgeObject"] = OUString::boolean(pObject->IsEdgeObj());
+    aMap["Is3DObject"] = OUString::boolean(pObject->Is3DObj());
+    aMap["IsUNOObject"] = OUString::boolean(pObject->IsUnoObj());
+    aMap["MoveProtected"] = OUString::boolean(pObject->IsMoveProtect());
+    aMap["ResizeProtected"] = OUString::boolean(pObject->IsResizeProtect());
+    aMap["Printable"] = OUString::boolean(pObject->IsPrintable());
+    aMap["Visible"] = OUString::boolean(pObject->IsVisible());
+    aMap["HasText"] = OUString::boolean(pObject->HasText());
+
+    return aMap;
+}
+
+void SdrUIObject::execute(const OUString& rAction,
+        const StringMap& rParameters)
+{
+    SdrObject* pObj = get_object();
+    if (!pObj)
+        return;
+
+    if (rAction == "MOVE")
+    {
+        auto itrNX = rParameters.find("X");
+        if (itrNX == rParameters.end())
+            throw css::uno::RuntimeException("missing parameter X");
+
+        auto itrNY = rParameters.find("Y");
+        if (itrNY == rParameters.end())
+            throw css::uno::RuntimeException("missing parameter Y");
+
+        long nX = itrNX->second.toInt32();
+        long nY = itrNY->second.toInt32();
+        Size aMoveRange(nX, nY);
+        pObj->Move(aMoveRange);
+    }
+    else if (rAction == "RESIZE")
+    {
+        Point aPos;
+        Fraction aFracX;
+        Fraction aFracY;
+        bool bRelative = true;
+        pObj->Resize(aPos, aFracX, aFracY, bRelative);
+    }
+    else if (rAction == "CROP")
+    {
+        Point aPos;
+        Fraction aFracX;
+        Fraction aFracY;
+        pObj->Crop(aPos, aFracX, aFracY);
+    }
+    else if (rAction == "Rotate")
+    {
+        Point aPos;
+        double nAngle = 0;
+        pObj->Rotate(aPos, nAngle, 0, 0);
+    }
+    else if (rAction == "Mirror")
+    {
+        Point aPos;
+        Point aPos2;
+        pObj->Mirror(aPos, aPos2);
+    }
+    else if (rAction == "SHEAR")
+    {
+        Point aPos;
+        double nAngle = 0;
+        pObj->Shear(aPos, nAngle, 0, false);
+    }
+}
+
+OUString SdrUIObject::get_type() const
+{
+    return OUString("SdrUIObject");
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list