Nux

Merge lp:~unity-team/nux/nux-fix-708020 into lp:nux/2.0

Proposed by Jay Taoko
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
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+83109@code.launchpad.net

Description of the change

* Added automated tests from mouse events
* Fixed double-click event: bug #708020
* Fixed: added missing functions in Layout.cpp/.h

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) 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.

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.

review: Needs Information
Revision history for this message
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://code.launchpad.net/~unity-team/nux/nux-fix-708020/+merge/83109
> Your team Unity Team is subscribed to branch lp:nux.
>

--
Sam Spilsbury

Revision history for this message
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-view.cpp?
>
> 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.

Revision history for this message
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).

lp:~unity-team/nux/nux-fix-708020 updated
522. By Jay Taoko

* Fixes
* Made the double click time delat a non-const static in GraphicsDisplay
* Removed GLSL shader code from TestView.
* Fixed layout::SetPadding(int, int) to conform to CSS style

Revision history for this message
Tim Penhey (thumper) wrote :

> void Layout::SetPadding(int top_bottom_padding, int left_right_padding)
> {
> top_padding_ = top_bottom_padding < 0 ? 0 : top_bottom_padding;
> bottom_padding_ = top_bottom_padding;

Surely that should be:
    bottom_padding_ = top_padding_;

review: Approve
Revision history for this message
Jay Taoko (jaytaoko) wrote :

> > void Layout::SetPadding(int top_bottom_padding, int left_right_padding)
> > {
> > 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!

lp:~unity-team/nux/nux-fix-708020 updated
523. By Jay Taoko

* Fix in Layout::SetPadding

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Nux/Layout.cpp'
--- Nux/Layout.cpp 2011-10-17 20:57:35 +0000
+++ Nux/Layout.cpp 2011-11-25 05:03:26 +0000
@@ -120,6 +120,24 @@
120 bottom_padding_ = bottom < 0 ? 0 : bottom;120 bottom_padding_ = bottom < 0 ? 0 : bottom;
121 }121 }
122122
123 void Layout::SetPadding(int padding)
124 {
125 top_padding_ = padding < 0 ? 0 : padding;
126 bottom_padding_ = top_padding_;
127 right_padding_ = top_padding_;
128 left_padding_ = top_padding_;
129 }
130
131 void Layout::SetPadding(int top_bottom_padding, int left_right_padding)
132 {
133 top_padding_ = top_bottom_padding < 0 ? 0 : top_bottom_padding;
134 bottom_padding_ = top_padding_;
135
136 right_padding_ = left_right_padding < 0 ? 0 : left_right_padding;
137 left_padding_ = right_padding_;
138 }
139
140
123 void Layout::SetPadding(int top, int right, int bottom, int left)141 void Layout::SetPadding(int top, int right, int bottom, int left)
124 {142 {
125 top_padding_ = top < 0 ? 0 : top;143 top_padding_ = top < 0 ? 0 : top;
126144
=== modified file 'Nux/Layout.h'
--- Nux/Layout.h 2011-10-10 01:52:00 +0000
+++ Nux/Layout.h 2011-11-25 05:03:26 +0000
@@ -117,10 +117,10 @@
117 Set the left/right and top/bottom padding of the layout. \n117 Set the left/right and top/bottom padding of the layout. \n
118 Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout.118 Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout.
119119
120 @param top_bottom_padding The top/bottom padding value of the layout.
120 @param left_right_padding The left/right padding value of the layout.121 @param left_right_padding The left/right padding value of the layout.
121 @param top_bottom_padding The top/bottom padding value of the layout.
122 */122 */
123 void SetPadding(int left_right_padding, int top_bottom_padding);123 void SetPadding(int top_bottom_padding, int left_right_padding);
124124
125 virtual unsigned int GetMaxStretchFactor();125 virtual unsigned int GetMaxStretchFactor();
126 unsigned int GetMinStretchFactor();126 unsigned int GetMinStretchFactor();
@@ -143,8 +143,27 @@
143 //! Deprecated. Use SetTopBottomPadding,143 //! Deprecated. Use SetTopBottomPadding,
144 void SetVerticalExternalMargin(int m);144 void SetVerticalExternalMargin(int m);
145145
146 //! Set the left/right/top/bottom padding of the layout.
147 /*!
148 Set the left/right and top/bottom padding of the layout. \n
149 Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout.
150
151 @param top The top padding value of the layout.
152 @param right The right padding value of the layout.
153 @param bottom The bottom padding value of the layout.
154 @param left The left padding value of the layout.
155 */
146 void SetPadding(int top, int right, int bottom, int left);156 void SetPadding(int top, int right, int bottom, int left);
147157
158 //! Set the left/right/top/bottom padding of the layout.
159 /*!
160 Set the left/right/top/bottom padding of the layout. \n
161 Valid only for HLayout, VLayouts, HGridLayouts and VGridLayout.
162
163 @param padding The top/right/bottom/left padding value of the layout.
164 */
165 void SetPadding(int padding);
166
148 int GetLeftPadding() const;167 int GetLeftPadding() const;
149 int GetRightPadding() const;168 int GetRightPadding() const;
150 int GetTopPadding() const;169 int GetTopPadding() const;
151170
=== modified file 'NuxGraphics/GraphicsDisplayX11.cpp'
--- NuxGraphics/GraphicsDisplayX11.cpp 2011-11-22 07:13:53 +0000
+++ NuxGraphics/GraphicsDisplayX11.cpp 2011-11-25 05:03:26 +0000
@@ -39,24 +39,26 @@
39{39{
40 EventToNameStruct EventToName[] =40 EventToNameStruct EventToName[] =
41 {41 {
42 {NUX_NO_EVENT, "NUX_NO_EVENT" },42 {NUX_NO_EVENT, "NO_EVENT" },
43 {NUX_MOUSE_PRESSED, "NUX_MOUSE_PRESSED" },43 {NUX_MOUSE_PRESSED, "MOUSE_PRESSED" },
44 {NUX_MOUSE_RELEASED, "NUX_MOUSE_RELEASED" },44 {NUX_MOUSE_RELEASED, "MOUSE_RELEASED" },
45 {NUX_KEYDOWN, "NUX_KEYDOWN" },45 {NUX_KEYDOWN, "KEYDOWN" },
46 {NUX_KEYUP, "NUX_KEYUP" },46 {NUX_KEYUP, "KEYUP" },
47 {NUX_MOUSE_MOVE, "NUX_MOUSE_MOVE" },47 {NUX_MOUSE_MOVE, "MOUSE_MOVE" },
48 {NUX_SIZE_CONFIGURATION, "NUX_SIZE_CONFIGURATION" },48 {NUX_SIZE_CONFIGURATION, "SIZE_CONFIGURATION" },
49 {NUX_WINDOW_CONFIGURATION, "NUX_WINDOW_CONFIGURATION" },49 {NUX_WINDOW_CONFIGURATION, "WINDOW_CONFIGURATION" },
50 {NUX_WINDOW_MAP, "NUX_WINDOW_MAP" },50 {NUX_WINDOW_MAP, "WINDOW_MAP" },
51 {NUX_WINDOW_UNMAP, "NUX_WINDOW_UNMAP" },51 {NUX_WINDOW_UNMAP, "WINDOW_UNMAP" },
52 {NUX_WINDOW_ENTER_FOCUS, "NUX_WINDOW_ENTER_FOCUS" },52 {NUX_WINDOW_ENTER_FOCUS, "WINDOW_ENTER_FOCUS" },
53 {NUX_WINDOW_EXIT_FOCUS, "NUX_WINDOW_EXIT_FOCUS" },53 {NUX_WINDOW_EXIT_FOCUS, "WINDOW_EXIT_FOCUS" },
54 {NUX_WINDOW_DIRTY, "NUX_WINDOW_DIRTY" },54 {NUX_WINDOW_DIRTY, "WINDOW_DIRTY" },
55 {NUX_WINDOW_MOUSELEAVE, "NUX_WINDOW_MOUSELEAVE" },55 {NUX_WINDOW_MOUSELEAVE, "WINDOW_MOUSELEAVE" },
56 {NUX_TERMINATE_APP, "NUX_TERMINATE_APP" },56 {NUX_TERMINATE_APP, "TERMINATE_APP" },
57 {NUX_TAKE_FOCUS, "NUX_TAKE_FOCUS" }57 {NUX_TAKE_FOCUS, "TAKE_FOCUS" }
58 };58 };
5959
60 int GraphicsDisplay::double_click_time_delay = 400; // milliseconds
61
60 GraphicsDisplay::GraphicsDisplay()62 GraphicsDisplay::GraphicsDisplay()
61 : m_X11Display(NULL)63 : m_X11Display(NULL)
62 , m_X11Screen(0)64 , m_X11Screen(0)
@@ -78,6 +80,8 @@
78 , m_ScreenBitDepth(32)80 , m_ScreenBitDepth(32)
79 , m_GfxInterfaceCreated(false)81 , m_GfxInterfaceCreated(false)
80 , m_BestMode(-1)82 , m_BestMode(-1)
83 , last_click_time_(0)
84 , double_click_counter_(0)
81 , m_CreatedFromForeignWindow(false)85 , m_CreatedFromForeignWindow(false)
82 , m_num_device_modes(0)86 , m_num_device_modes(0)
83 , m_pEvent(NULL)87 , m_pEvent(NULL)
@@ -1002,7 +1006,7 @@
1002 m_GfxInterfaceCreated = false;1006 m_GfxInterfaceCreated = false;
1003 }1007 }
10041008
1005 static int mouse_move(XEvent xevent, Event *m_pEvent)1009 int GraphicsDisplay::MouseMove(XEvent xevent, Event *m_pEvent)
1006 {1010 {
1007 // Erase mouse event and mouse doubleclick events. Keep the mouse states.1011 // Erase mouse event and mouse doubleclick events. Keep the mouse states.
1008 unsigned int _mouse_state = m_pEvent->e_mouse_state & 0x0F000000;1012 unsigned int _mouse_state = m_pEvent->e_mouse_state & 0x0F000000;
@@ -1027,12 +1031,22 @@
1027 return 0;1031 return 0;
1028 }1032 }
10291033
1030 static int mouse_press(XEvent xevent, Event *m_pEvent)1034 int GraphicsDisplay::MousePress(XEvent xevent, Event *m_pEvent)
1031 {1035 {
1032 // Erase mouse event and mouse double-click events. Keep the mouse states.1036 // Erase mouse event and mouse double-click events. Keep the mouse states.
1033 ulong _mouse_state = m_pEvent->e_mouse_state & 0x0F000000;1037 ulong _mouse_state = m_pEvent->e_mouse_state & 0x0F000000;
10341038
1035 m_pEvent->e_event = NUX_MOUSE_PRESSED;1039 Time current_time = xevent.xbutton.time;
1040 if ((double_click_counter_ == 1) && (current_time - last_click_time_ < double_click_time_delay))
1041 {
1042 m_pEvent->e_event = NUX_MOUSE_DOUBLECLICK;
1043 double_click_counter_ = 0;
1044 }
1045 else
1046 {
1047 m_pEvent->e_event = NUX_MOUSE_PRESSED;
1048 double_click_counter_ = 1;
1049 }
10361050
1037 // State of the button before the event1051 // State of the button before the event
1038 _mouse_state |= (xevent.xbutton.state & Button1Mask) ? NUX_STATE_BUTTON1_DOWN : 0;1052 _mouse_state |= (xevent.xbutton.state & Button1Mask) ? NUX_STATE_BUTTON1_DOWN : 0;
@@ -1082,12 +1096,12 @@
1082 return 0;1096 return 0;
1083 }1097 }
10841098
1085 static int mouse_release(XEvent xevent, Event *m_pEvent)1099 int GraphicsDisplay::MouseRelease(XEvent xevent, Event *m_pEvent)
1086 {1100 {
1087 // Erase mouse event and mouse double-click events. Keep the mouse states.1101 // Erase mouse event and mouse double-click events. Keep the mouse states.
1088 ulong _mouse_state = m_pEvent->e_mouse_state & 0x0F000000;1102 ulong _mouse_state = m_pEvent->e_mouse_state & 0x0F000000;
10891103
1090 m_pEvent->e_event = NUX_MOUSE_RELEASED;1104 m_pEvent->e_event = NUX_MOUSE_RELEASED;
10911105
1092 // State of the button before the event1106 // State of the button before the event
1093 _mouse_state |= (xevent.xbutton.state & Button1Mask) ? NUX_STATE_BUTTON1_DOWN : 0;1107 _mouse_state |= (xevent.xbutton.state & Button1Mask) ? NUX_STATE_BUTTON1_DOWN : 0;
@@ -1116,6 +1130,7 @@
1116 }1130 }
11171131
1118 m_pEvent->e_mouse_state = _mouse_state;1132 m_pEvent->e_mouse_state = _mouse_state;
1133 last_click_time_ = xevent.xbutton.time;
11191134
1120 return 0;1135 return 0;
1121 }1136 }
@@ -1526,7 +1541,7 @@
1526 m_pEvent->e_x_root = 0;1541 m_pEvent->e_x_root = 0;
1527 m_pEvent->e_y_root = 0;1542 m_pEvent->e_y_root = 0;
1528 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);1543 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);
1529 mouse_press(xevent, m_pEvent);1544 MousePress(xevent, m_pEvent);
1530 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ButtonPress event.");1545 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ButtonPress event.");
1531 break;1546 break;
1532 }1547 }
@@ -1544,7 +1559,7 @@
1544 m_pEvent->e_x_root = 0;1559 m_pEvent->e_x_root = 0;
1545 m_pEvent->e_y_root = 0;1560 m_pEvent->e_y_root = 0;
1546 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);1561 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);
1547 mouse_release(xevent, m_pEvent);1562 MouseRelease(xevent, m_pEvent);
1548 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ButtonRelease event.");1563 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: ButtonRelease event.");
1549 break;1564 break;
1550 }1565 }
@@ -1562,7 +1577,7 @@
1562 m_pEvent->e_x_root = 0;1577 m_pEvent->e_x_root = 0;
1563 m_pEvent->e_y_root = 0;1578 m_pEvent->e_y_root = 0;
1564 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);1579 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);
1565 mouse_move(xevent, m_pEvent);1580 MouseMove(xevent, m_pEvent);
1566 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: MotionNotify event.");1581 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: MotionNotify event.");
1567 break;1582 break;
1568 }1583 }
@@ -1593,7 +1608,7 @@
1593 m_pEvent->e_x_root = 0;1608 m_pEvent->e_x_root = 0;
1594 m_pEvent->e_y_root = 0;1609 m_pEvent->e_y_root = 0;
1595 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);1610 m_pEvent->e_key_modifiers = GetModifierKeyState(xevent.xkey.state);
1596 mouse_move(xevent, m_pEvent);1611 MouseMove(xevent, m_pEvent);
1597 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: EnterNotify event.");1612 //nuxDebugMsg("[GraphicsDisplay::ProcessXEvents]: EnterNotify event.");
1598 break;1613 break;
1599 }1614 }
16001615
=== modified file 'NuxGraphics/GraphicsDisplayX11.h'
--- NuxGraphics/GraphicsDisplayX11.h 2011-11-18 07:31:49 +0000
+++ NuxGraphics/GraphicsDisplayX11.h 2011-11-25 05:03:26 +0000
@@ -135,6 +135,13 @@
135 int m_BestMode;135 int m_BestMode;
136136
137 bool m_CreatedFromForeignWindow;137 bool m_CreatedFromForeignWindow;
138 Time last_click_time_;
139 /*!
140 Maximum time allowed between the end of the last click (mouse up) and the next mouse down
141 to be considered as a double click event.
142 */
143 static int double_click_time_delay;
144 int double_click_counter_;
138145
139 public:146 public:
140 typedef void(*GrabReleaseCallback) (bool replaced, void *user_data);147 typedef void(*GrabReleaseCallback) (bool replaced, void *user_data);
@@ -436,7 +443,9 @@
436 GLXEWContext m_GLXEWContext;443 GLXEWContext m_GLXEWContext;
437#endif444#endif
438445
439 static int X11ErrorHandler(Display *display, XErrorEvent *error);446 int MouseMove(XEvent xevent, Event *event);
447 int MousePress(XEvent xevent, Event *event);
448 int MouseRelease(XEvent xevent, Event *event);
440449
441 friend class DisplayAccessController;450 friend class DisplayAccessController;
442 friend class GraphicsEngine;451 friend class GraphicsEngine;
443452
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2011-11-22 07:13:53 +0000
+++ tests/Makefile.am 2011-11-25 05:03:26 +0000
@@ -4,7 +4,8 @@
4 gtest-nux-core \4 gtest-nux-core \
5 test-graphics-display \5 test-graphics-display \
6 test-empty-window \6 test-empty-window \
7 button-xtest7 button-xtest \
8 mouse-events-test
89
9# Please keep alphabetical10# Please keep alphabetical
10test_nux_SOURCES = \11test_nux_SOURCES = \
@@ -108,6 +109,11 @@
108button_xtest_LDADD = $(TestLibs)109button_xtest_LDADD = $(TestLibs)
109button_xtest_LDFLAGS = -lpthread -lXtst110button_xtest_LDFLAGS = -lpthread -lXtst
110111
112mouse_events_test_SOURCES = mouse-events-test.cpp test-view.cpp nux_test_framework.cpp nux_automated_test_framework.cpp
113mouse_events_test_CPPFLAGS = $(TestFlags)
114mouse_events_test_LDADD = $(TestLibs)
115mouse_events_test_LDFLAGS = -lpthread -lXtst
116
111#run make test as part of make check117#run make test as part of make check
112check-local: test gtest test-apps118check-local: test gtest test-apps
113119
@@ -117,10 +123,11 @@
117gtest: gtest-nux-core123gtest: gtest-nux-core
118 ./gtest-nux-core124 ./gtest-nux-core
119125
120test-apps: test-graphics-display test-empty-window button-xtest126test-apps: test-graphics-display test-empty-window button-xtest mouse-events-test
121 ./test-graphics-display127 ./test-graphics-display
122 ./test-empty-window128 ./test-empty-window
123 ./button-xtest129 ./button-xtest
130 ./mouse-events-test
124131
125check-report:132check-report:
126 @gtester -k -o=test-nux-results.xml -k ./test-nux \133 @gtester -k -o=test-nux-results.xml -k ./test-nux \
127134
=== modified file 'tests/Readme.txt'
--- tests/Readme.txt 2011-11-21 17:24:00 +0000
+++ tests/Readme.txt 2011-11-25 05:03:26 +0000
@@ -1,5 +1,13 @@
1
2Automated Tests
3---------------
4Since the instruction for the simulated events are comming from a separate thread, the tests are very sensible
5to 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.
6
7All test must be over in 20 seconds or less.
8
1Description of tests:9Description of tests:
210---------------------
3graphics_display_states:11graphics_display_states:
4 Test the graphics display states after it has been created.12 Test the graphics display states after it has been created.
513
@@ -7,4 +15,23 @@
7 Display an empty window and close it after 3 seconds.15 Display an empty window and close it after 3 seconds.
816
9button_xtest:17button_xtest:
10 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.
11\ No newline at end of file18\ No newline at end of file
19 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.
20
21mouse_events_test:
22 Test the following mouse events:
23 - mouse down
24 - mouse up
25 - mouse click
26 - mouse double-click
27 - mouse drag
28 - mouse enter
29 - mouse leave
30 - mouse move
31
32
33mouse_button_tests:
34 Make sure that only mouse button 1, 2 and 3 generate mouse-down and mouse-up events.
35 The artificial button event 4, 5, 6... should not generate mouse-down or mouse-up events.
36
37
38
12\ No newline at end of file39\ No newline at end of file
1340
=== modified file 'tests/button-xtest.cpp'
--- tests/button-xtest.cpp 2011-11-21 17:24:00 +0000
+++ tests/button-xtest.cpp 2011-11-25 05:03:26 +0000
@@ -135,7 +135,7 @@
135 int xstatus = XInitThreads();135 int xstatus = XInitThreads();
136 nuxAssertMsg(xstatus > 0, "XInitThreads has failed");136 nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
137137
138 test_button = new TestButton("Button XTest", 300, 300, 15000);138 test_button = new TestButton("Button XTest", 300, 300, 20000);
139 test_button->Startup();139 test_button->Startup();
140 test_button->UserInterfaceSetup();140 test_button->UserInterfaceSetup();
141141
142142
=== added file 'tests/mouse-events-test.cpp'
--- tests/mouse-events-test.cpp 1970-01-01 00:00:00 +0000
+++ tests/mouse-events-test.cpp 2011-11-25 05:03:26 +0000
@@ -0,0 +1,156 @@
1/*
2 * Copyright 2010 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: Jay Taoko <jaytaoko@inalogic.com>
18 *
19 */
20
21#include "Nux/Nux.h"
22#include "Nux/WindowThread.h"
23#include "Nux/VLayout.h"
24#include "Nux/Layout.h"
25#include <X11/extensions/XTest.h>
26#include <X11/keysym.h>
27#include "nux_test_framework.h"
28#include "nux_automated_test_framework.h"
29#include "test-view.h"
30
31class EventsTest: public NuxTestFramework
32{
33public:
34 EventsTest(const char *program_name, int window_width, int window_height, int program_life_span);
35 ~EventsTest();
36
37 virtual void UserInterfaceSetup();
38
39 void ResetEvents();
40 TestView *test_view_;
41};
42
43EventsTest::EventsTest(const char *program_name,
44 int window_width,
45 int window_height,
46 int program_life_span)
47 : NuxTestFramework(program_name, window_width, window_height, program_life_span)
48{
49 ResetEvents();
50 test_view_ = NULL;
51}
52
53EventsTest::~EventsTest()
54{
55
56}
57
58void EventsTest::ResetEvents()
59{
60 if (test_view_)
61 test_view_->ResetEvents();
62}
63
64void EventsTest::UserInterfaceSetup()
65{
66 nux::VLayout *main_layout = new nux::VLayout(NUX_TRACKER_LOCATION);
67 test_view_ = new TestView(NUX_TRACKER_LOCATION);
68
69 main_layout->AddView(test_view_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
70 main_layout->SetPadding(10, 10);
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
78EventsTest *event_test = NULL;
79
80void TestingThread(nux::NThread *thread, void *user_data)
81{
82 while (event_test->ReadyToGo() == false)
83 {
84 nuxDebugMsg("Waiting to start");
85 nux::SleepForMilliseconds(300);
86 }
87
88 nux::SleepForMilliseconds(1000);
89
90 nux::WindowThread *wnd_thread = static_cast<nux::WindowThread*>(user_data);
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(event_test->test_view_, "TestView created");
100
101 event_test->ResetEvents();
102 test.ViewSendMouseMotionToCenter(event_test->test_view_);
103
104 test.TestReportMsg(event_test->test_view_->registered_mouse_move_, "Mouse move event");
105 test.TestReportMsg(event_test->test_view_->registered_mouse_enter_, "Mouse enter event");
106 test.ViewSendMouseClick(0, 1);
107
108 test.TestReportMsg(event_test->test_view_->registered_mouse_down_, "Mouse down event");
109 test.TestReportMsg(event_test->test_view_->registered_mouse_up_, "Mouse up event");
110 test.TestReportMsg(event_test->test_view_->registered_mouse_click_, "Mouse click event");
111
112 test.ViewSendMouseDrag(event_test->test_view_, 1, 0, 0, 50, 50);
113 test.TestReportMsg(event_test->test_view_->registered_mouse_click_, "Mouse drag event");
114
115 test.ViewSendMouseMotionTo(event_test->test_view_, -5, -5);
116 test.TestReportMsg(event_test->test_view_->registered_mouse_leave_, "Mouse leave event");
117
118 event_test->test_view_->EnableDoubleClick(true);
119 test.ViewSendMouseDoubleClick(event_test->test_view_, 1);
120 test.TestReportMsg(event_test->test_view_->registered_mouse_double_click_, "Mouse double click event");
121
122 event_test->ResetEvents();
123 // Deactivate double click and test if the view still receives it.
124 event_test->test_view_->EnableDoubleClick(false);
125 test.ViewSendMouseDoubleClick(event_test->test_view_, 1);
126 test.TestReportMsg(!event_test->test_view_->registered_mouse_double_click_, "Mouse double click de-activated");
127
128 if (test.WhenDoneTerminateProgram())
129 {
130 nux::SleepForMilliseconds(1000);
131 wnd_thread->NuxMainLoopQuit();
132 }
133 nuxDebugMsg("Exit testing thread");
134}
135
136int main(int argc, char **argv)
137{
138 int xstatus = XInitThreads();
139 nuxAssertMsg(xstatus > 0, "XInitThreads has failed");
140
141 event_test = new EventsTest("Events Test", 300, 300, 20000);
142 event_test->Startup();
143 event_test->UserInterfaceSetup();
144
145 nux::SystemThread *test_thread = nux::CreateSystemThread(event_test->GetWindowThread(), &TestingThread, event_test->GetWindowThread());
146
147 test_thread->Start(event_test);
148
149 event_test->Run();
150
151 delete test_thread;
152 delete event_test;
153
154 return 0;
155}
156
0157
=== modified file 'tests/nux_automated_test_framework.cpp'
--- tests/nux_automated_test_framework.cpp 2011-11-21 17:24:00 +0000
+++ tests/nux_automated_test_framework.cpp 2011-11-25 05:03:26 +0000
@@ -24,9 +24,10 @@
24#include "nux_automated_test_framework.h"24#include "nux_automated_test_framework.h"
2525
2626
27int NuxAutomatedTestFramework::mouse_motion_time_span = 1000;27int NuxAutomatedTestFramework::mouse_motion_time_span = 1000; // milliseconds
28int NuxAutomatedTestFramework::mouse_click_time_span = 300;28int NuxAutomatedTestFramework::mouse_click_time_span = 300; // milliseconds
29int NuxAutomatedTestFramework::safety_border_inside_view = 1;29int NuxAutomatedTestFramework::minimum_sleep_time = 600; // milliseconds
30int NuxAutomatedTestFramework::safety_border_inside_view = 1; // pixels
3031
31NuxAutomatedTestFramework::NuxAutomatedTestFramework(nux::WindowThread *window_thread)32NuxAutomatedTestFramework::NuxAutomatedTestFramework(nux::WindowThread *window_thread)
32{33{
@@ -85,6 +86,34 @@
85 SendFakeMouseEvent(button, true);86 SendFakeMouseEvent(button, true);
86 nux::SleepForMilliseconds(NuxAutomatedTestFramework::mouse_click_time_span);87 nux::SleepForMilliseconds(NuxAutomatedTestFramework::mouse_click_time_span);
87 SendFakeMouseEvent(button, false);88 SendFakeMouseEvent(button, false);
89
90 XSync(display_, False);
91 nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
92}
93
94void NuxAutomatedTestFramework::ViewSendMouseDoubleClick(nux::View *view, int button)
95{
96 nux::Rect r;
97 if (view)
98 {
99 r = view->GetAbsoluteGeometry();
100 r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2);
101 }
102 else
103 {
104 r = window_thread_->GetWindow().GetWindowGeometry();
105 r.OffsetPosition(r.width/2, r.height/2);
106 }
107
108 // Send the mouse to the center of the view
109 SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);
110
111 XTestFakeButtonEvent(display_, button, true, CurrentTime);
112 XTestFakeButtonEvent(display_, button, false, CurrentTime);
113 XTestFakeButtonEvent(display_, button, true, CurrentTime);
114 XTestFakeButtonEvent(display_, button, false, CurrentTime);
115 XSync(display_, False);
116 nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
88}117}
89118
90void NuxAutomatedTestFramework::ViewSendMouseDown(nux::View *view, int button)119void NuxAutomatedTestFramework::ViewSendMouseDown(nux::View *view, int button)
@@ -112,7 +141,7 @@
112 int view_center_x = r.x + r.width/2;141 int view_center_x = r.x + r.width/2;
113 int view_center_y = r.y + r.height/2;142 int view_center_y = r.y + r.height/2;
114 SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);143 SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
115 nux::SleepForMilliseconds(600);144 nux::SleepForMilliseconds(minimum_sleep_time);
116 }145 }
117 SendFakeMouseEvent(button, true);146 SendFakeMouseEvent(button, true);
118}147}
@@ -126,7 +155,7 @@
126 // int view_center_y = r.y + r.height/2;155 // int view_center_y = r.y + r.height/2;
127156
128 // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000);157 // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000);
129 // nux::SleepForMilliseconds(600);158 // nux::SleepForMilliseconds(minimum_sleep_time);
130 SendFakeMouseEvent(button, false);159 SendFakeMouseEvent(button, false);
131}160}
132161
@@ -139,14 +168,14 @@
139168
140 // Go to first point169 // Go to first point
141 SendFakeMouseMotionEvent(r0.x, r0.y, NuxAutomatedTestFramework::mouse_motion_time_span);170 SendFakeMouseMotionEvent(r0.x, r0.y, NuxAutomatedTestFramework::mouse_motion_time_span);
142 nux::SleepForMilliseconds(600);171 nux::SleepForMilliseconds(minimum_sleep_time);
143 172
144 // Mouse down173 // Mouse down
145 ViewSendMouseDown(view, button_index);174 ViewSendMouseDown(view, button_index);
146175
147 // Drag to second point176 // Drag to second point
148 SendFakeMouseMotionEvent(r1.x, r1.y, NuxAutomatedTestFramework::mouse_motion_time_span);177 SendFakeMouseMotionEvent(r1.x, r1.y, NuxAutomatedTestFramework::mouse_motion_time_span);
149 nux::SleepForMilliseconds(600);178 nux::SleepForMilliseconds(minimum_sleep_time);
150179
151 // Mouse up180 // Mouse up
152 ViewSendMouseUp(view, button_index);181 ViewSendMouseUp(view, button_index);
@@ -338,6 +367,12 @@
338 SendFakeKeyEvent(XK_Return, 0);367 SendFakeKeyEvent(XK_Return, 0);
339}368}
340369
370void NuxAutomatedTestFramework::PutMouseAt(int x, int y)
371{
372 XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);
373 XSync(display_, False);
374}
375
341void NuxAutomatedTestFramework::SendFakeKeyEvent(KeySym keysym, KeySym modsym)376void NuxAutomatedTestFramework::SendFakeKeyEvent(KeySym keysym, KeySym modsym)
342{377{
343 KeyCode keycode = 0;378 KeyCode keycode = 0;
@@ -410,6 +445,7 @@
410445
411 XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime); 446 XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);
412 XSync(display_, False);447 XSync(display_, False);
448 nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
413}449}
414450
415void NuxAutomatedTestFramework::TestReportMsg(bool b, const char* msg)451void NuxAutomatedTestFramework::TestReportMsg(bool b, const char* msg)
416452
=== modified file 'tests/nux_automated_test_framework.h'
--- tests/nux_automated_test_framework.h 2011-11-21 17:24:00 +0000
+++ tests/nux_automated_test_framework.h 2011-11-25 05:03:26 +0000
@@ -34,7 +34,15 @@
34 void Startup();34 void Startup();
3535
36 //! Simulate a mouse click event on a view.36 //! Simulate a mouse click event on a view.
37 /*!
38 Move the mouse to the middle of the view (if it isn't there already) and perform a click event.
39 */
37 void ViewSendMouseClick(nux::View *view, int button);40 void ViewSendMouseClick(nux::View *view, int button);
41 //! Simulate a mouse double click event on a view.
42 /*!
43 Move the mouse to the middle of the view (if it isn't there already) and perform a double click event.
44 */
45 void ViewSendMouseDoubleClick(nux::View *view, int button);
38 //! Simulate a mouse down event on a view.46 //! Simulate a mouse down event on a view.
39 void ViewSendMouseDown(nux::View *view, int button);47 void ViewSendMouseDown(nux::View *view, int button);
40 //! Simulate a mouse up event on a view.48 //! Simulate a mouse up event on a view.
@@ -73,6 +81,8 @@
73 //! Simulate Return key.81 //! Simulate Return key.
74 void ViewSendReturn();82 void ViewSendReturn();
7583
84 //! Put the mouse pointer anywhere on the display.
85 void PutMouseAt(int x, int y);
7686
77 //! Simulate a mouse event.87 //! Simulate a mouse event.
78 void SendFakeMouseEvent(int mouse_button_index, bool pressed);88 void SendFakeMouseEvent(int mouse_button_index, bool pressed);
@@ -107,9 +117,10 @@
107 int window_height_;117 int window_height_;
108 bool terminate_when_test_over_;118 bool terminate_when_test_over_;
109119
110 static int mouse_motion_time_span; // in seconds120 static int mouse_motion_time_span; // in milliseconds
111 static int mouse_click_time_span; // in seconds121 static int mouse_click_time_span; // in milliseconds
112 static int safety_border_inside_view; // in pixels122 static int minimum_sleep_time; // in milliseconds
123 static int safety_border_inside_view; // in pixels
113};124};
114125
115#endif // NUX_AUTOMATED_TEST_FRAMEWORK_H126#endif // NUX_AUTOMATED_TEST_FRAMEWORK_H
116127
=== added file 'tests/test-view.cpp'
--- tests/test-view.cpp 1970-01-01 00:00:00 +0000
+++ tests/test-view.cpp 2011-11-25 05:03:26 +0000
@@ -0,0 +1,132 @@
1
2#include "Nux/Nux.h"
3#include "test-view.h"
4
5/*
6 TestView:
7 This class is a Nux view that processes all mouse events that it receives. It is meant for testing simulated
8 mouse events.
9*/
10
11NUX_IMPLEMENT_OBJECT_TYPE(TestView);
12
13TestView::TestView(NUX_FILE_LINE_DECL)
14 : nux::View(NUX_FILE_LINE_PARAM)
15{
16 ResetEvents();
17
18 normal_color_ = nux::color::Green;
19 mouse_down_color_ = nux::color::Red;
20 mouse_drag_color_ = nux::color::Yellow;
21 mouse_in_color_ = nux::color::Blue;
22 current_color_ = normal_color_;
23
24 mouse_in_ = false;
25 mouse_mouse_drag_ = false;
26 mouse_mouse_down_ = false;
27
28 mouse_down.connect(sigc::mem_fun(this, &TestView::OnMouseDown));
29 mouse_up.connect(sigc::mem_fun(this, &TestView::OnMouseUp));
30 mouse_drag.connect(sigc::mem_fun(this, &TestView::OnMouseDrag));
31 mouse_click.connect(sigc::mem_fun(this, &TestView::OnMouseClick));
32 mouse_double_click.connect(sigc::mem_fun(this, &TestView::OnMouseDoubleClick));
33 mouse_move.connect(sigc::mem_fun(this, &TestView::OnMouseMove));
34 mouse_enter.connect(sigc::mem_fun(this, &TestView::OnMouseEnter));
35 mouse_leave.connect(sigc::mem_fun(this, &TestView::OnMouseLeave));
36}
37
38TestView::~TestView()
39{
40
41}
42
43void TestView::ResetEvents()
44{
45 registered_mouse_down_ = false;
46 registered_mouse_up_ = false;
47 registered_mouse_drag_ = false;
48 registered_mouse_enter_ = false;
49 registered_mouse_leave_ = false;
50 registered_mouse_click_ = false;
51 registered_mouse_double_click_ = false;
52 registered_mouse_move_ = false;
53 registered_mouse_enter_ = false;
54 registered_mouse_leave_ = false;
55
56}
57
58nux::Color TestView::GetColor() const
59{
60 return current_color_;
61}
62
63void TestView::Draw(nux::GraphicsEngine &graphics_engine, bool force_draw)
64{
65 nux::Geometry geo = GetGeometry();
66 graphics_engine.QRP_Color(0, 0, geo.width, geo.height, current_color_);
67}
68
69void TestView::OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags)
70{
71 registered_mouse_down_ = true;
72 current_color_ = mouse_down_color_;
73 mouse_mouse_down_ = true;
74 QueueDraw();
75}
76
77void TestView::OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags)
78{
79 registered_mouse_up_ = true;
80 if (mouse_in_)
81 current_color_ = mouse_in_color_;
82 else
83 current_color_ = normal_color_;
84
85 mouse_mouse_down_ = false;
86 mouse_mouse_drag_ = false;
87 QueueDraw();
88}
89
90void TestView::OnMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
91{
92 registered_mouse_drag_ = true;
93 current_color_ = mouse_drag_color_;
94 mouse_mouse_drag_ = true;
95 QueueDraw();
96}
97
98void TestView::OnMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
99{
100 registered_mouse_click_ = true;
101 QueueDraw();
102}
103
104void TestView::OnMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags)
105{
106 registered_mouse_double_click_ = true;
107 current_color_ = mouse_down_color_;
108 mouse_mouse_down_ = true;
109 QueueDraw();
110}
111
112void TestView::OnMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags)
113{
114 registered_mouse_move_ = true;
115 QueueDraw();
116}
117
118void TestView::OnMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags)
119{
120 registered_mouse_enter_ = true;
121 mouse_in_ = true;
122 current_color_ = mouse_in_color_;
123 QueueDraw();
124}
125
126void TestView::OnMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags)
127{
128 registered_mouse_leave_ = true;
129 mouse_in_ = false;
130 current_color_ = normal_color_;
131 QueueDraw();
132}
0133
=== added file 'tests/test-view.h'
--- tests/test-view.h 1970-01-01 00:00:00 +0000
+++ tests/test-view.h 2011-11-25 05:03:26 +0000
@@ -0,0 +1,51 @@
1
2#ifndef TEST_VIEW_H
3#define TEST_VIEW_H
4
5#include "Nux/TextureArea.h"
6
7class TestView: public nux::View
8{
9 NUX_DECLARE_OBJECT_TYPE(TestView, View);
10public:
11 TestView(NUX_FILE_LINE_PROTO);
12 ~TestView();
13
14 nux::Color GetColor() const;
15
16 void ResetEvents();
17
18 bool registered_mouse_down_;
19 bool registered_mouse_up_;
20 bool registered_mouse_drag_;
21 bool registered_mouse_click_;
22 bool registered_mouse_double_click_;
23 bool registered_mouse_move_;
24 bool registered_mouse_enter_;
25 bool registered_mouse_leave_;
26
27protected:
28 nux::Color current_color_;
29 nux::Color normal_color_;
30 nux::Color mouse_down_color_;
31 nux::Color mouse_drag_color_;
32 nux::Color mouse_in_color_;
33
34 bool mouse_in_;
35 bool mouse_mouse_drag_;
36 bool mouse_mouse_down_;
37
38 void OnMouseDown(int x, int y, unsigned long button_flags, unsigned long key_flags);
39 void OnMouseUp(int x, int y, unsigned long button_flags, unsigned long key_flags);
40 void OnMouseDrag(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
41 void OnMouseClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
42 void OnMouseDoubleClick(int x, int y, unsigned long button_flags, unsigned long key_flags);
43 void OnMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags);
44 void OnMouseEnter(int x, int y, unsigned long button_flags, unsigned long key_flags);
45 void OnMouseLeave(int x, int y, unsigned long button_flags, unsigned long key_flags);
46
47 void Draw(nux::GraphicsEngine &graphics_engine, bool force_draw);
48};
49
50#endif // TEST_VIEW_H
51

Subscribers

People subscribed via source and target branches

to all changes: