~sil2100/location-service/gps-arm64

« back to all changes in this revision

Viewing changes to tests/position_test.cpp

  • Committer: Thomas Voß
  • Date: 2013-05-28 14:20:45 UTC
  • Revision ID: thomas.voss@canonical.com-20130528142045-kq5umqdmm4o53vwk
Initial push.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "com/ubuntu/location/position.h"
 
2
 
 
3
#include <gtest/gtest.h>
 
4
 
 
5
TEST(Position, AllFieldsAreInvalidForDefaultConstructor)
 
6
{
 
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());
 
12
}
 
13
 
 
14
TEST(Position, InitWithLatLonGivesValidFieldsForLatLon)
 
15
{
 
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());
 
21
}
 
22
 
 
23
TEST(Position, InitWithLatLonAltGivesValidFieldsForLatLonAlt)
 
24
{
 
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());
 
33
}
 
34
 
 
35
TEST(Position, MutatorsAdjustFieldFlags)
 
36
{
 
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());
 
53
}
 
54
 
 
55
#include "com/ubuntu/location/codec.h"
 
56
 
 
57
#include "org/freedesktop/dbus/message.h"
 
58
 
 
59
TEST(Position, EncodingAndDecodingGivesSameResults)
 
60
{
 
61
 
 
62
    auto msg = org::freedesktop::dbus::Message::make_method_call(
 
63
        "org.freedesktop.DBus",
 
64
        "/org/freedesktop/DBus",
 
65
        "org.freedesktop.DBus",
 
66
        "ListNames");
 
67
 
 
68
    {
 
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}};
 
73
 
 
74
        msg->writer() << p;
 
75
    }
 
76
 
 
77
    {
 
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}};
 
83
        EXPECT_EQ(p_ref, p);
 
84
    }
 
85
}