summaryrefslogtreecommitdiff
path: root/src/tests/ecore_con
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2015-04-15 14:29:33 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-15 14:29:37 +0200
commit2f4dee02e4bb57cccb35403039e703a18a0dbeb2 (patch)
tree74a041291d309ce0b9da9bf14d6e9307f81e8eb7 /src/tests/ecore_con
parent398378bf9009e1c479407f18e683f888d22227c3 (diff)
ecore_con: add test cases related to cookies.
Summary: Added test cases related to ecore_con_url cookies. Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2298 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/ecore_con')
-rw-r--r--src/tests/ecore_con/ecore_con_test_ecore_con_url.c149
1 files changed, 138 insertions, 11 deletions
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
index 0ddcfe5..177c4c9 100644
--- a/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
+++ b/src/tests/ecore_con/ecore_con_test_ecore_con_url.c
@@ -10,6 +10,9 @@
10#include <Eina.h> 10#include <Eina.h>
11#include <unistd.h> 11#include <unistd.h>
12 12
13#define COOKIEJAR "testcookieXXXXXX.jar"
14#define DEFAULT_LINK "www.google.com"
15
13typedef struct _url_test 16typedef struct _url_test
14{ 17{
15 const char *_test_file; 18 const char *_test_file;
@@ -155,7 +158,7 @@ error_user:
155} 158}
156 159
157#ifdef ECORE_CON_FTP_TEST_URL 160#ifdef ECORE_CON_FTP_TEST_URL
158START_TEST(ecore_test_ecore_con_url_ftp_upload) 161START_TEST(ecore_con_test_ecore_con_url_ftp_upload)
159{ 162{
160 Ecore_Con_Url *ec_url; 163 Ecore_Con_Url *ec_url;
161 url_test *info; 164 url_test *info;
@@ -193,7 +196,7 @@ END_TEST
193#endif 196#endif
194 197
195#ifdef ECORE_CON_HTTP_TEST_URL 198#ifdef ECORE_CON_HTTP_TEST_URL
196START_TEST(ecore_test_ecore_con_url_post) 199START_TEST(ecore_con_test_ecore_con_url_post)
197{ 200{
198 Ecore_Con_Url *ec_url; 201 Ecore_Con_Url *ec_url;
199 url_test *info; 202 url_test *info;
@@ -236,7 +239,7 @@ START_TEST(ecore_test_ecore_con_url_post)
236END_TEST 239END_TEST
237#endif 240#endif
238 241
239START_TEST(ecore_test_ecore_con_url_download) 242START_TEST(ecore_con_test_ecore_con_url_download)
240{ 243{
241 Ecore_Con_Url *url; 244 Ecore_Con_Url *url;
242 url_test *info; 245 url_test *info;
@@ -244,7 +247,7 @@ START_TEST(ecore_test_ecore_con_url_download)
244#ifdef ECORE_CON_HTTP_TEST_URL 247#ifdef ECORE_CON_HTTP_TEST_URL
245 const char link[] = ECORE_CON_HTTP_TEST_URL; 248 const char link[] = ECORE_CON_HTTP_TEST_URL;
246#else 249#else
247 const char link[] = "www.google.com"; 250 const char link[] = DEFAULT_LINK;
248#endif 251#endif
249 char url_data[] = "test"; 252 char url_data[] = "test";
250 253
@@ -285,7 +288,7 @@ START_TEST(ecore_test_ecore_con_url_download)
285} 288}
286END_TEST 289END_TEST
287 290
288START_TEST(ecore_test_ecore_con_url_create) 291START_TEST(ecore_con_test_ecore_con_url_create)
289{ 292{
290 Ecore_Con_Url *url; 293 Ecore_Con_Url *url;
291 int ret; 294 int ret;
@@ -306,7 +309,7 @@ START_TEST(ecore_test_ecore_con_url_create)
306} 309}
307END_TEST 310END_TEST
308 311
309START_TEST(ecore_test_ecore_con_url_init) 312START_TEST(ecore_con_test_ecore_con_url_init)
310{ 313{
311 int ret; 314 int ret;
312 315
@@ -318,15 +321,139 @@ START_TEST(ecore_test_ecore_con_url_init)
318} 321}
319END_TEST 322END_TEST
320 323
324static Eina_Bool
325_url_cookies_compl_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
326{
327 Ecore_Con_Event_Url_Complete *url_complete = event_info;
328 const Eina_List *headers, *l;
329 char *str;
330
331 headers = ecore_con_url_response_headers_get(url_complete->url_con);
332
333 fail_unless(headers);
334
335 printf("response headers:\n");
336 EINA_LIST_FOREACH(headers, l, str)
337 printf("header: %s", str);
338
339 ecore_con_url_cookies_jar_write(url_complete->url_con);
340
341 ecore_main_loop_quit();
342
343 return EINA_TRUE;
344}
345
346static Ecore_Con_Url *
347_ecore_con_url_cookies_test_init()
348{
349 Ecore_Con_Url *ec_url = NULL;
350#ifdef ECORE_CON_HTTP_TEST_URL
351 const char link[] = ECORE_CON_HTTP_TEST_URL;
352#else
353 const char link[] = DEFAULT_LINK;
354#endif
355
356 eina_init();
357 ecore_con_init();
358 ecore_con_url_init();
359
360 ec_url = ecore_con_url_new(link);
361 fail_unless(ec_url);
362
363 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
364 _url_cookies_compl_cb, NULL);
365
366 ecore_con_url_additional_header_add(ec_url, "User-Agent",
367 "Ecore_Con client");
368
369 ecore_con_url_cookies_init(ec_url);
370
371 return ec_url;
372}
373
374static void
375_ecore_con_url_cookies_test_shutdown(Ecore_Con_Url *ec_url, int tmpfd, Eina_Tmpstr **path)
376{
377 close(tmpfd);
378 unlink(*path);
379 eina_tmpstr_del(*path);
380 ecore_con_url_free(ec_url);
381 ecore_con_url_shutdown();
382 ecore_con_shutdown();
383 eina_shutdown();
384}
385
386START_TEST(ecore_con_test_ecore_con_url_cookies_clear)
387{
388 Ecore_Con_Url *ec_url = _ecore_con_url_cookies_test_init();
389 Eina_Tmpstr *path;
390 int tmpfd;
391
392 tmpfd = eina_file_mkstemp(COOKIEJAR, &path);
393
394 ecore_con_url_cookies_file_add(ec_url, path);
395 fail_unless(ecore_con_url_cookies_jar_file_set(ec_url, path));
396 ecore_con_url_cookies_clear(ec_url);
397
398 fail_unless(ecore_con_url_get(ec_url));
399
400 ecore_main_loop_begin();
401
402 _ecore_con_url_cookies_test_shutdown(ec_url, tmpfd, &path);
403}
404END_TEST
405
406START_TEST(ecore_con_test_ecore_con_url_cookies_clear_session)
407{
408 Ecore_Con_Url *ec_url = _ecore_con_url_cookies_test_init();
409 Eina_Tmpstr *path;
410 int tmpfd;
411
412 tmpfd = eina_file_mkstemp(COOKIEJAR, &path);
413
414 ecore_con_url_cookies_file_add(ec_url, path);
415 fail_unless(ecore_con_url_cookies_jar_file_set(ec_url, path));
416 ecore_con_url_cookies_session_clear(ec_url);
417
418 fail_unless(ecore_con_url_get(ec_url));
419
420 ecore_main_loop_begin();
421
422 _ecore_con_url_cookies_test_shutdown(ec_url, tmpfd, &path);
423}
424END_TEST
425
426START_TEST(ecore_con_test_ecore_con_url_cookies_ignore_session)
427{
428 Ecore_Con_Url *ec_url = _ecore_con_url_cookies_test_init();
429 Eina_Tmpstr *path;
430 int tmpfd;
431
432 tmpfd = eina_file_mkstemp(COOKIEJAR, &path);
433
434 fail_unless(ecore_con_url_cookies_jar_file_set(ec_url, path));
435 ecore_con_url_cookies_ignore_old_session_set(ec_url,EINA_TRUE);
436
437 fail_unless(ecore_con_url_get(ec_url));
438
439 ecore_main_loop_begin();
440
441 _ecore_con_url_cookies_test_shutdown(ec_url, tmpfd, &path);
442}
443END_TEST
444
321void ecore_con_test_ecore_con_url(TCase *tc) 445void ecore_con_test_ecore_con_url(TCase *tc)
322{ 446{
323 tcase_add_test(tc, ecore_test_ecore_con_url_init); 447 tcase_add_test(tc, ecore_con_test_ecore_con_url_init);
324 tcase_add_test(tc, ecore_test_ecore_con_url_create); 448 tcase_add_test(tc, ecore_con_test_ecore_con_url_create);
325 tcase_add_test(tc, ecore_test_ecore_con_url_download); 449 tcase_add_test(tc, ecore_con_test_ecore_con_url_download);
450 tcase_add_test(tc, ecore_con_test_ecore_con_url_cookies_clear);
451 tcase_add_test(tc, ecore_con_test_ecore_con_url_cookies_clear_session);
452 tcase_add_test(tc, ecore_con_test_ecore_con_url_cookies_ignore_session);
326#ifdef ECORE_CON_HTTP_TEST_URL 453#ifdef ECORE_CON_HTTP_TEST_URL
327 tcase_add_test(tc, ecore_test_ecore_con_url_post); 454 tcase_add_test(tc, ecore_con_test_ecore_con_url_post);
328#endif 455#endif
329#ifdef ECORE_CON_FTP_TEST_URL 456#ifdef ECORE_CON_FTP_TEST_URL
330 tcase_add_test(tc, ecore_test_ecore_con_url_ftp_upload); 457 tcase_add_test(tc, ecore_con_test_ecore_con_url_ftp_upload);
331#endif 458#endif
332} 459}