2
* Copyright © 2012-2013 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/service/harvester.h>
21
#include "mock_connectivity_manager.h"
22
#include "null_provider_selection_policy.h"
24
#include <gmock/gmock.h>
25
#include <gtest/gtest.h>
27
namespace location = com::ubuntu::location;
31
struct MockReporter : public location::service::Harvester::Reporter
33
MockReporter() = default;
35
/** @brief Tell the reporter that it should start operating. */
36
MOCK_METHOD0(start, void());
38
/** @brief Tell the reporter to shut down its operation. */
39
MOCK_METHOD0(stop, void());
42
* @brief Triggers the reporter to send off the information.
46
const location::Update<location::Position>&,
47
const std::vector<location::connectivity::WirelessNetwork::Ptr>&,
48
const std::vector<location::connectivity::RadioCell::Ptr>&));
51
location::Update<location::Position> reference_position_update
54
location::wgs84::Latitude{9. * location::units::Degrees},
55
location::wgs84::Longitude{53. * location::units::Degrees},
56
location::wgs84::Altitude{-2. * location::units::Meters}
58
location::Clock::now()
62
TEST(Harvester, calls_start_and_stop_on_reporter)
64
using namespace ::testing;
66
auto reporter = std::make_shared<MockReporter>();
68
EXPECT_CALL(*reporter, start()).Times(1);
69
EXPECT_CALL(*reporter, stop()).Times(1);
71
location::service::Harvester::Configuration config
73
location::connectivity::platform_default_manager(),
77
location::service::Harvester harvester(config);
82
TEST(Harvester, invokes_reporter_on_location_update_only_if_started)
84
using namespace ::testing;
86
auto reporter = std::make_shared<NiceMock<MockReporter>>();
88
EXPECT_CALL(*reporter, report(reference_position_update,_,_)).Times(1);
90
location::service::Harvester::Configuration config
92
location::connectivity::platform_default_manager(),
96
location::service::Harvester harvester(config);
99
harvester.report_position_update(reference_position_update);
102
harvester.report_position_update(reference_position_update);
105
TEST(Harvester, queries_wifis_and_cells_on_location_update)
107
using namespace ::testing;
108
using namespace location;
110
auto conn_man = std::make_shared<MockConnectivityManager>();
112
EXPECT_CALL(*conn_man, enumerate_connected_radio_cells(_)).Times(1);
113
EXPECT_CALL(*conn_man, enumerate_visible_wireless_networks(_)).Times(1);
115
service::Harvester::Configuration config
118
std::make_shared<NiceMock<MockReporter>>()
121
service::Harvester harvester(config);
124
harvester.report_position_update(reference_position_update);