Merge lp:~3v1n0/unity/fixed-bad-quicklist-items-drawing into lp:unity

Proposed by Marco Trevisan (Treviño)
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
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
Mirco Müller (community) Needs Fixing
Review via email: mp+87177@code.launchpad.net

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://paste.ubuntu.com/788515/
You can see the issue in this screenshot: http://go.3v1n0.net/vhgofi

This branch fixes these issues, and this is the expected result: http://ubuntuone.com/5avZ10Lrd8MFxnBmRIOJfQ
(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.

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Mostly looking good, but can you update the TestQuicklistMenuitems.cpp with the code-example you posted please.

review: Needs Fixing
Revision history for this message
Mirco Müller (macslow) wrote :

Still can't compile/test this branch (make standalone-clients) as I get errors: https://pastebin.canonical.com/58842 this is not an issue of a stale libunity-core in my staging directory, I made sure that's not the case. Got to poke Alex about this, when he's online.

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

Revision history for this message
Andrea Azzarone (azzar1) wrote :

You've copied the entire nux test framework in the unity directory. Is it really a good idea?

review: Needs Information
Revision history for this message
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.

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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp'
--- plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp 2011-12-14 21:12:28 +0000
+++ plugins/unityshell/src/QuicklistMenuItemCheckmark.cpp 2012-02-01 16:25:13 +0000
@@ -110,13 +110,12 @@
110}110}
111111
112void112void
113QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext,113QuicklistMenuItemCheckmark::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
114 bool forceDraw)
115{114{
116 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;115 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
117116
118 // Check if the texture have been computed. If they haven't, exit the function.117 // Check if the texture have been computed. If they haven't, exit the function.
119 if (!_normalTexture[0])118 if (!_normalTexture[0] || !_prelightTexture[0])
120 return;119 return;
121120
122 nux::Geometry base = GetGeometry();121 nux::Geometry base = GetGeometry();
@@ -130,42 +129,19 @@
130 gfxContext.GetRenderStates().SetBlend(true);129 gfxContext.GetRenderStates().SetBlend(true);
131 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);130 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
132131
133 if (GetEnabled())132 unsigned int texture_idx = GetActive() ? 1 : 0;
133
134 if (!_prelight || !GetEnabled())
134 {135 {
135 if (GetActive() && _prelight)136 texture = _normalTexture[texture_idx]->GetDeviceTexture();
136 {
137 texture = _prelightTexture[0]->GetDeviceTexture();
138 }
139 else if (GetActive())
140 {
141 texture = _normalTexture[0]->GetDeviceTexture();
142 }
143
144 if ((!GetActive()) && _prelight)
145 {
146 texture = _prelightTexture[1]->GetDeviceTexture();
147 }
148 else if (!GetActive())
149 {
150 texture = _normalTexture[1]->GetDeviceTexture();
151 }
152
153 _color = nux::color::White;
154 }137 }
155 else138 else
156 {139 {
157 if (GetActive())140 texture = _prelightTexture[texture_idx]->GetDeviceTexture();
158 {
159 texture = _prelightTexture[0]->GetDeviceTexture();
160 }
161 else
162 {
163 texture = _normalTexture[0]->GetDeviceTexture();
164 }
165
166 _color = nux::Color(0.8f, 0.8f, 0.8f, 1.0f);
167 }141 }
168142
143 _color = GetEnabled() ? nux::color::White : nux::Color(0.8f, 0.8f, 0.8f, 1.0f);
144
169 gfxContext.QRP_1Tex(base.x,145 gfxContext.QRP_1Tex(base.x,
170 base.y,146 base.y,
171 base.width,147 base.width,
172148
=== modified file 'plugins/unityshell/src/QuicklistMenuItemRadio.cpp'
--- plugins/unityshell/src/QuicklistMenuItemRadio.cpp 2011-12-14 21:12:28 +0000
+++ plugins/unityshell/src/QuicklistMenuItemRadio.cpp 2012-02-01 16:25:13 +0000
@@ -109,15 +109,14 @@
109}109}
110110
111void111void
112QuicklistMenuItemRadio::Draw(nux::GraphicsEngine& gfxContext,112QuicklistMenuItemRadio::Draw(nux::GraphicsEngine& gfxContext, bool forceDraw)
113 bool forceDraw)
114{113{
114 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
115
115 // Check if the texture have been computed. If they haven't, exit the function.116 // Check if the texture have been computed. If they haven't, exit the function.
116 if (!_normalTexture[0])117 if (!_normalTexture[0] || !_prelightTexture[0])
117 return;118 return;
118119
119 nux::ObjectPtr<nux::IOpenGLBaseTexture> texture;
120
121 nux::Geometry base = GetGeometry();120 nux::Geometry base = GetGeometry();
122121
123 gfxContext.PushClippingRectangle(base);122 gfxContext.PushClippingRectangle(base);
@@ -129,42 +128,19 @@
129 gfxContext.GetRenderStates().SetBlend(true);128 gfxContext.GetRenderStates().SetBlend(true);
130 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);129 gfxContext.GetRenderStates().SetPremultipliedBlend(nux::SRC_OVER);
131130
132 if (GetEnabled())131 unsigned int texture_idx = GetActive() ? 1 : 0;
132
133 if (!_prelight || !GetEnabled())
133 {134 {
134 if (GetActive() && _prelight)135 texture = _normalTexture[texture_idx]->GetDeviceTexture();
135 {
136 texture = _prelightTexture[0]->GetDeviceTexture();
137 }
138 else if (GetActive())
139 {
140 texture = _normalTexture[0]->GetDeviceTexture();
141 }
142
143 if ((!GetActive()) && _prelight)
144 {
145 texture = _prelightTexture[1]->GetDeviceTexture();
146 }
147 else if (!GetActive())
148 {
149 texture = _normalTexture[1]->GetDeviceTexture();
150 }
151
152 _color = nux::color::White;
153 }136 }
154 else137 else
155 {138 {
156 if (GetActive())139 texture = _prelightTexture[texture_idx]->GetDeviceTexture();
157 {
158 texture = _prelightTexture[0]->GetDeviceTexture();
159 }
160 else
161 {
162 texture = _normalTexture[0]->GetDeviceTexture();
163 }
164
165 _color = nux::Color(0.8f, 0.8f, 0.8f, 1.0f);
166 }140 }
167141
142 _color = GetEnabled() ? nux::color::White : nux::Color(0.8f, 0.8f, 0.8f, 1.0f);
143
168 gfxContext.QRP_1Tex(base.x,144 gfxContext.QRP_1Tex(base.x,
169 base.y,145 base.y,
170 base.width,146 base.width,
171147
=== modified file 'plugins/unityshell/src/QuicklistView.cpp'
--- plugins/unityshell/src/QuicklistView.cpp 2011-12-19 20:20:22 +0000
+++ plugins/unityshell/src/QuicklistView.cpp 2012-02-01 16:25:13 +0000
@@ -905,8 +905,7 @@
905905
906std::list<QuicklistMenuItem*> QuicklistView::GetChildren()906std::list<QuicklistMenuItem*> QuicklistView::GetChildren()
907{907{
908 std::list<QuicklistMenuItem*> l;908 return _item_list;
909 return l;
910}909}
911910
912void QuicklistView::DefaultToFirstItem()911void QuicklistView::DefaultToFirstItem()
913912
=== modified file 'standalone-clients/CMakeLists.txt'
--- standalone-clients/CMakeLists.txt 2012-01-24 08:53:48 +0000
+++ standalone-clients/CMakeLists.txt 2012-02-01 16:25:13 +0000
@@ -8,7 +8,7 @@
8# Unit tests8# Unit tests
9#9#
10find_package (PkgConfig)10find_package (PkgConfig)
11set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.0.0")11set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.0.0 xtst")
12pkg_check_modules (TEST_UNIT_DEPS REQUIRED ${TEST_DEPS})12pkg_check_modules (TEST_UNIT_DEPS REQUIRED ${TEST_DEPS})
1313
14set (TESTDATADIR "${CMAKE_CURRENT_SOURCE_DIR}/data")14set (TESTDATADIR "${CMAKE_CURRENT_SOURCE_DIR}/data")
@@ -26,7 +26,7 @@
26 )26 )
27add_definitions (${CFLAGS})27add_definitions (${CFLAGS})
2828
29set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU")29set (LIBS ${TEST_UNIT_DEPS_LIBRARIES} "-lunity-core-${UNITY_API_VERSION} -lm -lGL -lGLU -lXtst")
30link_libraries (${LIBS})30link_libraries (${LIBS})
3131
32set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})32set (LIB_PATHS ${TEST_UNIT_DEPS_LIBRARY_DIRS})
@@ -178,6 +178,8 @@
178 ${UNITY_SRC}/WindowManager.cpp178 ${UNITY_SRC}/WindowManager.cpp
179 ${UNITY_SRC}/IconRenderer.cpp179 ${UNITY_SRC}/IconRenderer.cpp
180 ${UNITY_SRC}/IconRenderer.h180 ${UNITY_SRC}/IconRenderer.h
181 ${UNITY_SRC}/Introspectable.cpp
182 ${UNITY_SRC}/Introspectable.h
181 ${UNITY_SRC}/MockLauncherIcon.h183 ${UNITY_SRC}/MockLauncherIcon.h
182 ${UNITY_SRC}/BackgroundEffectHelper.h184 ${UNITY_SRC}/BackgroundEffectHelper.h
183 ${UNITY_SRC}/BackgroundEffectHelper.cpp185 ${UNITY_SRC}/BackgroundEffectHelper.cpp
@@ -251,6 +253,8 @@
251 ${UNITY_SRC}/BackgroundEffectHelper.cpp253 ${UNITY_SRC}/BackgroundEffectHelper.cpp
252 ${UNITY_SRC}/StaticCairoText.cpp254 ${UNITY_SRC}/StaticCairoText.cpp
253 ${UNITY_SRC}/StaticCairoText.h255 ${UNITY_SRC}/StaticCairoText.h
256 ${UNITY_SRC}/SoftwareCenterLauncherIcon.cpp
257 ${UNITY_SRC}/SoftwareCenterLauncherIcon.h
254 ${UNITY_SRC}/Introspectable.cpp258 ${UNITY_SRC}/Introspectable.cpp
255 ${UNITY_SRC}/Introspectable.h259 ${UNITY_SRC}/Introspectable.h
256 ${UNITY_SRC}/QuicklistMenuItem.cpp260 ${UNITY_SRC}/QuicklistMenuItem.cpp
@@ -286,8 +290,10 @@
286290
287add_executable (quicklist291add_executable (quicklist
288 ui/TestQuicklist.cpp292 ui/TestQuicklist.cpp
289 ui/EventFaker.cpp293 nux_test_framework.cpp
290 ui/EventFaker.h294 nux_test_framework.h
295 nux_automated_test_framework.cpp
296 nux_automated_test_framework.h
291 ${UNITY_SRC}/Introspectable.cpp297 ${UNITY_SRC}/Introspectable.cpp
292 ${UNITY_SRC}/Introspectable.h298 ${UNITY_SRC}/Introspectable.h
293 ${UNITY_SRC}/QuicklistMenuItem.cpp299 ${UNITY_SRC}/QuicklistMenuItem.cpp
@@ -347,16 +353,18 @@
347353
348add_executable (filter-bar354add_executable (filter-bar
349 TestFilterBar.cpp355 TestFilterBar.cpp
356 ${UNITY_SRC}/FilterAllButton.cpp
357 ${UNITY_SRC}/FilterBar.cpp
358 ${UNITY_SRC}/FilterBasicButton.cpp
350 ${UNITY_SRC}/FilterExpanderLabel.cpp359 ${UNITY_SRC}/FilterExpanderLabel.cpp
351 ${UNITY_SRC}/FilterFactory.cpp360 ${UNITY_SRC}/FilterFactory.cpp
352 ${UNITY_SRC}/FilterBasicButton.cpp
353 ${UNITY_SRC}/FilterRatingsButton.cpp
354 ${UNITY_SRC}/FilterRatingsWidget.cpp
355 ${UNITY_SRC}/FilterMultiRangeWidget.cpp361 ${UNITY_SRC}/FilterMultiRangeWidget.cpp
356 ${UNITY_SRC}/FilterMultiRangeButton.cpp362 ${UNITY_SRC}/FilterMultiRangeButton.cpp
357 ${UNITY_SRC}/FilterGenreButton.cpp363 ${UNITY_SRC}/FilterGenreButton.cpp
358 ${UNITY_SRC}/FilterGenreWidget.cpp364 ${UNITY_SRC}/FilterGenreWidget.cpp
359 ${UNITY_SRC}/FilterBar.cpp365 ${UNITY_SRC}/FilterRatingsButton.cpp
366 ${UNITY_SRC}/FilterRatingsWidget.cpp
367 ${UNITY_SRC}/FilterWidget.cpp
360 ${UNITY_SRC}/DashStyle.cpp368 ${UNITY_SRC}/DashStyle.cpp
361 ${UNITY_SRC}/JSONParser.cpp369 ${UNITY_SRC}/JSONParser.cpp
362 )370 )
363371
=== modified file 'standalone-clients/TestFilterBar.cpp'
--- standalone-clients/TestFilterBar.cpp 2012-01-15 22:14:35 +0000
+++ standalone-clients/TestFilterBar.cpp 2012-02-01 16:25:13 +0000
@@ -53,7 +53,7 @@
5353
54void TestRunner::Init ()54void TestRunner::Init ()
55{55{
56 unity::FilterBar *filterbar = new unity::FilterBar(NUX_TRACKER_LOCATION);56 auto *filterbar = new unity::dash::FilterBar(NUX_TRACKER_LOCATION);
5757
58 layout = new nux::VLayout(NUX_TRACKER_LOCATION);58 layout = new nux::VLayout(NUX_TRACKER_LOCATION);
5959
6060
=== modified file 'standalone-clients/TestFilters.cpp'
--- standalone-clients/TestFilters.cpp 2012-01-15 22:14:35 +0000
+++ standalone-clients/TestFilters.cpp 2012-02-01 16:25:13 +0000
@@ -57,13 +57,13 @@
5757
58void TestRunner::Init ()58void TestRunner::Init ()
59{59{
60 unity::FilterBasicButton *button = new unity::FilterBasicButton ("hello world", NUX_TRACKER_LOCATION);60 auto *button = new unity::dash::FilterBasicButton ("hello world", NUX_TRACKER_LOCATION);
61 unity::FilterRatingsWidget *ratings = new unity::FilterRatingsWidget (NUX_TRACKER_LOCATION);61 auto *ratings = new unity::dash::FilterRatingsWidget (NUX_TRACKER_LOCATION);
62 unity::FilterGenreButton *genre_button = new unity::FilterGenreButton ("genre button", NUX_TRACKER_LOCATION);62 auto *genre_button = new unity::dash::FilterGenreButton ("genre button", NUX_TRACKER_LOCATION);
6363
64 unity::FilterGenre *genre = new unity::FilterGenre(NUX_TRACKER_LOCATION);64 auto *genre = new unity::dash::FilterGenre(3, NUX_TRACKER_LOCATION);
6565
66 unity::FilterMultiRange *multi_range = new unity::FilterMultiRange (NUX_TRACKER_LOCATION);66 auto *multi_range = new unity::dash::FilterMultiRange (NUX_TRACKER_LOCATION);
6767
68 layout = new nux::VLayout(NUX_TRACKER_LOCATION);68 layout = new nux::VLayout(NUX_TRACKER_LOCATION);
6969
7070
=== added file 'standalone-clients/nux_automated_test_framework.cpp'
--- standalone-clients/nux_automated_test_framework.cpp 1970-01-01 00:00:00 +0000
+++ standalone-clients/nux_automated_test_framework.cpp 2012-02-01 16:25:13 +0000
@@ -0,0 +1,461 @@
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 <X11/extensions/XTest.h>
23#include <X11/keysym.h>
24#include "nux_automated_test_framework.h"
25
26
27int NuxAutomatedTestFramework::mouse_motion_time_span = 1000; // milliseconds
28int NuxAutomatedTestFramework::mouse_click_time_span = 300; // milliseconds
29int NuxAutomatedTestFramework::minimum_sleep_time = 600; // milliseconds
30int NuxAutomatedTestFramework::safety_border_inside_view = 1; // pixels
31
32NuxAutomatedTestFramework::NuxAutomatedTestFramework(nux::WindowThread *window_thread)
33{
34 ready_to_start_ = false;
35 display_ = NULL;
36 window_thread_ = window_thread;
37 window_x_ = 0;
38 window_y_ = 0;
39 window_width_ = 0;
40 window_height_ = 0;
41 terminate_when_test_over_ = false;
42}
43
44NuxAutomatedTestFramework::~NuxAutomatedTestFramework()
45{
46 XCloseDisplay(display_);
47}
48
49void NuxAutomatedTestFramework::SetTerminateProgramWhenDone(bool terminate)
50{
51 terminate_when_test_over_ = terminate;
52}
53
54bool NuxAutomatedTestFramework::WhenDoneTerminateProgram()
55{
56 return terminate_when_test_over_;
57}
58
59void NuxAutomatedTestFramework::Startup()
60{
61 display_ = XOpenDisplay(NULL);
62 nux::Geometry rect = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
63 //nuxDebugMsg("Window geometry: (%d, %d, %d, %d)", rect.x, rect.y, rect.width, rect.height);
64
65 window_x_ = rect.x;
66 window_y_ = rect.y;
67 window_width_ = rect.width;
68 window_height_ = rect.height;
69}
70
71void NuxAutomatedTestFramework::ViewSendMouseClick(nux::View *view, int button)
72{
73 nux::Rect r;
74 if (view)
75 {
76 r = view->GetAbsoluteGeometry();
77 r.OffsetPosition(window_x_ + r.width/2, window_y_ + r.height/2);
78 }
79 else
80 {
81 r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
82 r.OffsetPosition(r.width/2, r.height/2);
83 }
84
85 SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);
86 SendFakeMouseEvent(button, true);
87 nux::SleepForMilliseconds(NuxAutomatedTestFramework::mouse_click_time_span);
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_->GetGraphicsDisplay().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);
117}
118
119void NuxAutomatedTestFramework::ViewSendMouseDown(nux::View *view, int button)
120{
121 XEvent event;
122 /* Get the current pointer position */
123 XQueryPointer(display_, RootWindow(display_, 0),
124 &event.xbutton.root, &event.xbutton.window,
125 &event.xbutton.x_root, &event.xbutton.y_root,
126 &event.xbutton.x, &event.xbutton.y,
127 &event.xbutton.state);
128
129 int current_x = event.xbutton.x - window_x_;
130 int current_y = event.xbutton.y - window_y_;
131
132 nux::Rect r = view->GetAbsoluteGeometry();
133
134 if (!r.IsInside(nux::Point(current_x, current_y)))
135 {
136 // The mouse pointer is not inside the view.
137 // Move the mouse pointer to the center of the view.
138 r.OffsetPosition(window_x_, window_y_);
139
140 // Go to the center of the view
141 int view_center_x = r.x + r.width/2;
142 int view_center_y = r.y + r.height/2;
143 SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
144 nux::SleepForMilliseconds(minimum_sleep_time);
145 }
146 SendFakeMouseEvent(button, true);
147}
148
149void NuxAutomatedTestFramework::ViewSendMouseUp(nux::View *view, int button)
150{
151 // nux::Rect r = view->GetAbsoluteGeometry();
152 // r.OffsetPosition(window_x_, window_y_);
153
154 // int view_center_x = r.x + r.width/2;
155 // int view_center_y = r.y + r.height/2;
156
157 // SendFakeMouseMotionEvent(view_center_x, view_center_y, 1000);
158 // nux::SleepForMilliseconds(minimum_sleep_time);
159 SendFakeMouseEvent(button, false);
160}
161
162void NuxAutomatedTestFramework::ViewSendMouseDrag(nux::View *view, int button_index, int x0, int y0, int x1, int y1)
163{
164 nux::Rect r0 = view->GetAbsoluteGeometry();
165 nux::Rect r1 = view->GetAbsoluteGeometry();
166 r0.OffsetPosition(window_x_ + x0, window_y_ + y0);
167 r1.OffsetPosition(window_x_ + x1, window_y_ + y1);
168
169 // Go to first point
170 SendFakeMouseMotionEvent(r0.x, r0.y, NuxAutomatedTestFramework::mouse_motion_time_span);
171 nux::SleepForMilliseconds(minimum_sleep_time);
172
173 // Mouse down
174 ViewSendMouseDown(view, button_index);
175
176 // Drag to second point
177 SendFakeMouseMotionEvent(r1.x, r1.y, NuxAutomatedTestFramework::mouse_motion_time_span);
178 nux::SleepForMilliseconds(minimum_sleep_time);
179
180 // Mouse up
181 ViewSendMouseUp(view, button_index);
182}
183
184void NuxAutomatedTestFramework::ViewSendMouseMotionTo(nux::View *view, int x, int y)
185{
186 nux::Rect r;
187 if (view)
188 {
189 r = view->GetAbsoluteGeometry();
190 r.OffsetPosition(window_x_ + x, window_y_ + y);
191 }
192 else
193 {
194 r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
195 r.OffsetPosition(x, y);
196 }
197
198 SendFakeMouseMotionEvent(r.x, r.y, NuxAutomatedTestFramework::mouse_motion_time_span);
199}
200
201void NuxAutomatedTestFramework::ViewSendMouseMotionToCenter(nux::View *view)
202{
203 nux::Rect r;
204 if (view)
205 {
206 r = view->GetAbsoluteGeometry();
207 r.OffsetPosition(window_x_, window_y_);
208 }
209 else
210 {
211 r = window_thread_->GetGraphicsDisplay().GetWindowGeometry();
212 }
213
214 int view_center_x = r.x + r.width/2;
215 int view_center_y = r.y + r.height/2;
216
217 SendFakeMouseMotionEvent(view_center_x, view_center_y, NuxAutomatedTestFramework::mouse_motion_time_span);
218}
219
220void NuxAutomatedTestFramework::ViewSendMouseMotionToTopLeft(nux::View *view)
221{
222 nux::Rect r = view->GetAbsoluteGeometry();
223 r.OffsetPosition(window_x_, window_y_);
224
225 SendFakeMouseMotionEvent(r.x + safety_border_inside_view, r.y + safety_border_inside_view, NuxAutomatedTestFramework::mouse_motion_time_span);
226}
227
228void NuxAutomatedTestFramework::ViewSendMouseMotionToTopRight(nux::View *view)
229{
230 nux::Rect r = view->GetAbsoluteGeometry();
231 r.OffsetPosition(window_x_, window_y_);
232
233 SendFakeMouseMotionEvent(r.x + r.width-1, r.y+safety_border_inside_view, NuxAutomatedTestFramework::mouse_motion_time_span);
234}
235
236void NuxAutomatedTestFramework::ViewSendMouseMotionToBottomLeft(nux::View *view)
237{
238 nux::Rect r = view->GetAbsoluteGeometry();
239 r.OffsetPosition(window_x_, window_y_);
240
241 SendFakeMouseMotionEvent(r.x+safety_border_inside_view, r.y + r.height-1, NuxAutomatedTestFramework::mouse_motion_time_span);
242}
243
244void NuxAutomatedTestFramework::ViewSendMouseMotionToBottomRight(nux::View *view)
245{
246 nux::Rect r = view->GetAbsoluteGeometry();
247 r.OffsetPosition(window_x_, window_y_);
248
249 SendFakeMouseMotionEvent(r.x + r.width-1, r.y + r.height-1, NuxAutomatedTestFramework::mouse_motion_time_span);
250}
251
252void NuxAutomatedTestFramework::ViewSendChar(const char c)
253{
254 KeySym modifier = 0;
255
256 if ((c >= 'A') && (c <= 'Z'))
257 {
258 modifier = XK_Shift_L;
259 }
260
261 std::string s(1, c);
262 SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier);
263 nux::SleepForMilliseconds(300);
264}
265
266void NuxAutomatedTestFramework::ViewSendString(const std::string &str)
267{
268 int l = str.length();
269 if (l == 0)
270 return;
271
272 int i = 0;
273
274 while (i < l)
275 {
276 KeySym modifier = 0;
277 char c = str[i++];
278
279 if ((c >= 'A') && (c <= 'Z'))
280 {
281 modifier = XK_Shift_L;
282 }
283
284 std::string s(1, c);
285 SendFakeKeyEvent(XStringToKeysym(s.c_str()), modifier);
286 nux::SleepForMilliseconds(300);
287 }
288}
289
290void NuxAutomatedTestFramework::ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c)
291{
292 KeyCode keycode = 0;
293 KeyCode modcode0 = 0;
294 KeyCode modcode1 = 0;
295 KeyCode modcode2 = 0;
296
297 std::string s(1, c);
298 keycode = XKeysymToKeycode(display_, XStringToKeysym(s.c_str()));
299 XTestGrabControl(display_, True);
300
301 /* Generate modkey press */
302 if (modsym0 != 0)
303 {
304 modcode0 = XKeysymToKeycode(display_, modsym0);
305 XTestFakeKeyEvent(display_, modcode0, True, 0);
306 }
307 if (modsym1 != 0)
308 {
309 modcode1 = XKeysymToKeycode(display_, modsym1);
310 XTestFakeKeyEvent(display_, modcode1, True, 0);
311 }
312 if (modsym2 != 0)
313 {
314 modcode2 = XKeysymToKeycode(display_, modsym2);
315 XTestFakeKeyEvent(display_, modcode2, True, 0);
316 }
317
318 /* Generate regular key press and release */
319 XTestFakeKeyEvent(display_, keycode, True, 0);
320 XTestFakeKeyEvent(display_, keycode, False, 0);
321
322 /* Generate modkey release */
323 if (modsym0 != 0)
324 {
325 XTestFakeKeyEvent(display_, modcode0, False, 0);
326 }
327 if (modsym1 != 0)
328 {
329 XTestFakeKeyEvent(display_, modcode1, False, 0);
330 }
331 if (modsym2 != 0)
332 {
333 XTestFakeKeyEvent(display_, modcode2, False, 0);
334 }
335
336 XSync(display_, False);
337 XTestGrabControl(display_, False);
338}
339
340void NuxAutomatedTestFramework::ViewSendCtrlA()
341{
342 ViewSendKeyCombo(XK_Control_L, 0, 0, 'a');
343}
344
345void NuxAutomatedTestFramework::ViewSendDelete()
346{
347 SendFakeKeyEvent(XK_Delete, 0);
348}
349
350void NuxAutomatedTestFramework::ViewSendBackspace()
351{
352 SendFakeKeyEvent(XK_BackSpace, 0);
353}
354
355void NuxAutomatedTestFramework::ViewSendEscape()
356{
357 SendFakeKeyEvent(XK_Escape, 0);
358}
359
360void NuxAutomatedTestFramework::ViewSendTab()
361{
362 SendFakeKeyEvent(XK_Tab, 0);
363}
364
365void NuxAutomatedTestFramework::ViewSendReturn()
366{
367 SendFakeKeyEvent(XK_Return, 0);
368}
369
370void NuxAutomatedTestFramework::PutMouseAt(int x, int y)
371{
372 XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);
373 XSync(display_, False);
374}
375
376void NuxAutomatedTestFramework::SendFakeKeyEvent(KeySym keysym, KeySym modsym)
377{
378 KeyCode keycode = 0;
379 KeyCode modcode = 0;
380
381 keycode = XKeysymToKeycode(display_, keysym);
382 XTestGrabControl(display_, True);
383
384 /* Generate modkey press */
385 if (modsym != 0)
386 {
387 modcode = XKeysymToKeycode(display_, modsym);
388 XTestFakeKeyEvent(display_, modcode, True, 0);
389 }
390
391 /* Generate regular key press and release */
392 XTestFakeKeyEvent(display_, keycode, True, 0);
393 XTestFakeKeyEvent(display_, keycode, False, 0);
394
395 /* Generate modkey release */
396 if (modsym != 0)
397 {
398 XTestFakeKeyEvent(display_, modcode, False, 0);
399 }
400
401 XSync(display_, False);
402 XTestGrabControl(display_, False);
403}
404
405void NuxAutomatedTestFramework::SendFakeMouseEvent(int mouse_button_index, bool pressed)
406{
407 XTestFakeButtonEvent(display_, mouse_button_index, pressed, CurrentTime);
408 XSync(display_, False);
409}
410
411void NuxAutomatedTestFramework::SendFakeMouseMotionEvent(int x, int y, int ms_delay)
412{
413 XEvent event;
414 /* Get the current pointer position */
415 XQueryPointer(display_, RootWindow(display_, 0),
416 &event.xbutton.root, &event.xbutton.window,
417 &event.xbutton.x_root, &event.xbutton.y_root,
418 &event.xbutton.x, &event.xbutton.y,
419 &event.xbutton.state);
420
421 int old_x = event.xbutton.x;
422 int old_y = event.xbutton.y;
423
424 int n_iteration = ms_delay / 16.0f;
425
426 //nuxDebugMsg("n_iteration: %d", n_iteration);
427
428 if (n_iteration < 1)
429 {
430 n_iteration = 1;
431 }
432
433 XSync(display_, False);
434
435 for (int i = 0; i < n_iteration; i++)
436 {
437 float t = ((float)i + 1.0f) / n_iteration;
438
439 int cx = (1.0f - t) * old_x + t * x;
440 int cy = (1.0f - t) * old_y + t * y;
441 XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), cx, cy, CurrentTime);
442 XSync(display_, False);
443 usleep(16*1000);
444 }
445
446 XTestFakeMotionEvent(display_, XScreenNumberOfScreen(DefaultScreenOfDisplay(display_)), x, y, CurrentTime);
447 XSync(display_, False);
448 nux::SleepForMilliseconds(NuxAutomatedTestFramework::minimum_sleep_time);
449}
450
451void NuxAutomatedTestFramework::TestReportMsg(bool b, const char* msg)
452{
453 if (b)
454 {
455 nuxOkMsg("%s: %s", msg, "Ok");
456 }
457 else
458 {
459 nuxAlertMsg("%s: %s", msg, "Failed");
460 }
461}
0\ No newline at end of file462\ No newline at end of file
1463
=== added file 'standalone-clients/nux_automated_test_framework.h'
--- standalone-clients/nux_automated_test_framework.h 1970-01-01 00:00:00 +0000
+++ standalone-clients/nux_automated_test_framework.h 2012-02-01 16:25:13 +0000
@@ -0,0 +1,127 @@
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 <X11/extensions/XTest.h>
22#include <X11/keysym.h>
23
24#ifndef NUX_AUTOMATED_TEST_FRAMEWORK_H
25#define NUX_AUTOMATED_TEST_FRAMEWORK_H
26
27class NuxAutomatedTestFramework
28{
29public:
30 NuxAutomatedTestFramework(nux::WindowThread *window_thread);
31 virtual ~NuxAutomatedTestFramework();
32
33 //! Initialize the testing framework.
34 void Startup();
35
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 */
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);
46 //! Simulate a mouse down event on a view.
47 void ViewSendMouseDown(nux::View *view, int button);
48 //! Simulate a mouse up event on a view.
49 void ViewSendMouseUp(nux::View *view, int button);
50 //! Simulate a drag event on a view from (x0, y0) to (x1, y1).
51 void ViewSendMouseDrag(nux::View *view, int button, int x0, int y0, int x1, int y1);
52 //! Simulate mouse motion to (x, y).
53 void ViewSendMouseMotionTo(nux::View *view, int x, int y);
54 //! Simulate mouse motion to the center of a view.
55 void ViewSendMouseMotionToCenter(nux::View *view);
56 //! Simulate mouse motion to the top left corner of a view.
57 void ViewSendMouseMotionToTopLeft(nux::View *view);
58 //! Simulate mouse motion to the top right corner of a view.
59 void ViewSendMouseMotionToTopRight(nux::View *view);
60 //! Simulate mouse motion to the bottom left corner of a view.
61 void ViewSendMouseMotionToBottomLeft(nux::View *view);
62 //! Simulate mouse motion to the bottom right corner of a view.
63 void ViewSendMouseMotionToBottomRight(nux::View *view);
64
65 //! Simulate a key event.
66 void ViewSendChar(const char c);
67 //! Simulate a succession of key events.
68 void ViewSendString(const std::string &str);
69 //! Simulate a key combo.
70 void ViewSendKeyCombo(KeySym modsym0, KeySym modsym1, KeySym modsym2, const char c);
71 //! Simulate Ctrl+a.
72 void ViewSendCtrlA();
73 //! Simulate Delete key.
74 void ViewSendDelete();
75 //! Simulate Backspace key.
76 void ViewSendBackspace();
77 //! Simulate Escape key.
78 void ViewSendEscape();
79 //! Simulate Tab key.
80 void ViewSendTab();
81 //! Simulate Return key.
82 void ViewSendReturn();
83
84 //! Put the mouse pointer anywhere on the display.
85 void PutMouseAt(int x, int y);
86
87 //! Simulate a mouse event.
88 void SendFakeMouseEvent(int mouse_button_index, bool pressed);
89 //! Simulate a key event.
90 void SendFakeKeyEvent(KeySym keysym, KeySym modsym);
91 //! Simulate a mouse motion event.
92 void SendFakeMouseMotionEvent(int x, int y, int ms_delay);
93
94 /*!
95 Set the test thread to terminae the program when testing is over.
96 */
97 void SetTerminateProgramWhenDone(bool terminate);
98 /*!
99 Return true if the test thread is allowed to terminate the program after testing is over.
100 */
101 bool WhenDoneTerminateProgram();
102
103 /*!
104 Print a report message to the console.
105 */
106 void TestReportMsg(bool b, const char* msg);
107
108private:
109 void WindowConfigSignal(int x, int y, int width, int height);
110
111 bool ready_to_start_;
112 Display* display_;
113 nux::WindowThread *window_thread_;
114 int window_x_;
115 int window_y_;
116 int window_width_;
117 int window_height_;
118 bool terminate_when_test_over_;
119
120 static int mouse_motion_time_span; // in milliseconds
121 static int mouse_click_time_span; // in milliseconds
122 static int minimum_sleep_time; // in milliseconds
123 static int safety_border_inside_view; // in pixels
124};
125
126#endif // NUX_AUTOMATED_TEST_FRAMEWORK_H
127
0128
=== added file 'standalone-clients/nux_test_framework.cpp'
--- standalone-clients/nux_test_framework.cpp 1970-01-01 00:00:00 +0000
+++ standalone-clients/nux_test_framework.cpp 2012-02-01 16:25:13 +0000
@@ -0,0 +1,129 @@
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/VLayout.h"
23#include "Nux/HLayout.h"
24#include "Nux/WindowThread.h"
25#include "Nux/TextEntry.h"
26#include "nux_test_framework.h"
27
28
29NuxTestFramework::NuxTestFramework(const char* program_name,
30 int window_width,
31 int window_height,
32 int program_life_span)
33{
34 ready_to_go_ = false;
35 window_width_ = window_width;
36 window_height_ = window_height;
37
38 if (window_width_ < 100)
39 window_width_ = 100;
40
41 if (window_height_ < 100)
42 window_height_ = 100;
43
44 timeout_signal_ = NULL;
45 window_thread_ = NULL;
46 program_name_ = program_name;
47 program_life_span_ = program_life_span;
48
49 if (program_life_span_ > 0 && program_life_span_ < 1000)
50 {
51 // Minimum life span is 1 second.
52 program_life_span_ = 1000;
53 }
54}
55
56NuxTestFramework::~NuxTestFramework()
57{
58 if (window_thread_)
59 delete window_thread_;
60}
61
62void NuxTestFramework::Startup()
63{
64 nux::NuxInitialize(0);
65 window_thread_ = nux::CreateGUIThread(program_name_.c_str(), window_width_, window_height_, NULL, NULL, NULL);
66
67 window_thread_->window_configuration.connect(sigc::mem_fun(this, &NuxTestFramework::WaitForConfigureEvent));
68}
69
70void NuxTestFramework::UserInterfaceSetup()
71{
72 // nux::VLayout *MainVLayout = new nux::VLayout(NUX_TRACKER_LOCATION);
73 // nux::TextEntry *text_entry_0 = new nux::TextEntry(TEXT("0123456789abcdefghij"), NUX_TRACKER_LOCATION);
74
75 // MainVLayout->AddView(text_entry_0, 0, nux::eCenter, nux::eFull);
76 // MainVLayout->SetVerticalInternalMargin(10);
77 // MainVLayout->SetContentDistribution(nux::eStackCenter);
78
79 // nux::GetWindowThread()->SetLayout(MainVLayout);
80 // nux::ColorLayer background(nux::Color(0xFF4D4D4D));
81 // window_thread_->SetWindowBackgroundPaintLayer(&background);
82}
83
84void NuxTestFramework::Run()
85{
86 if (window_thread_ == NULL)
87 return;
88
89 if (program_life_span_ > 0)
90 {
91 timeout_signal_ = new nux::TimeOutSignal();
92 timeout_signal_->time_expires.connect(sigc::mem_fun(this, &NuxTestFramework::ProgramExitCall));
93 window_thread_->GetTimerHandler().AddTimerHandler(program_life_span_, timeout_signal_, NULL, NULL);
94 }
95
96 window_thread_->Run(NULL);
97}
98
99bool NuxTestFramework::ReadyToGo()
100{
101 return window_thread_;
102}
103
104nux::WindowThread* NuxTestFramework::GetWindowThread()
105{
106 return window_thread_;
107}
108
109void NuxTestFramework::ProgramExitCall(void *data)
110{
111 if (window_thread_)
112 window_thread_->ExitMainLoop();
113}
114
115void NuxTestFramework::WaitForConfigureEvent(int x, int y, int width, int height)
116{
117 ready_to_go_ = true;
118}
119
120
121// int main(int argc, char **argv)
122// {
123// NuxTestFramework test("Text Entry", 300, 300, 3000);
124// test.Startup();
125// test.UserInterfaceSetup();
126// test.Run();
127
128// return 0;
129// }
0130
=== added file 'standalone-clients/nux_test_framework.h'
--- standalone-clients/nux_test_framework.h 1970-01-01 00:00:00 +0000
+++ standalone-clients/nux_test_framework.h 2012-02-01 16:25:13 +0000
@@ -0,0 +1,61 @@
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/VLayout.h"
23#include "Nux/HLayout.h"
24#include "Nux/WindowThread.h"
25#include "Nux/TextEntry.h"
26
27#ifndef NUXTESTFRAMEWORK_H
28#define NUXTESTFRAMEWORK_H
29
30class NuxTestFramework
31{
32public:
33 NuxTestFramework(const char* program_name, int window_width, int window_height, int program_life_span);
34 virtual ~NuxTestFramework();
35
36 virtual void Startup();
37 virtual void UserInterfaceSetup();
38 virtual void Run();
39
40 bool ReadyToGo();
41
42 nux::WindowThread* GetWindowThread();
43
44public:
45 std::string program_name_;
46 int program_life_span_; //!< The program will auto-terminate after a delay in milliseconds.
47 nux::TimeOutSignal *timeout_signal_;
48
49 nux::WindowThread *window_thread_;
50
51 int window_width_;
52 int window_height_;
53
54private:
55 void ProgramExitCall(void *data);
56 void WaitForConfigureEvent(int x, int y, int width, int height);
57 bool ready_to_go_;
58};
59
60#endif // NUXTESTFRAMEWORK_H
61
062
=== modified file 'standalone-clients/ui/TestQuicklist.cpp'
--- standalone-clients/ui/TestQuicklist.cpp 2012-01-09 16:49:50 +0000
+++ standalone-clients/ui/TestQuicklist.cpp 2012-02-01 16:25:13 +0000
@@ -14,11 +14,11 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *15 *
16 * Authored by: Mirco Müller <mirco.mueller@canonical.com>16 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
17 * Marco Trevisan (Treviño) <3v1n0@ubuntu.com>
17 */18 */
1819
19#include <glib.h>20#include <glib.h>
20#include <gtk/gtk.h>21#include <gtk/gtk.h>
21#include <dbus/dbus-glib.h>
2222
23#include "Nux/Nux.h"23#include "Nux/Nux.h"
24#include "Nux/VLayout.h"24#include "Nux/VLayout.h"
@@ -31,33 +31,141 @@
31#include "QuicklistMenuItemCheckmark.h"31#include "QuicklistMenuItemCheckmark.h"
32#include "QuicklistMenuItemRadio.h"32#include "QuicklistMenuItemRadio.h"
3333
34#include "EventFaker.h"34#include "nux_test_framework.h"
35#include <X11/Xlib.h>35#include "nux_automated_test_framework.h"
3636
37#define WIN_WIDTH 40037#define WIN_WIDTH 400
38#define WIN_HEIGHT 30038#define WIN_HEIGHT 400
3939
40gboolean gResult[3] = {false, false, false};40class TestQuicklist: public NuxTestFramework
4141{
42QuicklistView* gQuicklist = NULL;42public:
43QuicklistMenuItemCheckmark* gCheckmark = NULL;43 TestQuicklist(const char *program_name, int window_width, int window_height, int program_life_span);
44QuicklistMenuItemRadio* gRadio = NULL;44 ~TestQuicklist();
45QuicklistMenuItemLabel* gLabel = NULL;45
4646 virtual void UserInterfaceSetup();
47void47 int ItemNaturalPosition(QuicklistMenuItem* item);
48activatedCallback (DbusmenuMenuitem* item,48 bool HasNthItemActivated(unsigned int index);
49 int time,49
50 gpointer data)50 QuicklistView* quicklist_;
51{51 std::map<QuicklistMenuItem*,bool> activated_;
52 gboolean* result = (gboolean*) data;52
5353private:
54 *result = true;54 QuicklistMenuItemSeparator* createSeparatorItem();
5555 QuicklistMenuItemLabel* createLabelItem(std::string const& label, bool enabled = true);
56 g_print ("Quicklist-item activated\n");56 QuicklistMenuItemCheckmark* createCheckmarkItem(std::string const& label, bool enabled, bool checked);
57}57 QuicklistMenuItemRadio* createRadioItem(std::string const& label, bool enabled, bool checked);
5858 void AddItem(QuicklistMenuItem* item);
59QuicklistMenuItemCheckmark*59
60createCheckmarkItem ()60 void connectToActivatedSignal(DbusmenuMenuitem* item);
61 static void activatedCallback(DbusmenuMenuitem* item, int time, gpointer data);
62
63 std::map<DbusmenuMenuitem*, QuicklistMenuItem*> menus2qitem_;
64};
65
66TestQuicklist::TestQuicklist(const char *program_name, int window_width, int window_height, int program_life_span)
67 : NuxTestFramework(program_name, window_width, window_height, program_life_span),
68 quicklist_(nullptr)
69{}
70
71TestQuicklist::~TestQuicklist()
72{
73 if (quicklist_)
74 quicklist_->UnReference();
75}
76
77int TestQuicklist::ItemNaturalPosition(QuicklistMenuItem* item)
78{
79 int pos = 1;
80
81 for (auto it : quicklist_->GetChildren())
82 {
83 if (it == item)
84 return pos;
85
86 if (it->GetItemType() != MENUITEM_TYPE_SEPARATOR)
87 pos++;
88 }
89
90 return -1;
91}
92
93bool TestQuicklist::HasNthItemActivated(unsigned int index)
94{
95 return activated_[quicklist_->GetNthItems(index)];
96}
97
98void TestQuicklist::activatedCallback(DbusmenuMenuitem* item, int time, gpointer data)
99{
100 auto self = static_cast<TestQuicklist*>(data);
101 QuicklistMenuItem* qitem = self->menus2qitem_[item];
102
103 if (!self->activated_[qitem])
104 {
105 self->activated_[qitem] = true;
106 g_debug("Quicklist-item %d activated", self->ItemNaturalPosition(qitem));
107 }
108}
109
110void TestQuicklist::connectToActivatedSignal(DbusmenuMenuitem* item)
111{
112 g_signal_connect (item,
113 DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
114 G_CALLBACK (&TestQuicklist::activatedCallback),
115 this);
116}
117
118QuicklistMenuItemSeparator* TestQuicklist::createSeparatorItem()
119{
120 DbusmenuMenuitem* item = NULL;
121 QuicklistMenuItemSeparator* separator = NULL;
122
123 item = dbusmenu_menuitem_new ();
124
125 dbusmenu_menuitem_property_set_bool (item,
126 DBUSMENU_MENUITEM_PROP_ENABLED,
127 true);
128
129 separator = new QuicklistMenuItemSeparator (item, true);
130 menus2qitem_[item] = separator;
131
132 return separator;
133}
134
135QuicklistMenuItemRadio* TestQuicklist::createRadioItem(std::string const& label, bool enabled, bool checked)
136{
137 DbusmenuMenuitem* item = NULL;
138 QuicklistMenuItemRadio* radio = NULL;
139
140 item = dbusmenu_menuitem_new ();
141
142 dbusmenu_menuitem_property_set (item,
143 DBUSMENU_MENUITEM_PROP_LABEL,
144 label.c_str());
145
146 dbusmenu_menuitem_property_set (item,
147 DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
148 DBUSMENU_MENUITEM_TOGGLE_RADIO);
149
150 dbusmenu_menuitem_property_set_bool (item,
151 DBUSMENU_MENUITEM_PROP_ENABLED,
152 enabled);
153
154 dbusmenu_menuitem_property_set_int (item,
155 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
156 (checked ?
157 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
158 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
159 ));
160
161 connectToActivatedSignal(item);
162 radio = new QuicklistMenuItemRadio (item, true);
163 menus2qitem_[item] = radio;
164
165 return radio;
166}
167
168QuicklistMenuItemCheckmark* TestQuicklist::createCheckmarkItem(std::string const& label, bool enabled, bool checked)
61{169{
62 DbusmenuMenuitem* item = NULL;170 DbusmenuMenuitem* item = NULL;
63 QuicklistMenuItemCheckmark* checkmark = NULL;171 QuicklistMenuItemCheckmark* checkmark = NULL;
@@ -66,7 +174,7 @@
66174
67 dbusmenu_menuitem_property_set (item,175 dbusmenu_menuitem_property_set (item,
68 DBUSMENU_MENUITEM_PROP_LABEL,176 DBUSMENU_MENUITEM_PROP_LABEL,
69 "Unchecked");177 label.c_str());
70178
71 dbusmenu_menuitem_property_set (item,179 dbusmenu_menuitem_property_set (item,
72 DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,180 DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
@@ -74,58 +182,24 @@
74182
75 dbusmenu_menuitem_property_set_bool (item,183 dbusmenu_menuitem_property_set_bool (item,
76 DBUSMENU_MENUITEM_PROP_ENABLED,184 DBUSMENU_MENUITEM_PROP_ENABLED,
77 true);185 enabled);
78186
79 dbusmenu_menuitem_property_set_int (item,187 dbusmenu_menuitem_property_set_int (item,
80 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,188 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
81 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);189 (checked ?
190 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
191 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
192 ));
193
194 connectToActivatedSignal(item);
82195
83 checkmark = new QuicklistMenuItemCheckmark (item, true);196 checkmark = new QuicklistMenuItemCheckmark (item, true);
84197 menus2qitem_[item] = checkmark;
85 g_signal_connect (item,198
86 DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
87 G_CALLBACK (activatedCallback),
88 &gResult[0]);
89
90 return checkmark;199 return checkmark;
91}200}
92201
93QuicklistMenuItemRadio*202QuicklistMenuItemLabel* TestQuicklist::createLabelItem(std::string const& title, bool enabled)
94createRadioItem ()
95{
96 DbusmenuMenuitem* item = NULL;
97 QuicklistMenuItemRadio* radio = NULL;
98
99 item = dbusmenu_menuitem_new ();
100
101 dbusmenu_menuitem_property_set (item,
102 DBUSMENU_MENUITEM_PROP_LABEL,
103 "Radio Active");
104
105 dbusmenu_menuitem_property_set (item,
106 DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE,
107 DBUSMENU_MENUITEM_TOGGLE_RADIO);
108
109 dbusmenu_menuitem_property_set_bool (item,
110 DBUSMENU_MENUITEM_PROP_ENABLED,
111 false);
112
113 dbusmenu_menuitem_property_set_int (item,
114 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
115 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);
116
117 radio = new QuicklistMenuItemRadio (item, true);
118
119 g_signal_connect (item,
120 DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
121 G_CALLBACK (activatedCallback),
122 &gResult[1]);
123
124 return radio;
125}
126
127QuicklistMenuItemLabel*
128createLabelItem ()
129{203{
130 DbusmenuMenuitem* item = NULL;204 DbusmenuMenuitem* item = NULL;
131 QuicklistMenuItemLabel* label = NULL;205 QuicklistMenuItemLabel* label = NULL;
@@ -134,172 +208,144 @@
134208
135 dbusmenu_menuitem_property_set (item,209 dbusmenu_menuitem_property_set (item,
136 DBUSMENU_MENUITEM_PROP_LABEL,210 DBUSMENU_MENUITEM_PROP_LABEL,
137 "A Label");211 title.c_str());
138212
139 dbusmenu_menuitem_property_set_bool (item,213 dbusmenu_menuitem_property_set_bool (item,
140 DBUSMENU_MENUITEM_PROP_ENABLED,214 DBUSMENU_MENUITEM_PROP_ENABLED,
141 true);215 enabled);
216
217 connectToActivatedSignal(item);
142218
143 label = new QuicklistMenuItemLabel (item, true);219 label = new QuicklistMenuItemLabel (item, true);
144220 menus2qitem_[item] = label;
145 g_signal_connect (item,
146 DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
147 G_CALLBACK (activatedCallback),
148 &gResult[2]);
149221
150 return label;222 return label;
151}223}
152224
153void225void TestQuicklist::AddItem(QuicklistMenuItem* item)
154ThreadWidgetInit (nux::NThread* thread,226{
155 void* initData)227 if (!quicklist_)
156{228 return;
157 gQuicklist = new QuicklistView ();229
158 gQuicklist->Reference ();230 quicklist_->AddMenuItem(item);
159231}
160 gCheckmark = createCheckmarkItem ();232
161 gQuicklist->AddMenuItem (gCheckmark);233void TestQuicklist::UserInterfaceSetup()
162 gRadio = createRadioItem ();234{
163 gQuicklist->AddMenuItem (gRadio);235 QuicklistMenuItem *item;
164 gLabel = createLabelItem ();236
165 gQuicklist->AddMenuItem (gLabel);237 quicklist_ = new QuicklistView();
166238 quicklist_->EnableQuicklistForTesting(true);
167 gQuicklist->EnableQuicklistForTesting (true);239 quicklist_->SetBaseXY(0, 0);
168240
169 gQuicklist->SetBaseXY (0, 0);241 item = createLabelItem("Item1, normal");
170 gQuicklist->ShowWindow (true);242 AddItem(item);
171}243
172244 item = createSeparatorItem();
173void245 AddItem(item);
174ControlThread (nux::NThread* thread,246
175 void* data)247 item = createRadioItem("Item2, radio, checked", true, true);
176{248 AddItem(item);
177 // sleep for 3 seconds249
178 nux::SleepForMilliseconds (3000);250 item = createRadioItem("Item3, radio, unchecked", true, false);
179 printf ("ControlThread successfully started\n");251 AddItem(item);
180252
181 nux::WindowThread* mainWindowThread = NUX_STATIC_CAST (nux::WindowThread*, 253 item = createRadioItem("Item4, disabled radio, checked", false, true);
182 data);254 AddItem(item);
183255
184 mainWindowThread->SetFakeEventMode (true);256 item = createRadioItem("Item5, disabled radio, unchecked", false, false);
185 Display* display = mainWindowThread->GetWindow ().GetX11Display ();257 AddItem(item);
186258
187 // assemble first button-click event259 item = createCheckmarkItem("Item6, checkmark, checked", true, true);
188 XEvent buttonPressEvent;260 AddItem(item);
189 buttonPressEvent.xbutton.type = ButtonPress;261
190 buttonPressEvent.xbutton.serial = 0;262 item = createCheckmarkItem("Item7, checkmark, unchecked", true, false);
191 buttonPressEvent.xbutton.send_event = False;263 AddItem(item);
192 buttonPressEvent.xbutton.display = display;264
193 buttonPressEvent.xbutton.window = 0;265 item = createCheckmarkItem("Item8, disabled checkmark, checked", false, true);
194 buttonPressEvent.xbutton.root = 0;266 AddItem(item);
195 buttonPressEvent.xbutton.subwindow = 0;267
196 buttonPressEvent.xbutton.time = CurrentTime;268 item = createCheckmarkItem("Item9, disabled checkmark, unchecked", false, false);
197 buttonPressEvent.xbutton.x = 50;269 AddItem(item);
198 buttonPressEvent.xbutton.y = 30;270
199 buttonPressEvent.xbutton.x_root = 0;271 item = createLabelItem("Item10, disabled", false);
200 buttonPressEvent.xbutton.y_root = 0;272 AddItem(item);
201 buttonPressEvent.xbutton.state = 0;273
202 buttonPressEvent.xbutton.button = Button1;274 quicklist_->ShowWindow(true);
203 buttonPressEvent.xbutton.same_screen = True;275
204276 auto wt = static_cast<nux::WindowThread*>(window_thread_);
205 mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,277 nux::ColorLayer background (nux::Color (0x772953));
206 (XEvent*) &buttonPressEvent);278 wt->SetWindowBackgroundPaintLayer(&background);
207279}
208 while (!mainWindowThread->ReadyForNextFakeEvent ())280
209 nux::SleepForMilliseconds (10);281TestQuicklist *test_quicklist = NULL;
210282
211 XEvent buttonReleaseEvent;283void TestingThread(nux::NThread *thread, void *user_data)
212 buttonReleaseEvent.xbutton.type = ButtonRelease;284{
213 buttonReleaseEvent.xbutton.serial = 0;285 while (test_quicklist->ReadyToGo() == false)
214 buttonReleaseEvent.xbutton.send_event = False;286 {
215 buttonReleaseEvent.xbutton.display = display;287 nuxDebugMsg("Waiting to start");
216 buttonReleaseEvent.xbutton.window = 0;288 nux::SleepForMilliseconds(300);
217 buttonReleaseEvent.xbutton.root = 0;289 }
218 buttonReleaseEvent.xbutton.subwindow = 0;290
219 buttonReleaseEvent.xbutton.time = CurrentTime;291 nux::SleepForMilliseconds(1300);
220 buttonReleaseEvent.xbutton.x = 50;292
221 buttonReleaseEvent.xbutton.y = 30;293 auto *wnd_thread = static_cast<nux::WindowThread*>(user_data);
222 buttonReleaseEvent.xbutton.x_root = 0;294
223 buttonReleaseEvent.xbutton.y_root = 0;295 NuxAutomatedTestFramework test(wnd_thread);
224 buttonReleaseEvent.xbutton.state = 0;296
225 buttonReleaseEvent.xbutton.button = Button1;297 test.Startup();
226 buttonReleaseEvent.xbutton.same_screen = True;298
227299 for (auto child : test_quicklist->quicklist_->GetChildren())
228 mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,300 {
229 (XEvent*) &buttonReleaseEvent);301 test.ViewSendMouseMotionToCenter(child);
230302 test.ViewSendMouseClick(child, 1);
231 while (!mainWindowThread->ReadyForNextFakeEvent ())303 bool activated = test_quicklist->activated_[child];
232 nux::SleepForMilliseconds (10);304 bool should_be_activated = (child->GetItemType() != MENUITEM_TYPE_SEPARATOR && child->GetEnabled());
233305
234 // assemble second button-click event306 std::string msg = std::string(child->GetLabel());
235 buttonPressEvent.xbutton.time = CurrentTime;307 msg += should_be_activated ? " | Activated" : " | NOT Activated";
236 buttonPressEvent.xbutton.x = 50;308
237 buttonPressEvent.xbutton.y = 50;309 test.TestReportMsg(activated == should_be_activated, msg.c_str());
238 mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,310 nux::SleepForMilliseconds(200);
239 (XEvent*) &buttonPressEvent);311 }
240 while (!mainWindowThread->ReadyForNextFakeEvent ())312
241 nux::SleepForMilliseconds (10);313 if (test.WhenDoneTerminateProgram())
242314 {
243 buttonReleaseEvent.xbutton.time = CurrentTime;315 wnd_thread->ExitMainLoop();
244 buttonReleaseEvent.xbutton.x = 50;316 }
245 buttonReleaseEvent.xbutton.y = 50;317 nuxDebugMsg("Exit testing thread");
246 mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
247 (XEvent*) &buttonReleaseEvent);
248 while (!mainWindowThread->ReadyForNextFakeEvent ())
249 nux::SleepForMilliseconds (10);
250
251 // assemble third button-click event
252 buttonPressEvent.xbutton.time = CurrentTime;
253 buttonPressEvent.xbutton.x = 50;
254 buttonPressEvent.xbutton.y = 70;
255 mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
256 (XEvent*) &buttonPressEvent);
257 while (!mainWindowThread->ReadyForNextFakeEvent ())
258 nux::SleepForMilliseconds (10);
259
260 buttonReleaseEvent.xbutton.time = CurrentTime;
261 buttonReleaseEvent.xbutton.x = 50;
262 buttonReleaseEvent.xbutton.y = 70;
263 mainWindowThread->PumpFakeEventIntoPipe (mainWindowThread,
264 (XEvent*) &buttonReleaseEvent);
265 while (!mainWindowThread->ReadyForNextFakeEvent ())
266 nux::SleepForMilliseconds (10);
267
268 mainWindowThread->SetFakeEventMode (false);
269}318}
270319
271int320int
272main (int argc, char **argv)321main (int argc, char **argv)
273{322{
274 nux::WindowThread* wt = NULL;323 gtk_init(&argc, &argv);
275 nux::SystemThread* st = NULL;324 nuxAssertMsg(XInitThreads() > 0, "XInitThreads has failed");
276325
277 g_type_init ();326 test_quicklist = new TestQuicklist("Quicklist Test", WIN_WIDTH, WIN_HEIGHT, 100000);
278 327 test_quicklist->Startup();
279 gtk_init (&argc, &argv);328 test_quicklist->UserInterfaceSetup();
280 dbus_g_thread_init ();329
281 nux::NuxInitialize (0);330 auto *test_thread = nux::CreateSystemThread(NULL, &TestingThread, test_quicklist->GetWindowThread());
282331 test_thread->Start(test_quicklist);
283 wt = nux::CreateGUIThread (TEXT ("Unity Quicklist"),332
284 WIN_WIDTH,333 test_quicklist->Run();
285 WIN_HEIGHT,334
286 0,335 g_assert_cmpint (test_quicklist->HasNthItemActivated(0), ==, true);
287 &ThreadWidgetInit,336 g_assert_cmpint (test_quicklist->HasNthItemActivated(1), ==, false);
288 NULL);337 g_assert_cmpint (test_quicklist->HasNthItemActivated(2), ==, true);
289338 g_assert_cmpint (test_quicklist->HasNthItemActivated(3), ==, true);
290 st = nux::CreateSystemThread (NULL, ControlThread, wt);339 g_assert_cmpint (test_quicklist->HasNthItemActivated(4), ==, false);
291 if (st)340 g_assert_cmpint (test_quicklist->HasNthItemActivated(5), ==, false);
292 st->Start (NULL);341 g_assert_cmpint (test_quicklist->HasNthItemActivated(6), ==, true);
293342 g_assert_cmpint (test_quicklist->HasNthItemActivated(7), ==, true);
294 wt->Run (NULL);343 g_assert_cmpint (test_quicklist->HasNthItemActivated(8), ==, false);
295344 g_assert_cmpint (test_quicklist->HasNthItemActivated(9), ==, false);
296 gQuicklist->UnReference ();345 g_assert_cmpint (test_quicklist->HasNthItemActivated(10), ==, false);
297 delete st;346
298 delete wt;347 delete test_thread;
299348 delete test_quicklist;
300 g_assert_cmpint (gResult[0], ==, true);
301 g_assert_cmpint (gResult[1], ==, true);
302 g_assert_cmpint (gResult[2], ==, true);
303349
304 return 0;350 return 0;
305}351}
306352
=== modified file 'standalone-clients/ui/TestQuicklistVisuals.cpp'
--- standalone-clients/ui/TestQuicklistVisuals.cpp 2012-01-09 16:49:50 +0000
+++ standalone-clients/ui/TestQuicklistVisuals.cpp 2012-02-01 16:25:13 +0000
@@ -18,7 +18,6 @@
1818
19#include <glib.h>19#include <glib.h>
20#include <gtk/gtk.h>20#include <gtk/gtk.h>
21#include <dbus/dbus-glib.h>
2221
23#include "Nux/Nux.h"22#include "Nux/Nux.h"
24#include "Nux/VLayout.h"23#include "Nux/VLayout.h"
@@ -60,14 +59,12 @@
60 DBUSMENU_MENUITEM_PROP_ENABLED,59 DBUSMENU_MENUITEM_PROP_ENABLED,
61 enabled);60 enabled);
6261
63 if (checked)62 dbusmenu_menuitem_property_set_int (item,
64 dbusmenu_menuitem_property_set_int (item,63 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
65 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,64 (checked ?
66 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);65 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
67 else66 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
68 dbusmenu_menuitem_property_set_int (item,67 ));
69 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
70 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
7168
72 radio = new QuicklistMenuItemRadio (item, true);69 radio = new QuicklistMenuItemRadio (item, true);
73 70
@@ -96,14 +93,12 @@
96 DBUSMENU_MENUITEM_PROP_ENABLED,93 DBUSMENU_MENUITEM_PROP_ENABLED,
97 enabled);94 enabled);
9895
99 if (checked)96 dbusmenu_menuitem_property_set_int (item,
100 dbusmenu_menuitem_property_set_int (item,97 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
101 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,98 (checked ?
102 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED);99 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED :
103 else100 DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED
104 dbusmenu_menuitem_property_set_int (item,101 ));
105 DBUSMENU_MENUITEM_PROP_TOGGLE_STATE,
106 DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
107102
108 checkmark = new QuicklistMenuItemCheckmark (item, true);103 checkmark = new QuicklistMenuItemCheckmark (item, true);
109 104
@@ -111,7 +106,7 @@
111}106}
112107
113QuicklistMenuItemLabel*108QuicklistMenuItemLabel*
114createLabelItem (const gchar* string)109createLabelItem (const gchar* string, bool enabled = true)
115{110{
116 DbusmenuMenuitem* item = NULL;111 DbusmenuMenuitem* item = NULL;
117 QuicklistMenuItemLabel* label = NULL;112 QuicklistMenuItemLabel* label = NULL;
@@ -124,7 +119,7 @@
124119
125 dbusmenu_menuitem_property_set_bool (item,120 dbusmenu_menuitem_property_set_bool (item,
126 DBUSMENU_MENUITEM_PROP_ENABLED,121 DBUSMENU_MENUITEM_PROP_ENABLED,
127 true);122 enabled);
128123
129 label = new QuicklistMenuItemLabel (item, true);124 label = new QuicklistMenuItemLabel (item, true);
130125
@@ -170,7 +165,8 @@
170 gQuicklists[0]->AddMenuItem (radio);165 gQuicklists[0]->AddMenuItem (radio);
171 separator = createSeparatorItem ();166 separator = createSeparatorItem ();
172 gQuicklists[0]->AddMenuItem (separator);167 gQuicklists[0]->AddMenuItem (separator);
173 label = createLabelItem ("Application Name");168 label = createLabelItem ("<b>Application Name</b>");
169 label->EnableLabelMarkup(true);
174 gQuicklists[0]->AddMenuItem (label);170 gQuicklists[0]->AddMenuItem (label);
175 separator = createSeparatorItem ();171 separator = createSeparatorItem ();
176 gQuicklists[0]->AddMenuItem (separator);172 gQuicklists[0]->AddMenuItem (separator);
@@ -193,7 +189,8 @@
193 gQuicklists[1]->AddMenuItem (checkmark);189 gQuicklists[1]->AddMenuItem (checkmark);
194 separator = createSeparatorItem ();190 separator = createSeparatorItem ();
195 gQuicklists[1]->AddMenuItem (separator);191 gQuicklists[1]->AddMenuItem (separator);
196 label = createLabelItem ("Application Name");192 label = createLabelItem ("<b>Application Name</b>");
193 label->EnableLabelMarkup(true);
197 gQuicklists[1]->AddMenuItem (label);194 gQuicklists[1]->AddMenuItem (label);
198 separator = createSeparatorItem ();195 separator = createSeparatorItem ();
199 gQuicklists[1]->AddMenuItem (separator);196 gQuicklists[1]->AddMenuItem (separator);
@@ -214,11 +211,12 @@
214 gQuicklists[2]->AddMenuItem (separator);211 gQuicklists[2]->AddMenuItem (separator);
215 checkmark = createCheckmarkItem ("Option 03", false, true);212 checkmark = createCheckmarkItem ("Option 03", false, true);
216 gQuicklists[2]->AddMenuItem (checkmark);213 gQuicklists[2]->AddMenuItem (checkmark);
217 checkmark = createCheckmarkItem ("Option 04", false, true);214 label = createLabelItem ("Option 04", false);
218 gQuicklists[2]->AddMenuItem (checkmark);215 gQuicklists[2]->AddMenuItem (label);
219 separator = createSeparatorItem ();216 separator = createSeparatorItem ();
220 gQuicklists[2]->AddMenuItem (separator);217 gQuicklists[2]->AddMenuItem (separator);
221 label = createLabelItem ("Application Name");218 label = createLabelItem ("<b>Application Name</b>");
219 label->EnableLabelMarkup(true);
222 gQuicklists[2]->AddMenuItem (label);220 gQuicklists[2]->AddMenuItem (label);
223 separator = createSeparatorItem ();221 separator = createSeparatorItem ();
224 gQuicklists[2]->AddMenuItem (separator);222 gQuicklists[2]->AddMenuItem (separator);
@@ -227,6 +225,9 @@
227 gQuicklists[2]->EnableQuicklistForTesting (true);225 gQuicklists[2]->EnableQuicklistForTesting (true);
228 gQuicklists[2]->SetBaseXY (45, 290);226 gQuicklists[2]->SetBaseXY (45, 290);
229 gQuicklists[2]->ShowWindow (true);227 gQuicklists[2]->ShowWindow (true);
228
229 nux::ColorLayer background (nux::Color (0x772953));
230 static_cast<nux::WindowThread*>(thread)->SetWindowBackgroundPaintLayer(&background);
230}231}
231232
232int233int
@@ -234,10 +235,7 @@
234{235{
235 nux::WindowThread* wt = NULL;236 nux::WindowThread* wt = NULL;
236237
237 g_type_init ();
238
239 gtk_init (&argc, &argv);238 gtk_init (&argc, &argv);
240 dbus_g_thread_init ();
241 nux::NuxInitialize (0);239 nux::NuxInitialize (0);
242240
243 wt = nux::CreateGUIThread (TEXT ("Unity visual Quicklist-test"),241 wt = nux::CreateGUIThread (TEXT ("Unity visual Quicklist-test"),
244242
=== modified file 'tests/unit/TestQuicklistMenuitems.cpp'
--- tests/unit/TestQuicklistMenuitems.cpp 2011-12-06 23:28:49 +0000
+++ tests/unit/TestQuicklistMenuitems.cpp 2012-02-01 16:25:13 +0000
@@ -241,6 +241,7 @@
241 g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1");241 g_assert_cmpstr(quicklist->GetNthItems(2)->GetLabel(), == , "label 1");
242 g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0");242 g_assert_cmpstr(quicklist->GetNthItems(3)->GetLabel(), == , "check mark 0");
243243
244 g_assert_cmpint(quicklist->GetChildren().size(), == , 4);
244245
245 quicklist->Dispose();246 quicklist->Dispose();
246}247}