1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*
* Copyright © 2012-2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Thomas Voß <thomas.voss@canonical.com>
*/
#include <com/ubuntu/location/provider.h>
#include <com/ubuntu/location/session.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
namespace
{
struct MockProvider : public core::location::Provider
{
MOCK_METHOD1(subscribe_to_position_updates,
core::location::ChannelConnection(std::function<void(const core::location::Update<core::location::Position>&)>));
MOCK_METHOD1(subscribe_to_heading_updates,
core::location::ChannelConnection(std::function<void(const core::location::Update<core::location::Heading>&)>));
MOCK_METHOD1(subscribe_to_velocity_updates,
core::location::ChannelConnection(std::function<void(const core::location::Update<core::location::Velocity>&)>));
};
}
TEST(LocationSession, constructing_with_a_null_provider_throws)
{
EXPECT_ANY_THROW(core::location::Session session(core::location::Provider::Ptr {}));
}
TEST(LocationSession, changing_provider_association_of_session_results_in_connections_to_new_provider)
{
using namespace ::testing;
NiceMock<MockProvider> mock_provider1;
ON_CALL(mock_provider1, subscribe_to_position_updates(_))
.WillByDefault(Return(core::location::ChannelConnection()));
ON_CALL(mock_provider1, subscribe_to_heading_updates(_))
.WillByDefault(Return(core::location::ChannelConnection()));
ON_CALL(mock_provider1, subscribe_to_velocity_updates(_))
.WillByDefault(Return(core::location::ChannelConnection()));
NiceMock<MockProvider> mock_provider2;
EXPECT_CALL(mock_provider2, subscribe_to_position_updates(_))
.WillRepeatedly(Return(core::location::ChannelConnection()));
EXPECT_CALL(mock_provider2, subscribe_to_heading_updates(_))
.WillRepeatedly(Return(core::location::ChannelConnection()));
EXPECT_CALL(mock_provider2, subscribe_to_velocity_updates(_))
.WillRepeatedly(Return(core::location::ChannelConnection()));
core::location::Session session(core::location::Provider::Ptr {&mock_provider1, [](core::location::Provider*) {}});
session.change_provider_assocation_to(core::location::Provider::Ptr {&mock_provider2, [](core::location::Provider*) {}});
}
TEST(LocationSession, installing_updates_handlers_connects_them_to_the_provider_associated_to_the_session)
{
using namespace ::testing;
NiceMock<MockProvider> mock_provider;
EXPECT_CALL(mock_provider, subscribe_to_position_updates(_))
.Times(1)
.WillRepeatedly(Return(core::location::ChannelConnection()));
EXPECT_CALL(mock_provider, subscribe_to_heading_updates(_))
.Times(1)
.WillRepeatedly(Return(core::location::ChannelConnection()));
EXPECT_CALL(mock_provider, subscribe_to_velocity_updates(_))
.Times(1)
.WillRepeatedly(Return(core::location::ChannelConnection()));
core::location::Session session(core::location::Provider::Ptr {&mock_provider, [](core::location::Provider*) {}});
session.install_position_updates_handler([](const core::location::Update<core::location::Position>&)
{
});
session.install_heading_updates_handler([](const core::location::Update<core::location::Heading>&)
{
});
session.install_velocity_updates_handler([](const core::location::Update<core::location::Velocity>&)
{
});
}
|