bus: Assign a serial number for messages from the driver
[platform/upstream/dbus.git] / test / internals / syslog.c
1 /* Manual regression test for syslog support
2  *
3  * Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
4  * Copyright © 2011 Nokia Corporation
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation files
8  * (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26
27 #include <config.h>
28
29 #include <stdlib.h>
30
31 #include <glib.h>
32
33 #include <dbus/dbus.h>
34 #include <dbus/dbus-sysdeps.h>
35
36 #include "test-utils-glib.h"
37
38 typedef struct {
39     int dummy;
40 } Fixture;
41
42 static void
43 setup (Fixture *f,
44     gconstpointer data)
45 {
46 }
47
48 /* hopefully clear enough that people don't think these messages in syslog
49  * are a bug */
50 #define MESSAGE "regression test for _dbus_log(): "
51
52 static void
53 test_syslog_normal (Fixture *f,
54     gconstpointer data)
55 {
56   if (g_test_subprocess ())
57     {
58       _dbus_init_system_log ("test-syslog",
59           DBUS_LOG_FLAGS_SYSTEM_LOG | DBUS_LOG_FLAGS_STDERR);
60       _dbus_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
61       _dbus_log (DBUS_SYSTEM_LOG_WARNING, MESSAGE "%d", 45);
62       _dbus_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
63       _dbus_log (DBUS_SYSTEM_LOG_ERROR, MESSAGE "%d", 23);
64
65       _dbus_init_system_log ("test-syslog-stderr", DBUS_LOG_FLAGS_STDERR);
66       _dbus_log (DBUS_SYSTEM_LOG_INFO,
67           MESSAGE "this should not appear in the syslog");
68       _dbus_init_system_log ("test-syslog-both",
69           DBUS_LOG_FLAGS_SYSTEM_LOG | DBUS_LOG_FLAGS_STDERR);
70       _dbus_log (DBUS_SYSTEM_LOG_INFO,
71           MESSAGE "this should appear in the syslog and on stderr");
72       _dbus_init_system_log ("test-syslog-only", DBUS_LOG_FLAGS_SYSTEM_LOG);
73       _dbus_log (DBUS_SYSTEM_LOG_INFO,
74           MESSAGE "this should appear in the syslog only");
75
76       exit (0);
77     }
78
79   g_test_trap_subprocess (NULL, 0, 0);
80   g_test_trap_assert_passed ();
81   g_test_trap_assert_stderr ("*" MESSAGE "42\n"
82                              "*" MESSAGE "45\n"
83                              "*" MESSAGE "666\n"
84                              "*" MESSAGE "23\n"
85                              "*test-syslog-stderr*" MESSAGE
86                                "this should not appear in the syslog\n"
87                              "*test-syslog-both*" MESSAGE
88                                "this should appear in the syslog and "
89                                "on stderr\n");
90   g_test_trap_assert_stderr_unmatched ("*this should appear in the syslog "
91                                        "only*");
92   g_test_trap_assert_stderr_unmatched ("*test-syslog-only*");
93 }
94
95 static void
96 teardown (Fixture *f,
97     gconstpointer data)
98 {
99 }
100
101 int
102 main (int argc,
103     char **argv)
104 {
105   test_init (&argc, &argv);
106
107   g_test_add ("/syslog/normal", Fixture, NULL, setup, test_syslog_normal,
108               teardown);
109
110   return g_test_run ();
111 }