Mir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
event_matchers.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2013 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as 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: Robert Carr <robert.carr@canonical.com>
17  */
18 
19 #ifndef MIR_TEST_EVENT_MATCHERS_H_
20 #define MIR_TEST_EVENT_MATCHERS_H_
21 
22 #include "mir_toolkit/event.h"
23 
24 #include <androidfw/Input.h>
25 
26 #include <gmock/gmock.h>
27 
28 namespace mir
29 {
30 namespace test
31 {
32 
33 MATCHER_P(IsKeyEventWithKey, key, "")
34 {
35  if (arg.type != mir_event_type_key)
36  return false;
37 
38  return arg.key.key_code == key;
39 }
40 MATCHER(KeyDownEvent, "")
41 {
42  if (arg.type != mir_event_type_key)
43  return false;
44 
45  return arg.key.action == mir_key_action_down;
46 }
47 MATCHER(ButtonDownEvent, "")
48 {
49  if (arg.type != mir_event_type_motion)
50  return false;
51  if (arg.motion.button_state == 0)
52  return false;
53  return arg.motion.action == mir_motion_action_down;
54 }
55 MATCHER(ButtonUpEvent, "")
56 {
57  if (arg.type != mir_event_type_motion)
58  return false;
59  return arg.motion.action == mir_motion_action_up;
60 }
61 MATCHER_P2(MotionEvent, dx, dy, "")
62 {
63  if (arg.type != mir_event_type_motion)
64  return false;
65  auto coords = &arg.motion.pointer_coordinates[0];
66  return (coords->x == dx) && (coords->y == dy);
67 }
68 
69 MATCHER_P2(SurfaceEvent, attrib, value, "")
70 {
71  if (arg.type != mir_event_type_surface)
72  return false;
73  auto surface_ev = arg.surface;
74  if (surface_ev.attrib != attrib)
75  return false;
76  if (surface_ev.value != value)
77  return false;
78  return true;
79 }
80 
81 }
82 } // namespace mir
83 
84 #endif // MIR_TEST_EVENT_MATCHERS_H_

Copyright © 2012,2013 Canonical Ltd.
Generated on Wed Oct 30 18:52:19 UTC 2013