From aa10f2f1efd9e910b675381c7be3d363c019e06a Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 8 Aug 2016 13:42:27 +0100 Subject: wrap urldb tests in check harness and add minimal session test --- test/data/urldb | 101 ++++++++++++++++++++++++++++ test/urldbtest.c | 200 ++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 246 insertions(+), 55 deletions(-) create mode 100644 test/data/urldb diff --git a/test/data/urldb b/test/data/urldb new file mode 100644 index 000000000..62e0da805 --- /dev/null +++ b/test/data/urldb @@ -0,0 +1,101 @@ +106 +en.wikipedia.org +2 +http + +/wiki/Main_Page +1 +1470493303 +0 + + +https + +/wiki/Main_Page +1 +1470493304 +1 + +Wikipedia, the free encyclopedia +localhost +1 +file + +/home/vince/dev-netsurf/workspace/netsurf/%21NetSurf/Resources/en/welcome.html%2Cfaf +0 +0 +0 + + +news.bbc.co.uk +1 +http + +/ +0 +0 +0 + + +slashdot.org +2 +http + +/ +2 +1469961837 +0 + + +https + +/ +3 +1470350373 +1 + +Slashdot: News for nerds, stuff that matters +www.bbc.co.uk +1 +http + +/news/science_and_environment +1 +1470493359 +1 + +Science & Environment - BBC News +www.netsurf-browser.org +4 +http + +/ +0 +0 +0 + + +http + +/contact +0 +0 +0 + + +http + +/documentation +0 +0 +0 + + +http + +/downloads/ +0 +0 +0 + + diff --git a/test/urldbtest.c b/test/urldbtest.c index 338ce1f66..51111e458 100644 --- a/test/urldbtest.c +++ b/test/urldbtest.c @@ -1,6 +1,6 @@ /* - * Copyright 2006 John M Bell - * Copyright 2009 John Tytgat + * Copyright 2015 Vincent Sanders + * Copyright 2011 John Mark Bell * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -17,40 +17,31 @@ * along with this program. If not, see . */ +/** + * \file + * Test nsurl operations. + */ #include -#include -#include #include #include #include -#include -#include +#include -#include "utils/errors.h" -#include "utils/nsurl.h" -#include "netsurf/bitmap.h" -#include "content/content.h" -#include "content/urldb.h" -#include "desktop/cookie_manager.h" -#include "utils/nsoption.h" -#ifdef riscos -/** \todo lose this */ -#include "riscos/bitmap.h" -#endif +#include + +#include "utils/corestrings.h" #include "utils/log.h" #include "utils/corestrings.h" -#include "utils/filename.h" -#include "utils/url.h" -#include "utils/utils.h" +#include "utils/nsurl.h" +#include "netsurf/url_db.h" +#include "content/urldb.h" + +const char *test_urldb_path = "test/data/urldb"; -int option_expire_url = 0; struct netsurf_table *guit = NULL; -static void netsurf_lwc_iterator(lwc_string *str, void *pw) -{ - LOG("[%3u] %.*s", str->refcnt, (int)lwc_string_length(str), lwc_string_data(str)); -} +/*************** original test helpers ************/ bool cookie_manager_add(const struct cookie_data *data) { @@ -61,21 +52,6 @@ void cookie_manager_remove(const struct cookie_data *data) { } - -void bitmap_destroy(void *bitmap) -{ -} - -char *path_to_url(const char *path) -{ - char *r = malloc(strlen(path) + 7 + 1); - - strcpy(r, "file://"); - strcat(r, path); - - return r; -} - nsurl *make_url(const char *url) { nsurl *nsurl; @@ -108,7 +84,6 @@ lwc_string *make_lwc(const char *str) return lwc; } - bool test_urldb_set_cookie(const char *header, const char *url, const char *referer) { @@ -139,7 +114,40 @@ char *test_urldb_get_cookie(const char *url) return ret; } -int main(void) + +/*************************************************/ + +/** urldb create fixture */ +static void urldb_create(void) +{ + nserror res; + res = corestrings_init(); + ck_assert_int_eq(res, NSERROR_OK); +} + +static void urldb_lwc_iterator(lwc_string *str, void *pw) +{ + int *scount = pw; + + LOG("[%3u] %.*s", str->refcnt, + (int)lwc_string_length(str), + lwc_string_data(str)); + (*scount)++; +} + +/** urldb teardown fixture */ +static void urldb_teardown(void) +{ + int scount = 0; + + corestrings_fini(); + + LOG("Remaining lwc strings:"); + lwc_iterate_strings(urldb_lwc_iterator, &scount); + ck_assert_int_eq(scount, 0); +} + +START_TEST(urldb_original_test) { struct host_part *h; struct path_data *p; @@ -150,9 +158,6 @@ int main(void) nsurl *urlr; char *path_query; - - corestrings_init(); - h = urldb_add_host("127.0.0.1"); if (!h) { LOG("failed adding host"); @@ -254,19 +259,19 @@ int main(void) urldb_get_cookie(url, true); nsurl_unref(url); - /* 1563546 */ + /* Mantis bug #993 */ url = make_url("http:moodle.org"); assert(urldb_add_url(url) == true); assert(urldb_get_url(url) != NULL); nsurl_unref(url); - /* also 1563546 */ + /* Mantis bug #993 */ url = make_url("http://a_a/"); assert(urldb_add_url(url)); assert(urldb_get_url(url)); nsurl_unref(url); - /* 1597646 */ + /* Mantis bug #996 */ url = make_url("http://foo@moose.com/"); if (urldb_add_url(url)) { LOG("added %s", nsurl_access(url)); @@ -274,7 +279,7 @@ int main(void) } nsurl_unref(url); - /* 1535120 */ + /* Mantis bug #913 */ url = make_url("http://www2.2checkout.com/"); assert(urldb_add_url(url)); assert(urldb_get_url(url)); @@ -312,7 +317,7 @@ int main(void) /* Invalid path (contains different leafname) */ assert(test_urldb_set_cookie("name=value;Path=/index.html\r\n", "http://example.org/index.htm", NULL) == false); - + /* Invalid path (contains leafname in different directory) */ assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/bar/index.html", NULL) == false); @@ -361,13 +366,98 @@ int main(void) urldb_dump(); urldb_destroy(); +} +END_TEST - printf("PASS\n"); +TCase *urldb_original_case_create(void) +{ + TCase *tc; + tc = tcase_create("Original urldb tests"); - corestrings_fini(); - LOG("Remaining lwc strings:"); - lwc_iterate_strings(netsurf_lwc_iterator, NULL); + /* ensure corestrings are initialised and finalised for every test */ + tcase_add_checked_fixture(tc, + urldb_create, + urldb_teardown); + + tcase_add_test(tc, urldb_original_test); + + return tc; +} + +START_TEST(urldb_session_test) +{ + nserror res; + + res = urldb_load(test_urldb_path); + ck_assert_int_eq(res, NSERROR_OK); - return 0; + urldb_destroy(); +} +END_TEST + +TCase *urldb_session_case_create(void) +{ + TCase *tc; + tc = tcase_create("Full session"); + + /* ensure corestrings are initialised and finalised for every test */ + tcase_add_checked_fixture(tc, + urldb_create, + urldb_teardown); + + tcase_add_test(tc, urldb_session_test); + + return tc; } +/** + * Test urldb_add_host asserting on NULL. + */ +START_TEST(urldb_api_add_host_assert_test) +{ + struct host_part *res; + res = urldb_add_host(NULL); + ck_assert(res == NULL); +} +END_TEST + + +TCase *urldb_api_case_create(void) +{ + TCase *tc; + tc = tcase_create("API checks"); + + tcase_add_test_raise_signal(tc, + urldb_api_add_host_assert_test, + 6); + + return tc; +} + + +Suite *urldb_suite_create(void) +{ + Suite *s; + s = suite_create("URLDB"); + + suite_add_tcase(s, urldb_api_case_create()); + suite_add_tcase(s, urldb_session_case_create()); + suite_add_tcase(s, urldb_original_case_create()); + + return s; +} + +int main(int argc, char **argv) +{ + int number_failed; + SRunner *sr; + + sr = srunner_create(urldb_suite_create()); + + srunner_run_all(sr, CK_ENV); + + number_failed = srunner_ntests_failed(sr); + srunner_free(sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} -- cgit v1.2.3