summaryrefslogtreecommitdiff
path: root/src/tests/ecore_con
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2015-04-06 15:59:10 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-06 16:37:53 +0200
commit4b0e8795919d146b66f14b64d70dbb5a2796b8b9 (patch)
tree480abf25d22b0c2ddba73b2497e0487c2a6d3611 /src/tests/ecore_con
parent39432aa0f2ff65510c423c264818999f2d12ea84 (diff)
ecore_con: Split ecore_con test suite from ecore.
Summary: Have created ecore_con test suite. Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric, Sergeant_Whitespace, stefan_schmidt Subscribers: stefan_schmidt, Sergeant_Whitespace, cedric Maniphest Tasks: T2235 Differential Revision: https://phab.enlightenment.org/D2269
Diffstat (limited to 'src/tests/ecore_con')
-rw-r--r--src/tests/ecore_con/ecore_con_suite.c106
-rw-r--r--src/tests/ecore_con/ecore_con_suite.h9
-rw-r--r--src/tests/ecore_con/ecore_con_test_ecore_con.c564
-rw-r--r--src/tests/ecore_con/ecore_con_test_ecore_con_url.c332
-rw-r--r--src/tests/ecore_con/server.key15
-rw-r--r--src/tests/ecore_con/server.pem14
6 files changed, 1040 insertions, 0 deletions
diff --git a/src/tests/ecore_con/ecore_con_suite.c b/src/tests/ecore_con/ecore_con_suite.c
new file mode 100644
index 0000000..b695873
--- /dev/null
+++ b/src/tests/ecore_con/ecore_con_suite.c
@@ -0,0 +1,106 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7
8#include "Ecore.h"
9
10#include "ecore_con_suite.h"
11
12typedef struct _Ecore_Con_Test_Case Ecore_Con_Test_Case;
13
14struct _Ecore_Con_Test_Case
15{
16 const char *test_case;
17 void (*build)(TCase *tc);
18};
19
20static const Ecore_Con_Test_Case etc[] = {
21 { "Ecore_Con", ecore_con_test_ecore_con },
22 { "Ecore_Con_Url", ecore_con_test_ecore_con_url },
23 { NULL, NULL }
24};
25
26static void
27_list_tests(void)
28{
29 const Ecore_Con_Test_Case *itr;
30
31 itr = etc;
32 fputs("Available Test Cases:\n", stderr);
33 for (; itr->test_case; itr++)
34 fprintf(stderr, "\t%s\n", itr->test_case);
35}
36static Eina_Bool
37_use_test(int argc, const char **argv, const char *test_case)
38{
39 if (argc < 1)
40 return 1;
41
42 for (; argc > 0; argc--, argv++)
43 if (strcmp(test_case, *argv) == 0)
44 return 1;
45 return 0;
46}
47
48static Suite *
49ecore_con_suite_build(int argc, const char **argv)
50{
51 TCase *tc;
52 Suite *s;
53 int i;
54
55 s = suite_create("Ecore_Con");
56
57 for (i = 0; etc[i].test_case; ++i)
58 {
59 if (!_use_test(argc, argv, etc[i].test_case)) continue;
60 tc = tcase_create(etc[i].test_case);
61
62 etc[i].build(tc);
63
64 suite_add_tcase(s, tc);
65 tcase_set_timeout(tc, 0);
66 }
67
68 return s;
69}
70
71int
72main(int argc, char **argv)
73{
74 Suite *s;
75 SRunner *sr;
76 int i, failed_count;
77
78 for (i = 1; i < argc; i++)
79 if ((strcmp(argv[i], "-h") == 0) ||
80 (strcmp(argv[i], "--help") == 0))
81 {
82 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
83 argv[0]);
84 _list_tests();
85 return 0;
86 }
87 else if ((strcmp(argv[i], "-l") == 0) ||
88 (strcmp(argv[i], "--list") == 0))
89 {
90 _list_tests();
91 return 0;
92 }
93
94 putenv("EFL_RUN_IN_TREE=1");
95
96 s = ecore_con_suite_build(argc - 1, (const char **)argv + 1);
97 sr = srunner_create(s);
98
99 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
100
101 srunner_run_all(sr, CK_ENV);
102 failed_count = srunner_ntests_failed(sr);
103 srunner_free(sr);
104
105 return (failed_count == 0) ? 0 : 255;
106}
diff --git a/src/tests/ecore_con/ecore_con_suite.h b/src/tests/ecore_con/ecore_con_suite.h
new file mode 100644
index 0000000..9232189
--- /dev/null
+++ b/src/tests/ecore_con/ecore_con_suite.h
@@ -0,0 +1,9 @@
1#ifndef _ECORE_CON_SUITE_H
2#define _ECORE_CON_SUITE_H
3
4#include <check.h>
5
6void ecore_con_test_ecore_con(TCase *tc);
7void ecore_con_test_ecore_con_url(TCase *tc);
8
9#endif /* _ECORE_CON_SUITE_H */
diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con.c b/src/tests/ecore_con/ecore_con_test_ecore_con.c
new file mode 100644
index 0000000..1d8379e
--- /dev/null
+++ b/src/tests/ecore_con/ecore_con_test_ecore_con.c
@@ -0,0 +1,564 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ecore_con_suite.h"
6
7#include <stdio.h>
8#include <Ecore.h>
9#include <Ecore_Con.h>
10
11char sdata[] = "Server_info";
12char cdata[] = "Client_info";
13
14Eina_Bool
15_add(void *data, int type EINA_UNUSED, void *ev)
16{
17 fail_if (type != ECORE_CON_EVENT_CLIENT_ADD &&
18 type != ECORE_CON_EVENT_SERVER_ADD);
19
20 /* Server */
21 if (type == ECORE_CON_EVENT_CLIENT_ADD)
22 {
23 Ecore_Con_Event_Client_Add *event = ev;
24 double timeout_val = 10, ret;
25 void *del_data;
26
27 fail_if (data != (void *) 1);
28 fail_if (!event->client);
29
30 printf("Client with ip %s, port %d, connected = %d!\n",
31 ecore_con_client_ip_get(event->client),
32 ecore_con_client_port_get(event->client),
33 ecore_con_client_connected_get(event->client));
34
35 ecore_con_client_timeout_set(event->client, timeout_val);
36 ret = ecore_con_client_timeout_get(event->client);
37 fail_if (ret != timeout_val);
38
39 ecore_con_client_data_set(event->client, cdata);
40 del_data = ecore_con_client_data_get(event->client);
41 fail_if (strcmp((char *)del_data, cdata));
42 }
43 else if (type == ECORE_CON_EVENT_SERVER_ADD)
44 {
45 Ecore_Con_Event_Server_Add *event = ev;
46 const char ping[] = "PING";
47 int ret;
48
49 fail_if (data != (void *) 2);
50 fail_if (!event->server);
51 printf("Server with ip %s, name %s, port %d, connected = %d!\n",
52 ecore_con_server_ip_get(event->server),
53 ecore_con_server_name_get(event->server),
54 ecore_con_server_port_get(event->server),
55 ecore_con_server_connected_get(event->server));
56 ret = ecore_con_server_send(event->server, ping, sizeof(ping));
57 fail_if (ret != sizeof(ping));
58 ecore_con_server_flush(event->server);
59 }
60
61 return ECORE_CALLBACK_RENEW;
62}
63
64Eina_Bool
65_del(void *data , int type EINA_UNUSED, void *ev)
66{
67 void *del_data;
68
69 fail_if (type != ECORE_CON_EVENT_CLIENT_DEL &&
70 type != ECORE_CON_EVENT_SERVER_DEL);
71
72 /* Server */
73 if (type == ECORE_CON_EVENT_CLIENT_DEL)
74 {
75 Ecore_Con_Event_Client_Del *event = ev;
76
77 fail_if (data != (void *) 1);
78 fail_if (!event->client);
79
80 printf("Lost client with ip %s!\n",
81 ecore_con_client_ip_get(event->client));
82 printf("Client was connected for %0.3f seconds.\n",
83 ecore_con_client_uptime_get(event->client));
84
85 del_data = ecore_con_client_del(event->client);
86 fail_if (strcmp((char *)del_data, cdata));
87 }
88 else if (type == ECORE_CON_EVENT_SERVER_DEL)
89 {
90 Ecore_Con_Event_Server_Del *event = ev;
91
92 fail_if (!event->server);
93
94 fail_if (data != (void *) 2);
95
96 printf("Lost server with ip %s!\n", ecore_con_server_ip_get(event->server));
97
98 ecore_con_server_del(event->server);
99 }
100 fail ();
101
102 return ECORE_CALLBACK_RENEW;
103}
104
105Eina_Bool
106_data(void *data, int type EINA_UNUSED, void *ev)
107{
108
109 fail_if (type != ECORE_CON_EVENT_CLIENT_DATA &&
110 type != ECORE_CON_EVENT_SERVER_DATA);
111
112 /* Server */
113 if (type == ECORE_CON_EVENT_CLIENT_DATA)
114 {
115 Ecore_Con_Event_Client_Data *event = ev;
116 const char pong[] = "PONG";
117 int ret;
118
119 char fmt[128];
120 fail_if (data != (void *) 1);
121
122 snprintf(fmt, sizeof(fmt),
123 "Received %i bytes from client %s port %d:\n"
124 ">>>>>\n"
125 "%%.%is\n"
126 ">>>>>\n",
127 event->size, ecore_con_client_ip_get(event->client),
128 ecore_con_client_port_get(event->client), event->size);
129
130 printf(fmt, event->data);
131 fail_if (event->size != sizeof("PING"));
132 fail_if (memcmp (event->data, "PING", sizeof("PING")) != 0);
133
134 ret = ecore_con_client_send(event->client, pong, sizeof(pong));
135 fail_if (ret != sizeof(pong));
136 ecore_con_client_flush(event->client);
137 }
138 else if (type == ECORE_CON_EVENT_SERVER_DATA)
139 {
140 Ecore_Con_Event_Server_Data *event = ev;
141 char fmt[128];
142
143 fail_if (data != (void *) 2);
144
145 snprintf(fmt, sizeof(fmt),
146 "Received %i bytes from server:\n"
147 ">>>>>\n"
148 "%%.%is\n"
149 ">>>>>\n",
150 event->size, event->size);
151
152 printf(fmt, event->data);
153 fail_if (event->size != sizeof("PONG"));
154 fail_if (memcmp (event->data, "PONG", sizeof("PONG")) != 0);
155 ecore_main_loop_quit();
156 }
157
158 return ECORE_CALLBACK_RENEW;
159}
160
161Eina_Bool
162_dns_add_del(void *data, int type EINA_UNUSED, void *ev EINA_UNUSED)
163{
164 Eina_Bool *err_check = data;
165 *err_check = EINA_FALSE;
166 ecore_main_loop_quit();
167 return ECORE_CALLBACK_RENEW;
168}
169
170Eina_Bool
171_dns_err(void *data, int type EINA_UNUSED, void *ev EINA_UNUSED)
172{
173 Eina_Bool *err_check = data;
174 *err_check = EINA_TRUE;
175 ecore_main_loop_quit();
176 return ECORE_CALLBACK_RENEW;
177}
178
179void _ecore_con_server_client_tests(Ecore_Con_Type compl_type, const char *name, Eina_Bool is_ssl, int server_port)
180{
181 Ecore_Con_Server *server = NULL;
182 Ecore_Con_Server *client;
183 Ecore_Con_Client *cl;
184 const Eina_List *clients, *l;
185 Ecore_Event_Handler *handlers[6];
186 void *server_data = malloc (1);
187 void *client_data = malloc (1);
188 double timeout_val = 10, timeout_ret;
189 int ret;
190 void *del_ret;
191 const char *server_name;
192
193 ret = eina_init();
194 fail_if(ret != 1);
195 ret = ecore_con_init();
196 fail_if(ret != 1);
197
198 handlers[0] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD,
199 _add, (void *) 1);
200 fail_if(handlers[0] == NULL);
201 handlers[1] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL,
202 _del, (void *) 1);
203 fail_if(handlers[1] == NULL);
204 handlers[2] = ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA,
205 _data, (void *) 1);
206 fail_if(handlers[2] == NULL);
207
208 handlers[3] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD,
209 _add, (void *) 2);
210 fail_if(handlers[3] == NULL);
211 handlers[4] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL,
212 _del, (void *) 2);
213 fail_if(handlers[4] == NULL);
214 handlers[5] = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
215 _data, (void *) 2);
216 fail_if(handlers[5] == NULL);
217
218 fail_if (ecore_con_server_connected_get(server));
219
220 server = ecore_con_server_add(compl_type, name, server_port,
221 server_data);
222 fail_if (server == NULL);
223
224 if (is_ssl)
225 {
226 fail_unless(ecore_con_ssl_server_cert_add(server, TESTS_SRC_DIR"/server.pem"));
227 fail_unless(ecore_con_ssl_server_privkey_add(server, TESTS_SRC_DIR"/server.key"));
228 }
229
230 del_ret = ecore_con_server_data_get(server);
231 fail_if (del_ret != server_data);
232
233 del_ret = ecore_con_server_data_set(server, sdata);
234 fail_if (del_ret != server_data);
235
236 fail_if (!ecore_con_server_connected_get(server));
237
238 ecore_con_server_timeout_set(server, timeout_val);
239 timeout_ret = ecore_con_server_timeout_get(server);
240 fail_if (timeout_ret != timeout_val);
241
242 ret = ecore_con_server_port_get(server);
243 fail_if (ret != server_port);
244
245 ecore_con_server_client_limit_set(server, 1, 0);
246
247 client = ecore_con_server_connect(compl_type, name, server_port,
248 client_data);
249 fail_if (client == NULL);
250
251 if (is_ssl)
252 {
253 fail_unless(ecore_con_ssl_server_cafile_add(server, TESTS_SRC_DIR"/server.pem"));
254 server_name = ecore_con_ssl_server_verify_name_get(server);
255 ecore_con_ssl_server_verify_name_set(server,server_name);
256 ecore_con_ssl_server_verify_basic(server);
257 ecore_con_ssl_server_verify(server);
258 }
259
260 ecore_main_loop_begin();
261
262 clients = ecore_con_server_clients_get(server);
263 printf("Clients connected to this server when exiting: %d\n",
264 eina_list_count(clients));
265 EINA_LIST_FOREACH(clients, l, cl)
266 {
267 printf("%s\n", ecore_con_client_ip_get(cl));
268 }
269
270 printf("Server was up for %0.3f seconds\n",
271 ecore_con_server_uptime_get(server));
272
273 del_ret = ecore_con_server_del(server);
274 fail_if (strcmp((char *)del_ret, sdata));
275 free (server_data);
276 server_data = NULL;
277
278 del_ret = ecore_con_server_del(client);
279 fail_if (del_ret != client_data);
280 free (client_data);
281 client_data = NULL;
282
283 del_ret = ecore_event_handler_del (handlers[0]);
284 fail_if (del_ret != (void *) 1);
285 del_ret = ecore_event_handler_del (handlers[1]);
286 fail_if (del_ret != (void *) 1);
287 del_ret = ecore_event_handler_del (handlers[2]);
288 fail_if (del_ret != (void *) 1);
289
290 del_ret = ecore_event_handler_del (handlers[3]);
291 fail_if (del_ret != (void *) 2);
292 del_ret = ecore_event_handler_del (handlers[4]);
293 fail_if (del_ret != (void *) 2);
294 del_ret = ecore_event_handler_del (handlers[5]);
295 fail_if (del_ret != (void *) 2);
296
297 ret = ecore_con_shutdown();
298 fail_if(ret != 0);
299 ret = eina_shutdown();
300}
301
302START_TEST(ecore_test_ecore_con_local_user)
303{
304 _ecore_con_server_client_tests(ECORE_CON_LOCAL_USER, "test_sock", EINA_FALSE, 12345);
305}
306END_TEST
307
308START_TEST(ecore_test_ecore_con_local_user_home)
309{
310 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
311
312 unsetenv("XDG_RUNTIME_DIR");
313 _ecore_con_server_client_tests(ECORE_CON_LOCAL_USER, "test_soc", EINA_FALSE, 12345);
314 setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
315}
316END_TEST
317
318START_TEST(ecore_test_ecore_con_local_user_tmp)
319{
320 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
321 const char *homedir = getenv("HOME");
322
323 unsetenv("XDG_RUNTIME_DIR");
324 unsetenv("HOME");
325 _ecore_con_server_client_tests(ECORE_CON_LOCAL_USER, "test_sock", EINA_FALSE, 12345);
326 setenv("HOME", homedir, 1);
327 setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
328}
329END_TEST
330
331START_TEST(ecore_test_ecore_con_local_user_none)
332{
333 const char *xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
334 const char *homedir = getenv("HOME");
335 const char *tmp = getenv("TMPDIR");
336
337 unsetenv("XDG_RUNTIME_DIR");
338 unsetenv("HOME");
339 unsetenv("TMPDIR");
340 _ecore_con_server_client_tests(ECORE_CON_LOCAL_USER, "test_sock", EINA_FALSE, 12345);
341 setenv("TMPDIR", tmp, 1);
342 setenv("HOME", homedir, 1);
343 setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
344}
345END_TEST
346
347START_TEST(ecore_test_ecore_con_local_system)
348{
349 _ecore_con_server_client_tests(ECORE_CON_LOCAL_SYSTEM, "test_sock", EINA_FALSE, 12345);
350}
351END_TEST
352
353START_TEST(ecore_test_ecore_con_local_system_fullpath)
354{
355 _ecore_con_server_client_tests(ECORE_CON_LOCAL_SYSTEM, "/tmp/test_sock", EINA_FALSE, 12345);
356}
357END_TEST
358
359START_TEST(ecore_test_ecore_con_local_system_negport)
360{
361 _ecore_con_server_client_tests(ECORE_CON_LOCAL_SYSTEM, "test_sock", EINA_FALSE, -6);
362}
363END_TEST
364
365START_TEST(ecore_test_ecore_con_local_system_negport_fullpath)
366{
367 _ecore_con_server_client_tests(ECORE_CON_LOCAL_SYSTEM, "/tmp/test_sock", EINA_FALSE, -6);
368}
369END_TEST
370
371START_TEST(ecore_test_ecore_con_local_abstract)
372{
373 _ecore_con_server_client_tests(ECORE_CON_LOCAL_ABSTRACT, "test_sock", EINA_FALSE, 12345);
374}
375END_TEST
376
377START_TEST(ecore_test_ecore_con_remote_tcp)
378{
379 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP, "127.0.0.1", EINA_FALSE, 12345);
380}
381END_TEST
382
383START_TEST(ecore_test_ecore_con_remote_nodelay)
384{
385 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", EINA_FALSE, 12345);
386}
387END_TEST
388
389START_TEST(ecore_test_ecore_con_remote_tcp_ssl3)
390{
391 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_SSL3, "127.0.0.1", EINA_TRUE, 12345);
392}
393END_TEST
394
395START_TEST(ecore_test_ecore_con_remote_tcp_ssl3_load_cert)
396{
397 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT, "127.0.0.1", EINA_TRUE, 12345);
398}
399END_TEST
400
401START_TEST(ecore_test_ecore_con_remote_tcp_tls)
402{
403 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS, "127.0.0.1", EINA_TRUE, 12345);
404}
405END_TEST
406
407START_TEST(ecore_test_ecore_con_remote_tcp_tls_load_cert)
408{
409 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT, "127.0.0.1", EINA_TRUE, 12345);
410}
411END_TEST
412
413START_TEST(ecore_test_ecore_con_remote_tcp_mixed)
414{
415 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_MIXED, "127.0.0.1", EINA_TRUE, 12345);
416}
417END_TEST
418
419START_TEST(ecore_test_ecore_con_remote_tcp_mixed_load_cert)
420{
421 _ecore_con_server_client_tests(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT, "127.0.0.1", EINA_TRUE, 12345);
422}
423END_TEST
424
425START_TEST(ecore_test_ecore_con_remote_nodelay_ssl3)
426{
427 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_SSL3, "127.0.0.1", EINA_TRUE, 12345);
428}
429END_TEST
430
431START_TEST(ecore_test_ecore_con_remote_nodelay_ssl3_load_cert)
432{
433 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT, "127.0.0.1", EINA_TRUE, 12345);
434}
435END_TEST
436
437START_TEST(ecore_test_ecore_con_remote_nodelay_tls)
438{
439 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_TLS, "127.0.0.1", EINA_TRUE, 12345);
440}
441END_TEST
442
443START_TEST(ecore_test_ecore_con_remote_nodelay_tls_load_cert)
444{
445 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_TLS | ECORE_CON_LOAD_CERT, "127.0.0.1", EINA_TRUE, 12345);
446}
447END_TEST
448
449START_TEST(ecore_test_ecore_con_remote_nodelay_mixed)
450{
451 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_MIXED, "127.0.0.1", EINA_TRUE, 12345);
452}
453END_TEST
454
455START_TEST(ecore_test_ecore_con_remote_nodelay_mixed_load_cert)
456{
457 _ecore_con_server_client_tests(ECORE_CON_REMOTE_NODELAY | ECORE_CON_USE_MIXED | ECORE_CON_LOAD_CERT, "127.0.0.1", EINA_TRUE, 12345);
458}
459END_TEST
460
461START_TEST(ecore_test_ecore_con_ssl_available)
462{
463 int ret = ecore_con_ssl_available_get();
464#ifdef HAVE_GNUTLS
465 fail_if(ret != 1);
466#elif HAVE_OPENSSL
467 fail_if(ret != 2);
468#else
469 fail_if(!ret);
470#endif
471}
472END_TEST
473
474START_TEST(ecore_test_ecore_con_init)
475{
476 int ret;
477
478 ret = ecore_con_init();
479 fail_if(ret != 1);
480
481 ret = ecore_con_shutdown();
482 fail_if(ret != 0);
483}
484END_TEST
485
486START_TEST(ecore_test_ecore_con_dns)
487{
488 Ecore_Con_Server *client;
489 Ecore_Event_Handler *e_err;
490 Ecore_Event_Handler *e_add;
491 Eina_Bool err_check = EINA_FALSE;
492 int ret;
493
494 ret = eina_init();
495 fail_if(ret != 1);
496 ret = ecore_con_init();
497 fail_if(ret != 1);
498
499 e_add = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, _dns_add_del, (void *) &err_check);
500 e_err = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ERROR, _dns_err, (void *) &err_check);
501 /* For timeout */
502 e_err = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, _dns_add_del, (void *) &err_check);
503
504 client = ecore_con_server_connect(ECORE_CON_REMOTE_TCP,
505 "wongsub.wrongdns.lan", 1234, NULL);
506 fail_if (client == NULL);
507 ecore_con_server_timeout_set(client, 5.0);
508
509 ecore_main_loop_begin();
510 fail_if (err_check == EINA_FALSE);
511 fail_if (ecore_event_handler_del(e_err) != (void *) &err_check);
512 fail_if (ecore_event_handler_del(e_add) != (void *) &err_check);
513
514 ret = ecore_con_shutdown();
515 fail_if(ret != 0);
516 ret = eina_shutdown();
517}
518END_TEST
519
520START_TEST(ecore_test_ecore_con_shutdown_bef_init)
521{
522 int ret;
523
524 ret = ecore_con_shutdown();
525 fail_if(ret != 0);
526
527 ret = ecore_con_init();
528 fail_if(ret != 1);
529
530 ret = ecore_con_shutdown();
531 fail_if(ret != 0);
532}
533END_TEST
534
535void ecore_con_test_ecore_con(TCase *tc)
536{
537 tcase_add_test(tc, ecore_test_ecore_con_init);
538 tcase_add_test(tc, ecore_test_ecore_con_local_user);
539 tcase_add_test(tc, ecore_test_ecore_con_local_user_home);
540 tcase_add_test(tc, ecore_test_ecore_con_local_user_tmp);
541 tcase_add_test(tc, ecore_test_ecore_con_local_user_none);
542 tcase_add_test(tc, ecore_test_ecore_con_local_system);
543 tcase_add_test(tc, ecore_test_ecore_con_local_system_fullpath);
544 tcase_add_test(tc, ecore_test_ecore_con_local_system_negport);
545 tcase_add_test(tc, ecore_test_ecore_con_local_system_negport_fullpath);
546 tcase_add_test(tc, ecore_test_ecore_con_local_abstract);
547 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp);
548 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp_ssl3);
549 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp_ssl3_load_cert);
550 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp_tls);
551 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp_tls_load_cert);
552 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp_mixed);
553 tcase_add_test(tc, ecore_test_ecore_con_remote_tcp_mixed_load_cert);
554 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay);
555 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay_ssl3);
556 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay_ssl3_load_cert);
557 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay_tls);
558 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay_tls_load_cert);
559 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay_mixed);
560 tcase_add_test(tc, ecore_test_ecore_con_remote_nodelay_mixed_load_cert);
561 tcase_add_test(tc, ecore_test_ecore_con_ssl_available);
562 tcase_add_test(tc, ecore_test_ecore_con_dns);
563 tcase_add_test(tc, ecore_test_ecore_con_shutdown_bef_init);
564}
diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con_url.c b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
new file mode 100644
index 0000000..0ddcfe5
--- /dev/null
+++ b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
@@ -0,0 +1,332 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ecore_con_suite.h"
6
7#include <stdio.h>
8#include <Ecore.h>
9#include <Ecore_Con.h>
10#include <Eina.h>
11#include <unistd.h>
12
13typedef struct _url_test
14{
15 const char *_test_file;
16 int _tmpfd;
17} url_test;
18
19static void
20_free_url_test(url_test *info)
21{
22 unlink(info->_test_file);
23 eina_tmpstr_del(info->_test_file);
24 close(info->_tmpfd);
25 free(info);
26}
27
28static Eina_Bool
29_url_compl_cb(void *data, int type EINA_UNUSED, void *event_info)
30{
31 url_test *info = data;
32 Ecore_Con_Event_Url_Complete *ev = event_info;
33
34 printf("Total downloaded bytes = %d\n",
35 ecore_con_url_received_bytes_get(ev->url_con));
36
37 if (info->_tmpfd)
38 {
39 _free_url_test(info);
40 ecore_con_url_free(ev->url_con);
41 }
42 else
43 {
44 fail_unless(ecore_con_url_url_set(ev->url_con,
45 "ftp://ftp.kernel.org/pub/linux/kernel/README"));
46
47 ecore_con_url_verbose_set (ev->url_con, EINA_FALSE);
48
49 info->_tmpfd = eina_file_mkstemp("ecore_con_test_XXXXXX.html",
50 &(info->_test_file));
51 if (info->_tmpfd < 0)
52 {
53 free(info);
54 ecore_con_url_free(ev->url_con);
55 fail();
56 }
57
58 ecore_con_url_fd_set(ev->url_con, info->_tmpfd);
59 if (!ecore_con_url_get(ev->url_con))
60 {
61 _free_url_test(info);
62 ecore_con_url_free(ev->url_con);
63 fail();
64 }
65 }
66
67 return EINA_FALSE;
68}
69
70static Eina_Bool
71_parse_url(char *link, char *url, char **user, char **passwd, char **file, char **dir)
72{
73 int is_http;
74 char *temp, *temp1, *link_cpy;
75
76 if (!strncmp(link, "http://", 7))
77 is_http = EINA_TRUE;
78#ifdef ECORE_CON_FTP_TEST_URL
79 else if (!strncmp(link, "ftp://", 6))
80 is_http = EINA_FALSE;
81#endif
82 else
83 return EINA_FALSE;
84
85 link_cpy = strdup(link);
86 temp = link + 6;
87 if (is_http)
88 temp ++;
89
90 temp1 = strtok(temp, ":");
91 if (temp1)
92 *user = strdup(temp1);
93 else
94 goto error_user;
95
96 temp1 = strtok(NULL, "@");
97 if (temp1)
98 *passwd = strdup(temp1);
99 else
100 goto error_passwd;
101
102 if (is_http)
103 {
104 strcpy(url, "http://");
105 temp1 = strrchr(link_cpy, '@') + 1;
106 strcat(url, temp1);
107
108 free(link_cpy);
109 return EINA_TRUE;
110 }
111
112 strcpy(url, "ftp://");
113 temp1 = strtok(NULL, "?");
114 if (temp1)
115 strcat(url, temp1);
116 else
117 goto error_passwd;
118
119 if (strchr (link_cpy, '&'))
120 {
121 temp1 = strtok(NULL, "=");
122 if (temp1)
123 *file = strdup(strtok(NULL, "&"));
124 else
125 goto error_passwd;
126
127 temp1 = strrchr(link_cpy, '=') + 1;
128 if (temp1)
129 *dir = strdup(temp1);
130 else
131 goto error_file;
132 }
133 else
134 {
135 temp1 = strrchr(link_cpy,'=') + 1;
136 if (temp1)
137 *file = strdup(temp1);
138 else
139 goto error_passwd;
140 }
141
142 free(link_cpy);
143 return EINA_TRUE;
144
145error_file:
146 free(*file);
147
148error_passwd:
149 free(*user);
150
151error_user:
152 free(link_cpy);
153 fprintf(stderr, "Wrong URL format\n");
154 return EINA_FALSE;
155}
156
157#ifdef ECORE_CON_FTP_TEST_URL
158START_TEST(ecore_test_ecore_con_url_ftp_upload)
159{
160 Ecore_Con_Url *ec_url;
161 url_test *info;
162 int ret;
163 char link[] = ECORE_CON_FTP_TEST_URL;
164 char url[4096], *username, *password, *file = NULL, *dir = NULL;
165
166 ret = eina_init();
167 fail_if(ret != 1);
168 ret = ecore_con_url_init();
169 fail_if(ret != 1);
170
171 fail_unless(_parse_url(link, url, &username, &password, &file, &dir));
172
173 fprintf(stderr, "FTP: \n url = %s \n username = %s \n password = %s \n file = %s \n", url, username, password, file);
174 if (dir)
175 fprintf(stderr, "directory = %s\n", dir);
176
177 ec_url = ecore_con_url_new(link);
178 fail_unless (ec_url);
179
180 ecore_con_url_verbose_set(ec_url, EINA_TRUE);
181 ecore_con_url_ftp_use_epsv_set(ec_url, EINA_TRUE);
182
183 fail_unless(ecore_con_url_ftp_upload(ec_url, file, username, password, dir));
184
185 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
186 _url_compl_cb, info);
187
188 ret = ecore_con_url_shutdown();
189 fail_if(ret != 0);
190 ret = eina_shutdown();
191}
192END_TEST
193#endif
194
195#ifdef ECORE_CON_HTTP_TEST_URL
196START_TEST(ecore_test_ecore_con_url_post)
197{
198 Ecore_Con_Url *ec_url;
199 url_test *info;
200 int ret;
201 char link[] = ECORE_CON_HTTP_TEST_URL;
202 char url_data[] = "test";
203 char *username = NULL, *password = NULL;
204 char url[4096];
205
206 ret = eina_init();
207 fail_if(ret != 1);
208 ret = ecore_con_url_init();
209 fail_if(ret != 1);
210
211 fail_unless(_parse_url(link, url, &username, &password, NULL, NULL));
212
213 fprintf (stderr, "HTTP: \n url = %s \n username = %s \n password = %s \n", url, username, password);
214
215 ecore_con_url_pipeline_set(EINA_TRUE);
216 fail_unless (ecore_con_url_pipeline_get());
217
218 ec_url = ecore_con_url_custom_new(url, "POST");
219 fail_unless (ec_url);
220
221 ecore_con_url_additional_header_add(ec_url, "User-Agent", "blablabla");
222 ecore_con_url_verbose_set(ec_url, EINA_TRUE);
223
224 ecore_con_url_httpauth_set(ec_url, username, password, EINA_FALSE);
225 ecore_con_url_time(ec_url, ECORE_CON_URL_TIME_IFMODSINCE, 0);
226
227 fail_unless(ecore_con_url_post(ec_url, url_data, 4, NULL));
228
229 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
230 _url_compl_cb, info);
231
232 ret = ecore_con_url_shutdown();
233 fail_if(ret != 0);
234 ret = eina_shutdown();
235}
236END_TEST
237#endif
238
239START_TEST(ecore_test_ecore_con_url_download)
240{
241 Ecore_Con_Url *url;
242 url_test *info;
243 int ret;
244#ifdef ECORE_CON_HTTP_TEST_URL
245 const char link[] = ECORE_CON_HTTP_TEST_URL;
246#else
247 const char link[] = "www.google.com";
248#endif
249 char url_data[] = "test";
250
251 ret = eina_init();
252 fail_if(ret != 1);
253 ret = ecore_con_url_init();
254 fail_if(ret != 1);
255
256 url = ecore_con_url_new(link);
257 fail_unless (url);
258
259 ecore_con_url_verbose_set(url, EINA_TRUE);
260
261 fail_if (strcmp(ecore_con_url_url_get(url), link));
262
263 ecore_con_url_data_set(url, url_data);
264 fail_if (strcmp(ecore_con_url_data_get(url), url_data));
265
266 info = (url_test *) malloc(sizeof(url_test));
267 info->_tmpfd = 0;
268
269 if (!ecore_con_url_get(url))
270 {
271 close(info->_tmpfd);
272 free(info);
273 ecore_con_url_free(url);
274 fail();
275 }
276 else
277 {
278 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
279 _url_compl_cb, info);
280 }
281
282 ret = ecore_con_url_shutdown();
283 fail_if(ret != 0);
284 ret = eina_shutdown();
285}
286END_TEST
287
288START_TEST(ecore_test_ecore_con_url_create)
289{
290 Ecore_Con_Url *url;
291 int ret;
292
293 ret = eina_init();
294 fail_if(ret != 1);
295 ret = ecore_con_url_init();
296 fail_if(ret != 1);
297
298 url = ecore_con_url_new("http://google.com");
299 fail_if(!url);
300
301 ecore_con_url_free(url);
302
303 ret = ecore_con_url_shutdown();
304 fail_if(ret != 0);
305 ret = eina_shutdown();
306}
307END_TEST
308
309START_TEST(ecore_test_ecore_con_url_init)
310{
311 int ret;
312
313 ret = ecore_con_url_init();
314 fail_if(ret != 1);
315
316 ret = ecore_con_url_shutdown();
317 fail_if(ret != 0);
318}
319END_TEST
320
321void ecore_con_test_ecore_con_url(TCase *tc)
322{
323 tcase_add_test(tc, ecore_test_ecore_con_url_init);
324 tcase_add_test(tc, ecore_test_ecore_con_url_create);
325 tcase_add_test(tc, ecore_test_ecore_con_url_download);
326#ifdef ECORE_CON_HTTP_TEST_URL
327 tcase_add_test(tc, ecore_test_ecore_con_url_post);
328#endif
329#ifdef ECORE_CON_FTP_TEST_URL
330 tcase_add_test(tc, ecore_test_ecore_con_url_ftp_upload);
331#endif
332}
diff --git a/src/tests/ecore_con/server.key b/src/tests/ecore_con/server.key
new file mode 100644
index 0000000..922b0f7
--- /dev/null
+++ b/src/tests/ecore_con/server.key
@@ -0,0 +1,15 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXAIBAAKBgQDPM7htA+kHL37qJQOLK3CYP4x9mqCcYy4m4GvT+yn5b4IRqi1x
3iH0F+/A+hvG4EE/iamNsnM7uJ1bixw/BCya+m9EfE5qzQvZuU+6AN73D+nMXcgBd
44TTjfF8MD340a1Tn3RRVOx1hdSuuN61wpIFT/sn/dfTaVzD/UnMWj+AdBQIDAQAB
5AoGAYc6wSAWIgnPRHQXL3m3rAHM/BitvlWLb7k4RmEb/UVdptpz2Rpl/Ksv6ZAmf
6IJvSmbZOqH58z76SLQp6TU3OQ2IBikHo8+C+RgPWptBDlgYO57zGz4ee28tImqV/
7quxNE+TM9EBJDAhGA0ySaiQcdfOOErzRQvcFSTE2ie9LjAECQQDvUmMzsYhEEb8B
8RS7ASYNUFihBPprZh+/qhJeF37kK7t1g2zk5gwfEo2W9926DiKicpvX1/hxgKOwb
9ZpZuhRAhAkEA3aRNBnrDPo+gaP+wV4Z410+laW/myqbEN9l6tcGQqRZmOXw6jEAm
10Cq5zngIVibaVZ4g052c4PHl51txYoEjAZQJBAM4He2exWsJfFLSfPpRDtU/ak2U3
115E+Je73F0DxsUf1bjjIoCKe+ah2bHafhL78FE0NpaS4RSZRvJnSgaLlUzIECQB5H
12SMJ+2NdeFaLiczuxwiZf2hAKWnQKzjl2+12DIPkId1SZFQJ97PR+morWbAzRJZ3s
13LJYEMtmIGs3wcicLaUUCQFBmyP238jX58ixYd7crJdnxPnTvOtasQqb8cPJ9XSyT
14ara6m96iiQSvqXObtmRl6oGCWGw8q821iJYHKFD0ls4=
15-----END RSA PRIVATE KEY-----
diff --git a/src/tests/ecore_con/server.pem b/src/tests/ecore_con/server.pem
new file mode 100644
index 0000000..84e8de3
--- /dev/null
+++ b/src/tests/ecore_con/server.pem
@@ -0,0 +1,14 @@
1-----BEGIN CERTIFICATE-----
2MIICOTCCAaICCQDQ5umIhrgBUDANBgkqhkiG9w0BAQsFADBhMQswCQYDVQQGEwJJ
3TjEMMAoGA1UECAwDS2FyMRIwEAYDVQQHDAlCZW5nYWx1cnUxDDAKBgNVBAoMA0VG
4TDEOMAwGA1UECwwFRWNvcmUxEjAQBgNVBAMMCTEyNy4wLjAuMTAeFw0xNTAyMTIw
5NDIxMDVaFw0xNjAyMTIwNDIxMDVaMGExCzAJBgNVBAYTAklOMQwwCgYDVQQIDANL
6YXIxEjAQBgNVBAcMCUJlbmdhbHVydTEMMAoGA1UECgwDRUZMMQ4wDAYDVQQLDAVF
7Y29yZTESMBAGA1UEAwwJMTI3LjAuMC4xMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB
8iQKBgQDPM7htA+kHL37qJQOLK3CYP4x9mqCcYy4m4GvT+yn5b4IRqi1xiH0F+/A+
9hvG4EE/iamNsnM7uJ1bixw/BCya+m9EfE5qzQvZuU+6AN73D+nMXcgBd4TTjfF8M
10D340a1Tn3RRVOx1hdSuuN61wpIFT/sn/dfTaVzD/UnMWj+AdBQIDAQABMA0GCSqG
11SIb3DQEBCwUAA4GBALgUu21Ihj6W2/tagmV7Iwt4LJndnIJP1IINUrLptkH1vE4B
124p7uHxtRp7fQpOOl2ns1JhJabgHUjXLCPfjsZ1YS5YgTqs9IaiyqjYZDgCusSvrJ
13eJXeNVLWMb6iHgW0zsEDv9Vl1/XyBk9koyP0/stWw+JFxKqMJGCen5dRPQLZ
14-----END CERTIFICATE-----