Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / vcl / uitest / uiobject.hxx
blob2edec77ae109bf52d426874fb279a662168fa7f4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #ifndef INCLUDED_VCL_UITEST_UIOBJECT_HXX
11 #define INCLUDED_VCL_UITEST_UIOBJECT_HXX
13 #include <rtl/ustring.hxx>
14 #include <map>
15 #include <memory>
17 #include <vcl/window.hxx>
18 #include <vcl/spin.hxx>
19 #include <vcl/button.hxx>
20 #include <vcl/edit.hxx>
21 #include <vcl/tabpage.hxx>
22 #include <vcl/lstbox.hxx>
23 #include <vcl/combobox.hxx>
24 #include <vcl/spinfld.hxx>
25 #include <vcl/tabctrl.hxx>
27 #include <vcl/dllapi.h>
29 #include <set>
31 typedef std::map<const OUString, OUString> StringMap;
33 /**
34 * This class wraps a UI object like vcl::Window and provides
35 * an interface for the UI testing.
37 * This class should only have virtual methods.
39 class UITEST_DLLPUBLIC UIObject
41 UIObject(UIObject &) = delete;
42 void operator =(UIObject) = delete;
44 public:
45 UIObject() = default;
47 virtual ~UIObject();
49 /**
50 * Returns the state of the wrapped UI object as a
51 * string key value map.
53 virtual StringMap get_state();
55 /**
56 * Executes an action on the wrapped UI object,
57 * possibly with some additional parameters
59 virtual void execute(const OUString& rAction,
60 const StringMap& rParameters);
62 /**
63 * Returns the type of the UIObject. Additional information might
64 * be available through UIObject::get_state().
66 virtual OUString get_type() const;
68 /**
69 * Returns the child of the current UIObject with the corresponding id.
70 * If no object with that id is being found returns a nullptr.
73 virtual std::unique_ptr<UIObject> get_child(const OUString& rID);
75 /**
76 * Returns a set containing all descendants of the object.
78 virtual std::set<OUString> get_children() const;
80 /**
81 * Currently an internal method to dump the state of the current UIObject as represented by get_state().
83 * This method should not be exposed to the outside world.
86 virtual OUString dumpState() const;
88 /**
89 * Currently an internal method to dump the parent-child relationship starting from the current top focus window.
91 * This method should not be exposed to the outside world.
94 virtual OUString dumpHierarchy() const;
96 /**
97 * Gets the corresponding Action string for the event.
99 virtual OUString get_action(VclEventId nEvent) const;
102 class UITEST_DLLPUBLIC WindowUIObject : public UIObject
104 VclPtr<vcl::Window> mxWindow;
106 public:
108 WindowUIObject(VclPtr<vcl::Window> xWindow);
110 virtual StringMap get_state() override;
112 virtual void execute(const OUString& rAction,
113 const StringMap& rParameters) override;
115 virtual OUString get_type() const override;
117 virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override;
119 virtual std::set<OUString> get_children() const override;
121 virtual OUString dumpState() const override;
123 virtual OUString dumpHierarchy() const override;
125 virtual OUString get_action(VclEventId nEvent) const override;
127 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
129 protected:
131 virtual OUString get_name() const;
135 // TODO: moggi: what about push buttons?
136 class UITEST_DLLPUBLIC ButtonUIObject : public WindowUIObject
138 VclPtr<Button> mxButton;
139 public:
141 ButtonUIObject(VclPtr<Button> xButton);
142 virtual ~ButtonUIObject() override;
144 virtual StringMap get_state() override;
146 virtual void execute(const OUString& rAction,
147 const StringMap& rParameters) override;
149 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
151 protected:
153 virtual OUString get_name() const override;
156 class UITEST_DLLPUBLIC DialogUIObject : public WindowUIObject
158 VclPtr<Dialog> mxDialog;
160 public:
162 DialogUIObject(VclPtr<Dialog> xDialog);
163 virtual ~DialogUIObject() override;
165 virtual StringMap get_state() override;
167 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
169 protected:
171 virtual OUString get_name() const override;
174 class UITEST_DLLPUBLIC EditUIObject : public WindowUIObject
176 VclPtr<Edit> mxEdit;
178 public:
180 EditUIObject(VclPtr<Edit> xEdit);
181 virtual ~EditUIObject() override;
183 virtual void execute(const OUString& rAction,
184 const StringMap& rParameters) override;
186 virtual StringMap get_state() override;
188 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
190 protected:
192 virtual OUString get_name() const override;
195 // TODO: moggi: maybe let it inherit from the button case
196 class UITEST_DLLPUBLIC CheckBoxUIObject : public WindowUIObject
198 private:
199 VclPtr<CheckBox> mxCheckBox;
201 public:
202 CheckBoxUIObject(VclPtr<CheckBox> xCheckbox);
203 virtual ~CheckBoxUIObject() override;
205 virtual void execute(const OUString& rAction,
206 const StringMap& rParameters) override;
208 virtual StringMap get_state() override;
210 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
212 protected:
214 virtual OUString get_name() const override;
217 class UITEST_DLLPUBLIC RadioButtonUIObject : public WindowUIObject
219 private:
220 VclPtr<RadioButton> mxRadioButton;
222 public:
223 RadioButtonUIObject(VclPtr<RadioButton> xCheckbox);
224 virtual ~RadioButtonUIObject() override;
226 virtual void execute(const OUString& rAction,
227 const StringMap& rParameters) override;
229 virtual StringMap get_state() override;
231 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
233 protected:
235 virtual OUString get_name() const override;
238 class UITEST_DLLPUBLIC TabPageUIObject : public WindowUIObject
240 private:
241 VclPtr<TabPage> mxTabPage;
242 public:
243 TabPageUIObject(VclPtr<TabPage> xTabPage);
244 virtual ~TabPageUIObject() override;
246 virtual void execute(const OUString& rAction,
247 const StringMap& rParameters) override;
249 virtual StringMap get_state() override;
251 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
253 protected:
255 virtual OUString get_name() const override;
258 class UITEST_DLLPUBLIC ListBoxUIObject : public WindowUIObject
260 private:
261 VclPtr<ListBox> mxListBox;
263 public:
265 ListBoxUIObject(VclPtr<ListBox> xListBox);
266 virtual ~ListBoxUIObject() override;
268 virtual void execute(const OUString& rAction,
269 const StringMap& rParameters) override;
271 virtual StringMap get_state() override;
273 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
275 virtual OUString get_action(VclEventId nEvent) const override;
277 protected:
279 virtual OUString get_name() const override;
282 // TODO: moggi: should it inherit from EditUIObject?
283 class UITEST_DLLPUBLIC ComboBoxUIObject : public WindowUIObject
285 private:
286 VclPtr<ComboBox> mxComboBox;
288 public:
290 ComboBoxUIObject(VclPtr<ComboBox> xListBox);
291 virtual ~ComboBoxUIObject() override;
293 virtual void execute(const OUString& rAction,
294 const StringMap& rParameters) override;
296 virtual StringMap get_state() override;
298 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
300 protected:
302 virtual OUString get_name() const override;
305 class UITEST_DLLPUBLIC SpinUIObject : public WindowUIObject
307 private:
308 VclPtr<SpinButton> mxSpinButton;
310 public:
312 SpinUIObject(VclPtr<SpinButton> xSpinButton);
313 virtual ~SpinUIObject() override;
315 virtual void execute(const OUString& rAction,
316 const StringMap& rParameters) override;
318 virtual StringMap get_state() override;
320 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
322 protected:
324 virtual OUString get_name() const override;
327 class UITEST_DLLPUBLIC SpinFieldUIObject : public EditUIObject
329 VclPtr<SpinField> mxSpinField;
331 public:
333 SpinFieldUIObject(VclPtr<SpinField> xEdit);
334 virtual ~SpinFieldUIObject() override;
336 virtual void execute(const OUString& rAction,
337 const StringMap& rParameters) override;
339 virtual StringMap get_state() override;
341 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
343 protected:
345 virtual OUString get_name() const override;
348 class UITEST_DLLPUBLIC TabControlUIObject : public WindowUIObject
350 private:
351 VclPtr<TabControl> mxTabControl;
353 public:
355 TabControlUIObject(VclPtr<TabControl> mxTabControl);
356 virtual ~TabControlUIObject() override;
358 virtual void execute(const OUString& rAction,
359 const StringMap& rParameters) override;
361 virtual StringMap get_state() override;
363 static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
365 protected:
367 virtual OUString get_name() const override;
370 #endif
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */