Merge branch 'dbus-1.6'
[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 #define DBUS_COMPILATION    /* this test uses libdbus-internal */
34 #include <dbus/dbus.h>
35 #include <dbus/dbus-sysdeps.h>
36
37 typedef struct {
38     int dummy;
39 } Fixture;
40
41 static void
42 setup (Fixture *f,
43     gconstpointer data)
44 {
45 }
46
47 /* hopefully clear enough that people don't think these messages in syslog
48  * are a bug */
49 #define MESSAGE "regression test for _dbus_system_log(): "
50
51 static void
52 test_syslog (Fixture *f,
53     gconstpointer data)
54 {
55   if (g_test_trap_fork (0, 0))
56     {
57       _dbus_init_system_log (FALSE);
58       _dbus_system_log (DBUS_SYSTEM_LOG_FATAL, MESSAGE "%d", 23);
59       /* should not be reached: exit 0 so the assertion in the main process
60        * will fail */
61       exit (0);
62     }
63
64   g_test_trap_assert_failed ();
65   g_test_trap_assert_stderr ("*" MESSAGE "23\n*");
66
67   if (g_test_trap_fork (0, 0))
68     {
69       _dbus_init_system_log (FALSE);
70       _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
71       _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
72       exit (0);
73     }
74
75   g_test_trap_assert_passed ();
76   g_test_trap_assert_stderr ("*" MESSAGE "42\n*" MESSAGE "666\n*");
77
78   /* manual test (this is the best we can do on Windows) */
79   _dbus_init_system_log (FALSE);
80   _dbus_system_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
81   _dbus_system_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
82 }
83
84 static void
85 teardown (Fixture *f,
86     gconstpointer data)
87 {
88 }
89
90 int
91 main (int argc,
92     char **argv)
93 {
94   g_test_init (&argc, &argv, NULL);
95   g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
96
97   g_test_add ("/syslog", Fixture, NULL, setup, test_syslog, teardown);
98
99   return g_test_run ();
100 }