Debian Codegraph @

test/test-load.c

raw
1 /*
2 * Copyright © 2011 Red Hat, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of Red Hat
9 * not be used in advertising or publicity pertaining to distribution
10 * of the software without specific, written prior permission. Red
11 * Hat makes no representations about the suitability of this software
12 * for any purpose. It is provided "as is" without express or implied
13 * warranty.
14 *
15 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 *
23 * Authors:
24 * Peter Hutterer ([email protected])
25 */
26
27 #include "config.h"
28
29 #include <glib.h>
30 #include <stdlib.h>
31
32 #include "libwacom.h"
33 #include "linux/input-event-codes.h"
34
35 struct fixture {
36 WacomDeviceDatabase *db;
37 };
38
39 static WacomDeviceDatabase *
40 load_database(void)
41 {
42 WacomDeviceDatabase *db;
43 const char *datadir;
44
45 datadir = getenv("LIBWACOM_DATA_DIR");
46 if (!datadir)
47 datadir = TOPSRCDIR "/data";
48
49 db = libwacom_database_new_for_path(datadir);
50 if (!db)
51 printf("Failed to load data from %s", datadir);
52
53 g_assert(db);
54 return db;
55 }
56
57 static void
58 fixture_setup(struct fixture *f,
59 gconstpointer user_data)
60 {
61 f->db = load_database();
62 }
63
64 static void
65 fixture_teardown(struct fixture *f,
66 gconstpointer user_data)
67 {
68 libwacom_database_destroy(f->db);
69 }
70
71 static void
72 check_multiple_match(WacomDevice *device)
73 {
74 const WacomMatch **match;
75 int nmatches = 0;
76 int found_bus = 0, found_vendor_id = 0, found_product_id = 0;
77
78 for (match = libwacom_get_matches(device); *match; match++) {
79 nmatches++;
80 if (libwacom_match_get_bustype(*match) == libwacom_get_bustype(device))
81 found_bus = 1;
82 if ((int)libwacom_match_get_vendor_id(*match) ==
83 libwacom_get_vendor_id(device))
84 found_vendor_id = 1;
85 if ((int)libwacom_match_get_product_id(*match) ==
86 libwacom_get_product_id(device))
87 found_product_id = 1;
88 }
89
90 g_assert_cmpint(nmatches, ==, 2);
91 g_assert_true(found_bus);
92 g_assert_true(found_vendor_id);
93 g_assert_true(found_product_id);
94 }
95
96 static void
97 test_invalid_device(struct fixture *f,
98 gconstpointer user_data)
99 {
100 WacomDevice *device = libwacom_new_from_usbid(f->db, 0, 0, NULL);
101 g_assert_null(device);
102 }
103
104 static void
105 test_intuos4(struct fixture *f,
106 gconstpointer user_data)
107 {
108 WacomDevice *device = libwacom_new_from_usbid(f->db, 0x56a, 0x00bc, NULL);
109 g_assert_nonnull(device);
110
111 g_assert_cmpstr(libwacom_get_name(device), ==, "Wacom Intuos4 WL");
112 #pragma GCC diagnostic push
113 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
114 g_assert_cmpint(libwacom_get_class(device), ==, WCLASS_INTUOS4);
115 #pragma GCC diagnostic pop
116 g_assert_cmpint(libwacom_get_vendor_id(device), ==, 0x56a);
117 g_assert_cmpint(libwacom_get_product_id(device), ==, 0xbc);
118 g_assert_cmpint(libwacom_get_bustype(device), ==, WBUSTYPE_USB);
119 g_assert_cmpint(libwacom_get_num_buttons(device), ==, 9);
120 g_assert_true(libwacom_has_stylus(device));
121 g_assert_true(libwacom_is_reversible(device));
122 g_assert_false(libwacom_has_touch(device));
123 #pragma GCC diagnostic push
124 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
125 g_assert_true(libwacom_has_ring(device));
126 g_assert_false(libwacom_has_ring2(device));
127 #pragma GCC diagnostic pop
128 g_assert_cmpint(libwacom_get_num_rings(device), ==, 1);
129 g_assert_false(libwacom_has_touchswitch(device));
130 g_assert_cmpint(libwacom_get_num_strips(device), ==, 0);
131 g_assert_cmpint(libwacom_get_num_dials(device), ==, 0);
132 g_assert_cmpint(libwacom_get_integration_flags(device),
133 ==,
134 WACOM_DEVICE_INTEGRATED_NONE);
135 g_assert_cmpint(libwacom_get_width(device), ==, 8);
136 g_assert_cmpint(libwacom_get_height(device), ==, 5);
137
138 check_multiple_match(device);
139
140 libwacom_destroy(device);
141 }
142
143 static void
144 test_intuos4_wl(struct fixture *f,
145 gconstpointer user_data)
146 {
147 WacomDevice *device = libwacom_new_from_usbid(f->db, 0x56a, 0x00b9, NULL);
148 g_assert_nonnull(device);
149
150 g_assert_true(libwacom_get_button_flag(device, 'A') &
151 WACOM_BUTTON_RING_MODESWITCH);
152 g_assert_true(libwacom_get_button_flag(device, 'I') & WACOM_BUTTON_OLED);
153 #if 0
154 /* disabled - needs subprocesses testing but invalid data handling
155 is better handled in a separate test suite */
156 /*
157 * I4 WL has only 9 buttons, asking for a 10th button will raise a warning
158 * in libwacom_get_button_flag() which is expected.
159 */
160 printf("Following critical warning in libwacom_get_button_flag() is expected\n");
161 g_assert_cmpint(libwacom_get_button_flag(device, 'J'), ==, WACOM_BUTTON_NONE);
162 #endif
163 g_assert_cmpint(libwacom_get_ring_num_modes(device), ==, 4);
164
165 libwacom_destroy(device);
166 }
167
168 static void
169 test_cintiq24hd(struct fixture *f,
170 gconstpointer user_data)
171 {
172 WacomDevice *device = libwacom_new_from_usbid(f->db, 0x56a, 0x00f4, NULL);
173 g_assert_nonnull(device);
174
175 g_assert_cmpint(libwacom_get_ring_num_modes(device), ==, 3);
176 g_assert_cmpint(libwacom_get_ring2_num_modes(device), ==, 3);
177
178 libwacom_destroy(device);
179 }
180
181 static void
182 test_cintiq21ux(struct fixture *f,
183 gconstpointer user_data)
184 {
185 WacomDevice *device = libwacom_new_from_usbid(f->db, 0x56a, 0x00cc, NULL);
186 g_assert_nonnull(device);
187
188 g_assert_cmpint(libwacom_get_num_strips(device), ==, 2);
189 g_assert_cmpint(libwacom_get_num_dials(device), ==, 0);
190 libwacom_destroy(device);
191 }
192
193 static void
194 test_wacf004(struct fixture *f,
195 gconstpointer user_data)
196 {
197 WacomDevice *device =
198 libwacom_new_from_name(f->db, "Wacom Serial Tablet WACf004", NULL);
199 g_assert_nonnull(device);
200
201 g_assert_true(libwacom_get_integration_flags(device) &
202 WACOM_DEVICE_INTEGRATED_DISPLAY);
203 g_assert_true(libwacom_get_integration_flags(device) &
204 WACOM_DEVICE_INTEGRATED_SYSTEM);
205 g_assert_null(libwacom_get_model_name(device));
206
207 libwacom_destroy(device);
208 }
209
210 static void
211 test_cintiq24hdt(struct fixture *f,
212 gconstpointer user_data)
213 {
214 WacomDevice *device = libwacom_new_from_usbid(f->db, 0x56a, 0x00f8, NULL);
215 const WacomMatch *match;
216
217 g_assert_nonnull(device);
218 #pragma GCC diagnostic push
219 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
220 g_assert_cmpint(libwacom_get_class(device), ==, WCLASS_CINTIQ);
221 #pragma GCC diagnostic pop
222
223 /* 24HDT has one paired device */
224 match = libwacom_get_paired_device(device);
225 g_assert_nonnull(match);
226 g_assert_cmpint(libwacom_match_get_vendor_id(match), ==, 0x56a);
227 g_assert_cmpint(libwacom_match_get_product_id(match), ==, 0xf6);
228 g_assert_cmpint(libwacom_match_get_bustype(match), ==, WBUSTYPE_USB);
229
230 libwacom_destroy(device);
231 }
232
233 static void
234 test_cintiq13hd(struct fixture *f,
235 gconstpointer user_data)
236 {
237 WacomDevice *device = libwacom_new_from_name(f->db, "Wacom Cintiq 13HD", NULL);
238 g_assert_nonnull(device);
239 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'A'), ==, BTN_0);
240 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'B'), ==, BTN_1);
241 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'C'), ==, BTN_2);
242 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'D'), ==, BTN_3);
243 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'E'), ==, BTN_4);
244 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'F'), ==, BTN_5);
245 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'G'), ==, BTN_6);
246 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'H'), ==, BTN_7);
247 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'I'), ==, BTN_8);
248 g_assert_cmpstr(libwacom_get_model_name(device), ==, "DTK-1300");
249
250 libwacom_destroy(device);
251 }
252
253 static void
254 test_cintiqpro13(struct fixture *f,
255 gconstpointer user_data)
256 {
257 WacomDevice *device =
258 libwacom_new_from_name(f->db, "Wacom Cintiq Pro 13", NULL);
259 g_assert_nonnull(device);
260 g_assert_cmpint(libwacom_get_num_keys(device), ==, 5);
261
262 libwacom_destroy(device);
263 }
264
265 static void
266 test_bamboopen(struct fixture *f,
267 gconstpointer user_data)
268 {
269 WacomDevice *device = libwacom_new_from_name(f->db, "Wacom Bamboo Pen", NULL);
270 g_assert_nonnull(device);
271 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'A'), ==, BTN_BACK);
272 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'B'), ==, BTN_FORWARD);
273 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'C'), ==, BTN_LEFT);
274 g_assert_cmpint(libwacom_get_button_evdev_code(device, 'D'), ==, BTN_RIGHT);
275 g_assert_cmpstr(libwacom_get_model_name(device), ==, "MTE-450");
276
277 libwacom_destroy(device);
278 }
279
280 static void
281 test_dellcanvas(struct fixture *f,
282 gconstpointer user_data)
283 {
284 WacomDevice *device = libwacom_new_from_name(f->db, "Dell Canvas 27", NULL);
285
286 g_assert_nonnull(device);
287 g_assert_true(libwacom_get_integration_flags(device) &
288 WACOM_DEVICE_INTEGRATED_DISPLAY);
289 g_assert_false(libwacom_get_integration_flags(device) &
290 WACOM_DEVICE_INTEGRATED_SYSTEM);
291
292 libwacom_destroy(device);
293 }
294
295 static void
296 test_isdv4_4800(struct fixture *f,
297 gconstpointer user_data)
298 {
299 WacomDevice *device = libwacom_new_from_usbid(f->db, 0x56a, 0x4800, NULL);
300 g_assert_nonnull(device);
301
302 g_assert_true(libwacom_get_integration_flags(device) &
303 WACOM_DEVICE_INTEGRATED_DISPLAY);
304 g_assert_true(libwacom_get_integration_flags(device) &
305 WACOM_DEVICE_INTEGRATED_SYSTEM);
306 g_assert_null(libwacom_get_model_name(device));
307 g_assert_cmpint(libwacom_get_vendor_id(device), ==, 0x56a);
308 g_assert_cmpint(libwacom_get_product_id(device), ==, 0x4800);
309 g_assert_cmpint(libwacom_get_num_buttons(device), ==, 0);
310
311 libwacom_destroy(device);
312 }
313
314 int
315 main(int argc,
316 char **argv)
317 {
318 g_test_init(&argc, &argv, NULL);
319 g_test_set_nonfatal_assertions();
320
321 g_test_add("/load/0000:0000",
322 struct fixture,
323 NULL,
324 fixture_setup,
325 test_invalid_device,
326 fixture_teardown);
327 g_test_add("/load/056a:00bc",
328 struct fixture,
329 NULL,
330 fixture_setup,
331 test_intuos4,
332 fixture_teardown);
333 g_test_add("/load/056a:00b8",
334 struct fixture,
335 NULL,
336 fixture_setup,
337 test_intuos4_wl,
338 fixture_teardown);
339 g_test_add("/load/056a:00f4",
340 struct fixture,
341 NULL,
342 fixture_setup,
343 test_cintiq24hd,
344 fixture_teardown);
345 g_test_add("/load/056a:00cc",
346 struct fixture,
347 NULL,
348 fixture_setup,
349 test_cintiq21ux,
350 fixture_teardown);
351 g_test_add("/load/056a:00f8",
352 struct fixture,
353 NULL,
354 fixture_setup,
355 test_cintiq24hdt,
356 fixture_teardown);
357 g_test_add("/load/056a:0304",
358 struct fixture,
359 NULL,
360 fixture_setup,
361 test_cintiq13hd,
362 fixture_teardown);
363 g_test_add("/load/056a:034f",
364 struct fixture,
365 NULL,
366 fixture_setup,
367 test_cintiqpro13,
368 fixture_teardown);
369 g_test_add("/load/056a:0065",
370 struct fixture,
371 NULL,
372 fixture_setup,
373 test_bamboopen,
374 fixture_teardown);
375 g_test_add("/load/056a:4200",
376 struct fixture,
377 NULL,
378 fixture_setup,
379 test_dellcanvas,
380 fixture_teardown);
381 g_test_add("/load/056a:WACf004",
382 struct fixture,
383 NULL,
384 fixture_setup,
385 test_wacf004,
386 fixture_teardown);
387 g_test_add("/load/056a:4800",
388 struct fixture,
389 NULL,
390 fixture_setup,
391 test_isdv4_4800,
392 fixture_teardown);
393
394 return g_test_run();
395 }
396
397 /* vim: set noexpandtab tabstop=8 shiftwidth=8: */