Mir

Merge lp:~alan-griffiths/mir/nested-mir-can-hide-cursor into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 3003
Proposed branch: lp:~alan-griffiths/mir/nested-mir-can-hide-cursor
Merge into: lp:mir
Prerequisite: lp:~alan-griffiths/mir/tweak-cursor-configuration
Diff against target: 242 lines (+130/-68)
1 file modified
tests/acceptance-tests/test_nested_mir.cpp (+130/-68)
To merge this branch: bzr merge lp:~alan-griffiths/mir/nested-mir-can-hide-cursor
Reviewer Review Type Date Requested Status
Kevin DuBois (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+273537@code.launchpad.net

Commit message

tests: Test to prove the nested server can hide the cursor

Description of the change

tests: Test to prove the nested server can hide the cursor

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Failure is lp:1502896

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

nits, the rest lgtm:

+struct CursorImage : public mg::CursorImage
+public:
+struct CursorWrapper : public mg::Cursor
redundant 'public's

+ geom::Size size() const { return { 24, 24 }; }
+ connection, 24, 24, mir_pixel_format_argb_8888, mir_buffer_usage_software);
+ std::array<uint8_t, 4*8*24*24> data;

could have less repeating of '24' if we had a "int cursor_side_length{24}" somewhere.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm, thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/acceptance-tests/test_nested_mir.cpp'
2--- tests/acceptance-tests/test_nested_mir.cpp 2015-10-05 17:08:39 +0000
3+++ tests/acceptance-tests/test_nested_mir.cpp 2015-10-07 08:33:53 +0000
4@@ -113,6 +113,76 @@
5
6 std::chrono::seconds const timeout{10};
7
8+// We can't rely on the test environment to have X cursors, so we provide some of our own
9+auto const cursor_names = {
10+// mir_disabled_cursor_name,
11+ mir_arrow_cursor_name,
12+ mir_busy_cursor_name,
13+ mir_caret_cursor_name,
14+ mir_default_cursor_name,
15+ mir_pointing_hand_cursor_name,
16+ mir_open_hand_cursor_name,
17+ mir_closed_hand_cursor_name,
18+ mir_horizontal_resize_cursor_name,
19+ mir_vertical_resize_cursor_name,
20+ mir_diagonal_resize_bottom_to_top_cursor_name,
21+ mir_diagonal_resize_top_to_bottom_cursor_name,
22+ mir_omnidirectional_resize_cursor_name,
23+ mir_vsplit_resize_cursor_name,
24+ mir_hsplit_resize_cursor_name,
25+ mir_crosshair_cursor_name };
26+
27+int const cursor_size = 24;
28+
29+struct CursorImage : mg::CursorImage
30+{
31+ CursorImage(char const* name) :
32+ id{std::find(begin(cursor_names), end(cursor_names), name) - begin(cursor_names)},
33+ data{{uint8_t(id)}}
34+ {
35+ }
36+
37+ void const* as_argb_8888() const { return data.data(); }
38+
39+ geom::Size size() const { return {cursor_size, cursor_size}; }
40+
41+ geom::Displacement hotspot() const { return {0, 0}; }
42+
43+ ptrdiff_t id;
44+ std::array<uint8_t, MIR_BYTES_PER_PIXEL(mir_pixel_format_argb_8888) * cursor_size * cursor_size> data;
45+};
46+
47+struct CursorImages : mir::input::CursorImages
48+{
49+public:
50+
51+ std::shared_ptr<mg::CursorImage> image(std::string const& cursor_name, geom::Size const& /*size*/)
52+ {
53+ return std::make_shared<CursorImage>(cursor_name.c_str());
54+ }
55+};
56+
57+struct CursorWrapper : mg::Cursor
58+{
59+ CursorWrapper(std::shared_ptr<mg::Cursor> const& wrapped) : wrapped{wrapped} {}
60+ void show() override { if (!hidden) wrapped->show(); }
61+ void show(mg::CursorImage const& cursor_image) override { if (!hidden) wrapped->show(cursor_image); }
62+ void hide() override { wrapped->hide(); }
63+
64+ void move_to(geom::Point position) override { wrapped->move_to(position); }
65+
66+ void set_hidden(bool hidden)
67+ {
68+ this->hidden = hidden;
69+ if (hidden) hide();
70+ else show();
71+ }
72+
73+private:
74+ std::shared_ptr<mg::Cursor> const wrapped;
75+ bool hidden{false};
76+};
77+
78 class NestedMirRunner : public mtf::HeadlessNestedServerRunner
79 {
80 public:
81@@ -122,6 +192,11 @@
82 server.override_the_host_lifecycle_event_listener([this]
83 { return the_mock_host_lifecycle_event_listener(); });
84
85+ server.wrap_cursor([&](std::shared_ptr<mg::Cursor> const& wrapped)
86+ { return cursor_wrapper = std::make_shared<CursorWrapper>(wrapped); });
87+
88+ server.override_the_cursor_images([] { return std::make_shared<CursorImages>(); });
89+
90 start_server();
91 }
92
93@@ -136,6 +211,8 @@
94 { return std::make_shared<NiceMock<MockHostLifecycleEventListener>>(); });
95 }
96
97+ std::shared_ptr<CursorWrapper> cursor_wrapper;
98+
99 private:
100 mir::CachedPtr<MockHostLifecycleEventListener> mock_host_lifecycle_event_listener;
101 };
102@@ -498,7 +575,7 @@
103 server.the_cursor_listener()->cursor_moved_to(489, 9);
104
105 auto stream = mir_connection_create_buffer_stream_sync(
106- connection, 24, 24, mir_pixel_format_argb_8888, mir_buffer_usage_software);
107+ connection, cursor_size, cursor_size, mir_pixel_format_argb_8888, mir_buffer_usage_software);
108 mir_buffer_stream_swap_buffers_sync(stream);
109
110 {
111@@ -531,75 +608,9 @@
112 mir_connection_release(connection);
113 }
114
115-// We can't rely on the test environment to have X cursors, so we provide some of our own
116-namespace
117-{
118-static auto const cursor_names = {
119-// mir_disabled_cursor_name,
120- mir_arrow_cursor_name,
121- mir_busy_cursor_name,
122- mir_caret_cursor_name,
123- mir_default_cursor_name,
124- mir_pointing_hand_cursor_name,
125- mir_open_hand_cursor_name,
126- mir_closed_hand_cursor_name,
127- mir_horizontal_resize_cursor_name,
128- mir_vertical_resize_cursor_name,
129- mir_diagonal_resize_bottom_to_top_cursor_name,
130- mir_diagonal_resize_top_to_bottom_cursor_name,
131- mir_omnidirectional_resize_cursor_name,
132- mir_vsplit_resize_cursor_name,
133- mir_hsplit_resize_cursor_name,
134- mir_crosshair_cursor_name };
135-
136-struct CursorImage : public mg::CursorImage
137-{
138- CursorImage(char const* name) :
139- id{std::find(begin(cursor_names), end(cursor_names), name) - begin(cursor_names)},
140- data{{uint8_t(id)}}
141- {
142- }
143-
144- void const* as_argb_8888() const { return data.data(); }
145-
146- geom::Size size() const { return { 24, 24 }; }
147-
148- geom::Displacement hotspot() const { return {0, 0}; }
149-
150- ptrdiff_t id;
151- std::array<uint8_t, 4*8*24*24> data;
152-};
153-
154-struct CursorImages : mir::input::CursorImages
155-{
156-public:
157-
158- std::shared_ptr<mg::CursorImage> image(std::string const& cursor_name, geom::Size const& /*size*/)
159- {
160- return std::make_shared<CursorImage>(cursor_name.c_str());
161- }
162-};
163-
164-class NestedMirRunnerWithCursorImages : public mtf::HeadlessNestedServerRunner
165-{
166-public:
167- NestedMirRunnerWithCursorImages(std::string const& connection_string)
168- : mtf::HeadlessNestedServerRunner(connection_string)
169- {
170- server.override_the_cursor_images([] { return std::make_shared<CursorImages>(); });
171- start_server();
172- }
173-
174- ~NestedMirRunnerWithCursorImages()
175- {
176- stop_server();
177- }
178-};
179-}
180-
181 TEST_F(NestedServer, named_cursor_image_changes_are_forwarded_to_host)
182 {
183- NestedMirRunnerWithCursorImages nested_mir{new_connection()};
184+ NestedMirRunner nested_mir{new_connection()};
185
186 auto const connection = mir_connect_sync(nested_mir.new_connection().c_str(), __PRETTY_FUNCTION__);
187 auto const surface = make_and_paint_surface(connection);
188@@ -630,3 +641,54 @@
189 mir_surface_release_sync(surface);
190 mir_connection_release(connection);
191 }
192+
193+TEST_F(NestedServer, can_hide_the_host_cursor)
194+{
195+ int const frames = 10;
196+ NestedMirRunner nested_mir{new_connection()};
197+
198+ auto const connection = mir_connect_sync(nested_mir.new_connection().c_str(), __PRETTY_FUNCTION__);
199+ auto const surface = make_and_paint_surface(connection);
200+ auto const mock_cursor = the_mock_cursor();
201+
202+ auto const spec = mir_connection_create_spec_for_changes(connection);
203+ mir_surface_spec_set_fullscreen_on_output(spec, 1);
204+ mir_surface_apply_spec(surface, spec);
205+ mir_surface_spec_release(spec);
206+
207+ server.the_cursor_listener()->cursor_moved_to(489, 9);
208+
209+ auto stream = mir_connection_create_buffer_stream_sync(
210+ connection, cursor_size, cursor_size, mir_pixel_format_argb_8888, mir_buffer_usage_software);
211+ mir_buffer_stream_swap_buffers_sync(stream);
212+
213+ {
214+ mt::WaitCondition condition;
215+ EXPECT_CALL(*mock_cursor, show(_)).Times(1)
216+ .WillRepeatedly(InvokeWithoutArgs([&] { condition.wake_up_everyone(); }));
217+
218+ auto conf = mir_cursor_configuration_from_buffer_stream(stream, 0, 0);
219+ mir_wait_for(mir_surface_configure_cursor(surface, conf));
220+ mir_cursor_configuration_destroy(conf);
221+
222+ condition.wait_for_at_most_seconds(1);
223+ Mock::VerifyAndClearExpectations(mock_cursor.get());
224+ }
225+
226+ nested_mir.cursor_wrapper->set_hidden(true);
227+
228+ EXPECT_CALL(*mock_cursor, show(_)).Times(0);
229+
230+ for (int i = 0; i != frames; ++i)
231+ {
232+ mir_buffer_stream_swap_buffers_sync(stream);
233+ }
234+
235+ mir_buffer_stream_release_sync(stream);
236+ mir_surface_release_sync(surface);
237+ mir_connection_release(connection);
238+
239+ // Need to verify before test server teardown deletes the
240+ // surface as the host cursor then reverts to default.
241+ Mock::VerifyAndClearExpectations(mock_cursor.get());
242+}

Subscribers

People subscribed via source and target branches