summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2016-01-04 15:20:04 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-01-04 15:42:59 -0800
commit39dcf0e55aa76be1f0b9dbdb66bb95241b502b45 (patch)
tree6cfde22e9546efe8e67e72ec9c33c511c12a2762
parent7ded7cb707a1fa4055be970862ad5faf344ced87 (diff)
eina: add test case for eina_base64url_decode API.
Summary: Depends on D3521 Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D3522 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
-rw-r--r--src/tests/eina/eina_test_str.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/tests/eina/eina_test_str.c b/src/tests/eina/eina_test_str.c
index b0f98d1fe4..ecb71fee6c 100644
--- a/src/tests/eina/eina_test_str.c
+++ b/src/tests/eina/eina_test_str.c
@@ -423,9 +423,11 @@ START_TEST(str_base64_encode_decode)
423} 423}
424END_TEST 424END_TEST
425 425
426START_TEST(str_base64url_encode) 426START_TEST(str_base64url_encode_decode)
427{ 427{
428 unsigned int i; 428 unsigned int i;
429 int len;
430 unsigned char *decoded;
429 431
430 for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++) 432 for (i = 0; i < sizeof (tests) / sizeof (tests[0]); i++)
431 { 433 {
@@ -433,8 +435,23 @@ START_TEST(str_base64url_encode)
433 435
434 encoded = eina_str_base64url_encode((unsigned char*) tests[i].decoded_str, tests[i].len); 436 encoded = eina_str_base64url_encode((unsigned char*) tests[i].decoded_str, tests[i].len);
435 fail_if(strcmp(encoded, tests[i].encoded_url)); 437 fail_if(strcmp(encoded, tests[i].encoded_url));
438
439 decoded = eina_str_base64url_decode(tests[i].encoded_url, &len);
440 fail_if(memcmp(decoded, tests[i].decoded_str, tests[i].len));
441
442 fprintf(stderr, "len = %d, tests[%d].len = %d\n", len, i, tests[i].len);
443 fail_if(len != (int)tests[i].len);
444
436 free(encoded); 445 free(encoded);
446 free(decoded);
437 } 447 }
448
449 //Failure scenarios.
450 decoded = eina_str_base64url_decode(NULL, &len);
451 fail_if(decoded);
452
453 decoded = eina_str_base64url_decode("TWFu", NULL);
454 fail_if(memcmp(decoded, "Man", 3));
438} 455}
439END_TEST 456END_TEST
440 457
@@ -478,7 +495,7 @@ eina_test_str(TCase *tc)
478 tcase_add_test(tc, str_memdup); 495 tcase_add_test(tc, str_memdup);
479 tcase_add_test(tc, str_strftime); 496 tcase_add_test(tc, str_strftime);
480 tcase_add_test(tc, str_base64_encode_decode); 497 tcase_add_test(tc, str_base64_encode_decode);
481 tcase_add_test(tc, str_base64url_encode); 498 tcase_add_test(tc, str_base64url_encode_decode);
482#ifdef HAVE_ICONV 499#ifdef HAVE_ICONV
483 tcase_add_test(tc, str_convert); 500 tcase_add_test(tc, str_convert);
484#endif 501#endif