Back to index

nux  3.0.0
xtest-button.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/Button.h"
00025 #include "Nux/ProgramFramework/ProgramTemplate.h"
00026 #include <X11/extensions/XTest.h>
00027 #include <X11/keysym.h> 
00028 #include "nux_automated_test_framework.h"
00029 
00030 class TestButton: public ProgramTemplate
00031 {
00032 public:
00033   TestButton(const char* program_name, int window_width, int window_height, int program_life_span);
00034   ~TestButton();
00035 
00036   virtual void UserInterfaceSetup();
00037 
00038   void ButtonClick(nux::Button* button);
00039   void ResetEvents();
00040   nux::Button* button_;
00041 
00042   bool clicked_;
00043 };
00044 
00045 TestButton::TestButton(const char* program_name,
00046   int window_width,
00047   int window_height,
00048   int program_life_span)
00049 : ProgramTemplate(program_name, window_width, window_height, program_life_span)
00050 {
00051   ResetEvents();
00052   button_ = NULL;
00053 }
00054 
00055 TestButton::~TestButton()
00056 {
00057   
00058 }
00059 
00060 void TestButton::ResetEvents()
00061 {
00062   clicked_ = false;
00063 }
00064 
00065 void TestButton::ButtonClick(nux::Button* button)
00066 {
00067   if (button_ == button)
00068   {
00069     clicked_ = true;
00070   }
00071 }
00072 
00073 void TestButton::UserInterfaceSetup()
00074 {
00075   nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
00076   button_ = new nux::Button("NUX", NUX_TRACKER_LOCATION);
00077   button_->SetLabelFontSize(76);
00078 
00079   main_layout->AddView(button_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_MATCHCONTENT);
00080   main_layout->SetVerticalInternalMargin(10);
00081   main_layout->SetContentDistribution(nux::MAJOR_POSITION_CENTER);
00082 
00083   button_->click.connect(sigc::mem_fun(this, &TestButton::ButtonClick));
00084 
00085   static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout);
00086   
00087   nux::ColorLayer background(nux::Color(0xFF4D4D4D));
00088   static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
00089 }
00090 
00091 TestButton* test_button = NULL;
00092 
00093 void TestingThread(nux::NThread* thread, void* user_data)
00094 {
00095   while (test_button->ReadyToGo() == false)
00096   {
00097     nuxDebugMsg("Waiting to start");
00098     nux::SleepForMilliseconds(300);
00099   }
00100 
00101   nux::SleepForMilliseconds(1300);
00102 
00103   nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
00104 
00105   NuxAutomatedTestFramework test(wnd_thread);
00106 
00107   test.Startup();
00108 
00109   test.TestReportMsg(test_button->button_, "Button created");
00110 
00111   test_button->ResetEvents();
00112   test.ViewSendMouseMotionToCenter(test_button->button_);
00113   test.ViewSendMouseClick(0, 1);
00114 
00115   nux::SleepForMilliseconds(1000);
00116   test.TestReportMsg(test_button->clicked_, "Button clicked");
00117 
00118   if (test.WhenDoneTerminateProgram())
00119   {
00120     wnd_thread->ExitMainLoop();
00121   }
00122   nuxDebugMsg("Exit testing thread");
00123 }
00124 
00125 int main(int argc, char** argv)
00126 {
00127   int xstatus = XInitThreads();
00128   nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
00129 
00130   test_button = new TestButton("Button XTest", 300, 300, 10000);
00131   test_button->Startup();
00132   test_button->UserInterfaceSetup();
00133 
00134   nux::SystemThread* test_thread = nux::CreateSystemThread(NULL, &TestingThread, test_button->GetWindowThread());
00135 
00136   test_thread->Start(test_button);
00137 
00138   test_button->Run();
00139 
00140   delete test_thread;
00141   delete test_button;
00142 
00143   //nuxDebugMsg("Exit program");
00144   return 0;
00145 }
00146