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"
22
#include "mir/time_source.h"
23
#include "mir/input/dispatcher.h"
24
#include "mir/input/event.h"
25
#include "mir/input/filter.h"
26
#include "mir/input/logical_device.h"
27
#include "mir/input/position_info.h"
28
#include "mir/thread/all.h"
30
#include <gmock/gmock.h>
31
#include <gtest/gtest.h>
34
namespace mi = mir::input;
36
using mir::input::InputDispatchFixture;
40
static mir::Timestamp last_timestamp;
42
bool is_weakly_ordered(mi::Event* e)
44
bool result = e->get_system_timestamp() >= last_timestamp;
45
last_timestamp = e->get_system_timestamp();
50
void worker(mi::MockInputDevice* dev)
52
for(int i = 0; i < 1000; i++)
59
TEST_F(InputDispatchFixture, filters_are_always_invoked_in_order_and_events_are_weakly_ordered_by_their_timestamp)
61
using namespace::testing;
63
EXPECT_CALL(time_source, sample()).Times(AnyNumber());
65
EXPECT_CALL(*mock_null_filter, accept(Truly(is_weakly_ordered)))
67
.RetiresOnSaturation();
68
EXPECT_CALL(*mock_shell_filter, accept(Truly(is_weakly_ordered)))
70
.RetiresOnSaturation();
71
EXPECT_CALL(*mock_grab_filter, accept(Truly(is_weakly_ordered)))
73
.RetiresOnSaturation();
74
EXPECT_CALL(*mock_app_filter, accept(Truly(is_weakly_ordered)))
76
.RetiresOnSaturation();
78
mi::MockInputDevice* mock_device1 = new mi::MockInputDevice(&dispatcher);
79
mi::MockInputDevice* mock_device2 = new mi::MockInputDevice(&dispatcher);
80
EXPECT_CALL(*mock_device1, start()).Times(1);
81
EXPECT_CALL(*mock_device1, stop()).Times(1);
82
EXPECT_CALL(*mock_device2, start()).Times(1);
83
EXPECT_CALL(*mock_device2, stop()).Times(1);
84
std::unique_ptr<mi::LogicalDevice> device1(mock_device1);
85
std::unique_ptr<mi::LogicalDevice> device2(mock_device2);
87
auto token1 = dispatcher.register_device(std::move(device1));
88
auto token2 = dispatcher.register_device(std::move(device2));
90
std::thread t1(worker, mock_device1);
91
std::thread t2(worker, mock_device2);
96
dispatcher.unregister_device(token1);
97
dispatcher.unregister_device(token2);