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