Back to index

nux  3.0.0
xtest-mouse-buttons.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00018  *
00019  */
00020 
00021 #include "Nux/Nux.h"
00022 #include "Nux/WindowThread.h"
00023 #include "Nux/VLayout.h"
00024 #include "Nux/Layout.h"
00025 #include "Nux/ProgramFramework/ProgramTemplate.h"
00026 #include "Nux/ProgramFramework/TestView.h"
00027 #include <X11/extensions/XTest.h>
00028 #include <X11/keysym.h> 
00029 #include "nux_automated_test_framework.h"
00030 
00031 class ButtonEventsTest: public ProgramTemplate
00032 {
00033 public:
00034   ButtonEventsTest(const char* program_name, int window_width, int window_height, int program_life_span);
00035   ~ButtonEventsTest();
00036 
00037   virtual void UserInterfaceSetup();
00038   
00039   void ResetEvents();
00040   nux::TestView* test_view_;
00041 };
00042 
00043 ButtonEventsTest::ButtonEventsTest(const char* program_name,
00044   int window_width,
00045   int window_height,
00046   int program_life_span)
00047 : ProgramTemplate(program_name, window_width, window_height, program_life_span)
00048 {
00049   ResetEvents();
00050   test_view_ = NULL;
00051 }
00052 
00053 ButtonEventsTest::~ButtonEventsTest()
00054 {
00055   
00056 }
00057 
00058 void ButtonEventsTest::ResetEvents()
00059 {
00060   if (test_view_)
00061     test_view_->ResetEvents();
00062 }
00063 
00064 void ButtonEventsTest::UserInterfaceSetup()
00065 {
00066   nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00067   test_view_ = new nux::TestView(NUX_TRACKER_LOCATION);
00068 
00069   main_layout->AddView(test_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00070   main_layout->SetPadding(10, 10);
00071 
00072   static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
00073   
00074   nux::ColorLayer background(nux::Color(0xFF4D4D4D));
00075   static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
00076 }
00077 
00078 ButtonEventsTest* button_event_test = NULL;
00079 
00080 void TestingThread(nux::NThread* thread, void* user_data)
00081 {
00082   while (button_event_test->ReadyToGo() == false)
00083   {
00084     nuxDebugMsg("Waiting to start");
00085     nux::SleepForMilliseconds(300);
00086   }
00087 
00088   nux::SleepForMilliseconds(1000);
00089 
00090   nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
00091 
00092   NuxAutomatedTestFramework test(wnd_thread);
00093 
00094   test.Startup();
00095 
00096   // Set the mouse at coordinates (0, 0) (top-left corner) on the display
00097   test.PutMouseAt(0, 0);
00098 
00099   test.TestReportMsg(button_event_test->test_view_, "TestView created");
00100 
00101   
00102   // Move mouse to center of the view
00103   test.ViewSendMouseMotionToCenter(button_event_test->test_view_);
00104 
00105   // Mouse click with button 1
00106   button_event_test->ResetEvents();
00107   test.ViewSendMouseClick(button_event_test->test_view_, 1);
00108   test.TestReportMsg(button_event_test->test_view_->registered_mouse_down_, "Mouse button 1 down");
00109   test.TestReportMsg(button_event_test->test_view_->registered_mouse_up_, "Mouse button 1 up");
00110 
00111   // Mouse click with button 2
00112   button_event_test->ResetEvents();
00113   test.ViewSendMouseClick(button_event_test->test_view_, 2);
00114   test.TestReportMsg(button_event_test->test_view_->registered_mouse_down_, "Mouse button 2 down");
00115   test.TestReportMsg(button_event_test->test_view_->registered_mouse_up_, "Mouse button 2 up");
00116 
00117   // Mouse click with button 3
00118   button_event_test->ResetEvents();
00119   test.ViewSendMouseClick(button_event_test->test_view_, 3);
00120   test.TestReportMsg(button_event_test->test_view_->registered_mouse_down_, "Mouse button 3 down");
00121   test.TestReportMsg(button_event_test->test_view_->registered_mouse_up_, "Mouse button 3 up");
00122 
00123   // Mouse click with button 4
00124   button_event_test->ResetEvents();
00125   test.ViewSendMouseClick(button_event_test->test_view_, 4);
00126   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_down_, "Mouse button 4 down");
00127   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_up_, "Mouse button 4 up");
00128 
00129   // Mouse click with button 5
00130   button_event_test->ResetEvents();
00131   test.ViewSendMouseClick(button_event_test->test_view_, 5);
00132   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_down_, "Mouse button 5 down");
00133   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_up_, "Mouse button 5 up");
00134 
00135   // Mouse click with button 6
00136   button_event_test->ResetEvents();
00137   test.ViewSendMouseClick(button_event_test->test_view_, 6);
00138   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_down_, "Mouse button 6 down");
00139   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_up_, "Mouse button 6 up");
00140 
00141   // Mouse click with button 7
00142   button_event_test->ResetEvents();
00143   test.ViewSendMouseClick(button_event_test->test_view_, 7);
00144   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_down_, "Mouse button 7 down");
00145   test.TestReportMsg(!button_event_test->test_view_->registered_mouse_up_, "Mouse button 7 up");
00146 
00147   if (test.WhenDoneTerminateProgram())
00148   {
00149     nux::SleepForMilliseconds(1000);
00150     wnd_thread->ExitMainLoop();
00151   }
00152   nuxDebugMsg("Exit testing thread");
00153 }
00154 
00155 int main(int argc, char** argv)
00156 {
00157   int xstatus = XInitThreads();
00158   nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
00159 
00160   button_event_test = new ButtonEventsTest("Events Test", 300, 300, 30000);
00161   button_event_test->Startup();
00162   button_event_test->UserInterfaceSetup();
00163 
00164   nux::SystemThread* test_thread = nux::CreateSystemThread(button_event_test->GetWindowThread(), &TestingThread, button_event_test->GetWindowThread());
00165 
00166   test_thread->Start(button_event_test);
00167 
00168   button_event_test->Run();
00169 
00170   delete test_thread;
00171   delete button_event_test;
00172 
00173   return 0;
00174 }
00175