Debian Codegraph @

test/test-quirks.c

raw
1 /*
2 * Copyright © 2018 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
26 #include <libinput.h>
27
28 #include "libinput-util.h"
29 #include "litest.h"
30 #include "quirks.h"
31
32 static void
33 log_handler(struct libinput *this_is_null,
34 enum libinput_log_priority priority,
35 const char *format,
36 va_list args)
37 {
38 #if 0
39 vprintf(format, args);
40 #endif
41 }
42
43 struct data_dir {
44 char *dirname;
45 char *filename;
46 };
47
48 static struct data_dir *
49 data_dir_new(const char *file_content)
50 {
51 struct data_dir *dir = zalloc(sizeof(*dir));
52 char dirname[PATH_MAX] = "/tmp/litest-quirk-test-XXXXXX";
53
54 litest_assert_notnull(mkdtemp(dirname));
55 dir->dirname = safe_strdup(dirname);
56
57 if (file_content) {
58 char *filename = strdup_printf("%s/testfile.quirks", dirname);
59
60 _autofclose_ FILE *fp = fopen(filename, "w+");
61 #ifndef __clang_analyzer__
62 litest_assert_notnull(fp);
63 #else
64 assert(fp);
65 #endif
66 int rc = fputs(file_content, fp); // NOLINT: unix.Stream
67 litest_assert_errno_success(rc);
68 dir->filename = filename;
69 }
70
71 return dir;
72 }
73
74 static void
75 data_dir_destroy(struct data_dir *dd)
76 {
77 if (dd->filename) {
78 unlink(dd->filename);
79 free(dd->filename);
80 }
81 if (dd->dirname) {
82 rmdir(dd->dirname);
83 free(dd->dirname);
84 }
85 free(dd);
86 }
87
88 DEFINE_DESTROY_CLEANUP_FUNC(data_dir);
89
90 START_TEST(quirks_invalid_dir)
91 {
92 _unref_(quirks_context) *ctx = quirks_init_subsystem("/does-not-exist",
93 NULL,
94 log_handler,
95 NULL,
96 QLOG_LIBINPUT_LOGGING);
97 litest_assert(ctx == NULL);
98 }
99 END_TEST
100
101 START_TEST(quirks_empty_dir)
102 {
103 _destroy_(data_dir) *dd = data_dir_new(NULL);
104 _unref_(quirks_context) *ctx = quirks_init_subsystem(dd->dirname,
105 NULL,
106 log_handler,
107 NULL,
108 QLOG_LIBINPUT_LOGGING);
109 litest_assert(ctx == NULL);
110 }
111 END_TEST
112
113 START_TEST(quirks_section_empty)
114 {
115 const char quirks_file[] = "[Empty Section]";
116 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
117
118 _unref_(quirks_context) *ctx =
119 quirks_init_subsystem(dd->dirname,
120 NULL,
121 log_handler,
122 NULL,
123 QLOG_CUSTOM_LOG_PRIORITIES);
124 litest_assert(ctx == NULL);
125 }
126 END_TEST
127
128 START_TEST(quirks_section_double)
129 {
130 const char quirks_file[] = "[Section name]";
131 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
132
133 _unref_(quirks_context) *ctx =
134 quirks_init_subsystem(dd->dirname,
135 NULL,
136 log_handler,
137 NULL,
138 QLOG_CUSTOM_LOG_PRIORITIES);
139 litest_assert(ctx == NULL);
140 }
141 END_TEST
142
143 START_TEST(quirks_section_missing_match)
144 {
145 const char quirks_file[] =
146 "[Section name]\n"
147 "AttrSizeHint=10x10\n";
148 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
149
150 _unref_(quirks_context) *ctx =
151 quirks_init_subsystem(dd->dirname,
152 NULL,
153 log_handler,
154 NULL,
155 QLOG_CUSTOM_LOG_PRIORITIES);
156 litest_assert(ctx == NULL);
157 }
158 END_TEST
159
160 START_TEST(quirks_section_missing_attr)
161 {
162 const char quirks_file[] =
163 "[Section name]\n"
164 "MatchUdevType=mouse\n";
165 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
166
167 _unref_(quirks_context) *ctx =
168 quirks_init_subsystem(dd->dirname,
169 NULL,
170 log_handler,
171 NULL,
172 QLOG_CUSTOM_LOG_PRIORITIES);
173 litest_assert(ctx == NULL);
174 }
175 END_TEST
176
177 START_TEST(quirks_section_match_after_attr)
178 {
179 const char quirks_file[] =
180 "[Section name]\n"
181 "MatchUdevType=mouse\n"
182 "AttrSizeHint=10x10\n"
183 "MatchName=mouse\n";
184 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
185
186 _unref_(quirks_context) *ctx =
187 quirks_init_subsystem(dd->dirname,
188 NULL,
189 log_handler,
190 NULL,
191 QLOG_CUSTOM_LOG_PRIORITIES);
192 litest_assert(ctx == NULL);
193 }
194 END_TEST
195
196 START_TEST(quirks_section_duplicate_match)
197 {
198 const char quirks_file[] =
199 "[Section name]\n"
200 "MatchUdevType=mouse\n"
201 "MatchUdevType=mouse\n"
202 "AttrSizeHint=10x10\n";
203 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
204
205 _unref_(quirks_context) *ctx =
206 quirks_init_subsystem(dd->dirname,
207 NULL,
208 log_handler,
209 NULL,
210 QLOG_CUSTOM_LOG_PRIORITIES);
211 litest_assert(ctx == NULL);
212 }
213 END_TEST
214
215 START_TEST(quirks_section_duplicate_attr)
216 {
217 /* This shouldn't be allowed but the current parser
218 is happy with it */
219 const char quirks_file[] =
220 "[Section name]\n"
221 "MatchUdevType=mouse\n"
222 "AttrSizeHint=10x10\n"
223 "AttrSizeHint=10x10\n";
224 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
225
226 _unref_(quirks_context) *ctx =
227 quirks_init_subsystem(dd->dirname,
228 NULL,
229 log_handler,
230 NULL,
231 QLOG_CUSTOM_LOG_PRIORITIES);
232 litest_assert_notnull(ctx);
233 }
234 END_TEST
235
236 START_TEST(quirks_parse_error_section)
237 {
238 const char quirks_file[] =
239 "[Section Missing Bracket\n"
240 "MatchUdevType=mouse\n"
241 "AttrSizeHint=10x10\n";
242 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
243
244 _unref_(quirks_context) *ctx =
245 quirks_init_subsystem(dd->dirname,
246 NULL,
247 log_handler,
248 NULL,
249 QLOG_CUSTOM_LOG_PRIORITIES);
250 litest_assert(ctx == NULL);
251 }
252 END_TEST
253
254 START_TEST(quirks_parse_error_trailing_whitespace)
255 {
256 const char quirks_file[] =
257 "[Section name]\n"
258 "MatchUdevType=mouse \n"
259 "AttrSizeHint=10x10\n";
260 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
261
262 _unref_(quirks_context) *ctx =
263 quirks_init_subsystem(dd->dirname,
264 NULL,
265 log_handler,
266 NULL,
267 QLOG_CUSTOM_LOG_PRIORITIES);
268 litest_assert(ctx == NULL);
269 }
270 END_TEST
271
272 START_TEST(quirks_parse_error_unknown_match)
273 {
274 const char quirks_file[] =
275 "[Section name]\n"
276 "Matchblahblah=mouse\n"
277 "AttrSizeHint=10x10\n";
278 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
279
280 _unref_(quirks_context) *ctx =
281 quirks_init_subsystem(dd->dirname,
282 NULL,
283 log_handler,
284 NULL,
285 QLOG_CUSTOM_LOG_PRIORITIES);
286 litest_assert(ctx == NULL);
287 }
288 END_TEST
289
290 START_TEST(quirks_parse_error_unknown_attr)
291 {
292 const char quirks_file[] =
293 "[Section name]\n"
294 "MatchUdevType=mouse\n"
295 "Attrblahblah=10x10\n";
296 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
297
298 _unref_(quirks_context) *ctx =
299 quirks_init_subsystem(dd->dirname,
300 NULL,
301 log_handler,
302 NULL,
303 QLOG_CUSTOM_LOG_PRIORITIES);
304 litest_assert(ctx == NULL);
305 }
306 END_TEST
307
308 START_TEST(quirks_parse_error_unknown_model)
309 {
310 const char quirks_file[] =
311 "[Section name]\n"
312 "MatchUdevType=mouse\n"
313 "Modelblahblah=1\n";
314 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
315
316 _unref_(quirks_context) *ctx =
317 quirks_init_subsystem(dd->dirname,
318 NULL,
319 log_handler,
320 NULL,
321 QLOG_CUSTOM_LOG_PRIORITIES);
322 litest_assert(ctx == NULL);
323 }
324 END_TEST
325
326 START_TEST(quirks_parse_error_unknown_prefix)
327 {
328 const char quirks_file[] =
329 "[Section name]\n"
330 "MatchUdevType=mouse\n"
331 "Fooblahblah=10x10\n";
332 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
333
334 _unref_(quirks_context) *ctx =
335 quirks_init_subsystem(dd->dirname,
336 NULL,
337 log_handler,
338 NULL,
339 QLOG_CUSTOM_LOG_PRIORITIES);
340 litest_assert(ctx == NULL);
341 }
342 END_TEST
343
344 START_TEST(quirks_parse_error_model_not_one)
345 {
346 const char quirks_file[] =
347 "[Section name]\n"
348 "MatchUdevType=mouse\n"
349 "ModelAppleTouchpad=true\n";
350 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
351
352 _unref_(quirks_context) *ctx =
353 quirks_init_subsystem(dd->dirname,
354 NULL,
355 log_handler,
356 NULL,
357 QLOG_CUSTOM_LOG_PRIORITIES);
358 }
359 END_TEST
360
361 START_TEST(quirks_parse_comment_inline)
362 {
363 const char quirks_file[] =
364 "[Section name] # some inline comment\n"
365 "MatchUdevType=mouse\t # another inline comment\n"
366 "ModelAppleTouchpad=1#\n";
367 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
368
369 _unref_(quirks_context) *ctx =
370 quirks_init_subsystem(dd->dirname,
371 NULL,
372 log_handler,
373 NULL,
374 QLOG_CUSTOM_LOG_PRIORITIES);
375 litest_assert_notnull(ctx);
376 }
377 END_TEST
378
379 START_TEST(quirks_parse_comment_empty)
380 {
381 const char quirks_file[] =
382 "[Section name]\n"
383 "#\n"
384 " #\n"
385 "MatchUdevType=mouse\n"
386 "ModelAppleTouchpad=1\n";
387 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
388
389 _unref_(quirks_context) *ctx =
390 quirks_init_subsystem(dd->dirname,
391 NULL,
392 log_handler,
393 NULL,
394 QLOG_CUSTOM_LOG_PRIORITIES);
395 litest_assert_notnull(ctx);
396 }
397 END_TEST
398
399 START_TEST(quirks_parse_string_quotes_single)
400 {
401 const char quirks_file[] =
402 "[Section name]\n"
403 "MatchUdevType=mouse\n"
404 "AttrKeyboardIntegration='internal'\n";
405 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
406
407 _unref_(quirks_context) *ctx =
408 quirks_init_subsystem(dd->dirname,
409 NULL,
410 log_handler,
411 NULL,
412 QLOG_CUSTOM_LOG_PRIORITIES);
413 litest_assert(ctx == NULL);
414 }
415 END_TEST
416
417 START_TEST(quirks_parse_string_quotes_double)
418 {
419 const char quirks_file[] =
420 "[Section name]\n"
421 "MatchUdevType=mouse\n"
422 "AttrKeyboardIntegration=\"internal\"\n";
423 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
424
425 _unref_(quirks_context) *ctx =
426 quirks_init_subsystem(dd->dirname,
427 NULL,
428 log_handler,
429 NULL,
430 QLOG_CUSTOM_LOG_PRIORITIES);
431 litest_assert(ctx == NULL);
432 }
433 END_TEST
434
435 START_TEST(quirks_parse_bustype)
436 {
437 const char quirks_file[] =
438 "[Section name]\n"
439 "MatchBus=usb\n"
440 "ModelAppleTouchpad=1\n"
441 "\n"
442 "[Section name]\n"
443 "MatchBus=bluetooth\n"
444 "ModelAppleTouchpad=1\n"
445 "\n"
446 "[Section name]\n"
447 "MatchBus=i2c\n"
448 "ModelAppleTouchpad=1\n"
449 "\n"
450 "[Section name]\n"
451 "MatchBus=rmi\n"
452 "ModelAppleTouchpad=1\n"
453 "\n"
454 "[Section name]\n"
455 "MatchBus=ps2\n"
456 "ModelAppleTouchpad=1\n";
457 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
458
459 _unref_(quirks_context) *ctx =
460 quirks_init_subsystem(dd->dirname,
461 NULL,
462 log_handler,
463 NULL,
464 QLOG_CUSTOM_LOG_PRIORITIES);
465 litest_assert_notnull(ctx);
466 }
467 END_TEST
468
469 START_TEST(quirks_parse_bustype_invalid)
470 {
471 const char quirks_file[] =
472 "[Section name]\n"
473 "MatchBus=venga\n"
474 "ModelAppleTouchpad=1\n";
475 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
476
477 _unref_(quirks_context) *ctx =
478 quirks_init_subsystem(dd->dirname,
479 NULL,
480 log_handler,
481 NULL,
482 QLOG_CUSTOM_LOG_PRIORITIES);
483 litest_assert(ctx == NULL);
484 }
485 END_TEST
486
487 START_TEST(quirks_parse_vendor)
488 {
489 const char quirks_file[] =
490 "[Section name]\n"
491 "MatchVendor=0x0000\n"
492 "ModelAppleTouchpad=1\n"
493 "\n"
494 "[Section name]\n"
495 "MatchVendor=0x0001\n"
496 "ModelAppleTouchpad=1\n"
497 "\n"
498 "[Section name]\n"
499 "MatchVendor=0x2343\n"
500 "ModelAppleTouchpad=1\n";
501 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
502
503 _unref_(quirks_context) *ctx =
504 quirks_init_subsystem(dd->dirname,
505 NULL,
506 log_handler,
507 NULL,
508 QLOG_CUSTOM_LOG_PRIORITIES);
509 litest_assert_notnull(ctx);
510 }
511 END_TEST
512
513 START_TEST(quirks_parse_vendor_invalid)
514 {
515 const char *quirks_file[] = {
516 "[Section name]\n"
517 "MatchVendor=-1\n"
518 "ModelAppleTouchpad=1\n",
519 "[Section name]\n"
520 "MatchVendor=abc\n"
521 "ModelAppleTouchpad=1\n",
522 "[Section name]\n"
523 "MatchVendor=0xFFFFF\n"
524 "ModelAppleTouchpad=1\n",
525 "[Section name]\n"
526 "MatchVendor=123\n"
527 "ModelAppleTouchpad=1\n",
528 };
529
530 ARRAY_FOR_EACH(quirks_file, qf) {
531 _destroy_(data_dir) *dd = data_dir_new(*qf);
532
533 _unref_(quirks_context) *ctx =
534 quirks_init_subsystem(dd->dirname,
535 NULL,
536 log_handler,
537 NULL,
538 QLOG_CUSTOM_LOG_PRIORITIES);
539 litest_assert(ctx == NULL);
540 }
541 }
542 END_TEST
543
544 START_TEST(quirks_parse_product)
545 {
546 const char quirks_file[] =
547 "[Section name]\n"
548 "MatchProduct=0x12AB\n"
549 "ModelAppleTouchpad=1\n"
550 "\n"
551 "[Section name]\n"
552 "MatchProduct=0x0001;0x1234;0xABCD\n"
553 "ModelAppleTouchpad=1\n"
554 "\n"
555 "[Section name]\n"
556 "MatchProduct=0x2343\n"
557 "ModelAppleTouchpad=1\n";
558 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
559
560 _unref_(quirks_context) *ctx =
561 quirks_init_subsystem(dd->dirname,
562 NULL,
563 log_handler,
564 NULL,
565 QLOG_CUSTOM_LOG_PRIORITIES);
566 litest_assert_notnull(ctx);
567 }
568 END_TEST
569
570 START_TEST(quirks_parse_product_too_many)
571 {
572 const char prologue[] =
573 "[Section name]\n"
574 "MatchProduct=0x12AB\n"
575 "ModelAppleTouchpad=1\n"
576 "\n"
577 "[Section name]\n"
578 "MatchProduct=";
579 const char epilogue[] =
580 "\n"
581 "ModelAppleTouchpad=1\n"
582 "\n"
583 "[Section name]\n"
584 "MatchProduct=0x2343\n"
585 "ModelAppleTouchpad=1\n";
586
587 char matches[4096] = { 0 };
588
589 for (int i = 0; i < 128; i++) {
590 int len = strlen(matches);
591 int remaining = sizeof(matches) - len;
592 snprintf(&matches[len], remaining, "0x%04X", i);
593 }
594
595 char *quirks_file = strdup_printf("%s%s%s", prologue, matches, epilogue);
596 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
597
598 free(quirks_file);
599
600 /* This test will only blow up in valgrind/asan */
601 _unref_(quirks_context) *ctx =
602 quirks_init_subsystem(dd->dirname,
603 NULL,
604 log_handler,
605 NULL,
606 QLOG_CUSTOM_LOG_PRIORITIES);
607 litest_assert(ctx == NULL);
608 }
609 END_TEST
610
611 START_TEST(quirks_parse_product_invalid)
612 {
613 const char *quirks_file[] = {
614 "[Section name]\n"
615 "MatchProduct=-1\n"
616 "ModelAppleTouchpad=1\n",
617 "[Section name]\n"
618 "MatchProduct=abc\n"
619 "ModelAppleTouchpad=1\n",
620 "[Section name]\n"
621 "MatchProduct=0xFFFFF\n"
622 "ModelAppleTouchpad=1\n",
623 "[Section name]\n"
624 "MatchProduct=123\n"
625 "ModelAppleTouchpad=1\n",
626 };
627
628 ARRAY_FOR_EACH(quirks_file, qf) {
629 _destroy_(data_dir) *dd = data_dir_new(*qf);
630
631 _unref_(quirks_context) *ctx =
632 quirks_init_subsystem(dd->dirname,
633 NULL,
634 log_handler,
635 NULL,
636 QLOG_CUSTOM_LOG_PRIORITIES);
637 litest_assert(ctx == NULL);
638 }
639 }
640 END_TEST
641
642 START_TEST(quirks_parse_version)
643 {
644 const char quirks_file[] =
645 "[Section name]\n"
646 "MatchVersion=0x0000\n"
647 "ModelAppleTouchpad=1\n"
648 "\n"
649 "[Section name]\n"
650 "MatchVersion=0x0001\n"
651 "ModelAppleTouchpad=1\n"
652 "\n"
653 "[Section name]\n"
654 "MatchVersion=0x2343\n"
655 "ModelAppleTouchpad=1\n";
656 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
657
658 _unref_(quirks_context) *ctx =
659 quirks_init_subsystem(dd->dirname,
660 NULL,
661 log_handler,
662 NULL,
663 QLOG_CUSTOM_LOG_PRIORITIES);
664 litest_assert_notnull(ctx);
665 }
666 END_TEST
667
668 START_TEST(quirks_parse_version_invalid)
669 {
670 const char *quirks_file[] = {
671 "[Section name]\n"
672 "MatchVersion=-1\n"
673 "ModelAppleTouchpad=1\n",
674 "[Section name]\n"
675 "MatchVersion=abc\n"
676 "ModelAppleTouchpad=1\n",
677 "[Section name]\n"
678 "MatchVersion=0xFFFFF\n"
679 "ModelAppleTouchpad=1\n",
680 "[Section name]\n"
681 "MatchVersion=123\n"
682 "ModelAppleTouchpad=1\n",
683 };
684
685 ARRAY_FOR_EACH(quirks_file, qf) {
686 _destroy_(data_dir) *dd = data_dir_new(*qf);
687
688 _unref_(quirks_context) *ctx =
689 quirks_init_subsystem(dd->dirname,
690 NULL,
691 log_handler,
692 NULL,
693 QLOG_CUSTOM_LOG_PRIORITIES);
694 litest_assert(ctx == NULL);
695 }
696 }
697 END_TEST
698
699 START_TEST(quirks_parse_name)
700 {
701 const char quirks_file[] =
702 "[Section name]\n"
703 "MatchName=1235\n"
704 "ModelAppleTouchpad=1\n"
705 "\n"
706 "[Section name]\n"
707 "MatchName=abc\n"
708 "ModelAppleTouchpad=1\n"
709 "\n"
710 "[Section name]\n"
711 "MatchName=*foo\n"
712 "ModelAppleTouchpad=1\n"
713 "\n"
714 "[Section name]\n"
715 "MatchName=foo*\n"
716 "ModelAppleTouchpad=1\n"
717 "\n"
718 "[Section name]\n"
719 "MatchName=foo[]\n"
720 "ModelAppleTouchpad=1\n"
721 "\n"
722 "[Section name]\n"
723 "MatchName=*foo*\n"
724 "ModelAppleTouchpad=1\n";
725 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
726
727 _unref_(quirks_context) *ctx =
728 quirks_init_subsystem(dd->dirname,
729 NULL,
730 log_handler,
731 NULL,
732 QLOG_CUSTOM_LOG_PRIORITIES);
733 litest_assert_notnull(ctx);
734 }
735 END_TEST
736
737 START_TEST(quirks_parse_name_invalid)
738 {
739 const char *quirks_file[] = {
740 "[Section name]\n"
741 "MatchName=\n"
742 "ModelAppleTouchpad=1\n",
743 };
744
745 ARRAY_FOR_EACH(quirks_file, qf) {
746 _destroy_(data_dir) *dd = data_dir_new(*qf);
747
748 _unref_(quirks_context) *ctx =
749 quirks_init_subsystem(dd->dirname,
750 NULL,
751 log_handler,
752 NULL,
753 QLOG_CUSTOM_LOG_PRIORITIES);
754 litest_assert(ctx == NULL);
755 }
756 }
757 END_TEST
758
759 START_TEST(quirks_parse_uniq)
760 {
761 const char quirks_file[] =
762 "[Section Uniq]\n"
763 "MatchUniq=1235\n"
764 "ModelAppleTouchpad=1\n"
765 "\n"
766 "[Section Uniq]\n"
767 "MatchUniq=abc\n"
768 "ModelAppleTouchpad=1\n"
769 "\n"
770 "[Section Uniq]\n"
771 "MatchUniq=*foo\n"
772 "ModelAppleTouchpad=1\n"
773 "\n"
774 "[Section Uniq]\n"
775 "MatchUniq=foo*\n"
776 "ModelAppleTouchpad=1\n"
777 "\n"
778 "[Section Uniq]\n"
779 "MatchUniq=foo[]\n"
780 "ModelAppleTouchpad=1\n"
781 "\n"
782 "[Section Uniq]\n"
783 "MatchUniq=*foo*\n"
784 "ModelAppleTouchpad=1\n";
785 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
786
787 _unref_(quirks_context) *ctx =
788 quirks_init_subsystem(dd->dirname,
789 NULL,
790 log_handler,
791 NULL,
792 QLOG_CUSTOM_LOG_PRIORITIES);
793 litest_assert_notnull(ctx);
794 }
795 END_TEST
796
797 START_TEST(quirks_parse_uniq_invalid)
798 {
799 const char *quirks_file[] = {
800 "[Section name]\n"
801 "MatchUniq=\n"
802 "ModelAppleTouchpad=1\n",
803 };
804
805 ARRAY_FOR_EACH(quirks_file, qf) {
806 _destroy_(data_dir) *dd = data_dir_new(*qf);
807
808 _unref_(quirks_context) *ctx =
809 quirks_init_subsystem(dd->dirname,
810 NULL,
811 log_handler,
812 NULL,
813 QLOG_CUSTOM_LOG_PRIORITIES);
814 litest_assert(ctx == NULL);
815 }
816 }
817 END_TEST
818
819 START_TEST(quirks_parse_udev)
820 {
821 const char quirks_file[] =
822 "[Section name]\n"
823 "MatchUdevType=touchpad\n"
824 "ModelAppleTouchpad=1\n"
825 "\n"
826 "[Section name]\n"
827 "MatchUdevType=mouse\n"
828 "ModelAppleTouchpad=1\n"
829 "\n"
830 "[Section name]\n"
831 "MatchUdevType=pointingstick\n"
832 "ModelAppleTouchpad=1\n"
833 "\n"
834 "[Section name]\n"
835 "MatchUdevType=tablet\n"
836 "ModelAppleTouchpad=1\n"
837 "\n"
838 "[Section name]\n"
839 "MatchUdevType=tablet-pad\n"
840 "ModelAppleTouchpad=1\n"
841 "\n"
842 "[Section name]\n"
843 "MatchUdevType=keyboard\n"
844 "ModelAppleTouchpad=1\n"
845 "\n"
846 "[Section name]\n"
847 "MatchUdevType=joystick\n"
848 "ModelAppleTouchpad=1\n";
849 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
850
851 _unref_(quirks_context) *ctx =
852 quirks_init_subsystem(dd->dirname,
853 NULL,
854 log_handler,
855 NULL,
856 QLOG_CUSTOM_LOG_PRIORITIES);
857 litest_assert_notnull(ctx);
858 }
859 END_TEST
860
861 START_TEST(quirks_parse_udev_invalid)
862 {
863 const char *quirks_file[] = {
864 "[Section name]\n"
865 "MatchUdevType=blah\n"
866 "ModelAppleTouchpad=1\n",
867 "[Section name]\n"
868 "MatchUdevType=\n"
869 "ModelAppleTouchpad=1\n",
870 "[Section name]\n"
871 "MatchUdevType=123\n"
872 "ModelAppleTouchpad=1\n",
873 };
874
875 ARRAY_FOR_EACH(quirks_file, qf) {
876 _destroy_(data_dir) *dd = data_dir_new(*qf);
877
878 _unref_(quirks_context) *ctx =
879 quirks_init_subsystem(dd->dirname,
880 NULL,
881 log_handler,
882 NULL,
883 QLOG_CUSTOM_LOG_PRIORITIES);
884 litest_assert(ctx == NULL);
885 }
886 }
887 END_TEST
888
889 START_TEST(quirks_parse_dmi)
890 {
891 const char quirks_file[] =
892 "[Section name]\n"
893 "MatchDMIModalias=dmi:*\n"
894 "ModelAppleTouchpad=1\n"
895 "\n"
896 "[Section name]\n"
897 "MatchDMIModalias=dmi:*svn*pn*:\n"
898 "ModelAppleTouchpad=1\n";
899 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
900
901 _unref_(quirks_context) *ctx =
902 quirks_init_subsystem(dd->dirname,
903 NULL,
904 log_handler,
905 NULL,
906 QLOG_CUSTOM_LOG_PRIORITIES);
907 litest_assert_notnull(ctx);
908 }
909 END_TEST
910
911 START_TEST(quirks_parse_dmi_invalid)
912 {
913 const char *quirks_file[] = {
914 "[Section name]\n"
915 "MatchDMIModalias=\n"
916 "ModelAppleTouchpad=1\n",
917 "[Section name]\n"
918 "MatchDMIModalias=*pn*\n"
919 "ModelAppleTouchpad=1\n",
920 "[Section name]\n"
921 "MatchDMIModalias=dmi*pn*\n"
922 "ModelAppleTouchpad=1\n",
923 "[Section name]\n"
924 "MatchDMIModalias=foo\n"
925 "ModelAppleTouchpad=1\n",
926 };
927
928 ARRAY_FOR_EACH(quirks_file, qf) {
929 _destroy_(data_dir) *dd = data_dir_new(*qf);
930
931 _unref_(quirks_context) *ctx =
932 quirks_init_subsystem(dd->dirname,
933 NULL,
934 log_handler,
935 NULL,
936 QLOG_CUSTOM_LOG_PRIORITIES);
937 litest_assert(ctx == NULL);
938 }
939 }
940 END_TEST
941
942 typedef bool (*qparsefunc)(struct quirks *q, enum quirk which, void *data);
943
944 /*
945 Helper for generic testing, matches on a mouse device with the given
946 quirk set to the given string. Creates a data directory, inits the quirks
947 and calls func() to return the value in data. The func has to take the
948 right data, otherwise boom. Usage:
949 rc = test_attr_parse(dev, QUIRK_ATTR_SIZE_HINT,
950 "10x30", quirks_get_dimensions,
951 &some_struct_quirks_dimensions);
952 if (rc == false) // failed to parse
953 else // struct now contains the 10, 30 values
954 */
955 static bool
956 test_attr_parse(struct litest_device *dev,
957 enum quirk which,
958 const char *str,
959 qparsefunc func,
960 void *data)
961 {
962 _unref_(udev_device) *ud =
963 libinput_device_get_udev_device(dev->libinput_device);
964 char buf[512];
965 bool result;
966
967 snprintf(buf,
968 sizeof(buf),
969 "[Section name]\n"
970 "MatchUdevType=mouse\n"
971 "%s=%s\n",
972 quirk_get_name(which),
973 str);
974
975 _destroy_(data_dir) *dd = data_dir_new(buf);
976 _unref_(quirks_context) *ctx =
977 quirks_init_subsystem(dd->dirname,
978 NULL,
979 log_handler,
980 NULL,
981 QLOG_CUSTOM_LOG_PRIORITIES);
982 if (ctx != NULL) {
983 _unref_(quirks) *q = quirks_fetch_for_device(ctx, ud);
984 litest_assert_notnull(q);
985 litest_assert(func(q, which, data));
986 litest_assert(quirks_has_quirk(q, which));
987 result = true;
988 } else {
989 result = false;
990 }
991
992 return result;
993 }
994
995 struct qtest_dim {
996 const char *str;
997 bool success;
998 size_t w, h;
999 };
1000
1001 START_TEST(quirks_parse_dimension_attr)
1002 {
1003 struct litest_device *dev = litest_current_device();
1004 enum quirk attrs[] = {
1005 QUIRK_ATTR_SIZE_HINT,
1006 QUIRK_ATTR_RESOLUTION_HINT,
1007 };
1008 /* clang-format off */
1009 struct qtest_dim test_values[] = {
1010 { "10x10", true, 10, 10 },
1011 { "20x30", true, 20, 30 },
1012 { "-10x30", false, 0, 0 },
1013 { "10:30", false, 0, 0 },
1014 { "30", false, 0, 0 },
1015 { "0x00", false, 0, 0 },
1016 { "0xa0", false, 0, 0 },
1017 };
1018 /* clang-format on */
1019
1020 ARRAY_FOR_EACH(attrs, a) {
1021 ARRAY_FOR_EACH(test_values, t) {
1022 struct quirk_dimensions dim;
1023 bool rc;
1024
1025 rc = test_attr_parse(dev,
1026 *a,
1027 t->str,
1028 (qparsefunc)quirks_get_dimensions,
1029 &dim);
1030 litest_assert_int_eq(rc, t->success);
1031 if (!rc)
1032 continue;
1033
1034 litest_assert_int_eq(dim.x, t->w);
1035 litest_assert_int_eq(dim.y, t->h);
1036 }
1037 }
1038 }
1039 END_TEST
1040
1041 struct qtest_range {
1042 const char *str;
1043 bool success;
1044 int hi, lo;
1045 };
1046
1047 START_TEST(quirks_parse_range_attr)
1048 {
1049 struct litest_device *dev = litest_current_device();
1050 enum quirk attrs[] = {
1051 QUIRK_ATTR_TOUCH_SIZE_RANGE,
1052 QUIRK_ATTR_PRESSURE_RANGE,
1053 };
1054 /* clang-format off */
1055 struct qtest_range test_values[] = {
1056 { "20:10", true, 20, 10 },
1057 { "30:5", true, 30, 5 },
1058 { "30:-10", true, 30, -10 },
1059 { "-30:-100", true, -30, -100 },
1060
1061 { "5:10", false, 0, 0 },
1062 { "5:5", false, 0, 0 },
1063 { "-10:5", false, 0, 0 },
1064 { "-10:-5", false, 0, 0 },
1065 { "10x30", false, 0, 0 },
1066 { "30x10", false, 0, 0 },
1067 { "30", false, 0, 0 },
1068 { "0x00", false, 0, 0 },
1069 { "0xa0", false, 0, 0 },
1070 { "0x10:0x5", false, 0, 0 },
1071 };
1072 /* clang-format on */
1073
1074 ARRAY_FOR_EACH(attrs, a) {
1075 ARRAY_FOR_EACH(test_values, t) {
1076 struct quirk_range r;
1077 bool rc;
1078
1079 rc = test_attr_parse(dev,
1080 *a,
1081 t->str,
1082 (qparsefunc)quirks_get_range,
1083 &r);
1084 litest_assert_int_eq(rc, t->success);
1085 if (!rc)
1086 continue;
1087
1088 litest_assert_int_eq(r.lower, t->lo);
1089 litest_assert_int_eq(r.upper, t->hi);
1090 }
1091 }
1092 }
1093 END_TEST
1094
1095 struct qtest_uint {
1096 const char *str;
1097 bool success;
1098 uint32_t val;
1099 };
1100
1101 START_TEST(quirks_parse_uint_attr)
1102 {
1103 struct litest_device *dev = litest_current_device();
1104 enum quirk attrs[] = {
1105 QUIRK_ATTR_PALM_SIZE_THRESHOLD,
1106 QUIRK_ATTR_PALM_PRESSURE_THRESHOLD,
1107 QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD,
1108 };
1109 /* clang-format off */
1110 struct qtest_uint test_values[] = {
1111 { "10", true, 10 },
1112 { "0", true, 0 },
1113 { "5", true, 5 },
1114 { "65535", true, 65535 },
1115 { "4294967295", true, 4294967295 },
1116 { "-10", false, 0 },
1117 { "0x10", false, 0 },
1118 { "0xab", false, 0 },
1119 { "ab", false, 0 },
1120 };
1121 /* clang-format on */
1122
1123 ARRAY_FOR_EACH(attrs, a) {
1124 ARRAY_FOR_EACH(test_values, t) {
1125 uint32_t v;
1126 bool rc;
1127
1128 rc = test_attr_parse(dev,
1129 *a,
1130 t->str,
1131 (qparsefunc)quirks_get_uint32,
1132 &v);
1133 litest_assert_int_eq(rc, t->success);
1134 if (!rc)
1135 continue;
1136
1137 litest_assert_int_eq(v, t->val);
1138 }
1139 }
1140 }
1141 END_TEST
1142
1143 struct qtest_double {
1144 const char *str;
1145 bool success;
1146 double val;
1147 };
1148
1149 START_TEST(quirks_parse_double_attr)
1150 {
1151 struct litest_device *dev = litest_current_device();
1152 enum quirk attrs[] = {
1153 QUIRK_ATTR_TRACKPOINT_MULTIPLIER,
1154 };
1155 /* clang-format off */
1156 struct qtest_double test_values[] = {
1157 { "10", true, 10.0 },
1158 { "10.0", true, 10.0 },
1159 { "-10.0", true, -10.0 },
1160 { "0", true, 0.0 },
1161 { "0.0", true, 0.0 },
1162 { "5.1", true, 5.1 },
1163 { "-5.9", true, -5.9 },
1164 { "65535", true, 65535 },
1165 { "4294967295", true, 4294967295 },
1166 { "4294967295.123", true, 4294967295.123 },
1167 /* our safe_atoi parses hex even though we don't really want
1168 * to */
1169 { "0x10", false, 0 },
1170 { "0xab", false, 0 },
1171 { "ab", false, 0 },
1172 { "10:5", false, 0 },
1173 { "10x5", false, 0 },
1174 };
1175 /* clang-format on */
1176
1177 ARRAY_FOR_EACH(attrs, a) {
1178 ARRAY_FOR_EACH(test_values, t) {
1179 double v;
1180 bool rc;
1181
1182 rc = test_attr_parse(dev,
1183 *a,
1184 t->str,
1185 (qparsefunc)quirks_get_double,
1186 &v);
1187 litest_assert_int_eq(rc, t->success);
1188 if (!rc)
1189 continue;
1190
1191 litest_assert_double_eq(v, t->val);
1192 }
1193 }
1194 }
1195 END_TEST
1196
1197 struct qtest_str {
1198 const char *str;
1199 enum quirk where;
1200 };
1201
1202 START_TEST(quirks_parse_string_attr)
1203 {
1204 struct litest_device *dev = litest_current_device();
1205 enum quirk attrs[] = {
1206 QUIRK_ATTR_TPKBCOMBO_LAYOUT,
1207 QUIRK_ATTR_LID_SWITCH_RELIABILITY,
1208 QUIRK_ATTR_KEYBOARD_INTEGRATION,
1209 };
1210 /* clang-format off */
1211 struct qtest_str test_values[] = {
1212 { "below", QUIRK_ATTR_TPKBCOMBO_LAYOUT },
1213 { "reliable", QUIRK_ATTR_LID_SWITCH_RELIABILITY },
1214 { "write_open", QUIRK_ATTR_LID_SWITCH_RELIABILITY },
1215 { "internal", QUIRK_ATTR_KEYBOARD_INTEGRATION },
1216 { "external", QUIRK_ATTR_KEYBOARD_INTEGRATION },
1217
1218 { "10", 0 },
1219 { "-10", 0 },
1220 { "0", 0 },
1221 { "", 0 },
1222 { "banana", 0 },
1223 { "honk honk", 0 },
1224 { "0x12", 0 },
1225 { "0xa", 0 },
1226 { "0.0", 0 },
1227 };
1228 /* clang-format on */
1229
1230 ARRAY_FOR_EACH(attrs, a) {
1231 ARRAY_FOR_EACH(test_values, t) {
1232 bool rc;
1233 char *do_not_use; /* freed before we can use it */
1234
1235 rc = test_attr_parse(dev,
1236 *a,
1237 t->str,
1238 (qparsefunc)quirks_get_string,
1239 &do_not_use);
1240 if (*a == t->where)
1241 litest_assert_int_eq(rc, true);
1242 else
1243 litest_assert_int_eq(rc, false);
1244 }
1245 }
1246 }
1247 END_TEST
1248
1249 struct qtest_bool {
1250 const char *str;
1251 bool success;
1252 bool val;
1253 };
1254
1255 START_TEST(quirks_parse_bool_attr)
1256 {
1257 struct litest_device *dev = litest_current_device();
1258 enum quirk attrs[] = {
1259 QUIRK_ATTR_USE_VELOCITY_AVERAGING,
1260 QUIRK_ATTR_TABLET_SMOOTHING,
1261 };
1262 /* clang-format off */
1263 struct qtest_bool test_values[] = {
1264 { "0", true, false },
1265 { "1", true, true },
1266 { "2", false, false },
1267 { "-1", false, false },
1268 { "a", false, false },
1269 };
1270 /* clang-format on */
1271
1272 ARRAY_FOR_EACH(attrs, a) {
1273 ARRAY_FOR_EACH(test_values, t) {
1274 bool v;
1275 bool rc;
1276
1277 rc = test_attr_parse(dev,
1278 *a,
1279 t->str,
1280 (qparsefunc)quirks_get_bool,
1281 &v);
1282 litest_assert(rc == t->success);
1283 if (!rc)
1284 continue;
1285
1286 litest_assert(v == t->val);
1287 }
1288 }
1289 }
1290 END_TEST
1291
1292 START_TEST(quirks_parse_integration_attr)
1293 {
1294 struct litest_device *dev = litest_current_device();
1295 char *do_not_use; /* freed before we can use it */
1296 bool rc = test_attr_parse(dev,
1297 QUIRK_ATTR_KEYBOARD_INTEGRATION,
1298 "internal",
1299 (qparsefunc)quirks_get_string,
1300 &do_not_use);
1301 litest_assert(rc);
1302 rc = test_attr_parse(dev,
1303 QUIRK_ATTR_KEYBOARD_INTEGRATION,
1304 "external",
1305 (qparsefunc)quirks_get_string,
1306 &do_not_use);
1307 litest_assert(rc);
1308 rc = test_attr_parse(dev,
1309 QUIRK_ATTR_TRACKPOINT_INTEGRATION,
1310 "internal",
1311 (qparsefunc)quirks_get_string,
1312 &do_not_use);
1313 litest_assert(rc);
1314 rc = test_attr_parse(dev,
1315 QUIRK_ATTR_TRACKPOINT_INTEGRATION,
1316 "external",
1317 (qparsefunc)quirks_get_string,
1318 &do_not_use);
1319 litest_assert(rc);
1320 }
1321 END_TEST
1322
1323 START_TEST(quirks_model_one)
1324 {
1325 struct litest_device *dev = litest_current_device();
1326 _unref_(udev_device) *ud =
1327 libinput_device_get_udev_device(dev->libinput_device);
1328 const char quirks_file[] =
1329 "[Section name]\n"
1330 "MatchUdevType=mouse\n"
1331 "ModelAppleTouchpad=1\n";
1332 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
1333 bool isset;
1334
1335 _unref_(quirks_context) *ctx =
1336 quirks_init_subsystem(dd->dirname,
1337 NULL,
1338 log_handler,
1339 NULL,
1340 QLOG_CUSTOM_LOG_PRIORITIES);
1341 litest_assert_notnull(ctx);
1342
1343 _unref_(quirks) *q = quirks_fetch_for_device(ctx, ud);
1344 litest_assert_notnull(q);
1345
1346 litest_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset));
1347 litest_assert(isset == true);
1348 }
1349 END_TEST
1350
1351 START_TEST(quirks_model_zero)
1352 {
1353 struct litest_device *dev = litest_current_device();
1354 _unref_(udev_device) *ud =
1355 libinput_device_get_udev_device(dev->libinput_device);
1356 const char quirks_file[] =
1357 "[Section name]\n"
1358 "MatchUdevType=mouse\n"
1359 "ModelAppleTouchpad=0\n";
1360 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
1361 bool isset;
1362
1363 _unref_(quirks_context) *ctx =
1364 quirks_init_subsystem(dd->dirname,
1365 NULL,
1366 log_handler,
1367 NULL,
1368 QLOG_CUSTOM_LOG_PRIORITIES);
1369 litest_assert_notnull(ctx);
1370
1371 _unref_(quirks) *q = quirks_fetch_for_device(ctx, ud);
1372 litest_assert_notnull(q);
1373
1374 litest_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset));
1375 litest_assert(isset == false);
1376 }
1377 END_TEST
1378
1379 START_TEST(quirks_model_override)
1380 {
1381 struct litest_device *dev = litest_current_device();
1382 _unref_(udev_device) *ud =
1383 libinput_device_get_udev_device(dev->libinput_device);
1384 bool isset;
1385 bool set = litest_test_param_get_bool(test_env->params, "enable_model");
1386
1387 /* Test model quirks override by setting, then unsetting (or the
1388 other way round) */
1389 _autofree_ char *quirks_file = strdup_printf(
1390 "[first]\n"
1391 "MatchUdevType=mouse\n"
1392 "ModelAppleTouchpad=%d\n"
1393 "\n"
1394 "[second]\n"
1395 "MatchUdevType=mouse\n"
1396 "ModelAppleTouchpad=%d\n",
1397 set ? 0 : 1,
1398 set ? 1 : 0);
1399 litest_assert_ptr_notnull(quirks_file);
1400
1401 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
1402
1403 _unref_(quirks_context) *ctx =
1404 quirks_init_subsystem(dd->dirname,
1405 NULL,
1406 log_handler,
1407 NULL,
1408 QLOG_CUSTOM_LOG_PRIORITIES);
1409 litest_assert_notnull(ctx);
1410
1411 _unref_(quirks) *q = quirks_fetch_for_device(ctx, ud);
1412 litest_assert_notnull(q);
1413
1414 litest_assert(quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &isset));
1415 litest_assert(isset == set);
1416 }
1417 END_TEST
1418
1419 START_TEST(quirks_model_alps)
1420 {
1421 struct litest_device *dev = litest_current_device();
1422 struct libinput_device *device = dev->libinput_device;
1423 struct quirks *q;
1424 bool exists, value = false;
1425
1426 q = dev->quirks;
1427 exists = quirks_get_bool(q, QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD, &value);
1428
1429 if (strstr(libinput_device_get_name(device), "ALPS")) {
1430 litest_assert(exists);
1431 litest_assert(value);
1432 } else {
1433 litest_assert(!exists);
1434 litest_assert(!value);
1435 }
1436 }
1437 END_TEST
1438
1439 START_TEST(quirks_model_wacom)
1440 {
1441 struct litest_device *dev = litest_current_device();
1442 struct quirks *q;
1443 bool exists, value = false;
1444
1445 q = dev->quirks;
1446 exists = quirks_get_bool(q, QUIRK_MODEL_WACOM_TOUCHPAD, &value);
1447
1448 if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_WACOM) {
1449 litest_assert(exists);
1450 litest_assert(value);
1451 } else {
1452 litest_assert(!exists);
1453 litest_assert(!value);
1454 }
1455 }
1456 END_TEST
1457
1458 START_TEST(quirks_model_apple)
1459 {
1460 struct litest_device *dev = litest_current_device();
1461 struct quirks *q;
1462 bool exists, value = false;
1463
1464 q = dev->quirks;
1465 exists = quirks_get_bool(q, QUIRK_MODEL_APPLE_TOUCHPAD, &value);
1466
1467 if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_APPLE) {
1468 litest_assert(exists);
1469 litest_assert(value);
1470 } else {
1471 litest_assert(!exists);
1472 litest_assert(!value);
1473 }
1474 }
1475 END_TEST
1476
1477 START_TEST(quirks_model_synaptics_serial)
1478 {
1479 struct litest_device *dev = litest_current_device();
1480 struct quirks *q;
1481 bool exists, value = false;
1482
1483 q = dev->quirks;
1484 exists = quirks_get_bool(q, QUIRK_MODEL_SYNAPTICS_SERIAL_TOUCHPAD, &value);
1485
1486 if (libevdev_get_id_vendor(dev->evdev) == VENDOR_ID_SYNAPTICS_SERIAL &&
1487 libevdev_get_id_product(dev->evdev) == PRODUCT_ID_SYNAPTICS_SERIAL) {
1488 litest_assert(exists);
1489 litest_assert(value);
1490 } else {
1491 litest_assert(!exists);
1492 litest_assert(!value);
1493 }
1494 }
1495 END_TEST
1496
1497 START_TEST(quirks_call_NULL)
1498 {
1499 litest_assert(!quirks_fetch_for_device(NULL, NULL));
1500
1501 litest_assert(!quirks_get_uint32(NULL, QUIRK_NONE, NULL));
1502 litest_assert(!quirks_get_int32(NULL, QUIRK_NONE, NULL));
1503 litest_assert(!quirks_get_range(NULL, QUIRK_NONE, NULL));
1504 litest_assert(!quirks_get_dimensions(NULL, QUIRK_NONE, NULL));
1505 litest_assert(!quirks_get_double(NULL, QUIRK_NONE, NULL));
1506 litest_assert(!quirks_get_string(NULL, QUIRK_NONE, NULL));
1507 litest_assert(!quirks_get_bool(NULL, QUIRK_NONE, NULL));
1508 }
1509 END_TEST
1510
1511 START_TEST(quirks_ctx_ref)
1512 {
1513 struct quirks_context *ctx, *ctx2;
1514 const char quirks_file[] =
1515 "[Section name]\n"
1516 "MatchUdevType=mouse\n"
1517 "AttrSizeHint=10x10\n";
1518 _destroy_(data_dir) *dd = data_dir_new(quirks_file);
1519
1520 ctx = quirks_init_subsystem(dd->dirname,
1521 NULL,
1522 log_handler,
1523 NULL,
1524 QLOG_CUSTOM_LOG_PRIORITIES);
1525 litest_assert_notnull(ctx);
1526 ctx2 = quirks_context_ref(ctx);
1527 litest_assert_ptr_eq(ctx, ctx2);
1528 ctx2 = quirks_context_unref(ctx);
1529 litest_assert_ptr_eq(ctx2, NULL);
1530 ctx2 = quirks_context_unref(ctx);
1531 litest_assert_ptr_eq(ctx2, NULL);
1532 }
1533 END_TEST
1534
1535 TEST_COLLECTION(quirks)
1536 {
1537 /* clang-format off */
1538 litest_add_deviceless(quirks_invalid_dir);
1539 litest_add_deviceless(quirks_empty_dir);
1540
1541 litest_add_deviceless(quirks_section_empty);
1542 litest_add_deviceless(quirks_section_double);
1543 litest_add_deviceless(quirks_section_missing_match);
1544 litest_add_deviceless(quirks_section_missing_attr);
1545 litest_add_deviceless(quirks_section_match_after_attr);
1546 litest_add_deviceless(quirks_section_duplicate_match);
1547 litest_add_deviceless(quirks_section_duplicate_attr);
1548
1549 litest_add_deviceless(quirks_parse_error_section);
1550 litest_add_deviceless(quirks_parse_error_trailing_whitespace);
1551 litest_add_deviceless(quirks_parse_error_unknown_match);
1552 litest_add_deviceless(quirks_parse_error_unknown_attr);
1553 litest_add_deviceless(quirks_parse_error_unknown_model);
1554 litest_add_deviceless(quirks_parse_error_unknown_prefix);
1555 litest_add_deviceless(quirks_parse_error_model_not_one);
1556 litest_add_deviceless(quirks_parse_comment_inline);
1557 litest_add_deviceless(quirks_parse_comment_empty);
1558 litest_add_deviceless(quirks_parse_string_quotes_single);
1559 litest_add_deviceless(quirks_parse_string_quotes_double);
1560
1561 litest_add_deviceless(quirks_parse_bustype);
1562 litest_add_deviceless(quirks_parse_bustype_invalid);
1563 litest_add_deviceless(quirks_parse_vendor);
1564 litest_add_deviceless(quirks_parse_vendor_invalid);
1565 litest_add_deviceless(quirks_parse_product);
1566 litest_add_deviceless(quirks_parse_product_too_many);
1567 litest_add_deviceless(quirks_parse_product_invalid);
1568 litest_add_deviceless(quirks_parse_version);
1569 litest_add_deviceless(quirks_parse_version_invalid);
1570 litest_add_deviceless(quirks_parse_name);
1571 litest_add_deviceless(quirks_parse_name_invalid);
1572 litest_add_deviceless(quirks_parse_uniq);
1573 litest_add_deviceless(quirks_parse_uniq_invalid);
1574 litest_add_deviceless(quirks_parse_udev);
1575 litest_add_deviceless(quirks_parse_udev_invalid);
1576 litest_add_deviceless(quirks_parse_dmi);
1577 litest_add_deviceless(quirks_parse_dmi_invalid);
1578
1579 litest_add_for_device(quirks_parse_dimension_attr, LITEST_MOUSE);
1580 litest_add_for_device(quirks_parse_range_attr, LITEST_MOUSE);
1581 litest_add_for_device(quirks_parse_uint_attr, LITEST_MOUSE);
1582 litest_add_for_device(quirks_parse_double_attr, LITEST_MOUSE);
1583 litest_add_for_device(quirks_parse_string_attr, LITEST_MOUSE);
1584 litest_add_for_device(quirks_parse_bool_attr, LITEST_MOUSE);
1585 litest_add_for_device(quirks_parse_integration_attr, LITEST_MOUSE);
1586
1587 litest_add_for_device(quirks_model_one, LITEST_MOUSE);
1588 litest_add_for_device(quirks_model_zero, LITEST_MOUSE);
1589 litest_with_parameters(params, "enable_model", 'b') {
1590 litest_add_parametrized_for_device(quirks_model_override, LITEST_MOUSE, params);
1591 }
1592
1593 litest_add(quirks_model_alps, LITEST_TOUCHPAD, LITEST_ANY);
1594 litest_add(quirks_model_wacom, LITEST_TOUCHPAD, LITEST_ANY);
1595 litest_add(quirks_model_apple, LITEST_TOUCHPAD, LITEST_ANY);
1596 litest_add(quirks_model_synaptics_serial, LITEST_TOUCHPAD, LITEST_ANY);
1597
1598 litest_add_deviceless(quirks_call_NULL);
1599 litest_add_deviceless(quirks_ctx_ref);
1600 /* clang-format on */
1601 }