Fix warnings in unit tests

This commit is contained in:
Vincent Sanders 2016-08-08 22:12:16 +01:00
parent 1158536bff
commit 4448fa6cbf
6 changed files with 75 additions and 69 deletions

View File

@ -145,7 +145,7 @@ END_TEST
/* Suite */
Suite *bloom_suite(void)
static Suite *bloom_suite(void)
{
Suite *s;
TCase *tc_create;

View File

@ -56,7 +56,7 @@ static const struct test_pairs match_tests[] = {
static void match_hashtable_create(void)
{
int idx;
unsigned int idx;
match_hash_a = hash_create(79);
ck_assert(match_hash_a != NULL);
@ -246,7 +246,7 @@ END_TEST
/* Suite */
Suite *hashtable_suite(void)
static Suite *hashtable_suite(void)
{
Suite *s;
TCase *tc_create;

View File

@ -41,7 +41,7 @@ const char *test_messages_path = "test/data/Messages";
struct message_test_vec_s {
int test;
char *res;
const char *res;
};
struct message_test_vec_s message_errorcode_test_vec[] = {
@ -101,7 +101,7 @@ START_TEST(message_file_load_test)
}
END_TEST
TCase *message_session_case_create(void)
static TCase *message_session_case_create(void)
{
TCase *tc;
tc = tcase_create("Message adding");
@ -115,7 +115,7 @@ TCase *message_session_case_create(void)
}
Suite *message_suite_create(void)
static Suite *message_suite_create(void)
{
Suite *s;
s = suite_create("message");

View File

@ -40,7 +40,7 @@ const char *test_choices_full_path = "test/data/Choices-full";
const char *test_choices_missing_path = "test/data/Choices-missing";
nserror gui_options_init_defaults(struct nsoption_s *defaults)
static nserror gui_options_init_defaults(struct nsoption_s *defaults)
{
/* Set defaults for absent option strings */
nsoption_setnull_charp(ca_bundle, strdup("NetSurf:Resources.ca-bundle"));
@ -134,7 +134,9 @@ START_TEST(nsoption_session_test)
{
nserror res;
int argc = 2;
char *argv[] = { "nsoption", "--http_proxy_host=fooo", NULL};
char arg1[] = "nsoption";
char arg2[] = "--http_proxy_host=fooo";
char *argv[] = { arg1, arg2, NULL};
char *outnam;
res = nsoption_init(gui_options_init_defaults, NULL, NULL);
@ -173,7 +175,7 @@ START_TEST(nsoption_session_test)
}
END_TEST
TCase *nsoption_session_case_create(void)
static TCase *nsoption_session_case_create(void)
{
TCase *tc;
tc = tcase_create("Full session");
@ -263,7 +265,7 @@ END_TEST
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
TCase *nsoption_format_case_create(void)
static TCase *nsoption_format_case_create(void)
{
TCase *tc;
tc = tcase_create("Formatted output");
@ -366,13 +368,11 @@ START_TEST(nsoption_commandline_test)
{
nserror res;
int argc = 4;
char *argv[] = {
"nsoption",
"--http_proxy_host=fooo",
"--http_proxy_port",
"not-option",
NULL
};
char arg1[] = "nsoption";
char arg2[] = "--http_proxy_host=fooo";
char arg3[] = "--http_proxy_port";
char arg4[] = "not-option";
char *argv[] = { arg1, arg2, arg3, arg4, NULL};
/* commandline */
res = nsoption_commandline(&argc, &argv[0], NULL);
@ -383,7 +383,7 @@ START_TEST(nsoption_commandline_test)
}
END_TEST
TCase *nsoption_case_create(void)
static TCase *nsoption_case_create(void)
{
TCase *tc;
tc = tcase_create("File operations");
@ -508,7 +508,9 @@ START_TEST(nsoption_api_commandline_no_args_test)
{
nserror res;
int argc = 2;
char *argv[] = { "nsoption", "--http_proxy_host=fooo", NULL};
char arg1[] = "nsoption";
char arg2[] = "--http_proxy_host=fooo";
char *argv[] = { arg1, arg2, NULL};
/* commandline with no argument count or init */
res = nsoption_commandline(NULL, &argv[0], NULL);
@ -527,7 +529,9 @@ START_TEST(nsoption_api_commandline_no_init_test)
{
nserror res;
int argc = 2;
char *argv[] = { "nsoption", "--http_proxy_host=fooo", NULL};
char arg1[] = "nsoption";
char arg2[] = "--http_proxy_host=fooo";
char *argv[] = { arg1, arg2, NULL};
/* write with path but no init */
res = nsoption_commandline(&argc, &argv[0], NULL);
@ -633,7 +637,7 @@ START_TEST(nsoption_api_snoptionf_no_init_test)
END_TEST
TCase *nsoption_api_case_create(void)
static TCase *nsoption_api_case_create(void)
{
TCase *tc;
tc = tcase_create("API checks");
@ -659,7 +663,7 @@ TCase *nsoption_api_case_create(void)
}
Suite *nsoption_suite_create(void)
static Suite *nsoption_suite_create(void)
{
Suite *s;
s = suite_create("User options");

View File

@ -36,6 +36,7 @@
#include "utils/nsurl.h"
#include "netsurf/url_db.h"
#include "content/urldb.h"
#include "desktop/cookie_manager.h"
const char *test_urldb_path = "test/data/urldb";
@ -261,108 +262,108 @@ START_TEST(urldb_original_test)
/* Mantis bug #993 */
url = make_url("http:moodle.org");
assert(urldb_add_url(url) == true);
assert(urldb_get_url(url) != NULL);
ck_assert(urldb_add_url(url) == true);
ck_assert(urldb_get_url(url) != NULL);
nsurl_unref(url);
/* Mantis bug #993 */
url = make_url("http://a_a/");
assert(urldb_add_url(url));
assert(urldb_get_url(url));
ck_assert(urldb_add_url(url));
ck_assert(urldb_get_url(url));
nsurl_unref(url);
/* Mantis bug #996 */
url = make_url("http://foo@moose.com/");
if (urldb_add_url(url)) {
LOG("added %s", nsurl_access(url));
assert(urldb_get_url(url) != NULL);
ck_assert(urldb_get_url(url) != NULL);
}
nsurl_unref(url);
/* Mantis bug #913 */
url = make_url("http://www2.2checkout.com/");
assert(urldb_add_url(url));
assert(urldb_get_url(url));
ck_assert(urldb_add_url(url));
ck_assert(urldb_get_url(url));
nsurl_unref(url);
/* Numeric subdomains */
url = make_url("http://2.bp.blogspot.com/_448y6kVhntg/TSekubcLJ7I/AAAAAAAAHJE/yZTsV5xT5t4/s1600/covers.jpg");
assert(urldb_add_url(url));
assert(urldb_get_url(url));
ck_assert(urldb_add_url(url));
ck_assert(urldb_get_url(url));
nsurl_unref(url);
/* Valid path */
assert(test_urldb_set_cookie("name=value;Path=/\r\n", "http://www.google.com/", NULL));
ck_assert(test_urldb_set_cookie("name=value;Path=/\r\n", "http://www.google.com/", NULL));
/* Valid path (non-root directory) */
assert(test_urldb_set_cookie("name=value;Path=/foo/bar/\r\n", "http://www.example.org/foo/bar/", NULL));
ck_assert(test_urldb_set_cookie("name=value;Path=/foo/bar/\r\n", "http://www.example.org/foo/bar/", NULL));
/* Defaulted path */
assert(test_urldb_set_cookie("name=value\r\n", "http://www.example.org/foo/bar/baz/bat.html", NULL));
assert(test_urldb_get_cookie("http://www.example.org/foo/bar/baz/quux.htm"));
ck_assert(test_urldb_set_cookie("name=value\r\n", "http://www.example.org/foo/bar/baz/bat.html", NULL));
ck_assert(test_urldb_get_cookie("http://www.example.org/foo/bar/baz/quux.htm"));
/* Defaulted path with no non-leaf path segments */
assert(test_urldb_set_cookie("name=value\r\n", "http://no-non-leaf.example.org/index.html", NULL));
assert(test_urldb_get_cookie("http://no-non-leaf.example.org/page2.html"));
assert(test_urldb_get_cookie("http://no-non-leaf.example.org/"));
ck_assert(test_urldb_set_cookie("name=value\r\n", "http://no-non-leaf.example.org/index.html", NULL));
ck_assert(test_urldb_get_cookie("http://no-non-leaf.example.org/page2.html"));
ck_assert(test_urldb_get_cookie("http://no-non-leaf.example.org/"));
/* Valid path (includes leafname) */
assert(test_urldb_set_cookie("name=value;Version=1;Path=/index.cgi\r\n", "http://example.org/index.cgi", NULL));
assert(test_urldb_get_cookie("http://example.org/index.cgi"));
ck_assert(test_urldb_set_cookie("name=value;Version=1;Path=/index.cgi\r\n", "http://example.org/index.cgi", NULL));
ck_assert(test_urldb_get_cookie("http://example.org/index.cgi"));
/* Valid path (includes leafname in non-root directory) */
assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/foo/index.html", NULL));
ck_assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/foo/index.html", NULL));
/* Should _not_ match the above, as the leafnames differ */
assert(test_urldb_get_cookie("http://www.example.org/foo/bar.html") == NULL);
ck_assert(test_urldb_get_cookie("http://www.example.org/foo/bar.html") == NULL);
/* Invalid path (contains different leafname) */
assert(test_urldb_set_cookie("name=value;Path=/index.html\r\n", "http://example.org/index.htm", NULL) == false);
ck_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);
ck_assert(test_urldb_set_cookie("name=value;Path=/foo/index.html\r\n", "http://www.example.org/bar/index.html", NULL) == false);
/* Test partial domain match with IP address failing */
assert(test_urldb_set_cookie("name=value;Domain=.foo.org\r\n", "http://192.168.0.1/", NULL) == false);
ck_assert(test_urldb_set_cookie("name=value;Domain=.foo.org\r\n", "http://192.168.0.1/", NULL) == false);
/* Test handling of non-domain cookie sent by server (domain part should
* be ignored) */
assert(test_urldb_set_cookie("foo=value;Domain=blah.com\r\n", "http://www.example.com/", NULL));
assert(strcmp(test_urldb_get_cookie("http://www.example.com/"), "foo=value") == 0);
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);
/* Test handling of domain cookie from wrong host (strictly invalid but
* required to support the real world) */
assert(test_urldb_set_cookie("name=value;Domain=.example.com\r\n", "http://foo.bar.example.com/", NULL));
assert(strcmp(test_urldb_get_cookie("http://www.example.com/"), "foo=value; name=value") == 0);
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);
/* Test presence of separators in cookie value */
assert(test_urldb_set_cookie("name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\";Version=1\r\n", "http://www.example.org/", NULL));
assert(strcmp(test_urldb_get_cookie("http://www.example.org/"), "$Version=1; name=\"value=foo\\\\bar\\\\\\\";\\\\baz=quux\"") == 0);
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);
/* Test cookie with blank value */
assert(test_urldb_set_cookie("a=\r\n", "http://www.example.net/", NULL));
assert(strcmp(test_urldb_get_cookie("http://www.example.net/"), "a=") == 0);
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);
/* Test specification of multiple cookies in one header */
assert(test_urldb_set_cookie("a=b, foo=bar; Path=/\r\n", "http://www.example.net/", NULL));
assert(strcmp(test_urldb_get_cookie("http://www.example.net/"), "a=b; foo=bar") == 0);
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);
/* Test use of separators in unquoted cookie value */
assert(test_urldb_set_cookie("foo=moo@foo:blah?moar\\ text\r\n", "http://example.com/", NULL));
assert(strcmp(test_urldb_get_cookie("http://example.com/"), "foo=moo@foo:blah?moar\\ text; name=value") == 0);
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);
/* Test use of unnecessary quotes */
assert(test_urldb_set_cookie("foo=\"hello\";Version=1,bar=bat\r\n", "http://example.com/", NULL));
assert(strcmp(test_urldb_get_cookie("http://example.com/"), "foo=\"hello\"; bar=bat; name=value") == 0);
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);
/* Test domain matching in unverifiable transactions */
assert(test_urldb_set_cookie("foo=bar; domain=.example.tld\r\n", "http://www.foo.example.tld/", "http://bar.example.tld/"));
assert(strcmp(test_urldb_get_cookie("http://www.foo.example.tld/"), "foo=bar") == 0);
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);
/* Test expiry */
assert(test_urldb_set_cookie("foo=bar", "http://expires.com/", NULL));
assert(strcmp(test_urldb_get_cookie("http://expires.com/"), "foo=bar") == 0);
assert(test_urldb_set_cookie("foo=bar; expires=Thu, 01-Jan-1970 00:00:01 GMT\r\n", "http://expires.com/", NULL));
assert(test_urldb_get_cookie("http://expires.com/") == NULL);
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);
urldb_dump();
urldb_destroy();

View File

@ -27,7 +27,8 @@
* \note Earlier RFC (2396, 1738 and 1630) list the tilde ~ character
* as reserved so its handling is ambiguious
*
* \todo The url_escape should be tested for application/x-www-form-urlencoded type operation
* \todo The url_escape should be tested for application/x-www-form-urlencoded
* type operation
*/
#include <assert.h>
@ -148,7 +149,7 @@ START_TEST(url_escape_api_nullparam_test)
}
END_TEST
TCase *url_escape_case_create(void)
static TCase *url_escape_case_create(void)
{
TCase *tc;
tc = tcase_create("Escape");
@ -268,7 +269,7 @@ START_TEST(url_unescape_api_nullparam_test)
END_TEST
TCase *url_unescape_case_create(void)
static TCase *url_unescape_case_create(void)
{
TCase *tc;
tc = tcase_create("Unescape");
@ -287,7 +288,7 @@ TCase *url_unescape_case_create(void)
}
Suite *urlescape_suite_create(void)
static Suite *urlescape_suite_create(void)
{
Suite *s;
s = suite_create("Percent escaping");