add some basic url database iteration tests

This commit is contained in:
Vincent Sanders 2016-08-08 23:45:01 +01:00
parent 958fb6aa5e
commit 4bc029340e
2 changed files with 80 additions and 36 deletions

View File

@ -167,6 +167,7 @@ START_TEST(nsoption_session_test)
/* check for the correct answer */ /* check for the correct answer */
ck_assert_int_eq(cmp(outnam, test_choices_full_path), 0); ck_assert_int_eq(cmp(outnam, test_choices_full_path), 0);
/* remove test output */
unlink(outnam); unlink(outnam);
res = nsoption_finalise(NULL, NULL); res = nsoption_finalise(NULL, NULL);

View File

@ -126,6 +126,19 @@ static void urldb_create(void)
ck_assert_int_eq(res, NSERROR_OK); ck_assert_int_eq(res, NSERROR_OK);
} }
/** urldb create pre-loaded db fixture */
static void urldb_create_loaded(void)
{
nserror res;
res = corestrings_init();
ck_assert_int_eq(res, NSERROR_OK);
res = urldb_load(test_urldb_path);
ck_assert_int_eq(res, NSERROR_OK);
}
static void urldb_lwc_iterator(lwc_string *str, void *pw) static void urldb_lwc_iterator(lwc_string *str, void *pw)
{ {
int *scount = pw; int *scount = pw;
@ -136,11 +149,14 @@ static void urldb_lwc_iterator(lwc_string *str, void *pw)
(*scount)++; (*scount)++;
} }
/** urldb teardown fixture */
/** urldb teardown fixture with destroy */
static void urldb_teardown(void) static void urldb_teardown(void)
{ {
int scount = 0; int scount = 0;
urldb_destroy();
corestrings_fini(); corestrings_fini();
LOG("Remaining lwc strings:"); LOG("Remaining lwc strings:");
@ -148,6 +164,10 @@ static void urldb_teardown(void)
ck_assert_int_eq(scount, 0); ck_assert_int_eq(scount, 0);
} }
START_TEST(urldb_original_test) START_TEST(urldb_original_test)
{ {
struct host_part *h; struct host_part *h;
@ -160,24 +180,16 @@ START_TEST(urldb_original_test)
char *path_query; char *path_query;
h = urldb_add_host("127.0.0.1"); h = urldb_add_host("127.0.0.1");
if (!h) { ck_assert_msg(h != NULL, "failed adding host");
LOG("failed adding host");
return 1;
}
h = urldb_add_host("intranet"); h = urldb_add_host("intranet");
if (!h) { ck_assert_msg(h != NULL, "failed adding host");
LOG("failed adding host");
return 1;
}
url = make_url("http://intranet/"); url = make_url("http://intranet/");
scheme = nsurl_get_component(url, NSURL_SCHEME); scheme = nsurl_get_component(url, NSURL_SCHEME);
p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url); p = urldb_add_path(scheme, 0, h, strdup("/"), NULL, url);
if (!p) { ck_assert_msg(p != NULL, "failed adding path");
LOG("failed adding path");
return 1;
}
lwc_string_unref(scheme); lwc_string_unref(scheme);
urldb_set_url_title(url, "foo"); urldb_set_url_title(url, "foo");
@ -188,10 +200,7 @@ START_TEST(urldb_original_test)
/* Get host entry */ /* Get host entry */
h = urldb_add_host("netsurf.strcprstskrzkrk.co.uk"); h = urldb_add_host("netsurf.strcprstskrzkrk.co.uk");
if (!h) { ck_assert_msg(h != NULL, "failed adding host");
LOG("failed adding host");
return 1;
}
/* Get path entry */ /* Get path entry */
url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b"); url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b");
@ -199,26 +208,20 @@ START_TEST(urldb_original_test)
path_query = make_path_query(url); path_query = make_path_query(url);
fragment = make_lwc("zz"); fragment = make_lwc("zz");
p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url); p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
if (!p) { ck_assert_msg(p != NULL, "failed adding path");
LOG("failed adding path");
return 1;
}
lwc_string_unref(fragment); lwc_string_unref(fragment);
fragment = make_lwc("aa"); fragment = make_lwc("aa");
p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url); p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
if (!p) { ck_assert_msg(p != NULL, "failed adding path");
LOG("failed adding path");
return 1;
}
lwc_string_unref(fragment); lwc_string_unref(fragment);
fragment = make_lwc("yy"); fragment = make_lwc("yy");
p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url); p = urldb_add_path(scheme, 0, h, strdup(path_query), fragment, url);
if (!p) { ck_assert_msg(p != NULL, "failed adding path");
LOG("failed adding path");
return 1;
}
free(path_query); free(path_query);
lwc_string_unref(fragment); lwc_string_unref(fragment);
lwc_string_unref(scheme); lwc_string_unref(scheme);
@ -366,11 +369,10 @@ START_TEST(urldb_original_test)
ck_assert(test_urldb_get_cookie("http://expires.com/") == NULL); ck_assert(test_urldb_get_cookie("http://expires.com/") == NULL);
urldb_dump(); urldb_dump();
urldb_destroy();
} }
END_TEST END_TEST
TCase *urldb_original_case_create(void) static TCase *urldb_original_case_create(void)
{ {
TCase *tc; TCase *tc;
tc = tcase_create("Original_tests"); tc = tcase_create("Original_tests");
@ -402,16 +404,16 @@ START_TEST(urldb_session_test)
res = urldb_save(outnam); res = urldb_save(outnam);
ck_assert_int_eq(res, NSERROR_OK); ck_assert_int_eq(res, NSERROR_OK);
urldb_destroy();
/* finalise options */ /* finalise options */
res = nsoption_finalise(NULL, NULL); res = nsoption_finalise(NULL, NULL);
ck_assert_int_eq(res, NSERROR_OK); ck_assert_int_eq(res, NSERROR_OK);
/* remove test output */
unlink(outnam);
} }
END_TEST END_TEST
TCase *urldb_session_case_create(void) static TCase *urldb_session_case_create(void)
{ {
TCase *tc; TCase *tc;
tc = tcase_create("Full_session"); tc = tcase_create("Full_session");
@ -426,6 +428,46 @@ TCase *urldb_session_case_create(void)
return tc; return tc;
} }
bool urldb_iterate_entries_cb(nsurl *url, const struct url_data *data)
{
LOG("url: %s", nsurl_access(url));
return true;
}
START_TEST(urldb_iterate_entries_test)
{
urldb_iterate_entries(urldb_iterate_entries_cb);
}
END_TEST
bool urldb_iterate_cookies_cb(const struct cookie_data *data)
{
LOG("%p", data);
}
START_TEST(urldb_iterate_cookies_test)
{
urldb_iterate_cookies(urldb_iterate_cookies_cb);
}
END_TEST
static TCase *urldb_case_create(void)
{
TCase *tc;
tc = tcase_create("General");
/* ensure corestrings are initialised and finalised for every test */
tcase_add_checked_fixture(tc,
urldb_create_loaded,
urldb_teardown);
tcase_add_test(tc, urldb_iterate_entries_test);
tcase_add_test(tc, urldb_iterate_cookies_test);
return tc;
}
/** /**
* Test urldb_add_host asserting on NULL. * Test urldb_add_host asserting on NULL.
*/ */
@ -438,7 +480,7 @@ START_TEST(urldb_api_add_host_assert_test)
END_TEST END_TEST
TCase *urldb_api_case_create(void) static TCase *urldb_api_case_create(void)
{ {
TCase *tc; TCase *tc;
tc = tcase_create("API_checks"); tc = tcase_create("API_checks");
@ -451,13 +493,14 @@ TCase *urldb_api_case_create(void)
} }
Suite *urldb_suite_create(void) static Suite *urldb_suite_create(void)
{ {
Suite *s; Suite *s;
s = suite_create("URLDB"); s = suite_create("URLDB");
suite_add_tcase(s, urldb_api_case_create()); suite_add_tcase(s, urldb_api_case_create());
suite_add_tcase(s, urldb_session_case_create()); suite_add_tcase(s, urldb_session_case_create());
suite_add_tcase(s, urldb_case_create());
suite_add_tcase(s, urldb_original_case_create()); suite_add_tcase(s, urldb_original_case_create());
return s; return s;