utils: add ty_eina_unicode_base64_encode()

This commit is contained in:
Boris Faure 2023-08-16 17:28:59 +02:00
parent 0d640d2775
commit 682edf79dc
Signed by: borisfaure
GPG Key ID: EAA9CD729F522998
5 changed files with 62 additions and 0 deletions

View File

@ -911,6 +911,7 @@ elm_main(int argc, char **argv)
goto end;
}
emile_init();
ecore_con_init();
ecore_con_url_init();
@ -1069,6 +1070,7 @@ elm_main(int argc, char **argv)
ecore_con_url_shutdown();
ecore_con_shutdown();
emile_shutdown();
instance.config = NULL;
end:

View File

@ -41,6 +41,7 @@ static struct {
{ "color_parse_css_rgb", tytest_color_parse_css_rgb},
{ "color_parse_css_hsl", tytest_color_parse_css_hsl},
{ "extn_matching", tytest_extn_matching},
{ "base64", tytest_base64},
{ NULL, NULL},
};
@ -212,6 +213,7 @@ main(int argc, char **argv)
return _run_tytests(argc, argv);
eina_init();
emile_init();
_log_domain = eina_log_domain_register("tytest", NULL);
@ -223,6 +225,7 @@ main(int argc, char **argv)
tytest_common_shutdown();
emile_shutdown();
eina_shutdown();
return 0;

View File

@ -18,5 +18,6 @@ int tytest_color_parse_edc(void);
int tytest_color_parse_css_rgb(void);
int tytest_color_parse_css_hsl(void);
int tytest_extn_matching(void);
int tytest_base64(void);
#endif

View File

@ -1,8 +1,12 @@
#include "private.h"
#include "utils.h"
#include "sb.h"
#include <Ecore.h>
#include <Ecore_File.h>
#include <Emile.h>
#include <assert.h>
#include <unistd.h>
#include <pwd.h>
@ -72,3 +76,54 @@ end:
free(escaped);
free(s);
}
char *
ty_eina_unicode_base64_encode(Eina_Unicode *unicode)
{
int utf8_len = 0;
Eina_Binbuf *bb;
char *src;
char *res;
Eina_Strbuf *sb;
src = eina_unicode_unicode_to_utf8(unicode, &utf8_len);
bb = eina_binbuf_manage_new((const unsigned char*)src, utf8_len, EINA_FALSE);
sb = emile_base64_encode(bb);
eina_binbuf_free(bb);
res = (char*) eina_strbuf_string_steal(sb);
eina_strbuf_free(sb);
return res;
}
#if defined(BINARY_TYTEST)
int tytest_base64(void)
{
Eina_Unicode *src;
char *res;
const char *expected;
const char *terminology = "Terminology rox!";
src = eina_unicode_utf8_to_unicode(terminology, NULL);
res = ty_eina_unicode_base64_encode(src);
assert(res);
expected = "VGVybWlub2xvZ3kgcm94IQ==";
assert(memcmp(res, expected, strlen(expected)) == 0);
free(src);
free(res);
const char *hearts = "♥♡👍🚲✿ ❀ ❁🙌";
src = eina_unicode_utf8_to_unicode(hearts, NULL);
res = ty_eina_unicode_base64_encode(src);
assert(res);
expected = "4pml4pmh8J+RjfCfmrLinL8g4p2AIOKdgfCfmYw=";
assert(memcmp(res, expected, strlen(expected)) == 0);
free(src);
free(res);
return 0;
}
#endif

View File

@ -7,4 +7,5 @@
Eina_Bool homedir_get(char *buf, size_t size);
void open_url(const Config *config, const char *url);
char * ty_eina_unicode_base64_encode(Eina_Unicode *c);
#endif