~thomas-voss/location-service/generalize-glue-code-for-agps-operation

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
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * 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/service/harvester.h>

#include "mock_connectivity_manager.h"
#include "mock_reporter.h"
#include "null_provider_selection_policy.h"

#include <gmock/gmock.h>
#include <gtest/gtest.h>

namespace location = com::ubuntu::location;

namespace
{
location::Update<location::Position> reference_position_update
{
    {
        location::wgs84::Latitude{9. * location::units::Degrees},
        location::wgs84::Longitude{53. * location::units::Degrees},
        location::wgs84::Altitude{-2. * location::units::Meters}
    },
    location::Clock::now()
};
}

TEST(Harvester, calls_start_and_stop_on_reporter)
{
    using namespace ::testing;

    auto reporter = std::make_shared<MockReporter>();

    EXPECT_CALL(*reporter, start()).Times(1);
    EXPECT_CALL(*reporter, stop()).Times(1);

    location::service::Harvester::Configuration config
    {
        location::connectivity::platform_default_manager(),
        reporter
    };

    location::service::Harvester harvester(config);
    harvester.start();
    harvester.stop();
}

TEST(Harvester, invokes_reporter_on_location_update_only_if_started)
{
    using namespace ::testing;

    auto reporter = std::make_shared<NiceMock<MockReporter>>();

    EXPECT_CALL(*reporter, report(reference_position_update,_,_)).Times(1);

    location::service::Harvester::Configuration config
    {
        location::connectivity::platform_default_manager(),
        reporter
    };

    location::service::Harvester harvester(config);

    harvester.start();
    harvester.report_position_update(reference_position_update);

    harvester.stop();
    harvester.report_position_update(reference_position_update);
}

TEST(Harvester, queries_wifis_and_cells_on_location_update)
{
    using namespace ::testing;
    using namespace location;

    auto conn_man = std::make_shared<MockConnectivityManager>();

    EXPECT_CALL(*conn_man, enumerate_connected_radio_cells(_)).Times(1);
    EXPECT_CALL(*conn_man, enumerate_visible_wireless_networks(_)).Times(1);

    service::Harvester::Configuration config
    {
        conn_man,
        std::make_shared<NiceMock<MockReporter>>()
    };

    service::Harvester harvester(config);

    harvester.start();
    harvester.report_position_update(reference_position_update);
}