1
#include "com/ubuntu/location/position.h"
3
#include <gtest/gtest.h>
5
TEST(Position, AllFieldsAreInvalidForDefaultConstructor)
7
com::ubuntu::location::Position p;
8
EXPECT_FALSE(p.has_latitude());
9
EXPECT_FALSE(p.has_longitude());
10
EXPECT_FALSE(p.has_altitude());
11
EXPECT_EQ(0, p.flags().to_ulong());
14
TEST(Position, InitWithLatLonGivesValidFieldsForLatLon)
16
com::ubuntu::location::Position p{com::ubuntu::location::wgs84::Latitude{}, com::ubuntu::location::wgs84::Longitude{}};
17
EXPECT_TRUE(p.has_latitude());
18
EXPECT_TRUE(p.has_longitude());
19
EXPECT_FALSE(p.has_altitude());
20
EXPECT_EQ(3, p.flags().to_ulong());
23
TEST(Position, InitWithLatLonAltGivesValidFieldsForLatLonAlt)
25
com::ubuntu::location::Position p{
26
com::ubuntu::location::wgs84::Latitude{},
27
com::ubuntu::location::wgs84::Longitude{},
28
com::ubuntu::location::wgs84::Altitude{}};
29
EXPECT_TRUE(p.has_latitude());
30
EXPECT_TRUE(p.has_longitude());
31
EXPECT_TRUE(p.has_altitude());
32
EXPECT_EQ(7, p.flags().to_ulong());
35
TEST(Position, MutatorsAdjustFieldFlags)
37
com::ubuntu::location::Position p;
38
EXPECT_FALSE(p.has_latitude());
39
EXPECT_FALSE(p.has_longitude());
40
EXPECT_FALSE(p.has_altitude());
41
p.latitude(com::ubuntu::location::wgs84::Latitude{});
42
EXPECT_TRUE(p.has_latitude());
43
EXPECT_FALSE(p.has_longitude());
44
EXPECT_FALSE(p.has_altitude());
45
p.longitude(com::ubuntu::location::wgs84::Longitude{});
46
EXPECT_TRUE(p.has_latitude());
47
EXPECT_TRUE(p.has_longitude());
48
EXPECT_FALSE(p.has_altitude());
49
p.altitude(com::ubuntu::location::wgs84::Altitude{});
50
EXPECT_TRUE(p.has_latitude());
51
EXPECT_TRUE(p.has_longitude());
52
EXPECT_TRUE(p.has_altitude());
55
#include "com/ubuntu/location/codec.h"
57
#include "org/freedesktop/dbus/message.h"
59
TEST(Position, EncodingAndDecodingGivesSameResults)
62
auto msg = org::freedesktop::dbus::Message::make_method_call(
63
"org.freedesktop.DBus",
64
"/org/freedesktop/DBus",
65
"org.freedesktop.DBus",
69
com::ubuntu::location::Position p{
70
com::ubuntu::location::wgs84::Latitude{9. * com::ubuntu::location::units::Degrees},
71
com::ubuntu::location::wgs84::Longitude{53. * com::ubuntu::location::units::Degrees},
72
com::ubuntu::location::wgs84::Altitude{-2. * com::ubuntu::location::units::Meters}};
78
com::ubuntu::location::Position p; msg->reader() >> p;
79
com::ubuntu::location::Position p_ref{
80
com::ubuntu::location::wgs84::Latitude{9. * com::ubuntu::location::units::Degrees},
81
com::ubuntu::location::wgs84::Longitude{53. * com::ubuntu::location::units::Degrees},
82
com::ubuntu::location::wgs84::Altitude{-2. * com::ubuntu::location::units::Meters}};