eina: test case for base64 encoding function.
authorSrivardhan Hebbar <sri.hebbar@samsung.com>
Fri, 20 Nov 2015 01:44:07 +0000 (02:44 +0100)
committerCedric BAIL <cedric@osg.samsung.com>
Sun, 22 Nov 2015 22:28:09 +0000 (23:28 +0100)
Summary: Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com>

Reviewers: cedric

Differential Revision: https://phab.enlightenment.org/D3229

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/tests/eina/eina_test_str.c

index 97b3865..d4fc5e1 100644 (file)
@@ -365,6 +365,55 @@ START_TEST(str_strftime)
 }
 END_TEST
 
+START_TEST(str_base64_encode)
+{
+   /* All cases are taken from https://en.wikipedia.org/wiki/Base64 */
+
+   unsigned char *str = (unsigned char *)"any carnal pleasure.";
+   char *encoded;
+
+   encoded = eina_str_base64_encode(str, 20);
+   fail_unless(strcmp(encoded, "YW55IGNhcm5hbCBwbGVhc3VyZS4="));
+   free(encoded);
+
+   encoded = eina_str_base64_encode(str, 19);
+   fail_unless(strcmp(encoded, "YW55IGNhcm5hbCBwbGVhc3VyZQ=="));
+   free(encoded);
+
+   encoded = eina_str_base64_encode(str, 18);
+   fail_unless(strcmp(encoded, "YW55IGNhcm5hbCBwbGVhc3Vy"));
+   free(encoded);
+
+   encoded = eina_str_base64_encode(str, 17);
+   fail_unless(strcmp(encoded, "YW55IGNhcm5hbCBwbGVhc3U="));
+   free(encoded);
+
+   encoded = eina_str_base64_encode(str, 16);
+   fail_unless(strcmp(encoded, "YW55IGNhcm5hbCBwbGVhcw=="));
+   free(encoded);
+
+   encoded = eina_str_base64_encode((unsigned char *)"pleasure.", 9);
+   fail_unless(strcmp(encoded, "cGxlYXN1cmUu"));
+   free(encoded);
+
+   encoded = eina_str_base64_encode((unsigned char *)"leasure.", 8);
+   fail_unless(strcmp(encoded, "bGVhc3VyZS4="));
+   free(encoded);
+
+   encoded = eina_str_base64_encode((unsigned char *)"easure.", 7);
+   fail_unless(strcmp(encoded, "ZWFzdXJlLg=="));
+   free(encoded);
+
+   encoded = eina_str_base64_encode((unsigned char *)"asure.", 6);
+   fail_unless(strcmp(encoded, "YXN1cmUu"));
+   free(encoded);
+
+   encoded = eina_str_base64_encode((unsigned char *)"sure.", 5);
+   fail_unless(strcmp(encoded, "YXN1cmUu"));
+   free(encoded);
+}
+END_TEST
+
 #ifdef HAVE_ICONV
 START_TEST(str_convert)
 {
@@ -404,6 +453,7 @@ eina_test_str(TCase *tc)
    tcase_add_test(tc, str_join_len);
    tcase_add_test(tc, str_memdup);
    tcase_add_test(tc, str_strftime);
+   tcase_add_test(tc, str_base64_encode);
 #ifdef HAVE_ICONV
    tcase_add_test(tc, str_convert);
 #endif