From 94de23dce9b4cb490bcaf08433c6ba75abf4a29c Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 9 Aug 2016 13:15:36 +0100 Subject: [PATCH] add more tests for partial iterator in url database --- test/urldbtest.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 3 deletions(-) diff --git a/test/urldbtest.c b/test/urldbtest.c index 67f833e99..bc707edfb 100644 --- a/test/urldbtest.c +++ b/test/urldbtest.c @@ -483,12 +483,20 @@ END_TEST /** * iterate through partial matches */ -START_TEST(urldb_iterate_partial_test) +START_TEST(urldb_iterate_partial_www_test) { cb_count = 0; urldb_iterate_partial("www", urldb_iterate_entries_cb); ck_assert_int_eq(cb_count, 7); +} +END_TEST + +/** + * iterate through partial matches + */ +START_TEST(urldb_iterate_partial_nomatch_test) +{ cb_count = 0; urldb_iterate_partial("/", urldb_iterate_entries_cb); ck_assert_int_eq(cb_count, 0); @@ -496,6 +504,62 @@ START_TEST(urldb_iterate_partial_test) } END_TEST +/** + * iterate through partial matches + */ +START_TEST(urldb_iterate_partial_add_test) +{ + nsurl *url; + + cb_count = 0; + urldb_iterate_partial("wikipedia", urldb_iterate_entries_cb); + ck_assert_int_eq(cb_count, 0); + + url = make_url(wikipedia_url); + urldb_add_url(url); + nsurl_unref(url); + + cb_count = 0; + urldb_iterate_partial("wikipedia", urldb_iterate_entries_cb); + ck_assert_int_eq(cb_count, 1); +} +END_TEST + +/** + * iterate through partial matches + */ +START_TEST(urldb_iterate_partial_path_test) +{ + + cb_count = 0; + urldb_iterate_partial("en.wikipedia.org/wiki", urldb_iterate_entries_cb); + ck_assert_int_eq(cb_count, 2); +} +END_TEST + +/** + * iterate through partial matches + */ +START_TEST(urldb_iterate_partial_numeric_test) +{ + nsurl *url; + + cb_count = 0; + urldb_iterate_partial("192.168.7.1/", urldb_iterate_entries_cb); + ck_assert_int_eq(cb_count, 0); + + url = make_url("http://192.168.7.1/index.html"); + urldb_add_url(url); + nsurl_unref(url); + + cb_count = 0; + urldb_iterate_partial("192.168.7.1/", urldb_iterate_entries_cb); + ck_assert_int_eq(cb_count, 1); + + +} +END_TEST + START_TEST(urldb_auth_details_test) { nsurl *url; @@ -509,7 +573,6 @@ START_TEST(urldb_auth_details_test) ck_assert_str_eq(res, auth); nsurl_unref(url); - } END_TEST @@ -623,7 +686,11 @@ static TCase *urldb_case_create(void) urldb_teardown); tcase_add_test(tc, urldb_iterate_entries_test); - tcase_add_test(tc, urldb_iterate_partial_test); + tcase_add_test(tc, urldb_iterate_partial_www_test); + tcase_add_test(tc, urldb_iterate_partial_nomatch_test); + tcase_add_test(tc, urldb_iterate_partial_add_test); + tcase_add_test(tc, urldb_iterate_partial_path_test); + tcase_add_test(tc, urldb_iterate_partial_numeric_test); tcase_add_test(tc, urldb_auth_details_test); tcase_add_test(tc, urldb_thumbnail_test); tcase_add_test(tc, urldb_cert_permissions_test); @@ -715,6 +782,16 @@ START_TEST(urldb_api_add_host_assert_test) } END_TEST +/** + * test url database finalisation without initialisation. + */ +START_TEST(urldb_api_destroy_no_init_test) +{ + urldb_destroy(); +} +END_TEST + + /** * test case for urldb API including error returns and asserts */ @@ -727,6 +804,9 @@ static TCase *urldb_api_case_create(void) urldb_api_add_host_assert_test, 6); + tcase_add_test(tc, urldb_api_destroy_no_init_test); + + return tc; }