File: event_matchers.cpp

package info (click to toggle)
mir 2.25.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,104 kB
  • sloc: cpp: 192,777; xml: 13,784; ansic: 8,207; python: 1,304; sh: 794; makefile: 258
file content (232 lines) | stat: -rw-r--r-- 6,347 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
 * Copyright © Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 or 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <mir/test/event_matchers.h>

#include <mir/event_printer.h>

void PrintTo(MirEvent const& event, std::ostream *os)
{
    using mir::operator<<;
    *os << event;
}

void PrintTo(MirEvent const* event, std::ostream *os)
{
    if (event)
        PrintTo(*event, os);
    else
        *os << "nullptr";
}

#define STRINGIFY(val) \
case val: \
    return #val;

auto get_enum_value(MirEventType event)
-> char const*
{
    switch(event)
    {
    STRINGIFY(mir_event_type_window)
    STRINGIFY(mir_event_type_resize)
    STRINGIFY(mir_event_type_prompt_session_state_change)
    STRINGIFY(mir_event_type_orientation)
    STRINGIFY(mir_event_type_close_window)
    STRINGIFY(mir_event_type_input)
    STRINGIFY(mir_event_type_window_output)
    STRINGIFY(mir_event_type_input_device_state)
    STRINGIFY(mir_event_type_window_placement)

    default:
        throw std::logic_error("Invalid MirEventType in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirInputEventType event)
-> char const*
{
    switch(event)
    {
    STRINGIFY(mir_input_event_type_key)
    STRINGIFY(mir_input_event_type_touch)
    STRINGIFY(mir_input_event_type_pointer)
    STRINGIFY(mir_input_event_type_keyboard_resync)

    default:
        throw std::logic_error("Invalid MirInputEventType in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirInputEventModifier modifier)
-> char const*
{
    switch(modifier)
    {
    STRINGIFY(mir_input_event_modifier_none)
    STRINGIFY(mir_input_event_modifier_alt)
    STRINGIFY(mir_input_event_modifier_alt_left)
    STRINGIFY(mir_input_event_modifier_alt_right)
    STRINGIFY(mir_input_event_modifier_shift)
    STRINGIFY(mir_input_event_modifier_shift_left)
    STRINGIFY(mir_input_event_modifier_shift_right)
    STRINGIFY(mir_input_event_modifier_sym)
    STRINGIFY(mir_input_event_modifier_function)
    STRINGIFY(mir_input_event_modifier_ctrl)
    STRINGIFY(mir_input_event_modifier_ctrl_left)
    STRINGIFY(mir_input_event_modifier_ctrl_right)
    STRINGIFY(mir_input_event_modifier_meta)
    STRINGIFY(mir_input_event_modifier_meta_left)
    STRINGIFY(mir_input_event_modifier_meta_right)
    STRINGIFY(mir_input_event_modifier_caps_lock)
    STRINGIFY(mir_input_event_modifier_num_lock)
    STRINGIFY(mir_input_event_modifier_scroll_lock)

    default:
        throw std::logic_error("Invalid MirInputEventModifier in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirKeyboardAction action)
-> char const*
{
    switch(action)
    {
    STRINGIFY(mir_keyboard_action_up)
    STRINGIFY(mir_keyboard_action_down)
    STRINGIFY(mir_keyboard_action_repeat)

    default:
        throw std::logic_error("Invalid MirKeyboardAction in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirTouchAction action)
-> char const*
{
    switch(action)
    {
    STRINGIFY(mir_touch_action_up)
    STRINGIFY(mir_touch_action_down)
    STRINGIFY(mir_touch_action_change)

    default:
        throw std::logic_error("Invalid MirTouchAction in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirTouchAxis axis)
-> char const*
{
    switch(axis)
    {
    STRINGIFY(mir_touch_axis_x)
    STRINGIFY(mir_touch_axis_y)
    STRINGIFY(mir_touch_axis_pressure)
    STRINGIFY(mir_touch_axis_touch_major)
    STRINGIFY(mir_touch_axis_touch_minor)
    STRINGIFY(mir_touch_axis_size)

    default:
        throw std::logic_error("Invalid MirTouchAxis in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirTouchTooltype tooltype)
-> char const*
{
    switch(tooltype)
    {
    STRINGIFY(mir_touch_tooltype_unknown)
    STRINGIFY(mir_touch_tooltype_finger)
    STRINGIFY(mir_touch_tooltype_stylus)

    default:
        throw std::logic_error("Invalid MirTouchTooltype in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirPointerAction action)
-> char const*
{
    switch(action)
    {
    STRINGIFY(mir_pointer_action_button_up)
    STRINGIFY(mir_pointer_action_button_down)
    STRINGIFY(mir_pointer_action_enter)
    STRINGIFY(mir_pointer_action_leave)
    STRINGIFY(mir_pointer_action_motion)

    default:
        throw std::logic_error("Invalid MirPointerAction in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirPointerAxis axis)
-> char const*
{
    switch(axis)
    {
    STRINGIFY(mir_pointer_axis_x)
    STRINGIFY(mir_pointer_axis_y)
    STRINGIFY(mir_pointer_axis_vscroll)
    STRINGIFY(mir_pointer_axis_hscroll)
    STRINGIFY(mir_pointer_axis_relative_x)
    STRINGIFY(mir_pointer_axis_relative_y)
    STRINGIFY(mir_pointer_axis_vscroll_value120)
    STRINGIFY(mir_pointer_axis_hscroll_value120)

    default:
        throw std::logic_error("Invalid MirPointerAxis in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirPointerButtons button)
-> char const*
{
    switch(button)
    {
    STRINGIFY(mir_pointer_button_primary)
    STRINGIFY(mir_pointer_button_secondary)
    STRINGIFY(mir_pointer_button_tertiary)
    STRINGIFY(mir_pointer_button_back)
    STRINGIFY(mir_pointer_button_forward)
    STRINGIFY(mir_pointer_button_side)
    STRINGIFY(mir_pointer_button_extra)
    STRINGIFY(mir_pointer_button_task)

    default:
        throw std::logic_error("Invalid MirPointerButtons in mir::test::get_enum_value()");
    }
}

auto get_enum_value(MirPointerAxisSource source)
-> char const*
{
    switch(source)
    {
    STRINGIFY(mir_pointer_axis_source_none)
    STRINGIFY(mir_pointer_axis_source_wheel)
    STRINGIFY(mir_pointer_axis_source_finger)
    STRINGIFY(mir_pointer_axis_source_continuous)
    STRINGIFY(mir_pointer_axis_source_wheel_tilt)

    default:
        throw std::logic_error("Invalid MirPointerAxisSource in mir::test::get_enum_value()");
    }
}

#undef STRINGIFY