Back to index

nux  3.0.0
xtest-scrollbar.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011 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: Andrea Azzarone <azzaronea@gmail.com>
00018  *
00019  */
00020 
00021 #include "Nux/Nux.h"
00022 #include "Nux/WindowThread.h"
00023 #include "Nux/VLayout.h"
00024 #include "Nux/ProgramFramework/ProgramTemplate.h"
00025 #include "Nux/ProgramFramework/TestView.h"
00026 #include <X11/extensions/XTest.h>
00027 #include <X11/keysym.h> 
00028 #include "nux_automated_test_framework.h"
00029 #include "test-scrollview.h"
00030 
00031 class ScrollBarTest: public ProgramTemplate
00032 {
00033 public:
00034   ScrollBarTest(const char* program_name, int window_width, int window_height, int program_life_span);
00035   ~ScrollBarTest();
00036 
00037   virtual void UserInterfaceSetup();
00038   
00039   nux::VLayout* layout_;
00040   TestScrollView* scroll_view_;
00041   nux::VLayout* in_layout_;
00042   nux::TestView* test_view_;
00043 };
00044 
00045 ScrollBarTest::ScrollBarTest(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 }
00052 
00053 ScrollBarTest::~ScrollBarTest()
00054 {
00055 }
00056 
00057 void ScrollBarTest::UserInterfaceSetup()
00058 {  
00059   layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
00060   layout_->SetPadding(20, 20);
00061 
00062   scroll_view_ = new TestScrollView();
00063   layout_->AddView(scroll_view_);
00064   
00065   in_layout_ = new nux::VLayout(NUX_TRACKER_LOCATION);
00066   scroll_view_->SetLayout(in_layout_);
00067   
00068   test_view_ = new nux::TestView();
00069   test_view_->SetMinimumHeight(1000);
00070   in_layout_->AddView(test_view_);
00071   
00072   static_cast<nux::WindowThread*>(window_thread_)->SetLayout(layout_);
00073   
00074   nux::ColorLayer background(nux::Color(0xFF4D4D4D));
00075   static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background);
00076 }
00077 
00078 ScrollBarTest* scrollbar_test;
00079 
00080 void TestingThread(nux::NThread* thread, void* user_data)
00081 {
00082   while (scrollbar_test->ReadyToGo() == false)
00083   {
00084     nuxDebugMsg("Waiting to start");
00085     nux::SleepForMilliseconds(300);
00086   }
00087   nux::SleepForMilliseconds(1000);
00088 
00089   nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data);
00090   NuxAutomatedTestFramework test(wnd_thread);
00091   test.Startup();
00092 
00093   test.TestReportMsg(scrollbar_test->scroll_view_, "TestScrollView created");
00094   
00095   scrollbar_test->scroll_view_->ResetEvents();
00096   test.ViewSendMouseMotionToCenter(scrollbar_test->scroll_view_);
00097   test.ViewSendMouseClick(scrollbar_test->scroll_view_, 4);
00098   nux::SleepForMilliseconds(1000);
00099   test.TestReportMsg(scrollbar_test->scroll_view_->registered_scroll_, "Scroll on the center of the scrollview");
00100   
00101   
00102   scrollbar_test->scroll_view_->ResetEvents();
00103   test.ViewSendMouseMotionToCenter(scrollbar_test->scroll_view_->GetVScrollbar());
00104   test.ViewSendMouseClick(scrollbar_test->scroll_view_->GetVScrollbar(), 4);
00105   nux::SleepForMilliseconds(1000);
00106   test.TestReportMsg(scrollbar_test->scroll_view_->registered_scroll_, "Scroll on the scrollbar");
00107 
00108   if (test.WhenDoneTerminateProgram())
00109   {
00110     nux::SleepForMilliseconds(1000);
00111     wnd_thread->ExitMainLoop();
00112   }
00113   nuxDebugMsg("Exit testing thread");
00114 }
00115 
00116 int main(int argc, char** argv)
00117 {
00118   int xstatus = XInitThreads();
00119   nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
00120 
00121   scrollbar_test = new ScrollBarTest("Scrollbar Test", 500, 400, 13000);
00122   scrollbar_test->Startup();
00123   scrollbar_test->UserInterfaceSetup();
00124 
00125   nux::SystemThread* test_thread = nux::CreateSystemThread(scrollbar_test->GetWindowThread(), &TestingThread, scrollbar_test->GetWindowThread());
00126 
00127   test_thread->Start(scrollbar_test);
00128 
00129   scrollbar_test->Run();
00130 
00131   delete test_thread;
00132   delete scrollbar_test;
00133 
00134   return 0;
00135 }
00136