529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
1 |
/*
|
2 |
* Copyright 2011 Inalogic Inc.
|
|
3 |
*
|
|
4 |
* This program is free software: you can redistribute it and/or modify it
|
|
5 |
* under the terms of the GNU General Public License version 3, as published
|
|
6 |
* by the Free Software Foundation.
|
|
7 |
*
|
|
8 |
* This program is distributed in the hope that it will be useful, but
|
|
9 |
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
10 |
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
|
|
11 |
* PURPOSE. See the GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License
|
|
14 |
* version 3 along with this program. If not, see
|
|
15 |
* <http://www.gnu.org/licenses/>
|
|
16 |
*
|
|
17 |
* Authored by: Andrea Azzarone <azzaronea@gmail.com>
|
|
18 |
*
|
|
19 |
*/
|
|
20 |
||
21 |
#include "Nux/Nux.h" |
|
22 |
#include "Nux/WindowThread.h" |
|
23 |
#include "Nux/VLayout.h" |
|
544.7.3
by Jay Taoko
* Renamed the TextFramework directory to ProgramFramework as this is a facility that can be use to write any type of programs, not just tests. |
24 |
#include "Nux/ProgramFramework/ProgramTemplate.h" |
25 |
#include "Nux/ProgramFramework/TestView.h" |
|
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
26 |
#include <X11/extensions/XTest.h> |
27 |
#include <X11/keysym.h> |
|
28 |
#include "nux_automated_test_framework.h" |
|
29 |
||
544.7.3
by Jay Taoko
* Renamed the TextFramework directory to ProgramFramework as this is a facility that can be use to write any type of programs, not just tests. |
30 |
class FocusOnMouseDownTest: public ProgramTemplate |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
31 |
{
|
32 |
public: |
|
544.7.1
by Jay Taoko
* Renamed automated tests source files with and "xtest-" prefix |
33 |
FocusOnMouseDownTest(const char* program_name, int window_width, int window_height, int program_life_span); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
34 |
~FocusOnMouseDownTest(); |
35 |
||
36 |
virtual void UserInterfaceSetup(); |
|
37 |
||
575.5.5
by Jay Taoko
|
38 |
nux::TestView* focus_view_; |
39 |
nux::TestView* no_focus_view_; |
|
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
40 |
};
|
41 |
||
42 |
FocusOnMouseDownTest::FocusOnMouseDownTest(const char* program_name, |
|
43 |
int window_width, |
|
44 |
int window_height, |
|
45 |
int program_life_span) |
|
544.7.3
by Jay Taoko
* Renamed the TextFramework directory to ProgramFramework as this is a facility that can be use to write any type of programs, not just tests. |
46 |
: ProgramTemplate(program_name, window_width, window_height, program_life_span) |
544.7.1
by Jay Taoko
* Renamed automated tests source files with and "xtest-" prefix |
47 |
, focus_view_(nullptr) |
48 |
, no_focus_view_(nullptr) |
|
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
49 |
{
|
50 |
}
|
|
51 |
||
52 |
FocusOnMouseDownTest::~FocusOnMouseDownTest() |
|
53 |
{
|
|
54 |
}
|
|
55 |
||
56 |
void FocusOnMouseDownTest::UserInterfaceSetup() |
|
57 |
{
|
|
58 |
nux::VLayout* main_layout = new nux::VLayout(NUX_TRACKER_LOCATION); |
|
59 |
main_layout->SetSpaceBetweenChildren(10); |
|
60 |
main_layout->SetPadding(10, 10); |
|
61 |
||
575.5.5
by Jay Taoko
|
62 |
focus_view_ = new nux::TestView(NUX_TRACKER_LOCATION); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
63 |
focus_view_->can_focus_ = true; |
529.3.4
by Andrea Azzarone
Fixes. |
64 |
focus_view_->SetAcceptKeyNavFocusOnMouseDown(true); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
65 |
main_layout->AddView(focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
66 |
||
575.5.5
by Jay Taoko
|
67 |
no_focus_view_ = new nux::TestView(NUX_TRACKER_LOCATION); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
68 |
no_focus_view_->can_focus_ = true; |
529.3.4
by Andrea Azzarone
Fixes. |
69 |
no_focus_view_->SetAcceptKeyNavFocusOnMouseDown(false); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
70 |
main_layout->AddView(no_focus_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
71 |
||
72 |
static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout); |
|
73 |
||
74 |
nux::ColorLayer background(nux::Color(0xFF4D4D4D)); |
|
75 |
static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background); |
|
76 |
}
|
|
77 |
||
78 |
FocusOnMouseDownTest* focus_on_mouse_down_test = nullptr; |
|
79 |
||
667.2.1
by Michi Henning
Added -Wextra to compiler flags. Fixed a large number of warnings about unused parameters. Fixes #1056633. |
80 |
void TestingThread(nux::NThread* /* thread */, void* user_data) |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
81 |
{
|
82 |
while (focus_on_mouse_down_test->ReadyToGo() == false) |
|
83 |
{
|
|
84 |
nuxDebugMsg("Waiting to start"); |
|
85 |
nux::SleepForMilliseconds(300); |
|
86 |
}
|
|
87 |
||
88 |
nux::SleepForMilliseconds(1000); |
|
89 |
||
544.7.1
by Jay Taoko
* Renamed automated tests source files with and "xtest-" prefix |
90 |
nux::WindowThread* wnd_thread = static_cast<nux::WindowThread*>(user_data); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
91 |
|
92 |
NuxAutomatedTestFramework test(wnd_thread); |
|
93 |
||
94 |
test.Startup(); |
|
95 |
||
96 |
// Set the mouse at coordinates (0, 0) (top-left corner) on the display
|
|
97 |
test.PutMouseAt(0, 0); |
|
98 |
||
99 |
test.TestReportMsg(focus_on_mouse_down_test->focus_view_, "Focus view created"); |
|
100 |
test.TestReportMsg(focus_on_mouse_down_test->no_focus_view_, "No focus view created"); |
|
101 |
||
102 |
// Move mouse to center of focus_view
|
|
103 |
test.ViewSendMouseMotionToCenter(focus_on_mouse_down_test->focus_view_); |
|
104 |
||
105 |
// Mouse down/up on focus_view_
|
|
106 |
test.ViewSendMouseClick(focus_on_mouse_down_test->focus_view_, 1); |
|
107 |
nux::SleepForMilliseconds(500); |
|
108 |
test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse down: focus_view_ got the focus"); |
|
109 |
test.ViewSendMouseUp(focus_on_mouse_down_test->focus_view_, 1); |
|
110 |
nux::SleepForMilliseconds(500); |
|
111 |
test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse up: focus is still on focus_view_"); |
|
112 |
||
113 |
// Move mouse to center of no_focus_view
|
|
114 |
test.ViewSendMouseMotionToCenter(focus_on_mouse_down_test->no_focus_view_); |
|
115 |
||
116 |
// Mouse down/up on no_focus_view_
|
|
117 |
test.ViewSendMouseDown(focus_on_mouse_down_test->no_focus_view_, 1); |
|
118 |
nux::SleepForMilliseconds(500); |
|
119 |
test.TestReportMsg(!focus_on_mouse_down_test->no_focus_view_->has_focus_, "Mouse down: no_focus_view_ did not take the focus"); |
|
120 |
test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse down: focus is still on focus_view_"); |
|
121 |
test.ViewSendMouseUp(focus_on_mouse_down_test->no_focus_view_, 1); |
|
122 |
nux::SleepForMilliseconds(500); |
|
123 |
test.TestReportMsg(!focus_on_mouse_down_test->no_focus_view_->has_focus_, "Mouse up: no_focus_view_ still doesn't have the focus"); |
|
124 |
test.TestReportMsg(focus_on_mouse_down_test->focus_view_->has_focus_, "Mouse up: focus is still on focus_view_"); |
|
125 |
||
126 |
||
127 |
if (test.WhenDoneTerminateProgram()) |
|
128 |
{
|
|
129 |
nux::SleepForMilliseconds(1000); |
|
532.1.1
by Andrea Azzarone
Adds the possiblity to don't get the focus on mouse down. |
130 |
wnd_thread->ExitMainLoop(); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
131 |
}
|
132 |
nuxDebugMsg("Exit testing thread"); |
|
133 |
}
|
|
134 |
||
667.2.1
by Michi Henning
Added -Wextra to compiler flags. Fixed a large number of warnings about unused parameters. Fixes #1056633. |
135 |
int main() |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
136 |
{
|
667.2.3
by Michi Henning
Removed a bunch more warnings that appeared only when building in release mode. |
137 |
XInitThreads(); |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
138 |
|
139 |
focus_on_mouse_down_test = new FocusOnMouseDownTest("Focus On Mouse Down Test", 300, 300, 15000); |
|
140 |
focus_on_mouse_down_test->Startup(); |
|
141 |
focus_on_mouse_down_test->UserInterfaceSetup(); |
|
142 |
||
544.7.1
by Jay Taoko
* Renamed automated tests source files with and "xtest-" prefix |
143 |
nux::SystemThread* test_thread = nux::CreateSystemThread(focus_on_mouse_down_test->GetWindowThread(), |
529.3.2
by Andrea Azzarone
Add a simple test for AcceptKeyNavOnMouseDown. |
144 |
&TestingThread, |
145 |
focus_on_mouse_down_test->GetWindowThread()); |
|
146 |
||
147 |
test_thread->Start(focus_on_mouse_down_test); |
|
148 |
||
149 |
focus_on_mouse_down_test->Run(); |
|
150 |
||
151 |
delete test_thread; |
|
152 |
delete focus_on_mouse_down_test; |
|
153 |
||
154 |
return 0; |
|
155 |
}
|
|
156 |