2
* Copyright © 2016 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
19
#include <com/ubuntu/location/state_tracking_provider.h>
21
#include <com/ubuntu/location/clock.h>
22
#include <com/ubuntu/location/update.h>
23
#include <com/ubuntu/location/position.h>
24
#include <com/ubuntu/location/units/units.h>
25
#include <com/ubuntu/location/wgs84/latitude.h>
26
#include <com/ubuntu/location/wgs84/longitude.h>
27
#include <com/ubuntu/location/wgs84/altitude.h>
29
#include "mock_provider.h"
31
#include <gtest/gtest.h>
33
namespace cul = com::ubuntu::location;
37
auto timestamp = cul::Clock::now();
39
// Create reference objects for injecting and validating updates.
40
cul::Update<cul::Position> reference_position_update
43
cul::wgs84::Latitude{9. * cul::units::Degrees},
44
cul::wgs84::Longitude{53. * cul::units::Degrees},
45
cul::wgs84::Altitude{-2. * cul::units::Meters}
50
cul::Update<cul::Velocity> reference_velocity_update
52
{5. * cul::units::MetersPerSecond},
56
cul::Update<cul::Heading> reference_heading_update
58
{120. * cul::units::Degrees},
62
TEST(StateTrackingProviderTest, forwards_calls_to_impl)
64
using namespace testing;
66
auto impl = std::make_shared<MockProvider>();
67
EXPECT_CALL(*impl, supports(_)).Times(1).WillOnce(Return(true));
68
EXPECT_CALL(*impl, requires(_)).Times(1).WillOnce(Return(false));
69
EXPECT_CALL(*impl, matches_criteria(_)).Times(1).WillOnce(Return(false));
70
EXPECT_CALL(*impl, on_wifi_and_cell_reporting_state_changed(_)).Times(1);
71
EXPECT_CALL(*impl, on_reference_location_updated(_)).Times(1);
72
EXPECT_CALL(*impl, on_reference_velocity_updated(_)).Times(1);
73
EXPECT_CALL(*impl, on_reference_heading_updated(_)).Times(1);
74
EXPECT_CALL(*impl, start_position_updates()).Times(1);
75
EXPECT_CALL(*impl, stop_position_updates()).Times(1);
76
EXPECT_CALL(*impl, start_velocity_updates()).Times(1);
77
EXPECT_CALL(*impl, stop_velocity_updates()).Times(1);
78
EXPECT_CALL(*impl, start_heading_updates()).Times(1);
79
EXPECT_CALL(*impl, stop_heading_updates()).Times(1);
81
com::ubuntu::location::StateTrackingProvider stp{impl};
82
EXPECT_TRUE(stp.supports(com::ubuntu::location::Provider::Features::none));
83
EXPECT_FALSE(stp.requires(com::ubuntu::location::Provider::Requirements::none));
84
EXPECT_FALSE(stp.matches_criteria(com::ubuntu::location::Criteria{}));
85
stp.on_wifi_and_cell_reporting_state_changed(com::ubuntu::location::WifiAndCellIdReportingState::on);
86
stp.on_reference_location_updated(reference_position_update);
87
stp.on_reference_heading_updated(reference_heading_update);
88
stp.on_reference_velocity_updated(reference_velocity_update);
89
stp.start_position_updates();
90
stp.stop_position_updates();
91
stp.start_heading_updates();
92
stp.stop_heading_updates();
93
stp.start_velocity_updates();
94
stp.stop_velocity_updates();
97
TEST(StateTrackingProviderTest, state_after_construction_is_enabled)
99
using namespace ::testing;
100
cul::StateTrackingProvider stp{std::make_shared<NiceMock<MockProvider>>()};
101
EXPECT_EQ(cul::StateTrackingProvider::State::enabled, stp.state());
104
TEST(StateTrackingProviderTest, state_after_start_is_active)
106
using namespace ::testing;
107
cul::StateTrackingProvider stp{std::make_shared<NiceMock<MockProvider>>()};
108
stp.start_position_updates();
109
EXPECT_EQ(cul::StateTrackingProvider::State::active, stp.state());
112
TEST(StateTrackingProviderTest, stop_switches_to_enabled)
114
using namespace ::testing;
115
cul::StateTrackingProvider stp{std::make_shared<NiceMock<MockProvider>>()};
116
stp.start_position_updates();
117
stp.stop_position_updates();
118
EXPECT_EQ(cul::StateTrackingProvider::State::enabled, stp.state());