/src/libreoffice/include/vcl/uitest/uiobject.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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 | | */ |
9 | | |
10 | | #pragma once |
11 | | |
12 | | #include <rtl/ustring.hxx> |
13 | | #include <map> |
14 | | #include <memory> |
15 | | |
16 | | // hack needed for treelistbox.hxx inclusion here |
17 | | #define VCL_INTERNALS |
18 | | #include <vcl/toolkit/treelistbox.hxx> |
19 | | #include <vcl/vclptr.hxx> |
20 | | #include <vcl/dllapi.h> |
21 | | #include <vcl/window.hxx> |
22 | | |
23 | | #include <set> |
24 | | |
25 | | class Button; |
26 | | class CheckBox; |
27 | | class ComboBox; |
28 | | class Dialog; |
29 | | class Edit; |
30 | | class ListBox; |
31 | | class RadioButton; |
32 | | class TabControl; |
33 | | class TabPage; |
34 | | class SvTreeListBox; |
35 | | class SvTreeListEntry; |
36 | | class SpinButton; |
37 | | class SpinField; |
38 | | class VerticalTabControl; |
39 | | class VclExpander; |
40 | | class VclDrawingArea; |
41 | | class VclMultiLineEdit; |
42 | | class MenuButton; |
43 | | enum class VclEventId; |
44 | | namespace weld { class CustomWidgetController; } |
45 | | |
46 | | typedef std::map<OUString, OUString> StringMap; |
47 | | |
48 | | /** |
49 | | * This class wraps a UI object like vcl::Window and provides |
50 | | * an interface for the UI testing. |
51 | | * |
52 | | * This class should only have virtual methods. |
53 | | */ |
54 | | class UITEST_DLLPUBLIC UIObject |
55 | | { |
56 | | UIObject(UIObject const &) = delete; |
57 | | UIObject& operator =(UIObject const &) = delete; |
58 | | |
59 | | public: |
60 | 0 | UIObject() = default; |
61 | | |
62 | | virtual ~UIObject(); |
63 | | |
64 | | /** |
65 | | * Returns the state of the wrapped UI object as a |
66 | | * string key value map. |
67 | | */ |
68 | | virtual StringMap get_state(); |
69 | | |
70 | | /** |
71 | | * Executes an action on the wrapped UI object, |
72 | | * possibly with some additional parameters |
73 | | */ |
74 | | virtual void execute(const OUString& rAction, |
75 | | const StringMap& rParameters); |
76 | | |
77 | | /** |
78 | | * Returns the type of the UIObject. Additional information might |
79 | | * be available through UIObject::get_state(). |
80 | | */ |
81 | | virtual OUString get_type() const; |
82 | | |
83 | | /** |
84 | | * Returns the child of the current UIObject with the corresponding id. |
85 | | * If no object with that id is being found returns a nullptr. |
86 | | * |
87 | | */ |
88 | | virtual std::unique_ptr<UIObject> get_child(const OUString& rID); |
89 | | |
90 | | /** |
91 | | * Returns a set containing all descendants of the object. |
92 | | */ |
93 | | virtual std::set<OUString> get_children() const; |
94 | | |
95 | | /** |
96 | | * Currently an internal method to dump the state of the current UIObject as represented by get_state(). |
97 | | * |
98 | | * This method should not be exposed to the outside world. |
99 | | * |
100 | | */ |
101 | | virtual OUString dumpState() const; |
102 | | |
103 | | /** |
104 | | * Currently an internal method to dump the parent-child relationship starting from the current top focus window. |
105 | | * |
106 | | * This method should not be exposed to the outside world. |
107 | | * |
108 | | */ |
109 | | virtual OUString dumpHierarchy() const; |
110 | | |
111 | | /** |
112 | | * Gets the corresponding Action string for the event. |
113 | | */ |
114 | | virtual OUString get_action(VclEventId nEvent) const; |
115 | | |
116 | | /** |
117 | | * Does this represent the same underlying UI widget as rOther? |
118 | | */ |
119 | | virtual bool equals(const UIObject& rOther) const = 0; |
120 | | }; |
121 | | |
122 | | class UITEST_DLLPUBLIC WindowUIObject : public UIObject |
123 | | { |
124 | | VclPtr<vcl::Window> mxWindow; |
125 | | |
126 | | public: |
127 | | |
128 | | WindowUIObject(const VclPtr<vcl::Window>& xWindow); |
129 | | |
130 | | virtual StringMap get_state() override; |
131 | | |
132 | | virtual void execute(const OUString& rAction, |
133 | | const StringMap& rParameters) override; |
134 | | |
135 | | virtual OUString get_type() const override; |
136 | | |
137 | | virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; |
138 | | |
139 | | std::unique_ptr<UIObject> get_visible_child(const OUString& rID); |
140 | | |
141 | | virtual std::set<OUString> get_children() const override; |
142 | | |
143 | | virtual OUString dumpState() const override; |
144 | | |
145 | | virtual OUString dumpHierarchy() const override; |
146 | | |
147 | | virtual OUString get_action(VclEventId nEvent) const override; |
148 | | |
149 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
150 | | |
151 | | virtual bool equals(const UIObject& rOther) const override; |
152 | | |
153 | | protected: |
154 | | |
155 | | virtual OUString get_name() const; |
156 | | |
157 | | }; |
158 | | |
159 | | // TODO: moggi: what about push buttons? |
160 | | class ButtonUIObject final : public WindowUIObject |
161 | | { |
162 | | VclPtr<Button> mxButton; |
163 | | public: |
164 | | |
165 | | ButtonUIObject(const VclPtr<Button>& xButton); |
166 | | virtual ~ButtonUIObject() override; |
167 | | |
168 | | virtual StringMap get_state() override; |
169 | | |
170 | | virtual void execute(const OUString& rAction, |
171 | | const StringMap& rParameters) override; |
172 | | |
173 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
174 | | |
175 | | virtual OUString get_action(VclEventId nEvent) const override; |
176 | | |
177 | | private: |
178 | | |
179 | | virtual OUString get_name() const override; |
180 | | }; |
181 | | |
182 | | class DialogUIObject final : public WindowUIObject |
183 | | { |
184 | | VclPtr<Dialog> mxDialog; |
185 | | |
186 | | public: |
187 | | |
188 | | DialogUIObject(const VclPtr<Dialog>& xDialog); |
189 | | virtual ~DialogUIObject() override; |
190 | | |
191 | | virtual StringMap get_state() override; |
192 | | |
193 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
194 | | |
195 | | private: |
196 | | |
197 | | virtual OUString get_name() const override; |
198 | | }; |
199 | | |
200 | | class EditUIObject : public WindowUIObject |
201 | | { |
202 | | VclPtr<Edit> mxEdit; |
203 | | |
204 | | public: |
205 | | |
206 | | EditUIObject(const VclPtr<Edit>& xEdit); |
207 | | virtual ~EditUIObject() override; |
208 | | |
209 | | virtual void execute(const OUString& rAction, |
210 | | const StringMap& rParameters) override; |
211 | | |
212 | | virtual StringMap get_state() override; |
213 | | |
214 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
215 | | |
216 | | virtual OUString get_action(VclEventId nEvent) const override; |
217 | | |
218 | | protected: |
219 | | |
220 | | virtual OUString get_name() const override; |
221 | | }; |
222 | | |
223 | | class MultiLineEditUIObject final : public WindowUIObject |
224 | | { |
225 | | VclPtr<VclMultiLineEdit> mxEdit; |
226 | | |
227 | | public: |
228 | | |
229 | | MultiLineEditUIObject(const VclPtr<VclMultiLineEdit>& xEdit); |
230 | | virtual ~MultiLineEditUIObject() override; |
231 | | |
232 | | virtual void execute(const OUString& rAction, |
233 | | const StringMap& rParameters) override; |
234 | | |
235 | | virtual StringMap get_state() override; |
236 | | |
237 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
238 | | |
239 | | private: |
240 | | |
241 | | virtual OUString get_name() const override; |
242 | | }; |
243 | | |
244 | | class ExpanderUIObject final : public WindowUIObject |
245 | | { |
246 | | VclPtr<VclExpander> mxExpander; |
247 | | |
248 | | public: |
249 | | |
250 | | ExpanderUIObject(const VclPtr<VclExpander>& xExpander); |
251 | | virtual ~ExpanderUIObject() override; |
252 | | |
253 | | virtual void execute(const OUString& rAction, |
254 | | const StringMap& rParameters) override; |
255 | | |
256 | | virtual StringMap get_state() override; |
257 | | |
258 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
259 | | private: |
260 | | |
261 | | virtual OUString get_name() const override; |
262 | | }; |
263 | | |
264 | | |
265 | | // TODO: moggi: maybe let it inherit from the button case |
266 | | class CheckBoxUIObject final : public WindowUIObject |
267 | | { |
268 | | private: |
269 | | VclPtr<CheckBox> mxCheckBox; |
270 | | |
271 | | public: |
272 | | CheckBoxUIObject(const VclPtr<CheckBox>& xCheckbox); |
273 | | virtual ~CheckBoxUIObject() override; |
274 | | |
275 | | virtual void execute(const OUString& rAction, |
276 | | const StringMap& rParameters) override; |
277 | | |
278 | | virtual StringMap get_state() override; |
279 | | |
280 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
281 | | |
282 | | virtual OUString get_action(VclEventId nEvent) const override; |
283 | | |
284 | | private: |
285 | | |
286 | | virtual OUString get_name() const override; |
287 | | }; |
288 | | |
289 | | class RadioButtonUIObject final : public WindowUIObject |
290 | | { |
291 | | private: |
292 | | VclPtr<RadioButton> mxRadioButton; |
293 | | |
294 | | public: |
295 | | RadioButtonUIObject(const VclPtr<RadioButton>& xCheckbox); |
296 | | virtual ~RadioButtonUIObject() override; |
297 | | |
298 | | virtual void execute(const OUString& rAction, |
299 | | const StringMap& rParameters) override; |
300 | | |
301 | | virtual StringMap get_state() override; |
302 | | |
303 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
304 | | |
305 | | virtual OUString get_action(VclEventId nEvent) const override; |
306 | | |
307 | | private: |
308 | | |
309 | | virtual OUString get_name() const override; |
310 | | }; |
311 | | |
312 | | class TabPageUIObject final : public WindowUIObject |
313 | | { |
314 | | private: |
315 | | VclPtr<TabPage> mxTabPage; |
316 | | public: |
317 | | TabPageUIObject(const VclPtr<TabPage>& xTabPage); |
318 | | virtual ~TabPageUIObject() override; |
319 | | |
320 | | virtual void execute(const OUString& rAction, |
321 | | const StringMap& rParameters) override; |
322 | | |
323 | | virtual StringMap get_state() override; |
324 | | |
325 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
326 | | |
327 | | private: |
328 | | |
329 | | virtual OUString get_name() const override; |
330 | | }; |
331 | | |
332 | | class ListBoxUIObject final : public WindowUIObject |
333 | | { |
334 | | private: |
335 | | VclPtr<ListBox> mxListBox; |
336 | | |
337 | | public: |
338 | | |
339 | | ListBoxUIObject(const VclPtr<ListBox>& xListBox); |
340 | | virtual ~ListBoxUIObject() override; |
341 | | |
342 | | virtual void execute(const OUString& rAction, |
343 | | const StringMap& rParameters) override; |
344 | | |
345 | | virtual StringMap get_state() override; |
346 | | |
347 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
348 | | |
349 | | virtual OUString get_action(VclEventId nEvent) const override; |
350 | | |
351 | | private: |
352 | | |
353 | | virtual OUString get_name() const override; |
354 | | }; |
355 | | |
356 | | // TODO: moggi: should it inherit from EditUIObject? |
357 | | class ComboBoxUIObject final : public WindowUIObject |
358 | | { |
359 | | private: |
360 | | VclPtr<ComboBox> mxComboBox; |
361 | | |
362 | | public: |
363 | | |
364 | | ComboBoxUIObject(const VclPtr<ComboBox>& xListBox); |
365 | | virtual ~ComboBoxUIObject() override; |
366 | | |
367 | | virtual void execute(const OUString& rAction, |
368 | | const StringMap& rParameters) override; |
369 | | |
370 | | virtual StringMap get_state() override; |
371 | | |
372 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
373 | | |
374 | | virtual OUString get_action(VclEventId nEvent) const override; |
375 | | |
376 | | private: |
377 | | |
378 | | virtual OUString get_name() const override; |
379 | | }; |
380 | | |
381 | | class SpinUIObject final : public WindowUIObject |
382 | | { |
383 | | private: |
384 | | VclPtr<SpinButton> mxSpinButton; |
385 | | |
386 | | public: |
387 | | |
388 | | SpinUIObject(const VclPtr<SpinButton>& xSpinButton); |
389 | | virtual ~SpinUIObject() override; |
390 | | |
391 | | virtual void execute(const OUString& rAction, |
392 | | const StringMap& rParameters) override; |
393 | | |
394 | | virtual StringMap get_state() override; |
395 | | |
396 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
397 | | |
398 | | virtual OUString get_action(VclEventId nEvent) const override; |
399 | | |
400 | | private: |
401 | | |
402 | | virtual OUString get_name() const override; |
403 | | }; |
404 | | |
405 | | class SpinFieldUIObject : public EditUIObject |
406 | | { |
407 | | VclPtr<SpinField> mxSpinField; |
408 | | |
409 | | public: |
410 | | |
411 | | SpinFieldUIObject(const VclPtr<SpinField>& xEdit); |
412 | | virtual ~SpinFieldUIObject() override; |
413 | | |
414 | | virtual void execute(const OUString& rAction, |
415 | | const StringMap& rParameters) override; |
416 | | |
417 | | virtual StringMap get_state() override; |
418 | | |
419 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
420 | | |
421 | | virtual OUString get_action(VclEventId nEvent) const override; |
422 | | |
423 | | private: |
424 | | |
425 | | virtual OUString get_name() const override; |
426 | | }; |
427 | | |
428 | | class TabControlUIObject final : public WindowUIObject |
429 | | { |
430 | | private: |
431 | | VclPtr<TabControl> mxTabControl; |
432 | | |
433 | | public: |
434 | | |
435 | | TabControlUIObject(const VclPtr<TabControl>& mxTabControl); |
436 | | virtual ~TabControlUIObject() override; |
437 | | |
438 | | virtual void execute(const OUString& rAction, |
439 | | const StringMap& rParameters) override; |
440 | | |
441 | | virtual StringMap get_state() override; |
442 | | |
443 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
444 | | |
445 | | virtual OUString get_action(VclEventId nEvent) const override; |
446 | | |
447 | | private: |
448 | | |
449 | | virtual OUString get_name() const override; |
450 | | }; |
451 | | |
452 | | class VerticalTabControlUIObject final : public WindowUIObject |
453 | | { |
454 | | private: |
455 | | VclPtr<VerticalTabControl> mxTabControl; |
456 | | |
457 | | public: |
458 | | |
459 | | VerticalTabControlUIObject(const VclPtr<VerticalTabControl>& mxTabControl); |
460 | | virtual ~VerticalTabControlUIObject() override; |
461 | | |
462 | | virtual void execute(const OUString& rAction, |
463 | | const StringMap& rParameters) override; |
464 | | |
465 | | virtual StringMap get_state() override; |
466 | | |
467 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
468 | | |
469 | | private: |
470 | | |
471 | | virtual OUString get_name() const override; |
472 | | }; |
473 | | |
474 | | class TreeListUIObject : public WindowUIObject |
475 | | { |
476 | | public: |
477 | | TreeListUIObject(const VclPtr<SvTreeListBox>& xTreeList); |
478 | | |
479 | | virtual StringMap get_state() override; |
480 | | |
481 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
482 | | |
483 | | virtual void execute(const OUString& rAction, |
484 | | const StringMap& rParameters) override; |
485 | | |
486 | | virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; |
487 | | |
488 | | virtual std::set<OUString> get_children() const override; |
489 | | |
490 | | protected: |
491 | | |
492 | | virtual OUString get_name() const override; |
493 | | |
494 | | VclPtr<SvTreeListBox> mxTreeList; |
495 | | }; |
496 | | |
497 | | class TreeListEntryUIObject final : public UIObject |
498 | | { |
499 | | public: |
500 | | |
501 | | TreeListEntryUIObject(const VclPtr<SvTreeListBox>& xTreeList, std::vector<sal_Int32> nTreePath); |
502 | | |
503 | | virtual StringMap get_state() override; |
504 | | |
505 | | virtual void execute(const OUString& rAction, |
506 | | const StringMap& rParameters) override; |
507 | | |
508 | | virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override; |
509 | | |
510 | | virtual std::set<OUString> get_children() const override; |
511 | | |
512 | | virtual OUString get_type() const override; |
513 | | |
514 | | virtual bool equals(const UIObject& rOther) const override; |
515 | | |
516 | | private: |
517 | | |
518 | | SvTreeListEntry* getEntry() const; |
519 | | |
520 | | VclPtr<SvTreeListBox> mxTreeList; |
521 | | |
522 | | std::vector<sal_Int32> maTreePath; |
523 | | }; |
524 | | |
525 | | class IconViewUIObject final : public TreeListUIObject |
526 | | { |
527 | | public: |
528 | | IconViewUIObject(const VclPtr<SvTreeListBox>& xIconView); |
529 | | |
530 | | virtual StringMap get_state() override; |
531 | | |
532 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
533 | | |
534 | | private: |
535 | | |
536 | | virtual OUString get_name() const override; |
537 | | }; |
538 | | |
539 | | class MenuButtonUIObject final : public WindowUIObject |
540 | | { |
541 | | VclPtr<MenuButton> mxMenuButton; |
542 | | |
543 | | public: |
544 | | |
545 | | MenuButtonUIObject(const VclPtr<MenuButton>& xMenuButton); |
546 | | virtual ~MenuButtonUIObject() override; |
547 | | |
548 | | virtual StringMap get_state() override; |
549 | | |
550 | | virtual void execute(const OUString& rAction, |
551 | | const StringMap& rParameters) override; |
552 | | |
553 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
554 | | |
555 | | private: |
556 | | |
557 | | virtual OUString get_name() const override; |
558 | | }; |
559 | | |
560 | | class UITEST_DLLPUBLIC DrawingAreaUIObject : public WindowUIObject |
561 | | { |
562 | | private: |
563 | | VclPtr<VclDrawingArea> mxDrawingArea; |
564 | | protected: |
565 | | weld::CustomWidgetController* mpController; |
566 | | public: |
567 | | DrawingAreaUIObject(const VclPtr<vcl::Window>& rDrawingArea); |
568 | | virtual ~DrawingAreaUIObject() override; |
569 | | virtual void execute(const OUString& rAction, const StringMap& rParameters) override; |
570 | | static std::unique_ptr<UIObject> create(vcl::Window* pWindow); |
571 | | }; |
572 | | |
573 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |