[Libreoffice-commits] core.git: include/vcl vcl/Library_vcl.mk vcl/source
Markus Mohrhard
markus.mohrhard at googlemail.com
Mon Mar 20 01:48:42 UTC 2017
include/vcl/uitest/logger.hxx | 37 +++++++++++++++++++
include/vcl/uitest/uiobject.hxx | 7 +++
vcl/Library_vcl.mk | 1
vcl/source/uitest/logger.cxx | 76 ++++++++++++++++++++++++++++++++++++++++
vcl/source/uitest/uiobject.cxx | 30 +++++++++++++++
5 files changed, 151 insertions(+)
New commits:
commit 26ee34d1332e164cf938fcf78902df7d0cc3fe8f
Author: Markus Mohrhard <markus.mohrhard at googlemail.com>
Date: Mon Mar 20 00:45:28 2017 +0100
uitest: add logging for UI actions
The long term goal for this logging is that it generates content in a
DSL for the UI testing. The generated file can then be interpreted by
the UI testing and replay the interaction with the UI.
For now the plan is to have a readable output of what happens in the UI
layer that allows to quickly transform it to a UI test.
Change-Id: Ic536db766e41d03d048c920f6d551047af6fbb74
Reviewed-on: https://gerrit.libreoffice.org/35447
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/include/vcl/uitest/logger.hxx b/include/vcl/uitest/logger.hxx
new file mode 100644
index 000000000000..32625c7f60a7
--- /dev/null
+++ b/include/vcl/uitest/logger.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/.
+ */
+
+#include <vcl/dllapi.h>
+
+#include <tools/stream.hxx>
+#include <vcl/ctrl.hxx>
+
+class UITEST_DLLPUBLIC UITestLogger
+{
+private:
+
+ SvFileStream maStream;
+
+ bool mbValid;
+
+public:
+
+ UITestLogger();
+
+ void logCommand(const OUString& rAction);
+
+ void logAction(VclPtr<Control>& xUIElement, VclEventId nEvent);
+
+ void log(const OUString& rString);
+
+ static UITestLogger& getInstance();
+
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx
index c2de7d4652b1..4641b999722c 100644
--- a/include/vcl/uitest/uiobject.hxx
+++ b/include/vcl/uitest/uiobject.hxx
@@ -92,6 +92,11 @@ public:
*
*/
virtual OUString dumpHierarchy() const;
+
+ /**
+ * Gets the corresponding Action string for the event.
+ */
+ virtual OUString get_action(VclEventId nEvent) const;
};
class UITEST_DLLPUBLIC WindowUIObject : public UIObject
@@ -117,6 +122,8 @@ public:
virtual OUString dumpHierarchy() const override;
+ virtual OUString get_action(VclEventId nEvent) const override;
+
static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
protected:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index b7dad29a3f80..79efcbaa0817 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -393,6 +393,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
vcl/source/fontsubset/sft \
vcl/source/fontsubset/ttcr \
vcl/source/fontsubset/xlat \
+ vcl/source/uitest/logger \
vcl/source/uitest/uiobject \
vcl/source/uitest/uitest \
vcl/source/uitest/uno/uiobject_uno \
diff --git a/vcl/source/uitest/logger.cxx b/vcl/source/uitest/logger.cxx
new file mode 100644
index 000000000000..d24efeb5d0a8
--- /dev/null
+++ b/vcl/source/uitest/logger.cxx
@@ -0,0 +1,76 @@
+/* -*- 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 <config_folders.h>
+
+#include <vcl/uitest/logger.hxx>
+
+#include <rtl/bootstrap.hxx>
+#include <osl/file.hxx>
+#include <vcl/uitest/uiobject.hxx>
+
+#include <memory>
+
+UITestLogger::UITestLogger():
+ maStream(),
+ mbValid(false)
+{
+ static const char* pFile = std::getenv("LO_COLLECT_UIINFO");
+ if (pFile)
+ {
+ OUString aDirPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/uitest/");
+ rtl::Bootstrap::expandMacros(aDirPath);
+ osl::Directory::createPath(aDirPath);
+ OUString aFilePath = aDirPath + OUString::fromUtf8(pFile);
+
+ maStream.Open(aFilePath, StreamMode::READWRITE);
+ mbValid = true;
+ }
+}
+
+void UITestLogger::logCommand(const OUString& rAction)
+{
+ if (!mbValid)
+ return;
+
+ maStream.WriteLine(OUStringToOString(rAction, RTL_TEXTENCODING_UTF8));
+}
+
+void UITestLogger::logAction(VclPtr<Control>& xUIElement, VclEventId nEvent)
+{
+ if (!mbValid)
+ return;
+
+ if (xUIElement->get_id().isEmpty())
+ return;
+
+ std::unique_ptr<UIObject> pUIObject = xUIElement->GetUITestFactory()(xUIElement.get());
+ OUString aAction = pUIObject->get_action(nEvent);
+ if (!aAction.isEmpty())
+ maStream.WriteLine(OUStringToOString(aAction, RTL_TEXTENCODING_UTF8));
+}
+
+void UITestLogger::log(const OUString& rString)
+{
+ if (!mbValid)
+ return;
+
+ if (rString.isEmpty())
+ return;
+
+ maStream.WriteLine(OUStringToOString(rString, RTL_TEXTENCODING_UTF8));
+}
+
+UITestLogger& UITestLogger::getInstance()
+{
+ static UITestLogger aInstance;
+ return aInstance;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx
index fee55d88dc11..f89ba6d0238b 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -69,6 +69,11 @@ OUString UIObject::dumpHierarchy() const
return OUString();
}
+OUString UIObject::get_action(VclEventId /*nEvent*/) const
+{
+ return OUString();
+}
+
namespace {
bool isDialogWindow(vcl::Window* pWindow)
@@ -471,6 +476,31 @@ OUString WindowUIObject::dumpHierarchy() const
return pParentWrapper->dumpState();
}
+OUString WindowUIObject::get_action(VclEventId nEvent) const
+{
+
+ OUString aActionName;
+ switch (nEvent)
+ {
+ case VclEventId::ControlGetFocus:
+ case VclEventId::ControlLoseFocus:
+ return OUString();
+
+ case VclEventId::ButtonClick:
+ case VclEventId::CheckboxToggle:
+ aActionName = "CLICK";
+ break;
+
+ case VclEventId::EditModify:
+ aActionName = "TYPE";
+ break;
+ default:
+ aActionName = OUString::number(static_cast<int>(nEvent));
+ }
+
+ return "Action on element: " + mxWindow->get_id() + " with action : " + aActionName;
+}
+
std::unique_ptr<UIObject> WindowUIObject::create(vcl::Window* pWindow)
{
return std::unique_ptr<UIObject>(new WindowUIObject(pWindow));
More information about the Libreoffice-commits
mailing list