~alan-griffiths/mir/knee-jerk-mir_surface_state_automatic

« back to all changes in this revision

Viewing changes to tests/integration-tests/input/test_input_dispatch1.cpp

  • Committer: Kevin DuBois
  • Date: 2012-11-13 01:36:29 UTC
  • mfrom: (245 trunk)
  • mto: This revision was merged to the branch mainline in revision 246.
  • Revision ID: kevin.dubois@canonical.com-20121113013629-q4496w4mp5e33auk
merge in base branch. move the demo clients to a new directory, examples/

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2012 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: Thomas Voss <thomas.voss@canonical.com>
17
 
 */
18
 
 
19
 
#include "input_dispatch_fixture.h"
20
 
#include "mock_input_device.h"
21
 
#include "mock_input_event.h"
22
 
 
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"
30
 
 
31
 
#include "mir/thread/all.h"
32
 
 
33
 
#include <gmock/gmock.h>
34
 
#include <gtest/gtest.h>
35
 
 
36
 
 
37
 
namespace mi = mir::input;
38
 
 
39
 
using mir::input::InputDispatchFixture;
40
 
 
41
 
TEST_F(InputDispatchFixture, incoming_input_triggers_filter)
42
 
{
43
 
    using namespace testing;
44
 
    using ::testing::_;
45
 
    using ::testing::Return;
46
 
    
47
 
    mi::MockInputDevice* mock_device = new mi::MockInputDevice(&dispatcher);
48
 
    std::unique_ptr<mi::LogicalDevice> device(mock_device);
49
 
 
50
 
    EXPECT_CALL(*mock_device, start()).Times(AtLeast(1));
51
 
    mi::Dispatcher::DeviceToken token = dispatcher.register_device(std::move(device));
52
 
    
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));
57
 
 
58
 
    EXPECT_CALL(time_source, sample());
59
 
 
60
 
    mock_device->trigger_event();
61
 
 
62
 
    EXPECT_CALL(*mock_device, stop()).Times(AtLeast(1));
63
 
    dispatcher.unregister_device(token);
64
 
}
65
 
 
66
 
TEST_F(InputDispatchFixture, incoming_input_is_timestamped)
67
 
{
68
 
    using namespace testing;
69
 
 
70
 
    mir::Timestamp ts;
71
 
    DefaultValue<mir::Timestamp>::Set(ts);
72
 
    
73
 
    mi::MockInputDevice* mock_device = new mi::MockInputDevice(&dispatcher);
74
 
    std::unique_ptr<mi::LogicalDevice> device(mock_device);
75
 
 
76
 
    EXPECT_CALL(*mock_device, start()).Times(AtLeast(1));
77
 
    mi::Dispatcher::DeviceToken token = dispatcher.register_device(std::move(device));
78
 
    
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(_));
83
 
 
84
 
    EXPECT_CALL(time_source, sample()).Times(AtLeast(1));
85
 
    mock_device->trigger_event();
86
 
 
87
 
    EXPECT_EQ(mock_device->event.get_system_timestamp(), ts);
88
 
 
89
 
    EXPECT_CALL(*mock_device, stop()).Times(AtLeast(1));
90
 
    dispatcher.unregister_device(token);
91
 
}
92
 
 
93
 
TEST_F(InputDispatchFixture, device_registration_starts_and_stops_event_producer)
94
 
{
95
 
    using namespace ::testing;
96
 
    
97
 
    mi::MockInputDevice* mock_device = new mi::MockInputDevice(&dispatcher);
98
 
    std::unique_ptr<mi::LogicalDevice> device(mock_device);
99
 
 
100
 
    EXPECT_CALL(*mock_device, start()).Times(AtLeast(1));
101
 
    mi::Dispatcher::DeviceToken token = dispatcher.register_device(std::move(device));
102
 
 
103
 
    EXPECT_CALL(*mock_device, stop()).Times(AtLeast(1));
104
 
    dispatcher.unregister_device(token);
105
 
}
106