1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
---|
2 | #include <stdio.h> |
---|
3 | #include <stdlib.h> |
---|
4 | #include <time.h> |
---|
5 | |
---|
6 | #include <bonobo-activation/bonobo-activation.h> |
---|
7 | |
---|
8 | #define DEBUG_TIMEOUT 2 |
---|
9 | #define DEBUG_TIME 1 |
---|
10 | |
---|
11 | typedef struct { |
---|
12 | gboolean callback_called; |
---|
13 | gboolean succeeded; |
---|
14 | } callback_data_t; |
---|
15 | |
---|
16 | |
---|
17 | static void |
---|
18 | test_callback (CORBA_Object activated_object, |
---|
19 | const char *error_reason, |
---|
20 | gpointer user_data) |
---|
21 | { |
---|
22 | callback_data_t *data; |
---|
23 | |
---|
24 | data = (callback_data_t *) user_data; |
---|
25 | |
---|
26 | if (activated_object == CORBA_OBJECT_NIL) { |
---|
27 | data->succeeded = FALSE; |
---|
28 | } else { |
---|
29 | CORBA_Environment ev; |
---|
30 | |
---|
31 | CORBA_exception_init (&ev); |
---|
32 | CORBA_Object_release (activated_object, &ev); |
---|
33 | CORBA_exception_free (&ev); |
---|
34 | |
---|
35 | data->succeeded = TRUE; |
---|
36 | } |
---|
37 | |
---|
38 | data->callback_called = TRUE; |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | /* returns TRUE in case of success. FALSE otherwise. |
---|
43 | -1 if answer timeouted.... */ |
---|
44 | static int |
---|
45 | test_activate (char *requirements) |
---|
46 | { |
---|
47 | CORBA_Environment ev; |
---|
48 | callback_data_t data; |
---|
49 | #if DEBUG_TIME |
---|
50 | time_t beg_time; |
---|
51 | #endif |
---|
52 | |
---|
53 | CORBA_exception_init (&ev); |
---|
54 | |
---|
55 | data.callback_called = FALSE; |
---|
56 | bonobo_activation_activate_async (requirements, NULL, 0, test_callback, &data, &ev); |
---|
57 | |
---|
58 | #if DEBUG_TIME |
---|
59 | beg_time = time (NULL); |
---|
60 | #endif |
---|
61 | |
---|
62 | while (data.callback_called == FALSE) { |
---|
63 | g_main_context_iteration (NULL, FALSE); |
---|
64 | #if DEBUG_TIME |
---|
65 | if (time (NULL) > (beg_time + DEBUG_TIMEOUT)) { |
---|
66 | return -1; |
---|
67 | } |
---|
68 | #endif |
---|
69 | } |
---|
70 | |
---|
71 | |
---|
72 | if (data.succeeded == TRUE) { |
---|
73 | return TRUE; |
---|
74 | } else { |
---|
75 | return FALSE; |
---|
76 | } |
---|
77 | } |
---|
78 | |
---|
79 | /* returns TRUE in case of success. FALSE otherwise. |
---|
80 | -1 if answer timeouted.... */ |
---|
81 | static int |
---|
82 | test_activate_from_id (char *aid) |
---|
83 | { |
---|
84 | CORBA_Environment ev; |
---|
85 | callback_data_t data; |
---|
86 | #if DEBUG_TIME |
---|
87 | time_t beg_time; |
---|
88 | #endif |
---|
89 | |
---|
90 | CORBA_exception_init (&ev); |
---|
91 | |
---|
92 | data.callback_called = FALSE; |
---|
93 | bonobo_activation_activate_from_id_async (aid, 0, test_callback, &data, &ev); |
---|
94 | |
---|
95 | #if DEBUG_TIME |
---|
96 | beg_time = time (NULL); |
---|
97 | #endif |
---|
98 | |
---|
99 | while (data.callback_called == FALSE) { |
---|
100 | g_main_context_iteration (NULL, FALSE); |
---|
101 | #if DEBUG_TIME |
---|
102 | if (time (NULL) > (beg_time + DEBUG_TIMEOUT)) { |
---|
103 | return -1; |
---|
104 | } |
---|
105 | #endif |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | if (data.succeeded == TRUE) { |
---|
110 | return TRUE; |
---|
111 | } else { |
---|
112 | return FALSE; |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | |
---|
117 | #define TOTAL_TESTS 4 |
---|
118 | int |
---|
119 | main (int argc, char *argv[]) |
---|
120 | { |
---|
121 | int test_status; |
---|
122 | int test_passed; |
---|
123 | |
---|
124 | test_passed = 0; |
---|
125 | |
---|
126 | bonobo_activation_init (argc, argv); |
---|
127 | printf ("testing async interfaces\n"); |
---|
128 | |
---|
129 | printf ("testing activate_async... "); |
---|
130 | /* this should fail */ |
---|
131 | test_status = test_activate (""); |
---|
132 | if (test_status == FALSE) { |
---|
133 | test_passed++; |
---|
134 | printf (" passed\n"); |
---|
135 | } else if (test_status == TRUE |
---|
136 | || test_status == -1) { |
---|
137 | printf (" failed\n"); |
---|
138 | } |
---|
139 | |
---|
140 | printf ("testing activate_async... "); |
---|
141 | test_status = test_activate ("has (repo_ids, 'IDL:Empty:1.0')"); |
---|
142 | if (test_status == TRUE) { |
---|
143 | test_passed++; |
---|
144 | printf (" passed\n"); |
---|
145 | } else if (test_status == FALSE |
---|
146 | || test_status == -1) { |
---|
147 | printf (" failed\n"); |
---|
148 | } |
---|
149 | |
---|
150 | printf ("testing activate_from_id_async... "); |
---|
151 | test_status = test_activate_from_id (""); |
---|
152 | if (test_status == FALSE) { |
---|
153 | test_passed++; |
---|
154 | printf (" passed\n"); |
---|
155 | } else if (test_status == TRUE |
---|
156 | || test_status == -1) { |
---|
157 | printf (" failed\n"); |
---|
158 | } |
---|
159 | |
---|
160 | printf ("testing activate_from_id_async... "); |
---|
161 | test_status = test_activate_from_id ("OAFIID:Empty:19991025"); |
---|
162 | if (test_status == TRUE) { |
---|
163 | test_passed++; |
---|
164 | printf (" passed\n"); |
---|
165 | } else if (test_status == FALSE |
---|
166 | || test_status == -1) { |
---|
167 | printf (" failed\n"); |
---|
168 | } |
---|
169 | |
---|
170 | printf ("Async Test Results: %d passed upon %d \n", |
---|
171 | test_passed, TOTAL_TESTS); |
---|
172 | |
---|
173 | if (test_passed != TOTAL_TESTS) { |
---|
174 | return 1; |
---|
175 | } |
---|
176 | |
---|
177 | if (bonobo_activation_debug_shutdown ()) { |
---|
178 | return 0; |
---|
179 | } else { |
---|
180 | return 1; |
---|
181 | } |
---|
182 | } |
---|