aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-11-18 17:05:33 +0000
committerChristian Grothoff <christian@grothoff.org>2013-11-18 17:05:33 +0000
commite317089337c59773aecd7aef7c761be4804462f3 (patch)
tree03952abc282af4f0b120fb759b9cae979e572643 /src
parent2f458da11619c091b26e4f6d0f5c2cd05564dc9f (diff)
downloadgnunet-e317089337c59773aecd7aef7c761be4804462f3.tar.gz
gnunet-e317089337c59773aecd7aef7c761be4804462f3.zip
-towards a real test for conversation
Diffstat (limited to 'src')
-rw-r--r--src/conversation/Makefile.am8
-rw-r--r--src/conversation/test_conversation.conf2
-rw-r--r--src/conversation/test_conversation_api.c292
3 files changed, 265 insertions, 37 deletions
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am
index e40846098..701dfd820 100644
--- a/src/conversation/Makefile.am
+++ b/src/conversation/Makefile.am
@@ -146,8 +146,16 @@ test_conversation_api_SOURCES = \
146 test_conversation_api.c 146 test_conversation_api.c
147test_conversation_api_LDADD = \ 147test_conversation_api_LDADD = \
148 libgnunetconversation.la \ 148 libgnunetconversation.la \
149 libgnunetspeaker.la \
150 libgnunetmicrophone.la \
151 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
152 $(top_builddir)/src/namestore/libgnunetnamestore.la \
153 $(top_builddir)/src/identity/libgnunetidentity.la \
154 $(top_builddir)/src/testing/libgnunettesting.la \
149 $(top_builddir)/src/util/libgnunetutil.la 155 $(top_builddir)/src/util/libgnunetutil.la
150test_conversation_api_LDFLAGS = \ 156test_conversation_api_LDFLAGS = \
151 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic 157 $(GNUNET_LDFLAGS) $(WINFLAGS) -export-dynamic
152 158
153 pkgcfg_DATA = conversation.conf 159 pkgcfg_DATA = conversation.conf
160
161EXTRA_DIST = test_conversation.conf
diff --git a/src/conversation/test_conversation.conf b/src/conversation/test_conversation.conf
new file mode 100644
index 000000000..25e4bb34d
--- /dev/null
+++ b/src/conversation/test_conversation.conf
@@ -0,0 +1,2 @@
1[conversation]
2LINE=1
diff --git a/src/conversation/test_conversation_api.c b/src/conversation/test_conversation_api.c
index 101245c9e..592eeacd1 100644
--- a/src/conversation/test_conversation_api.c
+++ b/src/conversation/test_conversation_api.c
@@ -23,64 +23,282 @@
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "gnunet_util_lib.h" 25#include "gnunet_util_lib.h"
26#include "gnunet_testing_lib.h"
27#include "gnunet_gnsrecord_lib.h"
26#include "gnunet_conversation_service.h" 28#include "gnunet_conversation_service.h"
27 29#include "gnunet_identity_service.h"
30#include "gnunet_namestore_service.h"
28 31
29static int ok = 1; 32static int ok = 1;
30 33
34static const struct GNUNET_CONFIGURATION_Handle *cfg;
35
36static struct GNUNET_IDENTITY_Handle *id;
37
38static struct GNUNET_IDENTITY_Operation *op;
39
40static struct GNUNET_CONVERSATION_Phone *phone;
41
42static struct GNUNET_NAMESTORE_Handle *ns;
43
44static struct GNUNET_CONVERSATION_Call *call;
45
46static struct GNUNET_NAMESTORE_QueueEntry *qe;
47
48static char *gns_name;
49
50static int
51enable_speaker (void *cls)
52{
53 const char *origin = cls;
54
55 fprintf (stderr, "Speaker %s enabled\n", origin);
56 return GNUNET_OK;
57}
31 58
32static void 59static void
33run (void *cls, 60disable_speaker (void *cls)
34 char *const *args,
35 const char *cfgfile,
36 const struct GNUNET_CONFIGURATION_Handle *cfg)
37{ 61{
38 ok = 0; 62 const char *origin = cls;
63
64 fprintf (stderr, "Speaker %s disabled\n", origin);
65}
66
67static void
68play (void *cls,
69 size_t data_size,
70 const void *data)
71{
72 const char *origin = cls;
73
74 fprintf (stderr, "Speaker %s plays %u bytes\n", origin, (unsigned int) data_size);
75}
76
77static void
78destroy_speaker (void *cls)
79{
80 const char *origin = cls;
81
82 fprintf (stderr, "Speaker %s destroyed\n", origin);
39} 83}
40 84
41 85
86static struct GNUNET_SPEAKER_Handle caller_speaker = {
87 &enable_speaker,
88 &play,
89 &disable_speaker,
90 &destroy_speaker,
91 "caller"
92};
93
94
42static int 95static int
43check () 96enable_mic (void *cls,
97 GNUNET_MICROPHONE_RecordedDataCallback rdc,
98 void *rdc_cls)
99{
100 const char *origin = cls;
101
102 fprintf (stderr, "Mic %s enabled\n", origin);
103 return GNUNET_OK;
104}
105
106static void
107disable_mic (void *cls)
108{
109 const char *origin = cls;
110
111 fprintf (stderr, "Mic %s disabled\n", origin);
112}
113
114static void
115destroy_mic (void *cls)
44{ 116{
45 char *const argv[] = { "test-conversation-api", NULL }; 117 const char *origin = cls;
46 struct GNUNET_GETOPT_CommandLineOption options[] = {
47 GNUNET_GETOPT_OPTION_END
48 };
49 struct GNUNET_OS_Process *proc;
50 char *path = GNUNET_OS_get_libexec_binary_path ( "gnunet-service-conversation");
51 118
52 if (NULL == path) 119 fprintf (stderr, "Mic %s destroyed\n", origin);
120}
121
122
123static struct GNUNET_MICROPHONE_Handle caller_mic = {
124 &enable_mic,
125 &disable_mic,
126 &destroy_mic,
127 "caller"
128};
129
130/**
131 * Signature of the main function of a task.
132 *
133 * @param cls closure
134 * @param tc context information (why was this task triggered now)
135 */
136static void
137end_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
138{
139 GNUNET_SCHEDULER_shutdown ();
140 if (NULL != op)
53 { 141 {
54 fprintf (stderr, "Service executable not found `%s'\n", "gnunet-service-conversation"); 142 GNUNET_IDENTITY_cancel (op);
55 return 0; 143 op = NULL;
144 }
145 if (NULL != call)
146 {
147 GNUNET_CONVERSATION_call_stop (call);
148 call = NULL;
149 }
150 if (NULL != phone)
151 {
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from PHONE service.\n");
153 GNUNET_CONVERSATION_phone_destroy (phone);
154 phone = NULL;
155 }
156 if (NULL != id)
157 {
158 GNUNET_IDENTITY_disconnect (id);
159 id = NULL;
160 }
161 if (NULL != qe)
162 {
163 GNUNET_NAMESTORE_cancel (qe);
164 qe = NULL;
165 }
166 if (NULL != ns)
167 {
168 GNUNET_NAMESTORE_disconnect (ns);
169 ns = NULL;
170 }
171}
172
173
174static void
175phone_event_handler (void *cls,
176 enum GNUNET_CONVERSATION_PhoneEventCode code,
177 struct GNUNET_CONVERSATION_Caller *caller,
178 const char *caller_id)
179{
180 fprintf (stderr, "Phone code: %d - %s\n", code, caller_id);
181 ok = 0;
182 GNUNET_SCHEDULER_shutdown ();
183}
184
185
186static void
187caller_event_handler (void *cls,
188 enum GNUNET_CONVERSATION_CallEventCode code)
189{
190 fprintf (stderr, "Caller code: %d\n", code);
191}
192
193
194static void
195caller_ego_create_cont (void *cls,
196 const char *emsg)
197{
198 op = NULL;
199 GNUNET_assert (NULL == emsg);
200}
201
202
203static void
204namestore_put_cont (void *cls,
205 int32_t success,
206 const char *emsg)
207{
208 qe = NULL;
209 GNUNET_assert (GNUNET_YES == success);
210 GNUNET_assert (NULL == emsg);
211 GNUNET_assert (NULL == op);
212 op = GNUNET_IDENTITY_create (id, "caller-ego", &caller_ego_create_cont, NULL);
213}
214
215
216static void
217identity_cb (void *cls,
218 struct GNUNET_IDENTITY_Ego *ego,
219 void **ctx,
220 const char *name)
221{
222 struct GNUNET_GNSRECORD_Data rd;
223 struct GNUNET_CRYPTO_EcdsaPublicKey pub;
224
225 if (NULL == name)
226 return;
227 if (NULL == ego)
228 return;
229 if (0 == strcmp (name, "phone-ego"))
230 {
231 GNUNET_IDENTITY_ego_get_public_key (ego, &pub);
232 GNUNET_asprintf (&gns_name,
233 "phone.%s",
234 GNUNET_GNSRECORD_pkey_to_zkey (&pub));
235 phone = GNUNET_CONVERSATION_phone_create (cfg,
236 ego,
237 &phone_event_handler,
238 NULL);
239 GNUNET_assert (NULL != phone);
240 memset (&rd, 0, sizeof (rd));
241 GNUNET_CONVERSATION_phone_get_record (phone,
242 &rd);
243 GNUNET_assert (rd.record_type == GNUNET_GNSRECORD_TYPE_PHONE);
244 rd.expiration_time = UINT64_MAX;
245 qe = GNUNET_NAMESTORE_records_store (ns,
246 GNUNET_IDENTITY_ego_get_private_key (ego),
247 "phone" /* GNS label */,
248 1,
249 &rd,
250 &namestore_put_cont,
251 NULL);
252 return;
253 }
254 if (0 == strcmp (name, "caller-ego"))
255 {
256 call = GNUNET_CONVERSATION_call_start (cfg,
257 ego,
258 gns_name,
259 &caller_speaker,
260 &caller_mic,
261 &caller_event_handler,
262 NULL);
263 return;
56 } 264 }
57 proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, NULL, 265}
58 path, 266
59 "gnunet-service-conversation", 267
60 NULL); 268static void
61 269phone_ego_create_cont (void *cls,
62 GNUNET_free (path); 270 const char *emsg)
63 GNUNET_assert (NULL != proc); 271{
64 GNUNET_PROGRAM_run (1, argv, "test-ext-conversation", "nohelp", 272 op = NULL;
65 options, &run, &ok); 273 GNUNET_assert (NULL == emsg);
66 if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) 274}
67 { 275
68 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 276
69 ok = 1; 277static void
70 } 278run (void *cls,
71 GNUNET_OS_process_wait (proc); 279 const struct GNUNET_CONFIGURATION_Handle *c,
72 GNUNET_OS_process_destroy (proc); 280 struct GNUNET_TESTING_Peer *peer)
73 return ok; 281{
282 cfg = c;
283 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
284 (GNUNET_TIME_UNIT_MINUTES, 1), &end_test,
285 NULL);
286 id = GNUNET_IDENTITY_connect (cfg,
287 &identity_cb,
288 NULL);
289 op = GNUNET_IDENTITY_create (id, "phone-ego", &phone_ego_create_cont, NULL);
290 ns = GNUNET_NAMESTORE_connect (cfg);
74} 291}
75 292
76 293
77int 294int
78main (int argc, char *argv[]) 295main (int argc, char *argv[])
79{ 296{
80 GNUNET_log_setup ("test_conversation_api", 297 if (0 != GNUNET_TESTING_peer_run ("test_conversation_api",
81 "WARNING", 298 "test_conversation.conf",
82 NULL); 299 &run, NULL))
83 return check (); 300 return 1;
301 return ok;
84} 302}
85 303
86/* end of test_conversation_api.c */ 304/* end of test_conversation_api.c */