2 * Copyright © 2014 Red Hat, Inc.
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.
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.
34 static int log_handler_called;
35 static void *log_handler_userdata;
37 static int open_restricted(const char *path, int flags, void *data)
40 fd = open(path, flags);
41 return fd < 0 ? -errno : fd;
43 static void close_restricted(int fd, void *data)
48 const struct libinput_interface simple_interface = {
49 .open_restricted = open_restricted,
50 .close_restricted = close_restricted,
54 simple_log_handler(enum libinput_log_priority priority,
60 ck_assert(userdata == log_handler_userdata);
61 ck_assert(format != NULL);
64 START_TEST(log_default_priority)
66 enum libinput_log_priority pri;
68 pri = libinput_log_get_priority();
70 ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
74 START_TEST(log_handler_invoked)
77 enum libinput_log_priority pri = libinput_log_get_priority();
79 libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
80 libinput_log_set_handler(simple_log_handler, NULL);
81 log_handler_userdata = NULL;
83 li = libinput_path_create_context(&simple_interface, NULL);
84 libinput_path_add_device(li, "/tmp");
86 ck_assert_int_gt(log_handler_called, 0);
87 log_handler_called = 0;
90 libinput_log_set_priority(pri);
94 START_TEST(log_userdata_NULL)
97 enum libinput_log_priority pri = libinput_log_get_priority();
99 libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
100 libinput_log_set_handler(simple_log_handler, NULL);
101 log_handler_userdata = NULL;
103 li = libinput_path_create_context(&simple_interface, NULL);
104 libinput_path_add_device(li, "/tmp");
106 ck_assert_int_gt(log_handler_called, 0);
107 log_handler_called = 0;
109 libinput_destroy(li);
111 libinput_log_set_priority(pri);
115 START_TEST(log_userdata)
118 enum libinput_log_priority pri = libinput_log_get_priority();
120 libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
121 libinput_log_set_handler(simple_log_handler, &li);
122 log_handler_userdata = &li;
124 li = libinput_path_create_context(&simple_interface, NULL);
125 libinput_path_add_device(li, "/tmp");
127 ck_assert_int_gt(log_handler_called, 0);
128 log_handler_called = 0;
130 libinput_destroy(li);
131 libinput_log_set_priority(pri);
135 START_TEST(log_handler_NULL)
138 enum libinput_log_priority pri = libinput_log_get_priority();
140 libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_DEBUG);
141 libinput_log_set_handler(NULL, NULL);
142 log_handler_userdata = NULL;
144 li = libinput_path_create_context(&simple_interface, NULL);
145 libinput_path_add_device(li, "/tmp");
147 ck_assert_int_eq(log_handler_called, 0);
148 log_handler_called = 0;
149 libinput_log_set_handler(simple_log_handler, NULL);
151 libinput_destroy(li);
152 libinput_log_set_priority(pri);
156 START_TEST(log_priority)
159 enum libinput_log_priority pri = libinput_log_get_priority();
161 libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_ERROR);
162 libinput_log_set_handler(simple_log_handler, NULL);
163 log_handler_userdata = NULL;
165 li = libinput_path_create_context(&simple_interface, NULL);
166 libinput_path_add_device(li, "/tmp");
168 ck_assert_int_eq(log_handler_called, 0);
170 libinput_log_set_priority(LIBINPUT_LOG_PRIORITY_INFO);
171 libinput_path_add_device(li, "/tmp");
172 ck_assert_int_gt(log_handler_called, 0);
174 log_handler_called = 0;
176 libinput_destroy(li);
177 libinput_log_set_priority(pri);
181 int main (int argc, char **argv) {
182 litest_add_no_device("log:defaults", log_default_priority);
183 litest_add_no_device("log:logging", log_handler_invoked);
184 litest_add_no_device("log:logging", log_handler_NULL);
185 litest_add_no_device("log:logging", log_userdata);
186 litest_add_no_device("log:logging", log_userdata_NULL);
187 litest_add_no_device("log:logging", log_priority);
189 return litest_run(argc, argv);