Merge lp:~unity-team/nux/nux-fix-708020 into lp:nux/2.0
- nux-fix-708020
- Merge into 2.0
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Jay Taoko | ||||
Approved revision: | 523 | ||||
Merged at revision: | 523 | ||||
Proposed branch: | lp:~unity-team/nux/nux-fix-708020 | ||||
Merge into: | lp:nux/2.0 | ||||
Diff against target: |
855 lines (+524/-43) 12 files modified
Nux/Layout.cpp (+18/-0) Nux/Layout.h (+21/-2) NuxGraphics/GraphicsDisplayX11.cpp (+40/-25) NuxGraphics/GraphicsDisplayX11.h (+10/-1) tests/Makefile.am (+9/-2) tests/Readme.txt (+29/-2) tests/button-xtest.cpp (+1/-1) tests/mouse-events-test.cpp (+156/-0) tests/nux_automated_test_framework.cpp (+43/-7) tests/nux_automated_test_framework.h (+14/-3) tests/test-view.cpp (+132/-0) tests/test-view.h (+51/-0) |
||||
To merge this branch: | bzr merge lp:~unity-team/nux/nux-fix-708020 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Penhey (community) | Approve | ||
Review via email: mp+83109@code.launchpad.net |
Commit message
Description of the change
* Added automated tests from mouse events
* Fixed double-click event: bug #708020
* Fixed: added missing functions in Layout.cpp/.h
Sam Spilsbury (smspillaz) wrote : | # |
On Thu, Nov 24, 2011 at 11:56 AM, Tim Penhey <email address hidden> wrote:
> Review: Needs Information
>
>
> It looks like this test is testing multiple things. You are defining shaders
> and recording events.
The shaders in this case look like core profile shaders, eg, what's
required to make the thing render anything at all.
>
> --
> https:/
> Your team Unity Team is subscribed to branch lp:nux.
>
--
Sam Spilsbury
Jay Taoko (jaytaoko) wrote : | # |
> Can I strongly suggest that you reorder the two parameter SetPadding?
> CSS for two values has (top and bottom, left and right) as the pair.
> It would be nice to have consistency here.
>
Will do.
> It also appears that the double click time is hard coded. Is there any way to
> query the system? Can people configure their double click time?
Yes, it is hard-coded for now. I need to figure out where to get it from, or simply let Unity set it.
> Re: line 425, why sleep for a second once you have been told that the test is
> ready to go?
>
> Also, why sleep for a second before terminating? This is just strange.
Due to the asynchronous nature of X, I have to resort to this. I spent some time trying to figure when I can be certain that a window is realized. But that is hard to do.
The tests are very sensible to timings. I do the need to sleep the testing thread to leave some time for the window thread to finish processing events.
> What is the purpose of tests/test-
>
> Perhpas a comment at the top of the test file as to its purpose would help a
> lot.
Will do.
> It looks like this test is testing multiple things. You are defining shaders
> and recording events.
Only using a shader, not testing it. The TestView class will be re-used when I do rendering tests.
Jay Taoko (jaytaoko) wrote : | # |
>
> It looks like this test is testing multiple things. You are defining shaders
> and recording events.
I realized that the test will not work if the system does not have GLSL shaders support. So I am removing the shader code and using Nux custom drawing code (that supports both GLSL and ARB assembly programs).
Tim Penhey (thumper) wrote : | # |
> void Layout:
> {
> top_padding_ = top_bottom_padding < 0 ? 0 : top_bottom_padding;
> bottom_padding_ = top_bottom_padding;
Surely that should be:
bottom_padding_ = top_padding_;
Jay Taoko (jaytaoko) wrote : | # |
> > void Layout:
> > {
> > top_padding_ = top_bottom_padding < 0 ? 0 : top_bottom_padding;
> > bottom_padding_ = top_bottom_padding;
>
> Surely that should be:
> bottom_padding_ = top_padding_;
Right! will fix!
Preview Diff
1 | === modified file 'Nux/Layout.cpp' |
2 | --- Nux/Layout.cpp 2011-10-17 20:57:35 +0000 |
3 | +++ Nux/Layout.cpp 2011-11-25 05:03:26 +0000 |
4 | @@ -120,6 +120,24 @@ |
5 | bottom_padding_ = bottom < 0 ? 0 : bottom; |
6 | } |
7 | |
8 | + void Layout::SetPadding(int padding) |
9 | + { |
10 | + top_padding_ = padding < 0 ? 0 : padding; |
11 | + bottom_padding_ = top_padding_; |
12 | + right_padding_ = top_padding_; |
13 | + left_padding_ = top_padding_; |
14 | + } |
15 | + |
16 | + void Layout::SetPadding(int top_bottom_padding, int left_right_padding) |
17 | + { |
18 | + top_padding_ = top_bottom_padding < 0 ? 0 : top_bottom_padding; |
19 | + bottom_padding_ = top_padding_; |
20 | + |
21 | + right_padding_ = left_right_padding < 0 ? 0 : left_right_padding; |
22 | + left_padding_ = right_padding_; |
23 | + } |
24 | + |
25 | + |
26 | void Layout::SetPadding(int top, int right, int bottom, int left) |
27 | { |
28 | top_padding_ = top < 0 ? 0 : top; |
29 | |
30 | === modified file 'Nux/Layout.h' |
31 | --- Nux/Layout.h 2011-10-10 01:52:00 +0000 |
32 | +++ Nux/Layout.h 2011-11-25 05:03:26 +0000 |
33 | @@ -117,10 +117,10 @@ |
34 | Set the left/right and top/bottom padding of the layout. \n |
35 | Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout. |
36 | |
37 | + @param top_bottom_padding The top/bottom padding value of the layout. |
38 | @param left_right_padding The left/right padding value of the layout. |
39 | - @param top_bottom_padding The top/bottom padding value of the layout. |
40 | */ |
41 | - void SetPadding(int left_right_padding, int top_bottom_padding); |
42 | + void SetPadding(int top_bottom_padding, int left_right_padding); |
43 | |
44 | virtual unsigned int GetMaxStretchFactor(); |
45 | unsigned int GetMinStretchFactor(); |
46 | @@ -143,8 +143,27 @@ |
47 | //! Deprecated. Use SetTopBottomPadding, |
48 | void SetVerticalExternalMargin(int m); |
49 | |
50 | + //! Set the left/right/top/bottom padding of the layout. |
51 | + /*! |
52 | + Set the left/right and top/bottom padding of the layout. \n |
53 | + Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout. |
54 | + |
55 | + @param top The top padding value of the layout. |
56 | + @param right The right padding value of the layout. |
57 | + @param bottom The bottom padding value of the layout. |
58 | + @param left The left padding value of the layout. |
59 | + */ |
60 | void SetPadding(int top, int right, int bottom, int left); |
61 | |
62 | + //! Set the left/right/top/bottom padding of the layout. |
63 | + /*! |
64 | + Set the left/right/top/bottom padding of the layout. \n |
65 | + Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout. |
66 | + |
67 | + @param padding The top/right/bottom/left padding value of the layout. |
68 | + */ |
69 | + void SetPadding(int padding); |
70 | + |
71 | int GetLeftPadding() const; |
72 | int GetRightPadding() const; |
73 | int GetTopPadding() const; |
74 | |
75 | === modified file 'NuxGraphics/GraphicsDisplayX11.cpp' |
76 | --- NuxGraphics/GraphicsDisplayX11.cpp 2011-11-22 07:13:53 +0000 |
77 | +++ NuxGraphics/GraphicsDisplayX11.cpp 2011-11-25 05:03:26 +0000 |
78 | @@ -39,24 +39,26 @@ |
79 | { |
80 | EventToNameStruct EventToName[] = |
81 | { |
82 | - {NUX_NO_EVENT, "NUX_NO_EVENT" }, |
83 | - {NUX_MOUSE_PRESSED, "NUX_MOUSE_PRESSED" }, |
84 | - {NUX_MOUSE_RELEASED, "NUX_MOUSE_RELEASED" }, |
85 | - {NUX_KEYDOWN, "NUX_KEYDOWN" }, |
86 | - {NUX_KEYUP, "NUX_KEYUP" }, |
87 | - {NUX_MOUSE_MOVE, "NUX_MOUSE_MOVE" }, |
88 | - {NUX_SIZE_CONFIGURATION, "NUX_SIZE_CONFIGURATION" }, |
89 | - {NUX_WINDOW_CONFIGURATION, "NUX_WINDOW_CONFIGURATION" }, |
90 | - {NUX_WINDOW_MAP, "NUX_WINDOW_MAP" }, |
91 | - {NUX_WINDOW_UNMAP, "NUX_WINDOW_UNMAP" }, |
92 | - {NUX_WINDOW_ENTER_FOCUS, "NUX_WINDOW_ENTER_FOCUS" }, |
93 | - {NUX_WINDOW_EXIT_FOCUS, "NUX_WINDOW_EXIT_FOCUS" }, |
94 | - {NUX_WINDOW_DIRTY, "NUX_WINDOW_DIRTY" }, |
95 | - {NUX_WINDOW_MOUSELEAVE, "NUX_WINDOW_MOUSELEAVE" }, |
96 | - {NUX_TERMINATE_APP, "NUX_TERMINATE_APP" }, |
97 | - {NUX_TAKE_FOCUS, "NUX_TAKE_FOCUS" } |
98 | + {NUX_NO_EVENT, "NO_EVENT" }, |
99 | + {NUX_MOUSE_PRESSED, "MOUSE_PRESSED" }, |
100 | + {NUX_MOUSE_RELEASED, "MOUSE_RELEASED" }, |
101 | + {NUX_KEYDOWN, "KEYDOWN" }, |
102 | + {NUX_KEYUP, "KEYUP" }, |
103 | + {NUX_MOUSE_MOVE, "MOUSE_MOVE" }, |
104 | + {NUX_SIZE_CONFIGURATION, "SIZE_CONFIGURATION" }, |
105 | + {NUX_WINDOW_CONFIGURATION, "WINDOW_CONFIGURATION" }, |
106 | + {NUX_WINDOW_MAP, "WINDOW_MAP" }, |
107 | + {NUX_WINDOW_UNMAP, "WINDOW_UNMAP" }, |
108 | + {NUX_WINDOW_ENTER_FOCUS, "WINDOW_ENTER_FOCUS" }, |
109 | + {NUX_WINDOW_EXIT_FOCUS, "WINDOW_EXIT_FOCUS" }, |
110 | + {NUX_WINDOW_DIRTY, "WINDOW_DIRTY" }, |
111 | + {NUX_WINDOW_MOUSELEAVE, "WINDOW_MOUSELEAVE" }, |
112 | + {NUX_TERMINATE_APP, "TERMINATE_APP" }, |
113 | + {NUX_TAKE_FOCUS, "TAKE_FOCUS" } |
114 | }; |
115 | |
116 | + int GraphicsDisplay::double_click_time_delay = 400; // milliseconds |
117 | + |
118 | GraphicsDisplay::GraphicsDisplay() |
119 | : m_X11Display(NULL) |
120 | , m_X11Screen(0) |
121 | @@ -78,6 +80,8 @@ |
122 | , m_ScreenBitDepth(32) |
123 | , m_GfxInterfaceCreated(false) |
124 | , m_BestMode(-1) |
125 | + , last_click_time_(0) |
126 | + , double_click_counter_(0) |
127 | , m_CreatedFromForeignWindow(false) |
128 | , m_num_device_modes(0) |
129 | , m_pEvent(NULL) |
130 | @@ -1002,7 +1006,7 @@ |
131 | m_GfxInterfaceCreated = false; |
132 | } |
133 | |
134 | - static int mouse_move(XEvent xevent, Event *m_pEvent) |
135 | + int GraphicsDisplay::MouseMove(XEvent xevent, Event *m_pEvent) |
136 | { |
137 | // Erase mouse event and mouse doubleclick events. Keep the mouse states. |
138 | unsigned int _mouse_state = m_pEvent->e_mouse_state & 0x0F000000; |
139 | @@ -1027,12 +1031,22 @@ |
140 | return 0; |
141 | } |
142 | |
143 | - static int mouse_press(XEvent xevent, Event *m_pEvent) |
144 | + int GraphicsDisplay::MousePress(XEvent xevent, Event *m_pEvent) |
145 | { |
146 | // Erase mouse event and mouse double-click events. Keep the mouse states. |
147 | ulong _mouse_state = m_pEvent->e_mouse_state & 0x0F000000; |
148 | |
149 | - m_pEvent->e_event = NUX_MOUSE_PRESSED; |
150 | + Time current_time = xevent.xbutton.time; |
151 | + if ((double_click_counter_ == 1) && (current_time - last_click_time_ < double_click_time_delay)) |
152 | + { |
153 | + m_pEvent->e_event = NUX_MOUSE_DOUBLECLICK; |
154 | + double_click_counter_ = 0; |
155 | + } |
156 | + else |
157 | + { |
158 | + m_pEvent->e_event = NUX_MOUSE_PRESSED; |
159 | + double_click_counter_ = 1; |
160 | + } |
161 | |
162 | // State of the button before the event |
163 | _mouse_state |= (xevent.xbutton.state & Button1Mask) ? NUX_STATE_BUTTON1_DOWN : 0; |
164 | @@ -1082,12 +1096,12 @@ |
165 | return 0; |
166 | } |
167 | |
168 | - static int mouse_release(XEvent xevent, Event *m_pEvent) |
169 | + int GraphicsDisplay::MouseRelease(XEvent xevent, Event *m_pEvent) |
170 | { |
171 | // Erase mouse event and mouse double-click events. Keep the mouse states. |
172 | ulong _mouse_state = m_pEvent->e_mouse_state & 0x0F000000; |
173 | |
174 | - m_pEvent->e_event = NUX_MOUSE_RELEASED; |
175 | + m_pEvent->e_event = NUX_MOUSE_RELEASED; |
176 | |
177 | // State of the button before the event |
178 | _mouse_state |= (xevent.xbutton.state & Button1Mask) ? NUX_STATE_BUTTON1_DOWN : 0; |
179 | @@ -1116,6 +1130,7 @@ |
180 | } |
181 | |
182 | m_pEvent->e_mouse_state = _mouse_state; |
183 | + last_click_time_ = xevent.xbutton.time; |
184 | |
185 | return 0; |
186 | } |
187 | @@ -1526,7 +1541,7 @@ |
188 | m_pEvent->e_x_root = 0; |
189 | m_pEvent->e_y_root = 0; |
190 | m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state); |
191 | - mouse_press(xevent, m_pEvent); |
192 | + MousePress(xevent, m_pEvent); |
193 | //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ButtonPress event."); |
194 | break; |
195 | } |
196 | @@ -1544,7 +1559,7 @@ |
197 | m_pEvent->e_x_root = 0; |
198 | m_pEvent->e_y_root = 0; |
199 | m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state); |
200 | - mouse_release(xevent, m_pEvent); |
201 | + MouseRelease(xevent, m_pEvent); |
202 | //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ButtonRelease event."); |
203 | break; |
204 | } |
205 | @@ -1562,7 +1577,7 @@ |
206 | m_pEvent->e_x_root = 0; |
207 | m_pEvent->e_y_root = 0; |
208 | m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state); |
209 | - mouse_move(xevent, m_pEvent); |
210 | + MouseMove(xevent, m_pEvent); |
211 | //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: MotionNotify event."); |
212 | break; |
213 | } |
214 | @@ -1593,7 +1608,7 @@ |
215 | m_pEvent->e_x_root = 0; |
216 | m_pEvent->e_y_root = 0; |
217 | m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state); |
218 | - mouse_move(xevent, m_pEvent); |
219 | + MouseMove(xevent, m_pEvent); |
220 | //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: EnterNotify event."); |
221 | break; |
222 | } |
223 | |
224 | === modified file 'NuxGraphics/GraphicsDisplayX11.h' |
225 | --- NuxGraphics/GraphicsDisplayX11.h 2011-11-18 07:31:49 +0000 |
226 | +++ NuxGraphics/GraphicsDisplayX11.h 2011-11-25 05:03:26 +0000 |
227 | @@ -135,6 +135,13 @@ |
228 | int m_BestMode; |
229 | |
230 | bool m_CreatedFromForeignWindow; |
231 | + Time last_click_time_; |
232 | + /*! |
233 | + Maximum time allowed between the end of the last click (mouse up) and the next mouse down |
234 | + to be considered as a double click event. |
235 | + */ |
236 | + static int double_click_time_delay; |
237 | + int double_click_counter_; |
238 | |
239 | public: |
240 | typedef void(*GrabReleaseCallback) (bool replaced, void *user_data); |
241 | @@ -436,7 +443,9 @@ |
242 | GLXEWContext m_GLXEWContext; |
243 | #endif |
244 | |
245 | - static int X11ErrorHandler(Display *display, XErrorEvent *error); |
246 | + int MouseMove(XEvent xevent, Event *event); |
247 | + int MousePress(XEvent xevent, Event *event); |
248 | + int MouseRelease(XEvent xevent, Event *event); |
249 | |
250 | friend class DisplayAccessController; |
251 | friend class GraphicsEngine; |
252 | |
253 | === modified file 'tests/Makefile.am' |
254 | --- tests/Makefile.am 2011-11-22 07:13:53 +0000 |
255 | +++ tests/Makefile.am 2011-11-25 05:03:26 +0000 |
256 | @@ -4,7 +4,8 @@ |
257 | gtest-nux-core \ |
258 | test-graphics-display \ |
259 | test-empty-window \ |
260 | - button-xtest |
261 | + button-xtest \ |
262 | + mouse-events-test |
263 | |
264 | # Please keep alphabetical |
265 | test_nux_SOURCES = \ |
266 | @@ -108,6 +109,11 @@ |
267 | button_xtest_LDADD = $(TestLibs) |
268 | button_xtest_LDFLAGS = -lpthread -lXtst |
269 | |
270 | +mouse_events_test_SOURCES = mouse-events-test.cpp test-view.cpp nux_test_framework.cpp nux_automated_test_framework.cpp |
271 | +mouse_events_test_CPPFLAGS = $(TestFlags) |
272 | +mouse_events_test_LDADD = $(TestLibs) |
273 | +mouse_events_test_LDFLAGS = -lpthread -lXtst |
274 | + |
275 | #run make test as part of make check |
276 | check-local: test gtest test-apps |
277 | |
278 | @@ -117,10 +123,11 @@ |
279 | gtest: gtest-nux-core |
280 | ./gtest-nux-core |
281 | |
282 | -test-apps: test-graphics-display test-empty-window button-xtest |
283 | +test-apps: test-graphics-display test-empty-window button-xtest mouse-events-test |
284 | ./test-graphics-display |
285 | ./test-empty-window |
286 | ./button-xtest |
287 | + ./mouse-events-test |
288 | |
289 | check-report: |
290 | @gtester -k -o=test-nux-results.xml -k ./test-nux \ |
291 | |
292 | === modified file 'tests/Readme.txt' |
293 | --- tests/Readme.txt 2011-11-21 17:24:00 +0000 |
294 | +++ tests/Readme.txt 2011-11-25 05:03:26 +0000 |
295 | @@ -1,5 +1,13 @@ |
296 | + |
297 | +Automated Tests |
298 | +--------------- |
299 | +Since the instruction for the simulated events are comming from a separate thread, the tests are very sensible |
300 | +to timing and can generate false negatives. For this reason, in some location of the code, there are sleeping periodes that have been added to allow time for events to be processed and for results to be generated. |
301 | + |
302 | +All test must be over in 20 seconds or less. |
303 | + |
304 | Description of tests: |
305 | - |
306 | +--------------------- |
307 | graphics_display_states: |
308 | Test the graphics display states after it has been created. |
309 | |
310 | @@ -7,4 +15,23 @@ |
311 | Display an empty window and close it after 3 seconds. |
312 | |
313 | button_xtest: |
314 | - Using XTest, love the mouse around the boundaries of a button view and simulate click and drag mouse events. The program close itself after a delay. |
315 | \ No newline at end of file |
316 | + Using XTest, love the mouse around the boundaries of a button view and simulate click and drag mouse events. The program close itself after a delay. |
317 | + |
318 | +mouse_events_test: |
319 | + Test the following mouse events: |
320 | + - mouse down |
321 | + - mouse up |
322 | + - mouse click |
323 | + - mouse double-click |
324 | + - mouse drag |
325 | + - mouse enter |
326 | + - mouse leave |
327 | + - mouse move |
328 | + |
329 | + |
330 | +mouse_button_tests: |
331 | + Make sure that only mouse button 1, 2 and 3 generate mouse-down and mouse-up events. |
332 | + The artificial button event 4, 5, 6... should not generate mouse-down or mouse-up events. |
333 | + |
334 | + |
335 | + |
336 | \ No newline at end of file |
337 | |
338 | === modified file 'tests/button-xtest.cpp' |
339 | --- tests/button-xtest.cpp 2011-11-21 17:24:00 +0000 |
340 | +++ tests/button-xtest.cpp 2011-11-25 05:03:26 +0000 |
341 | @@ -135,7 +135,7 @@ |
342 | int xstatus = XInitThreads(); |
343 | nuxAssertMsg(xstatus > 0, "XInitThreads has failed"); |
344 | |
345 | - test_button = new TestButton("Button XTest", 300, 300, 15000); |
346 | + test_button = new TestButton("Button XTest", 300, 300, 20000); |
347 | test_button->Startup(); |
348 | test_button->UserInterfaceSetup(); |
349 | |
350 | |
351 | === added file 'tests/mouse-events-test.cpp' |
352 | --- tests/mouse-events-test.cpp 1970-01-01 00:00:00 +0000 |
353 | +++ tests/mouse-events-test.cpp 2011-11-25 05:03:26 +0000 |
354 | @@ -0,0 +1,156 @@ |
355 | +/* |
356 | + * Copyright 2010 Inalogic Inc. |
357 | + * |
358 | + * This program is free software: you can redistribute it and/or modify it |
359 | + * under the terms of the GNU General Public License version 3, as published |
360 | + * by the Free Software Foundation. |
361 | + * |
362 | + * This program is distributed in the hope that it will be useful, but |
363 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
364 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
365 | + * PURPOSE. See the GNU General Public License for more details. |
366 | + * |
367 | + * You should have received a copy of the GNU General Public License |
368 | + * version 3 along with this program. If not, see |
369 | + * <http://www.gnu.org/licenses/> |
370 | + * |
371 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
372 | + * |
373 | + */ |
374 | + |
375 | +#include "Nux/Nux.h" |
376 | +#include "Nux/WindowThread.h" |
377 | +#include "Nux/VLayout.h" |
378 | +#include "Nux/Layout.h" |
379 | +#include <X11/extensions/XTest.h> |
380 | +#include <X11/keysym.h> |
381 | +#include "nux_test_framework.h" |
382 | +#include "nux_automated_test_framework.h" |
383 | +#include "test-view.h" |
384 | + |
385 | +class EventsTest: public NuxTestFramework |
386 | +{ |
387 | +public: |
388 | + EventsTest(const char *program_name, int window_width, int window_height, int program_life_span); |
389 | + ~EventsTest(); |
390 | + |
391 | + virtual void UserInterfaceSetup(); |
392 | + |
393 | + void ResetEvents(); |
394 | + TestView *test_view_; |
395 | +}; |
396 | + |
397 | +EventsTest::EventsTest(const char *program_name, |
398 | + int window_width, |
399 | + int window_height, |
400 | + int program_life_span) |
401 | + : NuxTestFramework(program_name, window_width, window_height, program_life_span) |
402 | +{ |
403 | + ResetEvents(); |
404 | + test_view_ = NULL; |
405 | +} |
406 | + |
407 | +EventsTest::~EventsTest() |
408 | +{ |
409 | + |
410 | +} |
411 | + |
412 | +void EventsTest::ResetEvents() |
413 | +{ |
414 | + if (test_view_) |
415 | + test_view_->ResetEvents(); |
416 | +} |
417 | + |
418 | +void EventsTest::UserInterfaceSetup() |
419 | +{ |
420 | + nux::VLayout *main_layout = new nux::VLayout(NUX_TRACKER_LOCATION); |
421 | + test_view_ = new TestView(NUX_TRACKER_LOCATION); |
422 | + |
423 | + main_layout->AddView(test_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
424 | + main_layout->SetPadding(10, 10); |
425 | + |
426 | + static_cast<nux::WindowThread*>(window_thread_)->SetLayout(main_layout); |
427 | + |
428 | + nux::ColorLayer background(nux::Color(0xFF4D4D4D)); |
429 | + static_cast<nux::WindowThread*>(window_thread_)->SetWindowBackgroundPaintLayer(&background); |
430 | +} |
431 | + |
432 | +EventsTest *event_test = NULL; |
433 | + |
434 | +void TestingThread(nux::NThread *thread, void *user_data) |
435 | +{ |
436 | + while (event_test->ReadyToGo() == false) |
437 | + { |
438 | + nuxDebugMsg("Waiting to start"); |
439 | + nux::SleepForMilliseconds(300); |
440 | + } |
441 | + |
442 | + nux::SleepForMilliseconds(1000); |
443 | + |
444 | + nux::WindowThread *wnd_thread = static_cast<nux::WindowThread*>(user_data); |
445 | + |
446 | + NuxAutomatedTestFramework test(wnd_thread); |
447 | + |
448 | + test.Startup(); |
449 | + |
450 | + // Set the mouse at coordinates (0, 0) (top-left corner) on the display |
451 | + test.PutMouseAt(0, 0); |
452 | + |
453 | + test.TestReportMsg(event_test->test_view_, "TestView created"); |
454 | + |
455 | + event_test->ResetEvents(); |
456 | + test.ViewSendMouseMotionToCenter(event_test->test_view_); |
457 | + |
458 | + test.TestReportMsg(event_test->test_view_->registered_mouse_move_, "Mouse move event"); |
459 | + test.TestReportMsg(event_test->test_view_->registered_mouse_enter_, "Mouse enter event"); |
460 | + test.ViewSendMouseClick(0, 1); |
461 | + |
462 | + test.TestReportMsg(event_test->test_view_->registered_mouse_down_, "Mouse down event"); |
463 | + test.TestReportMsg(event_test->test_view_->registered_mouse_up_, "Mouse up event"); |
464 | + test.TestReportMsg(event_test->test_view_->registered_mouse_click_, "Mouse click event"); |
465 | + |
466 | + test.ViewSendMouseDrag(event_test->test_view_, 1, 0, 0, 50, 50); |
467 | + test.TestReportMsg(event_test->test_view_->registered_mouse_click_, "Mouse drag event"); |
468 | + |
469 | + test.ViewSendMouseMotionTo(event_test->test_view_, -5, -5); |
470 | + test.TestReportMsg(event_test->test_view_->registered_mouse_leave_, "Mouse leave event"); |
471 | + |
472 | + event_test->test_view_->EnableDoubleClick(true); |
473 | + test.ViewSendMouseDoubleClick(event_test->test_view_, 1); |
474 | + test.TestReportMsg(event_test->test_view_->registered_mouse_double_click_, "Mouse double click event"); |
475 | + |
476 | + event_test->ResetEvents(); |
477 | + // Deactivate double click and test if the view still receives it. |
478 | + event_test->test_view_->EnableDoubleClick(false); |
479 | + test.ViewSendMouseDoubleClick(event_test->test_view_, 1); |
480 | + test.TestReportMsg(!event_test->test_view_->registered_mouse_double_click_, "Mouse double click de-activated"); |
481 | + |
482 | + if (test.WhenDoneTerminateProgram()) |
483 | + { |
484 | + nux::SleepForMilliseconds(1000); |
485 | + wnd_thread->NuxMainLoopQuit(); |
486 | + } |
487 | + nuxDebugMsg("Exit testing thread"); |
488 | +} |
489 | + |
490 | +int main(int argc, char **argv) |
491 | +{ |
492 | + int xstatus = XInitThreads(); |
493 | + nuxAssertMsg(xstatus > 0, "XInitThreads has failed"); |
494 | + |
495 | + event_test = new EventsTest("Events Test", 300, 300, 20000); |
496 | + event_test->Startup(); |
497 | + event_test->UserInterfaceSetup(); |
498 | + |
499 | + nux::SystemThread *test_thread = nux::CreateSystemThread(event_test->GetWindowThread(), &TestingThread, event_test->GetWindowThread()); |
500 | + |
501 | + test_thread->Start(event_test); |
502 | + |
503 | + event_test->Run(); |
504 | + |
505 | + delete test_thread; |
506 | + delete event_test; |
507 | + |
508 | + return 0; |
509 | +} |
510 | + |
511 | |
512 | === modified file 'tests/nux_automated_test_framework.cpp' |
513 | --- tests/nux_automated_test_framework.cpp 2011-11-21 17:24:00 +0000 |
514 | +++ tests/nux_automated_test_framework.cpp 2011-11-25 05:03:26 +0000 |
515 | @@ -24,9 +24,10 @@ |
516 | #include "nux_automated_test_framework.h" |
517 | |
518 | |
519 | -int NuxAutomatedTestFramework::mouse_motion_time_span = 1000; |
520 | -int NuxAutomatedTestFramework::mouse_click_time_span = 300; |
521 | -int NuxAutomatedTestFramework::safety_border_inside_view = 1; |
522 | +int NuxAutomatedTestFramework::mouse_motion_time_span = 1000; // milliseconds |
523 | +int NuxAutomatedTestFramework::mouse_click_time_span = 300; // milliseconds |
524 | +int NuxAutomatedTestFramework::minimum_sleep_time = 600; // milliseconds |
525 | +int NuxAutomatedTestFramework::safety_border_inside_view = 1; // pixels |
526 | |
527 | NuxAutomatedTestFramework::NuxAutomatedTestFramework(nux::WindowThread *window_thread) |
528 | { |
529 | @@ -85,6 +86,34 @@ |
530 | SendFakeMouseEvent(button, true); |
531 | nux::SleepForMilliseconds(NuxAutomatedTestFramework::mouse_click_time_span); |
532 | SendFakeMouseEvent(button, false); |
533 | + |
534 | + XSync(display_, False); |
535 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time); |
536 | +} |
537 | + |
538 | +void NuxAutomatedTestFramework::ViewSendMouseDoubleClick(nux::View *view, int button) |
539 | +{ |
540 | + nux::Rect r; |
541 | + if (view) |
542 | + { |
543 | + r = view->GetAbsoluteGeometry(); |
544 | + r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2); |
545 | + } |
546 | + else |
547 | + { |
548 | + r = window_thread_->GetWindow().GetWindowGeometry(); |
549 | + r.OffsetPosition(r.width/2, r.height/2); |
550 | + } |
551 | + |
552 | + // Send the mouse to the center of the view |
553 | + SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
554 | + |
555 | + XTestFakeButtonEvent(display_, button, true, CurrentTime); |
556 | + XTestFakeButtonEvent(display_, button, false, CurrentTime); |
557 | + XTestFakeButtonEvent(display_, button, true, CurrentTime); |
558 | + XTestFakeButtonEvent(display_, button, false, CurrentTime); |
559 | + XSync(display_, False); |
560 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time); |
561 | } |
562 | |
563 | void NuxAutomatedTestFramework::ViewSendMouseDown(nux::View *view, int button) |
564 | @@ -112,7 +141,7 @@ |
565 | int view_center_x = r.x + r.width/2; |
566 | int view_center_y = r.y + r.height/2; |
567 | SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span); |
568 | - nux::SleepForMilliseconds(600); |
569 | + nux::SleepForMilliseconds(minimum_sleep_time); |
570 | } |
571 | SendFakeMouseEvent(button, true); |
572 | } |
573 | @@ -126,7 +155,7 @@ |
574 | // int view_center_y = r.y + r.height/2; |
575 | |
576 | // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000); |
577 | - // nux::SleepForMilliseconds(600); |
578 | + // nux::SleepForMilliseconds(minimum_sleep_time); |
579 | SendFakeMouseEvent(button, false); |
580 | } |
581 | |
582 | @@ -139,14 +168,14 @@ |
583 | |
584 | // Go to first point |
585 | SendFakeMouseMotionEvent(r0.x, r0.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
586 | - nux::SleepForMilliseconds(600); |
587 | + nux::SleepForMilliseconds(minimum_sleep_time); |
588 | |
589 | // Mouse down |
590 | ViewSendMouseDown(view, button_index); |
591 | |
592 | // Drag to second point |
593 | SendFakeMouseMotionEvent(r1.x, r1.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
594 | - nux::SleepForMilliseconds(600); |
595 | + nux::SleepForMilliseconds(minimum_sleep_time); |
596 | |
597 | // Mouse up |
598 | ViewSendMouseUp(view, button_index); |
599 | @@ -338,6 +367,12 @@ |
600 | SendFakeKeyEvent(XK_Return, 0); |
601 | } |
602 | |
603 | +void NuxAutomatedTestFramework::PutMouseAt(int x, int y) |
604 | +{ |
605 | + XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime); |
606 | + XSync(display_, False); |
607 | +} |
608 | + |
609 | void NuxAutomatedTestFramework::SendFakeKeyEvent(KeySym keysym, KeySym modsym) |
610 | { |
611 | KeyCode keycode = 0; |
612 | @@ -410,6 +445,7 @@ |
613 | |
614 | XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime); |
615 | XSync(display_, False); |
616 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time); |
617 | } |
618 | |
619 | void NuxAutomatedTestFramework::TestReportMsg(bool b, const char* msg) |
620 | |
621 | === modified file 'tests/nux_automated_test_framework.h' |
622 | --- tests/nux_automated_test_framework.h 2011-11-21 17:24:00 +0000 |
623 | +++ tests/nux_automated_test_framework.h 2011-11-25 05:03:26 +0000 |
624 | @@ -34,7 +34,15 @@ |
625 | void Startup(); |
626 | |
627 | //! Simulate a mouse click event on a view. |
628 | + /*! |
629 | + Move the mouse to the middle of the view (if it isn't there already) and perform a click event. |
630 | + */ |
631 | void ViewSendMouseClick(nux::View *view, int button); |
632 | + //! Simulate a mouse double click event on a view. |
633 | + /*! |
634 | + Move the mouse to the middle of the view (if it isn't there already) and perform a double click event. |
635 | + */ |
636 | + void ViewSendMouseDoubleClick(nux::View *view, int button); |
637 | //! Simulate a mouse down event on a view. |
638 | void ViewSendMouseDown(nux::View *view, int button); |
639 | //! Simulate a mouse up event on a view. |
640 | @@ -73,6 +81,8 @@ |
641 | //! Simulate Return key. |
642 | void ViewSendReturn(); |
643 | |
644 | + //! Put the mouse pointer anywhere on the display. |
645 | + void PutMouseAt(int x, int y); |
646 | |
647 | //! Simulate a mouse event. |
648 | void SendFakeMouseEvent(int mouse_button_index, bool pressed); |
649 | @@ -107,9 +117,10 @@ |
650 | int window_height_; |
651 | bool terminate_when_test_over_; |
652 | |
653 | - static int mouse_motion_time_span; // in seconds |
654 | - static int mouse_click_time_span; // in seconds |
655 | - static int safety_border_inside_view; // in pixels |
656 | + static int mouse_motion_time_span; // in milliseconds |
657 | + static int mouse_click_time_span; // in milliseconds |
658 | + static int minimum_sleep_time; // in milliseconds |
659 | + static int safety_border_inside_view; // in pixels |
660 | }; |
661 | |
662 | #endif // NUX_AUTOMATED_TEST_FRAMEWORK_H |
663 | |
664 | === added file 'tests/test-view.cpp' |
665 | --- tests/test-view.cpp 1970-01-01 00:00:00 +0000 |
666 | +++ tests/test-view.cpp 2011-11-25 05:03:26 +0000 |
667 | @@ -0,0 +1,132 @@ |
668 | + |
669 | +#include "Nux/Nux.h" |
670 | +#include "test-view.h" |
671 | + |
672 | +/* |
673 | + TestView: |
674 | + This class is a Nux view that processes all mouse events that it receives. It is meant for testing simulated |
675 | + mouse events. |
676 | +*/ |
677 | + |
678 | +NUX_IMPLEMENT_OBJECT_TYPE(TestView); |
679 | + |
680 | +TestView::TestView(NUX_FILE_LINE_DECL) |
681 | + : nux::View(NUX_FILE_LINE_PARAM) |
682 | +{ |
683 | + ResetEvents(); |
684 | + |
685 | + normal_color_ = nux::color::Green; |
686 | + mouse_down_color_ = nux::color::Red; |
687 | + mouse_drag_color_ = nux::color::Yellow; |
688 | + mouse_in_color_ = nux::color::Blue; |
689 | + current_color_ = normal_color_; |
690 | + |
691 | + mouse_in_ = false; |
692 | + mouse_mouse_drag_ = false; |
693 | + mouse_mouse_down_ = false; |
694 | + |
695 | + mouse_down.connect(sigc::mem_fun(this, &TestView::OnMouseDown)); |
696 | + mouse_up.connect(sigc::mem_fun(this, &TestView::OnMouseUp)); |
697 | + mouse_drag.connect(sigc::mem_fun(this, &TestView::OnMouseDrag)); |
698 | + mouse_click.connect(sigc::mem_fun(this, &TestView::OnMouseClick)); |
699 | + mouse_double_click.connect(sigc::mem_fun(this, &TestView::OnMouseDoubleClick)); |
700 | + mouse_move.connect(sigc::mem_fun(this, &TestView::OnMouseMove)); |
701 | + mouse_enter.connect(sigc::mem_fun(this, &TestView::OnMouseEnter)); |
702 | + mouse_leave.connect(sigc::mem_fun(this, &TestView::OnMouseLeave)); |
703 | +} |
704 | + |
705 | +TestView::~TestView() |
706 | +{ |
707 | + |
708 | +} |
709 | + |
710 | +void TestView::ResetEvents() |
711 | +{ |
712 | + registered_mouse_down_ = false; |
713 | + registered_mouse_up_ = false; |
714 | + registered_mouse_drag_ = false; |
715 | + registered_mouse_enter_ = false; |
716 | + registered_mouse_leave_ = false; |
717 | + registered_mouse_click_ = false; |
718 | + registered_mouse_double_click_ = false; |
719 | + registered_mouse_move_ = false; |
720 | + registered_mouse_enter_ = false; |
721 | + registered_mouse_leave_ = false; |
722 | + |
723 | +} |
724 | + |
725 | +nux::Color TestView::GetColor() const |
726 | +{ |
727 | + return current_color_; |
728 | +} |
729 | + |
730 | +void TestView::Draw(nux::GraphicsEngine &graphics_engine, bool force_draw) |
731 | +{ |
732 | + nux::Geometry geo = GetGeometry(); |
733 | + graphics_engine.QRP_Color(0, 0, geo.width, geo.height, current_color_); |
734 | +} |
735 | + |
736 | +void TestView::OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags) |
737 | +{ |
738 | + registered_mouse_down_ = true; |
739 | + current_color_ = mouse_down_color_; |
740 | + mouse_mouse_down_ = true; |
741 | + QueueDraw(); |
742 | +} |
743 | + |
744 | +void TestView::OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags) |
745 | +{ |
746 | + registered_mouse_up_ = true; |
747 | + if (mouse_in_) |
748 | + current_color_ = mouse_in_color_; |
749 | + else |
750 | + current_color_ = normal_color_; |
751 | + |
752 | + mouse_mouse_down_ = false; |
753 | + mouse_mouse_drag_ = false; |
754 | + QueueDraw(); |
755 | +} |
756 | + |
757 | +void TestView::OnMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
758 | +{ |
759 | + registered_mouse_drag_ = true; |
760 | + current_color_ = mouse_drag_color_; |
761 | + mouse_mouse_drag_ = true; |
762 | + QueueDraw(); |
763 | +} |
764 | + |
765 | +void TestView::OnMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags) |
766 | +{ |
767 | + registered_mouse_click_ = true; |
768 | + QueueDraw(); |
769 | +} |
770 | + |
771 | +void TestView::OnMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags) |
772 | +{ |
773 | + registered_mouse_double_click_ = true; |
774 | + current_color_ = mouse_down_color_; |
775 | + mouse_mouse_down_ = true; |
776 | + QueueDraw(); |
777 | +} |
778 | + |
779 | +void TestView::OnMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) |
780 | +{ |
781 | + registered_mouse_move_ = true; |
782 | + QueueDraw(); |
783 | +} |
784 | + |
785 | +void TestView::OnMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags) |
786 | +{ |
787 | + registered_mouse_enter_ = true; |
788 | + mouse_in_ = true; |
789 | + current_color_ = mouse_in_color_; |
790 | + QueueDraw(); |
791 | +} |
792 | + |
793 | +void TestView::OnMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags) |
794 | +{ |
795 | + registered_mouse_leave_ = true; |
796 | + mouse_in_ = false; |
797 | + current_color_ = normal_color_; |
798 | + QueueDraw(); |
799 | +} |
800 | |
801 | === added file 'tests/test-view.h' |
802 | --- tests/test-view.h 1970-01-01 00:00:00 +0000 |
803 | +++ tests/test-view.h 2011-11-25 05:03:26 +0000 |
804 | @@ -0,0 +1,51 @@ |
805 | + |
806 | +#ifndef TEST_VIEW_H |
807 | +#define TEST_VIEW_H |
808 | + |
809 | +#include "Nux/TextureArea.h" |
810 | + |
811 | +class TestView: public nux::View |
812 | +{ |
813 | + NUX_DECLARE_OBJECT_TYPE(TestView, View); |
814 | +public: |
815 | + TestView(NUX_FILE_LINE_PROTO); |
816 | + ~TestView(); |
817 | + |
818 | + nux::Color GetColor() const; |
819 | + |
820 | + void ResetEvents(); |
821 | + |
822 | + bool registered_mouse_down_; |
823 | + bool registered_mouse_up_; |
824 | + bool registered_mouse_drag_; |
825 | + bool registered_mouse_click_; |
826 | + bool registered_mouse_double_click_; |
827 | + bool registered_mouse_move_; |
828 | + bool registered_mouse_enter_; |
829 | + bool registered_mouse_leave_; |
830 | + |
831 | +protected: |
832 | + nux::Color current_color_; |
833 | + nux::Color normal_color_; |
834 | + nux::Color mouse_down_color_; |
835 | + nux::Color mouse_drag_color_; |
836 | + nux::Color mouse_in_color_; |
837 | + |
838 | + bool mouse_in_; |
839 | + bool mouse_mouse_drag_; |
840 | + bool mouse_mouse_down_; |
841 | + |
842 | + void OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags); |
843 | + void OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags); |
844 | + void OnMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
845 | + void OnMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags); |
846 | + void OnMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags); |
847 | + void OnMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags); |
848 | + void OnMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags); |
849 | + void OnMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags); |
850 | + |
851 | + void Draw(nux::GraphicsEngine &graphics_engine, bool force_draw); |
852 | +}; |
853 | + |
854 | +#endif // TEST_VIEW_H |
855 | + |
Can I strongly suggest that you reorder the two parameter SetPadding?
CSS for two values has (top and bottom, left and right) as the pair.
It would be nice to have consistency here.
It also appears that the double click time is hard coded. Is there any way to
query the system? Can people configure their double click time?
Re: line 425, why sleep for a second once you have been told that the test is
ready to go?
Also, why sleep for a second before terminating? This is just strange.
What is the purpose of tests/test- view.cpp?
Perhpas a comment at the top of the test file as to its purpose would help a
lot.
It looks like this test is testing multiple things. You are defining shaders
and recording events.