2
* Copyright © 2015 Canonical Ltd.
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.
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.
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/>.
16
* Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
19
#include "mir/input/input_device_info.h"
20
#include "mir/input/input_device_observer.h"
21
#include "mir/input/input_device_hub.h"
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"
29
#include <gtest/gtest.h>
30
#include <gmock/gmock.h>
32
namespace mi = mir::input;
33
namespace mt = mir::test;
34
namespace mtf = mir_test_framework;
39
struct MockInputDeviceObserver : public mi::InputDeviceObserver
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());
47
struct TestInputDeviceHub : mtf::HeadlessInProcessServer
49
MockInputDeviceObserver observer;
50
mt::WaitCondition observer_registered;
51
mt::WaitCondition callbacks_received;
52
std::shared_ptr<mtf::FakeInputDevice> keep_on_living;
57
TEST_F(TestInputDeviceHub, calls_observers_with_changes_complete_on_registry)
59
using namespace testing;
60
EXPECT_CALL(observer, changes_complete())
61
.WillOnce(mt::WakeUp(&observer_registered));
63
server.the_input_device_hub()->add_observer(mt::fake_shared(observer));
64
observer_registered.wait_for_at_most_seconds(4);
67
TEST_F(TestInputDeviceHub, notifies_input_device_observer_about_available_devices)
69
using namespace testing;
71
EXPECT_CALL(observer, changes_complete())
72
.WillOnce(mt::WakeUp(&observer_registered));
74
EXPECT_CALL(observer, device_added(_));
75
EXPECT_CALL(observer, changes_complete())
76
.WillOnce(mt::WakeUp(&callbacks_received));
78
server.the_input_device_hub()->add_observer(mt::fake_shared(observer));
79
observer_registered.wait_for_at_most_seconds(4);
81
keep_on_living = mtf::add_fake_input_device(mi::InputDeviceInfo{0, "keyboard", "keyboard-uid", mir::input::DeviceCapability::keyboard});
83
callbacks_received.wait_for_at_most_seconds(4);