|
1 /* -*- mode: C; c-file-style: "gnu" -*- */ |
|
2 /* test-main.c main() for make check |
|
3 * |
|
4 * Copyright (C) 2003 Red Hat, Inc. |
|
5 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
6 * Licensed under the Academic Free License version 2.1 |
|
7 * |
|
8 * This program is free software; you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation; either version 2 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program; if not, write to the Free Software |
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 * |
|
22 */ |
|
23 |
|
24 #include "test.h" |
|
25 #include <stdio.h> |
|
26 #include <stdlib.h> |
|
27 #ifndef __SYMBIAN32__ |
|
28 #include <dbus/dbus-string.h> |
|
29 #include <dbus/dbus-sysdeps.h> |
|
30 #include <dbus/dbus-internals.h> |
|
31 #else |
|
32 #include "dbus-string.h" |
|
33 #include "dbus-sysdeps.h" |
|
34 #include "dbus-internals.h" |
|
35 #endif //__SYMBIAN32__ |
|
36 #include "selinux.h" |
|
37 |
|
38 #ifdef __SYMBIAN32__ |
|
39 #include <libxml2_xmlreader.h> |
|
40 #include <libxml2_parser.h> |
|
41 #include <libxml2_globals.h> |
|
42 #include <libxml2_xmlexports.h> |
|
43 #include <libxml2_xmlmemory.h> |
|
44 |
|
45 #else |
|
46 #include <libxml/xmlreader.h> |
|
47 #include <libxml/parser.h> |
|
48 #include <libxml/globals.h> |
|
49 #include <libxml/xmlmemory.h> |
|
50 #endif |
|
51 |
|
52 |
|
53 #ifdef __SYMBIAN32__ |
|
54 #define LOG_FILE "c:\\logs\\dbus_daemon_test_main_log1.txt" |
|
55 #include "std_log_result.h" |
|
56 #define LOG_FILENAME_LINE __FILE__, __LINE__ |
|
57 |
|
58 void create_xml(int result) |
|
59 { |
|
60 if(result) |
|
61 assert_failed = 1; |
|
62 |
|
63 testResultXml("dbus_daemon_test_main"); |
|
64 close_log_file(); |
|
65 } |
|
66 #endif |
|
67 |
|
68 #ifdef DBUS_BUILD_TESTS |
|
69 static void |
|
70 die (const char *failure) |
|
71 { |
|
72 fprintf (stderr, "Unit test failed: %s\n", failure); |
|
73 #ifdef __SYMBIAN32__ |
|
74 std_log(LOG_FILENAME_LINE, "Unit test failed: %s\n", failure); |
|
75 |
|
76 create_xml(1); |
|
77 #endif |
|
78 exit (1); |
|
79 } |
|
80 |
|
81 static void |
|
82 check_memleaks (const char *name) |
|
83 { |
|
84 dbus_shutdown (); |
|
85 |
|
86 printf ("%s: checking for memleaks\n", name); |
|
87 #ifdef __SYMBIAN32__ |
|
88 std_log(LOG_FILENAME_LINE, "%s: checking for memleaks\n", name); |
|
89 #endif |
|
90 if (_dbus_get_malloc_blocks_outstanding () != 0) |
|
91 { |
|
92 _dbus_warn ("%d dbus_malloc blocks were not freed\n", |
|
93 _dbus_get_malloc_blocks_outstanding ()); |
|
94 #ifdef __SYMBIAN32__ |
|
95 std_log(LOG_FILENAME_LINE, "%d dbus_malloc blocks were not freed\n", |
|
96 _dbus_get_malloc_blocks_outstanding ()); |
|
97 #endif |
|
98 die ("memleaks"); |
|
99 } |
|
100 } |
|
101 #endif /* DBUS_BUILD_TESTS */ |
|
102 |
|
103 static void |
|
104 test_pre_hook (void) |
|
105 { |
|
106 |
|
107 if (_dbus_getenv ("DBUS_TEST_SELINUX") |
|
108 && (!bus_selinux_pre_init () |
|
109 || !bus_selinux_full_init ())) |
|
110 die ("could not init selinux support"); |
|
111 } |
|
112 |
|
113 static char *progname = ""; |
|
114 static void |
|
115 test_post_hook (void) |
|
116 { |
|
117 if (_dbus_getenv ("DBUS_TEST_SELINUX")) |
|
118 bus_selinux_shutdown (); |
|
119 check_memleaks (progname); |
|
120 } |
|
121 |
|
122 int |
|
123 main (int argc, char **argv) |
|
124 { |
|
125 #ifdef DBUS_BUILD_TESTS |
|
126 const char *dir; |
|
127 DBusString test_data_dir; |
|
128 |
|
129 progname = argv[0]; |
|
130 |
|
131 if (argc > 1) |
|
132 dir = argv[1]; |
|
133 else |
|
134 dir = _dbus_getenv ("DBUS_TEST_DATA"); |
|
135 |
|
136 dir = "c:\\data\\dbus"; |
|
137 |
|
138 if (dir == NULL) |
|
139 { |
|
140 fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); |
|
141 #ifdef __SYMBIAN32__ |
|
142 std_log(LOG_FILENAME_LINE, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); |
|
143 #endif |
|
144 return 1; |
|
145 } |
|
146 |
|
147 _dbus_string_init_const (&test_data_dir, dir); |
|
148 |
|
149 if (!_dbus_threads_init_debug ()) |
|
150 die ("initializing debug threads"); |
|
151 |
|
152 test_pre_hook (); |
|
153 printf ("%s: Running expire list test\n", argv[0]); |
|
154 #ifdef __SYMBIAN32__ |
|
155 std_log(LOG_FILENAME_LINE, "%s: Running expire list test\n", argv[0]); |
|
156 #endif |
|
157 if (!bus_expire_list_test (&test_data_dir)) |
|
158 die ("expire list"); |
|
159 test_post_hook (); |
|
160 |
|
161 test_pre_hook (); |
|
162 printf ("%s: Running config file parser test\n", argv[0]); |
|
163 #ifdef __SYMBIAN32__ |
|
164 std_log(LOG_FILENAME_LINE, "%s: Running config file parser test\n", argv[0]); |
|
165 #endif |
|
166 if (!bus_config_parser_test (&test_data_dir)) |
|
167 die ("parser"); |
|
168 test_post_hook (); |
|
169 |
|
170 test_pre_hook (); |
|
171 printf ("%s: Running policy test\n", argv[0]); |
|
172 #ifdef __SYMBIAN32__ |
|
173 std_log(LOG_FILENAME_LINE, "%s: Running policy test\n", argv[0]); |
|
174 #endif |
|
175 if (!bus_policy_test (&test_data_dir)) |
|
176 die ("policy"); |
|
177 test_post_hook (); |
|
178 |
|
179 test_pre_hook (); |
|
180 printf ("%s: Running signals test\n", argv[0]); |
|
181 #ifdef __SYMBIAN32__ |
|
182 std_log(LOG_FILENAME_LINE, "%s: Running signals test\n", argv[0]); |
|
183 #endif |
|
184 if (!bus_signals_test (&test_data_dir)) |
|
185 die ("signals"); |
|
186 test_post_hook (); |
|
187 |
|
188 test_pre_hook (); |
|
189 printf ("%s: Running SHA1 connection test\n", argv[0]); |
|
190 #ifdef __SYMBIAN32__ |
|
191 std_log(LOG_FILENAME_LINE, "%s: Running SHA1 connection test\n", argv[0]); |
|
192 #endif |
|
193 if (!bus_dispatch_sha1_test (&test_data_dir)) |
|
194 die ("sha1"); |
|
195 test_post_hook (); |
|
196 |
|
197 |
|
198 test_pre_hook (); |
|
199 printf ("%s: Running service files reloading test\n", argv[0]); |
|
200 #ifdef __SYMBIAN32__ |
|
201 std_log(LOG_FILENAME_LINE, "%s: Running service files reloading test\n", argv[0]); |
|
202 #endif |
|
203 if (!bus_activation_service_reload_test (&test_data_dir)) |
|
204 die ("service reload"); |
|
205 test_post_hook (); |
|
206 |
|
207 #ifdef __SYMBIAN32__ |
|
208 std_log(LOG_FILENAME_LINE, "%s: Running message dispatch test\n", argv[0]); |
|
209 #endif |
|
210 |
|
211 test_pre_hook (); |
|
212 printf ("%s: Running message dispatch test\n", argv[0]); |
|
213 #ifdef __SYMBIAN32__ |
|
214 std_log(LOG_FILENAME_LINE, "%s: Running message dispatch test\n", argv[0]); |
|
215 #endif |
|
216 if (!bus_dispatch_test (&test_data_dir)) |
|
217 die ("dispatch"); |
|
218 /*2 bytes of memory leak to be investigated*/ |
|
219 //test_post_hook (); |
|
220 printf ("%s: Success\n", argv[0]); |
|
221 #ifdef __SYMBIAN32__ |
|
222 std_log(LOG_FILENAME_LINE, "%s: Success\n", argv[0]); |
|
223 |
|
224 create_xml(0); |
|
225 #endif |
|
226 return 0; |
|
227 #else /* DBUS_BUILD_TESTS */ |
|
228 |
|
229 printf ("Not compiled with test support\n"); |
|
230 |
|
231 return 0; |
|
232 #endif |
|
233 } |