diff options
Diffstat (limited to 'include/vcl/uitest')
-rw-r--r-- | include/vcl/uitest/eventdescription.hxx | 24 | ||||
-rw-r--r-- | include/vcl/uitest/factory.hxx | 27 | ||||
-rw-r--r-- | include/vcl/uitest/formattedfielduiobject.hxx | 37 | ||||
-rw-r--r-- | include/vcl/uitest/logger.hxx | 68 | ||||
-rw-r--r-- | include/vcl/uitest/metricfielduiobject.hxx | 37 | ||||
-rw-r--r-- | include/vcl/uitest/uiobject.hxx | 589 | ||||
-rw-r--r-- | include/vcl/uitest/uitest.hxx | 40 |
7 files changed, 822 insertions, 0 deletions
diff --git a/include/vcl/uitest/eventdescription.hxx b/include/vcl/uitest/eventdescription.hxx new file mode 100644 index 000000000..47bf9e117 --- /dev/null +++ b/include/vcl/uitest/eventdescription.hxx @@ -0,0 +1,24 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_UITEST_EVENTDESCRIPTION_HXX +#define INCLUDED_VCL_UITEST_EVENTDESCRIPTION_HXX + +#include <rtl/ustring.hxx> +#include <map> + +struct EventDescription +{ + OUString aKeyWord, aAction, aID, aParent; + std::map<OUString, OUString> aParameters; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/uitest/factory.hxx b/include/vcl/uitest/factory.hxx new file mode 100644 index 000000000..e51427876 --- /dev/null +++ b/include/vcl/uitest/factory.hxx @@ -0,0 +1,27 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_UITEST_FACTORY_HXX +#define INCLUDED_VCL_UITEST_FACTORY_HXX + +#include <memory> +#include <functional> + +namespace vcl +{ +class Window; +} + +class UIObject; + +typedef std::function<std::unique_ptr<UIObject>(vcl::Window*)> FactoryFunction; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/uitest/formattedfielduiobject.hxx b/include/vcl/uitest/formattedfielduiobject.hxx new file mode 100644 index 000000000..0bbc95c75 --- /dev/null +++ b/include/vcl/uitest/formattedfielduiobject.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/. + */ + +#ifndef INCLUDED_VCL_UITEST_FORMATTEDFIELDUIOBJECT_HXX +#define INCLUDED_VCL_UITEST_FORMATTEDFIELDUIOBJECT_HXX + +#include <vcl/uitest/uiobject.hxx> + +class FormattedField; + +class FormattedFieldUIObject final : public SpinFieldUIObject +{ + VclPtr<FormattedField> mxFormattedField; + +public: + FormattedFieldUIObject(const VclPtr<FormattedField>& xEdit); + virtual ~FormattedFieldUIObject() override; + + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + virtual OUString get_name() const override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/uitest/logger.hxx b/include/vcl/uitest/logger.hxx new file mode 100644 index 000000000..c810b7eb7 --- /dev/null +++ b/include/vcl/uitest/logger.hxx @@ -0,0 +1,68 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_UITEST_LOGGER_HXX +#define INCLUDED_VCL_UITEST_LOGGER_HXX + +#include <sal/config.h> + +#include <string_view> + +#include <vcl/dllapi.h> + +#include <tools/stream.hxx> +#include <vcl/vclevent.hxx> + +namespace com::sun::star::beans +{ +struct PropertyValue; +} +namespace com::sun::star::uno +{ +template <class E> class Sequence; +} +struct EventDescription; +class Control; +class KeyEvent; + +class UITEST_DLLPUBLIC UITestLogger +{ +private: + SvFileStream maStream; + + bool mbValid; + + OUString app_name; + +public: + UITestLogger(); + + void logCommand(std::u16string_view rAction, + const css::uno::Sequence<css::beans::PropertyValue>& rArgs); + + void logAction(VclPtr<Control> const& xUIElement, VclEventId nEvent); + + void logAction(vcl::Window* const& xUIWin, VclEventId nEvent); + + void log(std::u16string_view rString); + + void logKeyInput(VclPtr<vcl::Window> const& xUIElement, const KeyEvent& rEvent); + + void logEvent(const EventDescription& rDescription); + + static UITestLogger& getInstance(); + + void setAppName(OUString name) { app_name = name; } + + const OUString& getAppName() const { return app_name; } +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/uitest/metricfielduiobject.hxx b/include/vcl/uitest/metricfielduiobject.hxx new file mode 100644 index 000000000..f45da7723 --- /dev/null +++ b/include/vcl/uitest/metricfielduiobject.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/. + */ + +#ifndef INCLUDED_VCL_UITEST_METRICFIELDUIOBJECT_HXX +#define INCLUDED_VCL_UITEST_METRICFIELDUIOBJECT_HXX + +#include <vcl/uitest/uiobject.hxx> + +class MetricField; + +class MetricFieldUIObject final : public SpinFieldUIObject +{ + VclPtr<MetricField> mxMetricField; + +public: + MetricFieldUIObject(const VclPtr<MetricField>& xEdit); + virtual ~MetricFieldUIObject() override; + + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + virtual OUString get_name() const override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx new file mode 100644 index 000000000..c9a932ec6 --- /dev/null +++ b/include/vcl/uitest/uiobject.hxx @@ -0,0 +1,589 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_UITEST_UIOBJECT_HXX +#define INCLUDED_VCL_UITEST_UIOBJECT_HXX + +#include <rtl/ustring.hxx> +#include <map> +#include <memory> + +#include <vcl/vclevent.hxx> +#include <vcl/vclptr.hxx> +#include <vcl/dllapi.h> +#include <vcl/window.hxx> + +#include <set> + +class Button; +class CheckBox; +class ComboBox; +class Dialog; +class Edit; +class IconView; +class ListBox; +class RadioButton; +class TabControl; +class TabPage; +class SvTreeListBox; +class SvTreeListEntry; +class SpinButton; +class SpinField; +class VerticalTabControl; +class VclExpander; +class VclDrawingArea; +class VclMultiLineEdit; +class MenuButton; +class ToolBox; +namespace vcl { class Window; } +namespace weld { class CustomWidgetController; } + +typedef std::map<OUString, OUString> StringMap; + +/** + * This class wraps a UI object like vcl::Window and provides + * an interface for the UI testing. + * + * This class should only have virtual methods. + */ +class UITEST_DLLPUBLIC UIObject +{ + UIObject(UIObject const &) = delete; + UIObject& operator =(UIObject const &) = delete; + +public: + UIObject() = default; + + virtual ~UIObject(); + + /** + * Returns the state of the wrapped UI object as a + * string key value map. + */ + virtual StringMap get_state(); + + /** + * Executes an action on the wrapped UI object, + * possibly with some additional parameters + */ + virtual void execute(const OUString& rAction, + const StringMap& rParameters); + + /** + * Returns the type of the UIObject. Additional information might + * be available through UIObject::get_state(). + */ + virtual OUString get_type() const; + + /** + * Returns the child of the current UIObject with the corresponding id. + * If no object with that id is being found returns a nullptr. + * + */ + virtual std::unique_ptr<UIObject> get_child(const OUString& rID); + + /** + * Returns a set containing all descendants 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. + * + */ + virtual OUString dumpState() const; + + /** + * Currently an internal method to dump the parent-child relationship starting from the current top focus window. + * + * This method should not be exposed to the outside world. + * + */ + 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 +{ + VclPtr<vcl::Window> mxWindow; + +public: + + WindowUIObject(const VclPtr<vcl::Window>& xWindow); + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual OUString get_type() const override; + + virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; + + std::unique_ptr<UIObject> get_visible_child(const OUString& rID); + + virtual std::set<OUString> get_children() const override; + + virtual OUString dumpState() const override; + + virtual OUString dumpHierarchy() const override; + + virtual OUString get_action(VclEventId nEvent) const override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +protected: + + virtual OUString get_name() const; + +}; + +// TODO: moggi: what about push buttons? +class ButtonUIObject final : public WindowUIObject +{ + VclPtr<Button> mxButton; +public: + + ButtonUIObject(const VclPtr<Button>& xButton); + virtual ~ButtonUIObject() override; + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class DialogUIObject final : public WindowUIObject +{ + VclPtr<Dialog> mxDialog; + +public: + + DialogUIObject(const VclPtr<Dialog>& xDialog); + virtual ~DialogUIObject() override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + +class EditUIObject : public WindowUIObject +{ + VclPtr<Edit> mxEdit; + +public: + + EditUIObject(const VclPtr<Edit>& xEdit); + virtual ~EditUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +protected: + + virtual OUString get_name() const override; +}; + +class MultiLineEditUIObject final : public WindowUIObject +{ + VclPtr<VclMultiLineEdit> mxEdit; + +public: + + MultiLineEditUIObject(const VclPtr<VclMultiLineEdit>& xEdit); + virtual ~MultiLineEditUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + +class ExpanderUIObject : public WindowUIObject +{ + VclPtr<VclExpander> mxExpander; + +public: + + ExpanderUIObject(const VclPtr<VclExpander>& xExpander); + virtual ~ExpanderUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); +private: + + virtual OUString get_name() const override; +}; + + +// TODO: moggi: maybe let it inherit from the button case +class CheckBoxUIObject final : public WindowUIObject +{ +private: + VclPtr<CheckBox> mxCheckBox; + +public: + CheckBoxUIObject(const VclPtr<CheckBox>& xCheckbox); + virtual ~CheckBoxUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class RadioButtonUIObject final : public WindowUIObject +{ +private: + VclPtr<RadioButton> mxRadioButton; + +public: + RadioButtonUIObject(const VclPtr<RadioButton>& xCheckbox); + virtual ~RadioButtonUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class TabPageUIObject final : public WindowUIObject +{ +private: + VclPtr<TabPage> mxTabPage; +public: + TabPageUIObject(const VclPtr<TabPage>& xTabPage); + virtual ~TabPageUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + +class ListBoxUIObject final : public WindowUIObject +{ +private: + VclPtr<ListBox> mxListBox; + +public: + + ListBoxUIObject(const VclPtr<ListBox>& xListBox); + virtual ~ListBoxUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +// TODO: moggi: should it inherit from EditUIObject? +class ComboBoxUIObject final : public WindowUIObject +{ +private: + VclPtr<ComboBox> mxComboBox; + +public: + + ComboBoxUIObject(const VclPtr<ComboBox>& xListBox); + virtual ~ComboBoxUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class SpinUIObject final : public WindowUIObject +{ +private: + VclPtr<SpinButton> mxSpinButton; + +public: + + SpinUIObject(const VclPtr<SpinButton>& xSpinButton); + virtual ~SpinUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class SpinFieldUIObject : public EditUIObject +{ + VclPtr<SpinField> mxSpinField; + +public: + + SpinFieldUIObject(const VclPtr<SpinField>& xEdit); + virtual ~SpinFieldUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class TabControlUIObject final : public WindowUIObject +{ +private: + VclPtr<TabControl> mxTabControl; + +public: + + TabControlUIObject(const VclPtr<TabControl>& mxTabControl); + virtual ~TabControlUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class VerticalTabControlUIObject final : public WindowUIObject +{ +private: + VclPtr<VerticalTabControl> mxTabControl; + +public: + + VerticalTabControlUIObject(const VclPtr<VerticalTabControl>& mxTabControl); + virtual ~VerticalTabControlUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + +class TreeListUIObject : public WindowUIObject +{ +public: + TreeListUIObject(const VclPtr<SvTreeListBox>& xTreeList); + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; + + virtual std::set<OUString> get_children() const override; + +protected: + + virtual OUString get_name() const override; + + VclPtr<SvTreeListBox> mxTreeList; +}; + +class TreeListEntryUIObject final : public UIObject +{ +public: + + TreeListEntryUIObject(const VclPtr<SvTreeListBox>& xTreeList, SvTreeListEntry* pEntry); + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; + + virtual std::set<OUString> get_children() const override; + + virtual OUString get_type() const override; + +private: + + VclPtr<SvTreeListBox> mxTreeList; + + SvTreeListEntry* const mpEntry; +}; + +class IconViewUIObject final : public TreeListUIObject +{ +public: + IconViewUIObject(const VclPtr<SvTreeListBox>& xIconView); + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + +class ToolBoxUIObject final : public WindowUIObject +{ +private: + VclPtr<ToolBox> mxToolBox; + +public: + + ToolBoxUIObject(const VclPtr<ToolBox>& mxToolBox); + virtual ~ToolBoxUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + + virtual OUString get_action(VclEventId nEvent) const override; + +private: + + virtual OUString get_name() const override; +}; + +class MenuButtonUIObject final : public WindowUIObject +{ + VclPtr<MenuButton> mxMenuButton; + +public: + + MenuButtonUIObject(const VclPtr<MenuButton>& xMenuButton); + virtual ~MenuButtonUIObject() override; + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + +class UITEST_DLLPUBLIC DrawingAreaUIObject : public WindowUIObject +{ +private: + VclPtr<VclDrawingArea> mxDrawingArea; +protected: + weld::CustomWidgetController* mpController; +public: + DrawingAreaUIObject(const VclPtr<vcl::Window>& rDrawingArea); + virtual ~DrawingAreaUIObject() override; + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/uitest/uitest.hxx b/include/vcl/uitest/uitest.hxx new file mode 100644 index 000000000..53bdded59 --- /dev/null +++ b/include/vcl/uitest/uitest.hxx @@ -0,0 +1,40 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_VCL_UITEST_UITEST_HXX +#define INCLUDED_VCL_UITEST_UITEST_HXX + +#include <rtl/ustring.hxx> + +#include <memory> + +namespace com::sun::star::beans { struct PropertyValue; } +namespace com::sun::star::uno { template <typename > class Sequence; } + +class UIObject; + +class UITest +{ +public: + + static bool executeCommand(const OUString& rCommand); + + static bool executeCommandWithParameters(const OUString& rCommand, + const css::uno::Sequence< css::beans::PropertyValue >& rArgs); + + static bool executeDialog(const OUString& rCommand); + + static std::unique_ptr<UIObject> getFocusTopWindow(); + + static std::unique_ptr<UIObject> getFloatWindow(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |