2010-06-29 11:20:12 +04:00
|
|
|
/*
|
2016-08-08 15:42:27 +03:00
|
|
|
* Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
|
|
|
|
* Copyright 2011 John Mark Bell <jmb@netsurf-browser.org>
|
2010-06-29 11:20:12 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Test nsurl operations.
|
|
|
|
*/
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-08-09 01:59:21 +03:00
|
|
|
#include <unistd.h>
|
2016-08-08 15:42:27 +03:00
|
|
|
#include <check.h>
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
#include <libwapcaplet/libwapcaplet.h>
|
|
|
|
|
|
|
|
#include "utils/corestrings.h"
|
2010-06-29 11:20:12 +04:00
|
|
|
#include "utils/log.h"
|
2012-10-08 23:22:04 +04:00
|
|
|
#include "utils/corestrings.h"
|
2016-08-08 15:42:27 +03:00
|
|
|
#include "utils/nsurl.h"
|
2016-08-09 01:59:21 +03:00
|
|
|
#include "utils/nsoption.h"
|
2016-08-08 15:42:27 +03:00
|
|
|
#include "netsurf/url_db.h"
|
2016-08-09 02:09:33 +03:00
|
|
|
#include "netsurf/cookie_db.h"
|
2016-08-09 14:26:37 +03:00
|
|
|
#include "netsurf/bitmap.h"
|
2016-08-08 15:42:27 +03:00
|
|
|
#include "content/urldb.h"
|
2016-08-09 14:26:37 +03:00
|
|
|
#include "desktop/gui_internal.h"
|
2016-08-09 00:12:16 +03:00
|
|
|
#include "desktop/cookie_manager.h"
|
2016-08-08 15:42:27 +03:00
|
|
|
|
2017-03-09 01:22:54 +03:00
|
|
|
/**
|
|
|
|
* url database used as input to test sets
|
|
|
|
*/
|
2016-08-08 15:42:27 +03:00
|
|
|
const char *test_urldb_path = "test/data/urldb";
|
2017-03-09 01:22:54 +03:00
|
|
|
/**
|
|
|
|
* url database used as output reference
|
|
|
|
*/
|
|
|
|
const char *test_urldb_out_path = "test/data/urldb-out";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cookie database used as input
|
|
|
|
*/
|
2016-08-09 02:09:33 +03:00
|
|
|
const char *test_cookies_path = "test/data/cookies";
|
2017-03-09 01:22:54 +03:00
|
|
|
/**
|
|
|
|
* cookie database used as output reference
|
|
|
|
*/
|
|
|
|
const char *test_cookies_out_path = "test/data/cookies-out";
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2016-08-09 14:41:16 +03:00
|
|
|
const char *wikipedia_url = "http://www.wikipedia.org/";
|
|
|
|
|
2015-07-07 18:02:54 +03:00
|
|
|
struct netsurf_table *guit = NULL;
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2017-03-13 19:44:30 +03:00
|
|
|
|
2017-03-14 00:20:47 +03:00
|
|
|
struct test_urls {
|
2017-03-13 19:44:30 +03:00
|
|
|
const char* url;
|
|
|
|
const char* title;
|
2017-03-14 01:04:38 +03:00
|
|
|
const content_type type;
|
|
|
|
const bool persistent;
|
2017-03-13 19:44:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
|
|
|
|
|
|
|
|
|
2017-09-09 12:59:21 +03:00
|
|
|
/* Stubs */
|
|
|
|
nserror nslog_set_filter_by_options() { return NSERROR_OK; }
|
|
|
|
|
2017-03-10 01:11:55 +03:00
|
|
|
/**
|
|
|
|
* generate test output filenames
|
|
|
|
*/
|
|
|
|
static char *testnam(char *out)
|
|
|
|
{
|
|
|
|
static int count = 0;
|
|
|
|
static char name[64];
|
2017-03-14 00:20:47 +03:00
|
|
|
snprintf(name, 64, "/tmp/urldbtest%d-%d", getpid(), count);
|
2017-03-10 01:11:55 +03:00
|
|
|
count++;
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-03-09 01:22:54 +03:00
|
|
|
/**
|
|
|
|
* compare two files contents
|
|
|
|
*/
|
|
|
|
static int cmp(const char *f1, const char *f2)
|
|
|
|
{
|
|
|
|
int res = 0;
|
|
|
|
FILE *fp1;
|
|
|
|
FILE *fp2;
|
|
|
|
int ch1;
|
|
|
|
int ch2;
|
|
|
|
|
|
|
|
fp1 = fopen(f1, "r");
|
|
|
|
if (fp1 == NULL) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
fp2 = fopen(f2, "r");
|
|
|
|
if (fp2 == NULL) {
|
|
|
|
fclose(fp1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (res == 0) {
|
|
|
|
ch1 = fgetc(fp1);
|
|
|
|
ch2 = fgetc(fp2);
|
|
|
|
|
|
|
|
if (ch1 != ch2) {
|
|
|
|
res = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ch1 == EOF) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp1);
|
|
|
|
fclose(fp2);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
/*************** original test helpers ************/
|
2012-10-08 23:22:04 +04:00
|
|
|
|
2013-09-03 01:41:04 +04:00
|
|
|
bool cookie_manager_add(const struct cookie_data *data)
|
2010-06-29 11:20:12 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-03 01:41:04 +04:00
|
|
|
void cookie_manager_remove(const struct cookie_data *data)
|
2011-01-12 11:40:08 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-08 20:03:57 +03:00
|
|
|
static nsurl *make_url(const char *url)
|
2012-10-08 23:22:04 +04:00
|
|
|
{
|
|
|
|
nsurl *nsurl;
|
|
|
|
if (nsurl_create(url, &nsurl) != NSERROR_OK) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "failed creating nsurl");
|
2012-10-08 23:22:04 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
return nsurl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-08 20:03:57 +03:00
|
|
|
static bool test_urldb_set_cookie(const char *header, const char *url,
|
2012-10-08 23:22:04 +04:00
|
|
|
const char *referer)
|
|
|
|
{
|
|
|
|
nsurl *r = NULL;
|
|
|
|
nsurl *nsurl = make_url(url);
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
if (referer != NULL)
|
|
|
|
r = make_url(referer);
|
|
|
|
|
|
|
|
ret = urldb_set_cookie(header, nsurl, r);
|
|
|
|
|
|
|
|
if (referer != NULL)
|
|
|
|
nsurl_unref(r);
|
|
|
|
nsurl_unref(nsurl);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-08-08 20:03:57 +03:00
|
|
|
static char *test_urldb_get_cookie(const char *url)
|
2012-10-08 23:22:04 +04:00
|
|
|
{
|
|
|
|
nsurl *nsurl = make_url(url);
|
|
|
|
char *ret;
|
|
|
|
|
2013-04-08 20:25:12 +04:00
|
|
|
ret = urldb_get_cookie(nsurl, true);
|
2012-10-08 23:22:04 +04:00
|
|
|
nsurl_unref(nsurl);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
|
|
|
|
/*************************************************/
|
|
|
|
|
2016-08-09 14:26:37 +03:00
|
|
|
/* mock table callbacks */
|
|
|
|
static void destroy_bitmap(void *b)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gui_bitmap_table tst_bitmap_table = {
|
|
|
|
.destroy = destroy_bitmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct netsurf_table tst_table = {
|
|
|
|
.bitmap = &tst_bitmap_table,
|
|
|
|
};
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
/** urldb create fixture */
|
|
|
|
static void urldb_create(void)
|
|
|
|
{
|
|
|
|
nserror res;
|
2016-08-09 14:26:37 +03:00
|
|
|
|
|
|
|
/* mock bitmap interface */
|
|
|
|
guit = &tst_table;
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
res = corestrings_init();
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
}
|
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
/** urldb create pre-loaded db fixture */
|
|
|
|
static void urldb_create_loaded(void)
|
|
|
|
{
|
|
|
|
nserror res;
|
|
|
|
|
2016-08-09 14:26:37 +03:00
|
|
|
/* mock bitmap interface */
|
|
|
|
guit = &tst_table;
|
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
res = corestrings_init();
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
|
|
|
res = urldb_load(test_urldb_path);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
2016-08-09 02:09:33 +03:00
|
|
|
urldb_load_cookies(test_cookies_path);
|
2016-08-09 01:45:01 +03:00
|
|
|
}
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
static void urldb_lwc_iterator(lwc_string *str, void *pw)
|
|
|
|
{
|
|
|
|
int *scount = pw;
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "[%3u] %.*s", str->refcnt,
|
|
|
|
(int)lwc_string_length(str), lwc_string_data(str));
|
2016-08-08 15:42:27 +03:00
|
|
|
(*scount)++;
|
|
|
|
}
|
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
|
|
|
|
/** urldb teardown fixture with destroy */
|
2016-08-08 15:42:27 +03:00
|
|
|
static void urldb_teardown(void)
|
|
|
|
{
|
|
|
|
int scount = 0;
|
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
urldb_destroy();
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
corestrings_fini();
|
|
|
|
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Remaining lwc strings:");
|
2016-08-08 15:42:27 +03:00
|
|
|
lwc_iterate_strings(urldb_lwc_iterator, &scount);
|
|
|
|
ck_assert_int_eq(scount, 0);
|
|
|
|
}
|
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
START_TEST(urldb_original_test)
|
2010-06-29 11:20:12 +04:00
|
|
|
{
|
2012-10-08 23:22:04 +04:00
|
|
|
nsurl *url;
|
|
|
|
nsurl *urlr;
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
/* fragments */
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm?a=b");
|
2017-03-08 16:27:00 +03:00
|
|
|
ck_assert(urldb_add_url(url) == true);
|
|
|
|
nsurl_unref(url);
|
2016-08-09 01:45:01 +03:00
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#zz?a=b");
|
|
|
|
ck_assert(urldb_add_url(url) == true);
|
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#aa?a=b");
|
|
|
|
ck_assert(urldb_add_url(url) == true);
|
|
|
|
nsurl_unref(url);
|
2016-08-09 01:45:01 +03:00
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
url = make_url("http://netsurf.strcprstskrzkrk.co.uk/path/to/resource.htm#yy?a=b");
|
|
|
|
ck_assert(urldb_add_url(url) == true);
|
2012-10-08 23:22:04 +04:00
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2012-10-10 21:00:47 +04:00
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
/* set cookies on urls */
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2");
|
|
|
|
urldb_set_cookie("mmblah=foo; path=/; expires=Thur, 31-Dec-2099 00:00:00 GMT\r\n", url, NULL);
|
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("http://www.minimarcos.org.uk/cgi-bin/forum/Blah.pl?,v=login,p=2");
|
|
|
|
urldb_set_cookie("BlahPW=bar; path=/; expires=Thur, 31-Dec-2099 00:00:00 GMT\r\n", url, NULL);
|
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("http://ccdb.cropcircleresearch.com/");
|
|
|
|
urldb_set_cookie("details=foo|bar|Sun, 03-Jun-2007;expires=Mon, 24-Jul-2006 09:53:45 GMT\r\n", url, NULL);
|
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("http://www.google.com/");
|
|
|
|
urldb_set_cookie("PREF=ID=a:TM=b:LM=c:S=d; path=/; domain=.google.com\r\n", url, NULL);
|
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("http://www.bbc.co.uk/");
|
|
|
|
urldb_set_cookie("test=foo, bar, baz; path=/, quux=blah; path=/", url, NULL);
|
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
// urldb_set_cookie("a=b; path=/; domain=.a.com", "http://a.com/", NULL);
|
|
|
|
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("https://www.foo.com/blah/moose");
|
|
|
|
urlr = make_url("https://www.foo.com/blah/moose");
|
|
|
|
urldb_set_cookie("foo=bar;Path=/blah;Secure\r\n", url, urlr);
|
|
|
|
nsurl_unref(url);
|
|
|
|
nsurl_unref(urlr);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2012-10-08 23:22:04 +04:00
|
|
|
url = make_url("https://www.foo.com/blah/wxyzabc");
|
2013-04-08 20:25:12 +04:00
|
|
|
urldb_get_cookie(url, true);
|
2012-10-08 23:22:04 +04:00
|
|
|
nsurl_unref(url);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2011-01-12 11:40:08 +03:00
|
|
|
|
2010-06-29 11:20:12 +04:00
|
|
|
/* Valid path */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Path=/\r\n", "http://www.google.com/", NULL));
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Valid path (non-root directory) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Path=/foo/bar/\r\n", "http://www.example.org/foo/bar/", NULL));
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Defaulted path */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value\r\n", "http://www.example.org/foo/bar/baz/bat.html", NULL));
|
2017-03-09 16:22:37 +03:00
|
|
|
ck_assert(test_urldb_get_cookie("http://www.example.org/foo/bar/baz/quux.htm") != NULL);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2011-01-29 18:17:42 +03:00
|
|
|
/* Defaulted path with no non-leaf path segments */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value\r\n", "http://no-non-leaf.example.org/index.html", NULL));
|
2017-03-09 16:22:37 +03:00
|
|
|
ck_assert(test_urldb_get_cookie("http://no-non-leaf.example.org/page2.html") != NULL);
|
|
|
|
ck_assert(test_urldb_get_cookie("http://no-non-leaf.example.org/") != NULL);
|
2011-01-29 18:17:42 +03:00
|
|
|
|
2010-06-29 11:20:12 +04:00
|
|
|
/* Valid path (includes leafname) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Version=1;Path=/index.cgi\r\n", "http://example.org/index.cgi", NULL));
|
2017-03-09 16:22:37 +03:00
|
|
|
ck_assert(test_urldb_get_cookie("http://example.org/index.cgi") != NULL);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Valid path (includes leafname in non-root directory) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/foo/index.html", NULL));
|
2010-06-29 11:20:12 +04:00
|
|
|
/* Should _not_ match the above, as the leafnames differ */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_get_cookie("http://www.example.org/foo/bar.html") == NULL);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Invalid path (contains different leafname) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Path=/index.html\r\n", "http://example.org/index.htm", NULL) == false);
|
2016-08-08 15:42:27 +03:00
|
|
|
|
2010-06-29 11:20:12 +04:00
|
|
|
/* Invalid path (contains leafname in different directory) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/bar/index.html", NULL) == false);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test partial domain match with IP address failing */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Domain=.foo.org\r\n", "http://192.168.0.1/", NULL) == false);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test handling of non-domain cookie sent by server (domain part should
|
|
|
|
* be ignored) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("foo=value;Domain=blah.com\r\n", "http://www.example.com/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://www.example.com/"), "foo=value") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test handling of domain cookie from wrong host (strictly invalid but
|
|
|
|
* required to support the real world) */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=value;Domain=.example.com\r\n", "http://foo.bar.example.com/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://www.example.com/"), "foo=value; name=value") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test presence of separators in cookie value */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\";Version=1\r\n", "http://www.example.org/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://www.example.org/"), "$Version=1; name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\"") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test cookie with blank value */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("a=\r\n", "http://www.example.net/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://www.example.net/"), "a=") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test specification of multiple cookies in one header */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("a=b, foo=bar; Path=/\r\n", "http://www.example.net/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://www.example.net/"), "a=b; foo=bar") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test use of separators in unquoted cookie value */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("foo=moo@foo:blah?moar\\ text\r\n", "http://example.com/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://example.com/"), "foo=moo@foo:blah?moar\\ text; name=value") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test use of unnecessary quotes */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("foo=\"hello\";Version=1,bar=bat\r\n", "http://example.com/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://example.com/"), "foo=\"hello\"; bar=bat; name=value") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
|
|
|
/* Test domain matching in unverifiable transactions */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("foo=bar; domain=.example.tld\r\n", "http://www.foo.example.tld/", "http://bar.example.tld/"));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://www.foo.example.tld/"), "foo=bar") == 0);
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2011-11-22 04:34:06 +04:00
|
|
|
/* Test expiry */
|
2016-08-09 00:12:16 +03:00
|
|
|
ck_assert(test_urldb_set_cookie("foo=bar", "http://expires.com/", NULL));
|
|
|
|
ck_assert(strcmp(test_urldb_get_cookie("http://expires.com/"), "foo=bar") == 0);
|
|
|
|
ck_assert(test_urldb_set_cookie("foo=bar; expires=Thu, 01-Jan-1970 00:00:01 GMT\r\n", "http://expires.com/", NULL));
|
|
|
|
ck_assert(test_urldb_get_cookie("http://expires.com/") == NULL);
|
2011-11-22 04:34:06 +04:00
|
|
|
|
2010-06-29 11:20:12 +04:00
|
|
|
urldb_dump();
|
2016-08-08 15:42:27 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2017-03-13 19:44:30 +03:00
|
|
|
/**
|
|
|
|
* test case comprised of tests historicaly found in netsurf
|
|
|
|
*
|
|
|
|
* These tests are carried forward from original open coded tests
|
|
|
|
* found in the url database code.
|
|
|
|
*/
|
2016-08-09 01:45:01 +03:00
|
|
|
static TCase *urldb_original_case_create(void)
|
2016-08-08 15:42:27 +03:00
|
|
|
{
|
|
|
|
TCase *tc;
|
2016-08-09 01:13:23 +03:00
|
|
|
tc = tcase_create("Original_tests");
|
2010-06-29 11:20:12 +04:00
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2017-03-13 19:44:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* add set and get tests
|
|
|
|
*/
|
2017-03-14 00:20:47 +03:00
|
|
|
static const struct test_urls add_set_get_tests[] = {
|
|
|
|
{
|
|
|
|
"http://intranet/",
|
|
|
|
"foo",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
}, /* from legacy tests */
|
|
|
|
{
|
|
|
|
"http:moodle.org",
|
|
|
|
"buggy",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
}, /* Mantis bug #993 */
|
|
|
|
{
|
|
|
|
"http://a_a/",
|
|
|
|
"buggsy",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
}, /* Mantis bug #993 */
|
|
|
|
{
|
|
|
|
"http://www2.2checkout.com/",
|
|
|
|
"foobar",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
}, /* Mantis bug #913 */
|
|
|
|
{
|
|
|
|
"http://2.bp.blogspot.com/_448y6kVhntg/TSekubcLJ7I/AAAAAAAAHJE/yZTsV5xT5t4/s1600/covers.jpg",
|
|
|
|
"a more complex title",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_IMAGE,
|
2017-03-14 00:20:47 +03:00
|
|
|
true
|
|
|
|
}, /* Numeric subdomains */
|
|
|
|
{
|
2017-03-14 01:23:50 +03:00
|
|
|
"http://tree.example.com/this_url_has_a_ridiculously_long_path/made_up_from_a_number_of_inoranately_long_elments_some_of_well_over_forty/characters_in_length/the_whole_path_comes_out_well_in_excess_of_two_hundred_characters_in_length/this_is_intended_to_try_and_drive/the_serialisation_code_mad/foo.png",
|
2017-03-14 00:20:47 +03:00
|
|
|
NULL,
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_IMAGE,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"https://tree.example.com:8080/example.png",
|
|
|
|
"fishy port ",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
},
|
2017-03-14 01:23:50 +03:00
|
|
|
{
|
|
|
|
"http://tree.example.com/bar.png",
|
|
|
|
"\t ",
|
|
|
|
CONTENT_IMAGE,
|
|
|
|
false
|
|
|
|
}, /* silly title */
|
2017-03-14 00:20:47 +03:00
|
|
|
{
|
|
|
|
"http://[2001:db8:1f70::999:de8:7648:6e8]:100/",
|
|
|
|
"ipv6 with port",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_TEXTPLAIN,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"file:///home/",
|
|
|
|
NULL,
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
}, /* no title */
|
|
|
|
{
|
|
|
|
"http://foo@moose.com/",
|
|
|
|
NULL,
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
}, /* Mantis bug #996 */
|
|
|
|
{
|
|
|
|
"http://a.xn--11b4c3d/a",
|
|
|
|
"a title",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"https://smog.大众汽车/test",
|
|
|
|
"unicode title 大众汽车",
|
2017-03-14 01:04:38 +03:00
|
|
|
CONTENT_HTML,
|
2017-03-14 00:20:47 +03:00
|
|
|
false
|
|
|
|
},
|
2017-03-13 19:44:30 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add set and get test
|
|
|
|
*/
|
|
|
|
START_TEST(urldb_add_set_get_test)
|
|
|
|
{
|
|
|
|
nserror err;
|
|
|
|
nsurl *url;
|
|
|
|
nsurl *res_url;
|
2017-03-14 00:20:47 +03:00
|
|
|
const struct url_data *data;
|
|
|
|
const struct test_urls *tst = &add_set_get_tests[_i];
|
2017-03-13 19:44:30 +03:00
|
|
|
|
|
|
|
/* not testing create, this should always succeed */
|
|
|
|
err = nsurl_create(tst->url, &url);
|
|
|
|
ck_assert(err == NSERROR_OK);
|
|
|
|
|
|
|
|
/* add the url to the database */
|
|
|
|
ck_assert(urldb_add_url(url) == true);
|
|
|
|
|
|
|
|
/* set title */
|
|
|
|
err = urldb_set_url_title(url, tst->title);
|
|
|
|
ck_assert(err == NSERROR_OK);
|
|
|
|
|
2017-03-14 01:04:38 +03:00
|
|
|
err = urldb_set_url_content_type(url, tst->type);
|
|
|
|
ck_assert(err == NSERROR_OK);
|
|
|
|
|
2017-03-13 19:44:30 +03:00
|
|
|
/* retrieve the url from the database and check it matches */
|
|
|
|
res_url = urldb_get_url(url);
|
|
|
|
ck_assert(res_url != NULL);
|
|
|
|
ck_assert(nsurl_compare(url, res_url, NSURL_COMPLETE) == true);
|
|
|
|
|
|
|
|
/* retrieve url data and check title matches */
|
|
|
|
data = urldb_get_url_data(url);
|
|
|
|
ck_assert(data != NULL);
|
|
|
|
|
|
|
|
/* ensure title matches */
|
|
|
|
if (tst->title != NULL) {
|
|
|
|
ck_assert_str_eq(data->title, tst->title);
|
|
|
|
} else {
|
|
|
|
ck_assert(data->title == NULL);
|
|
|
|
}
|
|
|
|
|
2017-03-14 01:04:38 +03:00
|
|
|
/* ensure type matches */
|
|
|
|
ck_assert(data->type == tst->type);
|
|
|
|
|
2017-03-13 19:44:30 +03:00
|
|
|
/* release test url */
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test cases that simply add and then get a url
|
|
|
|
*
|
|
|
|
* these tests exercise the adding and retrival of urls verifying the
|
|
|
|
* data added.
|
|
|
|
*/
|
|
|
|
static TCase *urldb_add_get_case_create(void)
|
|
|
|
{
|
|
|
|
TCase *tc;
|
|
|
|
tc = tcase_create("Add Get tests");
|
|
|
|
|
|
|
|
/* ensure corestrings are initialised and finalised for every test */
|
|
|
|
tcase_add_checked_fixture(tc,
|
|
|
|
urldb_create,
|
|
|
|
urldb_teardown);
|
|
|
|
|
|
|
|
tcase_add_loop_test(tc,
|
|
|
|
urldb_add_set_get_test,
|
|
|
|
0, NELEMS(add_set_get_tests));
|
|
|
|
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
/**
|
|
|
|
* Session basic test case
|
|
|
|
*
|
|
|
|
* The databases are loaded and saved with no manipulation
|
2017-07-26 11:17:57 +03:00
|
|
|
*
|
|
|
|
* \warning This test will fail when 32bit time_t wraps in 2038 as the
|
|
|
|
* cookie database expiry field is limited to that size.
|
2017-03-08 16:27:00 +03:00
|
|
|
*/
|
2016-08-08 15:42:27 +03:00
|
|
|
START_TEST(urldb_session_test)
|
|
|
|
{
|
|
|
|
nserror res;
|
2016-08-09 01:13:23 +03:00
|
|
|
char *outnam;
|
|
|
|
|
|
|
|
/* writing output requires options initialising */
|
|
|
|
res = nsoption_init(NULL, NULL, NULL);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
2016-08-08 15:42:27 +03:00
|
|
|
|
|
|
|
res = urldb_load(test_urldb_path);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
2012-10-08 23:22:04 +04:00
|
|
|
|
2016-08-09 02:09:33 +03:00
|
|
|
urldb_load_cookies(test_cookies_path);
|
|
|
|
|
2016-08-09 01:13:23 +03:00
|
|
|
/* write database out */
|
2017-03-10 01:11:55 +03:00
|
|
|
outnam = testnam(NULL);
|
2016-08-09 01:13:23 +03:00
|
|
|
res = urldb_save(outnam);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
2017-07-26 11:17:57 +03:00
|
|
|
/* check the url database file written and the test file match */
|
2017-03-09 01:22:54 +03:00
|
|
|
ck_assert_int_eq(cmp(outnam, test_urldb_out_path), 0);
|
|
|
|
|
2016-08-09 02:09:33 +03:00
|
|
|
/* remove test output */
|
|
|
|
unlink(outnam);
|
|
|
|
|
|
|
|
/* write cookies out */
|
2017-03-10 01:11:55 +03:00
|
|
|
outnam = testnam(NULL);
|
2016-08-09 02:09:33 +03:00
|
|
|
urldb_save_cookies(outnam);
|
|
|
|
|
2017-07-26 11:17:57 +03:00
|
|
|
/* check the cookies file written and the test file match */
|
2017-03-09 01:22:54 +03:00
|
|
|
ck_assert_int_eq(cmp(outnam, test_cookies_out_path), 0);
|
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
/* remove test output */
|
|
|
|
unlink(outnam);
|
|
|
|
|
2016-08-09 01:13:23 +03:00
|
|
|
/* finalise options */
|
|
|
|
res = nsoption_finalise(NULL, NULL);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
/**
|
|
|
|
* Session more extensive test case
|
|
|
|
*
|
|
|
|
* The databases are loaded and saved with a host and paths added
|
|
|
|
*/
|
2017-03-07 03:35:57 +03:00
|
|
|
START_TEST(urldb_session_add_test)
|
|
|
|
{
|
|
|
|
nserror res;
|
|
|
|
char *outnam;
|
|
|
|
nsurl *url;
|
2017-03-14 00:20:47 +03:00
|
|
|
unsigned int t;
|
2017-03-07 03:35:57 +03:00
|
|
|
|
|
|
|
/* writing output requires options initialising */
|
|
|
|
res = nsoption_init(NULL, NULL, NULL);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
|
|
|
res = urldb_load(test_urldb_path);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
|
|
|
urldb_load_cookies(test_cookies_path);
|
|
|
|
|
2017-03-13 23:07:56 +03:00
|
|
|
/* add to db */
|
|
|
|
for (t = 0; t < NELEMS(add_set_get_tests); t++) {
|
2017-03-14 00:20:47 +03:00
|
|
|
const struct test_urls *tst = &add_set_get_tests[t];
|
2017-03-08 16:27:00 +03:00
|
|
|
|
2017-03-13 23:07:56 +03:00
|
|
|
/* not testing url creation, this should always succeed */
|
|
|
|
res = nsurl_create(tst->url, &url);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
2017-03-07 03:35:57 +03:00
|
|
|
|
2017-03-13 23:07:56 +03:00
|
|
|
/* add the url to the database */
|
|
|
|
ck_assert(urldb_add_url(url) == true);
|
|
|
|
|
2017-03-14 00:20:47 +03:00
|
|
|
/* set title */
|
|
|
|
res = urldb_set_url_title(url, tst->title);
|
|
|
|
ck_assert(res == NSERROR_OK);
|
|
|
|
|
2017-03-13 23:07:56 +03:00
|
|
|
/* update the visit time so it gets serialised */
|
2017-03-14 00:20:47 +03:00
|
|
|
if (tst->persistent) {
|
|
|
|
res = urldb_set_url_persistence(url, true);
|
|
|
|
} else {
|
|
|
|
res = urldb_update_url_visit_data(url);
|
|
|
|
}
|
2017-03-13 23:07:56 +03:00
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
2017-03-07 03:35:57 +03:00
|
|
|
|
|
|
|
/* write database out */
|
2017-03-10 01:11:55 +03:00
|
|
|
outnam = testnam(NULL);
|
2017-03-07 03:35:57 +03:00
|
|
|
res = urldb_save(outnam);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
2017-03-13 23:07:56 +03:00
|
|
|
/* remove urldb test output */
|
2017-03-07 03:35:57 +03:00
|
|
|
unlink(outnam);
|
|
|
|
|
|
|
|
/* write cookies out */
|
2017-03-10 01:11:55 +03:00
|
|
|
outnam = testnam(NULL);
|
2017-03-07 03:35:57 +03:00
|
|
|
urldb_save_cookies(outnam);
|
|
|
|
|
2017-03-13 23:07:56 +03:00
|
|
|
/* remove cookies test output */
|
2017-03-08 16:27:00 +03:00
|
|
|
unlink(outnam);
|
|
|
|
|
2017-03-07 03:35:57 +03:00
|
|
|
/* finalise options */
|
|
|
|
res = nsoption_finalise(NULL, NULL);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
/**
|
|
|
|
* Test case to check entire session
|
|
|
|
*
|
|
|
|
* These tests define a session as loading a url database and cookie
|
|
|
|
* database and then saving them back to disc.
|
|
|
|
*/
|
2016-08-09 01:45:01 +03:00
|
|
|
static TCase *urldb_session_case_create(void)
|
2016-08-08 15:42:27 +03:00
|
|
|
{
|
|
|
|
TCase *tc;
|
2016-08-09 01:13:23 +03:00
|
|
|
tc = tcase_create("Full_session");
|
2016-08-08 15:42:27 +03:00
|
|
|
|
|
|
|
/* 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);
|
2017-03-07 03:35:57 +03:00
|
|
|
tcase_add_test(tc, urldb_session_add_test);
|
2016-08-08 15:42:27 +03:00
|
|
|
|
|
|
|
return tc;
|
2010-06-29 11:20:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-09 14:26:37 +03:00
|
|
|
static int cb_count;
|
|
|
|
|
2016-08-09 01:59:21 +03:00
|
|
|
static bool urldb_iterate_entries_cb(nsurl *url, const struct url_data *data)
|
2016-08-09 01:45:01 +03:00
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "url: %s", nsurl_access(url));
|
2016-08-09 12:47:47 +03:00
|
|
|
/* fprintf(stderr, "url:%s\ntitle:%s\n\n",nsurl_access(url), data->title); */
|
2016-08-09 14:26:37 +03:00
|
|
|
cb_count++;
|
2016-08-09 01:45:01 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(urldb_iterate_entries_test)
|
|
|
|
{
|
|
|
|
urldb_iterate_entries(urldb_iterate_entries_cb);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-09 14:26:37 +03:00
|
|
|
/**
|
|
|
|
* iterate through partial matches
|
|
|
|
*/
|
2016-08-09 15:15:36 +03:00
|
|
|
START_TEST(urldb_iterate_partial_www_test)
|
2016-08-09 01:45:01 +03:00
|
|
|
{
|
2016-08-09 14:26:37 +03:00
|
|
|
cb_count = 0;
|
2016-08-09 12:47:47 +03:00
|
|
|
urldb_iterate_partial("www", urldb_iterate_entries_cb);
|
2016-08-09 14:26:37 +03:00
|
|
|
ck_assert_int_eq(cb_count, 7);
|
|
|
|
|
2016-08-09 15:15:36 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iterate through partial matches
|
|
|
|
*/
|
|
|
|
START_TEST(urldb_iterate_partial_nomatch_test)
|
|
|
|
{
|
2016-08-09 14:26:37 +03:00
|
|
|
cb_count = 0;
|
|
|
|
urldb_iterate_partial("/", urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 0);
|
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-09 15:15:36 +03:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
|
/**
|
2017-03-14 01:23:50 +03:00
|
|
|
* iterate through partial matches of numeric v4 address
|
2016-08-09 15:15:36 +03:00
|
|
|
*/
|
2017-03-14 01:23:50 +03:00
|
|
|
START_TEST(urldb_iterate_partial_numeric_v4_test)
|
2016-08-09 15:15:36 +03:00
|
|
|
{
|
|
|
|
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);
|
2017-03-14 01:23:50 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* iterate through partial matches of numeric v6 address
|
|
|
|
*/
|
|
|
|
START_TEST(urldb_iterate_partial_numeric_v6_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
|
|
|
|
cb_count = 0;
|
2017-03-14 02:44:06 +03:00
|
|
|
urldb_iterate_partial("[2001:db8:1f70::999:de8:7648:6e8]",
|
2017-03-14 01:23:50 +03:00
|
|
|
urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 0);
|
2016-08-09 15:15:36 +03:00
|
|
|
|
2017-03-14 01:23:50 +03:00
|
|
|
url = make_url("http://[2001:db8:1f70::999:de8:7648:6e8]/index.html");
|
|
|
|
urldb_add_url(url);
|
|
|
|
nsurl_unref(url);
|
2016-08-09 15:15:36 +03:00
|
|
|
|
2017-03-14 01:23:50 +03:00
|
|
|
cb_count = 0;
|
2017-03-14 02:44:06 +03:00
|
|
|
urldb_iterate_partial("[2001:db8:1f70::999:de8:7648:6e8]/index.wrong",
|
|
|
|
urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 0);
|
|
|
|
|
|
|
|
cb_count = 0;
|
|
|
|
urldb_iterate_partial("[2001:db8:1f70::999:de8:7648:6e8]",
|
2017-03-14 01:23:50 +03:00
|
|
|
urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 1);
|
2017-03-14 02:44:06 +03:00
|
|
|
|
|
|
|
cb_count = 0;
|
|
|
|
urldb_iterate_partial("[2001:db8:1f70::999:de8:7648:6e8]/in",
|
|
|
|
urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 1);
|
|
|
|
|
2017-03-14 02:52:56 +03:00
|
|
|
/* double path separators are ignored */
|
|
|
|
cb_count = 0;
|
|
|
|
urldb_iterate_partial("[2001:db8:1f70::999:de8:7648:6e8]//index.html",
|
|
|
|
urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 1);
|
|
|
|
|
|
|
|
/* bad ipv6 address inet_pton should fail with this */
|
|
|
|
cb_count = 0;
|
|
|
|
urldb_iterate_partial("[2001::1f70::999::7648:8]",
|
|
|
|
urldb_iterate_entries_cb);
|
|
|
|
ck_assert_int_eq(cb_count, 0);
|
|
|
|
|
2016-08-09 15:15:36 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2017-03-14 01:23:50 +03:00
|
|
|
|
2016-08-09 01:59:21 +03:00
|
|
|
START_TEST(urldb_auth_details_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
const char *res;
|
|
|
|
const char *auth = "mooooo";
|
2016-08-09 02:09:33 +03:00
|
|
|
|
2016-08-09 14:41:16 +03:00
|
|
|
url = make_url(wikipedia_url);
|
2016-08-09 01:59:21 +03:00
|
|
|
urldb_set_auth_details(url, "tree", auth);
|
|
|
|
|
|
|
|
res = urldb_get_auth_details(url, "tree");
|
|
|
|
ck_assert_str_eq(res, auth);
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-09 14:26:37 +03:00
|
|
|
|
2016-08-09 12:47:47 +03:00
|
|
|
START_TEST(urldb_cert_permissions_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
bool permit;
|
|
|
|
|
2016-08-09 14:41:16 +03:00
|
|
|
url = make_url(wikipedia_url);
|
2016-08-09 12:47:47 +03:00
|
|
|
|
|
|
|
urldb_set_cert_permissions(url, true); /* permit invalid certs for url */
|
|
|
|
|
|
|
|
permit = urldb_get_cert_permissions(url);
|
|
|
|
|
|
|
|
ck_assert(permit == true);
|
|
|
|
|
|
|
|
urldb_set_cert_permissions(url, false); /* do not permit invalid certs for url */
|
|
|
|
|
|
|
|
permit = urldb_get_cert_permissions(url);
|
|
|
|
|
|
|
|
ck_assert(permit == false);
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-09 14:26:37 +03:00
|
|
|
START_TEST(urldb_update_visit_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
|
2016-08-09 14:41:16 +03:00
|
|
|
url = make_url(wikipedia_url);
|
|
|
|
|
|
|
|
urldb_update_url_visit_data(url);
|
|
|
|
|
|
|
|
urldb_add_url(url);
|
2016-08-09 14:26:37 +03:00
|
|
|
|
|
|
|
urldb_update_url_visit_data(url);
|
|
|
|
/** \todo test needs to check results */
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(urldb_reset_visit_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
|
2016-08-09 14:41:16 +03:00
|
|
|
url = make_url(wikipedia_url);
|
|
|
|
|
|
|
|
urldb_reset_url_visit_data(url);
|
|
|
|
|
|
|
|
urldb_add_url(url);
|
2016-08-09 14:26:37 +03:00
|
|
|
|
|
|
|
urldb_reset_url_visit_data(url);
|
|
|
|
/** \todo test needs to check results */
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(urldb_persistence_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
|
2016-08-09 14:41:16 +03:00
|
|
|
url = make_url(wikipedia_url);
|
|
|
|
|
|
|
|
urldb_set_url_persistence(url, true);
|
|
|
|
|
|
|
|
urldb_add_url(url);
|
2016-08-09 14:26:37 +03:00
|
|
|
|
|
|
|
urldb_set_url_persistence(url, true);
|
|
|
|
|
|
|
|
urldb_set_url_persistence(url, false);
|
|
|
|
/** \todo test needs to check results */
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-09 12:47:47 +03:00
|
|
|
|
2016-08-09 01:45:01 +03:00
|
|
|
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);
|
2016-08-09 15:15:36 +03:00
|
|
|
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);
|
2017-03-14 01:23:50 +03:00
|
|
|
tcase_add_test(tc, urldb_iterate_partial_numeric_v4_test);
|
|
|
|
tcase_add_test(tc, urldb_iterate_partial_numeric_v6_test);
|
2016-08-09 01:59:21 +03:00
|
|
|
tcase_add_test(tc, urldb_auth_details_test);
|
2016-08-09 12:47:47 +03:00
|
|
|
tcase_add_test(tc, urldb_cert_permissions_test);
|
2016-08-09 14:26:37 +03:00
|
|
|
tcase_add_test(tc, urldb_update_visit_test);
|
|
|
|
tcase_add_test(tc, urldb_reset_visit_test);
|
2016-08-09 14:41:16 +03:00
|
|
|
tcase_add_test(tc, urldb_persistence_test);
|
2016-08-09 12:47:47 +03:00
|
|
|
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool urldb_iterate_cookies_cb(const struct cookie_data *data)
|
|
|
|
{
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "%p", data);
|
2016-08-09 12:47:47 +03:00
|
|
|
/* fprintf(stderr, "domain:%s\npath:%s\nname:%s\n\n",data->domain, data->path, data->name);*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
START_TEST(urldb_iterate_cookies_test)
|
|
|
|
{
|
|
|
|
urldb_iterate_cookies(urldb_iterate_cookies_cb);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(urldb_cookie_create_test)
|
|
|
|
{
|
|
|
|
/* Valid path (includes leafname) */
|
|
|
|
const char *cookie_hdr = "name=value;Version=1;Path=/index.cgi\r\n";
|
|
|
|
const char *cookie = "$Version=1; name=value; $Path=\"/index.cgi\"";
|
|
|
|
char *cdata; /* cookie data */
|
|
|
|
|
|
|
|
ck_assert(test_urldb_set_cookie(cookie_hdr, "http://example.org/index.cgi", NULL));
|
|
|
|
cdata = test_urldb_get_cookie("http://example.org/index.cgi");
|
|
|
|
ck_assert_str_eq(cdata, cookie);
|
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
START_TEST(urldb_cookie_delete_test)
|
|
|
|
{
|
|
|
|
/* Valid path (includes leafname) */
|
|
|
|
const char *cookie_hdr = "name=value;Version=1;Path=/index.cgi\r\n";
|
|
|
|
const char *cookie = "$Version=1; name=value; $Path=\"/index.cgi\"";
|
|
|
|
char *cdata; /* cookie data */
|
|
|
|
|
|
|
|
ck_assert(test_urldb_set_cookie(cookie_hdr, "http://example.org/index.cgi", NULL));
|
|
|
|
cdata = test_urldb_get_cookie("http://example.org/index.cgi");
|
|
|
|
ck_assert_str_eq(cdata, cookie);
|
|
|
|
|
|
|
|
urldb_delete_cookie("example.org", "/index.cgi", "name");
|
|
|
|
|
|
|
|
cdata = test_urldb_get_cookie("http://example.org/index.cgi");
|
|
|
|
ck_assert(cdata == NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test case for urldb cookie management
|
|
|
|
*/
|
|
|
|
static TCase *urldb_cookie_case_create(void)
|
|
|
|
{
|
|
|
|
TCase *tc;
|
|
|
|
tc = tcase_create("Cookies");
|
|
|
|
|
|
|
|
/* ensure corestrings are initialised and finalised for every test */
|
|
|
|
tcase_add_checked_fixture(tc,
|
|
|
|
urldb_create_loaded,
|
|
|
|
urldb_teardown);
|
|
|
|
|
|
|
|
tcase_add_test(tc, urldb_cookie_create_test);
|
|
|
|
tcase_add_test(tc, urldb_iterate_cookies_test);
|
|
|
|
tcase_add_test(tc, urldb_cookie_delete_test);
|
2016-08-09 01:45:01 +03:00
|
|
|
|
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2016-08-09 12:47:47 +03:00
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
/**
|
2017-03-08 16:27:00 +03:00
|
|
|
* Test urldb_add_url asserting on NULL.
|
2016-08-08 15:42:27 +03:00
|
|
|
*/
|
2017-03-08 16:27:00 +03:00
|
|
|
START_TEST(urldb_api_add_url_assert_test)
|
2016-08-08 15:42:27 +03:00
|
|
|
{
|
2017-03-08 16:27:00 +03:00
|
|
|
bool res;
|
|
|
|
res = urldb_add_url(NULL);
|
|
|
|
ck_assert(res == true);
|
2016-08-08 15:42:27 +03:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2017-03-08 16:27:00 +03:00
|
|
|
|
2017-03-14 00:53:42 +03:00
|
|
|
/**
|
|
|
|
* Test urldb find failing for differing bad url.
|
|
|
|
*/
|
|
|
|
START_TEST(urldb_api_url_find_test)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
nserror res;
|
|
|
|
|
|
|
|
urldb_create();
|
|
|
|
|
|
|
|
/* search for a url with mailto scheme */
|
|
|
|
res = nsurl_create("mailto:", &url);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
|
|
|
|
res = urldb_set_url_persistence(url, true);
|
|
|
|
ck_assert_int_eq(res, NSERROR_NOT_FOUND);
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
|
|
|
|
/* search for a url with odd scheme and no host */
|
|
|
|
res = nsurl_create("fish:///", &url);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
ck_assert(nsurl_has_component(url, NSURL_HOST) == false);
|
|
|
|
|
2017-03-14 01:04:38 +03:00
|
|
|
res = urldb_set_url_title(url, NULL);
|
2017-03-14 00:53:42 +03:00
|
|
|
ck_assert_int_eq(res, NSERROR_NOT_FOUND);
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
|
|
|
|
/* search for a url with not found url */
|
|
|
|
res = nsurl_create("http://no.example.com/", &url);
|
|
|
|
ck_assert_int_eq(res, NSERROR_OK);
|
|
|
|
ck_assert(nsurl_has_component(url, NSURL_HOST) == true);
|
|
|
|
|
|
|
|
res = urldb_set_url_persistence(url, true);
|
|
|
|
ck_assert_int_eq(res, NSERROR_NOT_FOUND);
|
|
|
|
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-09 15:15:36 +03:00
|
|
|
/**
|
|
|
|
* test url database finalisation without initialisation.
|
|
|
|
*/
|
|
|
|
START_TEST(urldb_api_destroy_no_init_test)
|
|
|
|
{
|
|
|
|
urldb_destroy();
|
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
2016-08-09 12:47:47 +03:00
|
|
|
/**
|
|
|
|
* test case for urldb API including error returns and asserts
|
|
|
|
*/
|
2016-08-09 01:45:01 +03:00
|
|
|
static TCase *urldb_api_case_create(void)
|
2016-08-08 15:42:27 +03:00
|
|
|
{
|
|
|
|
TCase *tc;
|
2016-08-09 01:13:23 +03:00
|
|
|
tc = tcase_create("API_checks");
|
2016-08-08 15:42:27 +03:00
|
|
|
|
|
|
|
tcase_add_test_raise_signal(tc,
|
2017-03-08 16:27:00 +03:00
|
|
|
urldb_api_add_url_assert_test,
|
2016-08-08 15:42:27 +03:00
|
|
|
6);
|
|
|
|
|
2017-03-14 00:53:42 +03:00
|
|
|
tcase_add_test(tc, urldb_api_url_find_test);
|
|
|
|
|
2016-08-09 15:15:36 +03:00
|
|
|
tcase_add_test(tc, urldb_api_destroy_no_init_test);
|
|
|
|
|
2017-03-14 00:20:47 +03:00
|
|
|
|
2016-08-08 15:42:27 +03:00
|
|
|
return tc;
|
|
|
|
}
|
|
|
|
|
2017-03-13 19:44:30 +03:00
|
|
|
/**
|
|
|
|
* Test suite for url database
|
|
|
|
*/
|
2016-08-09 01:45:01 +03:00
|
|
|
static Suite *urldb_suite_create(void)
|
2016-08-08 15:42:27 +03:00
|
|
|
{
|
|
|
|
Suite *s;
|
|
|
|
s = suite_create("URLDB");
|
|
|
|
|
|
|
|
suite_add_tcase(s, urldb_api_case_create());
|
2017-03-13 23:07:56 +03:00
|
|
|
suite_add_tcase(s, urldb_add_get_case_create());
|
2016-08-08 15:42:27 +03:00
|
|
|
suite_add_tcase(s, urldb_session_case_create());
|
2016-08-09 01:45:01 +03:00
|
|
|
suite_add_tcase(s, urldb_case_create());
|
2016-08-09 12:47:47 +03:00
|
|
|
suite_add_tcase(s, urldb_cookie_case_create());
|
2016-08-08 15:42:27 +03:00
|
|
|
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;
|
|
|
|
}
|