16
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#include "com/ubuntu/location/position.h"
18
#include <com/ubuntu/location/position.h>
20
20
#include <gtest/gtest.h>
22
namespace cul = com::ubuntu::location;
22
24
TEST(Position, AllFieldsAreInvalidForDefaultConstructor)
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());
27
EXPECT_FALSE(p.altitude);
28
EXPECT_FALSE(p.accuracy.vertical);
31
31
TEST(Position, InitWithLatLonGivesValidFieldsForLatLon)
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);
40
37
TEST(Position, InitWithLatLonAltGivesValidFieldsForLatLonAlt)
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());
52
TEST(Position, MutatorsAdjustFieldFlags)
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());
72
#include "com/ubuntu/location/codec.h"
74
#include "core/dbus/message.h"
75
#include "core/dbus/message_streaming_operators.h"
40
cul::wgs84::Latitude{},
41
cul::wgs84::Longitude{},
42
cul::wgs84::Altitude{}};
43
EXPECT_TRUE(p.altitude);
46
#include <com/ubuntu/location/codec.h>
48
#include <core/dbus/message_streaming_operators.h>
77
50
TEST(Position, EncodingAndDecodingGivesSameResults)
54
cul::wgs84::Latitude{9. * cul::units::Degrees},
55
cul::wgs84::Longitude{53. * cul::units::Degrees},
56
cul::wgs84::Altitude{-2. * cul::units::Meters}
59
p.accuracy.horizontal = cul::Position::Accuracy::Horizontal{300*cul::units::Meters};
60
p.accuracy.vertical = cul::Position::Accuracy::Vertical{100*cul::units::Meters};
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",
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}};
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}};