Mir

Merge lp:~alan-griffiths/mir/fix-1335741 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 1735
Proposed branch: lp:~alan-griffiths/mir/fix-1335741
Merge into: lp:mir
Diff against target: 71 lines (+17/-4)
1 file modified
tests/acceptance-tests/test_client_surface_events.cpp (+17/-4)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1335741
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alberto Aguirre (community) Approve
Alexandros Frantzis (community) Approve
Review via email: mp+224982@code.launchpad.net

Commit message

tests: add an event filter to ClientSurfaceEvents so that interesting events are not overwritten

Description of the change

tests: add an event filter to ClientSurfaceEvents so that interesting events are not overwritten

To post a comment you must log in.
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

Yep

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'tests/acceptance-tests/test_client_surface_events.cpp'
--- tests/acceptance-tests/test_client_surface_events.cpp 2014-06-19 16:15:42 +0000
+++ tests/acceptance-tests/test_client_surface_events.cpp 2014-06-30 11:17:53 +0000
@@ -100,6 +100,7 @@
100 MirSurface* other_surface;100 MirSurface* other_surface;
101101
102 std::mutex last_event_mutex;102 std::mutex last_event_mutex;
103 MirEventType event_filter{mir_event_type_surface};
103 std::condition_variable last_event_cv;104 std::condition_variable last_event_cv;
104 MirEvent last_event{};105 MirEvent last_event{};
105 MirSurface* last_event_surface = nullptr;106 MirSurface* last_event_surface = nullptr;
@@ -111,16 +112,24 @@
111 {112 {
112 ClientSurfaceEvents* self = static_cast<ClientSurfaceEvents*>(ctx);113 ClientSurfaceEvents* self = static_cast<ClientSurfaceEvents*>(ctx);
113 std::lock_guard<decltype(self->last_event_mutex)> last_event_lock{self->last_event_mutex};114 std::lock_guard<decltype(self->last_event_mutex)> last_event_lock{self->last_event_mutex};
115 // Don't overwrite an interesting event with an uninteresting one!
116 if (event->type != self->event_filter) return;
114 self->last_event = *event;117 self->last_event = *event;
115 self->last_event_surface = surface;118 self->last_event_surface = surface;
116 self->last_event_cv.notify_one();119 self->last_event_cv.notify_one();
117 }120 }
118121
119 bool wait_for_event(MirEventType type, std::chrono::milliseconds delay)122 bool wait_for_event(std::chrono::milliseconds delay)
120 {123 {
121 std::unique_lock<decltype(last_event_mutex)> last_event_lock{last_event_mutex};124 std::unique_lock<decltype(last_event_mutex)> last_event_lock{last_event_mutex};
122 return last_event_cv.wait_for(last_event_lock, delay,125 return last_event_cv.wait_for(last_event_lock, delay,
123 [&] { return !!last_event_surface && last_event.type == type; });126 [&] { return last_event_surface == surface && last_event.type == event_filter; });
127 }
128
129 void set_event_filter(MirEventType type)
130 {
131 std::lock_guard<decltype(last_event_mutex)> last_event_lock{last_event_mutex};
132 event_filter = type;
124 }133 }
125134
126 void reset_last_event()135 void reset_last_event()
@@ -218,11 +227,13 @@
218227
219TEST_P(OrientationEvents, surface_receives_orientation_events)228TEST_P(OrientationEvents, surface_receives_orientation_events)
220{229{
230 set_event_filter(mir_event_type_orientation);
231
221 auto const direction = GetParam();232 auto const direction = GetParam();
222233
223 scene_surface->set_orientation(direction);234 scene_surface->set_orientation(direction);
224235
225 EXPECT_TRUE(wait_for_event(mir_event_type_orientation, std::chrono::seconds(1)));236 EXPECT_TRUE(wait_for_event(std::chrono::seconds(1)));
226237
227 std::lock_guard<decltype(last_event_mutex)> last_event_lock{last_event_mutex};238 std::lock_guard<decltype(last_event_mutex)> last_event_lock{last_event_mutex};
228239
@@ -237,6 +248,8 @@
237248
238TEST_F(ClientSurfaceEvents, client_can_query_current_orientation)249TEST_F(ClientSurfaceEvents, client_can_query_current_orientation)
239{250{
251 set_event_filter(mir_event_type_orientation);
252
240 for (auto const direction:253 for (auto const direction:
241 {mir_orientation_normal, mir_orientation_left, mir_orientation_inverted,254 {mir_orientation_normal, mir_orientation_left, mir_orientation_inverted,
242 mir_orientation_right, mir_orientation_normal, mir_orientation_inverted,255 mir_orientation_right, mir_orientation_normal, mir_orientation_inverted,
@@ -246,7 +259,7 @@
246259
247 scene_surface->set_orientation(direction);260 scene_surface->set_orientation(direction);
248261
249 EXPECT_TRUE(wait_for_event(mir_event_type_orientation, std::chrono::seconds(1)));262 EXPECT_TRUE(wait_for_event(std::chrono::seconds(1)));
250263
251 EXPECT_THAT(mir_surface_get_orientation(surface), Eq(direction));264 EXPECT_THAT(mir_surface_get_orientation(surface), Eq(direction));
252 }265 }

Subscribers

People subscribed via source and target branches