summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-05-11 01:42:39 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-06-17 21:10:05 +0200
commit2bcf4407ebcd9b24feee5dd3dbd03df14389a539 (patch)
tree1e39c1ad18c63f5f3e9064a0cf68ed930b5fb1d3
parentuitest: add the ui demo tests (diff)
downloadcore-2bcf4407ebcd9b24feee5dd3dbd03df14389a539.tar.gz
core-2bcf4407ebcd9b24feee5dd3dbd03df14389a539.zip
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.hxx9
-rw-r--r--offapi/com/sun/star/ui/test/XUIObject.idl2
-rw-r--r--vcl/source/uitest/uiobject.cxx37
-rw-r--r--vcl/source/uitest/uno/uiobject_uno.cxx20
-rw-r--r--vcl/source/uitest/uno/uiobject_uno.hxx3
5 files changed, 71 insertions, 0 deletions
diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx
index f4c6ddba54bd..4ea2897908b9 100644
--- a/include/vcl/uitest/uiobject.hxx
+++ b/include/vcl/uitest/uiobject.hxx
@@ -14,6 +14,8 @@
#include <vcl/window.hxx>
#include <vcl/dllapi.h>
+#include <set>
+
typedef std::map<const OUString, OUString> StringMap;
/**
@@ -55,6 +57,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.
@@ -98,6 +105,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 e7378c61805e..bc6c26b87a52 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;