Merge lp:~mandel/location-service/delayed-providers into lp:location-service/trunk
- delayed-providers
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~mandel/location-service/delayed-providers |
Merge into: | lp:location-service/trunk |
Diff against target: |
562 lines (+406/-9) 4 files modified
include/location_service/com/ubuntu/location/provider.h (+43/-1) src/location_service/com/ubuntu/location/provider.cpp (+61/-8) tests/controller_test.cpp (+213/-0) tests/mock_delayed_provider.h (+89/-0) |
To merge this branch: | bzr merge lp:~mandel/location-service/delayed-providers |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Jim Hodapp (community) | code | Needs Fixing | |
Alfonso Sanchez-Beato | Approve | ||
Review via email: mp+261944@code.launchpad.net |
Commit message
Add the concept of a delayed providers. This will allow providers that are slow to start the chance to be started and later be connected accordingly.
Description of the change
Add the concept of a delayed providers. This will allow providers that are slow to start the chance to be started and later be connected accordingly.
PS Jenkins bot (ps-jenkins) wrote : | # |
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Please check inline comments.
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
See comment below
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:204
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
LGTM
Jim Hodapp (jhodapp) wrote : | # |
Some issues to address, see comments inline below.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:205
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 206. By Manuel de la Peña
-
Made changes according to reviews.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:206
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Unmerged revisions
- 206. By Manuel de la Peña
-
Made changes according to reviews.
- 205. By Manuel de la Peña
-
Update docs.
- 204. By Manuel de la Peña
-
Made chages as per review.
- 203. By Manuel de la Peña
-
Added support for delayed providers.
Preview Diff
1 | === modified file 'include/location_service/com/ubuntu/location/provider.h' | |||
2 | --- include/location_service/com/ubuntu/location/provider.h 2015-01-21 20:13:28 +0000 | |||
3 | +++ include/location_service/com/ubuntu/location/provider.h 2015-06-16 08:14:07 +0000 | |||
4 | @@ -150,6 +150,8 @@ | |||
5 | 150 | friend class Provider; | 150 | friend class Provider; |
6 | 151 | explicit Controller(Provider& instance); | 151 | explicit Controller(Provider& instance); |
7 | 152 | 152 | ||
8 | 153 | virtual void on_provider_booted(bool was_booted); | ||
9 | 154 | |||
10 | 153 | private: | 155 | private: |
11 | 154 | Provider& instance; | 156 | Provider& instance; |
12 | 155 | std::atomic<int> position_updates_counter; | 157 | std::atomic<int> position_updates_counter; |
13 | @@ -172,6 +174,20 @@ | |||
14 | 172 | core::Signal<Update<std::set<SpaceVehicle>>> svs; | 174 | core::Signal<Update<std::set<SpaceVehicle>>> svs; |
15 | 173 | }; | 175 | }; |
16 | 174 | 176 | ||
17 | 177 | /** | ||
18 | 178 | * @brief Wraps al those sigals that are related to the boot of the provider. | ||
19 | 179 | */ | ||
20 | 180 | struct Signals | ||
21 | 181 | { | ||
22 | 182 | core::Signal<bool> booted; | ||
23 | 183 | }; | ||
24 | 184 | |||
25 | 185 | enum class BootState { | ||
26 | 186 | NOT_BOOTED, | ||
27 | 187 | BOOTING, | ||
28 | 188 | BOOTED | ||
29 | 189 | }; | ||
30 | 190 | |||
31 | 175 | virtual ~Provider() = default; | 191 | virtual ~Provider() = default; |
32 | 176 | 192 | ||
33 | 177 | Provider(const Provider&) = delete; | 193 | Provider(const Provider&) = delete; |
34 | @@ -189,6 +205,18 @@ | |||
35 | 189 | virtual const Controller::Ptr& state_controller() const; | 205 | virtual const Controller::Ptr& state_controller() const; |
36 | 190 | 206 | ||
37 | 191 | /** | 207 | /** |
38 | 208 | * @brief Returns the booted signal to track the booting state of the provider. | ||
39 | 209 | * @return The signal that will be triggered once the provider has booted. | ||
40 | 210 | */ | ||
41 | 211 | virtual core::Signal<bool>& booted_signal(); | ||
42 | 212 | |||
43 | 213 | /** | ||
44 | 214 | * @brief Returns the booted signal to track the booting state of the provider. | ||
45 | 215 | * @return The signal that will be triggered once the provider has booted. | ||
46 | 216 | */ | ||
47 | 217 | virtual const core::Signal<bool>& booted_signal() const; | ||
48 | 218 | |||
49 | 219 | /** | ||
50 | 192 | * @brief Checks if the provider supports a specific feature. | 220 | * @brief Checks if the provider supports a specific feature. |
51 | 193 | * @param f Feature to test for | 221 | * @param f Feature to test for |
52 | 194 | * @return true iff the provider supports the feature. | 222 | * @return true iff the provider supports the feature. |
53 | @@ -210,6 +238,18 @@ | |||
54 | 210 | virtual bool matches_criteria(const Criteria& criteria); | 238 | virtual bool matches_criteria(const Criteria& criteria); |
55 | 211 | 239 | ||
56 | 212 | /** | 240 | /** |
57 | 241 | * @brief States the booting state of the provider. | ||
58 | 242 | * @return The boot state of the provider. | ||
59 | 243 | */ | ||
60 | 244 | virtual BootState boot_state() const; | ||
61 | 245 | |||
62 | 246 | /** | ||
63 | 247 | * @brief Indicates to the provider that it should start the boot process in order to be able to | ||
64 | 248 | * be used by the engine. | ||
65 | 249 | */ | ||
66 | 250 | virtual void boot(); | ||
67 | 251 | |||
68 | 252 | /** | ||
69 | 213 | * @brief Called by the engine whenever the wifi and cell ID reporting state changes. | 253 | * @brief Called by the engine whenever the wifi and cell ID reporting state changes. |
70 | 214 | * @param state The new state. | 254 | * @param state The new state. |
71 | 215 | */ | 255 | */ |
72 | @@ -270,12 +310,14 @@ | |||
73 | 270 | */ | 310 | */ |
74 | 271 | virtual void stop_velocity_updates(); | 311 | virtual void stop_velocity_updates(); |
75 | 272 | 312 | ||
77 | 273 | private: | 313 | protected: |
78 | 314 | // protected to allow better white box testing | ||
79 | 274 | struct | 315 | struct |
80 | 275 | { | 316 | { |
81 | 276 | Features features = Features::none; | 317 | Features features = Features::none; |
82 | 277 | Requirements requirements = Requirements::none; | 318 | Requirements requirements = Requirements::none; |
83 | 278 | Updates updates; | 319 | Updates updates; |
84 | 320 | Signals signals; | ||
85 | 279 | Controller::Ptr controller = Controller::Ptr{}; | 321 | Controller::Ptr controller = Controller::Ptr{}; |
86 | 280 | } d; | 322 | } d; |
87 | 281 | }; | 323 | }; |
88 | 282 | 324 | ||
89 | === modified file 'src/location_service/com/ubuntu/location/provider.cpp' | |||
90 | --- src/location_service/com/ubuntu/location/provider.cpp 2015-01-23 19:07:09 +0000 | |||
91 | +++ src/location_service/com/ubuntu/location/provider.cpp 2015-06-16 08:14:07 +0000 | |||
92 | @@ -16,9 +16,11 @@ | |||
93 | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> | 16 | * Authored by: Thomas Voß <thomas.voss@canonical.com> |
94 | 17 | */ | 17 | */ |
95 | 18 | #include <com/ubuntu/location/provider.h> | 18 | #include <com/ubuntu/location/provider.h> |
96 | 19 | #include <com/ubuntu/location/logging.h> | ||
97 | 19 | 20 | ||
98 | 20 | #include <atomic> | 21 | #include <atomic> |
99 | 21 | #include <bitset> | 22 | #include <bitset> |
100 | 23 | #include <functional> | ||
101 | 22 | #include <memory> | 24 | #include <memory> |
102 | 23 | 25 | ||
103 | 24 | namespace cul = com::ubuntu::location; | 26 | namespace cul = com::ubuntu::location; |
104 | @@ -51,12 +53,15 @@ | |||
105 | 51 | 53 | ||
106 | 52 | void cul::Provider::Controller::start_position_updates() | 54 | void cul::Provider::Controller::start_position_updates() |
107 | 53 | { | 55 | { |
109 | 54 | if (position_updates_counter < 0) | 56 | if (position_updates_counter < 0) { |
110 | 55 | return; | 57 | return; |
111 | 58 | } | ||
112 | 56 | 59 | ||
113 | 57 | if (++position_updates_counter == 1) | 60 | if (++position_updates_counter == 1) |
114 | 58 | { | 61 | { |
116 | 59 | instance.start_position_updates(); | 62 | if (instance.boot_state() == BootState::BOOTED) { |
117 | 63 | instance.start_position_updates(); | ||
118 | 64 | } | ||
119 | 60 | } | 65 | } |
120 | 61 | } | 66 | } |
121 | 62 | 67 | ||
122 | @@ -67,7 +72,8 @@ | |||
123 | 67 | 72 | ||
124 | 68 | if (--position_updates_counter == 0) | 73 | if (--position_updates_counter == 0) |
125 | 69 | { | 74 | { |
127 | 70 | instance.stop_position_updates(); | 75 | if (instance.boot_state() == BootState::BOOTED) |
128 | 76 | instance.stop_position_updates(); | ||
129 | 71 | } | 77 | } |
130 | 72 | } | 78 | } |
131 | 73 | 79 | ||
132 | @@ -83,7 +89,8 @@ | |||
133 | 83 | 89 | ||
134 | 84 | if (++heading_updates_counter == 1) | 90 | if (++heading_updates_counter == 1) |
135 | 85 | { | 91 | { |
137 | 86 | instance.start_heading_updates(); | 92 | if (instance.boot_state() == BootState::BOOTED) |
138 | 93 | instance.start_heading_updates(); | ||
139 | 87 | } | 94 | } |
140 | 88 | } | 95 | } |
141 | 89 | 96 | ||
142 | @@ -94,7 +101,8 @@ | |||
143 | 94 | 101 | ||
144 | 95 | if (--heading_updates_counter == 0) | 102 | if (--heading_updates_counter == 0) |
145 | 96 | { | 103 | { |
147 | 97 | instance.stop_heading_updates(); | 104 | if (instance.boot_state() == BootState::BOOTED) |
148 | 105 | instance.stop_heading_updates(); | ||
149 | 98 | } | 106 | } |
150 | 99 | } | 107 | } |
151 | 100 | 108 | ||
152 | @@ -110,7 +118,8 @@ | |||
153 | 110 | 118 | ||
154 | 111 | if (++velocity_updates_counter == 1) | 119 | if (++velocity_updates_counter == 1) |
155 | 112 | { | 120 | { |
157 | 113 | instance.start_velocity_updates(); | 121 | if (instance.boot_state() == BootState::BOOTED) |
158 | 122 | instance.start_velocity_updates(); | ||
159 | 114 | } | 123 | } |
160 | 115 | } | 124 | } |
161 | 116 | 125 | ||
162 | @@ -121,7 +130,8 @@ | |||
163 | 121 | 130 | ||
164 | 122 | if (--velocity_updates_counter == 0) | 131 | if (--velocity_updates_counter == 0) |
165 | 123 | { | 132 | { |
167 | 124 | instance.stop_velocity_updates(); | 133 | if (instance.boot_state() == BootState::BOOTED) |
168 | 134 | instance.stop_velocity_updates(); | ||
169 | 125 | } | 135 | } |
170 | 126 | } | 136 | } |
171 | 127 | 137 | ||
172 | @@ -130,12 +140,38 @@ | |||
173 | 130 | return velocity_updates_counter > 0; | 140 | return velocity_updates_counter > 0; |
174 | 131 | } | 141 | } |
175 | 132 | 142 | ||
176 | 143 | void cul::Provider::Controller::on_provider_booted(bool was_booted) | ||
177 | 144 | { | ||
178 | 145 | if (!was_booted) | ||
179 | 146 | return; | ||
180 | 147 | |||
181 | 148 | // we need to propagate the state of the provider using the internal counters as references | ||
182 | 149 | if (position_updates_counter > 0) { | ||
183 | 150 | instance.start_position_updates(); | ||
184 | 151 | } | ||
185 | 152 | if (heading_updates_counter > 0) { | ||
186 | 153 | instance.start_heading_updates(); | ||
187 | 154 | } | ||
188 | 155 | if (velocity_updates_counter > 0) { | ||
189 | 156 | instance.start_velocity_updates(); | ||
190 | 157 | } | ||
191 | 158 | } | ||
192 | 159 | |||
193 | 133 | cul::Provider::Controller::Controller(cul::Provider& instance) | 160 | cul::Provider::Controller::Controller(cul::Provider& instance) |
194 | 134 | : instance(instance), | 161 | : instance(instance), |
195 | 135 | position_updates_counter(0), | 162 | position_updates_counter(0), |
196 | 136 | heading_updates_counter(0), | 163 | heading_updates_counter(0), |
197 | 137 | velocity_updates_counter(0) | 164 | velocity_updates_counter(0) |
199 | 138 | { | 165 | { |
200 | 166 | using namespace std::placeholders; | ||
201 | 167 | |||
202 | 168 | if (instance.boot_state() != BootState::BOOTED) { | ||
203 | 169 | // if the instance has not booted and is delayed we need to keep track of its booting state | ||
204 | 170 | instance.booted_signal().connect(std::bind(&Controller::on_provider_booted, this, _1)); | ||
205 | 171 | if (instance.boot_state() != BootState::BOOTING) { | ||
206 | 172 | instance.boot(); | ||
207 | 173 | } | ||
208 | 174 | } | ||
209 | 139 | } | 175 | } |
210 | 140 | 176 | ||
211 | 141 | const cul::Provider::Controller::Ptr& cul::Provider::state_controller() const | 177 | const cul::Provider::Controller::Ptr& cul::Provider::state_controller() const |
212 | @@ -158,11 +194,28 @@ | |||
213 | 158 | return false; | 194 | return false; |
214 | 159 | } | 195 | } |
215 | 160 | 196 | ||
216 | 197 | cul::Provider::BootState cul::Provider::boot_state() const | ||
217 | 198 | { | ||
218 | 199 | return cul::Provider::BootState::BOOTED; | ||
219 | 200 | } | ||
220 | 201 | |||
221 | 202 | void cul::Provider::boot() { } | ||
222 | 203 | |||
223 | 161 | const cul::Provider::Updates& cul::Provider::updates() const | 204 | const cul::Provider::Updates& cul::Provider::updates() const |
224 | 162 | { | 205 | { |
225 | 163 | return d.updates; | 206 | return d.updates; |
226 | 164 | } | 207 | } |
227 | 165 | 208 | ||
228 | 209 | core::Signal<bool>& cul::Provider::booted_signal() | ||
229 | 210 | { | ||
230 | 211 | return d.signals.booted; | ||
231 | 212 | } | ||
232 | 213 | |||
233 | 214 | const core::Signal<bool>& cul::Provider::booted_signal() const | ||
234 | 215 | { | ||
235 | 216 | return d.signals.booted; | ||
236 | 217 | } | ||
237 | 218 | |||
238 | 166 | cul::Provider::Provider( | 219 | cul::Provider::Provider( |
239 | 167 | const cul::Provider::Features& features, | 220 | const cul::Provider::Features& features, |
240 | 168 | const cul::Provider::Requirements& requirements) | 221 | const cul::Provider::Requirements& requirements) |
241 | 169 | 222 | ||
242 | === modified file 'tests/controller_test.cpp' | |||
243 | --- tests/controller_test.cpp 2014-09-10 19:34:09 +0000 | |||
244 | +++ tests/controller_test.cpp 2015-06-16 08:14:07 +0000 | |||
245 | @@ -18,6 +18,7 @@ | |||
246 | 18 | #include <com/ubuntu/location/provider.h> | 18 | #include <com/ubuntu/location/provider.h> |
247 | 19 | 19 | ||
248 | 20 | #include "mock_provider.h" | 20 | #include "mock_provider.h" |
249 | 21 | #include "mock_delayed_provider.h" | ||
250 | 21 | 22 | ||
251 | 22 | #include <gmock/gmock.h> | 23 | #include <gmock/gmock.h> |
252 | 23 | #include <gtest/gtest.h> | 24 | #include <gtest/gtest.h> |
253 | @@ -130,3 +131,215 @@ | |||
254 | 130 | EXPECT_FALSE(controller->are_velocity_updates_running()); | 131 | EXPECT_FALSE(controller->are_velocity_updates_running()); |
255 | 131 | EXPECT_FALSE(controller->are_heading_updates_running()); | 132 | EXPECT_FALSE(controller->are_heading_updates_running()); |
256 | 132 | } | 133 | } |
257 | 134 | |||
258 | 135 | TEST(Controller, controller_resumes_state_after_boot) { | ||
259 | 136 | using namespace ::testing; | ||
260 | 137 | using ::testing::Mock; | ||
261 | 138 | |||
262 | 139 | MockDelayedProvider provider; | ||
263 | 140 | |||
264 | 141 | // ignore what ever was performed on construction | ||
265 | 142 | Mock::VerifyAndClear(&provider); | ||
266 | 143 | |||
267 | 144 | } | ||
268 | 145 | |||
269 | 146 | TEST(Controller, controller_does_not_call_start_position_if_not_booted) { | ||
270 | 147 | using namespace ::testing; | ||
271 | 148 | using ::testing::Mock; | ||
272 | 149 | |||
273 | 150 | MockDelayedProvider provider; | ||
274 | 151 | |||
275 | 152 | // ignore what ever was performed on construction | ||
276 | 153 | Mock::VerifyAndClear(&provider); | ||
277 | 154 | // use a mock controller | ||
278 | 155 | auto controller = provider.state_controller(); | ||
279 | 156 | |||
280 | 157 | EXPECT_CALL(provider, boot_state()).Times(Exactly(1)) | ||
281 | 158 | .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED)); | ||
282 | 159 | EXPECT_CALL(provider, start_position_updates()).Times(Exactly(0)); | ||
283 | 160 | |||
284 | 161 | controller->start_position_updates(); | ||
285 | 162 | controller->start_position_updates(); | ||
286 | 163 | } | ||
287 | 164 | |||
288 | 165 | TEST(Controller, controller_does_not_call_start_position_if_booting) { | ||
289 | 166 | using namespace ::testing; | ||
290 | 167 | using ::testing::Mock; | ||
291 | 168 | |||
292 | 169 | MockDelayedProvider provider; | ||
293 | 170 | |||
294 | 171 | // ignore what ever was performed on construction | ||
295 | 172 | Mock::VerifyAndClear(&provider); | ||
296 | 173 | // use a mock controller | ||
297 | 174 | auto controller = provider.state_controller(); | ||
298 | 175 | |||
299 | 176 | EXPECT_CALL(provider, boot_state()).Times(Exactly(1)) | ||
300 | 177 | .WillOnce(Return(cul::Provider::BootState::BOOTING)); | ||
301 | 178 | EXPECT_CALL(provider, start_position_updates()).Times(Exactly(0)); | ||
302 | 179 | |||
303 | 180 | controller->start_position_updates(); | ||
304 | 181 | } | ||
305 | 182 | |||
306 | 183 | TEST(Controller, controller_does_not_call_start_heading_if_not_booted) { | ||
307 | 184 | using namespace ::testing; | ||
308 | 185 | using ::testing::Mock; | ||
309 | 186 | |||
310 | 187 | MockDelayedProvider provider; | ||
311 | 188 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
312 | 189 | |||
313 | 190 | // ignore what ever was performed on construction | ||
314 | 191 | Mock::VerifyAndClear(&provider); | ||
315 | 192 | // use a mock controller | ||
316 | 193 | auto controller = provider.state_controller(); | ||
317 | 194 | |||
318 | 195 | EXPECT_CALL(provider, boot_state()).Times(Exactly(1)) | ||
319 | 196 | .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED)); | ||
320 | 197 | EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0)); | ||
321 | 198 | |||
322 | 199 | controller->start_heading_updates(); | ||
323 | 200 | } | ||
324 | 201 | |||
325 | 202 | TEST(Controller, controller_does_not_call_start_heading_if_booting) { | ||
326 | 203 | using namespace ::testing; | ||
327 | 204 | using ::testing::Mock; | ||
328 | 205 | |||
329 | 206 | MockDelayedProvider provider; | ||
330 | 207 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
331 | 208 | |||
332 | 209 | // ignore what ever was performed on construction | ||
333 | 210 | Mock::VerifyAndClear(&provider); | ||
334 | 211 | // use a mock controller | ||
335 | 212 | auto controller = provider.state_controller(); | ||
336 | 213 | |||
337 | 214 | EXPECT_CALL(provider, boot_state()).Times(Exactly(1)) | ||
338 | 215 | .WillOnce(Return(cul::Provider::BootState::BOOTING)); | ||
339 | 216 | EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0)); | ||
340 | 217 | |||
341 | 218 | controller->start_heading_updates(); | ||
342 | 219 | } | ||
343 | 220 | |||
344 | 221 | TEST(Controller, controller_does_not_call_start_velocity_if_not_booted) { | ||
345 | 222 | using namespace ::testing; | ||
346 | 223 | using ::testing::Mock; | ||
347 | 224 | |||
348 | 225 | MockDelayedProvider provider; | ||
349 | 226 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
350 | 227 | |||
351 | 228 | // ignore what ever was performed on construction | ||
352 | 229 | Mock::VerifyAndClear(&provider); | ||
353 | 230 | // use a mock controller | ||
354 | 231 | auto controller = provider.state_controller(); | ||
355 | 232 | |||
356 | 233 | EXPECT_CALL(provider, boot_state()).Times(Exactly(1)) | ||
357 | 234 | .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED)); | ||
358 | 235 | EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0)); | ||
359 | 236 | |||
360 | 237 | controller->start_velocity_updates(); | ||
361 | 238 | } | ||
362 | 239 | |||
363 | 240 | TEST(Controller, controller_does_not_call_start_velocity_if_booting) { | ||
364 | 241 | using namespace ::testing; | ||
365 | 242 | using ::testing::Mock; | ||
366 | 243 | |||
367 | 244 | MockDelayedProvider provider; | ||
368 | 245 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
369 | 246 | |||
370 | 247 | // ignore what ever was performed on construction | ||
371 | 248 | Mock::VerifyAndClear(&provider); | ||
372 | 249 | // use a mock controller | ||
373 | 250 | auto controller = provider.state_controller(); | ||
374 | 251 | |||
375 | 252 | EXPECT_CALL(provider, boot_state()).Times(Exactly(1)) | ||
376 | 253 | .WillOnce(Return(cul::Provider::BootState::BOOTING)); | ||
377 | 254 | EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0)); | ||
378 | 255 | |||
379 | 256 | controller->start_velocity_updates(); | ||
380 | 257 | } | ||
381 | 258 | |||
382 | 259 | TEST(Controller, controller_does_not_call_stop_position_if_not_booted) { | ||
383 | 260 | using namespace ::testing; | ||
384 | 261 | using ::testing::Mock; | ||
385 | 262 | |||
386 | 263 | MockDelayedProvider provider; | ||
387 | 264 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
388 | 265 | |||
389 | 266 | // ignore what ever was performed on construction | ||
390 | 267 | Mock::VerifyAndClear(&provider); | ||
391 | 268 | // use a mock controller | ||
392 | 269 | auto controller = provider.state_controller(); | ||
393 | 270 | |||
394 | 271 | EXPECT_CALL(provider, boot_state()).Times(Exactly(2)) | ||
395 | 272 | .WillOnce(Return(cul::Provider::BootState::BOOTED)) | ||
396 | 273 | .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED)); | ||
397 | 274 | EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1)); | ||
398 | 275 | EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(0)); | ||
399 | 276 | |||
400 | 277 | controller->start_position_updates(); | ||
401 | 278 | controller->stop_position_updates(); | ||
402 | 279 | } | ||
403 | 280 | |||
404 | 281 | TEST(Controller, controller_does_not_call_stop_position_if_booting) { | ||
405 | 282 | using namespace ::testing; | ||
406 | 283 | using ::testing::Mock; | ||
407 | 284 | |||
408 | 285 | MockDelayedProvider provider; | ||
409 | 286 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
410 | 287 | |||
411 | 288 | // ignore what ever was performed on construction | ||
412 | 289 | Mock::VerifyAndClear(&provider); | ||
413 | 290 | // use a mock controller | ||
414 | 291 | auto controller = provider.state_controller(); | ||
415 | 292 | |||
416 | 293 | EXPECT_CALL(provider, boot_state()).Times(Exactly(2)) | ||
417 | 294 | .WillOnce(Return(cul::Provider::BootState::BOOTED)) | ||
418 | 295 | .WillOnce(Return(cul::Provider::BootState::BOOTING)); | ||
419 | 296 | EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1)); | ||
420 | 297 | EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(0)); | ||
421 | 298 | |||
422 | 299 | controller->start_position_updates(); | ||
423 | 300 | controller->stop_position_updates(); | ||
424 | 301 | } | ||
425 | 302 | |||
426 | 303 | TEST(Controller, controller_does_not_call_stop_heading_if_not_booted) { | ||
427 | 304 | using namespace ::testing; | ||
428 | 305 | using ::testing::Mock; | ||
429 | 306 | |||
430 | 307 | MockDelayedProvider provider; | ||
431 | 308 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
432 | 309 | |||
433 | 310 | // ignore what ever was performed on construction | ||
434 | 311 | Mock::VerifyAndClear(&provider); | ||
435 | 312 | // use a mock controller | ||
436 | 313 | auto controller = provider.state_controller(); | ||
437 | 314 | |||
438 | 315 | EXPECT_CALL(provider, boot_state()).Times(Exactly(2)) | ||
439 | 316 | .WillOnce(Return(cul::Provider::BootState::BOOTED)) | ||
440 | 317 | .WillOnce(Return(cul::Provider::BootState::BOOTING)); | ||
441 | 318 | EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(1)); | ||
442 | 319 | EXPECT_CALL(provider, stop_heading_updates()).Times(Exactly(0)); | ||
443 | 320 | |||
444 | 321 | controller->start_heading_updates(); | ||
445 | 322 | controller->stop_heading_updates(); | ||
446 | 323 | } | ||
447 | 324 | |||
448 | 325 | TEST(Controller, controller_does_not_call_stop_velocity_if_not_booted) { | ||
449 | 326 | using namespace ::testing; | ||
450 | 327 | using ::testing::Mock; | ||
451 | 328 | |||
452 | 329 | MockDelayedProvider provider; | ||
453 | 330 | EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true)); | ||
454 | 331 | |||
455 | 332 | // ignore what ever was performed on construction | ||
456 | 333 | Mock::VerifyAndClear(&provider); | ||
457 | 334 | // use a mock controller | ||
458 | 335 | auto controller = provider.state_controller(); | ||
459 | 336 | |||
460 | 337 | EXPECT_CALL(provider, boot_state()).Times(Exactly(2)) | ||
461 | 338 | .WillOnce(Return(cul::Provider::BootState::BOOTED)) | ||
462 | 339 | .WillOnce(Return(cul::Provider::BootState::BOOTING)); | ||
463 | 340 | EXPECT_CALL(provider, start_velocity_updates()).Times(Exactly(1)); | ||
464 | 341 | EXPECT_CALL(provider, stop_velocity_updates()).Times(Exactly(0)); | ||
465 | 342 | |||
466 | 343 | controller->start_velocity_updates(); | ||
467 | 344 | controller->stop_velocity_updates(); | ||
468 | 345 | } | ||
469 | 133 | 346 | ||
470 | === added file 'tests/mock_delayed_provider.h' | |||
471 | --- tests/mock_delayed_provider.h 1970-01-01 00:00:00 +0000 | |||
472 | +++ tests/mock_delayed_provider.h 2015-06-16 08:14:07 +0000 | |||
473 | @@ -0,0 +1,89 @@ | |||
474 | 1 | /* | ||
475 | 2 | * Copyright © 2014 Canonical Ltd. | ||
476 | 3 | * | ||
477 | 4 | * This program is free software: you can redistribute it and/or modify it | ||
478 | 5 | * under the terms of the GNU Lesser General Public License version 3, | ||
479 | 6 | * as published by the Free Software Foundation. | ||
480 | 7 | * | ||
481 | 8 | * This program is distributed in the hope that it will be useful, | ||
482 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
483 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
484 | 11 | * GNU Lesser General Public License for more details. | ||
485 | 12 | * | ||
486 | 13 | * You should have received a copy of the GNU Lesser General Public License | ||
487 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
488 | 15 | * | ||
489 | 16 | * Authored by: M | ||
490 | 17 | */ | ||
491 | 18 | #ifndef MOCK_DELAYED_PROVIDER_H_ | ||
492 | 19 | #define MOCK_DELAYED_PROVIDER_H_ | ||
493 | 20 | |||
494 | 21 | #include <com/ubuntu/location/provider.h> | ||
495 | 22 | #include <com/ubuntu/location/logging.h> | ||
496 | 23 | |||
497 | 24 | #include <gmock/gmock.h> | ||
498 | 25 | |||
499 | 26 | struct PublicController : public com::ubuntu::location::Provider::Controller | ||
500 | 27 | { | ||
501 | 28 | |||
502 | 29 | explicit PublicController(com::ubuntu::location::Provider& instance) | ||
503 | 30 | : com::ubuntu::location::Provider::Controller(instance) {} | ||
504 | 31 | }; | ||
505 | 32 | |||
506 | 33 | struct MockDelayedProvider : public com::ubuntu::location::Provider | ||
507 | 34 | { | ||
508 | 35 | MockDelayedProvider() : com::ubuntu::location::Provider() | ||
509 | 36 | { | ||
510 | 37 | } | ||
511 | 38 | |||
512 | 39 | MOCK_METHOD1(matches_criteria, bool(const com::ubuntu::location::Criteria&)); | ||
513 | 40 | |||
514 | 41 | MOCK_CONST_METHOD1(supports, bool(const com::ubuntu::location::Provider::Features&)); | ||
515 | 42 | MOCK_CONST_METHOD1(requires, bool(const com::ubuntu::location::Provider::Requirements&)); | ||
516 | 43 | |||
517 | 44 | // Called by the engine whenever the wifi and cell ID reporting state changes. | ||
518 | 45 | MOCK_METHOD1(on_wifi_and_cell_reporting_state_changed, void(com::ubuntu::location::WifiAndCellIdReportingState state)); | ||
519 | 46 | |||
520 | 47 | // Called by the engine whenever the reference location changed. | ||
521 | 48 | MOCK_METHOD1(on_reference_location_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Position>& position)); | ||
522 | 49 | |||
523 | 50 | // Called by the engine whenever the reference velocity changed. | ||
524 | 51 | MOCK_METHOD1(on_reference_velocity_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& velocity)); | ||
525 | 52 | |||
526 | 53 | // Called by the engine whenever the reference heading changed. | ||
527 | 54 | MOCK_METHOD1(on_reference_heading_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Heading>& heading)); | ||
528 | 55 | |||
529 | 56 | MOCK_METHOD0(start_position_updates, void()); | ||
530 | 57 | MOCK_METHOD0(stop_position_updates, void()); | ||
531 | 58 | |||
532 | 59 | MOCK_METHOD0(start_heading_updates, void()); | ||
533 | 60 | MOCK_METHOD0(stop_heading_updates, void()); | ||
534 | 61 | |||
535 | 62 | MOCK_METHOD0(start_velocity_updates, void()); | ||
536 | 63 | MOCK_METHOD0(stop_velocity_updates, void()); | ||
537 | 64 | |||
538 | 65 | MOCK_CONST_METHOD0(has_delayed_boot, bool()); | ||
539 | 66 | MOCK_CONST_METHOD0(boot_state, BootState()); | ||
540 | 67 | MOCK_CONST_METHOD0(boot, void()); | ||
541 | 68 | |||
542 | 69 | |||
543 | 70 | // Inject a position update from the outside. | ||
544 | 71 | void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Position>& update) | ||
545 | 72 | { | ||
546 | 73 | mutable_updates().position(update); | ||
547 | 74 | } | ||
548 | 75 | |||
549 | 76 | // Inject a velocity update from the outside. | ||
550 | 77 | void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& update) | ||
551 | 78 | { | ||
552 | 79 | mutable_updates().velocity(update); | ||
553 | 80 | } | ||
554 | 81 | |||
555 | 82 | // Inject a heading update from the outside. | ||
556 | 83 | void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Heading>& update) | ||
557 | 84 | { | ||
558 | 85 | mutable_updates().heading(update); | ||
559 | 86 | } | ||
560 | 87 | }; | ||
561 | 88 | |||
562 | 89 | #endif // MOCK_PROVIDER_H_ |
PASSED: Continuous integration, rev:203 jenkins. qa.ubuntu. com/job/ location- service- ci/388/ jenkins. qa.ubuntu. com/job/ location- service- vivid-amd64- ci/60 jenkins. qa.ubuntu. com/job/ location- service- vivid-armhf- ci/60 jenkins. qa.ubuntu. com/job/ location- service- vivid-armhf- ci/60/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ location- service- vivid-i386- ci/60
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/location- service- ci/388/ rebuild
http://