Merge lp:~3v1n0/unity/fixed-bad-quicklist-items-drawing into lp:unity
- fixed-bad-quicklist-items-drawing
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Andrea Cimitan |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1901 |
Proposed branch: | lp:~3v1n0/unity/fixed-bad-quicklist-items-drawing |
Merge into: | lp:unity |
Diff against target: |
1770 lines (+1118/-336) 13 files modified
plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp (+9/-33) plugins/unityshell/src/QuicklistMenuItemRadio.cpp (+11/-35) plugins/unityshell/src/QuicklistView.cpp (+1/-2) standalone-clients/CMakeLists.txt (+16/-8) standalone-clients/TestFilterBar.cpp (+1/-1) standalone-clients/TestFilters.cpp (+7/-7) standalone-clients/nux_automated_test_framework.cpp (+461/-0) standalone-clients/nux_automated_test_framework.h (+127/-0) standalone-clients/nux_test_framework.cpp (+129/-0) standalone-clients/nux_test_framework.h (+61/-0) standalone-clients/ui/TestQuicklist.cpp (+269/-223) standalone-clients/ui/TestQuicklistVisuals.cpp (+25/-27) tests/unit/TestQuicklistMenuitems.cpp (+1/-0) |
To merge this branch: | bzr merge lp:~3v1n0/unity/fixed-bad-quicklist-items-drawing |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Andrea Azzarone (community) | Approve | ||
Mirco Müller (community) | Needs Fixing | ||
Review via email: mp+87177@code.launchpad.net |
Commit message
Description of the change
Fixed the drawing of the radios or checkmarks quicklist menu items
When using quicklist menu-items containing radios or checkmarks, unity draws them incorrectly.
First of all, the Active logic is inverted (unactive items were marked, while active were not), then the disabled status was causing an incorrect drawing.
This is an example code that underlines the issue: http://
You can see the issue in this screenshot: http://
This branch fixes these issues, and this is the expected result: http://
(of course now it works well also when an item is prelighted)
I've not added a manual test since for the graphic nature of the issue, I guess it's hard to automatically test it (and autopilot doesn't help at all, clearly). So, let me know if this is ok.
Mirco Müller (macslow) wrote : | # |
Still can't compile/test this branch (make standalone-clients) as I get errors: https:/
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
My clients were still working from an UI side, however I've rewritten the TestQuicklist to use the nux testing framework to check the events.
There are still compilation issues with other standalone clients, but you can just check these ones by doing make quicklist-visuals && make quicklist on your standalone-clients build subdir.
Andrea Azzarone (azzar1) wrote : | # |
You've copied the entire nux test framework in the unity directory. Is it really a good idea?
Marco Trevisan (Treviño) (3v1n0) wrote : | # |
Yes, I've done what Jay told me.
That's the only possible thing until Jay won't make that interface public (planned, but not done yet).
So, for now we must do this.
Andrea Azzarone (azzar1) wrote : | # |
> Yes, I've done what Jay told me.
> That's the only possible thing until Jay won't make that interface public
> (planned, but not done yet).
>
> So, for now we must do this.
Ok, if the plan is to make the interface public, I can approve.
Preview Diff
1 | === modified file 'plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp' |
2 | --- plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp 2011-12-14 21:12:28 +0000 |
3 | +++ plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp 2012-02-01 16:25:13 +0000 |
4 | @@ -110,13 +110,12 @@ |
5 | } |
6 | |
7 | void |
8 | -QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext, |
9 | - bool forceDraw) |
10 | +QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw) |
11 | { |
12 | nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
13 | |
14 | // Check if the texture have been computed. If they haven't, exit the function. |
15 | - if (!_normalTexture[0]) |
16 | + if (!_normalTexture[0] || !_prelightTexture[0]) |
17 | return; |
18 | |
19 | nux::Geometry base = GetGeometry(); |
20 | @@ -130,42 +129,19 @@ |
21 | gfxContext.GetRenderStates().SetBlend(true); |
22 | gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
23 | |
24 | - if (GetEnabled()) |
25 | + unsigned int texture_idx = GetActive() ? 1 : 0; |
26 | + |
27 | + if (!_prelight || !GetEnabled()) |
28 | { |
29 | - if (GetActive() && _prelight) |
30 | - { |
31 | - texture = _prelightTexture[0]->GetDeviceTexture(); |
32 | - } |
33 | - else if (GetActive()) |
34 | - { |
35 | - texture = _normalTexture[0]->GetDeviceTexture(); |
36 | - } |
37 | - |
38 | - if ((!GetActive()) && _prelight) |
39 | - { |
40 | - texture = _prelightTexture[1]->GetDeviceTexture(); |
41 | - } |
42 | - else if (!GetActive()) |
43 | - { |
44 | - texture = _normalTexture[1]->GetDeviceTexture(); |
45 | - } |
46 | - |
47 | - _color = nux::color::White; |
48 | + texture = _normalTexture[texture_idx]->GetDeviceTexture(); |
49 | } |
50 | else |
51 | { |
52 | - if (GetActive()) |
53 | - { |
54 | - texture = _prelightTexture[0]->GetDeviceTexture(); |
55 | - } |
56 | - else |
57 | - { |
58 | - texture = _normalTexture[0]->GetDeviceTexture(); |
59 | - } |
60 | - |
61 | - _color = nux::Color(0.8f, 0.8f, 0.8f, 1.0f); |
62 | + texture = _prelightTexture[texture_idx]->GetDeviceTexture(); |
63 | } |
64 | |
65 | + _color = GetEnabled() ? nux::color::White : nux::Color(0.8f, 0.8f, 0.8f, 1.0f); |
66 | + |
67 | gfxContext.QRP_1Tex(base.x, |
68 | base.y, |
69 | base.width, |
70 | |
71 | === modified file 'plugins/unityshell/src/QuicklistMenuItemRadio.cpp' |
72 | --- plugins/unityshell/src/QuicklistMenuItemRadio.cpp 2011-12-14 21:12:28 +0000 |
73 | +++ plugins/unityshell/src/QuicklistMenuItemRadio.cpp 2012-02-01 16:25:13 +0000 |
74 | @@ -109,15 +109,14 @@ |
75 | } |
76 | |
77 | void |
78 | -QuicklistMenuItemRadio::Draw(nux::GraphicsEngine& gfxContext, |
79 | - bool forceDraw) |
80 | +QuicklistMenuItemRadio::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw) |
81 | { |
82 | + nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
83 | + |
84 | // Check if the texture have been computed. If they haven't, exit the function. |
85 | - if (!_normalTexture[0]) |
86 | + if (!_normalTexture[0] || !_prelightTexture[0]) |
87 | return; |
88 | |
89 | - nux::ObjectPtr<nux::IOpenGLBaseTexture> texture; |
90 | - |
91 | nux::Geometry base = GetGeometry(); |
92 | |
93 | gfxContext.PushClippingRectangle(base); |
94 | @@ -129,42 +128,19 @@ |
95 | gfxContext.GetRenderStates().SetBlend(true); |
96 | gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER); |
97 | |
98 | - if (GetEnabled()) |
99 | + unsigned int texture_idx = GetActive() ? 1 : 0; |
100 | + |
101 | + if (!_prelight || !GetEnabled()) |
102 | { |
103 | - if (GetActive() && _prelight) |
104 | - { |
105 | - texture = _prelightTexture[0]->GetDeviceTexture(); |
106 | - } |
107 | - else if (GetActive()) |
108 | - { |
109 | - texture = _normalTexture[0]->GetDeviceTexture(); |
110 | - } |
111 | - |
112 | - if ((!GetActive()) && _prelight) |
113 | - { |
114 | - texture = _prelightTexture[1]->GetDeviceTexture(); |
115 | - } |
116 | - else if (!GetActive()) |
117 | - { |
118 | - texture = _normalTexture[1]->GetDeviceTexture(); |
119 | - } |
120 | - |
121 | - _color = nux::color::White; |
122 | + texture = _normalTexture[texture_idx]->GetDeviceTexture(); |
123 | } |
124 | else |
125 | { |
126 | - if (GetActive()) |
127 | - { |
128 | - texture = _prelightTexture[0]->GetDeviceTexture(); |
129 | - } |
130 | - else |
131 | - { |
132 | - texture = _normalTexture[0]->GetDeviceTexture(); |
133 | - } |
134 | - |
135 | - _color = nux::Color(0.8f, 0.8f, 0.8f, 1.0f); |
136 | + texture = _prelightTexture[texture_idx]->GetDeviceTexture(); |
137 | } |
138 | |
139 | + _color = GetEnabled() ? nux::color::White : nux::Color(0.8f, 0.8f, 0.8f, 1.0f); |
140 | + |
141 | gfxContext.QRP_1Tex(base.x, |
142 | base.y, |
143 | base.width, |
144 | |
145 | === modified file 'plugins/unityshell/src/QuicklistView.cpp' |
146 | --- plugins/unityshell/src/QuicklistView.cpp 2011-12-19 20:20:22 +0000 |
147 | +++ plugins/unityshell/src/QuicklistView.cpp 2012-02-01 16:25:13 +0000 |
148 | @@ -905,8 +905,7 @@ |
149 | |
150 | std::list<QuicklistMenuItem*> QuicklistView::GetChildren() |
151 | { |
152 | - std::list<QuicklistMenuItem*> l; |
153 | - return l; |
154 | + return _item_list; |
155 | } |
156 | |
157 | void QuicklistView::DefaultToFirstItem() |
158 | |
159 | === modified file 'standalone-clients/CMakeLists.txt' |
160 | --- standalone-clients/CMakeLists.txt 2012-01-24 08:53:48 +0000 |
161 | +++ standalone-clients/CMakeLists.txt 2012-02-01 16:25:13 +0000 |
162 | @@ -8,7 +8,7 @@ |
163 | # Unit tests |
164 | # |
165 | find_package (PkgConfig) |
166 | -set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.0.0") |
167 | +set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.0.0 xtst") |
168 | pkg_check_modules (TEST_UNIT_DEPS REQUIRED ${TEST_DEPS}) |
169 | |
170 | set (TESTDATADIR "${CMAKE_CURRENT_SOURCE_DIR}/data") |
171 | @@ -26,7 +26,7 @@ |
172 | ) |
173 | add_definitions (${CFLAGS}) |
174 | |
175 | -set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU") |
176 | +set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU -lXtst") |
177 | link_libraries (${LIBS}) |
178 | |
179 | set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS}) |
180 | @@ -178,6 +178,8 @@ |
181 | ${UNITY_SRC}/WindowManager.cpp |
182 | ${UNITY_SRC}/IconRenderer.cpp |
183 | ${UNITY_SRC}/IconRenderer.h |
184 | + ${UNITY_SRC}/Introspectable.cpp |
185 | + ${UNITY_SRC}/Introspectable.h |
186 | ${UNITY_SRC}/MockLauncherIcon.h |
187 | ${UNITY_SRC}/BackgroundEffectHelper.h |
188 | ${UNITY_SRC}/BackgroundEffectHelper.cpp |
189 | @@ -251,6 +253,8 @@ |
190 | ${UNITY_SRC}/BackgroundEffectHelper.cpp |
191 | ${UNITY_SRC}/StaticCairoText.cpp |
192 | ${UNITY_SRC}/StaticCairoText.h |
193 | + ${UNITY_SRC}/SoftwareCenterLauncherIcon.cpp |
194 | + ${UNITY_SRC}/SoftwareCenterLauncherIcon.h |
195 | ${UNITY_SRC}/Introspectable.cpp |
196 | ${UNITY_SRC}/Introspectable.h |
197 | ${UNITY_SRC}/QuicklistMenuItem.cpp |
198 | @@ -286,8 +290,10 @@ |
199 | |
200 | add_executable (quicklist |
201 | ui/TestQuicklist.cpp |
202 | - ui/EventFaker.cpp |
203 | - ui/EventFaker.h |
204 | + nux_test_framework.cpp |
205 | + nux_test_framework.h |
206 | + nux_automated_test_framework.cpp |
207 | + nux_automated_test_framework.h |
208 | ${UNITY_SRC}/Introspectable.cpp |
209 | ${UNITY_SRC}/Introspectable.h |
210 | ${UNITY_SRC}/QuicklistMenuItem.cpp |
211 | @@ -347,16 +353,18 @@ |
212 | |
213 | add_executable (filter-bar |
214 | TestFilterBar.cpp |
215 | + ${UNITY_SRC}/FilterAllButton.cpp |
216 | + ${UNITY_SRC}/FilterBar.cpp |
217 | + ${UNITY_SRC}/FilterBasicButton.cpp |
218 | ${UNITY_SRC}/FilterExpanderLabel.cpp |
219 | ${UNITY_SRC}/FilterFactory.cpp |
220 | - ${UNITY_SRC}/FilterBasicButton.cpp |
221 | - ${UNITY_SRC}/FilterRatingsButton.cpp |
222 | - ${UNITY_SRC}/FilterRatingsWidget.cpp |
223 | ${UNITY_SRC}/FilterMultiRangeWidget.cpp |
224 | ${UNITY_SRC}/FilterMultiRangeButton.cpp |
225 | ${UNITY_SRC}/FilterGenreButton.cpp |
226 | ${UNITY_SRC}/FilterGenreWidget.cpp |
227 | - ${UNITY_SRC}/FilterBar.cpp |
228 | + ${UNITY_SRC}/FilterRatingsButton.cpp |
229 | + ${UNITY_SRC}/FilterRatingsWidget.cpp |
230 | + ${UNITY_SRC}/FilterWidget.cpp |
231 | ${UNITY_SRC}/DashStyle.cpp |
232 | ${UNITY_SRC}/JSONParser.cpp |
233 | ) |
234 | |
235 | === modified file 'standalone-clients/TestFilterBar.cpp' |
236 | --- standalone-clients/TestFilterBar.cpp 2012-01-15 22:14:35 +0000 |
237 | +++ standalone-clients/TestFilterBar.cpp 2012-02-01 16:25:13 +0000 |
238 | @@ -53,7 +53,7 @@ |
239 | |
240 | void TestRunner::Init () |
241 | { |
242 | - unity::FilterBar *filterbar = new unity::FilterBar(NUX_TRACKER_LOCATION); |
243 | + auto *filterbar = new unity::dash::FilterBar(NUX_TRACKER_LOCATION); |
244 | |
245 | layout = new nux::VLayout(NUX_TRACKER_LOCATION); |
246 | |
247 | |
248 | === modified file 'standalone-clients/TestFilters.cpp' |
249 | --- standalone-clients/TestFilters.cpp 2012-01-15 22:14:35 +0000 |
250 | +++ standalone-clients/TestFilters.cpp 2012-02-01 16:25:13 +0000 |
251 | @@ -57,13 +57,13 @@ |
252 | |
253 | void TestRunner::Init () |
254 | { |
255 | - unity::FilterBasicButton *button = new unity::FilterBasicButton ("hello world", NUX_TRACKER_LOCATION); |
256 | - unity::FilterRatingsWidget *ratings = new unity::FilterRatingsWidget (NUX_TRACKER_LOCATION); |
257 | - unity::FilterGenreButton *genre_button = new unity::FilterGenreButton ("genre button", NUX_TRACKER_LOCATION); |
258 | - |
259 | - unity::FilterGenre *genre = new unity::FilterGenre(NUX_TRACKER_LOCATION); |
260 | - |
261 | - unity::FilterMultiRange *multi_range = new unity::FilterMultiRange (NUX_TRACKER_LOCATION); |
262 | + auto *button = new unity::dash::FilterBasicButton ("hello world", NUX_TRACKER_LOCATION); |
263 | + auto *ratings = new unity::dash::FilterRatingsWidget (NUX_TRACKER_LOCATION); |
264 | + auto *genre_button = new unity::dash::FilterGenreButton ("genre button", NUX_TRACKER_LOCATION); |
265 | + |
266 | + auto *genre = new unity::dash::FilterGenre(3, NUX_TRACKER_LOCATION); |
267 | + |
268 | + auto *multi_range = new unity::dash::FilterMultiRange (NUX_TRACKER_LOCATION); |
269 | |
270 | layout = new nux::VLayout(NUX_TRACKER_LOCATION); |
271 | |
272 | |
273 | === added file 'standalone-clients/nux_automated_test_framework.cpp' |
274 | --- standalone-clients/nux_automated_test_framework.cpp 1970-01-01 00:00:00 +0000 |
275 | +++ standalone-clients/nux_automated_test_framework.cpp 2012-02-01 16:25:13 +0000 |
276 | @@ -0,0 +1,461 @@ |
277 | +/* |
278 | + * Copyright 2010 Inalogic Inc. |
279 | + * |
280 | + * This program is free software: you can redistribute it and/or modify it |
281 | + * under the terms of the GNU General Public License version 3, as published |
282 | + * by the Free Software Foundation. |
283 | + * |
284 | + * This program is distributed in the hope that it will be useful, but |
285 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
286 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
287 | + * PURPOSE. See the GNU General Public License for more details. |
288 | + * |
289 | + * You should have received a copy of the GNU General Public License |
290 | + * version 3 along with this program. If not, see |
291 | + * <http://www.gnu.org/licenses/> |
292 | + * |
293 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
294 | + * |
295 | + */ |
296 | + |
297 | +#include "Nux/Nux.h" |
298 | +#include <X11/extensions/XTest.h> |
299 | +#include <X11/keysym.h> |
300 | +#include "nux_automated_test_framework.h" |
301 | + |
302 | + |
303 | +int NuxAutomatedTestFramework::mouse_motion_time_span = 1000; // milliseconds |
304 | +int NuxAutomatedTestFramework::mouse_click_time_span = 300; // milliseconds |
305 | +int NuxAutomatedTestFramework::minimum_sleep_time = 600; // milliseconds |
306 | +int NuxAutomatedTestFramework::safety_border_inside_view = 1; // pixels |
307 | + |
308 | +NuxAutomatedTestFramework::NuxAutomatedTestFramework(nux::WindowThread *window_thread) |
309 | +{ |
310 | + ready_to_start_ = false; |
311 | + display_ = NULL; |
312 | + window_thread_ = window_thread; |
313 | + window_x_ = 0; |
314 | + window_y_ = 0; |
315 | + window_width_ = 0; |
316 | + window_height_ = 0; |
317 | + terminate_when_test_over_ = false; |
318 | +} |
319 | + |
320 | +NuxAutomatedTestFramework::~NuxAutomatedTestFramework() |
321 | +{ |
322 | + XCloseDisplay(display_); |
323 | +} |
324 | + |
325 | +void NuxAutomatedTestFramework::SetTerminateProgramWhenDone(bool terminate) |
326 | +{ |
327 | + terminate_when_test_over_ = terminate; |
328 | +} |
329 | + |
330 | +bool NuxAutomatedTestFramework::WhenDoneTerminateProgram() |
331 | +{ |
332 | + return terminate_when_test_over_; |
333 | +} |
334 | + |
335 | +void NuxAutomatedTestFramework::Startup() |
336 | +{ |
337 | + display_ = XOpenDisplay(NULL); |
338 | + nux::Geometry rect = window_thread_->GetGraphicsDisplay().GetWindowGeometry(); |
339 | + //nuxDebugMsg("Window geometry: (%d, %d, %d, %d)", rect.x, rect.y, rect.width, rect.height); |
340 | + |
341 | + window_x_ = rect.x; |
342 | + window_y_ = rect.y; |
343 | + window_width_ = rect.width; |
344 | + window_height_ = rect.height; |
345 | +} |
346 | + |
347 | +void NuxAutomatedTestFramework::ViewSendMouseClick(nux::View *view, int button) |
348 | +{ |
349 | + nux::Rect r; |
350 | + if (view) |
351 | + { |
352 | + r = view->GetAbsoluteGeometry(); |
353 | + r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2); |
354 | + } |
355 | + else |
356 | + { |
357 | + r = window_thread_->GetGraphicsDisplay().GetWindowGeometry(); |
358 | + r.OffsetPosition(r.width/2, r.height/2); |
359 | + } |
360 | + |
361 | + SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
362 | + SendFakeMouseEvent(button, true); |
363 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::mouse_click_time_span); |
364 | + SendFakeMouseEvent(button, false); |
365 | + |
366 | + XSync(display_, False); |
367 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time); |
368 | +} |
369 | + |
370 | +void NuxAutomatedTestFramework::ViewSendMouseDoubleClick(nux::View *view, int button) |
371 | +{ |
372 | + nux::Rect r; |
373 | + if (view) |
374 | + { |
375 | + r = view->GetAbsoluteGeometry(); |
376 | + r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2); |
377 | + } |
378 | + else |
379 | + { |
380 | + r = window_thread_->GetGraphicsDisplay().GetWindowGeometry(); |
381 | + r.OffsetPosition(r.width/2, r.height/2); |
382 | + } |
383 | + |
384 | + // Send the mouse to the center of the view |
385 | + SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
386 | + |
387 | + XTestFakeButtonEvent(display_, button, true, CurrentTime); |
388 | + XTestFakeButtonEvent(display_, button, false, CurrentTime); |
389 | + XTestFakeButtonEvent(display_, button, true, CurrentTime); |
390 | + XTestFakeButtonEvent(display_, button, false, CurrentTime); |
391 | + XSync(display_, False); |
392 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time); |
393 | +} |
394 | + |
395 | +void NuxAutomatedTestFramework::ViewSendMouseDown(nux::View *view, int button) |
396 | +{ |
397 | + XEvent event; |
398 | + /* Get the current pointer position */ |
399 | + XQueryPointer(display_, RootWindow(display_, 0), |
400 | + &event.xbutton.root, &event.xbutton.window, |
401 | + &event.xbutton.x_root, &event.xbutton.y_root, |
402 | + &event.xbutton.x, &event.xbutton.y, |
403 | + &event.xbutton.state); |
404 | + |
405 | + int current_x = event.xbutton.x - window_x_; |
406 | + int current_y = event.xbutton.y - window_y_; |
407 | + |
408 | + nux::Rect r = view->GetAbsoluteGeometry(); |
409 | + |
410 | + if (!r.IsInside(nux::Point(current_x, current_y))) |
411 | + { |
412 | + // The mouse pointer is not inside the view. |
413 | + // Move the mouse pointer to the center of the view. |
414 | + r.OffsetPosition(window_x_, window_y_); |
415 | + |
416 | + // Go to the center of the view |
417 | + int view_center_x = r.x + r.width/2; |
418 | + int view_center_y = r.y + r.height/2; |
419 | + SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span); |
420 | + nux::SleepForMilliseconds(minimum_sleep_time); |
421 | + } |
422 | + SendFakeMouseEvent(button, true); |
423 | +} |
424 | + |
425 | +void NuxAutomatedTestFramework::ViewSendMouseUp(nux::View *view, int button) |
426 | +{ |
427 | + // nux::Rect r = view->GetAbsoluteGeometry(); |
428 | + // r.OffsetPosition(window_x_, window_y_); |
429 | + |
430 | + // int view_center_x = r.x + r.width/2; |
431 | + // int view_center_y = r.y + r.height/2; |
432 | + |
433 | + // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000); |
434 | + // nux::SleepForMilliseconds(minimum_sleep_time); |
435 | + SendFakeMouseEvent(button, false); |
436 | +} |
437 | + |
438 | +void NuxAutomatedTestFramework::ViewSendMouseDrag(nux::View *view, int button_index, int x0, int y0, int x1, int y1) |
439 | +{ |
440 | + nux::Rect r0 = view->GetAbsoluteGeometry(); |
441 | + nux::Rect r1 = view->GetAbsoluteGeometry(); |
442 | + r0.OffsetPosition(window_x_ + x0, window_y_ + y0); |
443 | + r1.OffsetPosition(window_x_ + x1, window_y_ + y1); |
444 | + |
445 | + // Go to first point |
446 | + SendFakeMouseMotionEvent(r0.x, r0.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
447 | + nux::SleepForMilliseconds(minimum_sleep_time); |
448 | + |
449 | + // Mouse down |
450 | + ViewSendMouseDown(view, button_index); |
451 | + |
452 | + // Drag to second point |
453 | + SendFakeMouseMotionEvent(r1.x, r1.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
454 | + nux::SleepForMilliseconds(minimum_sleep_time); |
455 | + |
456 | + // Mouse up |
457 | + ViewSendMouseUp(view, button_index); |
458 | +} |
459 | + |
460 | +void NuxAutomatedTestFramework::ViewSendMouseMotionTo(nux::View *view, int x, int y) |
461 | +{ |
462 | + nux::Rect r; |
463 | + if (view) |
464 | + { |
465 | + r = view->GetAbsoluteGeometry(); |
466 | + r.OffsetPosition(window_x_ + x, window_y_ + y); |
467 | + } |
468 | + else |
469 | + { |
470 | + r = window_thread_->GetGraphicsDisplay().GetWindowGeometry(); |
471 | + r.OffsetPosition(x, y); |
472 | + } |
473 | + |
474 | + SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span); |
475 | +} |
476 | + |
477 | +void NuxAutomatedTestFramework::ViewSendMouseMotionToCenter(nux::View *view) |
478 | +{ |
479 | + nux::Rect r; |
480 | + if (view) |
481 | + { |
482 | + r = view->GetAbsoluteGeometry(); |
483 | + r.OffsetPosition(window_x_, window_y_); |
484 | + } |
485 | + else |
486 | + { |
487 | + r = window_thread_->GetGraphicsDisplay().GetWindowGeometry(); |
488 | + } |
489 | + |
490 | + int view_center_x = r.x + r.width/2; |
491 | + int view_center_y = r.y + r.height/2; |
492 | + |
493 | + SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span); |
494 | +} |
495 | + |
496 | +void NuxAutomatedTestFramework::ViewSendMouseMotionToTopLeft(nux::View *view) |
497 | +{ |
498 | + nux::Rect r = view->GetAbsoluteGeometry(); |
499 | + r.OffsetPosition(window_x_, window_y_); |
500 | + |
501 | + SendFakeMouseMotionEvent(r.x + safety_border_inside_view, r.y + safety_border_inside_view, NuxAutomatedTestFramework::mouse_motion_time_span); |
502 | +} |
503 | + |
504 | +void NuxAutomatedTestFramework::ViewSendMouseMotionToTopRight(nux::View *view) |
505 | +{ |
506 | + nux::Rect r = view->GetAbsoluteGeometry(); |
507 | + r.OffsetPosition(window_x_, window_y_); |
508 | + |
509 | + SendFakeMouseMotionEvent(r.x + r.width-1, r.y+safety_border_inside_view, NuxAutomatedTestFramework::mouse_motion_time_span); |
510 | +} |
511 | + |
512 | +void NuxAutomatedTestFramework::ViewSendMouseMotionToBottomLeft(nux::View *view) |
513 | +{ |
514 | + nux::Rect r = view->GetAbsoluteGeometry(); |
515 | + r.OffsetPosition(window_x_, window_y_); |
516 | + |
517 | + SendFakeMouseMotionEvent(r.x+safety_border_inside_view, r.y + r.height-1, NuxAutomatedTestFramework::mouse_motion_time_span); |
518 | +} |
519 | + |
520 | +void NuxAutomatedTestFramework::ViewSendMouseMotionToBottomRight(nux::View *view) |
521 | +{ |
522 | + nux::Rect r = view->GetAbsoluteGeometry(); |
523 | + r.OffsetPosition(window_x_, window_y_); |
524 | + |
525 | + SendFakeMouseMotionEvent(r.x + r.width-1, r.y + r.height-1, NuxAutomatedTestFramework::mouse_motion_time_span); |
526 | +} |
527 | + |
528 | +void NuxAutomatedTestFramework::ViewSendChar(const char c) |
529 | +{ |
530 | + KeySym modifier = 0; |
531 | + |
532 | + if ((c >= 'A') && (c <= 'Z')) |
533 | + { |
534 | + modifier = XK_Shift_L; |
535 | + } |
536 | + |
537 | + std::string s(1, c); |
538 | + SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier); |
539 | + nux::SleepForMilliseconds(300); |
540 | +} |
541 | + |
542 | +void NuxAutomatedTestFramework::ViewSendString(const std::string &str) |
543 | +{ |
544 | + int l = str.length(); |
545 | + if (l == 0) |
546 | + return; |
547 | + |
548 | + int i = 0; |
549 | + |
550 | + while (i < l) |
551 | + { |
552 | + KeySym modifier = 0; |
553 | + char c = str[i++]; |
554 | + |
555 | + if ((c >= 'A') && (c <= 'Z')) |
556 | + { |
557 | + modifier = XK_Shift_L; |
558 | + } |
559 | + |
560 | + std::string s(1, c); |
561 | + SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier); |
562 | + nux::SleepForMilliseconds(300); |
563 | + } |
564 | +} |
565 | + |
566 | +void NuxAutomatedTestFramework::ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c) |
567 | +{ |
568 | + KeyCode keycode = 0; |
569 | + KeyCode modcode0 = 0; |
570 | + KeyCode modcode1 = 0; |
571 | + KeyCode modcode2 = 0; |
572 | + |
573 | + std::string s(1, c); |
574 | + keycode = XKeysymToKeycode(display_, XStringToKeysym(s.c_str())); |
575 | + XTestGrabControl(display_, True); |
576 | + |
577 | + /* Generate modkey press */ |
578 | + if (modsym0 != 0) |
579 | + { |
580 | + modcode0 = XKeysymToKeycode(display_, modsym0); |
581 | + XTestFakeKeyEvent(display_, modcode0, True, 0); |
582 | + } |
583 | + if (modsym1 != 0) |
584 | + { |
585 | + modcode1 = XKeysymToKeycode(display_, modsym1); |
586 | + XTestFakeKeyEvent(display_, modcode1, True, 0); |
587 | + } |
588 | + if (modsym2 != 0) |
589 | + { |
590 | + modcode2 = XKeysymToKeycode(display_, modsym2); |
591 | + XTestFakeKeyEvent(display_, modcode2, True, 0); |
592 | + } |
593 | + |
594 | + /* Generate regular key press and release */ |
595 | + XTestFakeKeyEvent(display_, keycode, True, 0); |
596 | + XTestFakeKeyEvent(display_, keycode, False, 0); |
597 | + |
598 | + /* Generate modkey release */ |
599 | + if (modsym0 != 0) |
600 | + { |
601 | + XTestFakeKeyEvent(display_, modcode0, False, 0); |
602 | + } |
603 | + if (modsym1 != 0) |
604 | + { |
605 | + XTestFakeKeyEvent(display_, modcode1, False, 0); |
606 | + } |
607 | + if (modsym2 != 0) |
608 | + { |
609 | + XTestFakeKeyEvent(display_, modcode2, False, 0); |
610 | + } |
611 | + |
612 | + XSync(display_, False); |
613 | + XTestGrabControl(display_, False); |
614 | +} |
615 | + |
616 | +void NuxAutomatedTestFramework::ViewSendCtrlA() |
617 | +{ |
618 | + ViewSendKeyCombo(XK_Control_L, 0, 0, 'a'); |
619 | +} |
620 | + |
621 | +void NuxAutomatedTestFramework::ViewSendDelete() |
622 | +{ |
623 | + SendFakeKeyEvent(XK_Delete, 0); |
624 | +} |
625 | + |
626 | +void NuxAutomatedTestFramework::ViewSendBackspace() |
627 | +{ |
628 | + SendFakeKeyEvent(XK_BackSpace, 0); |
629 | +} |
630 | + |
631 | +void NuxAutomatedTestFramework::ViewSendEscape() |
632 | +{ |
633 | + SendFakeKeyEvent(XK_Escape, 0); |
634 | +} |
635 | + |
636 | +void NuxAutomatedTestFramework::ViewSendTab() |
637 | +{ |
638 | + SendFakeKeyEvent(XK_Tab, 0); |
639 | +} |
640 | + |
641 | +void NuxAutomatedTestFramework::ViewSendReturn() |
642 | +{ |
643 | + SendFakeKeyEvent(XK_Return, 0); |
644 | +} |
645 | + |
646 | +void NuxAutomatedTestFramework::PutMouseAt(int x, int y) |
647 | +{ |
648 | + XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime); |
649 | + XSync(display_, False); |
650 | +} |
651 | + |
652 | +void NuxAutomatedTestFramework::SendFakeKeyEvent(KeySym keysym, KeySym modsym) |
653 | +{ |
654 | + KeyCode keycode = 0; |
655 | + KeyCode modcode = 0; |
656 | + |
657 | + keycode = XKeysymToKeycode(display_, keysym); |
658 | + XTestGrabControl(display_, True); |
659 | + |
660 | + /* Generate modkey press */ |
661 | + if (modsym != 0) |
662 | + { |
663 | + modcode = XKeysymToKeycode(display_, modsym); |
664 | + XTestFakeKeyEvent(display_, modcode, True, 0); |
665 | + } |
666 | + |
667 | + /* Generate regular key press and release */ |
668 | + XTestFakeKeyEvent(display_, keycode, True, 0); |
669 | + XTestFakeKeyEvent(display_, keycode, False, 0); |
670 | + |
671 | + /* Generate modkey release */ |
672 | + if (modsym != 0) |
673 | + { |
674 | + XTestFakeKeyEvent(display_, modcode, False, 0); |
675 | + } |
676 | + |
677 | + XSync(display_, False); |
678 | + XTestGrabControl(display_, False); |
679 | +} |
680 | + |
681 | +void NuxAutomatedTestFramework::SendFakeMouseEvent(int mouse_button_index, bool pressed) |
682 | +{ |
683 | + XTestFakeButtonEvent(display_, mouse_button_index, pressed, CurrentTime); |
684 | + XSync(display_, False); |
685 | +} |
686 | + |
687 | +void NuxAutomatedTestFramework::SendFakeMouseMotionEvent(int x, int y, int ms_delay) |
688 | +{ |
689 | + XEvent event; |
690 | + /* Get the current pointer position */ |
691 | + XQueryPointer(display_, RootWindow(display_, 0), |
692 | + &event.xbutton.root, &event.xbutton.window, |
693 | + &event.xbutton.x_root, &event.xbutton.y_root, |
694 | + &event.xbutton.x, &event.xbutton.y, |
695 | + &event.xbutton.state); |
696 | + |
697 | + int old_x = event.xbutton.x; |
698 | + int old_y = event.xbutton.y; |
699 | + |
700 | + int n_iteration = ms_delay / 16.0f; |
701 | + |
702 | + //nuxDebugMsg("n_iteration: %d", n_iteration); |
703 | + |
704 | + if (n_iteration < 1) |
705 | + { |
706 | + n_iteration = 1; |
707 | + } |
708 | + |
709 | + XSync(display_, False); |
710 | + |
711 | + for (int i = 0; i < n_iteration; i++) |
712 | + { |
713 | + float t = ((float)i + 1.0f) / n_iteration; |
714 | + |
715 | + int cx = (1.0f - t) * old_x + t * x; |
716 | + int cy = (1.0f - t) * old_y + t * y; |
717 | + XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), cx, cy, CurrentTime); |
718 | + XSync(display_, False); |
719 | + usleep(16*1000); |
720 | + } |
721 | + |
722 | + XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime); |
723 | + XSync(display_, False); |
724 | + nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time); |
725 | +} |
726 | + |
727 | +void NuxAutomatedTestFramework::TestReportMsg(bool b, const char* msg) |
728 | +{ |
729 | + if (b) |
730 | + { |
731 | + nuxOkMsg("%s: %s", msg, "Ok"); |
732 | + } |
733 | + else |
734 | + { |
735 | + nuxAlertMsg("%s: %s", msg, "Failed"); |
736 | + } |
737 | +} |
738 | \ No newline at end of file |
739 | |
740 | === added file 'standalone-clients/nux_automated_test_framework.h' |
741 | --- standalone-clients/nux_automated_test_framework.h 1970-01-01 00:00:00 +0000 |
742 | +++ standalone-clients/nux_automated_test_framework.h 2012-02-01 16:25:13 +0000 |
743 | @@ -0,0 +1,127 @@ |
744 | +/* |
745 | + * Copyright 2010 Inalogic Inc. |
746 | + * |
747 | + * This program is free software: you can redistribute it and/or modify it |
748 | + * under the terms of the GNU General Public License version 3, as published |
749 | + * by the Free Software Foundation. |
750 | + * |
751 | + * This program is distributed in the hope that it will be useful, but |
752 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
753 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
754 | + * PURPOSE. See the GNU General Public License for more details. |
755 | + * |
756 | + * You should have received a copy of the GNU General Public License |
757 | + * version 3 along with this program. If not, see |
758 | + * <http://www.gnu.org/licenses/> |
759 | + * |
760 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
761 | + * |
762 | + */ |
763 | + |
764 | +#include <X11/extensions/XTest.h> |
765 | +#include <X11/keysym.h> |
766 | + |
767 | +#ifndef NUX_AUTOMATED_TEST_FRAMEWORK_H |
768 | +#define NUX_AUTOMATED_TEST_FRAMEWORK_H |
769 | + |
770 | +class NuxAutomatedTestFramework |
771 | +{ |
772 | +public: |
773 | + NuxAutomatedTestFramework(nux::WindowThread *window_thread); |
774 | + virtual ~NuxAutomatedTestFramework(); |
775 | + |
776 | + //! Initialize the testing framework. |
777 | + void Startup(); |
778 | + |
779 | + //! Simulate a mouse click event on a view. |
780 | + /*! |
781 | + Move the mouse to the middle of the view (if it isn't there already) and perform a click event. |
782 | + */ |
783 | + void ViewSendMouseClick(nux::View *view, int button); |
784 | + //! Simulate a mouse double click event on a view. |
785 | + /*! |
786 | + Move the mouse to the middle of the view (if it isn't there already) and perform a double click event. |
787 | + */ |
788 | + void ViewSendMouseDoubleClick(nux::View *view, int button); |
789 | + //! Simulate a mouse down event on a view. |
790 | + void ViewSendMouseDown(nux::View *view, int button); |
791 | + //! Simulate a mouse up event on a view. |
792 | + void ViewSendMouseUp(nux::View *view, int button); |
793 | + //! Simulate a drag event on a view from (x0, y0) to (x1, y1). |
794 | + void ViewSendMouseDrag(nux::View *view, int button, int x0, int y0, int x1, int y1); |
795 | + //! Simulate mouse motion to (x, y). |
796 | + void ViewSendMouseMotionTo(nux::View *view, int x, int y); |
797 | + //! Simulate mouse motion to the center of a view. |
798 | + void ViewSendMouseMotionToCenter(nux::View *view); |
799 | + //! Simulate mouse motion to the top left corner of a view. |
800 | + void ViewSendMouseMotionToTopLeft(nux::View *view); |
801 | + //! Simulate mouse motion to the top right corner of a view. |
802 | + void ViewSendMouseMotionToTopRight(nux::View *view); |
803 | + //! Simulate mouse motion to the bottom left corner of a view. |
804 | + void ViewSendMouseMotionToBottomLeft(nux::View *view); |
805 | + //! Simulate mouse motion to the bottom right corner of a view. |
806 | + void ViewSendMouseMotionToBottomRight(nux::View *view); |
807 | + |
808 | + //! Simulate a key event. |
809 | + void ViewSendChar(const char c); |
810 | + //! Simulate a succession of key events. |
811 | + void ViewSendString(const std::string &str); |
812 | + //! Simulate a key combo. |
813 | + void ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c); |
814 | + //! Simulate Ctrl+a. |
815 | + void ViewSendCtrlA(); |
816 | + //! Simulate Delete key. |
817 | + void ViewSendDelete(); |
818 | + //! Simulate Backspace key. |
819 | + void ViewSendBackspace(); |
820 | + //! Simulate Escape key. |
821 | + void ViewSendEscape(); |
822 | + //! Simulate Tab key. |
823 | + void ViewSendTab(); |
824 | + //! Simulate Return key. |
825 | + void ViewSendReturn(); |
826 | + |
827 | + //! Put the mouse pointer anywhere on the display. |
828 | + void PutMouseAt(int x, int y); |
829 | + |
830 | + //! Simulate a mouse event. |
831 | + void SendFakeMouseEvent(int mouse_button_index, bool pressed); |
832 | + //! Simulate a key event. |
833 | + void SendFakeKeyEvent(KeySym keysym, KeySym modsym); |
834 | + //! Simulate a mouse motion event. |
835 | + void SendFakeMouseMotionEvent(int x, int y, int ms_delay); |
836 | + |
837 | + /*! |
838 | + Set the test thread to terminae the program when testing is over. |
839 | + */ |
840 | + void SetTerminateProgramWhenDone(bool terminate); |
841 | + /*! |
842 | + Return true if the test thread is allowed to terminate the program after testing is over. |
843 | + */ |
844 | + bool WhenDoneTerminateProgram(); |
845 | + |
846 | + /*! |
847 | + Print a report message to the console. |
848 | + */ |
849 | + void TestReportMsg(bool b, const char* msg); |
850 | + |
851 | +private: |
852 | + void WindowConfigSignal(int x, int y, int width, int height); |
853 | + |
854 | + bool ready_to_start_; |
855 | + Display* display_; |
856 | + nux::WindowThread *window_thread_; |
857 | + int window_x_; |
858 | + int window_y_; |
859 | + int window_width_; |
860 | + int window_height_; |
861 | + bool terminate_when_test_over_; |
862 | + |
863 | + static int mouse_motion_time_span; // in milliseconds |
864 | + static int mouse_click_time_span; // in milliseconds |
865 | + static int minimum_sleep_time; // in milliseconds |
866 | + static int safety_border_inside_view; // in pixels |
867 | +}; |
868 | + |
869 | +#endif // NUX_AUTOMATED_TEST_FRAMEWORK_H |
870 | + |
871 | |
872 | === added file 'standalone-clients/nux_test_framework.cpp' |
873 | --- standalone-clients/nux_test_framework.cpp 1970-01-01 00:00:00 +0000 |
874 | +++ standalone-clients/nux_test_framework.cpp 2012-02-01 16:25:13 +0000 |
875 | @@ -0,0 +1,129 @@ |
876 | +/* |
877 | + * Copyright 2010 Inalogic Inc. |
878 | + * |
879 | + * This program is free software: you can redistribute it and/or modify it |
880 | + * under the terms of the GNU General Public License version 3, as published |
881 | + * by the Free Software Foundation. |
882 | + * |
883 | + * This program is distributed in the hope that it will be useful, but |
884 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
885 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
886 | + * PURPOSE. See the GNU General Public License for more details. |
887 | + * |
888 | + * You should have received a copy of the GNU General Public License |
889 | + * version 3 along with this program. If not, see |
890 | + * <http://www.gnu.org/licenses/> |
891 | + * |
892 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
893 | + * |
894 | + */ |
895 | + |
896 | +#include "Nux/Nux.h" |
897 | +#include "Nux/VLayout.h" |
898 | +#include "Nux/HLayout.h" |
899 | +#include "Nux/WindowThread.h" |
900 | +#include "Nux/TextEntry.h" |
901 | +#include "nux_test_framework.h" |
902 | + |
903 | + |
904 | +NuxTestFramework::NuxTestFramework(const char* program_name, |
905 | + int window_width, |
906 | + int window_height, |
907 | + int program_life_span) |
908 | +{ |
909 | + ready_to_go_ = false; |
910 | + window_width_ = window_width; |
911 | + window_height_ = window_height; |
912 | + |
913 | + if (window_width_ < 100) |
914 | + window_width_ = 100; |
915 | + |
916 | + if (window_height_ < 100) |
917 | + window_height_ = 100; |
918 | + |
919 | + timeout_signal_ = NULL; |
920 | + window_thread_ = NULL; |
921 | + program_name_ = program_name; |
922 | + program_life_span_ = program_life_span; |
923 | + |
924 | + if (program_life_span_ > 0 && program_life_span_ < 1000) |
925 | + { |
926 | + // Minimum life span is 1 second. |
927 | + program_life_span_ = 1000; |
928 | + } |
929 | +} |
930 | + |
931 | +NuxTestFramework::~NuxTestFramework() |
932 | +{ |
933 | + if (window_thread_) |
934 | + delete window_thread_; |
935 | +} |
936 | + |
937 | +void NuxTestFramework::Startup() |
938 | +{ |
939 | + nux::NuxInitialize(0); |
940 | + window_thread_ = nux::CreateGUIThread(program_name_.c_str(), window_width_, window_height_, NULL, NULL, NULL); |
941 | + |
942 | + window_thread_->window_configuration.connect(sigc::mem_fun(this, &NuxTestFramework::WaitForConfigureEvent)); |
943 | +} |
944 | + |
945 | +void NuxTestFramework::UserInterfaceSetup() |
946 | +{ |
947 | + // nux::VLayout *MainVLayout = new nux::VLayout(NUX_TRACKER_LOCATION); |
948 | + // nux::TextEntry *text_entry_0 = new nux::TextEntry(TEXT("0123456789abcdefghij"), NUX_TRACKER_LOCATION); |
949 | + |
950 | + // MainVLayout->AddView(text_entry_0, 0, nux::eCenter, nux::eFull); |
951 | + // MainVLayout->SetVerticalInternalMargin(10); |
952 | + // MainVLayout->SetContentDistribution(nux::eStackCenter); |
953 | + |
954 | + // nux::GetWindowThread()->SetLayout(MainVLayout); |
955 | + // nux::ColorLayer background(nux::Color(0xFF4D4D4D)); |
956 | + // window_thread_->SetWindowBackgroundPaintLayer(&background); |
957 | +} |
958 | + |
959 | +void NuxTestFramework::Run() |
960 | +{ |
961 | + if (window_thread_ == NULL) |
962 | + return; |
963 | + |
964 | + if (program_life_span_ > 0) |
965 | + { |
966 | + timeout_signal_ = new nux::TimeOutSignal(); |
967 | + timeout_signal_->time_expires.connect(sigc::mem_fun(this, &NuxTestFramework::ProgramExitCall)); |
968 | + window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL); |
969 | + } |
970 | + |
971 | + window_thread_->Run(NULL); |
972 | +} |
973 | + |
974 | +bool NuxTestFramework::ReadyToGo() |
975 | +{ |
976 | + return window_thread_; |
977 | +} |
978 | + |
979 | +nux::WindowThread* NuxTestFramework::GetWindowThread() |
980 | +{ |
981 | + return window_thread_; |
982 | +} |
983 | + |
984 | +void NuxTestFramework::ProgramExitCall(void *data) |
985 | +{ |
986 | + if (window_thread_) |
987 | + window_thread_->ExitMainLoop(); |
988 | +} |
989 | + |
990 | +void NuxTestFramework::WaitForConfigureEvent(int x, int y, int width, int height) |
991 | +{ |
992 | + ready_to_go_ = true; |
993 | +} |
994 | + |
995 | + |
996 | +// int main(int argc, char **argv) |
997 | +// { |
998 | +// NuxTestFramework test("Text Entry", 300, 300, 3000); |
999 | +// test.Startup(); |
1000 | +// test.UserInterfaceSetup(); |
1001 | +// test.Run(); |
1002 | + |
1003 | +// return 0; |
1004 | +// } |
1005 | |
1006 | === added file 'standalone-clients/nux_test_framework.h' |
1007 | --- standalone-clients/nux_test_framework.h 1970-01-01 00:00:00 +0000 |
1008 | +++ standalone-clients/nux_test_framework.h 2012-02-01 16:25:13 +0000 |
1009 | @@ -0,0 +1,61 @@ |
1010 | +/* |
1011 | + * Copyright 2010 Inalogic Inc. |
1012 | + * |
1013 | + * This program is free software: you can redistribute it and/or modify it |
1014 | + * under the terms of the GNU General Public License version 3, as published |
1015 | + * by the Free Software Foundation. |
1016 | + * |
1017 | + * This program is distributed in the hope that it will be useful, but |
1018 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
1019 | + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR |
1020 | + * PURPOSE. See the GNU General Public License for more details. |
1021 | + * |
1022 | + * You should have received a copy of the GNU General Public License |
1023 | + * version 3 along with this program. If not, see |
1024 | + * <http://www.gnu.org/licenses/> |
1025 | + * |
1026 | + * Authored by: Jay Taoko <jaytaoko@inalogic.com> |
1027 | + * |
1028 | + */ |
1029 | + |
1030 | +#include "Nux/Nux.h" |
1031 | +#include "Nux/VLayout.h" |
1032 | +#include "Nux/HLayout.h" |
1033 | +#include "Nux/WindowThread.h" |
1034 | +#include "Nux/TextEntry.h" |
1035 | + |
1036 | +#ifndef NUXTESTFRAMEWORK_H |
1037 | +#define NUXTESTFRAMEWORK_H |
1038 | + |
1039 | +class NuxTestFramework |
1040 | +{ |
1041 | +public: |
1042 | + NuxTestFramework(const char* program_name, int window_width, int window_height, int program_life_span); |
1043 | + virtual ~NuxTestFramework(); |
1044 | + |
1045 | + virtual void Startup(); |
1046 | + virtual void UserInterfaceSetup(); |
1047 | + virtual void Run(); |
1048 | + |
1049 | + bool ReadyToGo(); |
1050 | + |
1051 | + nux::WindowThread* GetWindowThread(); |
1052 | + |
1053 | +public: |
1054 | + std::string program_name_; |
1055 | + int program_life_span_; //!< The program will auto-terminate after a delay in milliseconds. |
1056 | + nux::TimeOutSignal *timeout_signal_; |
1057 | + |
1058 | + nux::WindowThread *window_thread_; |
1059 | + |
1060 | + int window_width_; |
1061 | + int window_height_; |
1062 | + |
1063 | +private: |
1064 | + void ProgramExitCall(void *data); |
1065 | + void WaitForConfigureEvent(int x, int y, int width, int height); |
1066 | + bool ready_to_go_; |
1067 | +}; |
1068 | + |
1069 | +#endif // NUXTESTFRAMEWORK_H |
1070 | + |
1071 | |
1072 | === modified file 'standalone-clients/ui/TestQuicklist.cpp' |
1073 | --- standalone-clients/ui/TestQuicklist.cpp 2012-01-09 16:49:50 +0000 |
1074 | +++ standalone-clients/ui/TestQuicklist.cpp 2012-02-01 16:25:13 +0000 |
1075 | @@ -14,11 +14,11 @@ |
1076 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1077 | * |
1078 | * Authored by: Mirco Müller <mirco.mueller@canonical.com> |
1079 | + * Marco Trevisan (Treviño) <3v1n0@ubuntu.com> |
1080 | */ |
1081 | |
1082 | #include <glib.h> |
1083 | #include <gtk/gtk.h> |
1084 | -#include <dbus/dbus-glib.h> |
1085 | |
1086 | #include "Nux/Nux.h" |
1087 | #include "Nux/VLayout.h" |
1088 | @@ -31,33 +31,141 @@ |
1089 | #include "QuicklistMenuItemCheckmark.h" |
1090 | #include "QuicklistMenuItemRadio.h" |
1091 | |
1092 | -#include "EventFaker.h" |
1093 | -#include <X11/Xlib.h> |
1094 | +#include "nux_test_framework.h" |
1095 | +#include "nux_automated_test_framework.h" |
1096 | |
1097 | #define WIN_WIDTH 400 |
1098 | -#define WIN_HEIGHT 300 |
1099 | - |
1100 | -gboolean gResult[3] = {false, false, false}; |
1101 | - |
1102 | -QuicklistView* gQuicklist = NULL; |
1103 | -QuicklistMenuItemCheckmark* gCheckmark = NULL; |
1104 | -QuicklistMenuItemRadio* gRadio = NULL; |
1105 | -QuicklistMenuItemLabel* gLabel = NULL; |
1106 | - |
1107 | -void |
1108 | -activatedCallback (DbusmenuMenuitem* item, |
1109 | - int time, |
1110 | - gpointer data) |
1111 | -{ |
1112 | - gboolean* result = (gboolean*) data; |
1113 | - |
1114 | - *result = true; |
1115 | - |
1116 | - g_print ("Quicklist-item activated\n"); |
1117 | -} |
1118 | - |
1119 | -QuicklistMenuItemCheckmark* |
1120 | -createCheckmarkItem () |
1121 | +#define WIN_HEIGHT 400 |
1122 | + |
1123 | +class TestQuicklist: public NuxTestFramework |
1124 | +{ |
1125 | +public: |
1126 | + TestQuicklist(const char *program_name, int window_width, int window_height, int program_life_span); |
1127 | + ~TestQuicklist(); |
1128 | + |
1129 | + virtual void UserInterfaceSetup(); |
1130 | + int ItemNaturalPosition(QuicklistMenuItem* item); |
1131 | + bool HasNthItemActivated(unsigned int index); |
1132 | + |
1133 | + QuicklistView* quicklist_; |
1134 | + std::map<QuicklistMenuItem*,bool> activated_; |
1135 | + |
1136 | +private: |
1137 | + QuicklistMenuItemSeparator* createSeparatorItem(); |
1138 | + QuicklistMenuItemLabel* createLabelItem(std::string const& label, bool enabled = true); |
1139 | + QuicklistMenuItemCheckmark* createCheckmarkItem(std::string const& label, bool enabled, bool checked); |
1140 | + QuicklistMenuItemRadio* createRadioItem(std::string const& label, bool enabled, bool checked); |
1141 | + void AddItem(QuicklistMenuItem* item); |
1142 | + |
1143 | + void connectToActivatedSignal(DbusmenuMenuitem* item); |
1144 | + static void activatedCallback(DbusmenuMenuitem* item, int time, gpointer data); |
1145 | + |
1146 | + std::map<DbusmenuMenuitem*, QuicklistMenuItem*> menus2qitem_; |
1147 | +}; |
1148 | + |
1149 | +TestQuicklist::TestQuicklist(const char *program_name, int window_width, int window_height, int program_life_span) |
1150 | + : NuxTestFramework(program_name, window_width, window_height, program_life_span), |
1151 | + quicklist_(nullptr) |
1152 | +{} |
1153 | + |
1154 | +TestQuicklist::~TestQuicklist() |
1155 | +{ |
1156 | + if (quicklist_) |
1157 | + quicklist_->UnReference(); |
1158 | +} |
1159 | + |
1160 | +int TestQuicklist::ItemNaturalPosition(QuicklistMenuItem* item) |
1161 | +{ |
1162 | + int pos = 1; |
1163 | + |
1164 | + for (auto it : quicklist_->GetChildren()) |
1165 | + { |
1166 | + if (it == item) |
1167 | + return pos; |
1168 | + |
1169 | + if (it->GetItemType() != MENUITEM_TYPE_SEPARATOR) |
1170 | + pos++; |
1171 | + } |
1172 | + |
1173 | + return -1; |
1174 | +} |
1175 | + |
1176 | +bool TestQuicklist::HasNthItemActivated(unsigned int index) |
1177 | +{ |
1178 | + return activated_[quicklist_->GetNthItems(index)]; |
1179 | +} |
1180 | + |
1181 | +void TestQuicklist::activatedCallback(DbusmenuMenuitem* item, int time, gpointer data) |
1182 | +{ |
1183 | + auto self = static_cast<TestQuicklist*>(data); |
1184 | + QuicklistMenuItem* qitem = self->menus2qitem_[item]; |
1185 | + |
1186 | + if (!self->activated_[qitem]) |
1187 | + { |
1188 | + self->activated_[qitem] = true; |
1189 | + g_debug("Quicklist-item %d activated", self->ItemNaturalPosition(qitem)); |
1190 | + } |
1191 | +} |
1192 | + |
1193 | +void TestQuicklist::connectToActivatedSignal(DbusmenuMenuitem* item) |
1194 | +{ |
1195 | + g_signal_connect (item, |
1196 | + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, |
1197 | + G_CALLBACK (&TestQuicklist::activatedCallback), |
1198 | + this); |
1199 | +} |
1200 | + |
1201 | +QuicklistMenuItemSeparator* TestQuicklist::createSeparatorItem() |
1202 | +{ |
1203 | + DbusmenuMenuitem* item = NULL; |
1204 | + QuicklistMenuItemSeparator* separator = NULL; |
1205 | + |
1206 | + item = dbusmenu_menuitem_new (); |
1207 | + |
1208 | + dbusmenu_menuitem_property_set_bool (item, |
1209 | + DBUSMENU_MENUITEM_PROP_ENABLED, |
1210 | + true); |
1211 | + |
1212 | + separator = new QuicklistMenuItemSeparator (item, true); |
1213 | + menus2qitem_[item] = separator; |
1214 | + |
1215 | + return separator; |
1216 | +} |
1217 | + |
1218 | +QuicklistMenuItemRadio* TestQuicklist::createRadioItem(std::string const& label, bool enabled, bool checked) |
1219 | +{ |
1220 | + DbusmenuMenuitem* item = NULL; |
1221 | + QuicklistMenuItemRadio* radio = NULL; |
1222 | + |
1223 | + item = dbusmenu_menuitem_new (); |
1224 | + |
1225 | + dbusmenu_menuitem_property_set (item, |
1226 | + DBUSMENU_MENUITEM_PROP_LABEL, |
1227 | + label.c_str()); |
1228 | + |
1229 | + dbusmenu_menuitem_property_set (item, |
1230 | + DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
1231 | + DBUSMENU_MENUITEM_TOGGLE_RADIO); |
1232 | + |
1233 | + dbusmenu_menuitem_property_set_bool (item, |
1234 | + DBUSMENU_MENUITEM_PROP_ENABLED, |
1235 | + enabled); |
1236 | + |
1237 | + dbusmenu_menuitem_property_set_int (item, |
1238 | + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1239 | + (checked ? |
1240 | + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : |
1241 | + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED |
1242 | + )); |
1243 | + |
1244 | + connectToActivatedSignal(item); |
1245 | + radio = new QuicklistMenuItemRadio (item, true); |
1246 | + menus2qitem_[item] = radio; |
1247 | + |
1248 | + return radio; |
1249 | +} |
1250 | + |
1251 | +QuicklistMenuItemCheckmark* TestQuicklist::createCheckmarkItem(std::string const& label, bool enabled, bool checked) |
1252 | { |
1253 | DbusmenuMenuitem* item = NULL; |
1254 | QuicklistMenuItemCheckmark* checkmark = NULL; |
1255 | @@ -66,7 +174,7 @@ |
1256 | |
1257 | dbusmenu_menuitem_property_set (item, |
1258 | DBUSMENU_MENUITEM_PROP_LABEL, |
1259 | - "Unchecked"); |
1260 | + label.c_str()); |
1261 | |
1262 | dbusmenu_menuitem_property_set (item, |
1263 | DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
1264 | @@ -74,58 +182,24 @@ |
1265 | |
1266 | dbusmenu_menuitem_property_set_bool (item, |
1267 | DBUSMENU_MENUITEM_PROP_ENABLED, |
1268 | - true); |
1269 | + enabled); |
1270 | |
1271 | dbusmenu_menuitem_property_set_int (item, |
1272 | DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1273 | - DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
1274 | + (checked ? |
1275 | + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : |
1276 | + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED |
1277 | + )); |
1278 | + |
1279 | + connectToActivatedSignal(item); |
1280 | |
1281 | checkmark = new QuicklistMenuItemCheckmark (item, true); |
1282 | - |
1283 | - g_signal_connect (item, |
1284 | - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, |
1285 | - G_CALLBACK (activatedCallback), |
1286 | - &gResult[0]); |
1287 | - |
1288 | + menus2qitem_[item] = checkmark; |
1289 | + |
1290 | return checkmark; |
1291 | } |
1292 | |
1293 | -QuicklistMenuItemRadio* |
1294 | -createRadioItem () |
1295 | -{ |
1296 | - DbusmenuMenuitem* item = NULL; |
1297 | - QuicklistMenuItemRadio* radio = NULL; |
1298 | - |
1299 | - item = dbusmenu_menuitem_new (); |
1300 | - |
1301 | - dbusmenu_menuitem_property_set (item, |
1302 | - DBUSMENU_MENUITEM_PROP_LABEL, |
1303 | - "Radio Active"); |
1304 | - |
1305 | - dbusmenu_menuitem_property_set (item, |
1306 | - DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, |
1307 | - DBUSMENU_MENUITEM_TOGGLE_RADIO); |
1308 | - |
1309 | - dbusmenu_menuitem_property_set_bool (item, |
1310 | - DBUSMENU_MENUITEM_PROP_ENABLED, |
1311 | - false); |
1312 | - |
1313 | - dbusmenu_menuitem_property_set_int (item, |
1314 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1315 | - DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
1316 | - |
1317 | - radio = new QuicklistMenuItemRadio (item, true); |
1318 | - |
1319 | - g_signal_connect (item, |
1320 | - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, |
1321 | - G_CALLBACK (activatedCallback), |
1322 | - &gResult[1]); |
1323 | - |
1324 | - return radio; |
1325 | -} |
1326 | - |
1327 | -QuicklistMenuItemLabel* |
1328 | -createLabelItem () |
1329 | +QuicklistMenuItemLabel* TestQuicklist::createLabelItem(std::string const& title, bool enabled) |
1330 | { |
1331 | DbusmenuMenuitem* item = NULL; |
1332 | QuicklistMenuItemLabel* label = NULL; |
1333 | @@ -134,172 +208,144 @@ |
1334 | |
1335 | dbusmenu_menuitem_property_set (item, |
1336 | DBUSMENU_MENUITEM_PROP_LABEL, |
1337 | - "A Label"); |
1338 | + title.c_str()); |
1339 | |
1340 | dbusmenu_menuitem_property_set_bool (item, |
1341 | DBUSMENU_MENUITEM_PROP_ENABLED, |
1342 | - true); |
1343 | + enabled); |
1344 | + |
1345 | + connectToActivatedSignal(item); |
1346 | |
1347 | label = new QuicklistMenuItemLabel (item, true); |
1348 | - |
1349 | - g_signal_connect (item, |
1350 | - DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, |
1351 | - G_CALLBACK (activatedCallback), |
1352 | - &gResult[2]); |
1353 | + menus2qitem_[item] = label; |
1354 | |
1355 | return label; |
1356 | } |
1357 | |
1358 | -void |
1359 | -ThreadWidgetInit (nux::NThread* thread, |
1360 | - void* initData) |
1361 | -{ |
1362 | - gQuicklist = new QuicklistView (); |
1363 | - gQuicklist->Reference (); |
1364 | - |
1365 | - gCheckmark = createCheckmarkItem (); |
1366 | - gQuicklist->AddMenuItem (gCheckmark); |
1367 | - gRadio = createRadioItem (); |
1368 | - gQuicklist->AddMenuItem (gRadio); |
1369 | - gLabel = createLabelItem (); |
1370 | - gQuicklist->AddMenuItem (gLabel); |
1371 | - |
1372 | - gQuicklist->EnableQuicklistForTesting (true); |
1373 | - |
1374 | - gQuicklist->SetBaseXY (0, 0); |
1375 | - gQuicklist->ShowWindow (true); |
1376 | -} |
1377 | - |
1378 | -void |
1379 | -ControlThread (nux::NThread* thread, |
1380 | - void* data) |
1381 | -{ |
1382 | - // sleep for 3 seconds |
1383 | - nux::SleepForMilliseconds (3000); |
1384 | - printf ("ControlThread successfully started\n"); |
1385 | - |
1386 | - nux::WindowThread* mainWindowThread = NUX_STATIC_CAST (nux::WindowThread*, |
1387 | - data); |
1388 | - |
1389 | - mainWindowThread->SetFakeEventMode (true); |
1390 | - Display* display = mainWindowThread->GetWindow ().GetX11Display (); |
1391 | - |
1392 | - // assemble first button-click event |
1393 | - XEvent buttonPressEvent; |
1394 | - buttonPressEvent.xbutton.type = ButtonPress; |
1395 | - buttonPressEvent.xbutton.serial = 0; |
1396 | - buttonPressEvent.xbutton.send_event = False; |
1397 | - buttonPressEvent.xbutton.display = display; |
1398 | - buttonPressEvent.xbutton.window = 0; |
1399 | - buttonPressEvent.xbutton.root = 0; |
1400 | - buttonPressEvent.xbutton.subwindow = 0; |
1401 | - buttonPressEvent.xbutton.time = CurrentTime; |
1402 | - buttonPressEvent.xbutton.x = 50; |
1403 | - buttonPressEvent.xbutton.y = 30; |
1404 | - buttonPressEvent.xbutton.x_root = 0; |
1405 | - buttonPressEvent.xbutton.y_root = 0; |
1406 | - buttonPressEvent.xbutton.state = 0; |
1407 | - buttonPressEvent.xbutton.button = Button1; |
1408 | - buttonPressEvent.xbutton.same_screen = True; |
1409 | - |
1410 | - mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread, |
1411 | - (XEvent*) &buttonPressEvent); |
1412 | - |
1413 | - while (!mainWindowThread->ReadyForNextFakeEvent ()) |
1414 | - nux::SleepForMilliseconds (10); |
1415 | - |
1416 | - XEvent buttonReleaseEvent; |
1417 | - buttonReleaseEvent.xbutton.type = ButtonRelease; |
1418 | - buttonReleaseEvent.xbutton.serial = 0; |
1419 | - buttonReleaseEvent.xbutton.send_event = False; |
1420 | - buttonReleaseEvent.xbutton.display = display; |
1421 | - buttonReleaseEvent.xbutton.window = 0; |
1422 | - buttonReleaseEvent.xbutton.root = 0; |
1423 | - buttonReleaseEvent.xbutton.subwindow = 0; |
1424 | - buttonReleaseEvent.xbutton.time = CurrentTime; |
1425 | - buttonReleaseEvent.xbutton.x = 50; |
1426 | - buttonReleaseEvent.xbutton.y = 30; |
1427 | - buttonReleaseEvent.xbutton.x_root = 0; |
1428 | - buttonReleaseEvent.xbutton.y_root = 0; |
1429 | - buttonReleaseEvent.xbutton.state = 0; |
1430 | - buttonReleaseEvent.xbutton.button = Button1; |
1431 | - buttonReleaseEvent.xbutton.same_screen = True; |
1432 | - |
1433 | - mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread, |
1434 | - (XEvent*) &buttonReleaseEvent); |
1435 | - |
1436 | - while (!mainWindowThread->ReadyForNextFakeEvent ()) |
1437 | - nux::SleepForMilliseconds (10); |
1438 | - |
1439 | - // assemble second button-click event |
1440 | - buttonPressEvent.xbutton.time = CurrentTime; |
1441 | - buttonPressEvent.xbutton.x = 50; |
1442 | - buttonPressEvent.xbutton.y = 50; |
1443 | - mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread, |
1444 | - (XEvent*) &buttonPressEvent); |
1445 | - while (!mainWindowThread->ReadyForNextFakeEvent ()) |
1446 | - nux::SleepForMilliseconds (10); |
1447 | - |
1448 | - buttonReleaseEvent.xbutton.time = CurrentTime; |
1449 | - buttonReleaseEvent.xbutton.x = 50; |
1450 | - buttonReleaseEvent.xbutton.y = 50; |
1451 | - mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread, |
1452 | - (XEvent*) &buttonReleaseEvent); |
1453 | - while (!mainWindowThread->ReadyForNextFakeEvent ()) |
1454 | - nux::SleepForMilliseconds (10); |
1455 | - |
1456 | - // assemble third button-click event |
1457 | - buttonPressEvent.xbutton.time = CurrentTime; |
1458 | - buttonPressEvent.xbutton.x = 50; |
1459 | - buttonPressEvent.xbutton.y = 70; |
1460 | - mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread, |
1461 | - (XEvent*) &buttonPressEvent); |
1462 | - while (!mainWindowThread->ReadyForNextFakeEvent ()) |
1463 | - nux::SleepForMilliseconds (10); |
1464 | - |
1465 | - buttonReleaseEvent.xbutton.time = CurrentTime; |
1466 | - buttonReleaseEvent.xbutton.x = 50; |
1467 | - buttonReleaseEvent.xbutton.y = 70; |
1468 | - mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread, |
1469 | - (XEvent*) &buttonReleaseEvent); |
1470 | - while (!mainWindowThread->ReadyForNextFakeEvent ()) |
1471 | - nux::SleepForMilliseconds (10); |
1472 | - |
1473 | - mainWindowThread->SetFakeEventMode (false); |
1474 | +void TestQuicklist::AddItem(QuicklistMenuItem* item) |
1475 | +{ |
1476 | + if (!quicklist_) |
1477 | + return; |
1478 | + |
1479 | + quicklist_->AddMenuItem(item); |
1480 | +} |
1481 | + |
1482 | +void TestQuicklist::UserInterfaceSetup() |
1483 | +{ |
1484 | + QuicklistMenuItem *item; |
1485 | + |
1486 | + quicklist_ = new QuicklistView(); |
1487 | + quicklist_->EnableQuicklistForTesting(true); |
1488 | + quicklist_->SetBaseXY(0, 0); |
1489 | + |
1490 | + item = createLabelItem("Item1, normal"); |
1491 | + AddItem(item); |
1492 | + |
1493 | + item = createSeparatorItem(); |
1494 | + AddItem(item); |
1495 | + |
1496 | + item = createRadioItem("Item2, radio, checked", true, true); |
1497 | + AddItem(item); |
1498 | + |
1499 | + item = createRadioItem("Item3, radio, unchecked", true, false); |
1500 | + AddItem(item); |
1501 | + |
1502 | + item = createRadioItem("Item4, disabled radio, checked", false, true); |
1503 | + AddItem(item); |
1504 | + |
1505 | + item = createRadioItem("Item5, disabled radio, unchecked", false, false); |
1506 | + AddItem(item); |
1507 | + |
1508 | + item = createCheckmarkItem("Item6, checkmark, checked", true, true); |
1509 | + AddItem(item); |
1510 | + |
1511 | + item = createCheckmarkItem("Item7, checkmark, unchecked", true, false); |
1512 | + AddItem(item); |
1513 | + |
1514 | + item = createCheckmarkItem("Item8, disabled checkmark, checked", false, true); |
1515 | + AddItem(item); |
1516 | + |
1517 | + item = createCheckmarkItem("Item9, disabled checkmark, unchecked", false, false); |
1518 | + AddItem(item); |
1519 | + |
1520 | + item = createLabelItem("Item10, disabled", false); |
1521 | + AddItem(item); |
1522 | + |
1523 | + quicklist_->ShowWindow(true); |
1524 | + |
1525 | + auto wt = static_cast<nux::WindowThread*>(window_thread_); |
1526 | + nux::ColorLayer background (nux::Color (0x772953)); |
1527 | + wt->SetWindowBackgroundPaintLayer(&background); |
1528 | +} |
1529 | + |
1530 | +TestQuicklist *test_quicklist = NULL; |
1531 | + |
1532 | +void TestingThread(nux::NThread *thread, void *user_data) |
1533 | +{ |
1534 | + while (test_quicklist->ReadyToGo() == false) |
1535 | + { |
1536 | + nuxDebugMsg("Waiting to start"); |
1537 | + nux::SleepForMilliseconds(300); |
1538 | + } |
1539 | + |
1540 | + nux::SleepForMilliseconds(1300); |
1541 | + |
1542 | + auto *wnd_thread = static_cast<nux::WindowThread*>(user_data); |
1543 | + |
1544 | + NuxAutomatedTestFramework test(wnd_thread); |
1545 | + |
1546 | + test.Startup(); |
1547 | + |
1548 | + for (auto child : test_quicklist->quicklist_->GetChildren()) |
1549 | + { |
1550 | + test.ViewSendMouseMotionToCenter(child); |
1551 | + test.ViewSendMouseClick(child, 1); |
1552 | + bool activated = test_quicklist->activated_[child]; |
1553 | + bool should_be_activated = (child->GetItemType() != MENUITEM_TYPE_SEPARATOR && child->GetEnabled()); |
1554 | + |
1555 | + std::string msg = std::string(child->GetLabel()); |
1556 | + msg += should_be_activated ? " | Activated" : " | NOT Activated"; |
1557 | + |
1558 | + test.TestReportMsg(activated == should_be_activated, msg.c_str()); |
1559 | + nux::SleepForMilliseconds(200); |
1560 | + } |
1561 | + |
1562 | + if (test.WhenDoneTerminateProgram()) |
1563 | + { |
1564 | + wnd_thread->ExitMainLoop(); |
1565 | + } |
1566 | + nuxDebugMsg("Exit testing thread"); |
1567 | } |
1568 | |
1569 | int |
1570 | main (int argc, char **argv) |
1571 | { |
1572 | - nux::WindowThread* wt = NULL; |
1573 | - nux::SystemThread* st = NULL; |
1574 | - |
1575 | - g_type_init (); |
1576 | - |
1577 | - gtk_init (&argc, &argv); |
1578 | - dbus_g_thread_init (); |
1579 | - nux::NuxInitialize (0); |
1580 | - |
1581 | - wt = nux::CreateGUIThread (TEXT ("Unity Quicklist"), |
1582 | - WIN_WIDTH, |
1583 | - WIN_HEIGHT, |
1584 | - 0, |
1585 | - &ThreadWidgetInit, |
1586 | - NULL); |
1587 | - |
1588 | - st = nux::CreateSystemThread (NULL, ControlThread, wt); |
1589 | - if (st) |
1590 | - st->Start (NULL); |
1591 | - |
1592 | - wt->Run (NULL); |
1593 | - |
1594 | - gQuicklist->UnReference (); |
1595 | - delete st; |
1596 | - delete wt; |
1597 | - |
1598 | - g_assert_cmpint (gResult[0], ==, true); |
1599 | - g_assert_cmpint (gResult[1], ==, true); |
1600 | - g_assert_cmpint (gResult[2], ==, true); |
1601 | + gtk_init(&argc, &argv); |
1602 | + nuxAssertMsg(XInitThreads() > 0, "XInitThreads has failed"); |
1603 | + |
1604 | + test_quicklist = new TestQuicklist("Quicklist Test", WIN_WIDTH, WIN_HEIGHT, 100000); |
1605 | + test_quicklist->Startup(); |
1606 | + test_quicklist->UserInterfaceSetup(); |
1607 | + |
1608 | + auto *test_thread = nux::CreateSystemThread(NULL, &TestingThread, test_quicklist->GetWindowThread()); |
1609 | + test_thread->Start(test_quicklist); |
1610 | + |
1611 | + test_quicklist->Run(); |
1612 | + |
1613 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(0), ==, true); |
1614 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(1), ==, false); |
1615 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(2), ==, true); |
1616 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(3), ==, true); |
1617 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(4), ==, false); |
1618 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(5), ==, false); |
1619 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(6), ==, true); |
1620 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(7), ==, true); |
1621 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(8), ==, false); |
1622 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(9), ==, false); |
1623 | + g_assert_cmpint (test_quicklist->HasNthItemActivated(10), ==, false); |
1624 | + |
1625 | + delete test_thread; |
1626 | + delete test_quicklist; |
1627 | |
1628 | return 0; |
1629 | } |
1630 | |
1631 | === modified file 'standalone-clients/ui/TestQuicklistVisuals.cpp' |
1632 | --- standalone-clients/ui/TestQuicklistVisuals.cpp 2012-01-09 16:49:50 +0000 |
1633 | +++ standalone-clients/ui/TestQuicklistVisuals.cpp 2012-02-01 16:25:13 +0000 |
1634 | @@ -18,7 +18,6 @@ |
1635 | |
1636 | #include <glib.h> |
1637 | #include <gtk/gtk.h> |
1638 | -#include <dbus/dbus-glib.h> |
1639 | |
1640 | #include "Nux/Nux.h" |
1641 | #include "Nux/VLayout.h" |
1642 | @@ -60,14 +59,12 @@ |
1643 | DBUSMENU_MENUITEM_PROP_ENABLED, |
1644 | enabled); |
1645 | |
1646 | - if (checked) |
1647 | - dbusmenu_menuitem_property_set_int (item, |
1648 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1649 | - DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
1650 | - else |
1651 | - dbusmenu_menuitem_property_set_int (item, |
1652 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1653 | - DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
1654 | + dbusmenu_menuitem_property_set_int (item, |
1655 | + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1656 | + (checked ? |
1657 | + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : |
1658 | + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED |
1659 | + )); |
1660 | |
1661 | radio = new QuicklistMenuItemRadio (item, true); |
1662 | |
1663 | @@ -96,14 +93,12 @@ |
1664 | DBUSMENU_MENUITEM_PROP_ENABLED, |
1665 | enabled); |
1666 | |
1667 | - if (checked) |
1668 | - dbusmenu_menuitem_property_set_int (item, |
1669 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1670 | - DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); |
1671 | - else |
1672 | - dbusmenu_menuitem_property_set_int (item, |
1673 | - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1674 | - DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED); |
1675 | + dbusmenu_menuitem_property_set_int (item, |
1676 | + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, |
1677 | + (checked ? |
1678 | + DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : |
1679 | + DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED |
1680 | + )); |
1681 | |
1682 | checkmark = new QuicklistMenuItemCheckmark (item, true); |
1683 | |
1684 | @@ -111,7 +106,7 @@ |
1685 | } |
1686 | |
1687 | QuicklistMenuItemLabel* |
1688 | -createLabelItem (const gchar* string) |
1689 | +createLabelItem (const gchar* string, bool enabled = true) |
1690 | { |
1691 | DbusmenuMenuitem* item = NULL; |
1692 | QuicklistMenuItemLabel* label = NULL; |
1693 | @@ -124,7 +119,7 @@ |
1694 | |
1695 | dbusmenu_menuitem_property_set_bool (item, |
1696 | DBUSMENU_MENUITEM_PROP_ENABLED, |
1697 | - true); |
1698 | + enabled); |
1699 | |
1700 | label = new QuicklistMenuItemLabel (item, true); |
1701 | |
1702 | @@ -170,7 +165,8 @@ |
1703 | gQuicklists[0]->AddMenuItem (radio); |
1704 | separator = createSeparatorItem (); |
1705 | gQuicklists[0]->AddMenuItem (separator); |
1706 | - label = createLabelItem ("Application Name"); |
1707 | + label = createLabelItem ("<b>Application Name</b>"); |
1708 | + label->EnableLabelMarkup(true); |
1709 | gQuicklists[0]->AddMenuItem (label); |
1710 | separator = createSeparatorItem (); |
1711 | gQuicklists[0]->AddMenuItem (separator); |
1712 | @@ -193,7 +189,8 @@ |
1713 | gQuicklists[1]->AddMenuItem (checkmark); |
1714 | separator = createSeparatorItem (); |
1715 | gQuicklists[1]->AddMenuItem (separator); |
1716 | - label = createLabelItem ("Application Name"); |
1717 | + label = createLabelItem ("<b>Application Name</b>"); |
1718 | + label->EnableLabelMarkup(true); |
1719 | gQuicklists[1]->AddMenuItem (label); |
1720 | separator = createSeparatorItem (); |
1721 | gQuicklists[1]->AddMenuItem (separator); |
1722 | @@ -214,11 +211,12 @@ |
1723 | gQuicklists[2]->AddMenuItem (separator); |
1724 | checkmark = createCheckmarkItem ("Option 03", false, true); |
1725 | gQuicklists[2]->AddMenuItem (checkmark); |
1726 | - checkmark = createCheckmarkItem ("Option 04", false, true); |
1727 | - gQuicklists[2]->AddMenuItem (checkmark); |
1728 | + label = createLabelItem ("Option 04", false); |
1729 | + gQuicklists[2]->AddMenuItem (label); |
1730 | separator = createSeparatorItem (); |
1731 | gQuicklists[2]->AddMenuItem (separator); |
1732 | - label = createLabelItem ("Application Name"); |
1733 | + label = createLabelItem ("<b>Application Name</b>"); |
1734 | + label->EnableLabelMarkup(true); |
1735 | gQuicklists[2]->AddMenuItem (label); |
1736 | separator = createSeparatorItem (); |
1737 | gQuicklists[2]->AddMenuItem (separator); |
1738 | @@ -227,6 +225,9 @@ |
1739 | gQuicklists[2]->EnableQuicklistForTesting (true); |
1740 | gQuicklists[2]->SetBaseXY (45, 290); |
1741 | gQuicklists[2]->ShowWindow (true); |
1742 | + |
1743 | + nux::ColorLayer background (nux::Color (0x772953)); |
1744 | + static_cast<nux::WindowThread*>(thread)->SetWindowBackgroundPaintLayer(&background); |
1745 | } |
1746 | |
1747 | int |
1748 | @@ -234,10 +235,7 @@ |
1749 | { |
1750 | nux::WindowThread* wt = NULL; |
1751 | |
1752 | - g_type_init (); |
1753 | - |
1754 | gtk_init (&argc, &argv); |
1755 | - dbus_g_thread_init (); |
1756 | nux::NuxInitialize (0); |
1757 | |
1758 | wt = nux::CreateGUIThread (TEXT ("Unity visual Quicklist-test"), |
1759 | |
1760 | === modified file 'tests/unit/TestQuicklistMenuitems.cpp' |
1761 | --- tests/unit/TestQuicklistMenuitems.cpp 2011-12-06 23:28:49 +0000 |
1762 | +++ tests/unit/TestQuicklistMenuitems.cpp 2012-02-01 16:25:13 +0000 |
1763 | @@ -241,6 +241,7 @@ |
1764 | g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1"); |
1765 | g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0"); |
1766 | |
1767 | + g_assert_cmpint(quicklist->GetChildren().size(), == , 4); |
1768 | |
1769 | quicklist->Dispose(); |
1770 | } |
Mostly looking good, but can you update the TestQuicklistMe nuitems. cpp with the code-example you posted please.