From 22023d616a57286cb9d99489957489ba103e07c0 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 10 Jul 2015 16:25:35 +0100 Subject: Add nsurl unit tests for the component handling parts of the API --- test/nsurl.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'test/nsurl.c') diff --git a/test/nsurl.c b/test/nsurl.c index 1f4111b21..08e6a8283 100644 --- a/test/nsurl.c +++ b/test/nsurl.c @@ -562,6 +562,74 @@ START_TEST(nsurl_compare_test) } END_TEST + +/** + * url component tests + * + * each test1 parameter is converted to a url and + * nsurl[get|has]_component called on it with the given part. The + * result is checked against test1 and res as approprite. + */ +static const struct test_compare component_tests[] = { + { "http://a/b/c/d;p?q", + "http", + NSURL_SCHEME, + true }, + + { "file:///", + NULL, + NSURL_HOST, + false }, + +}; + +/** + * get component + */ +START_TEST(nsurl_get_component_test) +{ + nserror err; + nsurl *url1; + const struct test_compare *tst = &component_tests[_i]; + lwc_string *cmpnt; + + /* not testing create, this should always succeed */ + err = nsurl_create(tst->test1, &url1); + ck_assert(err == NSERROR_OK); + + cmpnt = nsurl_get_component(url1, tst->parts); + if (cmpnt == NULL) { + ck_assert(tst->test2 == NULL); + } else { + ck_assert_str_eq(lwc_string_data(cmpnt), tst->test2); + lwc_string_unref(cmpnt); + } + + nsurl_unref(url1); +} +END_TEST + +/** + * has component + */ +START_TEST(nsurl_has_component_test) +{ + nserror err; + nsurl *url1; + const struct test_compare *tst = &component_tests[_i]; + bool status; + + /* not testing create, this should always succeed */ + err = nsurl_create(tst->test1, &url1); + ck_assert(err == NSERROR_OK); + + status = nsurl_has_component(url1, tst->parts); + ck_assert(status == tst->res); + + nsurl_unref(url1); +} +END_TEST + /** * url reference (copy) and unreference(free) */ @@ -975,6 +1043,7 @@ Suite *nsurl_suite(void) TCase *tc_replace_query; TCase *tc_join; TCase *tc_compare; + TCase *tc_component; s = suite_create("nsurl"); @@ -1135,6 +1204,23 @@ Suite *nsurl_suite(void) suite_add_tcase(s, tc_compare); + /* component */ + tc_component = tcase_create("Component"); + + tcase_add_unchecked_fixture(tc_component, + corestring_create, + corestring_teardown); + + tcase_add_loop_test(tc_component, + nsurl_get_component_test, + 0, NELEMS(component_tests)); + + tcase_add_loop_test(tc_component, + nsurl_has_component_test, + 0, NELEMS(component_tests)); + + suite_add_tcase(s, tc_component); + return s; } -- cgit v1.2.3