Kaydet (Commit) 4c02332d authored tarafından Markus Mohrhard's avatar Markus Mohrhard

uitest: provide a way to get a json representation of the ui info

This just provides the information that is also available through the
getState method in a nicer way.

Change-Id: Ib64f6ecd2c4e9c0a940f3f9607c9a777233e90d2
Reviewed-on: https://gerrit.libreoffice.org/33978Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 90aac3a3
...@@ -83,7 +83,7 @@ public: ...@@ -83,7 +83,7 @@ public:
* This method should not be exposed to the outside world. * This method should not be exposed to the outside world.
* *
*/ */
virtual void dumpState() const; virtual OUString dumpState() const;
/** /**
* Currently an internal method to dump the parent-child relationship starting from the current top focus window. * Currently an internal method to dump the parent-child relationship starting from the current top focus window.
...@@ -91,7 +91,7 @@ public: ...@@ -91,7 +91,7 @@ public:
* This method should not be exposed to the outside world. * This method should not be exposed to the outside world.
* *
*/ */
virtual void dumpHierarchy() const; virtual OUString dumpHierarchy() const;
}; };
class UITEST_DLLPUBLIC WindowUIObject : public UIObject class UITEST_DLLPUBLIC WindowUIObject : public UIObject
...@@ -113,9 +113,9 @@ public: ...@@ -113,9 +113,9 @@ public:
virtual std::set<OUString> get_children() const override; virtual std::set<OUString> get_children() const override;
virtual void dumpState() const override; virtual OUString dumpState() const override;
virtual void dumpHierarchy() const override; virtual OUString dumpHierarchy() const override;
static std::unique_ptr<UIObject> create(vcl::Window* pWindow); static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
......
...@@ -25,6 +25,8 @@ interface XUIObject ...@@ -25,6 +25,8 @@ interface XUIObject
string getType(); string getType();
sequence<string> getChildren(); sequence<string> getChildren();
string getHierarchy();
}; };
}; }; }; }; }; }; }; }; }; };
......
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
#define DUMP_UITEST(x) SAL_INFO("vcl.uitest", x)
UIObject::~UIObject() UIObject::~UIObject()
{ {
} }
...@@ -61,12 +59,14 @@ std::set<OUString> UIObject::get_children() const ...@@ -61,12 +59,14 @@ std::set<OUString> UIObject::get_children() const
return std::set<OUString>(); return std::set<OUString>();
} }
void UIObject::dumpState() const OUString UIObject::dumpState() const
{ {
return OUString();
} }
void UIObject::dumpHierarchy() const OUString UIObject::dumpHierarchy() const
{ {
return OUString();
} }
namespace { namespace {
...@@ -425,34 +425,50 @@ OUString WindowUIObject::get_name() const ...@@ -425,34 +425,50 @@ OUString WindowUIObject::get_name() const
return OUString("WindowUIObject"); return OUString("WindowUIObject");
} }
void WindowUIObject::dumpState() const OUString WindowUIObject::dumpState() const
{ {
DUMP_UITEST(get_name() << " " << mxWindow->get_id()); OUStringBuffer aStateString = "{\"name\":\"" + mxWindow->get_id() + "\"";
DUMP_UITEST("Implementation Name: " << typeid(*mxWindow.get()).name()); aStateString.append(", \"ImplementationName\":\"").appendAscii(typeid(*mxWindow.get()).name()).append("\"");
StringMap aState = const_cast<WindowUIObject*>(this)->get_state(); StringMap aState = const_cast<WindowUIObject*>(this)->get_state();
for (auto itr = aState.begin(), itrEnd = aState.end(); itr != itrEnd; ++itr) for (auto itr = aState.begin(), itrEnd = aState.end(); itr != itrEnd; ++itr)
{ {
DUMP_UITEST("Property: " << itr->first << " with value: " << itr->second); OUString property = ",\"" + itr->first + "\":\"" + itr->second + "\"";
aStateString.append(property);
} }
size_t nCount = mxWindow->GetChildCount(); size_t nCount = mxWindow->GetChildCount();
if (nCount) if (nCount)
DUMP_UITEST("With " << nCount << " Children:"); aStateString.append(",\"children\":[");
for (size_t i = 0; i < nCount; ++i) for (size_t i = 0; i < nCount; ++i)
{ {
if (i != 0)
{
aStateString.append(",");
}
vcl::Window* pChild = mxWindow->GetChild(i); vcl::Window* pChild = mxWindow->GetChild(i);
std::unique_ptr<UIObject> pChildWrapper = std::unique_ptr<UIObject> pChildWrapper =
pChild->GetUITestFactory()(pChild); pChild->GetUITestFactory()(pChild);
pChildWrapper->dumpState(); OUString children = pChildWrapper->dumpState();
aStateString.append(children);
} }
if (nCount)
aStateString.append("]");
aStateString.append("}");
OUString aString = aStateString.makeStringAndClear();
return aString.replaceAll("\n", "\\n");
} }
void WindowUIObject::dumpHierarchy() const OUString WindowUIObject::dumpHierarchy() const
{ {
vcl::Window* pDialogParent = get_dialog_parent(mxWindow.get()); vcl::Window* pDialogParent = get_dialog_parent(mxWindow.get());
std::unique_ptr<UIObject> pParentWrapper = std::unique_ptr<UIObject> pParentWrapper =
pDialogParent->GetUITestFactory()(pDialogParent); pDialogParent->GetUITestFactory()(pDialogParent);
pParentWrapper->dumpState(); return pParentWrapper->dumpState();
} }
std::unique_ptr<UIObject> WindowUIObject::create(vcl::Window* pWindow) std::unique_ptr<UIObject> WindowUIObject::create(vcl::Window* pWindow)
......
...@@ -112,4 +112,13 @@ css::uno::Sequence<OUString> UIObjectUnoObj::getSupportedServiceNames() ...@@ -112,4 +112,13 @@ css::uno::Sequence<OUString> UIObjectUnoObj::getSupportedServiceNames()
return aServiceNames; return aServiceNames;
} }
OUString SAL_CALL UIObjectUnoObj::getHierarchy()
{
if (!mpObj)
throw css::uno::RuntimeException();
SolarMutexGuard aGuard;
return mpObj->dumpHierarchy();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -52,6 +52,8 @@ public: ...@@ -52,6 +52,8 @@ public:
sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
OUString SAL_CALL getHierarchy() override;
}; };
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment