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

« back to all changes in this revision

Viewing changes to tests/position_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:
15
15
 *
16
16
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17
17
 */
18
 
#include "com/ubuntu/location/position.h"
 
18
#include <com/ubuntu/location/position.h>
19
19
 
20
20
#include <gtest/gtest.h>
21
21
 
 
22
namespace cul = com::ubuntu::location;
 
23
 
22
24
TEST(Position, AllFieldsAreInvalidForDefaultConstructor)
23
25
{
24
 
    com::ubuntu::location::Position p;
25
 
    EXPECT_FALSE(p.has_latitude());
26
 
    EXPECT_FALSE(p.has_longitude());
27
 
    EXPECT_FALSE(p.has_altitude());
28
 
    EXPECT_EQ(0, p.flags().to_ulong());
 
26
    cul::Position p;
 
27
    EXPECT_FALSE(p.altitude);
 
28
    EXPECT_FALSE(p.accuracy.vertical);
29
29
}
30
30
 
31
31
TEST(Position, InitWithLatLonGivesValidFieldsForLatLon)
32
32
{
33
 
    com::ubuntu::location::Position p{com::ubuntu::location::wgs84::Latitude{}, com::ubuntu::location::wgs84::Longitude{}};
34
 
    EXPECT_TRUE(p.has_latitude());
35
 
    EXPECT_TRUE(p.has_longitude());
36
 
    EXPECT_FALSE(p.has_altitude());
37
 
    EXPECT_EQ(3, p.flags().to_ulong());
 
33
    cul::Position p{cul::wgs84::Latitude{}, cul::wgs84::Longitude{}};
 
34
    EXPECT_FALSE(p.altitude);
38
35
}
39
36
 
40
37
TEST(Position, InitWithLatLonAltGivesValidFieldsForLatLonAlt)
41
38
{
42
 
    com::ubuntu::location::Position p{
43
 
        com::ubuntu::location::wgs84::Latitude{}, 
44
 
        com::ubuntu::location::wgs84::Longitude{},
45
 
        com::ubuntu::location::wgs84::Altitude{}};
46
 
    EXPECT_TRUE(p.has_latitude());
47
 
    EXPECT_TRUE(p.has_longitude());
48
 
    EXPECT_TRUE(p.has_altitude());
49
 
    EXPECT_EQ(7, p.flags().to_ulong());
50
 
}
51
 
 
52
 
TEST(Position, MutatorsAdjustFieldFlags)
53
 
{
54
 
    com::ubuntu::location::Position p;
55
 
    EXPECT_FALSE(p.has_latitude());
56
 
    EXPECT_FALSE(p.has_longitude());
57
 
    EXPECT_FALSE(p.has_altitude());
58
 
    p.latitude(com::ubuntu::location::wgs84::Latitude{});
59
 
    EXPECT_TRUE(p.has_latitude());
60
 
    EXPECT_FALSE(p.has_longitude());
61
 
    EXPECT_FALSE(p.has_altitude());
62
 
    p.longitude(com::ubuntu::location::wgs84::Longitude{});
63
 
    EXPECT_TRUE(p.has_latitude());
64
 
    EXPECT_TRUE(p.has_longitude());
65
 
    EXPECT_FALSE(p.has_altitude());
66
 
    p.altitude(com::ubuntu::location::wgs84::Altitude{});
67
 
    EXPECT_TRUE(p.has_latitude());
68
 
    EXPECT_TRUE(p.has_longitude());
69
 
    EXPECT_TRUE(p.has_altitude());
70
 
}
71
 
 
72
 
#include "com/ubuntu/location/codec.h"
73
 
 
74
 
#include "core/dbus/message.h"
75
 
#include "core/dbus/message_streaming_operators.h"
 
39
    cul::Position p{
 
40
        cul::wgs84::Latitude{},
 
41
        cul::wgs84::Longitude{},
 
42
        cul::wgs84::Altitude{}};
 
43
    EXPECT_TRUE(p.altitude);
 
44
}
 
45
 
 
46
#include <com/ubuntu/location/codec.h>
 
47
 
 
48
#include <core/dbus/message_streaming_operators.h>
76
49
 
77
50
TEST(Position, EncodingAndDecodingGivesSameResults)
78
51
{
 
52
    cul::Position p
 
53
    {
 
54
        cul::wgs84::Latitude{9. * cul::units::Degrees},
 
55
        cul::wgs84::Longitude{53. * cul::units::Degrees},
 
56
        cul::wgs84::Altitude{-2. * cul::units::Meters}
 
57
    };
 
58
 
 
59
    p.accuracy.horizontal =  cul::Position::Accuracy::Horizontal{300*cul::units::Meters};
 
60
    p.accuracy.vertical = cul::Position::Accuracy::Vertical{100*cul::units::Meters};
79
61
 
80
62
    auto msg = core::dbus::Message::make_method_call(
81
63
        "org.freedesktop.DBus",
82
 
        core::dbus::types::ObjectPath("/core/DBus"),
 
64
        core::dbus::types::ObjectPath("/org/freedesktop/DBus"),
83
65
        "org.freedesktop.DBus",
84
66
        "ListNames");
85
67
 
86
 
    {
87
 
        com::ubuntu::location::Position p{
88
 
            com::ubuntu::location::wgs84::Latitude{9. * com::ubuntu::location::units::Degrees},
89
 
            com::ubuntu::location::wgs84::Longitude{53. * com::ubuntu::location::units::Degrees},
90
 
            com::ubuntu::location::wgs84::Altitude{-2. * com::ubuntu::location::units::Meters}};
91
 
 
92
 
        msg->writer() << p;
93
 
    }
94
 
 
95
 
    {
96
 
        com::ubuntu::location::Position p; msg->reader() >> p;
97
 
        com::ubuntu::location::Position p_ref{
98
 
            com::ubuntu::location::wgs84::Latitude{9. * com::ubuntu::location::units::Degrees},
99
 
            com::ubuntu::location::wgs84::Longitude{53. * com::ubuntu::location::units::Degrees},
100
 
            com::ubuntu::location::wgs84::Altitude{-2. * com::ubuntu::location::units::Meters}};
101
 
        EXPECT_EQ(p_ref, p);
102
 
    }
 
68
    msg->writer() << p;
 
69
 
 
70
    cul::Position pp;
 
71
    msg->reader() >> pp;
 
72
 
 
73
    EXPECT_EQ(p, pp);
103
74
}