2
* Copyright © 2012 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: Thomas Voss <thomas.voss@canonical.com>
19
#include "input_dispatch_fixture.h"
20
#include "mock_input_device.h"
21
#include "mock_input_event.h"
23
#include "mir/time_source.h"
24
#include "mir/input/dispatcher.h"
25
#include "mir/input/event.h"
26
#include "mir/input/filter.h"
27
#include "mir/input/grab_filter.h"
28
#include "mir/input/logical_device.h"
29
#include "mir/input/position_info.h"
31
#include "mir/thread/all.h"
33
#include <gmock/gmock.h>
34
#include <gtest/gtest.h>
37
namespace mi = mir::input;
39
using mir::input::InputDispatchFixture;
41
TEST_F(InputDispatchFixture, incoming_input_triggers_filter)
43
using namespace testing;
45
using ::testing::Return;
47
mi::MockInputDevice* mock_device = new mi::MockInputDevice(&dispatcher);
48
std::unique_ptr<mi::LogicalDevice> device(mock_device);
50
EXPECT_CALL(*mock_device, start()).Times(AtLeast(1));
51
mi::Dispatcher::DeviceToken token = dispatcher.register_device(std::move(device));
53
EXPECT_CALL(*mock_null_filter, accept(_));
54
EXPECT_CALL(*mock_shell_filter, accept(_)).Times(AtLeast(1));
55
EXPECT_CALL(*mock_grab_filter, accept(_)).Times(AtLeast(1));
56
EXPECT_CALL(*mock_app_filter, accept(_)).Times(AtLeast(1));
58
EXPECT_CALL(time_source, sample());
60
mock_device->trigger_event();
62
EXPECT_CALL(*mock_device, stop()).Times(AtLeast(1));
63
dispatcher.unregister_device(token);
66
TEST_F(InputDispatchFixture, incoming_input_is_timestamped)
68
using namespace testing;
71
DefaultValue<mir::Timestamp>::Set(ts);
73
mi::MockInputDevice* mock_device = new mi::MockInputDevice(&dispatcher);
74
std::unique_ptr<mi::LogicalDevice> device(mock_device);
76
EXPECT_CALL(*mock_device, start()).Times(AtLeast(1));
77
mi::Dispatcher::DeviceToken token = dispatcher.register_device(std::move(device));
79
EXPECT_CALL(*mock_null_filter, accept(_));
80
EXPECT_CALL(*mock_shell_filter, accept(_));
81
EXPECT_CALL(*mock_grab_filter, accept(_));
82
EXPECT_CALL(*mock_app_filter, accept(_));
84
EXPECT_CALL(time_source, sample()).Times(AtLeast(1));
85
mock_device->trigger_event();
87
EXPECT_EQ(mock_device->event.get_system_timestamp(), ts);
89
EXPECT_CALL(*mock_device, stop()).Times(AtLeast(1));
90
dispatcher.unregister_device(token);
93
TEST_F(InputDispatchFixture, device_registration_starts_and_stops_event_producer)
95
using namespace ::testing;
97
mi::MockInputDevice* mock_device = new mi::MockInputDevice(&dispatcher);
98
std::unique_ptr<mi::LogicalDevice> device(mock_device);
100
EXPECT_CALL(*mock_device, start()).Times(AtLeast(1));
101
mi::Dispatcher::DeviceToken token = dispatcher.register_device(std::move(device));
103
EXPECT_CALL(*mock_device, stop()).Times(AtLeast(1));
104
dispatcher.unregister_device(token);