1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
2 | #include <stdio.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <string.h> |
---|
5 | #include <unistd.h> |
---|
6 | |
---|
7 | #include <bonobo-activation/bonobo-activation.h> |
---|
8 | #include <bonobo-activation/bonobo-activation-private.h> |
---|
9 | #include "../server/server.h" |
---|
10 | |
---|
11 | #include "empty.h" |
---|
12 | #include "plugin.h" |
---|
13 | |
---|
14 | #define TOTAL_TEST_SCORE 16 |
---|
15 | |
---|
16 | CORBA_Object name_service = CORBA_OBJECT_NIL; |
---|
17 | |
---|
18 | static char * |
---|
19 | bonobo_activation_exception_id (CORBA_Environment *ev) |
---|
20 | { |
---|
21 | if (ev->_major == CORBA_USER_EXCEPTION) { |
---|
22 | if (!strcmp (ev->_id, "IDL:Bonobo/GeneralError:1.0")) { |
---|
23 | Bonobo_GeneralError *err = CORBA_exception_value (ev); |
---|
24 | |
---|
25 | if (!err || !err->description) { |
---|
26 | return "No general exception error message"; |
---|
27 | } else { |
---|
28 | return err->description; |
---|
29 | } |
---|
30 | } else { |
---|
31 | return ev->_id; |
---|
32 | } |
---|
33 | } else { |
---|
34 | return CORBA_exception_id (ev); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | static gboolean |
---|
39 | test_bonobo_activation_server (CORBA_Environment *ev, const char *type) |
---|
40 | { |
---|
41 | CORBA_Object ns; |
---|
42 | |
---|
43 | ns = bonobo_activation_name_service_get (ev); |
---|
44 | if (ev->_major != CORBA_NO_EXCEPTION) { |
---|
45 | g_warning ("Exception '%s' (%s) finding bonobo_activation_server %s", |
---|
46 | bonobo_activation_exception_id (ev), ev->_id, type); |
---|
47 | return FALSE; |
---|
48 | } |
---|
49 | |
---|
50 | if (name_service != CORBA_OBJECT_NIL && |
---|
51 | name_service != ns) { |
---|
52 | g_warning ("bonobo_activation_server crashed %s", type); |
---|
53 | return FALSE; |
---|
54 | } |
---|
55 | |
---|
56 | if (name_service == CORBA_OBJECT_NIL) |
---|
57 | name_service = ns; |
---|
58 | else |
---|
59 | CORBA_Object_release (ns, ev); |
---|
60 | |
---|
61 | return TRUE; |
---|
62 | } |
---|
63 | |
---|
64 | static gboolean |
---|
65 | test_object (CORBA_Object obj, CORBA_Environment *ev, const char *type) |
---|
66 | { |
---|
67 | if (ev->_major != CORBA_NO_EXCEPTION) { |
---|
68 | g_warning ("Activation %s failed: %s\n", type, |
---|
69 | bonobo_activation_exception_id (ev)); |
---|
70 | } else if (CORBA_Object_is_nil (obj, ev)) { |
---|
71 | g_warning ("Activation %s failed (returned NIL but no exception)!", type); |
---|
72 | } else { |
---|
73 | return TRUE; |
---|
74 | } |
---|
75 | |
---|
76 | if (!test_bonobo_activation_server (ev, type)) { |
---|
77 | return FALSE; |
---|
78 | } |
---|
79 | |
---|
80 | return FALSE; |
---|
81 | } |
---|
82 | |
---|
83 | static int |
---|
84 | test_plugin (CORBA_Object obj, CORBA_Environment *ev, const char *type) |
---|
85 | { |
---|
86 | Plugin_doPluginTest (obj, ev); |
---|
87 | |
---|
88 | if (ev->_major != CORBA_NO_EXCEPTION) { |
---|
89 | g_warning ("Call failed: %s\n", |
---|
90 | bonobo_activation_exception_id (ev)); |
---|
91 | return 0; |
---|
92 | } else { |
---|
93 | fprintf (stderr, "Test %s succeeded\n", type); |
---|
94 | CORBA_Object_release (obj, ev); |
---|
95 | return 1; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | static int |
---|
100 | test_empty (CORBA_Object obj, CORBA_Environment *ev, const char *type) |
---|
101 | { |
---|
102 | Empty_doNothing (obj, ev); |
---|
103 | |
---|
104 | if (ev->_major != CORBA_NO_EXCEPTION) { |
---|
105 | g_warning ("Call failed: %s\n", |
---|
106 | bonobo_activation_exception_id (ev)); |
---|
107 | return 0; |
---|
108 | } else { |
---|
109 | fprintf (stderr, "Test %s succeeded\n", type); |
---|
110 | CORBA_Object_release (obj, ev); |
---|
111 | return 1; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | static int |
---|
116 | idle_base_activation (gpointer user_data) |
---|
117 | { |
---|
118 | /* This is a facile test, we always activate the |
---|
119 | * ActivationContext first and then get the OD from it */ |
---|
120 | bonobo_activation_activation_context_get (); |
---|
121 | |
---|
122 | return FALSE; |
---|
123 | } |
---|
124 | |
---|
125 | static void |
---|
126 | race_base_init (void) |
---|
127 | { |
---|
128 | g_idle_add (idle_base_activation, NULL); |
---|
129 | /* to race with the activation context get in the same process */ |
---|
130 | bonobo_activation_object_directory_get (NULL, NULL); |
---|
131 | } |
---|
132 | |
---|
133 | int passed = 0; |
---|
134 | int failed = 0; |
---|
135 | int async_done = 0; |
---|
136 | |
---|
137 | static void |
---|
138 | empty_activation_cb (CORBA_Object obj, |
---|
139 | const char *error_reason, |
---|
140 | gpointer user_data) |
---|
141 | { |
---|
142 | CORBA_Environment ev; |
---|
143 | gboolean ret = FALSE; |
---|
144 | char *repo_id = user_data; |
---|
145 | |
---|
146 | CORBA_exception_init (&ev); |
---|
147 | |
---|
148 | if (error_reason) |
---|
149 | g_warning ("Async activation error activating '%s' : '%s'", repo_id, error_reason); |
---|
150 | |
---|
151 | else if (test_object (obj, &ev, "by async query")) |
---|
152 | ret = test_empty (obj, &ev, "by async query"); |
---|
153 | |
---|
154 | if (ret) { |
---|
155 | passed++; |
---|
156 | fprintf (stderr, "PASSED %d of %d: async activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
157 | } else { |
---|
158 | failed++; |
---|
159 | fprintf (stderr, "FAILED %d of %d: async activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
160 | } |
---|
161 | |
---|
162 | CORBA_exception_free (&ev); |
---|
163 | |
---|
164 | async_done++; |
---|
165 | } |
---|
166 | |
---|
167 | static void |
---|
168 | race_empty (CORBA_Environment *ev) |
---|
169 | { |
---|
170 | bonobo_activation_activate_async ( |
---|
171 | "repo_ids.has('IDL:Empty2:1.0')", NULL, |
---|
172 | 0, empty_activation_cb, "IDL:Empty2:1.0", ev); |
---|
173 | g_assert (ev->_major == CORBA_NO_EXCEPTION); |
---|
174 | |
---|
175 | bonobo_activation_activate_async ( |
---|
176 | "repo_ids.has('IDL:Empty:1.0')", NULL, |
---|
177 | 0, empty_activation_cb, "IDL:Empty:1.0", ev); |
---|
178 | g_assert (ev->_major == CORBA_NO_EXCEPTION); |
---|
179 | |
---|
180 | while (async_done < 2) |
---|
181 | linc_main_iteration (TRUE); |
---|
182 | } |
---|
183 | |
---|
184 | int |
---|
185 | main (int argc, char *argv[]) |
---|
186 | { |
---|
187 | CORBA_Object obj; |
---|
188 | CORBA_Environment ev; |
---|
189 | Bonobo_ServerInfoList *info; |
---|
190 | CORBA_Object ac; |
---|
191 | char *sort_by[4]; |
---|
192 | char *query; |
---|
193 | int i; |
---|
194 | GTimer *timer = g_timer_new (); |
---|
195 | |
---|
196 | CORBA_exception_init (&ev); |
---|
197 | |
---|
198 | bonobo_activation_object_directory_get ( |
---|
199 | bonobo_activation_username_get (), |
---|
200 | bonobo_activation_hostname_get ()); |
---|
201 | |
---|
202 | bonobo_activation_init (argc, argv); |
---|
203 | /* putenv("Bonobo_BARRIER_INIT=1"); */ |
---|
204 | |
---|
205 | race_base_init (); |
---|
206 | |
---|
207 | sort_by[0] = "prefer_by_list_order(iid, [" |
---|
208 | "'OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058'," |
---|
209 | "'OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c'," |
---|
210 | "'OAFIID:nautilus_music_view:9456b5d2-60a8-407f-a56e-d561e1821391'])"; |
---|
211 | sort_by[1] = "iid != 'OAFIID:nautilus_content_loser:95901458-c68b-43aa-aaca-870ced11062d'"; |
---|
212 | sort_by[2] = "iid != 'OAFIID:nautilus_sample_content_view:45c746bc-7d64-4346-90d5-6410463b43ae'"; |
---|
213 | sort_by[3] = NULL; |
---|
214 | |
---|
215 | query = "( (((repo_ids.has_all (['IDL:Bonobo/Control:1.0'," |
---|
216 | "'IDL:Nautilus/View:1.0']) OR (repo_ids.has_one " |
---|
217 | "(['IDL:Bonobo/Control:1.0','IDL:Bonobo/Embeddable:1.0']) AND " |
---|
218 | "repo_ids.has_one (['IDL:Bonobo/PersistStream:1.0', " |
---|
219 | "'IDL:Bonobo/ProgressiveDataSink:1.0', " |
---|
220 | "'IDL:Bonobo/PersistFile:1.0']))) AND (bonobo:supported_mime_types.defined () OR " |
---|
221 | "bonobo:supported_uri_schemes.defined () OR " |
---|
222 | "bonobo:additional_uri_schemes.defined ()) AND " |
---|
223 | "(((NOT bonobo:supported_mime_types.defined () OR " |
---|
224 | "bonobo:supported_mime_types.has ('x-directory/normal') OR " |
---|
225 | "bonobo:supported_mime_types.has ('x-directory/*') OR " |
---|
226 | "bonobo:supported_mime_types.has ('*/*')) AND " |
---|
227 | "(NOT bonobo:supported_uri_schemes.defined () OR " |
---|
228 | "bonobo:supported_uri_schemes.has ('file') OR " |
---|
229 | "bonobo:supported_uri_schemes.has ('*'))) OR " |
---|
230 | "(bonobo:additional_uri_schemes.has ('file') OR " |
---|
231 | "bonobo:additional_uri_schemes.has ('*'))) AND " |
---|
232 | "nautilus:view_as_name.defined ()) OR false) AND " |
---|
233 | "(has (['OAFIID:nautilus_file_manager_icon_view:42681b21-d5ca-4837-87d2-394d88ecc058', " |
---|
234 | "'OAFIID:nautilus_file_manager_list_view:521e489d-0662-4ad7-ac3a-832deabe111c'], iid)) ) AND " |
---|
235 | "(NOT test_only.defined() OR NOT test_only)"; |
---|
236 | |
---|
237 | ac = bonobo_activation_activation_context_get (); |
---|
238 | |
---|
239 | g_timer_start (timer); |
---|
240 | |
---|
241 | info = bonobo_activation_query (query, sort_by, &ev); |
---|
242 | |
---|
243 | for (i = 0; i < 1000; i++) { |
---|
244 | Bonobo_ServerInfoList *copy; |
---|
245 | #if 0 |
---|
246 | info = bonobo_activation_query (query, sort_by, &ev); |
---|
247 | |
---|
248 | if (ev._major == CORBA_NO_EXCEPTION) { |
---|
249 | CORBA_free (info); |
---|
250 | } else { |
---|
251 | fprintf (stderr, "Test of query failed '%s'\n", |
---|
252 | bonobo_activation_exception_id (&ev)); |
---|
253 | } |
---|
254 | #else |
---|
255 | copy = Bonobo_ServerInfoList_duplicate (info); |
---|
256 | CORBA_free (copy); |
---|
257 | #endif |
---|
258 | } |
---|
259 | g_timer_stop (timer); |
---|
260 | |
---|
261 | fprintf (stderr, "Time to query '%g'\n", g_timer_elapsed (timer, NULL)); |
---|
262 | if (ev._major == CORBA_NO_EXCEPTION) { |
---|
263 | passed++; |
---|
264 | fprintf (stderr, "PASSED %d of %d: timed query\n", passed + failed, TOTAL_TEST_SCORE); |
---|
265 | } else { |
---|
266 | failed++; |
---|
267 | fprintf (stderr, "FAILED %d of %d: timed query\n", passed + failed, TOTAL_TEST_SCORE); |
---|
268 | CORBA_exception_free (&ev); |
---|
269 | } |
---|
270 | |
---|
271 | /* |
---|
272 | * We wait to see if the server (sever) |
---|
273 | * timeout is mis-behaving [ at this stage we |
---|
274 | * havn't registered anything with the server ] |
---|
275 | */ |
---|
276 | fprintf (stderr, "Waiting to see if the server erroneously quits\n"); |
---|
277 | sleep (SERVER_IDLE_QUIT_TIMEOUT * 2 / 1000); |
---|
278 | g_assert (ORBit_small_get_connection_status (ac) == |
---|
279 | ORBIT_CONNECTION_CONNECTED); |
---|
280 | |
---|
281 | race_empty (&ev); |
---|
282 | |
---|
283 | obj = bonobo_activation_activate_from_id ("OAFIID:Empty:19991025", 0, NULL, &ev); |
---|
284 | if (test_object (obj, &ev, "from id") && test_empty (obj, &ev, "from id")) { |
---|
285 | passed++; |
---|
286 | fprintf (stderr, "PASSED %d of %d: IID activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
287 | } else { |
---|
288 | failed++; |
---|
289 | fprintf (stderr, "FAILED %d of %d: IID activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
290 | } |
---|
291 | |
---|
292 | obj = bonobo_activation_activate_from_id ("OAFAID:[OAFIID:Empty:19991025]", 0, NULL, &ev); |
---|
293 | if (test_object (obj, &ev, "from aid") && test_empty (obj, &ev, "from aid")) { |
---|
294 | passed++; |
---|
295 | fprintf (stderr, "PASSED %d of %d: AID activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
296 | } else { |
---|
297 | failed++; |
---|
298 | fprintf (stderr, "FAILED %d of %d: AID activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
299 | } |
---|
300 | |
---|
301 | obj = bonobo_activation_activate_from_id ("OAFAID:[OAFIID:Plugin:20010713]", 0, NULL, &ev); |
---|
302 | if (test_object (obj, &ev, "from aid") && test_plugin (obj, &ev, "from aid")) { |
---|
303 | passed++; |
---|
304 | fprintf (stderr, "PASSED %d of %d: plugin activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
305 | } else { |
---|
306 | failed++; |
---|
307 | fprintf (stderr, "FAILED %d of %d: plugin activation\n", passed + failed, TOTAL_TEST_SCORE); |
---|
308 | } |
---|
309 | |
---|
310 | obj = bonobo_activation_activate_from_id ("OAFIID:Bogus:20000526", 0, NULL, &ev); |
---|
311 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
312 | passed++; |
---|
313 | fprintf (stderr, "PASSED %d of %d: Broken link test : %s\n", |
---|
314 | passed + failed, TOTAL_TEST_SCORE, bonobo_activation_exception_id (&ev)); |
---|
315 | CORBA_exception_free (&ev); |
---|
316 | } else { |
---|
317 | failed++; |
---|
318 | fprintf (stderr, "FAILED %d of %d: Broken link test\n", passed + failed, TOTAL_TEST_SCORE); |
---|
319 | } |
---|
320 | |
---|
321 | if (test_bonobo_activation_server (&ev, "with broken factory link")) { |
---|
322 | passed++; |
---|
323 | fprintf (stderr, "PASSED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
324 | } else { |
---|
325 | failed++; |
---|
326 | fprintf (stderr, "FAILED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
327 | } |
---|
328 | |
---|
329 | fprintf (stderr, "Broken exe test "); |
---|
330 | obj = bonobo_activation_activate_from_id ("OAFIID:Broken:20000530", 0, NULL, &ev); |
---|
331 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
332 | passed++; |
---|
333 | fprintf (stderr, "PASSED %d of %d: Broken exe test : %s\n", |
---|
334 | passed + failed, TOTAL_TEST_SCORE, bonobo_activation_exception_id (&ev)); |
---|
335 | CORBA_exception_free (&ev); |
---|
336 | } else { |
---|
337 | failed++; |
---|
338 | fprintf (stderr, "FAILED %d of %d: Broken exe test\n", passed + failed, TOTAL_TEST_SCORE); |
---|
339 | } |
---|
340 | |
---|
341 | if (test_bonobo_activation_server (&ev, "with broken factory link")) { |
---|
342 | passed++; |
---|
343 | fprintf (stderr, "PASSED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
344 | } else { |
---|
345 | failed++; |
---|
346 | fprintf (stderr, "FAILED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
347 | } |
---|
348 | |
---|
349 | obj = bonobo_activation_activate_from_id ("OAFIID:Circular:20000530", 0, NULL, &ev); |
---|
350 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
351 | passed++; |
---|
352 | fprintf (stderr, "PASSED %d of %d: Circular link test : %s\n", |
---|
353 | passed + failed, TOTAL_TEST_SCORE, bonobo_activation_exception_id (&ev)); |
---|
354 | CORBA_exception_free (&ev); |
---|
355 | } else { |
---|
356 | failed++; |
---|
357 | fprintf (stderr, "FAILED %d of %d: Circular link test\n", passed + failed, TOTAL_TEST_SCORE); |
---|
358 | } |
---|
359 | |
---|
360 | if (test_bonobo_activation_server (&ev, "with broken factory link")) { |
---|
361 | passed++; |
---|
362 | fprintf (stderr, "PASSED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
363 | } else { |
---|
364 | failed++; |
---|
365 | fprintf (stderr, "FAILED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
366 | } |
---|
367 | |
---|
368 | obj = bonobo_activation_activate_from_id ("OAFIID:NotInServer:20000717", 0, NULL, &ev); |
---|
369 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
370 | passed++; |
---|
371 | fprintf (stderr, "PASSED %d of %d: Server that doesn't register IID test : %s\n", |
---|
372 | passed + failed, TOTAL_TEST_SCORE, bonobo_activation_exception_id (&ev)); |
---|
373 | CORBA_exception_free (&ev); |
---|
374 | } else { |
---|
375 | failed++; |
---|
376 | fprintf (stderr, "FAILED %d of %d: Server that doesn't register IID test\n", |
---|
377 | passed + failed, TOTAL_TEST_SCORE); |
---|
378 | } |
---|
379 | |
---|
380 | if (test_bonobo_activation_server (&ev, "with non-registering server")) { |
---|
381 | passed++; |
---|
382 | fprintf (stderr, "PASSED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
383 | } else { |
---|
384 | failed++; |
---|
385 | fprintf (stderr, "FAILED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
386 | } |
---|
387 | |
---|
388 | obj = bonobo_activation_activate_from_id ("OAFIID:BrokenNoType:20000808", 0, NULL, &ev); |
---|
389 | if (ev._major != CORBA_NO_EXCEPTION) { |
---|
390 | failed++; |
---|
391 | fprintf (stderr, "FAILED %d of %d: Server with IID but no type or location : %s\n", |
---|
392 | passed + failed, TOTAL_TEST_SCORE, bonobo_activation_exception_id (&ev)); |
---|
393 | CORBA_exception_free (&ev); |
---|
394 | } else if (obj) { |
---|
395 | failed++; |
---|
396 | fprintf (stderr, "FAILED %d of %d: Server with IID but no type or location\n", |
---|
397 | passed + failed, TOTAL_TEST_SCORE); |
---|
398 | } else { |
---|
399 | passed++; |
---|
400 | fprintf (stderr, "PASSED %d of %d: Server with IID but no type or location\n", |
---|
401 | passed + failed, TOTAL_TEST_SCORE); |
---|
402 | } |
---|
403 | |
---|
404 | if (test_bonobo_activation_server (&ev, "with no-type/loc server")) { |
---|
405 | passed++; |
---|
406 | fprintf (stderr, "PASSED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
407 | } else { |
---|
408 | failed++; |
---|
409 | fprintf (stderr, "FAILED %d of %d: activation server okay\n", passed + failed, TOTAL_TEST_SCORE); |
---|
410 | } |
---|
411 | |
---|
412 | fprintf (stderr, "\n%d of %d tests passed (%s)\n", passed, |
---|
413 | TOTAL_TEST_SCORE, |
---|
414 | passed == TOTAL_TEST_SCORE? "All": "some failures"); |
---|
415 | |
---|
416 | if (passed < (TOTAL_TEST_SCORE * 2 / 3)) { |
---|
417 | fprintf (stderr, "It looks like you havn't installed broken.server " |
---|
418 | "into ${prefix}/share/bonobo-activation/, this must be done " |
---|
419 | "by hand to avoid problems with normal operation.\n"); |
---|
420 | fprintf (stderr, "Another possibility is that you failed to kill " |
---|
421 | "bonobo_activation_server before running make check; try running bonobo-slay.\n"); |
---|
422 | } |
---|
423 | |
---|
424 | if (name_service != CORBA_OBJECT_NIL) |
---|
425 | CORBA_Object_release (name_service, &ev); |
---|
426 | |
---|
427 | CORBA_exception_free (&ev); |
---|
428 | |
---|
429 | if (passed == TOTAL_TEST_SCORE) { |
---|
430 | if (bonobo_activation_debug_shutdown ()) { |
---|
431 | return 0; |
---|
432 | } else { |
---|
433 | return 1; |
---|
434 | } |
---|
435 | } else { |
---|
436 | return 1; |
---|
437 | } |
---|
438 | } |
---|