~sil2100/location-service/gps-arm64

« back to all changes in this revision

Viewing changes to tests/session_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/provider.h"
 
2
#include "com/ubuntu/location/session.h"
 
3
 
 
4
#include <gmock/gmock.h>
 
5
#include <gtest/gtest.h>
 
6
 
 
7
namespace
 
8
{
 
9
struct MockProvider : public com::ubuntu::location::Provider
 
10
{
 
11
    MOCK_METHOD1(subscribe_to_position_updates,
 
12
                 com::ubuntu::location::ChannelConnection(std::function<void(const com::ubuntu::location::Update<com::ubuntu::location::Position>&)>));
 
13
 
 
14
    MOCK_METHOD1(subscribe_to_heading_updates,
 
15
                 com::ubuntu::location::ChannelConnection(std::function<void(const com::ubuntu::location::Update<com::ubuntu::location::Heading>&)>));
 
16
 
 
17
    MOCK_METHOD1(subscribe_to_velocity_updates,
 
18
                 com::ubuntu::location::ChannelConnection(std::function<void(const com::ubuntu::location::Update<com::ubuntu::location::Velocity>&)>));
 
19
};
 
20
}
 
21
 
 
22
TEST(LocationSession, constructing_with_a_null_provider_throws)
 
23
{
 
24
    EXPECT_ANY_THROW(com::ubuntu::location::Session session(com::ubuntu::location::Provider::Ptr {}));
 
25
}
 
26
 
 
27
TEST(LocationSession, changing_provider_association_of_session_results_in_connections_to_new_provider)
 
28
{
 
29
    using namespace ::testing;
 
30
    NiceMock<MockProvider> mock_provider1;
 
31
    ON_CALL(mock_provider1, subscribe_to_position_updates(_))
 
32
    .WillByDefault(Return(com::ubuntu::location::ChannelConnection()));
 
33
    ON_CALL(mock_provider1, subscribe_to_heading_updates(_))
 
34
    .WillByDefault(Return(com::ubuntu::location::ChannelConnection()));
 
35
    ON_CALL(mock_provider1, subscribe_to_velocity_updates(_))
 
36
    .WillByDefault(Return(com::ubuntu::location::ChannelConnection()));
 
37
 
 
38
    NiceMock<MockProvider> mock_provider2;
 
39
    EXPECT_CALL(mock_provider2, subscribe_to_position_updates(_))
 
40
    .WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
 
41
    EXPECT_CALL(mock_provider2, subscribe_to_heading_updates(_))
 
42
    .WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
 
43
    EXPECT_CALL(mock_provider2, subscribe_to_velocity_updates(_))
 
44
    .WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
 
45
 
 
46
    com::ubuntu::location::Session session(com::ubuntu::location::Provider::Ptr {&mock_provider1, [](com::ubuntu::location::Provider*) {}});
 
47
    session.change_provider_assocation_to(com::ubuntu::location::Provider::Ptr {&mock_provider2, [](com::ubuntu::location::Provider*) {}});
 
48
}
 
49
 
 
50
TEST(LocationSession, installing_updates_handlers_connects_them_to_the_provider_associated_to_the_session)
 
51
{
 
52
    using namespace ::testing;
 
53
 
 
54
    NiceMock<MockProvider> mock_provider;
 
55
 
 
56
    EXPECT_CALL(mock_provider, subscribe_to_position_updates(_))
 
57
    .Times(1)
 
58
    .WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
 
59
    EXPECT_CALL(mock_provider, subscribe_to_heading_updates(_))
 
60
    .Times(1)
 
61
    .WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
 
62
    EXPECT_CALL(mock_provider, subscribe_to_velocity_updates(_))
 
63
    .Times(1)
 
64
    .WillRepeatedly(Return(com::ubuntu::location::ChannelConnection()));
 
65
 
 
66
    com::ubuntu::location::Session session(com::ubuntu::location::Provider::Ptr {&mock_provider, [](com::ubuntu::location::Provider*) {}});
 
67
 
 
68
    session.install_position_updates_handler([](const com::ubuntu::location::Update<com::ubuntu::location::Position>&)
 
69
    {
 
70
    });
 
71
    session.install_heading_updates_handler([](const com::ubuntu::location::Update<com::ubuntu::location::Heading>&)
 
72
    {
 
73
    });
 
74
    session.install_velocity_updates_handler([](const com::ubuntu::location::Update<com::ubuntu::location::Velocity>&)
 
75
    {
 
76
    });
 
77
}