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 struct libinput *log_handler_context;
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(struct libinput *libinput,
55 enum libinput_log_priority priority,
60 if (log_handler_context)
61 ck_assert(libinput == log_handler_context);
62 ck_assert(format != NULL);
65 START_TEST(log_default_priority)
67 enum libinput_log_priority pri;
70 li = libinput_path_create_context(&simple_interface, NULL);
71 pri = libinput_log_get_priority(li);
73 ck_assert_int_eq(pri, LIBINPUT_LOG_PRIORITY_ERROR);
79 START_TEST(log_handler_invoked)
83 li = libinput_path_create_context(&simple_interface, NULL);
85 libinput_log_set_priority(li, LIBINPUT_LOG_PRIORITY_DEBUG);
86 libinput_log_set_handler(li, simple_log_handler);
87 log_handler_context = li;
89 libinput_path_add_device(li, "/tmp");
91 ck_assert_int_gt(log_handler_called, 0);
92 log_handler_called = 0;
96 log_handler_context = NULL;
100 START_TEST(log_handler_NULL)
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);
108 libinput_path_add_device(li, "/tmp");
110 ck_assert_int_eq(log_handler_called, 0);
111 log_handler_called = 0;
117 START_TEST(log_priority)
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;
126 libinput_path_add_device(li, "/tmp");
128 ck_assert_int_eq(log_handler_called, 0);
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);
134 log_handler_called = 0;
137 log_handler_context = NULL;
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);
147 return litest_run(argc, argv);