~ubuntu-branches/ubuntu/wily/mir/wily-proposed

« back to all changes in this revision

Viewing changes to tests/acceptance-tests/test_input_device_hub.cpp

  • Committer: Package Import Robot
  • Author(s): CI Train Bot
  • Date: 2015-05-12 13:12:55 UTC
  • mto: This revision was merged to the branch mainline in revision 96.
  • Revision ID: package-import@ubuntu.com-20150512131255-y7z12i8n4pbvo70x
Tags: upstream-0.13.0+15.10.20150512
Import upstream version 0.13.0+15.10.20150512

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2015 Canonical Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License version 3 as
 
6
 * published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
 
17
 */
 
18
 
 
19
#include "mir/input/input_device_info.h"
 
20
#include "mir/input/input_device_observer.h"
 
21
#include "mir/input/input_device_hub.h"
 
22
 
 
23
#include "mir_test_framework/headless_in_process_server.h"
 
24
#include "mir_test_framework/fake_input_device.h"
 
25
#include "mir_test_framework/stub_server_platform_factory.h"
 
26
#include "mir_test/wait_condition.h"
 
27
#include "mir_test/fake_shared.h"
 
28
 
 
29
#include <gtest/gtest.h>
 
30
#include <gmock/gmock.h>
 
31
 
 
32
namespace mi = mir::input;
 
33
namespace mt = mir::test;
 
34
namespace mtf = mir_test_framework;
 
35
 
 
36
namespace
 
37
{
 
38
 
 
39
struct MockInputDeviceObserver : public mi::InputDeviceObserver
 
40
{
 
41
    MOCK_METHOD1(device_added, void (mi::InputDeviceInfo const& device));
 
42
    MOCK_METHOD1(device_changed, void(mi::InputDeviceInfo const& device));
 
43
    MOCK_METHOD1(device_removed, void(mi::InputDeviceInfo const& device));
 
44
    MOCK_METHOD0(changes_complete, void());
 
45
};
 
46
 
 
47
struct TestInputDeviceHub : mtf::HeadlessInProcessServer
 
48
{
 
49
    MockInputDeviceObserver observer;
 
50
    mt::WaitCondition observer_registered;
 
51
    mt::WaitCondition callbacks_received;
 
52
    std::shared_ptr<mtf::FakeInputDevice> keep_on_living;
 
53
};
 
54
 
 
55
}
 
56
 
 
57
TEST_F(TestInputDeviceHub, calls_observers_with_changes_complete_on_registry)
 
58
{
 
59
    using namespace testing;
 
60
    EXPECT_CALL(observer, changes_complete())
 
61
        .WillOnce(mt::WakeUp(&observer_registered));
 
62
 
 
63
    server.the_input_device_hub()->add_observer(mt::fake_shared(observer));
 
64
    observer_registered.wait_for_at_most_seconds(4);
 
65
}
 
66
 
 
67
TEST_F(TestInputDeviceHub, notifies_input_device_observer_about_available_devices)
 
68
{
 
69
    using namespace testing;
 
70
    InSequence seq;
 
71
    EXPECT_CALL(observer, changes_complete())
 
72
        .WillOnce(mt::WakeUp(&observer_registered));
 
73
 
 
74
    EXPECT_CALL(observer, device_added(_));
 
75
    EXPECT_CALL(observer, changes_complete())
 
76
        .WillOnce(mt::WakeUp(&callbacks_received));
 
77
 
 
78
    server.the_input_device_hub()->add_observer(mt::fake_shared(observer));
 
79
    observer_registered.wait_for_at_most_seconds(4);
 
80
 
 
81
    keep_on_living = mtf::add_fake_input_device(mi::InputDeviceInfo{0, "keyboard", "keyboard-uid", mir::input::DeviceCapability::keyboard});
 
82
 
 
83
    callbacks_received.wait_for_at_most_seconds(4);
 
84
}