Back to index

nux  3.0.0
Classes | Functions | Variables
xtest-vlayout-key-navigation.cpp File Reference
#include "Nux/Nux.h"
#include "Nux/WindowThread.h"
#include "Nux/VLayout.h"
#include "Nux/ProgramFramework/ProgramTemplate.h"
#include "Nux/ProgramFramework/TestView.h"
#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include "nux_automated_test_framework.h"

Go to the source code of this file.

Classes

class  VLayoutKeyNavigationTest

Functions

void TestingThread (nux::NThread *thread, void *user_data)
int main (int argc, char **argv)

Variables

unsigned int const NUM_VIEWS = 5
unsigned int const ID_UNFOCUSABLE_VIEW = 1
VLayoutKeyNavigationTestkey_navigation_test = NULL

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 181 of file xtest-vlayout-key-navigation.cpp.

{
  int xstatus = XInitThreads();
  nuxAssertMsg(xstatus > 0, "XInitThreads has failed");

  key_navigation_test = new VLayoutKeyNavigationTest("Key navigation Test", 500, 400, 8000);
  key_navigation_test->Startup();
  key_navigation_test->UserInterfaceSetup();

  nux::SystemThread* test_thread = nux::CreateSystemThread(key_navigation_test->GetWindowThread(), &TestingThread, key_navigation_test->GetWindowThread());

  test_thread->Start(key_navigation_test);

  key_navigation_test->Run();

  delete test_thread;
  delete key_navigation_test;

  return 0;
}

Here is the call graph for this function:

void TestingThread ( nux::NThread thread,
void *  user_data 
)

Definition at line 94 of file xtest-vlayout-key-navigation.cpp.

{
  while (key_navigation_test->ReadyToGo() == false)
  {
    nuxDebugMsg("Waiting to start");
    nux::SleepForMilliseconds(300);
  }

  nux::SleepForMilliseconds(1000);

  nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);

  NuxAutomatedTestFramework test(wnd_thread);

  test.Startup();

  // Set the mouse at coordinates (0, 0) (top-left corner) on the display
  test.PutMouseAt(0, 0);

  test.TestReportMsg(key_navigation_test->vlayout_, "TestView created");
  test.TestReportMsg(key_navigation_test->views_[0]->has_focus_, "Top left tile has key focus");
  
  // Down key
  for (int i=0; i<NUM_VIEWS-1; ++i)
  {
    test.SendFakeKeyEvent(XK_Down, 0);
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(!key_navigation_test->views_[i]->has_focus_, "Down: key focus out");
    if ((i + 1) == ID_UNFOCUSABLE_VIEW)
    {
      test.TestReportMsg(!key_navigation_test->views_[i+1]->has_focus_, "Down: key focus skipped");
      test.TestReportMsg(key_navigation_test->views_[i+2]->has_focus_, "Down: key focus in");
      ++i;
    }
    else
    {
      test.TestReportMsg(key_navigation_test->views_[i+1]->has_focus_, "Down: key focus in");
    }
  }
  
  // Another down key, should do nothing
  test.SendFakeKeyEvent(XK_Down, 0);
  nux::SleepForMilliseconds(500);
  test.TestReportMsg(key_navigation_test->views_[NUM_VIEWS-1]->has_focus_, "Down key, last element");
  
  // Up key
  for (int i=NUM_VIEWS-1; i>0; --i)
  {
    test.SendFakeKeyEvent(XK_Up, 0);
    nux::SleepForMilliseconds(500);
    test.TestReportMsg(!key_navigation_test->views_[i]->has_focus_, "Up: key focus out");
    if ((i - 1) == ID_UNFOCUSABLE_VIEW)
    {
      test.TestReportMsg(!key_navigation_test->views_[i-1]->has_focus_, "Up: key focus skipped");
      test.TestReportMsg(key_navigation_test->views_[i-2]->has_focus_, "Up: key focus in");
      --i;
    }
    else
    {
      test.TestReportMsg(key_navigation_test->views_[i-1]->has_focus_, "Up: key focus in");
    }
  }
  
  // Another up key, should do nothing
  test.SendFakeKeyEvent(XK_Up, 0);
  nux::SleepForMilliseconds(500);
  test.TestReportMsg(key_navigation_test->views_[0]->has_focus_, "Up key, fist element");
  
   // Keft key, should do nothing
  test.SendFakeKeyEvent(XK_Left, 0);
  nux::SleepForMilliseconds(500);
  test.TestReportMsg(key_navigation_test->views_[0]->has_focus_, "Left key");
  
   // Right key, should do nothing
  test.SendFakeKeyEvent(XK_Right, 0);
  nux::SleepForMilliseconds(500);
  test.TestReportMsg(key_navigation_test->views_[0]->has_focus_, "Right key");


  if (test.WhenDoneTerminateProgram())
  {
    nux::SleepForMilliseconds(1000);
    wnd_thread->ExitMainLoop();
  }
  nuxDebugMsg("Exit testing thread");
}

Here is the call graph for this function:


Variable Documentation

unsigned int const ID_UNFOCUSABLE_VIEW = 1

Definition at line 31 of file xtest-vlayout-key-navigation.cpp.

Definition at line 92 of file xtest-vlayout-key-navigation.cpp.

unsigned int const NUM_VIEWS = 5

Definition at line 30 of file xtest-vlayout-key-navigation.cpp.