Gitweb links:
...log
http://git.netsurf-browser.org/netsurf.git/shortlog/05d2b9a92cd718a38aed647400159c6c40a743d2
...commit
http://git.netsurf-browser.org/netsurf.git/commit/05d2b9a92cd718a38aed647400159c6c40a743d2
...tree
http://git.netsurf-browser.org/netsurf.git/tree/05d2b9a92cd718a38aed647400159c6c40a743d2
The branch, master has been updated
via 05d2b9a92cd718a38aed647400159c6c40a743d2 (commit)
via aa10f2f1efd9e910b675381c7be3d363c019e06a (commit)
from 4394587ab0e9bcb51b6d482497c11c72da0723de (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=05d2b9a92cd718a38aed647400159c6c40a743d2
commit 05d2b9a92cd718a38aed647400159c6c40a743d2
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>
update urldb dump to use LOG rather than writing to stderr directly
diff --git a/content/urldb.c b/content/urldb.c
index 2f7b4a7..add0e4b 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -1343,25 +1343,36 @@ static void urldb_dump_hosts(struct host_part *parent)
static void urldb_dump_search(struct search_node *parent, int depth)
{
const struct host_part *h;
- int i;
+ int i; /* index into string */
+ char s[1024];
+ int r;
if (parent == &empty)
return;
urldb_dump_search(parent->left, depth + 1);
- for (i = 0; i != depth; i++)
- fputc(' ', stderr);
+ for (i = 0; i != depth; i++) {
+ s[i] = ' ';
+ }
for (h = parent->data; h; h = h->parent) {
- if (h->part)
- fprintf(stderr, "%s", h->part);
+ if (h->part) {
+ r = snprintf(&s[i], (sizeof(s) - 2) - i, "%s", h->part);
+ if ((i + r) > (sizeof(s) - 2)) {
+ break;
+ }
+ i += r;
+ }
- if (h->parent && h->parent->parent)
- fputc('.', stderr);
+ if (h->parent && h->parent->parent) {
+ s[i]='.';
+ i++;
+ }
}
+ s[i]= 0;
- fputc('\n', stderr);
+ LOG("%s", s);
urldb_dump_search(parent->right, depth + 1);
}
commitdiff
http://git.netsurf-browser.org/netsurf.git/commit/?id=aa10f2f1efd9e910b675381c7be3d363c019e06a
commit aa10f2f1efd9e910b675381c7be3d363c019e06a
Author: Vincent Sanders <[email protected]>
Commit: Vincent Sanders <[email protected]>
wrap urldb tests in check harness and add minimal session test
diff --git a/test/data/urldb b/test/data/urldb
new file mode 100644
index 0000000..62e0da8
--- /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 338ce1f..51111e4 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -1,6 +1,6 @@
/*
- * Copyright 2006 John M Bell <[email protected]>
- * Copyright 2009 John Tytgat <[email protected]>
+ * Copyright 2015 Vincent Sanders <[email protected]>
+ * Copyright 2011 John Mark Bell <[email protected]>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -17,40 +17,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Test nsurl operations.
+ */
#include <assert.h>
-#include <ctype.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
-#include <time.h>
+#include <check.h>
-#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 <libwapcaplet/libwapcaplet.h>
+
+#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://[email protected]/");
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;
+}
-----------------------------------------------------------------------
Summary of changes:
content/urldb.c | 27 +++++---
test/data/urldb | 101 +++++++++++++++++++++++++++
test/urldbtest.c | 200 +++++++++++++++++++++++++++++++++++++++---------------
3 files changed, 265 insertions(+), 63 deletions(-)
create mode 100644 test/data/urldb
diff --git a/content/urldb.c b/content/urldb.c
index 2f7b4a7..add0e4b 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -1343,25 +1343,36 @@ static void urldb_dump_hosts(struct host_part *parent)
static void urldb_dump_search(struct search_node *parent, int depth)
{
const struct host_part *h;
- int i;
+ int i; /* index into string */
+ char s[1024];
+ int r;
if (parent == &empty)
return;
urldb_dump_search(parent->left, depth + 1);
- for (i = 0; i != depth; i++)
- fputc(' ', stderr);
+ for (i = 0; i != depth; i++) {
+ s[i] = ' ';
+ }
for (h = parent->data; h; h = h->parent) {
- if (h->part)
- fprintf(stderr, "%s", h->part);
+ if (h->part) {
+ r = snprintf(&s[i], (sizeof(s) - 2) - i, "%s", h->part);
+ if ((i + r) > (sizeof(s) - 2)) {
+ break;
+ }
+ i += r;
+ }
- if (h->parent && h->parent->parent)
- fputc('.', stderr);
+ if (h->parent && h->parent->parent) {
+ s[i]='.';
+ i++;
+ }
}
+ s[i]= 0;
- fputc('\n', stderr);
+ LOG("%s", s);
urldb_dump_search(parent->right, depth + 1);
}
diff --git a/test/data/urldb b/test/data/urldb
new file mode 100644
index 0000000..62e0da8
--- /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 338ce1f..51111e4 100644
--- a/test/urldbtest.c
+++ b/test/urldbtest.c
@@ -1,6 +1,6 @@
/*
- * Copyright 2006 John M Bell <[email protected]>
- * Copyright 2009 John Tytgat <[email protected]>
+ * Copyright 2015 Vincent Sanders <[email protected]>
+ * Copyright 2011 John Mark Bell <[email protected]>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
@@ -17,40 +17,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/**
+ * \file
+ * Test nsurl operations.
+ */
#include <assert.h>
-#include <ctype.h>
-#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <strings.h>
-#include <time.h>
+#include <check.h>
-#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 <libwapcaplet/libwapcaplet.h>
+
+#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://[email protected]/");
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;
+}
--
NetSurf Browser
_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org