Merge lp:~mandel/location-service/espoo-provider into lp:location-service/trunk

Proposed by Manuel de la Peña
Status: Merged
Approved by: Thomas Voß
Approved revision: 107
Merged at revision: 100
Proposed branch: lp:~mandel/location-service/espoo-provider
Merge into: lp:location-service/trunk
Diff against target: 608 lines (+526/-3)
11 files modified
data/ubuntu-location-service.conf.in (+1/-1)
debian/changelog (+6/-0)
src/location_service/com/ubuntu/location/providers/CMakeLists.txt (+1/-0)
src/location_service/com/ubuntu/location/providers/config.cpp (+8/-0)
src/location_service/com/ubuntu/location/providers/geoclue/CMakeLists.txt (+2/-2)
src/location_service/com/ubuntu/location/providers/remote/CMakeLists.txt (+37/-0)
src/location_service/com/ubuntu/location/providers/remote/provider.cpp (+159/-0)
src/location_service/com/ubuntu/location/providers/remote/provider.h (+84/-0)
src/location_service/com/ubuntu/location/providers/remote/remote_interface.h (+108/-0)
tests/CMakeLists.txt (+21/-0)
tests/remote_provider_test.cpp (+99/-0)
To merge this branch: bzr merge lp:~mandel/location-service/espoo-provider
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Thomas Voß (community) Approve
Review via email: mp+231523@code.launchpad.net

Commit message

Add a new provider that uses the espoo project.

Description of the change

Add a new provided that will use the espoo service. The espoo service provides position updates via dbus signals.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Thomas Voß (thomas-voss) wrote :

Thanks for the changes. I added some niggles inline. However, the most important bit is the lack of tests being associated to this MP. I would expect at least a setup with a mocked remote provider that the location service with an instance of the espoo provider connects to.

One other thing: I don't think espoo is the correct name for the provider going forward and I would propose renaming it to something like Remote- or OutOfProcessProvider.

review: Needs Fixing
99. By Manuel de la Peña

Clean up code to make it more generic.

100. By Manuel de la Peña

Added extra tests and remove as much metions as possible of the espoo project. More will come once the espoo project is updated.

Revision history for this message
Ricardo Mendoza (ricmm) wrote :

Typo in method definition

101. By Manuel de la Peña

Remove small typo.

Revision history for this message
Manuel de la Peña (mandel) :
102. By Manuel de la Peña

Use the correct author.

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) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Thomas Voß (thomas-voss) wrote :

Minor niggles, and a big reminder in the very end.

review: Needs Fixing
103. By Manuel de la Peña

Make method public and then remove the need of the helper DummyProvider class.

104. By Manuel de la Peña

Changes according to the peer review.

105. By Manuel de la Peña

Changes aggording to peer review.

106. By Manuel de la Peña

Merged with trunk.

107. By Manuel de la Peña

Do not use dbus-test-runner.

Revision history for this message
Thomas Voß (thomas-voss) wrote :

LGTM, but let's wait for Jenkins until we top-approve.

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

The Jenkins test failure on armhf is a flaky one. Both amd64 and i386 pass cleanly.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'data/ubuntu-location-service.conf.in'
2--- data/ubuntu-location-service.conf.in 2013-10-15 16:02:00 +0000
3+++ data/ubuntu-location-service.conf.in 2014-08-26 16:04:21 +0000
4@@ -4,4 +4,4 @@
5
6 respawn
7
8-exec /usr/bin/ubuntu-location-serviced --bus system --provider gps::Provider
9+exec /usr/bin/ubuntu-location-serviced --bus system --provider gps::Provider --provider remote::Provider --remote::Provider::name="com.ubuntu.espoo.Service.Provider" --remote::Provider::path="/com/ubuntu/espoo/Service/Provider"
10
11=== modified file 'debian/changelog'
12--- debian/changelog 2014-08-25 09:14:46 +0000
13+++ debian/changelog 2014-08-26 16:04:21 +0000
14@@ -1,3 +1,9 @@
15+location-service (2.1) UNRELEASED; urgency=medium
16+
17+ * Add a new provider for the remote project.
18+
19+ -- Manuel de la Pena <manuel.delapena@canonical.com> Tue, 19 Aug 2014 11:54:49 +0000
20+
21 location-service (2.0.1+14.10.20140825-0ubuntu1) utopic; urgency=low
22
23 [ thomas-voss ]
24
25=== modified file 'src/location_service/com/ubuntu/location/providers/CMakeLists.txt'
26--- src/location_service/com/ubuntu/location/providers/CMakeLists.txt 2014-02-07 17:16:49 +0000
27+++ src/location_service/com/ubuntu/location/providers/CMakeLists.txt 2014-08-26 16:04:21 +0000
28@@ -1,4 +1,5 @@
29 add_subdirectory(dummy)
30+add_subdirectory(remote)
31 add_subdirectory(geoclue)
32 add_subdirectory(gps)
33 add_subdirectory(skyhook)
34
35=== modified file 'src/location_service/com/ubuntu/location/providers/config.cpp'
36--- src/location_service/com/ubuntu/location/providers/config.cpp 2014-05-19 09:55:25 +0000
37+++ src/location_service/com/ubuntu/location/providers/config.cpp 2014-08-26 16:04:21 +0000
38@@ -68,3 +68,11 @@
39 };
40 #endif // COM_UBUNTU_LOCATION_SERVICE_PROVIDERS_SKYHOOK
41
42+#if defined(COM_UBUNTU_LOCATION_SERVICE_PROVIDERS_REMOTE)
43+#include <com/ubuntu/location/providers/remote/provider.h>
44+static FactoryInjector remote_injector
45+{
46+ "remote::Provider",
47+ com::ubuntu::location::providers::remote::Provider::create_instance
48+};
49+#endif // COM_UBUNTU_LOCATION_SERVICE_PROVIDERS_REMOTE
50
51=== modified file 'src/location_service/com/ubuntu/location/providers/geoclue/CMakeLists.txt'
52--- src/location_service/com/ubuntu/location/providers/geoclue/CMakeLists.txt 2014-01-20 13:03:19 +0000
53+++ src/location_service/com/ubuntu/location/providers/geoclue/CMakeLists.txt 2014-08-26 16:04:21 +0000
54@@ -9,10 +9,10 @@
55 message(STATUS "Enabling support for Geoclue location providers")
56
57 add_library(geoclue provider.cpp)
58-
59+
60 set(
61 ENABLED_PROVIDER_TARGETS
62- ${ENABLED_PROVIDER_TARGETS} geoclue
63+ ${ENABLED_PROVIDER_TARGETS} geoclue
64 PARENT_SCOPE
65 )
66
67
68=== added directory 'src/location_service/com/ubuntu/location/providers/remote'
69=== added file 'src/location_service/com/ubuntu/location/providers/remote/CMakeLists.txt'
70--- src/location_service/com/ubuntu/location/providers/remote/CMakeLists.txt 1970-01-01 00:00:00 +0000
71+++ src/location_service/com/ubuntu/location/providers/remote/CMakeLists.txt 2014-08-26 16:04:21 +0000
72@@ -0,0 +1,37 @@
73+option(
74+ LOCATION_SERVICE_ENABLE_REMOTE_PROVIDER
75+ "Enable location provider relying on the remote provider SDK"
76+ ON
77+)
78+
79+if (LOCATION_SERVICE_ENABLE_REMOTE_PROVIDER)
80+
81+ message(STATUS "Enabling support for the remote location providers")
82+
83+ set(REMOTE_SOURCES
84+ provider.cpp
85+ )
86+
87+ set(REMOTE_HEADERS
88+ remote_interface.h
89+ provider.h
90+ )
91+
92+ add_library(remote
93+ ${REMOTE_HEADERS}
94+ ${REMOTE_SOURCES}
95+ )
96+
97+ set(
98+ ENABLED_PROVIDER_TARGETS
99+ ${ENABLED_PROVIDER_TARGETS} remote
100+ PARENT_SCOPE
101+ )
102+
103+ set(
104+ ENABLED_PROVIDER_TARGETS_DEFINITIONS
105+ -DCOM_UBUNTU_LOCATION_SERVICE_PROVIDERS_REMOTE ${ENABLED_PROVIDER_TARGETS_DEFINITIONS}
106+ PARENT_SCOPE
107+ )
108+
109+endif (LOCATION_SERVICE_ENABLE_REMOTE_PROVIDER)
110
111=== added file 'src/location_service/com/ubuntu/location/providers/remote/provider.cpp'
112--- src/location_service/com/ubuntu/location/providers/remote/provider.cpp 1970-01-01 00:00:00 +0000
113+++ src/location_service/com/ubuntu/location/providers/remote/provider.cpp 2014-08-26 16:04:21 +0000
114@@ -0,0 +1,159 @@
115+/*
116+ * Copyright © 2012-2013 Canonical Ltd.
117+ *
118+ * This program is free software: you can redistribute it and/or modify it
119+ * under the terms of the GNU Lesser General Public License version 3,
120+ * as published by the Free Software Foundation.
121+ *
122+ * This program is distributed in the hope that it will be useful,
123+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
124+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
125+ * GNU Lesser General Public License for more details.
126+ *
127+ * You should have received a copy of the GNU Lesser General Public License
128+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
129+ *
130+ * Authored by: Manuel de la Peña <manuel.delapena@canonical.com>
131+ */
132+#include <com/ubuntu/location/providers/remote/provider.h>
133+
134+#include <com/ubuntu/location/logging.h>
135+
136+#include <core/dbus/object.h>
137+#include <core/dbus/signal.h>
138+#include <core/dbus/asio/executor.h>
139+
140+#include <thread>
141+
142+namespace cul = com::ubuntu::location;
143+namespace culpr = com::ubuntu::location::providers::remote;
144+
145+namespace dbus = core::dbus;
146+
147+namespace
148+{
149+dbus::Bus::Ptr the_system_bus()
150+{
151+ dbus::Bus::Ptr system_bus = std::make_shared<dbus::Bus>(dbus::WellKnownBus::system);
152+ system_bus->install_executor(core::dbus::asio::make_executor(system_bus));
153+ return system_bus;
154+}
155+}
156+
157+struct culpr::Provider::Private
158+{
159+ typedef core::dbus::Signal<
160+ com::ubuntu::remote::RemoteInterface::Signals::PositionChanged,
161+ com::ubuntu::remote::RemoteInterface::Signals::PositionChanged::ArgumentType
162+ > PositionChanged;
163+
164+ Private(const culpr::Provider::Configuration& config)
165+ : bus(config.connection),
166+ service(dbus::Service::use_service(bus, config.name)),
167+ object(service->object_for_path(config.path)),
168+ signal_position_changed(object->get_signal<com::ubuntu::remote::RemoteInterface::Signals::PositionChanged>())
169+ {
170+ }
171+
172+ void start()
173+ {
174+ VLOG(10) << __PRETTY_FUNCTION__;
175+ if (!worker.joinable())
176+ worker = std::move(std::thread{std::bind(&dbus::Bus::run, bus)});
177+ }
178+
179+ void stop()
180+ {
181+ VLOG(10) << __PRETTY_FUNCTION__;
182+ try
183+ {
184+ bus->stop();
185+ }
186+ catch(...)
187+ {
188+ // can happen if the start method was not called
189+ VLOG(10) << "Stopping not started remote provider.";
190+ }
191+
192+ if (worker.joinable())
193+ worker.join();
194+ }
195+
196+ dbus::Bus::Ptr bus;
197+ dbus::Service::Ptr service;
198+ dbus::Object::Ptr object;
199+ PositionChanged::Ptr signal_position_changed;
200+ PositionChanged::SubscriptionToken position_updates_connection;
201+
202+ std::thread worker;
203+};
204+
205+std::string culpr::Provider::class_name()
206+{
207+ return "remote::Provider";
208+}
209+
210+cul::Provider::Ptr culpr::Provider::create_instance(const cul::ProviderFactory::Configuration& config)
211+{
212+ culpr::Provider::Configuration pConfig;
213+ pConfig.name = config.count(Configuration::key_name()) > 0 ? config.get<std::string>(Configuration::key_name()) : throw std::runtime_error("Missing bus-name");
214+ pConfig.path = config.count(Configuration::key_path()) > 0 ? config.get<std::string>(Configuration::key_path()) : throw std::runtime_error("Missing bus-path");
215+
216+ pConfig.connection = the_system_bus();
217+
218+ return cul::Provider::Ptr{new culpr::Provider{pConfig}};
219+}
220+
221+culpr::Provider::Provider(const culpr::Provider::Configuration& config)
222+ : com::ubuntu::location::Provider(config.features, config.requirements),
223+ d(new Private(config))
224+{
225+ d->position_updates_connection =
226+ d->signal_position_changed->connect(
227+ [this](const com::ubuntu::remote::RemoteInterface::Signals::PositionChanged::ArgumentType& arg)
228+ {
229+ this->on_position_changed(arg);
230+ });
231+}
232+
233+culpr::Provider::~Provider() noexcept
234+{
235+ d->stop();
236+}
237+
238+void culpr::Provider::on_position_changed(const com::ubuntu::remote::RemoteInterface::Signals::PositionChanged::ArgumentType& arg)
239+{
240+ auto longitude = std::get<0>(arg);
241+ auto latitude = std::get<1>(arg);
242+ auto altitude = std::get<2>(arg);
243+ VLOG(10) << "New update received with longitude: " << longitude
244+ << "latitude: " << latitude << "altitude: " << altitude;
245+
246+ cul::Position pos
247+ {
248+ cul::wgs84::Latitude{latitude* cul::units::Degrees},
249+ cul::wgs84::Longitude{longitude* cul::units::Degrees}
250+ };
251+
252+ pos.altitude = cul::wgs84::Altitude{altitude* cul::units::Meters};
253+ cul::Update<cul::Position> update(pos);
254+ VLOG(10) << "Position updated added";
255+ mutable_updates().position(update);
256+}
257+
258+bool culpr::Provider::matches_criteria(const cul::Criteria&)
259+{
260+ return true;
261+}
262+
263+void culpr::Provider::start_position_updates()
264+{
265+ VLOG(10) << "Starting remote provider\n";
266+ d->start();
267+}
268+
269+void culpr::Provider::stop_position_updates()
270+{
271+ VLOG(10) << "Stopping remote provider\n";
272+ d->stop();
273+}
274
275=== added file 'src/location_service/com/ubuntu/location/providers/remote/provider.h'
276--- src/location_service/com/ubuntu/location/providers/remote/provider.h 1970-01-01 00:00:00 +0000
277+++ src/location_service/com/ubuntu/location/providers/remote/provider.h 2014-08-26 16:04:21 +0000
278@@ -0,0 +1,84 @@
279+/*
280+ * Copyright © 2012-2013 Canonical Ltd.
281+ *
282+ * This program is free software: you can redistribute it and/or modify it
283+ * under the terms of the GNU Lesser General Public License version 3,
284+ * as published by the Free Software Foundation.
285+ *
286+ * This program is distributed in the hope that it will be useful,
287+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
288+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
289+ * GNU Lesser General Public License for more details.
290+ *
291+ * You should have received a copy of the GNU Lesser General Public License
292+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
293+ *
294+ * Authored by: Manuel de la Peña <manuel.delapena@canonical.com>
295+ */
296+#ifndef LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDERS_ESPOO_PROVIDER_H_
297+#define LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDERS_ESPOO_PROVIDER_H_
298+
299+#include <com/ubuntu/location/provider.h>
300+#include <com/ubuntu/location/provider_factory.h>
301+#include <com/ubuntu/location/providers/remote/remote_interface.h>
302+
303+#include <core/dbus/bus.h>
304+
305+namespace com
306+{
307+namespace ubuntu
308+{
309+namespace location
310+{
311+namespace providers
312+{
313+namespace remote
314+{
315+
316+class Provider : public com::ubuntu::location::Provider
317+{
318+ public:
319+ // For integration with the Provider factory.
320+ static std::string class_name();
321+
322+ // Instantiates a new provider instance, populating the configuration object
323+ // from the provided property bundle.
324+ static Provider::Ptr create_instance(const ProviderFactory::Configuration&);
325+
326+ // structure that represents the configuration used in the remote provider
327+ struct Configuration
328+ {
329+ static std::string key_name() { return "name"; }
330+ static std::string key_path() { return "path"; }
331+
332+ std::string name;
333+ std::string path;
334+
335+ core::dbus::Bus::Ptr connection;
336+
337+ Provider::Features features = Provider::Features::position;
338+ Provider::Requirements requirements = Provider::Requirements::cell_network |
339+ Provider::Requirements::data_network | Provider::Requirements::monetary_spending;
340+ };
341+
342+ Provider(const Configuration& config);
343+ ~Provider() noexcept;
344+
345+ virtual bool matches_criteria(const Criteria&);
346+
347+ virtual void start_position_updates();
348+ virtual void stop_position_updates();
349+
350+ void on_position_changed(const com::ubuntu::remote::RemoteInterface::Signals::PositionChanged::ArgumentType& arg);
351+
352+ private:
353+ struct Private;
354+ std::unique_ptr<Private> d;
355+};
356+
357+} // remote
358+} // providers
359+} // location
360+} // ubuntu
361+} // com
362+#endif // LOCATION_SERVICE_COM_UBUNTU_LOCATION_PROVIDERS_GEOCLUE_PROVIDER_H_
363
364=== added file 'src/location_service/com/ubuntu/location/providers/remote/remote_interface.h'
365--- src/location_service/com/ubuntu/location/providers/remote/remote_interface.h 1970-01-01 00:00:00 +0000
366+++ src/location_service/com/ubuntu/location/providers/remote/remote_interface.h 2014-08-26 16:04:21 +0000
367@@ -0,0 +1,108 @@
368+/*
369+ * Copyright © 2014 Canonical Ltd.
370+ *
371+ * This program is free software: you can redistribute it and/or modify it
372+ * under the terms of the GNU Lesser General Public License version 3,
373+ * as published by the Free Software Foundation.
374+ *
375+ * This program is distributed in the hope that it will be useful,
376+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
377+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
378+ * GNU Lesser General Public License for more details.
379+ *
380+ * You should have received a copy of the GNU Lesser General Public License
381+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
382+ *
383+ * Authored by: Manuel de la Pena <manuel.delapena@canonical.com>
384+ */
385+
386+#ifndef CORE_UBUNTU_ESPOO_PROVIDER_P_H_
387+#define CORE_UBUNTU_ESPOO_PROVIDER_P_H_
388+
389+#include <core/dbus/macros.h>
390+#include <core/dbus/traits/service.h>
391+
392+namespace com
393+{
394+namespace ubuntu
395+{
396+namespace remote
397+{
398+struct RemoteInterface
399+{
400+
401+ static const std::string& name()
402+ {
403+ static const std::string s{"com.ubuntu.remote.Service.Provider"};
404+ return s;
405+ }
406+
407+ DBUS_CPP_METHOD_DEF(StartPositionUpdates, RemoteInterface)
408+ DBUS_CPP_METHOD_DEF(StopPositionUpdates, RemoteInterface)
409+ DBUS_CPP_METHOD_DEF(StartHeadingUpdates, RemoteInterface)
410+ DBUS_CPP_METHOD_DEF(StopHeadingUpdates, RemoteInterface)
411+ DBUS_CPP_METHOD_DEF(StartVelocityUpdates, RemoteInterface)
412+ DBUS_CPP_METHOD_DEF(StopVelocityUpdates, RemoteInterface)
413+
414+ struct Signals
415+ {
416+ struct PositionChanged
417+ {
418+ inline static std::string name()
419+ {
420+ return "PositionChanged";
421+ };
422+ typedef RemoteInterface Interface;
423+ typedef std::tuple<double, double, double, double, uint32_t> ArgumentType;
424+ };
425+
426+ DBUS_CPP_SIGNAL_DEF(HeadingChanged, RemoteInterface, double)
427+ DBUS_CPP_SIGNAL_DEF(VelocityChanged, RemoteInterface, double)
428+ };
429+
430+ struct Properties
431+ {
432+ DBUS_CPP_READABLE_PROPERTY_DEF(HasPosition, RemoteInterface, bool)
433+ DBUS_CPP_READABLE_PROPERTY_DEF(HasVelocity, RemoteInterface, bool)
434+ DBUS_CPP_READABLE_PROPERTY_DEF(HasHeading, RemoteInterface, bool)
435+ DBUS_CPP_READABLE_PROPERTY_DEF(RequiresSatellites, RemoteInterface, bool)
436+ DBUS_CPP_READABLE_PROPERTY_DEF(RequiresCellNetwork, RemoteInterface, bool)
437+ DBUS_CPP_READABLE_PROPERTY_DEF(RequiresDataNetwork, RemoteInterface, bool)
438+ DBUS_CPP_READABLE_PROPERTY_DEF(RequiresMonetarySpending, RemoteInterface, bool)
439+ DBUS_CPP_READABLE_PROPERTY_DEF(ArePositionUpdatesRunning, RemoteInterface, bool)
440+ DBUS_CPP_READABLE_PROPERTY_DEF(AreHeadingUpdatesRunning, RemoteInterface, bool)
441+ DBUS_CPP_READABLE_PROPERTY_DEF(AreVelocityUpdatesRunning, RemoteInterface, bool)
442+ };
443+
444+};
445+} // remote
446+} // ubuntu
447+} // core
448+
449+namespace core
450+{
451+namespace dbus
452+{
453+namespace traits
454+{
455+template<>
456+struct Service<com::ubuntu::remote::RemoteInterface>
457+{
458+ static const std::string& interface_name()
459+ {
460+ static const std::string s{"com.ubuntu.espoo.Service.Provider"};
461+ return s;
462+ }
463+
464+ inline static const std::string& object_path()
465+ {
466+ static const std::string s{"/com/ubuntu/espoo/Service/Provider"};
467+ return s;
468+ }
469+
470+};
471+}
472+}
473+}
474+
475+#endif
476
477=== modified file 'tests/CMakeLists.txt'
478--- tests/CMakeLists.txt 2014-08-13 13:08:22 +0000
479+++ tests/CMakeLists.txt 2014-08-26 16:04:21 +0000
480@@ -116,3 +116,24 @@
481 add_test(geoclue_provider_test ${CMAKE_CURRENT_BINARY_DIR}/geoclue_provider_test)
482 endif (LOCATION_SERVICE_ENABLE_DBUS_TEST_RUNNER)
483 endif (LOCATION_SERVICE_ENABLE_GEOCLUE_PROVIDERS)
484+
485+if (LOCATION_SERVICE_ENABLE_REMOTE_PROVIDER)
486+ add_executable(remote_provider_test remote_provider_test.cpp)
487+ target_link_libraries(
488+ remote_provider_test
489+
490+ ubuntu-location-service
491+
492+ ${CMAKE_THREAD_LIBS_INIT}
493+ ${Boost_LIBRARIES}
494+ ${PROCESS_CPP_LIBRARIES}
495+ ${ARGN}
496+
497+ gmock
498+
499+ gtest
500+ gtest_main
501+ )
502+
503+ add_test(remote_provider_test ${CMAKE_CURRENT_BINARY_DIR}/remote_provider_test)
504+endif (LOCATION_SERVICE_ENABLE_REMOTE_PROVIDER)
505
506=== added file 'tests/remote_provider_test.cpp'
507--- tests/remote_provider_test.cpp 1970-01-01 00:00:00 +0000
508+++ tests/remote_provider_test.cpp 2014-08-26 16:04:21 +0000
509@@ -0,0 +1,99 @@
510+/*
511+ * Copyright © 2012-2013 Canonical Ltd.
512+ *
513+ * This program is free software: you can redistribute it and/or modify it
514+ * under the terms of the GNU Lesser General Public License version 3,
515+ * as published by the Free Software Foundation.
516+ *
517+ * This program is distributed in the hope that it will be useful,
518+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
519+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
520+ * GNU Lesser General Public License for more details.
521+ *
522+ * You should have received a copy of the GNU Lesser General Public License
523+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
524+ *
525+ * Authored by: Manuel de la Peña <manuel.delapena@canonical.com>
526+ */
527+
528+#include <com/ubuntu/location/provider.h>
529+#include <com/ubuntu/location/proxy_provider.h>
530+#include <com/ubuntu/location/providers/remote/provider.h>
531+
532+#include <core/dbus/fixture.h>
533+
534+#include <gmock/gmock.h>
535+#include <gtest/gtest.h>
536+
537+namespace cul = com::ubuntu::location;
538+namespace remote = com::ubuntu::location::providers::remote;
539+
540+using namespace ::testing;
541+
542+
543+MATCHER_P(postion_equals_tuple, value, "Returns if the string maps are equal.") {
544+ auto pos = arg.value;
545+
546+ // convert the tuple to the correct units
547+ cul::wgs84::Longitude longitude {std::get<0>(value)* cul::units::Degrees};
548+ cul::wgs84::Latitude latitude {std::get<1>(value)* cul::units::Degrees};
549+ cul::wgs84::Altitude altitude {std::get<2>(value)* cul::units::Meters};
550+
551+ return longitude == pos.longitude && latitude == pos.latitude && altitude == pos.altitude;
552+}
553+
554+namespace
555+{
556+struct RemoteProvider : public core::dbus::testing::Fixture
557+{
558+
559+};
560+
561+class MockEventConsumer
562+{
563+ public:
564+ MockEventConsumer() {}
565+
566+ MOCK_METHOD1(on_new_position, void(const cul::Update<cul::Position>&));
567+};
568+}
569+TEST_F(RemoteProvider, matches_criteria)
570+{
571+ auto conf = remote::Provider::Configuration{};
572+ conf.name = "com.ubuntu.espoo.Service.Provider";
573+ conf.path = "/com/ubuntu/espoo/Service/Provider";
574+ conf.connection = session_bus();
575+ remote::Provider provider(conf);
576+
577+ EXPECT_FALSE(provider.requires(com::ubuntu::location::Provider::Requirements::satellites));
578+ EXPECT_TRUE(provider.requires(com::ubuntu::location::Provider::Requirements::cell_network));
579+ EXPECT_TRUE(provider.requires(com::ubuntu::location::Provider::Requirements::data_network));
580+ EXPECT_TRUE(provider.requires(com::ubuntu::location::Provider::Requirements::monetary_spending));
581+}
582+
583+TEST_F(RemoteProvider, updates_are_fwd)
584+{
585+ // update received from the remote provider in a tuple
586+ std::tuple<double, double, double, double, uint32_t> update{3, 4, 4, 4, 0};
587+
588+ auto conf = remote::Provider::Configuration{};
589+ conf.name = "com.ubuntu.espoo.Service.Provider";
590+ conf.path = "/com/ubuntu/espoo/Service/Provider";
591+ conf.connection = session_bus();
592+
593+ remote::Provider provider{conf};
594+
595+ cul::Provider::Ptr p1{std::addressof(provider), [](cul::Provider*){}};
596+
597+ cul::ProviderSelection selection{p1, p1, p1};
598+
599+ cul::ProxyProvider pp{selection};
600+
601+ MockEventConsumer mec;
602+ EXPECT_CALL(mec, on_new_position(postion_equals_tuple(update))).Times(1);
603+
604+ pp.updates().position.connect([&mec](const cul::Update<cul::Position>& p){mec.on_new_position(p);});
605+
606+ // create an update to be processed
607+ provider.on_position_changed(update);
608+}

Subscribers

People subscribed via source and target branches