add nsurl get_utf8 test case

This commit is contained in:
Vincent Sanders 2017-03-10 10:22:17 +00:00
parent b307fa4311
commit 510efac384

View File

@ -53,6 +53,16 @@ struct test_compare {
bool res; bool res;
}; };
/* Fixtures */
static void corestring_create(void)
{
ck_assert(corestrings_init() == NSERROR_OK);
}
/**
* iterator for any remaining strings in teardown fixture
*/
static void netsurf_lwc_iterator(lwc_string *str, void *pw) static void netsurf_lwc_iterator(lwc_string *str, void *pw)
{ {
fprintf(stderr, fprintf(stderr,
@ -62,6 +72,15 @@ static void netsurf_lwc_iterator(lwc_string *str, void *pw)
lwc_string_data(str)); lwc_string_data(str));
} }
static void corestring_teardown(void)
{
corestrings_fini();
lwc_iterate_strings(netsurf_lwc_iterator, NULL);
}
/* tests */
static const char *base_str = "http://a/b/c/d;p?q"; static const char *base_str = "http://a/b/c/d;p?q";
static const struct test_pairs create_tests[] = { static const struct test_pairs create_tests[] = {
@ -1153,22 +1172,71 @@ START_TEST(nsurl_api_assert_parent_test)
END_TEST END_TEST
/* Fixtures */ /* utf8 test case */
static void corestring_create(void) /**
* utf8 tests
*/
static const struct test_pairs utf8_tests[] = {
{ "http://a.xn--11b4c3d/a", "http://a.कॉम/a" },
{ "https://smog.xn--3oq18vl8pn36a/test", "https://smog.大众汽车/test"},
};
/**
* get utf8 test
*/
START_TEST(nsurl_get_utf8_test)
{ {
ck_assert(corestrings_init() == NSERROR_OK); nserror err;
nsurl *url;
const struct test_pairs *tst = &utf8_tests[_i];
char *utf8out;
size_t utf8out_len;
/* not testing create, this should always succeed */
err = nsurl_create(tst->test, &url);
ck_assert(err == NSERROR_OK);
err = nsurl_get_utf8(url, &utf8out, &utf8out_len);
ck_assert(err == NSERROR_OK);
ck_assert_str_eq(utf8out, tst->res);
free(utf8out);
nsurl_unref(url);
}
END_TEST
/**
* test case for utf8 output
*/
static TCase *nsurl_utf8_case_create(void)
{
TCase *tc;
tc = tcase_create("UTF-8 output");
tcase_add_unchecked_fixture(tc,
corestring_create,
corestring_teardown);
tcase_add_loop_test(tc,
nsurl_get_utf8_test,
0, NELEMS(utf8_tests));
return tc;
} }
static void corestring_teardown(void)
{
corestrings_fini();
lwc_iterate_strings(netsurf_lwc_iterator, NULL);
}
/* suite generation */ /* test suite */
/**
* nsurl suite generation
*/
static Suite *nsurl_suite(void) static Suite *nsurl_suite(void)
{ {
Suite *s; Suite *s;
@ -1389,9 +1457,14 @@ static Suite *nsurl_suite(void)
suite_add_tcase(s, tc_parent); suite_add_tcase(s, tc_parent);
/* UTF-8 output */
suite_add_tcase(s, nsurl_utf8_case_create());
return s; return s;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int number_failed; int number_failed;