Mir

Merge lp:~afrantzis/mir/fix-1321215 into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 1646
Proposed branch: lp:~afrantzis/mir/fix-1321215
Merge into: lp:mir
Diff against target: 149 lines (+47/-32)
1 file modified
tests/acceptance-tests/test_custom_input_dispatcher.cpp (+47/-32)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1321215
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
PS Jenkins bot (community) continuous-integration Approve
Andreas Pokorny (community) Approve
Review via email: mp+220228@code.launchpad.net

Commit message

tests: Improve robustness of CustomInputDispatcher tests

Ensure that expectations for our custom input dispatcher are set once when it is first created, in order to avoid racing with the server starting up and using the dispatcher before we have set our expectations.

Description of the change

tests: Improve robustness of CustomInputDispatcher tests

Ensure that expectations for our custom input dispatcher are set once when it is first created, in order to avoid racing with the server starting up and using the dispatcher before we have set our expectations.

To post a comment you must log in.
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

thank you for figuring this out.
looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

The relationship between

21 std::shared_ptr<mi::InputDispatcher> the_input_dispatcher() override

and

41 + std::shared_ptr<::testing::NiceMock<CustomMockInputDispatcher>> the_input_dispatcher_mock()

is strange - I'd expect the former to be using the CachePtr not the latter. But that's pre-existing.

OTOH Doing it right would also mean that

57 + bool expectations_set{false};

isn't needed (as the lambda passed to the CachePtr is only executed when the object is created). Vis:

std::shared_ptr<mi::InputDispatcher> the_input_dispatcher() override
{
    return dispatcher(
    [this]
    {
        auto const dispatcher = the_input_dispatcher_mock();

        InSequence seq;
        EXPECT_CALL(*dispatcher, dispatch(mt::MotionEventWithPosition(1, 1))).Times(1);
        EXPECT_CALL(*dispatcher, dispatch(mt::KeyDownEvent()))
            .WillOnce(InvokeWithoutArgs([this]{ dispatching_done.signal_ready(); }));

        return dispatcher;
     });
}

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_custom_input_dispatcher.cpp'
2--- tests/acceptance-tests/test_custom_input_dispatcher.cpp 2014-05-20 08:38:05 +0000
3+++ tests/acceptance-tests/test_custom_input_dispatcher.cpp 2014-05-20 11:34:30 +0000
4@@ -52,12 +52,12 @@
5 namespace
6 {
7
8-class CustomInputDispatcher :
9+class CustomMockInputDispatcher :
10 public mtd::MockInputDispatcher,
11 public msh::InputTargeter
12 {
13 public:
14- CustomInputDispatcher() = default;
15+ CustomMockInputDispatcher() = default;
16 // mocks for InputTargeter
17 MOCK_METHOD1(focus_changed, void(std::shared_ptr<mi::InputChannel const> const& /*focus_channel*/));
18 MOCK_METHOD0(focus_cleared, void());
19@@ -67,49 +67,65 @@
20 {
21 std::shared_ptr<mi::InputDispatcher> the_input_dispatcher() override
22 {
23- return the_input_dispatcher_mock();
24+ auto const dispatcher = the_input_dispatcher_mock();
25+
26+ if (!expectations_set)
27+ {
28+ input_dispatcher_expectations();
29+ expectations_set = true;
30+ }
31+
32+ return dispatcher;
33 }
34+
35 std::shared_ptr<msh::InputTargeter> the_input_targeter() override
36 {
37 return the_input_dispatcher_mock();
38 }
39- std::shared_ptr<::testing::NiceMock<CustomInputDispatcher>> the_input_dispatcher_mock()
40+
41+ std::shared_ptr<::testing::NiceMock<CustomMockInputDispatcher>> the_input_dispatcher_mock()
42 {
43 return dispatcher(
44 [this]
45 {
46- return std::make_shared<::testing::NiceMock<CustomInputDispatcher>>();
47+ return std::make_shared<::testing::NiceMock<CustomMockInputDispatcher>>();
48 });
49 }
50
51- mir::CachedPtr<::testing::NiceMock<CustomInputDispatcher>> dispatcher;
52+ void inject_input() override {}
53+ virtual void input_dispatcher_expectations() {}
54+
55+ mir::CachedPtr<::testing::NiceMock<CustomMockInputDispatcher>> dispatcher;
56 mtf::CrossProcessSync dispatching_done;
57+ bool expectations_set{false};
58 };
59
60 }
61
62-using CustomInputDispatcherFixture = BespokeDisplayServerTestFixture;
63+using CustomInputDispatcher = BespokeDisplayServerTestFixture;
64
65-TEST_F(CustomInputDispatcherFixture, custom_input_dispatcher_receives_input)
66+TEST_F(CustomInputDispatcher, receives_input)
67 {
68 struct ServerConfig : CustomDispatcherServerConfig
69 {
70 void inject_input() override
71 {
72- auto dispatcher = the_input_dispatcher_mock();
73- {
74- using namespace ::testing;
75- InSequence seq;
76- EXPECT_CALL(*dispatcher, dispatch(mt::MotionEventWithPosition(1, 1))).Times(1);
77- EXPECT_CALL(*dispatcher, dispatch(mt::KeyDownEvent()))
78- .WillOnce(InvokeWithoutArgs([this]{ dispatching_done.signal_ready(); }));
79- }
80 fake_event_hub->synthesize_event(mis::a_motion_event().with_movement(1, 1));
81 fake_event_hub->synthesize_event(mis::a_key_down_event().of_scancode(KEY_ENTER));
82 }
83+
84+ void input_dispatcher_expectations() override
85+ {
86+ using namespace ::testing;
87+ auto const dispatcher = the_input_dispatcher_mock();
88+
89+ InSequence seq;
90+ EXPECT_CALL(*dispatcher, dispatch(mt::MotionEventWithPosition(1, 1))).Times(1);
91+ EXPECT_CALL(*dispatcher, dispatch(mt::KeyDownEvent()))
92+ .WillOnce(InvokeWithoutArgs([this]{ dispatching_done.signal_ready(); }));
93+ }
94 } server_config;
95
96-
97 launch_server_process(server_config);
98
99 // Since event handling happens asynchronously we need to allow some time
100@@ -121,35 +137,34 @@
101 });
102 }
103
104-TEST_F(CustomInputDispatcherFixture, custom_input_dispatcher_gets_started_and_stopped)
105+TEST_F(CustomInputDispatcher, gets_started_and_stopped)
106 {
107- struct ServecConfig : CustomDispatcherServerConfig
108+ struct ServerConfig : CustomDispatcherServerConfig
109 {
110- void inject_input() override
111+ void input_dispatcher_expectations() override
112 {
113- auto dispatcher = the_input_dispatcher_mock();
114- {
115- using namespace ::testing;
116- InSequence seq;
117- EXPECT_CALL(*dispatcher, start());
118- EXPECT_CALL(*dispatcher, stop());
119- }
120+ using namespace ::testing;
121+ auto const dispatcher = the_input_dispatcher_mock();
122+
123+ InSequence seq;
124+ EXPECT_CALL(*dispatcher, start());
125+ EXPECT_CALL(*dispatcher, stop());
126 }
127 } server_config;
128
129 launch_server_process(server_config);
130 }
131
132-TEST_F(CustomInputDispatcherFixture, custom_input_dispatcher_receives_focus_changes)
133+TEST_F(CustomInputDispatcher, receives_focus_changes)
134 {
135- struct ServecConfig : CustomDispatcherServerConfig
136+ struct ServerConfig : CustomDispatcherServerConfig
137 {
138- void inject_input() override
139+ void input_dispatcher_expectations() override
140 {
141- auto dispatcher = the_input_dispatcher_mock();
142 using namespace ::testing;
143+ auto const dispatcher = the_input_dispatcher_mock();
144+
145 InSequence seq;
146-
147 EXPECT_CALL(*dispatcher, focus_cleared()).Times(1);
148 EXPECT_CALL(*dispatcher, focus_changed(_)).Times(1);
149 EXPECT_CALL(*dispatcher, focus_cleared()).Times(1)

Subscribers

People subscribed via source and target branches