Drop semicolons after getter/setter macros
[platform/upstream/libevdev.git] / test / test-common.c
1 /*
2  * Copyright © 2013 Red Hat, Inc.
3  *
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.
13  *
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
20  * OF THIS SOFTWARE.
21  */
22
23 #include <config.h>
24 #include <check.h>
25 #include <errno.h>
26 #include <fcntl.h>
27
28 #include "test-common.h"
29
30 int test_create_device(struct uinput_device **uidev_return,
31                        struct libevdev **dev_return,
32                        ...)
33 {
34         int rc, fd;
35         struct uinput_device *uidev;
36         struct libevdev *dev;
37         va_list args;
38
39         va_start(args, dev_return);
40
41         rc = uinput_device_new_with_events_v(&uidev, TEST_DEVICE_NAME, DEFAULT_IDS, args);
42         va_end(args);
43
44         ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
45
46         fd = uinput_device_get_fd(uidev);
47
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));
52
53         *uidev_return = uidev;
54         *dev_return = dev;
55
56         return rc == 0 ? rc : -errno;
57 }
58
59 int test_create_abs_device(struct uinput_device **uidev_return,
60                            struct libevdev **dev_return,
61                            int nabs,
62                            const struct input_absinfo *abs,
63                            ...)
64 {
65         int rc, fd;
66         struct uinput_device *uidev;
67         struct libevdev *dev;
68         va_list args;
69
70         uidev = uinput_device_new(TEST_DEVICE_NAME);
71         ck_assert(uidev != NULL);
72
73         va_start(args, abs);
74         rc = uinput_device_set_event_bits_v(uidev, args);
75         va_end(args);
76
77         while (--nabs >= 0) {
78                 int code;
79                 struct input_absinfo a;
80
81                 code = abs[nabs].value;
82                 a = abs[nabs];
83                 a.value = 0;
84
85                 rc = uinput_device_set_abs_bit(uidev, code, &a);
86                 ck_assert_msg(rc == 0, "for abs field %d\n", nabs);
87         }
88
89         rc = uinput_device_create(uidev);
90         ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
91
92         fd = uinput_device_get_fd(uidev);
93
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));
98
99         *uidev_return = uidev;
100         *dev_return = dev;
101
102         return rc == 0 ? rc : -errno;
103 }