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
28 #include "test-common.h"
30 int test_create_device(struct uinput_device **uidev_return,
31 struct libevdev **dev_return,
35 struct uinput_device *uidev;
39 va_start(args, dev_return);
41 rc = uinput_device_new_with_events_v(&uidev, TEST_DEVICE_NAME, DEFAULT_IDS, args);
44 ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
46 fd = uinput_device_get_fd(uidev);
48 rc = libevdev_new_from_fd(fd, &dev);
49 ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
50 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
51 ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
53 *uidev_return = uidev;
56 return rc == 0 ? rc : -errno;
59 int test_create_abs_device(struct uinput_device **uidev_return,
60 struct libevdev **dev_return,
62 const struct input_absinfo *abs,
66 struct uinput_device *uidev;
70 uidev = uinput_device_new(TEST_DEVICE_NAME);
71 ck_assert(uidev != NULL);
74 rc = uinput_device_set_event_bits_v(uidev, args);
79 struct input_absinfo a;
81 code = abs[nabs].value;
85 rc = uinput_device_set_abs_bit(uidev, code, &a);
86 ck_assert_msg(rc == 0, "for abs field %d\n", nabs);
89 rc = uinput_device_create(uidev);
90 ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
92 fd = uinput_device_get_fd(uidev);
94 rc = libevdev_new_from_fd(fd, &dev);
95 ck_assert_msg(rc == 0, "Failed to init device device: %s", strerror(-rc));
96 rc = fcntl(fd, F_SETFL, O_NONBLOCK);
97 ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
99 *uidev_return = uidev;
102 return rc == 0 ? rc : -errno;