Merge lp:~mandel/location-service/delayed-providers into lp:location-service/15.04

Proposed by Scott Sweeny on 2015-10-22
Status: Needs review
Proposed branch: lp:~mandel/location-service/delayed-providers
Merge into: lp:location-service/15.04
Diff against target: 814 lines (+561/-22) (has conflicts)
11 files modified
data/ubuntu-location-service-trust-stored.conf.in (+4/-2)
debian/changelog (+21/-0)
include/location_service/com/ubuntu/location/provider.h (+43/-1)
po/br.po (+28/-0)
po/lb.po (+31/-0)
po/zh_HK.po (+27/-0)
src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp (+40/-11)
src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp (+4/-0)
src/location_service/com/ubuntu/location/provider.cpp (+61/-8)
tests/controller_test.cpp (+213/-0)
tests/mock_delayed_provider.h (+89/-0)
Text conflict in debian/changelog
To merge this branch: bzr merge lp:~mandel/location-service/delayed-providers
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team 2015-10-22 Pending
Review via email: mp+275377@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.

To post a comment you must log in.

Unmerged revisions

206. By Manuel de la Peña on 2015-06-16

Made changes according to reviews.

205. By Manuel de la Peña on 2015-06-15

Update docs.

204. By Manuel de la Peña on 2015-06-15

Made chages as per review.

203. By Manuel de la Peña on 2015-06-15

Added support for delayed providers.

202. By Launchpad Translations on behalf of phablet-team on 2015-06-06

Launchpad automatic translations update.

201. By Launchpad Translations on behalf of phablet-team on 2015-06-04

Launchpad automatic translations update.

200. By CI Train Bot Account on 2015-06-01

Releasing 2.1+15.10.20150601.2-0ubuntu1

199. By Manuel de la Peña on 2015-06-01

Ensure that the trust store is started when is needed.

Approved by: Michael Frey, PS Jenkins bot, Thomas Voß

198. By Launchpad Translations on behalf of phablet-team on 2015-06-01

Launchpad automatic translations update.

197. By CI Train Bot Account on 2015-05-28

Releasing 2.1+15.10.20150528.3-0ubuntu1

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ubuntu-location-service-trust-stored.conf.in'
2--- data/ubuntu-location-service-trust-stored.conf.in 2014-09-19 14:36:51 +0000
3+++ data/ubuntu-location-service-trust-stored.conf.in 2015-10-22 15:34:12 +0000
4@@ -4,8 +4,10 @@
5 # starting; if dbus is available and location-service isn't or vice-versa,
6 # startup will fail but the next event firing will trigger another start
7 start on (started dbus and xsession SESSION=ubuntu-touch) or \
8- :sys:started JOB=ubuntu-location-service
9-stop on desktop-end or :sys:stopping JOB=ubuntu-location-service
10+ dbus BUS=system SIGNAL=NameOwnerChanged INTERFACE=org.freedesktop.DBus OBJPATH=/org/freedesktop/DBus ARG0=com.ubuntu.location.Service ARG2!=""
11+
12+stop on desktop-end or \
13+ dbus BUS=system SIGNAL=NameOwnerChanged INTERFACE=org.freedesktop.DBus OBJPATH=/org/freedesktop/DBus ARG0=com.ubuntu.location.Service ARG2=""
14
15 respawn
16
17
18=== modified file 'debian/changelog'
19--- debian/changelog 2015-10-22 07:16:50 +0000
20+++ debian/changelog 2015-10-22 15:34:12 +0000
21@@ -1,3 +1,4 @@
22+<<<<<<< TREE
23 location-service (2.1+15.04.20151022-0ubuntu1) vivid; urgency=medium
24
25 [ Thomas Voß ]
26@@ -12,6 +13,26 @@
27
28 -- Thomas Voß <ci-train-bot@canonical.com> Thu, 22 Oct 2015 07:16:50 +0000
29
30+=======
31+location-service (2.1+15.10.20150601.2-0ubuntu1) wily; urgency=medium
32+
33+ [ CI Train Bot ]
34+ * New rebuild forced.
35+
36+ [ Manuel de la Pena ]
37+ * Ensure that the trust store is started when is needed.
38+
39+ -- CI Train Bot <ci-train-bot@canonical.com> Mon, 01 Jun 2015 15:13:06 +0000
40+
41+location-service (2.1+15.10.20150528.3-0ubuntu1) wily; urgency=medium
42+
43+ [ Thomas Voß ]
44+ * Make sure we always hand a lock owning its mutex to
45+ on_access_point_added. (LP: #1426307)
46+
47+ -- CI Train Bot <ci-train-bot@canonical.com> Thu, 28 May 2015 11:40:58 +0000
48+
49+>>>>>>> MERGE-SOURCE
50 location-service (2.1+15.04.20150427.1-0ubuntu1) vivid; urgency=medium
51
52 [ CI Train Bot ]
53
54=== modified file 'include/location_service/com/ubuntu/location/provider.h'
55--- include/location_service/com/ubuntu/location/provider.h 2015-01-21 20:13:28 +0000
56+++ include/location_service/com/ubuntu/location/provider.h 2015-10-22 15:34:12 +0000
57@@ -150,6 +150,8 @@
58 friend class Provider;
59 explicit Controller(Provider& instance);
60
61+ virtual void on_provider_booted(bool was_booted);
62+
63 private:
64 Provider& instance;
65 std::atomic<int> position_updates_counter;
66@@ -172,6 +174,20 @@
67 core::Signal<Update<std::set<SpaceVehicle>>> svs;
68 };
69
70+ /**
71+ * @brief Wraps al those sigals that are related to the boot of the provider.
72+ */
73+ struct Signals
74+ {
75+ core::Signal<bool> booted;
76+ };
77+
78+ enum class BootState {
79+ NOT_BOOTED,
80+ BOOTING,
81+ BOOTED
82+ };
83+
84 virtual ~Provider() = default;
85
86 Provider(const Provider&) = delete;
87@@ -189,6 +205,18 @@
88 virtual const Controller::Ptr& state_controller() const;
89
90 /**
91+ * @brief Returns the booted signal to track the booting state of the provider.
92+ * @return The signal that will be triggered once the provider has booted.
93+ */
94+ virtual core::Signal<bool>& booted_signal();
95+
96+ /**
97+ * @brief Returns the booted signal to track the booting state of the provider.
98+ * @return The signal that will be triggered once the provider has booted.
99+ */
100+ virtual const core::Signal<bool>& booted_signal() const;
101+
102+ /**
103 * @brief Checks if the provider supports a specific feature.
104 * @param f Feature to test for
105 * @return true iff the provider supports the feature.
106@@ -210,6 +238,18 @@
107 virtual bool matches_criteria(const Criteria& criteria);
108
109 /**
110+ * @brief States the booting state of the provider.
111+ * @return The boot state of the provider.
112+ */
113+ virtual BootState boot_state() const;
114+
115+ /**
116+ * @brief Indicates to the provider that it should start the boot process in order to be able to
117+ * be used by the engine.
118+ */
119+ virtual void boot();
120+
121+ /**
122 * @brief Called by the engine whenever the wifi and cell ID reporting state changes.
123 * @param state The new state.
124 */
125@@ -270,12 +310,14 @@
126 */
127 virtual void stop_velocity_updates();
128
129-private:
130+protected:
131+ // protected to allow better white box testing
132 struct
133 {
134 Features features = Features::none;
135 Requirements requirements = Requirements::none;
136 Updates updates;
137+ Signals signals;
138 Controller::Ptr controller = Controller::Ptr{};
139 } d;
140 };
141
142=== added file 'po/br.po'
143--- po/br.po 1970-01-01 00:00:00 +0000
144+++ po/br.po 2015-10-22 15:34:12 +0000
145@@ -0,0 +1,28 @@
146+# Breton translation for location-service
147+# Copyright (c) 2015 Rosetta Contributors and Canonical Ltd 2015
148+# This file is distributed under the same license as the location-service package.
149+# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
150+#
151+msgid ""
152+msgstr ""
153+"Project-Id-Version: location-service\n"
154+"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
155+"POT-Creation-Date: 2014-09-19 01:04+0200\n"
156+"PO-Revision-Date: 2015-06-05 06:21+0000\n"
157+"Last-Translator: Fohanno Thierry <thierry.fohanno@ofis-bzh.org>\n"
158+"Language-Team: Breton <br@li.org>\n"
159+"MIME-Version: 1.0\n"
160+"Content-Type: text/plain; charset=UTF-8\n"
161+"Content-Transfer-Encoding: 8bit\n"
162+"X-Launchpad-Export-Date: 2015-06-06 05:30+0000\n"
163+"X-Generator: Launchpad (build 17540)\n"
164+
165+#: /tmp/i18n/src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp:170
166+msgid "An unconfined application wants to access your current location."
167+msgstr ""
168+"Fellout a ra d'un arload ha n'eo ket bac'het gouzout pelec'h emaoc'h bremañ."
169+
170+#: /tmp/i18n/src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp:173
171+#, boost-format
172+msgid "%1% wants to access your current location."
173+msgstr "Fellout a ra da %1% gouzout pelec'h emaoc'h bremañ."
174
175=== added file 'po/lb.po'
176--- po/lb.po 1970-01-01 00:00:00 +0000
177+++ po/lb.po 2015-10-22 15:34:12 +0000
178@@ -0,0 +1,31 @@
179+# Luxembourgish translation for location-service
180+# Copyright (c) 2015 Rosetta Contributors and Canonical Ltd 2015
181+# This file is distributed under the same license as the location-service package.
182+# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
183+#
184+msgid ""
185+msgstr ""
186+"Project-Id-Version: location-service\n"
187+"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
188+"POT-Creation-Date: 2014-09-19 01:04+0200\n"
189+"PO-Revision-Date: 2015-05-31 16:04+0000\n"
190+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
191+"Language-Team: Luxembourgish <lb@li.org>\n"
192+"MIME-Version: 1.0\n"
193+"Content-Type: text/plain; charset=UTF-8\n"
194+"Content-Transfer-Encoding: 8bit\n"
195+"X-Launchpad-Export-Date: 2015-06-01 05:35+0000\n"
196+"X-Generator: Launchpad (build 17532)\n"
197+
198+#: /tmp/i18n/src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp:170
199+msgid "An unconfined application wants to access your current location."
200+msgstr ""
201+"Eng Applikatioun man onageschränkten Zougrëffsrechter wëll op Äer aktuell "
202+"Positioun zougräifen. Wëllt Däer dëser Applikatioun vertrauen?"
203+
204+#: /tmp/i18n/src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp:173
205+#, boost-format
206+msgid "%1% wants to access your current location."
207+msgstr ""
208+"%1% wëll op Äer aktuell Positioun zougräifen. Wëllt Däer dëser Applikatioun "
209+"vertrauen?"
210
211=== added file 'po/zh_HK.po'
212--- po/zh_HK.po 1970-01-01 00:00:00 +0000
213+++ po/zh_HK.po 2015-10-22 15:34:12 +0000
214@@ -0,0 +1,27 @@
215+# Chinese (Hong Kong) translation for location-service
216+# Copyright (c) 2015 Rosetta Contributors and Canonical Ltd 2015
217+# This file is distributed under the same license as the location-service package.
218+# FIRST AUTHOR <EMAIL@ADDRESS>, 2015.
219+#
220+msgid ""
221+msgstr ""
222+"Project-Id-Version: location-service\n"
223+"Report-Msgid-Bugs-To: FULL NAME <EMAIL@ADDRESS>\n"
224+"POT-Creation-Date: 2014-09-19 01:04+0200\n"
225+"PO-Revision-Date: 2015-06-03 18:46+0000\n"
226+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
227+"Language-Team: Chinese (Hong Kong) <zh_HK@li.org>\n"
228+"MIME-Version: 1.0\n"
229+"Content-Type: text/plain; charset=UTF-8\n"
230+"Content-Transfer-Encoding: 8bit\n"
231+"X-Launchpad-Export-Date: 2015-06-04 05:34+0000\n"
232+"X-Generator: Launchpad (build 17540)\n"
233+
234+#: /tmp/i18n/src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp:170
235+msgid "An unconfined application wants to access your current location."
236+msgstr "有一個尚未設限的應用程式想要存取你目前的位置。"
237+
238+#: /tmp/i18n/src/location_service/com/ubuntu/location/service/trust_store_permission_manager.cpp:173
239+#, boost-format
240+msgid "%1% wants to access your current location."
241+msgstr "%1% 想存取你目前的位置。"
242
243=== modified file 'src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp'
244--- src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp 2014-08-14 20:33:37 +0000
245+++ src/location_service/com/ubuntu/location/connectivity/cached_wireless_network.cpp 2015-10-22 15:34:12 +0000
246@@ -18,6 +18,10 @@
247
248 #include <com/ubuntu/location/connectivity/cached_wireless_network.h>
249
250+#include <fstream>
251+#include <sstream>
252+#include <string>
253+
254 namespace connectivity = com::ubuntu::location::connectivity;
255
256 namespace
257@@ -50,6 +54,39 @@
258
259 return mode;
260 }
261+
262+// boot_time returns the time since the epoch when the system booted.
263+std::chrono::system_clock::time_point boot_time()
264+{
265+ std::ifstream in{"/proc/stat"};
266+ std::string line;
267+
268+ while (std::getline(in, line))
269+ {
270+ if (line.empty())
271+ continue;
272+
273+ std::stringstream ss{line};
274+ std::string name; ss >> name;
275+
276+ if (name != "btime")
277+ continue;
278+
279+ std::uint64_t ts; ss >> ts;
280+ return std::chrono::system_clock::time_point{std::chrono::seconds{ts}};
281+ }
282+
283+ // Fallback to the best estimate we can give.
284+ return std::chrono::system_clock::now();
285+}
286+
287+// NetworkManager reports AP LastSeen timestamps in seconds since boot. We map that back to the epoch
288+// to keep dependent software working.
289+std::chrono::system_clock::time_point translate_time_stamp(std::uint64_t ts)
290+{
291+ static const auto ts_when_booted = boot_time();
292+ return ts_when_booted + std::chrono::seconds{ts};
293+}
294 }
295
296 const core::Property<std::chrono::system_clock::time_point>& detail::CachedWirelessNetwork::last_seen() const
297@@ -88,10 +125,7 @@
298 : device_(device),
299 access_point_(ap)
300 {
301- last_seen_ = std::chrono::system_clock::time_point
302- {
303- std::chrono::system_clock::duration{access_point_.last_seen->get()}
304- };
305+ last_seen_ = translate_time_stamp(access_point_.last_seen->get());
306
307 bssid_ = access_point_.hw_address->get();
308 ssid_ = utf8_ssid_to_string(access_point_.ssid->get());
309@@ -162,13 +196,8 @@
310 org::freedesktop::NetworkManager::AccessPoint::LastSeen::name(),
311 [](CachedWirelessNetwork& thiz, const core::dbus::types::Variant& value)
312 {
313- thiz.last_seen_ = std::chrono::system_clock::time_point
314- {
315- std::chrono::system_clock::duration
316- {
317- value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>()
318- }
319- };
320+ thiz.last_seen_ = translate_time_stamp(
321+ value.as<org::freedesktop::NetworkManager::AccessPoint::LastSeen::ValueType>());
322 }
323 }
324 };
325
326=== modified file 'src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp'
327--- src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2015-04-27 15:44:40 +0000
328+++ src/location_service/com/ubuntu/location/connectivity/ofono_nm_connectivity_manager.cpp 2015-10-22 15:34:12 +0000
329@@ -530,6 +530,10 @@
330 {
331 try
332 {
333+ // We have to make sure that we always hand in a lock that owns the mutex.
334+ if (not ul.owns_lock())
335+ ul.lock();
336+
337 on_access_point_added(path, device_path, ul);
338 }
339 catch (const std::exception& e)
340
341=== modified file 'src/location_service/com/ubuntu/location/provider.cpp'
342--- src/location_service/com/ubuntu/location/provider.cpp 2015-01-23 19:07:09 +0000
343+++ src/location_service/com/ubuntu/location/provider.cpp 2015-10-22 15:34:12 +0000
344@@ -16,9 +16,11 @@
345 * Authored by: Thomas Voß <thomas.voss@canonical.com>
346 */
347 #include <com/ubuntu/location/provider.h>
348+#include <com/ubuntu/location/logging.h>
349
350 #include <atomic>
351 #include <bitset>
352+#include <functional>
353 #include <memory>
354
355 namespace cul = com::ubuntu::location;
356@@ -51,12 +53,15 @@
357
358 void cul::Provider::Controller::start_position_updates()
359 {
360- if (position_updates_counter < 0)
361+ if (position_updates_counter < 0) {
362 return;
363+ }
364
365 if (++position_updates_counter == 1)
366 {
367- instance.start_position_updates();
368+ if (instance.boot_state() == BootState::BOOTED) {
369+ instance.start_position_updates();
370+ }
371 }
372 }
373
374@@ -67,7 +72,8 @@
375
376 if (--position_updates_counter == 0)
377 {
378- instance.stop_position_updates();
379+ if (instance.boot_state() == BootState::BOOTED)
380+ instance.stop_position_updates();
381 }
382 }
383
384@@ -83,7 +89,8 @@
385
386 if (++heading_updates_counter == 1)
387 {
388- instance.start_heading_updates();
389+ if (instance.boot_state() == BootState::BOOTED)
390+ instance.start_heading_updates();
391 }
392 }
393
394@@ -94,7 +101,8 @@
395
396 if (--heading_updates_counter == 0)
397 {
398- instance.stop_heading_updates();
399+ if (instance.boot_state() == BootState::BOOTED)
400+ instance.stop_heading_updates();
401 }
402 }
403
404@@ -110,7 +118,8 @@
405
406 if (++velocity_updates_counter == 1)
407 {
408- instance.start_velocity_updates();
409+ if (instance.boot_state() == BootState::BOOTED)
410+ instance.start_velocity_updates();
411 }
412 }
413
414@@ -121,7 +130,8 @@
415
416 if (--velocity_updates_counter == 0)
417 {
418- instance.stop_velocity_updates();
419+ if (instance.boot_state() == BootState::BOOTED)
420+ instance.stop_velocity_updates();
421 }
422 }
423
424@@ -130,12 +140,38 @@
425 return velocity_updates_counter > 0;
426 }
427
428+void cul::Provider::Controller::on_provider_booted(bool was_booted)
429+{
430+ if (!was_booted)
431+ return;
432+
433+ // we need to propagate the state of the provider using the internal counters as references
434+ if (position_updates_counter > 0) {
435+ instance.start_position_updates();
436+ }
437+ if (heading_updates_counter > 0) {
438+ instance.start_heading_updates();
439+ }
440+ if (velocity_updates_counter > 0) {
441+ instance.start_velocity_updates();
442+ }
443+}
444+
445 cul::Provider::Controller::Controller(cul::Provider& instance)
446 : instance(instance),
447 position_updates_counter(0),
448 heading_updates_counter(0),
449 velocity_updates_counter(0)
450-{
451+{
452+ using namespace std::placeholders;
453+
454+ if (instance.boot_state() != BootState::BOOTED) {
455+ // if the instance has not booted and is delayed we need to keep track of its booting state
456+ instance.booted_signal().connect(std::bind(&Controller::on_provider_booted, this, _1));
457+ if (instance.boot_state() != BootState::BOOTING) {
458+ instance.boot();
459+ }
460+ }
461 }
462
463 const cul::Provider::Controller::Ptr& cul::Provider::state_controller() const
464@@ -158,11 +194,28 @@
465 return false;
466 }
467
468+cul::Provider::BootState cul::Provider::boot_state() const
469+{
470+ return cul::Provider::BootState::BOOTED;
471+}
472+
473+void cul::Provider::boot() { }
474+
475 const cul::Provider::Updates& cul::Provider::updates() const
476 {
477 return d.updates;
478 }
479
480+core::Signal<bool>& cul::Provider::booted_signal()
481+{
482+ return d.signals.booted;
483+}
484+
485+const core::Signal<bool>& cul::Provider::booted_signal() const
486+{
487+ return d.signals.booted;
488+}
489+
490 cul::Provider::Provider(
491 const cul::Provider::Features& features,
492 const cul::Provider::Requirements& requirements)
493
494=== modified file 'tests/controller_test.cpp'
495--- tests/controller_test.cpp 2014-09-10 19:34:09 +0000
496+++ tests/controller_test.cpp 2015-10-22 15:34:12 +0000
497@@ -18,6 +18,7 @@
498 #include <com/ubuntu/location/provider.h>
499
500 #include "mock_provider.h"
501+#include "mock_delayed_provider.h"
502
503 #include <gmock/gmock.h>
504 #include <gtest/gtest.h>
505@@ -130,3 +131,215 @@
506 EXPECT_FALSE(controller->are_velocity_updates_running());
507 EXPECT_FALSE(controller->are_heading_updates_running());
508 }
509+
510+TEST(Controller, controller_resumes_state_after_boot) {
511+ using namespace ::testing;
512+ using ::testing::Mock;
513+
514+ MockDelayedProvider provider;
515+
516+ // ignore what ever was performed on construction
517+ Mock::VerifyAndClear(&provider);
518+
519+}
520+
521+TEST(Controller, controller_does_not_call_start_position_if_not_booted) {
522+ using namespace ::testing;
523+ using ::testing::Mock;
524+
525+ MockDelayedProvider provider;
526+
527+ // ignore what ever was performed on construction
528+ Mock::VerifyAndClear(&provider);
529+ // use a mock controller
530+ auto controller = provider.state_controller();
531+
532+ EXPECT_CALL(provider, boot_state()).Times(Exactly(1))
533+ .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED));
534+ EXPECT_CALL(provider, start_position_updates()).Times(Exactly(0));
535+
536+ controller->start_position_updates();
537+ controller->start_position_updates();
538+}
539+
540+TEST(Controller, controller_does_not_call_start_position_if_booting) {
541+ using namespace ::testing;
542+ using ::testing::Mock;
543+
544+ MockDelayedProvider provider;
545+
546+ // ignore what ever was performed on construction
547+ Mock::VerifyAndClear(&provider);
548+ // use a mock controller
549+ auto controller = provider.state_controller();
550+
551+ EXPECT_CALL(provider, boot_state()).Times(Exactly(1))
552+ .WillOnce(Return(cul::Provider::BootState::BOOTING));
553+ EXPECT_CALL(provider, start_position_updates()).Times(Exactly(0));
554+
555+ controller->start_position_updates();
556+}
557+
558+TEST(Controller, controller_does_not_call_start_heading_if_not_booted) {
559+ using namespace ::testing;
560+ using ::testing::Mock;
561+
562+ MockDelayedProvider provider;
563+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
564+
565+ // ignore what ever was performed on construction
566+ Mock::VerifyAndClear(&provider);
567+ // use a mock controller
568+ auto controller = provider.state_controller();
569+
570+ EXPECT_CALL(provider, boot_state()).Times(Exactly(1))
571+ .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED));
572+ EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0));
573+
574+ controller->start_heading_updates();
575+}
576+
577+TEST(Controller, controller_does_not_call_start_heading_if_booting) {
578+ using namespace ::testing;
579+ using ::testing::Mock;
580+
581+ MockDelayedProvider provider;
582+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
583+
584+ // ignore what ever was performed on construction
585+ Mock::VerifyAndClear(&provider);
586+ // use a mock controller
587+ auto controller = provider.state_controller();
588+
589+ EXPECT_CALL(provider, boot_state()).Times(Exactly(1))
590+ .WillOnce(Return(cul::Provider::BootState::BOOTING));
591+ EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0));
592+
593+ controller->start_heading_updates();
594+}
595+
596+TEST(Controller, controller_does_not_call_start_velocity_if_not_booted) {
597+ using namespace ::testing;
598+ using ::testing::Mock;
599+
600+ MockDelayedProvider provider;
601+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
602+
603+ // ignore what ever was performed on construction
604+ Mock::VerifyAndClear(&provider);
605+ // use a mock controller
606+ auto controller = provider.state_controller();
607+
608+ EXPECT_CALL(provider, boot_state()).Times(Exactly(1))
609+ .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED));
610+ EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0));
611+
612+ controller->start_velocity_updates();
613+}
614+
615+TEST(Controller, controller_does_not_call_start_velocity_if_booting) {
616+ using namespace ::testing;
617+ using ::testing::Mock;
618+
619+ MockDelayedProvider provider;
620+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
621+
622+ // ignore what ever was performed on construction
623+ Mock::VerifyAndClear(&provider);
624+ // use a mock controller
625+ auto controller = provider.state_controller();
626+
627+ EXPECT_CALL(provider, boot_state()).Times(Exactly(1))
628+ .WillOnce(Return(cul::Provider::BootState::BOOTING));
629+ EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(0));
630+
631+ controller->start_velocity_updates();
632+}
633+
634+TEST(Controller, controller_does_not_call_stop_position_if_not_booted) {
635+ using namespace ::testing;
636+ using ::testing::Mock;
637+
638+ MockDelayedProvider provider;
639+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
640+
641+ // ignore what ever was performed on construction
642+ Mock::VerifyAndClear(&provider);
643+ // use a mock controller
644+ auto controller = provider.state_controller();
645+
646+ EXPECT_CALL(provider, boot_state()).Times(Exactly(2))
647+ .WillOnce(Return(cul::Provider::BootState::BOOTED))
648+ .WillOnce(Return(cul::Provider::BootState::NOT_BOOTED));
649+ EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1));
650+ EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(0));
651+
652+ controller->start_position_updates();
653+ controller->stop_position_updates();
654+}
655+
656+TEST(Controller, controller_does_not_call_stop_position_if_booting) {
657+ using namespace ::testing;
658+ using ::testing::Mock;
659+
660+ MockDelayedProvider provider;
661+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
662+
663+ // ignore what ever was performed on construction
664+ Mock::VerifyAndClear(&provider);
665+ // use a mock controller
666+ auto controller = provider.state_controller();
667+
668+ EXPECT_CALL(provider, boot_state()).Times(Exactly(2))
669+ .WillOnce(Return(cul::Provider::BootState::BOOTED))
670+ .WillOnce(Return(cul::Provider::BootState::BOOTING));
671+ EXPECT_CALL(provider, start_position_updates()).Times(Exactly(1));
672+ EXPECT_CALL(provider, stop_position_updates()).Times(Exactly(0));
673+
674+ controller->start_position_updates();
675+ controller->stop_position_updates();
676+}
677+
678+TEST(Controller, controller_does_not_call_stop_heading_if_not_booted) {
679+ using namespace ::testing;
680+ using ::testing::Mock;
681+
682+ MockDelayedProvider provider;
683+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
684+
685+ // ignore what ever was performed on construction
686+ Mock::VerifyAndClear(&provider);
687+ // use a mock controller
688+ auto controller = provider.state_controller();
689+
690+ EXPECT_CALL(provider, boot_state()).Times(Exactly(2))
691+ .WillOnce(Return(cul::Provider::BootState::BOOTED))
692+ .WillOnce(Return(cul::Provider::BootState::BOOTING));
693+ EXPECT_CALL(provider, start_heading_updates()).Times(Exactly(1));
694+ EXPECT_CALL(provider, stop_heading_updates()).Times(Exactly(0));
695+
696+ controller->start_heading_updates();
697+ controller->stop_heading_updates();
698+}
699+
700+TEST(Controller, controller_does_not_call_stop_velocity_if_not_booted) {
701+ using namespace ::testing;
702+ using ::testing::Mock;
703+
704+ MockDelayedProvider provider;
705+ EXPECT_CALL(provider, has_delayed_boot()).WillRepeatedly(Return(true));
706+
707+ // ignore what ever was performed on construction
708+ Mock::VerifyAndClear(&provider);
709+ // use a mock controller
710+ auto controller = provider.state_controller();
711+
712+ EXPECT_CALL(provider, boot_state()).Times(Exactly(2))
713+ .WillOnce(Return(cul::Provider::BootState::BOOTED))
714+ .WillOnce(Return(cul::Provider::BootState::BOOTING));
715+ EXPECT_CALL(provider, start_velocity_updates()).Times(Exactly(1));
716+ EXPECT_CALL(provider, stop_velocity_updates()).Times(Exactly(0));
717+
718+ controller->start_velocity_updates();
719+ controller->stop_velocity_updates();
720+}
721
722=== added file 'tests/mock_delayed_provider.h'
723--- tests/mock_delayed_provider.h 1970-01-01 00:00:00 +0000
724+++ tests/mock_delayed_provider.h 2015-10-22 15:34:12 +0000
725@@ -0,0 +1,89 @@
726+/*
727+ * Copyright © 2014 Canonical Ltd.
728+ *
729+ * This program is free software: you can redistribute it and/or modify it
730+ * under the terms of the GNU Lesser General Public License version 3,
731+ * as published by the Free Software Foundation.
732+ *
733+ * This program is distributed in the hope that it will be useful,
734+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
735+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
736+ * GNU Lesser General Public License for more details.
737+ *
738+ * You should have received a copy of the GNU Lesser General Public License
739+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
740+ *
741+ * Authored by: M
742+ */
743+#ifndef MOCK_DELAYED_PROVIDER_H_
744+#define MOCK_DELAYED_PROVIDER_H_
745+
746+#include <com/ubuntu/location/provider.h>
747+#include <com/ubuntu/location/logging.h>
748+
749+#include <gmock/gmock.h>
750+
751+struct PublicController : public com::ubuntu::location::Provider::Controller
752+{
753+
754+ explicit PublicController(com::ubuntu::location::Provider& instance)
755+ : com::ubuntu::location::Provider::Controller(instance) {}
756+};
757+
758+struct MockDelayedProvider : public com::ubuntu::location::Provider
759+{
760+ MockDelayedProvider() : com::ubuntu::location::Provider()
761+ {
762+ }
763+
764+ MOCK_METHOD1(matches_criteria, bool(const com::ubuntu::location::Criteria&));
765+
766+ MOCK_CONST_METHOD1(supports, bool(const com::ubuntu::location::Provider::Features&));
767+ MOCK_CONST_METHOD1(requires, bool(const com::ubuntu::location::Provider::Requirements&));
768+
769+ // Called by the engine whenever the wifi and cell ID reporting state changes.
770+ MOCK_METHOD1(on_wifi_and_cell_reporting_state_changed, void(com::ubuntu::location::WifiAndCellIdReportingState state));
771+
772+ // Called by the engine whenever the reference location changed.
773+ MOCK_METHOD1(on_reference_location_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Position>& position));
774+
775+ // Called by the engine whenever the reference velocity changed.
776+ MOCK_METHOD1(on_reference_velocity_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& velocity));
777+
778+ // Called by the engine whenever the reference heading changed.
779+ MOCK_METHOD1(on_reference_heading_updated, void(const com::ubuntu::location::Update<com::ubuntu::location::Heading>& heading));
780+
781+ MOCK_METHOD0(start_position_updates, void());
782+ MOCK_METHOD0(stop_position_updates, void());
783+
784+ MOCK_METHOD0(start_heading_updates, void());
785+ MOCK_METHOD0(stop_heading_updates, void());
786+
787+ MOCK_METHOD0(start_velocity_updates, void());
788+ MOCK_METHOD0(stop_velocity_updates, void());
789+
790+ MOCK_CONST_METHOD0(has_delayed_boot, bool());
791+ MOCK_CONST_METHOD0(boot_state, BootState());
792+ MOCK_CONST_METHOD0(boot, void());
793+
794+
795+ // Inject a position update from the outside.
796+ void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Position>& update)
797+ {
798+ mutable_updates().position(update);
799+ }
800+
801+ // Inject a velocity update from the outside.
802+ void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Velocity>& update)
803+ {
804+ mutable_updates().velocity(update);
805+ }
806+
807+ // Inject a heading update from the outside.
808+ void inject_update(const com::ubuntu::location::Update<com::ubuntu::location::Heading>& update)
809+ {
810+ mutable_updates().heading(update);
811+ }
812+};
813+
814+#endif // MOCK_PROVIDER_H_

Subscribers

People subscribed via source and target branches