forked from enlightenment/efl
Eina coverage: Added eina_unicode_utf8_* and utf8<->Eina_Unicode testing coverage.
SVN revision: 57094
This commit is contained in:
parent
7214694dba
commit
0f686bb04b
|
@ -226,6 +226,111 @@ START_TEST(eina_unicode_strstr_test)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eina_unicode_utf8)
|
||||
{
|
||||
int ind;
|
||||
eina_init();
|
||||
|
||||
/* Valid utf-8 cases */
|
||||
/* First possible sequence of a certain length */
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\x00", &ind) != 0x00) ||
|
||||
(ind != 0));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\x01", &ind) != 0x01) ||
|
||||
(ind != 1));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xC2\x80", &ind) != 0x80) ||
|
||||
(ind != 2));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xE0\xA0\x80", &ind) != 0x800) ||
|
||||
(ind != 3));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xF0\x90\x80\x80", &ind) != 0x10000) ||
|
||||
(ind != 4));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xF8\x88\x80\x80\x80", &ind) != 0x200000) || (ind != 5));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xFC\x84\x80\x80\x80\x80", &ind) != 0x4000000) || (ind != 6));
|
||||
|
||||
/* Last possible sequence of a certain length */
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\x7F", &ind) != 0x7F) ||
|
||||
(ind != 1));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xDF\xBF", &ind) != 0x7FF) ||
|
||||
(ind != 2));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xEF\xBF\xBF", &ind) != 0xFFFF) ||
|
||||
(ind != 3));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xF7\xBF\xBF\xBF", &ind) != 0x1FFFFF) ||
|
||||
(ind != 4));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xFB\xBF\xBF\xBF\xBF", &ind) != 0x3FFFFFF) || (ind != 5));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xFD\xBF\xBF\xBF\xBF\xBF", &ind) != 0x7FFFFFFF) || (ind != 6));
|
||||
|
||||
/* Other boundary conditions */
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xED\x9F\xBF", &ind) != 0xD7FF) ||
|
||||
(ind != 3));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xEE\x80\x80", &ind) != 0xE000) ||
|
||||
(ind != 3));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xEF\xBF\xBD", &ind) != 0xFFFD) ||
|
||||
(ind != 3));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xF4\x8F\xBF\xBF", &ind) != 0x10FFFF) ||
|
||||
(ind != 4));
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\xF4\x90\x80\x80", &ind) != 0x110000) ||
|
||||
(ind != 4));
|
||||
|
||||
/* Error cases */
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_next("\x80", &ind) != 0xDC80) ||
|
||||
(ind != 1));
|
||||
/* Add some more error cases here */
|
||||
|
||||
/* Just to cover prev/len. General utf-8 parsing was covered above */
|
||||
fail_if(eina_unicode_utf8_get_len("\xF4\x90\x80\x80\xF4\x8F\xBF\xBF") != 2);
|
||||
ind = 0;
|
||||
fail_if((eina_unicode_utf8_get_prev("\xED\x9F\xBF", &ind) != 0xD7FF) ||
|
||||
(ind != 0));
|
||||
ind = 3;
|
||||
fail_if((eina_unicode_utf8_get_prev("\xED\x9F\xBF", &ind) != 0x00) ||
|
||||
(ind != 0));
|
||||
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eina_unicode_utf8_conversion)
|
||||
{
|
||||
Eina_Unicode uni_in[] = {0x5D0, 0xFDF6, 0xDC80, 0x1F459, 0x3FFFFFF,
|
||||
0x7FFFFFFF, 'a', 'b', 'c', 0};
|
||||
Eina_Unicode *uni_out;
|
||||
char c_in[] = "\xD7\x90""\xEF\xB7\xB6""\x80""\xF0\x9F\x91\x99"
|
||||
"\xFB\xBF\xBF\xBF\xBF""\xFD\xBF\xBF\xBF\xBF\xBF""abc";
|
||||
char *c_out;
|
||||
int len;
|
||||
|
||||
eina_init();
|
||||
|
||||
uni_out = eina_unicode_utf8_to_unicode(c_in, &len);
|
||||
fail_if((len != 9) || eina_unicode_strcmp(uni_in, uni_out));
|
||||
free(uni_out);
|
||||
|
||||
c_out = eina_unicode_unicode_to_utf8(uni_in, &len);
|
||||
fail_if((len != 24) || strcmp(c_in, c_out));
|
||||
free(c_out);
|
||||
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eina_test_ustr(TCase *tc)
|
||||
{
|
||||
|
@ -237,6 +342,8 @@ eina_test_ustr(TCase *tc)
|
|||
tcase_add_test(tc,eina_unicode_strnlen_test);
|
||||
tcase_add_test(tc,eina_unicode_strdup_test);
|
||||
tcase_add_test(tc,eina_unicode_strstr_test);
|
||||
tcase_add_test(tc,eina_unicode_utf8);
|
||||
tcase_add_test(tc,eina_unicode_utf8_conversion);
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue