Back to index

nux  3.0.0
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
NuxAutomatedTestFramework Class Reference

#include <nux_automated_test_framework.h>

Collaboration diagram for NuxAutomatedTestFramework:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NuxAutomatedTestFramework (nux::WindowThread *window_thread)
virtual ~NuxAutomatedTestFramework ()
void Startup ()
 Initialize the testing framework.
void ViewSendMouseClick (nux::View *view, int button)
 Simulate a mouse click event on a view.
void ViewSendMouseDoubleClick (nux::View *view, int button)
 Simulate a mouse double click event on a view.
void ViewSendMouseDown (nux::View *view, int button)
 Simulate a mouse down event on a view.
void ViewSendMouseUp (nux::View *view, int button)
 Simulate a mouse up event on a view.
void ViewSendMouseDrag (nux::View *view, int button, int x0, int y0, int x1, int y1)
 Simulate a drag event on a view from (x0, y0) to (x1, y1).
void ViewSendMouseMotionTo (nux::View *view, int x, int y)
 Simulate mouse motion to (x, y).
void ViewSendMouseMotionToCenter (nux::View *view)
 Simulate mouse motion to the center of a view.
void ViewSendMouseMotionToTopLeft (nux::View *view)
 Simulate mouse motion to the top left corner of a view.
void ViewSendMouseMotionToTopRight (nux::View *view)
 Simulate mouse motion to the top right corner of a view.
void ViewSendMouseMotionToBottomLeft (nux::View *view)
 Simulate mouse motion to the bottom left corner of a view.
void ViewSendMouseMotionToBottomRight (nux::View *view)
 Simulate mouse motion to the bottom right corner of a view.
void ViewSendChar (const char c)
 Simulate a key event.
void ViewSendString (const std::string &str)
 Simulate a succession of key events.
void ViewSendKeyCombo (KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c)
 Simulate a key combo.
void ViewSendCtrlA ()
 Simulate Ctrl+a.
void ViewSendDelete ()
 Simulate Delete key.
void ViewSendBackspace ()
 Simulate Backspace key.
void ViewSendEscape ()
 Simulate Escape key.
void ViewSendTab ()
 Simulate Tab key.
void ViewSendReturn ()
 Simulate Return key.
void ViewSendLeft ()
 Simulate Left arrow key.
void ViewSendRight ()
 Simulate Right arrow key.
void ViewSendUp ()
 Simulate Up arrow key.
void ViewSendDown ()
 Simulate Down arrow key.
void ViewSendCompositionKeys (const std::string &str)
 Simulate composition keys.
void ViewSendIBusToggle ()
void PutMouseAt (int x, int y)
 Put the mouse pointer anywhere on the display.
void SendFakeMouseEvent (int mouse_button_index, bool pressed)
 Simulate a mouse event.
void SendFakeKeyEvent (KeySym keysym, KeySym modsym)
 Simulate a key event.
void SendFakeMouseMotionEvent (int x, int y, int ms_delay)
 Simulate a mouse motion event.
void SetTerminateProgramWhenDone (bool terminate)
 Set the test thread to terminae the program when testing is over.
bool WhenDoneTerminateProgram ()
 Return true if the test thread is allowed to terminate the program after testing is over.
void TestReportMsg (bool b, const char *msg)
 Print a report message to the console.

Private Member Functions

void WindowConfigSignal (int x, int y, int width, int height)

Private Attributes

bool ready_to_start_
Display * display_
nux::WindowThreadwindow_thread_
int window_x_
int window_y_
int window_width_
int window_height_
bool terminate_when_test_over_

Static Private Attributes

static int mouse_motion_time_span = 1000
static int mouse_click_time_span = 300
static int minimum_sleep_time = 600
static int safety_border_inside_view = 1

Detailed Description

Definition at line 27 of file nux_automated_test_framework.h.


Constructor & Destructor Documentation

Definition at line 32 of file nux_automated_test_framework.cpp.

{
  ready_to_start_ = false;
  display_ = NULL;
  window_thread_ = window_thread;
  window_x_ = 0;
  window_y_ = 0;
  window_width_ = 0;
  window_height_ = 0;
  terminate_when_test_over_ = false;
}

Definition at line 44 of file nux_automated_test_framework.cpp.

{
  XCloseDisplay(display_);
}

Member Function Documentation

void NuxAutomatedTestFramework::PutMouseAt ( int  x,
int  y 
)

Put the mouse pointer anywhere on the display.

Definition at line 534 of file nux_automated_test_framework.cpp.

{
  XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);  
  XSync(display_, False);
}

Here is the caller graph for this function:

void NuxAutomatedTestFramework::SendFakeKeyEvent ( KeySym  keysym,
KeySym  modsym 
)

Simulate a key event.

Definition at line 540 of file nux_automated_test_framework.cpp.

{
  KeyCode keycode = 0;
  KeyCode modcode = 0;
  
  keycode = XKeysymToKeycode(display_, keysym);
  XTestGrabControl(display_, True);
  
  /* Generate modkey press */
  if (modsym != 0)
  {
    modcode = XKeysymToKeycode(display_, modsym);
    XTestFakeKeyEvent(display_, modcode, True, 0);
  }
  
  /* Generate regular key press and release */
  XTestFakeKeyEvent(display_, keycode, True, 0);
  XTestFakeKeyEvent(display_, keycode, False, 0);
  
  /* Generate modkey release */
  if (modsym != 0)
  {
    XTestFakeKeyEvent(display_, modcode, False, 0);
  }

  XSync(display_, False);
  XTestGrabControl(display_, False);
}

Here is the caller graph for this function:

void NuxAutomatedTestFramework::SendFakeMouseEvent ( int  mouse_button_index,
bool  pressed 
)

Simulate a mouse event.

Definition at line 569 of file nux_automated_test_framework.cpp.

{
  XTestFakeButtonEvent(display_, mouse_button_index, pressed,  CurrentTime);
  XSync(display_, False);  
}

Here is the caller graph for this function:

void NuxAutomatedTestFramework::SendFakeMouseMotionEvent ( int  x,
int  y,
int  ms_delay 
)

Simulate a mouse motion event.

Definition at line 575 of file nux_automated_test_framework.cpp.

{
  XEvent event;
  /* Get the current pointer position */
  XQueryPointer(display_, RootWindow(display_, 0),
        &event.xbutton.root, &event.xbutton.window,
        &event.xbutton.x_root, &event.xbutton.y_root,
        &event.xbutton.x, &event.xbutton.y,
        &event.xbutton.state);

  int old_x = event.xbutton.x;
  int old_y = event.xbutton.y;

  int n_iteration = ms_delay / 16.0f;

  //nuxDebugMsg("n_iteration: %d", n_iteration);

  if (n_iteration < 1)
  {
    n_iteration = 1;
  }

  XSync(display_, False);

  for (int i = 0; i < n_iteration; i++)
  {
    float t = ((float)i + 1.0f) / n_iteration;

    int cx = (1.0f - t) * old_x + t * x;
    int cy = (1.0f - t) * old_y + t * y;
    XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), cx, cy, CurrentTime);
    XSync(display_, False);
    usleep(16*1000);
  }

  XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);  
  XSync(display_, False);
  nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Set the test thread to terminae the program when testing is over.

Definition at line 49 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Initialize the testing framework.

Definition at line 59 of file nux_automated_test_framework.cpp.

{
  display_ = XOpenDisplay(NULL);
  nux::Geometry rect = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
  //nuxDebugMsg("Window geometry: (%d, %d, %d, %d)", rect.x, rect.y, rect.width, rect.height);

  window_x_ = rect.x;
  window_y_ = rect.y;
  window_width_ = rect.width;
  window_height_ = rect.height;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NuxAutomatedTestFramework::TestReportMsg ( bool  b,
const char *  msg 
)

Print a report message to the console.

Definition at line 615 of file nux_automated_test_framework.cpp.

{
  if (b)
  {
    nuxOkMsg("%s: %s", msg, "Ok");
  }
  else
  {
    nuxAlertMsg("%s: %s", msg, "Failed");
  }  
}

Here is the caller graph for this function:

Simulate Backspace key.

Definition at line 476 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_BackSpace, 0);  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate a key event.

Definition at line 252 of file nux_automated_test_framework.cpp.

{
  KeySym modifier = 0;

  if ((c >= 'A') && (c <= 'Z'))
  {
    modifier = XK_Shift_L;
  }

  std::string s(1, c);

  if (c == ' ')
  {
    SendFakeKeyEvent(XK_space, modifier);
  }
  else
  {   
    SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier);
  }

  nux::SleepForMilliseconds(300);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NuxAutomatedTestFramework::ViewSendCompositionKeys ( const std::string &  str)

Simulate composition keys.

Definition at line 399 of file nux_automated_test_framework.cpp.

{
  int l = str.length();
  if (l == 0)
    return;
  
  SendFakeKeyEvent(XK_Multi_key, 0);
  ViewSendString(str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate Ctrl+a.

Definition at line 466 of file nux_automated_test_framework.cpp.

{
  ViewSendKeyCombo(XK_Control_L, 0, 0, 'a');
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate Delete key.

Definition at line 471 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Delete, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate Down arrow key.

Definition at line 511 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Down, 0);
}

Here is the call graph for this function:

Simulate Escape key.

Definition at line 481 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Escape, 0);  
}

Here is the call graph for this function:

Definition at line 516 of file nux_automated_test_framework.cpp.

{
  KeyCode modcode0 = 0;
  KeyCode modcode1 = 0;

  modcode0 = XKeysymToKeycode(display_, XK_Control_L);
  XTestFakeKeyEvent(display_, modcode0, True, 0);

  modcode1 = XKeysymToKeycode(display_, XK_space);
  XTestFakeKeyEvent(display_, modcode1, True, 0);

  // release
  /* Generate modkey release */
  XTestFakeKeyEvent(display_, modcode1, False, 0);
  XTestFakeKeyEvent(display_, modcode0, False, 0);

}

Here is the caller graph for this function:

void NuxAutomatedTestFramework::ViewSendKeyCombo ( KeySym  modsym0,
KeySym  modsym1,
KeySym  modsym2,
const char  c 
)

Simulate a key combo.

Definition at line 409 of file nux_automated_test_framework.cpp.

{
  KeyCode keycode = 0;
  KeyCode modcode0 = 0;
  KeyCode modcode1 = 0;
  KeyCode modcode2 = 0;
  
  if (c != 0)
  {
    printf("ViewSendKeyCombo");
    std::string s(1, c);
    keycode = XKeysymToKeycode(display_, XStringToKeysym(s.c_str()));
  }
  XTestGrabControl(display_, True);
  
  /* Generate modkey press */
  if (modsym0 != 0)
  {
    modcode0 = XKeysymToKeycode(display_, modsym0);
    XTestFakeKeyEvent(display_, modcode0, True, 0);
  }
  if (modsym1 != 0)
  {
    modcode1 = XKeysymToKeycode(display_, modsym1);
    XTestFakeKeyEvent(display_, modcode1, True, 0);
  }
  if (modsym2 != 0)
  {
    modcode2 = XKeysymToKeycode(display_, modsym2);
    XTestFakeKeyEvent(display_, modcode2, True, 0);
  }
      
  /* Generate regular key press and release */
  if (keycode)
  {
    XTestFakeKeyEvent(display_, keycode, True, 0);
    XTestFakeKeyEvent(display_, keycode, False, 0);
  }
  
  /* Generate modkey release */
  if (modsym0 != 0)
  {
    XTestFakeKeyEvent(display_, modcode0, False, 0);
  }
  if (modsym1 != 0)
  {
    XTestFakeKeyEvent(display_, modcode1, False, 0);
  }
  if (modsym2 != 0)
  {
    XTestFakeKeyEvent(display_, modcode2, False, 0);
  }
    
  XSync(display_, False);
  XTestGrabControl(display_, False);  
}

Here is the caller graph for this function:

Simulate Left arrow key.

Definition at line 501 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Left, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NuxAutomatedTestFramework::ViewSendMouseClick ( nux::View view,
int  button 
)

Simulate a mouse click event on a view.

Move the mouse to the middle of the view (if it isn't there already) and perform a click event.

Definition at line 71 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate a mouse double click event on a view.

Move the mouse to the middle of the view (if it isn't there already) and perform a double click event.

Definition at line 94 of file nux_automated_test_framework.cpp.

{
  nux::Rect r;
  if (view)
  {
    r = view->GetAbsoluteGeometry();
    r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2);
  }
  else
  {
    r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
    r.OffsetPosition(r.width/2, r.height/2);
  }
    
  // Send the mouse to the center of the view
  SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);

  XTestFakeButtonEvent(display_, button, true,  CurrentTime);
  XTestFakeButtonEvent(display_, button, false,  CurrentTime);
  XTestFakeButtonEvent(display_, button, true,  CurrentTime);
  XTestFakeButtonEvent(display_, button, false,  CurrentTime);
  XSync(display_, False);
  nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NuxAutomatedTestFramework::ViewSendMouseDown ( nux::View view,
int  button 
)

Simulate a mouse down event on a view.

Definition at line 119 of file nux_automated_test_framework.cpp.

{
  XEvent event;
  /* Get the current pointer position */  
  XQueryPointer(display_, RootWindow(display_, 0),  
        &event.xbutton.root, &event.xbutton.window,  
        &event.xbutton.x_root, &event.xbutton.y_root,  
        &event.xbutton.x, &event.xbutton.y,  
        &event.xbutton.state);

  int current_x = event.xbutton.x - window_x_;
  int current_y = event.xbutton.y - window_y_;

  nux::Rect r = view->GetAbsoluteGeometry();

  if (!r.IsInside(nux::Point(current_x, current_y)))
  {
    // The mouse pointer is not inside the view.
    // Move the mouse pointer to the center of the view.
    r.OffsetPosition(window_x_, window_y_);

    // Go to the center of the view
    int view_center_x = r.x + r.width/2;
    int view_center_y = r.y + r.height/2;
    SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
    nux::SleepForMilliseconds(minimum_sleep_time);
  }
  SendFakeMouseEvent(button, true);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void NuxAutomatedTestFramework::ViewSendMouseDrag ( nux::View view,
int  button,
int  x0,
int  y0,
int  x1,
int  y1 
)

Simulate a drag event on a view from (x0, y0) to (x1, y1).

Definition at line 162 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void NuxAutomatedTestFramework::ViewSendMouseMotionTo ( nux::View view,
int  x,
int  y 
)

Simulate mouse motion to (x, y).

Definition at line 184 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate mouse motion to the bottom left corner of a view.

Definition at line 236 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Simulate mouse motion to the bottom right corner of a view.

Definition at line 244 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Simulate mouse motion to the center of a view.

Definition at line 201 of file nux_automated_test_framework.cpp.

{
  nux::Rect r;
  if (view)
  {
    r = view->GetAbsoluteGeometry();
    r.OffsetPosition(window_x_, window_y_);
  }
  else
  {
    r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
  }

  int view_center_x = r.x + r.width/2;
  int view_center_y = r.y + r.height/2;

  SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate mouse motion to the top left corner of a view.

Definition at line 220 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

Simulate mouse motion to the top right corner of a view.

Definition at line 228 of file nux_automated_test_framework.cpp.

Here is the call graph for this function:

void NuxAutomatedTestFramework::ViewSendMouseUp ( nux::View view,
int  button 
)

Simulate a mouse up event on a view.

Definition at line 149 of file nux_automated_test_framework.cpp.

{
  //   nux::Rect r = view->GetAbsoluteGeometry();
  // r.OffsetPosition(window_x_, window_y_);

  // int view_center_x = r.x + r.width/2;
  // int view_center_y = r.y + r.height/2;

  // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000);
  // nux::SleepForMilliseconds(minimum_sleep_time);
  SendFakeMouseEvent(button, false);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate Return key.

Definition at line 491 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Return, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate Right arrow key.

Definition at line 496 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Right, 0);
}

Here is the call graph for this function:

void NuxAutomatedTestFramework::ViewSendString ( const std::string &  str)

Simulate a succession of key events.

Definition at line 275 of file nux_automated_test_framework.cpp.

{
  int l = str.length();
  if (l == 0)
    return;
  
  int i = 0;

  while (i < l)
  {
    KeySym modifier = 0;
    char c = str[i++];

    if ((c >= 'A') && (c <= 'Z'))
    {
      modifier = XK_Shift_L;
    }

    std::string s(1, c);

    if (c == ' ')
    {
      SendFakeKeyEvent(XK_space, modifier);
    }
    else if (c == '^')
    {
      SendFakeKeyEvent(XK_asciicircum, XK_Shift_L);
    }
    else if (c == '~')
    {
      SendFakeKeyEvent(XK_asciitilde, XK_Shift_L);
    }
    else if (c == '`')
    {
      SendFakeKeyEvent(XK_asciitilde, 0);
    }
    else if (c == '=')
    {
      SendFakeKeyEvent(XK_equal, 0);
    }
    else if (c == '\"')
    {
      SendFakeKeyEvent(XK_quotedbl, XK_Shift_L);
    }
    else if (c == '!')
    {
      SendFakeKeyEvent(XK_exclam, XK_Shift_L);
    }
    else if (c == '|')
    {
      SendFakeKeyEvent(XK_bar, XK_Shift_L);
    }
    else if (c == '/')
    {
      SendFakeKeyEvent(XK_slash, 0);
    }
    else if (c == '\\')
    {
      SendFakeKeyEvent(XK_backslash, 0);
    }
    else if (c == '-')
    {
      SendFakeKeyEvent(XK_minus, 0);
    }
    else if (c == '+')
    {
      SendFakeKeyEvent(XK_plus, XK_Shift_L);
    }
    else if (c == ',')
    {
      SendFakeKeyEvent(XK_comma, 0);
    }
    else if (c == '_')
    {
      SendFakeKeyEvent(XK_underscore, XK_Shift_L);
    }
    else if (c == '<')
    { 
      SendFakeKeyEvent(XK_comma, XK_Shift_L);
    }
    else if (c == '>')
    {
      SendFakeKeyEvent(XK_greater, XK_Shift_L);
    }
    else if (c == '.')
    {
      SendFakeKeyEvent(XK_period, 0);
    }
    else if (c == '?')
    {
      SendFakeKeyEvent(XK_question, XK_Shift_L);
    }
    else if (c == '\'')
    {
      SendFakeKeyEvent(XK_quoteright, 0);
    }
    else if (c == ';')
    {
      SendFakeKeyEvent(XK_semicolon, 0);
    }
    else if (c == ':')
    {
      SendFakeKeyEvent(XK_colon, XK_Shift_L);
    }
    else if (c == '%')
    {
      SendFakeKeyEvent(XK_percent, XK_Shift_L);
    }
    else if (c == '(')
    {
      SendFakeKeyEvent(XK_parenleft, XK_Shift_L);
    }
    else if (c == ')')
    {
      SendFakeKeyEvent(XK_parenright, XK_Shift_L);
    }
    else
    {   
      SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier);
    }
    nux::SleepForMilliseconds(300);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Simulate Tab key.

Definition at line 486 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Tab, 0);
}

Here is the call graph for this function:

Simulate Up arrow key.

Definition at line 506 of file nux_automated_test_framework.cpp.

{
  SendFakeKeyEvent(XK_Up, 0);
}

Here is the call graph for this function:

Return true if the test thread is allowed to terminate the program after testing is over.

Definition at line 54 of file nux_automated_test_framework.cpp.

Here is the caller graph for this function:

void NuxAutomatedTestFramework::WindowConfigSignal ( int  x,
int  y,
int  width,
int  height 
) [private]

Member Data Documentation

Definition at line 124 of file nux_automated_test_framework.h.

int NuxAutomatedTestFramework::minimum_sleep_time = 600 [static, private]

Definition at line 134 of file nux_automated_test_framework.h.

Definition at line 133 of file nux_automated_test_framework.h.

Definition at line 132 of file nux_automated_test_framework.h.

Definition at line 123 of file nux_automated_test_framework.h.

Definition at line 135 of file nux_automated_test_framework.h.

Definition at line 130 of file nux_automated_test_framework.h.

Definition at line 129 of file nux_automated_test_framework.h.

Definition at line 125 of file nux_automated_test_framework.h.

Definition at line 128 of file nux_automated_test_framework.h.

Definition at line 126 of file nux_automated_test_framework.h.

Definition at line 127 of file nux_automated_test_framework.h.


The documentation for this class was generated from the following files: