touchpad: normalize the touchpad resolution to 400dpi, not 10 units/mm
[platform/upstream/libinput.git] / test / log.c
1 /*
2  * Copyright © 2014 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include <config.h>
24
25 #include <check.h>
26 #include <errno.h>
27 #include <fcntl.h>
28 #include <libinput.h>
29 #include <libudev.h>
30 #include <unistd.h>
31
32 #include "litest.h"
33
34 static int log_handler_called;
35 static struct libinput *log_handler_context;
36
37 static int open_restricted(const char *path, int flags, void *data)
38 {
39         int fd;
40         fd = open(path, flags);
41         return fd < 0 ? -errno : fd;
42 }
43 static void close_restricted(int fd, void *data)
44 {
45         close(fd);
46 }
47
48 const struct libinput_interface simple_interface = {
49         .open_restricted = open_restricted,
50         .close_restricted = close_restricted,
51 };
52
53 static void
54 simple_log_handler(struct libinput *libinput,
55                    enum libinput_log_priority priority,
56                    const char *format,
57                    va_list args)
58 {
59         log_handler_called++;
60         if (log_handler_context)
61                 ck_assert(libinput == log_handler_context);
62         ck_assert(format != NULL);
63 }
64
65 START_TEST(log_default_priority)
66 {
67         enum libinput_log_priority pri;
68         struct libinput *li;
69
70         li = libinput_path_create_context(&simple_interface, NULL);
71         pri = libinput_log_get_priority(li);
72
73         ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
74
75         libinput_unref(li);
76 }
77 END_TEST
78
79 START_TEST(log_handler_invoked)
80 {
81         struct libinput *li;
82
83         li = libinput_path_create_context(&simple_interface, NULL);
84
85         libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
86         libinput_log_set_handler(li, simple_log_handler);
87         log_handler_context = li;
88
89         libinput_path_add_device(li, "/tmp");
90
91         ck_assert_int_gt(log_handler_called, 0);
92         log_handler_called = 0;
93
94         libinput_unref(li);
95
96         log_handler_context = NULL;
97 }
98 END_TEST
99
100 START_TEST(log_handler_NULL)
101 {
102         struct libinput *li;
103
104         li = libinput_path_create_context(&simple_interface, NULL);
105         libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
106         libinput_log_set_handler(li, NULL);
107
108         libinput_path_add_device(li, "/tmp");
109
110         ck_assert_int_eq(log_handler_called, 0);
111         log_handler_called = 0;
112
113         libinput_unref(li);
114 }
115 END_TEST
116
117 START_TEST(log_priority)
118 {
119         struct libinput *li;
120
121         li = libinput_path_create_context(&simple_interface, NULL);
122         libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_ERROR);
123         libinput_log_set_handler(li, simple_log_handler);
124         log_handler_context = li;
125
126         libinput_path_add_device(li, "/tmp");
127
128         ck_assert_int_eq(log_handler_called, 0);
129
130         libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_INFO);
131         libinput_path_add_device(li, "/tmp");
132         ck_assert_int_gt(log_handler_called, 0);
133
134         log_handler_called = 0;
135
136         libinput_unref(li);
137         log_handler_context = NULL;
138 }
139 END_TEST
140
141 int main (int argc, char **argv) {
142         litest_add_no_device("log:defaults", log_default_priority);
143         litest_add_no_device("log:logging", log_handler_invoked);
144         litest_add_no_device("log:logging", log_handler_NULL);
145         litest_add_no_device("log:logging", log_priority);
146
147         return litest_run(argc, argv);
148 }