~azzar1/unity/proper-reboot

« back to all changes in this revision

Viewing changes to standalone-clients/nux_automated_test_framework.h

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License version 3, as published
 
6
 * by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * version 3 along with this program.  If not, see
 
15
 * <http://www.gnu.org/licenses/>
 
16
 *
 
17
 * Authored by: Jay Taoko <jaytaoko@inalogic.com>
 
18
 *
 
19
 */
 
20
 
 
21
#include <X11/extensions/XTest.h>
 
22
#include <X11/keysym.h> 
 
23
 
 
24
#ifndef NUX_AUTOMATED_TEST_FRAMEWORK_H
 
25
#define NUX_AUTOMATED_TEST_FRAMEWORK_H
 
26
 
 
27
class NuxAutomatedTestFramework
 
28
{
 
29
public:
 
30
  NuxAutomatedTestFramework(nux::WindowThread *window_thread);
 
31
  virtual ~NuxAutomatedTestFramework();
 
32
 
 
33
  //! Initialize the testing framework.
 
34
  void Startup();
 
35
 
 
36
  //! Simulate a mouse click event on a view.
 
37
  /*!
 
38
      Move the mouse to the middle of the view (if it isn't there already) and perform a click event.
 
39
  */  
 
40
  void ViewSendMouseClick(nux::View *view, int button);
 
41
  //! Simulate a mouse double click event on a view.
 
42
  /*!
 
43
      Move the mouse to the middle of the view (if it isn't there already) and perform a double click event.
 
44
  */  
 
45
  void ViewSendMouseDoubleClick(nux::View *view, int button);
 
46
  //! Simulate a mouse down event on a view.
 
47
  void ViewSendMouseDown(nux::View *view, int button);
 
48
  //! Simulate a mouse up event on a view.
 
49
  void ViewSendMouseUp(nux::View *view, int button);
 
50
  //! Simulate a drag event on a view from (x0, y0) to (x1, y1).
 
51
  void ViewSendMouseDrag(nux::View *view, int button, int x0, int y0, int x1, int y1);
 
52
  //! Simulate mouse motion to (x, y).
 
53
  void ViewSendMouseMotionTo(nux::View *view, int x, int y);
 
54
  //! Simulate mouse motion to the center of a view.
 
55
  void ViewSendMouseMotionToCenter(nux::View *view);
 
56
  //! Simulate mouse motion to the top left corner of a view.
 
57
  void ViewSendMouseMotionToTopLeft(nux::View *view);
 
58
  //! Simulate mouse motion to the top right corner of a view.
 
59
  void ViewSendMouseMotionToTopRight(nux::View *view);
 
60
  //! Simulate mouse motion to the bottom left corner of a view.
 
61
  void ViewSendMouseMotionToBottomLeft(nux::View *view);
 
62
  //! Simulate mouse motion to the bottom right corner of a view.
 
63
  void ViewSendMouseMotionToBottomRight(nux::View *view);
 
64
 
 
65
  //! Simulate a key event.
 
66
  void ViewSendChar(const char c);
 
67
  //! Simulate a succession of key events.
 
68
  void ViewSendString(const std::string &str);
 
69
  //! Simulate a key combo.
 
70
  void ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c);
 
71
  //! Simulate Ctrl+a.
 
72
  void ViewSendCtrlA();
 
73
  //! Simulate Delete key.
 
74
  void ViewSendDelete();
 
75
  //! Simulate Backspace key.
 
76
  void ViewSendBackspace();
 
77
  //! Simulate Escape key.
 
78
  void ViewSendEscape();
 
79
  //! Simulate Tab key.
 
80
  void ViewSendTab();
 
81
  //! Simulate Return key.
 
82
  void ViewSendReturn();
 
83
 
 
84
  //! Put the mouse pointer anywhere on the display.
 
85
  void PutMouseAt(int x, int y);
 
86
 
 
87
  //! Simulate a mouse event.
 
88
  void SendFakeMouseEvent(int mouse_button_index, bool pressed);
 
89
  //! Simulate a key event.
 
90
  void SendFakeKeyEvent(KeySym keysym, KeySym modsym);
 
91
  //! Simulate a mouse motion event.
 
92
  void SendFakeMouseMotionEvent(int x, int y, int ms_delay);
 
93
 
 
94
  /*!
 
95
      Set the test thread to terminae the program when testing is over.
 
96
  */
 
97
  void SetTerminateProgramWhenDone(bool terminate);
 
98
  /*!
 
99
      Return true if the test thread is allowed to terminate the program after testing is over.
 
100
  */
 
101
  bool WhenDoneTerminateProgram();
 
102
 
 
103
  /*!
 
104
      Print a report message to the console.
 
105
  */
 
106
  void TestReportMsg(bool b, const char* msg);
 
107
 
 
108
private:
 
109
  void WindowConfigSignal(int x, int y, int width, int height);
 
110
  
 
111
  bool ready_to_start_;
 
112
  Display* display_;
 
113
  nux::WindowThread *window_thread_;
 
114
  int window_x_;
 
115
  int window_y_;
 
116
  int window_width_;
 
117
  int window_height_;
 
118
  bool terminate_when_test_over_;
 
119
 
 
120
  static int mouse_motion_time_span;    // in milliseconds
 
121
  static int mouse_click_time_span;     // in milliseconds
 
122
  static int minimum_sleep_time;        // in milliseconds   
 
123
  static int safety_border_inside_view; // in pixels
 
124
};
 
125
 
 
126
#endif // NUX_AUTOMATED_TEST_FRAMEWORK_H
 
127