2 * Copyright © 2013 Red Hat, Inc.
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.
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
29 #include "test-common.h"
31 void test_logfunc_abort_on_error(enum libevdev_log_priority priority,
33 const char *file, int line,
35 const char *format, va_list args)
37 vprintf(format, args);
41 void test_logfunc_ignore_error(enum libevdev_log_priority priority,
43 const char *file, int line,
45 const char *format, va_list args)
49 void test_create_device(struct uinput_device **uidev_return,
50 struct libevdev **dev_return,
54 struct uinput_device *uidev;
58 va_start(args, dev_return);
60 rc = uinput_device_new_with_events_v(&uidev, TEST_DEVICE_NAME, DEFAULT_IDS, args);
63 ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
65 fd = uinput_device_get_fd(uidev);
67 rc = libevdev_new_from_fd(fd, &dev);
68 ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
69 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
70 ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
72 *uidev_return = uidev;
76 void test_create_abs_device(struct uinput_device **uidev_return,
77 struct libevdev **dev_return,
79 const struct input_absinfo *abs,
83 struct uinput_device *uidev;
87 uidev = uinput_device_new(TEST_DEVICE_NAME);
88 ck_assert(uidev != NULL);
91 rc = uinput_device_set_event_bits_v(uidev, args);
92 ck_assert_msg(rc == 0, "Failed to set uinput bits");
97 struct input_absinfo a;
99 code = abs[nabs].value;
103 rc = uinput_device_set_abs_bit(uidev, code, &a);
104 ck_assert_msg(rc == 0, "for abs field %d\n", nabs);
107 rc = uinput_device_create(uidev);
108 ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
110 fd = uinput_device_get_fd(uidev);
112 rc = libevdev_new_from_fd(fd, &dev);
113 ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
114 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
115 ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
117 *uidev_return = uidev;