diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-05-11 01:42:39 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2016-06-18 17:02:16 +0200 |
commit | 0c5abdea5fe40350df6234e71b70cab1f11764ac (patch) | |
tree | 0e1fcdb3d1b0b9a1f9c70c5ad8de81e6c21f35ea | |
parent | 4ec1c63b91ac1f0c77f7ead33b4cbbd9d80a613b (diff) |
uitest: add method to get all children of a ui object
This makes writing ui tests so much easier.
Change-Id: Ice7d98c354fc9b68ee4532bc854561b5b9446e3f
-rw-r--r-- | include/vcl/uitest/uiobject.hxx | 9 | ||||
-rw-r--r-- | offapi/com/sun/star/ui/test/XUIObject.idl | 2 | ||||
-rw-r--r-- | vcl/source/uitest/uiobject.cxx | 37 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.cxx | 20 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.hxx | 3 |
5 files changed, 71 insertions, 0 deletions
diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx index b9a3f484b58f..f00d80fc4d0a 100644 --- a/include/vcl/uitest/uiobject.hxx +++ b/include/vcl/uitest/uiobject.hxx @@ -22,6 +22,8 @@ #include <vcl/dllapi.h> +#include <set> + typedef std::map<const OUString, OUString> StringMap; /** @@ -63,6 +65,11 @@ public: virtual std::unique_ptr<UIObject> get_child(const OUString& rID); /** + * Returns a set containing all decendants of the object. + */ + virtual std::set<OUString> get_children() const; + + /** * Currently an internal method to dump the state of the current UIObject as represented by get_state(). * * This method should not be exposed to the outside world. @@ -96,6 +103,8 @@ public: virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; + virtual std::set<OUString> get_children() const override; + virtual void dumpState() const override; virtual void dumpHierarchy() const override; diff --git a/offapi/com/sun/star/ui/test/XUIObject.idl b/offapi/com/sun/star/ui/test/XUIObject.idl index 9a0ca6b36fd0..9409490226ff 100644 --- a/offapi/com/sun/star/ui/test/XUIObject.idl +++ b/offapi/com/sun/star/ui/test/XUIObject.idl @@ -23,6 +23,8 @@ interface XUIObject com::sun::star::beans::PropertyValues getState(); string getType(); + + sequence<string> getChildren(); }; }; }; }; }; }; diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx index 285241502ae9..6b4c471cc51c 100644 --- a/vcl/source/uitest/uiobject.cxx +++ b/vcl/source/uitest/uiobject.cxx @@ -56,6 +56,11 @@ std::unique_ptr<UIObject> UIObject::get_child(const OUString&) return std::unique_ptr<UIObject>(); } +std::set<OUString> UIObject::get_children() const +{ + return std::set<OUString>(); +} + void UIObject::dumpState() const { } @@ -311,6 +316,29 @@ vcl::Window* findChild(vcl::Window* pParent, const OUString& rID) return nullptr; } +void addChildren(vcl::Window* pParent, std::set<OUString>& rChildren) +{ + if (!pParent) + return; + + size_t nCount = pParent->GetChildCount(); + for (size_t i = 0; i < nCount; ++i) + { + vcl::Window* pChild = pParent->GetChild(i); + if (pChild) + { + OUString aId = pChild->get_id(); + if (!aId.isEmpty()) + { + auto ret = rChildren.insert(aId); + SAL_WARN_IF(!ret.second, "vcl.uitest", "duplicate ids for ui elements. violates locally unique requirement"); + } + + addChildren(pChild, rChildren); + } + } +} + } std::unique_ptr<UIObject> WindowUIObject::get_child(const OUString& rID) @@ -322,6 +350,15 @@ std::unique_ptr<UIObject> WindowUIObject::get_child(const OUString& rID) return aFunction(pWindow); } +std::set<OUString> WindowUIObject::get_children() const +{ + vcl::Window* pDialogParent = get_dialog_parent(mxWindow.get()); + std::set<OUString> aChildren; + aChildren.insert(pDialogParent->get_id()); + addChildren(pDialogParent, aChildren); + return aChildren; +} + OUString WindowUIObject::get_name() const { return OUString("WindowUIObject"); diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx index 998a0d9a78b8..7c6ca8398b90 100644 --- a/vcl/source/uitest/uno/uiobject_uno.cxx +++ b/vcl/source/uitest/uno/uiobject_uno.cxx @@ -10,6 +10,8 @@ #include "uiobject_uno.hxx" #include <vcl/svapp.hxx> +#include <set> + UIObjectUnoObj::UIObjectUnoObj(std::unique_ptr<UIObject> pObj): UIObjectBase(m_aMutex), mpObj(std::move(pObj)) @@ -69,6 +71,24 @@ css::uno::Sequence<css::beans::PropertyValue> UIObjectUnoObj::getState() return aProps; } +css::uno::Sequence<OUString> UIObjectUnoObj::getChildren() + throw (css::uno::RuntimeException, std::exception) +{ + if (!mpObj) + throw css::uno::RuntimeException(); + + std::set<OUString> aChildren = mpObj->get_children(); + + css::uno::Sequence<OUString> aRet(aChildren.size()); + sal_Int32 i = 0; + for (auto itr = aChildren.begin(), itrEnd = aChildren.end(); itr != itrEnd; ++itr, ++i) + { + aRet[i] = *itr; + } + + return aRet; +} + OUString SAL_CALL UIObjectUnoObj::getType() throw (css::uno::RuntimeException, std::exception) { diff --git a/vcl/source/uitest/uno/uiobject_uno.hxx b/vcl/source/uitest/uno/uiobject_uno.hxx index d3519bfbaadc..fe0669a0c977 100644 --- a/vcl/source/uitest/uno/uiobject_uno.hxx +++ b/vcl/source/uitest/uno/uiobject_uno.hxx @@ -46,6 +46,9 @@ public: css::uno::Sequence<css::beans::PropertyValue> SAL_CALL getState() throw (css::uno::RuntimeException, std::exception) override; + css::uno::Sequence<OUString> SAL_CALL getChildren() + throw (css::uno::RuntimeException, std::exception) override; + OUString SAL_CALL getType() throw (css::uno::RuntimeException, std::exception) override; |