diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-02-06 18:09:12 +0100 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-02-07 10:16:25 +0000 |
commit | 4c02332d3d60de7a166d10413edf6e76b85d5a91 (patch) | |
tree | e0e36b529082c1a67ba7335d7a7aadcc70026baa /vcl/source/uitest | |
parent | 90aac3a3fd42ae6e3ac76ac4a0edb3a000cc0920 (diff) |
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/33978
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'vcl/source/uitest')
-rw-r--r-- | vcl/source/uitest/uiobject.cxx | 40 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.cxx | 9 | ||||
-rw-r--r-- | vcl/source/uitest/uno/uiobject_uno.hxx | 2 |
3 files changed, 39 insertions, 12 deletions
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx index d5b1d7082787..10c67b0ff071 100644 --- a/vcl/source/uitest/uiobject.cxx +++ b/vcl/source/uitest/uiobject.cxx @@ -26,8 +26,6 @@ #include <iostream> #include <vector> -#define DUMP_UITEST(x) SAL_INFO("vcl.uitest", x) - UIObject::~UIObject() { } @@ -61,12 +59,14 @@ std::set<OUString> UIObject::get_children() const 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 { @@ -425,34 +425,50 @@ OUString WindowUIObject::get_name() const return OUString("WindowUIObject"); } -void WindowUIObject::dumpState() const +OUString WindowUIObject::dumpState() const { - DUMP_UITEST(get_name() << " " << mxWindow->get_id()); - DUMP_UITEST("Implementation Name: " << typeid(*mxWindow.get()).name()); + OUStringBuffer aStateString = "{\"name\":\"" + mxWindow->get_id() + "\""; + aStateString.append(", \"ImplementationName\":\"").appendAscii(typeid(*mxWindow.get()).name()).append("\""); StringMap aState = const_cast<WindowUIObject*>(this)->get_state(); 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(); + if (nCount) - DUMP_UITEST("With " << nCount << " Children:"); + aStateString.append(",\"children\":["); for (size_t i = 0; i < nCount; ++i) { + if (i != 0) + { + aStateString.append(","); + } vcl::Window* pChild = mxWindow->GetChild(i); std::unique_ptr<UIObject> pChildWrapper = 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()); std::unique_ptr<UIObject> pParentWrapper = pDialogParent->GetUITestFactory()(pDialogParent); - pParentWrapper->dumpState(); + return pParentWrapper->dumpState(); } std::unique_ptr<UIObject> WindowUIObject::create(vcl::Window* pWindow) diff --git a/vcl/source/uitest/uno/uiobject_uno.cxx b/vcl/source/uitest/uno/uiobject_uno.cxx index 9907e7bc4ecc..c3db38a3a57e 100644 --- a/vcl/source/uitest/uno/uiobject_uno.cxx +++ b/vcl/source/uitest/uno/uiobject_uno.cxx @@ -112,4 +112,13 @@ css::uno::Sequence<OUString> UIObjectUnoObj::getSupportedServiceNames() 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: */ diff --git a/vcl/source/uitest/uno/uiobject_uno.hxx b/vcl/source/uitest/uno/uiobject_uno.hxx index 510c22c16631..b709cdc6a992 100644 --- a/vcl/source/uitest/uno/uiobject_uno.hxx +++ b/vcl/source/uitest/uno/uiobject_uno.hxx @@ -52,6 +52,8 @@ public: sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + OUString SAL_CALL getHierarchy() override; }; #endif |