test: add helpers to wait for specific events
[platform/upstream/libinput.git] / test / litest.h
1 /*
2  * Copyright © 2013 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that copyright
7  * notice and this permission notice appear in supporting documentation, and
8  * that the name of the copyright holders not be used in advertising or
9  * publicity pertaining to distribution of the software without specific,
10  * written prior permission.  The copyright holders make no representations
11  * about the suitability of this software for any purpose.  It is provided "as
12  * is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20  * OF THIS SOFTWARE.
21  */
22
23 #if HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #ifndef LITEST_H
28 #define LITEST_H
29
30 #include <stdbool.h>
31 #include <check.h>
32 #include <libevdev/libevdev.h>
33 #include <libevdev/libevdev-uinput.h>
34 #include <libinput.h>
35
36 enum litest_device_type {
37         LITEST_NO_DEVICE = -1,
38         LITEST_SYNAPTICS_CLICKPAD,
39         LITEST_SYNAPTICS_TOUCHPAD,
40         LITEST_SYNAPTICS_TOPBUTTONPAD,
41         LITEST_BCM5974,
42         LITEST_KEYBOARD,
43         LITEST_TRACKPOINT,
44         LITEST_MOUSE,
45         LITEST_WACOM_TOUCH,
46         LITEST_ALPS_SEMI_MT,
47 };
48
49 enum litest_device_feature {
50         LITEST_DISABLE_DEVICE = -1,
51         LITEST_ANY = 0,
52         LITEST_TOUCHPAD = 1 << 0,
53         LITEST_CLICKPAD = 1 << 1,
54         LITEST_BUTTON = 1 << 2,
55         LITEST_KEYS = 1 << 3,
56         LITEST_POINTER = 1 << 4,
57         LITEST_WHEEL = 1 << 5,
58         LITEST_TOUCH = 1 << 6,
59         LITEST_SINGLE_TOUCH = 1 << 7,
60         LITEST_APPLE_CLICKPAD = 1 << 8,
61         LITEST_TOPBUTTONPAD = 1 << 9,
62         LITEST_SEMI_MT = 1 << 10,
63 };
64
65 struct litest_device {
66         struct libevdev *evdev;
67         struct libevdev_uinput *uinput;
68         struct libinput *libinput;
69         bool owns_context;
70         struct libinput_device *libinput_device;
71         struct litest_device_interface *interface;
72
73         int ntouches_down;
74         void *private; /* device-specific data */
75 };
76
77 struct libinput *litest_create_context(void);
78
79 void litest_add(const char *name, void *func,
80                 enum litest_device_feature required_feature,
81                 enum litest_device_feature excluded_feature);
82 void
83 litest_add_for_device(const char *name,
84                       void *func,
85                       enum litest_device_type type);
86 void litest_add_no_device(const char *name, void *func);
87
88 int litest_run(int argc, char **argv);
89 struct litest_device * litest_create_device(enum litest_device_type which);
90 struct libevdev_uinput *
91 litest_create_uinput_device_from_description(const char *name,
92                                              const struct input_id *id,
93                                              const struct input_absinfo *abs,
94                                              const int *events);
95 struct litest_device *
96 litest_create_device_with_overrides(enum litest_device_type which,
97                                     const char *name_override,
98                                     struct input_id *id_override,
99                                     const struct input_absinfo *abs_override,
100                                     const int *events_override);
101 struct litest_device *
102 litest_add_device_with_overrides(struct libinput *libinput,
103                                  enum litest_device_type which,
104                                  const char *name_override,
105                                  struct input_id *id_override,
106                                  const struct input_absinfo *abs_override,
107                                  const int *events_override);
108
109 struct litest_device *litest_current_device(void);
110 void litest_delete_device(struct litest_device *d);
111 int litest_handle_events(struct litest_device *d);
112
113 void litest_event(struct litest_device *t,
114                   unsigned int type,
115                   unsigned int code,
116                   int value);
117 int litest_auto_assign_value(struct litest_device *d,
118                              const struct input_event *ev,
119                              int slot, double x, double y);
120 void litest_touch_up(struct litest_device *d, unsigned int slot);
121 void litest_touch_move(struct litest_device *d,
122                        unsigned int slot,
123                        double x,
124                        double y);
125 void litest_touch_down(struct litest_device *d,
126                        unsigned int slot,
127                        double x,
128                        double y);
129 void litest_touch_move_to(struct litest_device *d,
130                           unsigned int slot,
131                           double x_from, double y_from,
132                           double x_to, double y_to,
133                           int steps);
134 void litest_button_click(struct litest_device *d,
135                          unsigned int button,
136                          bool is_press);
137 void litest_keyboard_key(struct litest_device *d,
138                          unsigned int key,
139                          bool is_press);
140 void litest_wait_for_event(struct libinput *li);
141 void litest_wait_for_event_of_type(struct libinput *li, ...);
142 void litest_drain_events(struct libinput *li);
143 void litest_assert_empty_queue(struct libinput *li);
144
145 struct libevdev_uinput * litest_create_uinput_device(const char *name,
146                                                      struct input_id *id,
147                                                      ...);
148 struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
149                                                          struct input_id *id,
150                                                          const struct input_absinfo *abs,
151                                                          ...);
152
153 #ifndef ck_assert_notnull
154 #define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
155 #endif
156
157 #endif /* LITEST_H */