1
#include "com/ubuntu/location/provider.h"
2
#include "com/ubuntu/location/session.h"
4
#include <gmock/gmock.h>
5
#include <gtest/gtest.h>
9
struct MockProvider : public com::ubuntu::location::Provider
11
MOCK_METHOD1(subscribe_to_position_updates,
12
com::ubuntu::location::ChannelConnection(std::function<void(const com::ubuntu::location::Update<com::ubuntu::location::Position>&)>));
14
MOCK_METHOD1(subscribe_to_heading_updates,
15
com::ubuntu::location::ChannelConnection(std::function<void(const com::ubuntu::location::Update<com::ubuntu::location::Heading>&)>));
17
MOCK_METHOD1(subscribe_to_velocity_updates,
18
com::ubuntu::location::ChannelConnection(std::function<void(const com::ubuntu::location::Update<com::ubuntu::location::Velocity>&)>));
22
TEST(LocationSession, constructing_with_a_null_provider_throws)
24
EXPECT_ANY_THROW(com::ubuntu::location::Session session(com::ubuntu::location::Provider::Ptr {}));
27
TEST(LocationSession, changing_provider_association_of_session_results_in_connections_to_new_provider)
29
using namespace ::testing;
30
NiceMock<MockProvider> mock_provider1;
31
ON_CALL(mock_provider1, subscribe_to_position_updates(_))
32
.WillByDefault(Return(com::ubuntu::location::ChannelConnection()));
33
ON_CALL(mock_provider1, subscribe_to_heading_updates(_))
34
.WillByDefault(Return(com::ubuntu::location::ChannelConnection()));
35
ON_CALL(mock_provider1, subscribe_to_velocity_updates(_))
36
.WillByDefault(Return(com::ubuntu::location::ChannelConnection()));
38
NiceMock<MockProvider> mock_provider2;
39
EXPECT_CALL(mock_provider2, subscribe_to_position_updates(_))
40
.WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
41
EXPECT_CALL(mock_provider2, subscribe_to_heading_updates(_))
42
.WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
43
EXPECT_CALL(mock_provider2, subscribe_to_velocity_updates(_))
44
.WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
46
com::ubuntu::location::Session session(com::ubuntu::location::Provider::Ptr {&mock_provider1, [](com::ubuntu::location::Provider*) {}});
47
session.change_provider_assocation_to(com::ubuntu::location::Provider::Ptr {&mock_provider2, [](com::ubuntu::location::Provider*) {}});
50
TEST(LocationSession, installing_updates_handlers_connects_them_to_the_provider_associated_to_the_session)
52
using namespace ::testing;
54
NiceMock<MockProvider> mock_provider;
56
EXPECT_CALL(mock_provider, subscribe_to_position_updates(_))
58
.WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
59
EXPECT_CALL(mock_provider, subscribe_to_heading_updates(_))
61
.WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
62
EXPECT_CALL(mock_provider, subscribe_to_velocity_updates(_))
64
.WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
66
com::ubuntu::location::Session session(com::ubuntu::location::Provider::Ptr {&mock_provider, [](com::ubuntu::location::Provider*) {}});
68
session.install_position_updates_handler([](const com::ubuntu::location::Update<com::ubuntu::location::Position>&)
71
session.install_heading_updates_handler([](const com::ubuntu::location::Update<com::ubuntu::location::Heading>&)
74
session.install_velocity_updates_handler([](const com::ubuntu::location::Update<com::ubuntu::location::Velocity>&)