Fix documentation for libinput_log_set_handler
[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 = -2,
39         LITEST_SYNAPTICS_TOUCHPAD = -3,
40         LITEST_SYNAPTICS_TOPBUTTONPAD = -4,
41         LITEST_BCM5974 = -5,
42         LITEST_KEYBOARD = -6,
43         LITEST_TRACKPOINT = -7,
44         LITEST_MOUSE = -8,
45         LITEST_WACOM_TOUCH = -9,
46         LITEST_ALPS_SEMI_MT = -10,
47         LITEST_GENERIC_SINGLETOUCH = -11,
48 };
49
50 enum litest_device_feature {
51         LITEST_DISABLE_DEVICE = -1,
52         LITEST_ANY = 0,
53         LITEST_TOUCHPAD = 1 << 0,
54         LITEST_CLICKPAD = 1 << 1,
55         LITEST_BUTTON = 1 << 2,
56         LITEST_KEYS = 1 << 3,
57         LITEST_POINTER = 1 << 4,
58         LITEST_WHEEL = 1 << 5,
59         LITEST_TOUCH = 1 << 6,
60         LITEST_SINGLE_TOUCH = 1 << 7,
61         LITEST_APPLE_CLICKPAD = 1 << 8,
62         LITEST_TOPBUTTONPAD = 1 << 9,
63         LITEST_SEMI_MT = 1 << 10,
64         LITEST_POINTINGSTICK = 1 << 11,
65 };
66
67 struct litest_device {
68         struct libevdev *evdev;
69         struct libevdev_uinput *uinput;
70         struct libinput *libinput;
71         bool owns_context;
72         struct libinput_device *libinput_device;
73         struct litest_device_interface *interface;
74
75         int ntouches_down;
76         bool skip_ev_syn;
77
78         void *private; /* device-specific data */
79 };
80
81 struct libinput *litest_create_context(void);
82
83 void litest_add(const char *name, void *func,
84                 enum litest_device_feature required_feature,
85                 enum litest_device_feature excluded_feature);
86 void
87 litest_add_for_device(const char *name,
88                       void *func,
89                       enum litest_device_type type);
90 void litest_add_no_device(const char *name, void *func);
91
92 int litest_run(int argc, char **argv);
93 struct litest_device * litest_create_device(enum litest_device_type which);
94 struct litest_device * litest_add_device(struct libinput *libinput,
95                                          enum litest_device_type which);
96 struct libevdev_uinput *
97 litest_create_uinput_device_from_description(const char *name,
98                                              const struct input_id *id,
99                                              const struct input_absinfo *abs,
100                                              const int *events);
101 struct litest_device *
102 litest_create_device_with_overrides(enum litest_device_type which,
103                                     const char *name_override,
104                                     struct input_id *id_override,
105                                     const struct input_absinfo *abs_override,
106                                     const int *events_override);
107 struct litest_device *
108 litest_add_device_with_overrides(struct libinput *libinput,
109                                  enum litest_device_type which,
110                                  const char *name_override,
111                                  struct input_id *id_override,
112                                  const struct input_absinfo *abs_override,
113                                  const int *events_override);
114
115 struct litest_device *litest_current_device(void);
116 void litest_delete_device(struct litest_device *d);
117 int litest_handle_events(struct litest_device *d);
118
119 void litest_event(struct litest_device *t,
120                   unsigned int type,
121                   unsigned int code,
122                   int value);
123 int litest_auto_assign_value(struct litest_device *d,
124                              const struct input_event *ev,
125                              int slot, double x, double y);
126 void litest_touch_up(struct litest_device *d, unsigned int slot);
127 void litest_touch_move(struct litest_device *d,
128                        unsigned int slot,
129                        double x,
130                        double y);
131 void litest_touch_down(struct litest_device *d,
132                        unsigned int slot,
133                        double x,
134                        double y);
135 void litest_touch_move_to(struct litest_device *d,
136                           unsigned int slot,
137                           double x_from, double y_from,
138                           double x_to, double y_to,
139                           int steps);
140 void litest_button_click(struct litest_device *d,
141                          unsigned int button,
142                          bool is_press);
143 void litest_keyboard_key(struct litest_device *d,
144                          unsigned int key,
145                          bool is_press);
146 void litest_wait_for_event(struct libinput *li);
147 void litest_wait_for_event_of_type(struct libinput *li, ...);
148 void litest_drain_events(struct libinput *li);
149 void litest_assert_empty_queue(struct libinput *li);
150 void litest_assert_button_event(struct libinput *li,
151                                 unsigned int button,
152                                 enum libinput_button_state state);
153 void litest_assert_scroll(struct libinput *li, unsigned int axis, int dir);
154
155 struct libevdev_uinput * litest_create_uinput_device(const char *name,
156                                                      struct input_id *id,
157                                                      ...);
158 struct libevdev_uinput * litest_create_uinput_abs_device(const char *name,
159                                                          struct input_id *id,
160                                                          const struct input_absinfo *abs,
161                                                          ...);
162
163 void litest_timeout_tap(void);
164 void litest_timeout_softbuttons(void);
165
166 void litest_push_event_frame(struct litest_device *dev);
167 void litest_pop_event_frame(struct litest_device *dev);
168
169 #ifndef ck_assert_notnull
170 #define ck_assert_notnull(ptr) ck_assert_ptr_ne(ptr, NULL)
171 #endif
172
173 #endif /* LITEST_H */