diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-07 21:08:57 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-07 21:08:57 +0000 |
commit | 1dcc15b451d79fda1bda12077c78f4a6b73d4a48 (patch) | |
tree | a1fa91a3637c33c7247bdc32a7cf3d5c80750e5f | |
parent | d66ade0522e3a00c9f8e2b84632f80e93d49e753 (diff) | |
download | gnunet-1dcc15b451d79fda1bda12077c78f4a6b73d4a48.tar.gz gnunet-1dcc15b451d79fda1bda12077c78f4a6b73d4a48.zip |
adding test for immediately rejected phone call
-rw-r--r-- | src/conversation/Makefile.am | 16 | ||||
-rw-r--r-- | src/conversation/test_conversation_api_reject.c | 339 |
2 files changed, 354 insertions, 1 deletions
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am index 66a5a2b5b..da5702653 100644 --- a/src/conversation/Makefile.am +++ b/src/conversation/Makefile.am | |||
@@ -79,6 +79,7 @@ endif | |||
79 | 79 | ||
80 | check_PROGRAMS = \ | 80 | check_PROGRAMS = \ |
81 | test_conversation_api \ | 81 | test_conversation_api \ |
82 | test_conversation_api_reject \ | ||
82 | test_conversation_api_twocalls | 83 | test_conversation_api_twocalls |
83 | 84 | ||
84 | if HAVE_PULSE | 85 | if HAVE_PULSE |
@@ -157,7 +158,6 @@ test_conversation_api_LDADD = \ | |||
157 | test_conversation_api_LDFLAGS = \ | 158 | test_conversation_api_LDFLAGS = \ |
158 | $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic | 159 | $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic |
159 | 160 | ||
160 | |||
161 | test_conversation_api_twocalls_SOURCES = \ | 161 | test_conversation_api_twocalls_SOURCES = \ |
162 | test_conversation_api_twocalls.c | 162 | test_conversation_api_twocalls.c |
163 | test_conversation_api_twocalls_LDADD = \ | 163 | test_conversation_api_twocalls_LDADD = \ |
@@ -172,6 +172,20 @@ test_conversation_api_twocalls_LDADD = \ | |||
172 | test_conversation_api_twocalls_LDFLAGS = \ | 172 | test_conversation_api_twocalls_LDFLAGS = \ |
173 | $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic | 173 | $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic |
174 | 174 | ||
175 | test_conversation_api_reject_SOURCES = \ | ||
176 | test_conversation_api_reject.c | ||
177 | test_conversation_api_reject_LDADD = \ | ||
178 | libgnunetconversation.la \ | ||
179 | libgnunetspeaker.la \ | ||
180 | libgnunetmicrophone.la \ | ||
181 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
182 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
183 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
184 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
185 | $(top_builddir)/src/util/libgnunetutil.la | ||
186 | test_conversation_api_reject_LDFLAGS = \ | ||
187 | $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic | ||
188 | |||
175 | 189 | ||
176 | pkgcfg_DATA = conversation.conf | 190 | pkgcfg_DATA = conversation.conf |
177 | 191 | ||
diff --git a/src/conversation/test_conversation_api_reject.c b/src/conversation/test_conversation_api_reject.c new file mode 100644 index 000000000..78882c3bb --- /dev/null +++ b/src/conversation/test_conversation_api_reject.c | |||
@@ -0,0 +1,339 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file conversation/test_conversation_api_reject.c | ||
22 | * @brief testcase for conversation_api.c | ||
23 | * | ||
24 | * This test performs the operations of a call to a phone | ||
25 | * where the phone user immediately hangs up (rejecting the | ||
26 | * call). | ||
27 | */ | ||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | #include "gnunet_gnsrecord_lib.h" | ||
32 | #include "gnunet_conversation_service.h" | ||
33 | #include "gnunet_identity_service.h" | ||
34 | #include "gnunet_namestore_service.h" | ||
35 | |||
36 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 25) | ||
37 | |||
38 | static int ok = 1; | ||
39 | |||
40 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
41 | |||
42 | static struct GNUNET_IDENTITY_Handle *id; | ||
43 | |||
44 | static struct GNUNET_IDENTITY_Operation *op; | ||
45 | |||
46 | static struct GNUNET_CONVERSATION_Phone *phone; | ||
47 | |||
48 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
49 | |||
50 | static struct GNUNET_CONVERSATION_Call *call; | ||
51 | |||
52 | static struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
53 | |||
54 | static char *gns_name; | ||
55 | |||
56 | static char *gns_caller_id; | ||
57 | |||
58 | |||
59 | static int | ||
60 | enable_speaker (void *cls) | ||
61 | { | ||
62 | GNUNET_break (0); | ||
63 | return GNUNET_SYSERR; | ||
64 | } | ||
65 | |||
66 | |||
67 | static void | ||
68 | disable_speaker (void *cls) | ||
69 | { | ||
70 | GNUNET_break (0); | ||
71 | } | ||
72 | |||
73 | |||
74 | static void | ||
75 | play (void *cls, | ||
76 | size_t data_size, | ||
77 | const void *data) | ||
78 | { | ||
79 | GNUNET_break (0); | ||
80 | } | ||
81 | |||
82 | |||
83 | static void | ||
84 | destroy_speaker (void *cls) | ||
85 | { | ||
86 | } | ||
87 | |||
88 | |||
89 | static struct GNUNET_SPEAKER_Handle call_speaker = { | ||
90 | &enable_speaker, | ||
91 | &play, | ||
92 | &disable_speaker, | ||
93 | &destroy_speaker, | ||
94 | "caller" | ||
95 | }; | ||
96 | |||
97 | |||
98 | static int | ||
99 | enable_mic (void *cls, | ||
100 | GNUNET_MICROPHONE_RecordedDataCallback rdc, | ||
101 | void *rdc_cls) | ||
102 | { | ||
103 | GNUNET_break (0); | ||
104 | return GNUNET_SYSERR; | ||
105 | } | ||
106 | |||
107 | |||
108 | static void | ||
109 | disable_mic (void *cls) | ||
110 | { | ||
111 | GNUNET_break (0); | ||
112 | } | ||
113 | |||
114 | |||
115 | static void | ||
116 | destroy_mic (void *cls) | ||
117 | { | ||
118 | } | ||
119 | |||
120 | |||
121 | static struct GNUNET_MICROPHONE_Handle call_mic = { | ||
122 | &enable_mic, | ||
123 | &disable_mic, | ||
124 | &destroy_mic, | ||
125 | "caller" | ||
126 | }; | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Signature of the main function of a task. | ||
131 | * | ||
132 | * @param cls closure | ||
133 | * @param tc context information (why was this task triggered now) | ||
134 | */ | ||
135 | static void | ||
136 | end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
137 | { | ||
138 | GNUNET_SCHEDULER_shutdown (); | ||
139 | if (NULL != op) | ||
140 | { | ||
141 | GNUNET_IDENTITY_cancel (op); | ||
142 | op = NULL; | ||
143 | } | ||
144 | if (NULL != call) | ||
145 | { | ||
146 | GNUNET_CONVERSATION_call_stop (call); | ||
147 | call = NULL; | ||
148 | } | ||
149 | if (NULL != phone) | ||
150 | { | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n"); | ||
152 | GNUNET_CONVERSATION_phone_destroy (phone); | ||
153 | phone = NULL; | ||
154 | } | ||
155 | if (NULL != id) | ||
156 | { | ||
157 | GNUNET_IDENTITY_disconnect (id); | ||
158 | id = NULL; | ||
159 | } | ||
160 | if (NULL != qe) | ||
161 | { | ||
162 | GNUNET_NAMESTORE_cancel (qe); | ||
163 | qe = NULL; | ||
164 | } | ||
165 | if (NULL != ns) | ||
166 | { | ||
167 | GNUNET_NAMESTORE_disconnect (ns); | ||
168 | ns = NULL; | ||
169 | } | ||
170 | } | ||
171 | |||
172 | |||
173 | static void | ||
174 | phone_event_handler (void *cls, | ||
175 | enum GNUNET_CONVERSATION_PhoneEventCode code, | ||
176 | struct GNUNET_CONVERSATION_Caller *caller, | ||
177 | const char *caller_id) | ||
178 | { | ||
179 | static enum GNUNET_CONVERSATION_PhoneEventCode expect | ||
180 | = GNUNET_CONVERSATION_EC_PHONE_RING; | ||
181 | |||
182 | GNUNET_break (0 == strcmp (caller_id, | ||
183 | gns_caller_id)); | ||
184 | GNUNET_break (code == expect); | ||
185 | switch (code) | ||
186 | { | ||
187 | case GNUNET_CONVERSATION_EC_PHONE_RING: | ||
188 | GNUNET_CONVERSATION_caller_hang_up (caller); | ||
189 | break; | ||
190 | default: | ||
191 | fprintf (stderr, "Unexpected phone code: %d\n", code); | ||
192 | break; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | |||
197 | static void | ||
198 | call_event_handler (void *cls, | ||
199 | enum GNUNET_CONVERSATION_CallEventCode code) | ||
200 | { | ||
201 | static enum GNUNET_CONVERSATION_CallEventCode expect | ||
202 | = GNUNET_CONVERSATION_EC_CALL_RINGING; | ||
203 | |||
204 | GNUNET_break (code == expect); | ||
205 | switch (code) | ||
206 | { | ||
207 | case GNUNET_CONVERSATION_EC_CALL_RINGING: | ||
208 | expect = GNUNET_CONVERSATION_EC_CALL_HUNG_UP; | ||
209 | break; | ||
210 | case GNUNET_CONVERSATION_EC_CALL_HUNG_UP: | ||
211 | call = NULL; | ||
212 | ok = 0; | ||
213 | GNUNET_SCHEDULER_shutdown (); | ||
214 | expect = -1; | ||
215 | break; | ||
216 | case GNUNET_CONVERSATION_EC_CALL_PICKED_UP: | ||
217 | case GNUNET_CONVERSATION_EC_CALL_GNS_FAIL: | ||
218 | case GNUNET_CONVERSATION_EC_CALL_SUSPENDED: | ||
219 | case GNUNET_CONVERSATION_EC_CALL_RESUMED: | ||
220 | fprintf (stderr, "Unexpected call code: %d\n", code); | ||
221 | break; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | |||
226 | static void | ||
227 | caller_ego_create_cont (void *cls, | ||
228 | const char *emsg) | ||
229 | { | ||
230 | op = NULL; | ||
231 | GNUNET_assert (NULL == emsg); | ||
232 | } | ||
233 | |||
234 | |||
235 | static void | ||
236 | namestore_put_cont (void *cls, | ||
237 | int32_t success, | ||
238 | const char *emsg) | ||
239 | { | ||
240 | qe = NULL; | ||
241 | GNUNET_assert (GNUNET_YES == success); | ||
242 | GNUNET_assert (NULL == emsg); | ||
243 | GNUNET_assert (NULL == op); | ||
244 | op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL); | ||
245 | } | ||
246 | |||
247 | |||
248 | static void | ||
249 | identity_cb (void *cls, | ||
250 | struct GNUNET_IDENTITY_Ego *ego, | ||
251 | void **ctx, | ||
252 | const char *name) | ||
253 | { | ||
254 | struct GNUNET_GNSRECORD_Data rd; | ||
255 | struct GNUNET_CRYPTO_EcdsaPublicKey pub; | ||
256 | |||
257 | if (NULL == name) | ||
258 | return; | ||
259 | if (NULL == ego) | ||
260 | return; | ||
261 | if (0 == strcmp (name, "phone-ego")) | ||
262 | { | ||
263 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | ||
264 | GNUNET_asprintf (&gns_name, | ||
265 | "phone.%s", | ||
266 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | ||
267 | phone = GNUNET_CONVERSATION_phone_create (cfg, | ||
268 | ego, | ||
269 | &phone_event_handler, | ||
270 | NULL); | ||
271 | GNUNET_assert (NULL != phone); | ||
272 | memset (&rd, 0, sizeof (rd)); | ||
273 | GNUNET_CONVERSATION_phone_get_record (phone, | ||
274 | &rd); | ||
275 | GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE); | ||
276 | rd.expiration_time = UINT64_MAX; | ||
277 | qe = GNUNET_NAMESTORE_records_store (ns, | ||
278 | GNUNET_IDENTITY_ego_get_private_key (ego), | ||
279 | "phone" /* GNS label */, | ||
280 | 1, | ||
281 | &rd, | ||
282 | &namestore_put_cont, | ||
283 | NULL); | ||
284 | return; | ||
285 | } | ||
286 | if (0 == strcmp (name, "caller-ego")) | ||
287 | { | ||
288 | GNUNET_IDENTITY_ego_get_public_key (ego, &pub); | ||
289 | GNUNET_asprintf (&gns_caller_id, | ||
290 | "%s", | ||
291 | GNUNET_GNSRECORD_pkey_to_zkey (&pub)); | ||
292 | call = GNUNET_CONVERSATION_call_start (cfg, | ||
293 | ego, | ||
294 | gns_name, | ||
295 | &call_speaker, | ||
296 | &call_mic, | ||
297 | &call_event_handler, | ||
298 | NULL); | ||
299 | return; | ||
300 | } | ||
301 | } | ||
302 | |||
303 | |||
304 | static void | ||
305 | phone_ego_create_cont (void *cls, | ||
306 | const char *emsg) | ||
307 | { | ||
308 | op = NULL; | ||
309 | GNUNET_assert (NULL == emsg); | ||
310 | } | ||
311 | |||
312 | |||
313 | static void | ||
314 | run (void *cls, | ||
315 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
316 | struct GNUNET_TESTING_Peer *peer) | ||
317 | { | ||
318 | cfg = c; | ||
319 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_test, | ||
320 | NULL); | ||
321 | id = GNUNET_IDENTITY_connect (cfg, | ||
322 | &identity_cb, | ||
323 | NULL); | ||
324 | op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL); | ||
325 | ns = GNUNET_NAMESTORE_connect (cfg); | ||
326 | } | ||
327 | |||
328 | |||
329 | int | ||
330 | main (int argc, char *argv[]) | ||
331 | { | ||
332 | if (0 != GNUNET_TESTING_peer_run ("test_conversation_api", | ||
333 | "test_conversation.conf", | ||
334 | &run, NULL)) | ||
335 | return 1; | ||
336 | return ok; | ||
337 | } | ||
338 | |||
339 | /* end of test_conversation_api_reject.c */ | ||