~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_dispatch.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
 
 
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"
29
 
 
30
 
#include <gmock/gmock.h>
31
 
#include <gtest/gtest.h>
32
 
 
33
 
 
34
 
namespace mi = mir::input;
35
 
 
36
 
using mir::input::InputDispatchFixture;
37
 
 
38
 
namespace
39
 
{
40
 
static mir::Timestamp last_timestamp;
41
 
 
42
 
bool is_weakly_ordered(mi::Event* e)
43
 
{
44
 
    bool result = e->get_system_timestamp() >= last_timestamp;
45
 
    last_timestamp = e->get_system_timestamp();
46
 
    return result;
47
 
}
48
 
 
49
 
 
50
 
void worker(mi::MockInputDevice* dev)
51
 
{
52
 
    for(int i = 0; i < 1000; i++)
53
 
        dev->trigger_event();
54
 
}
55
 
}
56
 
 
57
 
namespace mir
58
 
{
59
 
TEST_F(InputDispatchFixture, filters_are_always_invoked_in_order_and_events_are_weakly_ordered_by_their_timestamp)
60
 
{
61
 
    using namespace::testing;
62
 
 
63
 
    EXPECT_CALL(time_source, sample()).Times(AnyNumber());
64
 
    
65
 
    EXPECT_CALL(*mock_null_filter, accept(Truly(is_weakly_ordered)))
66
 
            .Times(AnyNumber())
67
 
            .RetiresOnSaturation();
68
 
    EXPECT_CALL(*mock_shell_filter, accept(Truly(is_weakly_ordered)))
69
 
            .Times(AnyNumber())
70
 
            .RetiresOnSaturation();
71
 
    EXPECT_CALL(*mock_grab_filter, accept(Truly(is_weakly_ordered)))
72
 
            .Times(AnyNumber())
73
 
            .RetiresOnSaturation();
74
 
    EXPECT_CALL(*mock_app_filter, accept(Truly(is_weakly_ordered)))
75
 
            .Times(AnyNumber())
76
 
            .RetiresOnSaturation();
77
 
 
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);
86
 
 
87
 
    auto token1 = dispatcher.register_device(std::move(device1));
88
 
    auto token2 = dispatcher.register_device(std::move(device2));
89
 
    
90
 
    std::thread t1(worker, mock_device1);
91
 
    std::thread t2(worker, mock_device2);
92
 
 
93
 
    t1.join();
94
 
    t2.join();
95
 
    
96
 
    dispatcher.unregister_device(token1);
97
 
    dispatcher.unregister_device(token2);
98
 
}
99
 
}