~thomas-voss/location-service/fix-1347887

« back to all changes in this revision

Viewing changes to tests/harvester_test.cpp

This MP consolidates multiple related changes together, with the goal of:

(1.) Make the service instance accessible via a cli. Useful for testing scenarios.
(2.) To cut down time-to-first-fix (ttff) by:
  (2.1) Leveraging SUPL and other supplementary data downloaded over ordinary data connections.
  (2.2) Enabling network-based positioning providers to acquire fast position estimates.

In more detail:

* Added tests for daemon and cli.
* Unified daemon and cli header and implementation files.
* Add a command-line interface to the service.
* Split up provider selection policy to rely on an interface ProviderEnumerator to ease in testing.
* Trimmed down on types.
* Removed connectivity API draft to prepare for simpler approach.
* Refactored includes.
* Added a configuration option to handle cell and wifi ID reporting.
* Add a mock for a connectivity API exposed to providers and reporters.
* Add units for connectivity api.
* Refactor cell class into namespace radio. Fixes: 1226204, 1248973, 1281817

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2012-2013 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/service/harvester.h>
 
20
 
 
21
#include "mock_connectivity_manager.h"
 
22
#include "null_provider_selection_policy.h"
 
23
 
 
24
#include <gmock/gmock.h>
 
25
#include <gtest/gtest.h>
 
26
 
 
27
namespace location = com::ubuntu::location;
 
28
 
 
29
namespace
 
30
{
 
31
struct MockReporter : public location::service::Harvester::Reporter
 
32
{
 
33
    MockReporter() = default;
 
34
 
 
35
    /** @brief Tell the reporter that it should start operating. */
 
36
    MOCK_METHOD0(start, void());
 
37
 
 
38
    /** @brief Tell the reporter to shut down its operation. */
 
39
    MOCK_METHOD0(stop, void());
 
40
 
 
41
    /**
 
42
     * @brief Triggers the reporter to send off the information.
 
43
     */
 
44
    MOCK_METHOD3(report,
 
45
                 void(
 
46
                     const location::Update<location::Position>&,
 
47
                     const std::vector<location::connectivity::WirelessNetwork::Ptr>&,
 
48
                     const std::vector<location::connectivity::RadioCell::Ptr>&));
 
49
};
 
50
 
 
51
location::Update<location::Position> reference_position_update
 
52
{
 
53
    {
 
54
        location::wgs84::Latitude{9. * location::units::Degrees},
 
55
        location::wgs84::Longitude{53. * location::units::Degrees},
 
56
        location::wgs84::Altitude{-2. * location::units::Meters}
 
57
    },
 
58
    location::Clock::now()
 
59
};
 
60
}
 
61
 
 
62
TEST(Harvester, calls_start_and_stop_on_reporter)
 
63
{
 
64
    using namespace ::testing;
 
65
 
 
66
    auto reporter = std::make_shared<MockReporter>();
 
67
 
 
68
    EXPECT_CALL(*reporter, start()).Times(1);
 
69
    EXPECT_CALL(*reporter, stop()).Times(1);
 
70
 
 
71
    location::service::Harvester::Configuration config
 
72
    {
 
73
        location::connectivity::platform_default_manager(),
 
74
        reporter
 
75
    };
 
76
 
 
77
    location::service::Harvester harvester(config);
 
78
    harvester.start();
 
79
    harvester.stop();
 
80
}
 
81
 
 
82
TEST(Harvester, invokes_reporter_on_location_update_only_if_started)
 
83
{
 
84
    using namespace ::testing;
 
85
 
 
86
    auto reporter = std::make_shared<NiceMock<MockReporter>>();
 
87
 
 
88
    EXPECT_CALL(*reporter, report(reference_position_update,_,_)).Times(1);
 
89
 
 
90
    location::service::Harvester::Configuration config
 
91
    {
 
92
        location::connectivity::platform_default_manager(),
 
93
        reporter
 
94
    };
 
95
 
 
96
    location::service::Harvester harvester(config);
 
97
 
 
98
    harvester.start();
 
99
    harvester.report_position_update(reference_position_update);
 
100
 
 
101
    harvester.stop();
 
102
    harvester.report_position_update(reference_position_update);
 
103
}
 
104
 
 
105
TEST(Harvester, queries_wifis_and_cells_on_location_update)
 
106
{
 
107
    using namespace ::testing;
 
108
    using namespace location;
 
109
 
 
110
    auto conn_man = std::make_shared<MockConnectivityManager>();
 
111
 
 
112
    EXPECT_CALL(*conn_man, enumerate_connected_radio_cells(_)).Times(1);
 
113
    EXPECT_CALL(*conn_man, enumerate_visible_wireless_networks(_)).Times(1);
 
114
 
 
115
    service::Harvester::Configuration config
 
116
    {
 
117
        conn_man,
 
118
        std::make_shared<NiceMock<MockReporter>>()
 
119
    };
 
120
 
 
121
    service::Harvester harvester(config);
 
122
 
 
123
    harvester.start();
 
124
    harvester.report_position_update(reference_position_update);
 
125
}