• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2013 Red Hat, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  * DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include "config.h"
25 #include <limits.h>
26 
27 #ifndef LITEST_INT_H
28 #define LITEST_INT_H
29 #include "litest.h"
30 
31 /* Use as designater for litest to change the value */
32 #define LITEST_AUTO_ASSIGN INT_MIN
33 
34 /* Special event code to auto-assign the BTN_TOOL_PEN and friends */
35 #define LITEST_BTN_TOOL_AUTO (KEY_MAX << 1)
36 
37 struct litest_test_device {
38 	struct list node; /* global test device list */
39 
40 	enum litest_device_type type;
41 	int64_t features;
42 	const char *shortname;
43 	void (*setup)(void); /* test fixture, used by check */
44 	void (*teardown)(void); /* test fixture, used by check */
45 	/**
46 	* If create is non-NULL it will be called to initialize the device.
47 	* For such devices, no overrides are possible. If create is NULL,
48 	* the information in name, id, events, absinfo is used to
49 	* create the device instead.
50 	*
51 	* @return true if the device needs to be created by litest, false if
52 	*	the device creates itself
53 	*/
54 	bool (*create)(struct litest_device *d);
55 
56 	/**
57 	 * The device name. Only used when create is NULL.
58 	 */
59 	const char *name;
60 	/**
61 	 * The device id. Only used when create is NULL.
62 	 */
63 	const struct input_id *id;
64 	/**
65 	* List of event type/code tuples, terminated with -1, e.g.
66 	* EV_REL, REL_X, EV_KEY, BTN_LEFT, -1
67 	* Special tuple is INPUT_PROP_MAX, <actual property> to set.
68 	*
69 	* Any EV_ABS codes in this list will be initialized with a default
70 	* axis range.
71 	*/
72 	int *events;
73 	/**
74 	 * List of abs codes to enable, with absinfo.value determining the
75 	 * code to set. List must be terminated with absinfo.value -1
76 	 */
77 	struct input_absinfo *absinfo;
78 	struct litest_device_interface *interface;
79 
80 	const char *udev_rule;
81 	const char *quirk_file;
82 
83 	const struct key_value_str udev_properties[32];
84 };
85 
86 struct litest_device_interface {
87 	bool (*touch_down)(struct litest_device *d, unsigned int slot, double x, double y);
88 	bool (*touch_move)(struct litest_device *d, unsigned int slot, double x, double y);
89 	bool (*touch_up)(struct litest_device *d, unsigned int slot);
90 
91 	/**
92 	 * Default value for the given EV_ABS axis.
93 	 * @return 0 on success, nonzero otherwise
94 	 */
95 	int (*get_axis_default)(struct litest_device *d, unsigned int code, int32_t *value);
96 
97 	/**
98 	 * Set of of events to execute on touch down, terminated by a .type
99 	 * and .code value of -1. If the event value is LITEST_AUTO_ASSIGN,
100 	 * it will be automatically assigned by the framework (valid for x,
101 	 * y, tracking id and slot).
102 	 *
103 	 * These events are only used if touch_down is NULL.
104 	 */
105 	struct input_event *touch_down_events;
106 	struct input_event *touch_move_events;
107 	struct input_event *touch_up_events;
108 
109 	/**
110 	 * Tablet events, LITEST_AUTO_ASSIGN is allowed on event values for
111 	 * ABS_X, ABS_Y, ABS_DISTANCE and ABS_PRESSURE.
112 	 */
113 	struct input_event *tablet_proximity_in_events;
114 	struct input_event *tablet_proximity_out_events;
115 	struct input_event *tablet_motion_events;
116 
117 	bool (*tablet_proximity_in)(struct litest_device *d,
118 				    unsigned int tool_type,
119 				    double x, double y,
120 				    struct axis_replacement *axes);
121 	bool (*tablet_proximity_out)(struct litest_device *d, unsigned int tool_type);
122 
123 	/**
124 	 * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
125 	 * for ABS_WHEEL
126 	 */
127 	struct input_event *pad_ring_start_events;
128 	struct input_event *pad_ring_change_events;
129 	struct input_event *pad_ring_end_events;
130 
131 	/**
132 	 * Pad events, LITEST_AUTO_ASSIGN is allowed on event values
133 	 * for ABS_RX
134 	 */
135 	struct input_event *pad_strip_start_events;
136 	struct input_event *pad_strip_change_events;
137 	struct input_event *pad_strip_end_events;
138 
139 	int min[2]; /* x/y axis minimum */
140 	int max[2]; /* x/y axis maximum */
141 
142 	unsigned int tool_type;
143 };
144 
145 struct path {
146 	struct list link;
147 	char *path;
148 	int fd;
149 };
150 
151 struct litest_context {
152 	struct litest_user_data *user_data;
153 	struct list paths;
154 };
155 
156 void litest_set_current_device(struct litest_device *device);
157 int litest_scale(const struct litest_device *d, unsigned int axis, double val);
158 void litest_generic_device_teardown(void);
159 
160 #endif
161