Back to index

nux  3.0.0
xtest-mouse-events.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 
00032 class EventsTest: public ProgramTemplate
00033 {
00034 public:
00035   EventsTest(const char* program_name, int window_width, int window_height, int program_life_span);
00036   ~EventsTest();
00037 
00038   virtual void UserInterfaceSetup();
00039   
00040   void ResetEvents();
00041   nux::TestView* test_view_;
00042 };
00043 
00044 EventsTest::EventsTest(const char* program_name,
00045   int window_width,
00046   int window_height,
00047   int program_life_span)
00048 : ProgramTemplate(program_name, window_width, window_height, program_life_span)
00049 {
00050   ResetEvents();
00051   test_view_ = NULL;
00052 }
00053 
00054 EventsTest::~EventsTest()
00055 {
00056   
00057 }
00058 
00059 void EventsTest::ResetEvents()
00060 {
00061   if (test_view_)
00062     test_view_->ResetEvents();
00063 }
00064 
00065 void EventsTest::UserInterfaceSetup()
00066 {
00067   nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00068   test_view_ = new nux::TestView(NUX_TRACKER_LOCATION);
00069 
00070   main_layout->AddView(test_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
00071   main_layout->SetPadding(10, 10);
00072 
00073   static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
00074   
00075   nux::ColorLayer background(nux::Color(0xFF4D4D4D));
00076   static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
00077 }
00078 
00079 EventsTest* event_test = NULL;
00080 
00081 void TestingThread(nux::NThread* thread, void* user_data)
00082 {
00083   while (event_test->ReadyToGo() == false)
00084   {
00085     nuxDebugMsg("Waiting to start");
00086     nux::SleepForMilliseconds(300);
00087   }
00088 
00089   nux::SleepForMilliseconds(1000);
00090 
00091   nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
00092 
00093   NuxAutomatedTestFramework test(wnd_thread);
00094 
00095   test.Startup();
00096 
00097   // Set the mouse at coordinates (0, 0) (top-left corner) on the display
00098   test.PutMouseAt(0, 0);
00099 
00100   test.TestReportMsg(event_test->test_view_, "TestView created");
00101 
00102   event_test->ResetEvents();
00103   test.ViewSendMouseMotionToCenter(event_test->test_view_);
00104 
00105   test.TestReportMsg(event_test->test_view_->registered_mouse_move_, "Mouse move event");
00106   test.TestReportMsg(event_test->test_view_->registered_mouse_enter_, "Mouse enter event");
00107   test.ViewSendMouseClick(0, 1);
00108 
00109   test.TestReportMsg(event_test->test_view_->registered_mouse_down_, "Mouse down event");
00110   test.TestReportMsg(event_test->test_view_->registered_mouse_up_, "Mouse up event");
00111   test.TestReportMsg(event_test->test_view_->registered_mouse_click_, "Mouse click event");
00112 
00113   test.ViewSendMouseDrag(event_test->test_view_, 1, 0, 0, 50, 50);
00114   test.TestReportMsg(event_test->test_view_->registered_mouse_click_, "Mouse drag event");
00115 
00116   test.ViewSendMouseMotionTo(event_test->test_view_, -5, -5);
00117   test.TestReportMsg(event_test->test_view_->registered_mouse_leave_, "Mouse leave event");
00118 
00119   event_test->test_view_->EnableDoubleClick(true);
00120   test.ViewSendMouseDoubleClick(event_test->test_view_, 1);
00121   test.TestReportMsg(event_test->test_view_->registered_mouse_double_click_, "Mouse double click event");
00122 
00123   event_test->ResetEvents();
00124   // Deactivate double click and test if the view still receives it.
00125   event_test->test_view_->EnableDoubleClick(false);
00126   test.ViewSendMouseDoubleClick(event_test->test_view_, 1);
00127   test.TestReportMsg(!event_test->test_view_->registered_mouse_double_click_, "Mouse double click de-activated");
00128 
00129   if (test.WhenDoneTerminateProgram())
00130   {
00131     nux::SleepForMilliseconds(1000);
00132     wnd_thread->ExitMainLoop();
00133   }
00134   nuxDebugMsg("Exit testing thread");
00135 }
00136 
00137 int main(int argc, char** argv)
00138 {
00139   int xstatus = XInitThreads();
00140   nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
00141 
00142   event_test = new EventsTest("Events Test", 300, 300, 20000);
00143   event_test->Startup();
00144   event_test->UserInterfaceSetup();
00145 
00146   nux::SystemThread* test_thread = nux::CreateSystemThread(event_test->GetWindowThread(), &TestingThread, event_test->GetWindowThread());
00147 
00148   test_thread->Start(event_test);
00149 
00150   event_test->Run();
00151 
00152   delete test_thread;
00153   delete event_test;
00154 
00155   return 0;
00156 }
00157