~ci-train-bot/location-service/location-service-ubuntu-yakkety-landing-028

« back to all changes in this revision

Viewing changes to tests/state_tracking_provider_test.cpp

Expose service::State to the bus. (LP: #1536774)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2016 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 
17
 */
 
18
 
 
19
#include <com/ubuntu/location/state_tracking_provider.h>
 
20
 
 
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>
 
28
 
 
29
#include "mock_provider.h"
 
30
 
 
31
#include <gtest/gtest.h>
 
32
 
 
33
namespace cul = com::ubuntu::location;
 
34
 
 
35
namespace
 
36
{
 
37
auto timestamp = cul::Clock::now();
 
38
 
 
39
// Create reference objects for injecting and validating updates.
 
40
cul::Update<cul::Position> reference_position_update
 
41
{
 
42
    {
 
43
        cul::wgs84::Latitude{9. * cul::units::Degrees},
 
44
        cul::wgs84::Longitude{53. * cul::units::Degrees},
 
45
        cul::wgs84::Altitude{-2. * cul::units::Meters}
 
46
    },
 
47
    timestamp
 
48
};
 
49
 
 
50
cul::Update<cul::Velocity> reference_velocity_update
 
51
{
 
52
    {5. * cul::units::MetersPerSecond},
 
53
    timestamp
 
54
};
 
55
 
 
56
cul::Update<cul::Heading> reference_heading_update
 
57
{
 
58
    {120. * cul::units::Degrees},
 
59
    timestamp
 
60
};
 
61
}
 
62
TEST(StateTrackingProviderTest, forwards_calls_to_impl)
 
63
{
 
64
    using namespace testing;
 
65
 
 
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);
 
80
 
 
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();
 
95
}
 
96
 
 
97
TEST(StateTrackingProviderTest, state_after_construction_is_enabled)
 
98
{
 
99
    using namespace ::testing;
 
100
    cul::StateTrackingProvider stp{std::make_shared<NiceMock<MockProvider>>()};
 
101
    EXPECT_EQ(cul::StateTrackingProvider::State::enabled, stp.state());
 
102
}
 
103
 
 
104
TEST(StateTrackingProviderTest, state_after_start_is_active)
 
105
{
 
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());
 
110
}
 
111
 
 
112
TEST(StateTrackingProviderTest, stop_switches_to_enabled)
 
113
{
 
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());
 
119
}