diff options
| author | Garrett D'Amore <garrett@damore.org> | 2020-11-21 22:11:21 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2020-11-23 22:20:12 -0800 |
| commit | d1218d7309475193b53911667911c4f59a1a7752 (patch) | |
| tree | 6ea796998fb60d2cb8afa704faa77fe7fddd644c /src/core/url_test.c | |
| parent | b826bfc171d90f8bde7bd672c0ac14201b8b2742 (diff) | |
| download | nng-d1218d7309475193b53911667911c4f59a1a7752.tar.gz nng-d1218d7309475193b53911667911c4f59a1a7752.tar.bz2 nng-d1218d7309475193b53911667911c4f59a1a7752.zip | |
New NUTS test framework (NNG Unit Test Support).
This is based on testutil/acutest, but is cleaner and fixes some
short-comings. We will be adding more support for additional
common paradigms to better facilitate transport tests.
While here we added some more test cases, and fixed a possible
symbol collision in the the stats framework (due to Linux use
of a macro definition of "si_value" in a standard OS header).
Test coverage may regress slightly as we are no longer using
some of the legacy APIs.
Diffstat (limited to 'src/core/url_test.c')
| -rw-r--r-- | src/core/url_test.c | 489 |
1 files changed, 241 insertions, 248 deletions
diff --git a/src/core/url_test.c b/src/core/url_test.c index 847b7df3..6504ff6c 100644 --- a/src/core/url_test.c +++ b/src/core/url_test.c @@ -1,5 +1,5 @@ // -// Copyright 2018 Staysail Systems, Inc. <info@staysail.tech> +// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> // Copyright 2018 Capitar IT Group BV <info@capitar.com> // // This software is supplied under the terms of the MIT License, a @@ -8,33 +8,26 @@ // found online at https://opensource.org/licenses/MIT. // - -#include "acutest.h" - +#include "nng_impl.h" +#include <nuts.h> #include <string.h> -#include <nng/nng.h> - -#include "core/url.h" - -#include "testutil.h" - void test_url_host(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://www.google.com")); - TEST_ASSERT(url != NULL); - TEST_CHECK(strcmp(url->u_scheme, "http") == 0); - TEST_CHECK(strcmp(url->u_host, "www.google.com") == 0); - TEST_CHECK(strcmp(url->u_hostname, "www.google.com") == 0); - TEST_CHECK(strcmp(url->u_port, "80") == 0); - TEST_CHECK(strcmp(url->u_path, "") == 0); - TEST_CHECK(strcmp(url->u_requri, "") == 0); - TEST_CHECK(url->u_query == NULL); - TEST_CHECK(url->u_fragment == NULL); - TEST_CHECK(url->u_userinfo == NULL); + NUTS_PASS(nng_url_parse(&url, "http://www.google.com")); + NUTS_ASSERT(url != NULL); + NUTS_TRUE(strcmp(url->u_scheme, "http") == 0); + NUTS_TRUE(strcmp(url->u_host, "www.google.com") == 0); + NUTS_TRUE(strcmp(url->u_hostname, "www.google.com") == 0); + NUTS_TRUE(strcmp(url->u_port, "80") == 0); + NUTS_TRUE(strcmp(url->u_path, "") == 0); + NUTS_TRUE(strcmp(url->u_requri, "") == 0); + NUTS_TRUE(url->u_query == NULL); + NUTS_TRUE(url->u_fragment == NULL); + NUTS_TRUE(url->u_userinfo == NULL); nng_url_free(url); } @@ -42,17 +35,17 @@ void test_url_host_port(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://www.google.com:1234")); - TEST_ASSERT(url != NULL); - TEST_CHECK(strcmp(url->u_scheme, "http") == 0); - TEST_CHECK(strcmp(url->u_host, "www.google.com:1234") == 0); - TEST_CHECK(strcmp(url->u_hostname, "www.google.com") == 0); - TEST_CHECK(strcmp(url->u_port, "1234") == 0); - TEST_CHECK(strcmp(url->u_path, "") == 0); - TEST_CHECK(strcmp(url->u_requri, "") == 0); - TEST_CHECK(url->u_query == NULL); - TEST_CHECK(url->u_fragment == NULL); - TEST_CHECK(url->u_userinfo == NULL); + NUTS_PASS(nng_url_parse(&url, "http://www.google.com:1234")); + NUTS_ASSERT(url != NULL); + NUTS_TRUE(strcmp(url->u_scheme, "http") == 0); + NUTS_TRUE(strcmp(url->u_host, "www.google.com:1234") == 0); + NUTS_TRUE(strcmp(url->u_hostname, "www.google.com") == 0); + NUTS_TRUE(strcmp(url->u_port, "1234") == 0); + NUTS_TRUE(strcmp(url->u_path, "") == 0); + NUTS_TRUE(strcmp(url->u_requri, "") == 0); + NUTS_TRUE(url->u_query == NULL); + NUTS_TRUE(url->u_fragment == NULL); + NUTS_TRUE(url->u_userinfo == NULL); nng_url_free(url); } @@ -61,18 +54,18 @@ test_url_host_port_path(void) { nng_url *url; - TEST_NNG_PASS( + NUTS_PASS( nng_url_parse(&url, "http://www.google.com:1234/somewhere")); - TEST_ASSERT(url != NULL); - TEST_CHECK(strcmp(url->u_scheme, "http") == 0); - TEST_CHECK(strcmp(url->u_host, "www.google.com:1234") == 0); - TEST_CHECK(strcmp(url->u_hostname, "www.google.com") == 0); - TEST_CHECK(strcmp(url->u_port, "1234") == 0); - TEST_CHECK(strcmp(url->u_path, "/somewhere") == 0); - TEST_CHECK(strcmp(url->u_requri, "/somewhere") == 0); - TEST_CHECK(url->u_userinfo == NULL); - TEST_CHECK(url->u_query == NULL); - TEST_CHECK(url->u_fragment == NULL); + NUTS_ASSERT(url != NULL); + NUTS_TRUE(strcmp(url->u_scheme, "http") == 0); + NUTS_TRUE(strcmp(url->u_host, "www.google.com:1234") == 0); + NUTS_TRUE(strcmp(url->u_hostname, "www.google.com") == 0); + NUTS_TRUE(strcmp(url->u_port, "1234") == 0); + NUTS_TRUE(strcmp(url->u_path, "/somewhere") == 0); + NUTS_TRUE(strcmp(url->u_requri, "/somewhere") == 0); + NUTS_TRUE(url->u_userinfo == NULL); + NUTS_TRUE(url->u_query == NULL); + NUTS_TRUE(url->u_fragment == NULL); nng_url_free(url); } @@ -80,18 +73,18 @@ void test_url_user_info(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse( + NUTS_PASS(nng_url_parse( &url, "http://garrett@www.google.com:1234/somewhere")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_userinfo, "garrett"); - TEST_STREQUAL(url->u_host, "www.google.com:1234"); - TEST_STREQUAL(url->u_hostname, "www.google.com"); - TEST_STREQUAL(url->u_port, "1234"); - TEST_STREQUAL(url->u_path, "/somewhere"); - TEST_STREQUAL(url->u_requri, "/somewhere"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_userinfo, "garrett"); + NUTS_MATCH(url->u_host, "www.google.com:1234"); + NUTS_MATCH(url->u_hostname, "www.google.com"); + NUTS_MATCH(url->u_port, "1234"); + NUTS_MATCH(url->u_path, "/somewhere"); + NUTS_MATCH(url->u_requri, "/somewhere"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); nng_url_free(url); } @@ -99,18 +92,18 @@ void test_url_path_query_param(void) { nng_url *url; - TEST_NNG_PASS( + NUTS_PASS( nng_url_parse(&url, "http://www.google.com/somewhere?result=yes")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "www.google.com"); - TEST_STREQUAL(url->u_hostname, "www.google.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/somewhere"); - TEST_STREQUAL(url->u_query, "result=yes"); - TEST_STREQUAL(url->u_requri, "/somewhere?result=yes"); - TEST_NULL(url->u_userinfo); - TEST_NULL(url->u_fragment); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "www.google.com"); + NUTS_MATCH(url->u_hostname, "www.google.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/somewhere"); + NUTS_MATCH(url->u_query, "result=yes"); + NUTS_MATCH(url->u_requri, "/somewhere?result=yes"); + NUTS_NULL(url->u_userinfo); + NUTS_NULL(url->u_fragment); nng_url_free(url); } @@ -118,19 +111,19 @@ void test_url_query_param_anchor(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, + NUTS_PASS(nng_url_parse(&url, "http://www.google.com/" "somewhere?result=yes#chapter1")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "www.google.com"); - TEST_STREQUAL(url->u_hostname, "www.google.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/somewhere"); - TEST_STREQUAL(url->u_query, "result=yes"); - TEST_STREQUAL(url->u_fragment, "chapter1"); - TEST_STREQUAL(url->u_requri, "/somewhere?result=yes#chapter1"); - TEST_NULL(url->u_userinfo); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "www.google.com"); + NUTS_MATCH(url->u_hostname, "www.google.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/somewhere"); + NUTS_MATCH(url->u_query, "result=yes"); + NUTS_MATCH(url->u_fragment, "chapter1"); + NUTS_MATCH(url->u_requri, "/somewhere?result=yes#chapter1"); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -138,18 +131,18 @@ void test_url_path_anchor(void) { nng_url *url; - TEST_NNG_PASS( + NUTS_PASS( nng_url_parse(&url, "http://www.google.com/somewhere#chapter2")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "www.google.com"); - TEST_STREQUAL(url->u_hostname, "www.google.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/somewhere"); - TEST_STREQUAL(url->u_fragment, "chapter2"); - TEST_STREQUAL(url->u_requri, "/somewhere#chapter2"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_userinfo); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "www.google.com"); + NUTS_MATCH(url->u_hostname, "www.google.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/somewhere"); + NUTS_MATCH(url->u_fragment, "chapter2"); + NUTS_MATCH(url->u_requri, "/somewhere#chapter2"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -157,17 +150,17 @@ void test_url_anchor(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://www.google.com#chapter3")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "www.google.com"); - TEST_STREQUAL(url->u_hostname, "www.google.com"); - TEST_STREQUAL(url->u_path, ""); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_fragment, "chapter3"); - TEST_STREQUAL(url->u_requri, "#chapter3"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "http://www.google.com#chapter3")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "www.google.com"); + NUTS_MATCH(url->u_hostname, "www.google.com"); + NUTS_MATCH(url->u_path, ""); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_fragment, "chapter3"); + NUTS_MATCH(url->u_requri, "#chapter3"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -175,17 +168,17 @@ void test_url_query_param(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://www.google.com?color=red")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "www.google.com"); - TEST_STREQUAL(url->u_hostname, "www.google.com"); - TEST_STREQUAL(url->u_path, ""); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_query, "color=red"); - TEST_STREQUAL(url->u_requri, "?color=red"); - TEST_ASSERT(url != NULL); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "http://www.google.com?color=red")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "www.google.com"); + NUTS_MATCH(url->u_hostname, "www.google.com"); + NUTS_MATCH(url->u_path, ""); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_query, "color=red"); + NUTS_MATCH(url->u_requri, "?color=red"); + NUTS_ASSERT(url != NULL); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -193,16 +186,16 @@ void test_url_v6_host(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://[::1]")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "[::1]"); - TEST_STREQUAL(url->u_hostname, "::1"); - TEST_STREQUAL(url->u_path, ""); - TEST_STREQUAL(url->u_port, "80"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "http://[::1]")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "[::1]"); + NUTS_MATCH(url->u_hostname, "::1"); + NUTS_MATCH(url->u_path, ""); + NUTS_MATCH(url->u_port, "80"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -210,16 +203,16 @@ void test_url_v6_host_port(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://[::1]:29")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "[::1]:29"); - TEST_STREQUAL(url->u_hostname, "::1"); - TEST_STREQUAL(url->u_path, ""); - TEST_STREQUAL(url->u_port, "29"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "http://[::1]:29")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "[::1]:29"); + NUTS_MATCH(url->u_hostname, "::1"); + NUTS_MATCH(url->u_path, ""); + NUTS_MATCH(url->u_port, "29"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -227,16 +220,16 @@ void test_url_v6_host_port_path(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "http://[::1]:29/bottles")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_host, "[::1]:29"); - TEST_STREQUAL(url->u_hostname, "::1"); - TEST_STREQUAL(url->u_path, "/bottles"); - TEST_STREQUAL(url->u_port, "29"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "http://[::1]:29/bottles")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_host, "[::1]:29"); + NUTS_MATCH(url->u_hostname, "::1"); + NUTS_MATCH(url->u_path, "/bottles"); + NUTS_MATCH(url->u_port, "29"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -244,16 +237,16 @@ void test_url_tcp_port(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "tcp://:9876/")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "tcp"); - TEST_STREQUAL(url->u_host, ":9876"); - TEST_STREQUAL(url->u_hostname, ""); - TEST_STREQUAL(url->u_path, "/"); - TEST_STREQUAL(url->u_port, "9876"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "tcp://:9876/")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "tcp"); + NUTS_MATCH(url->u_host, ":9876"); + NUTS_MATCH(url->u_hostname, ""); + NUTS_MATCH(url->u_path, "/"); + NUTS_MATCH(url->u_port, "9876"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -262,16 +255,16 @@ test_url_bare_ws(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "ws://")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "ws"); - TEST_STREQUAL(url->u_host, ""); - TEST_STREQUAL(url->u_hostname, ""); - TEST_STREQUAL(url->u_path, ""); - TEST_STREQUAL(url->u_port, "80"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "ws://")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "ws"); + NUTS_MATCH(url->u_host, ""); + NUTS_MATCH(url->u_hostname, ""); + NUTS_MATCH(url->u_path, ""); + NUTS_MATCH(url->u_port, "80"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -279,16 +272,16 @@ void test_url_ws_wildcard(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "ws://*:12345/foobar")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "ws"); - TEST_STREQUAL(url->u_host, ":12345"); - TEST_STREQUAL(url->u_hostname, ""); - TEST_STREQUAL(url->u_path, "/foobar"); - TEST_STREQUAL(url->u_port, "12345"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_NULL(url->u_userinfo); + NUTS_PASS(nng_url_parse(&url, "ws://*:12345/foobar")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "ws"); + NUTS_MATCH(url->u_host, ":12345"); + NUTS_MATCH(url->u_hostname, ""); + NUTS_MATCH(url->u_path, "/foobar"); + NUTS_MATCH(url->u_port, "12345"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_NULL(url->u_userinfo); nng_url_free(url); } @@ -296,16 +289,16 @@ void test_url_ssh(void) { nng_url *url; - TEST_NNG_PASS(nng_url_parse(&url, "ssh://user@host.example.com")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "ssh"); - TEST_STREQUAL(url->u_host, "host.example.com"); - TEST_STREQUAL(url->u_hostname, "host.example.com"); - TEST_STREQUAL(url->u_path, ""); - TEST_STREQUAL(url->u_port, "22"); - TEST_NULL(url->u_query); - TEST_NULL(url->u_fragment); - TEST_STREQUAL(url->u_userinfo, "user"); + NUTS_PASS(nng_url_parse(&url, "ssh://user@host.example.com")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "ssh"); + NUTS_MATCH(url->u_host, "host.example.com"); + NUTS_MATCH(url->u_hostname, "host.example.com"); + NUTS_MATCH(url->u_path, ""); + NUTS_MATCH(url->u_port, "22"); + NUTS_NULL(url->u_query); + NUTS_NULL(url->u_fragment); + NUTS_MATCH(url->u_userinfo, "user"); nng_url_free(url); } @@ -313,33 +306,33 @@ void test_url_bad_scheme(void) { nng_url *url = NULL; - TEST_NNG_FAIL(nng_url_parse(&url, "www.google.com"), NNG_EINVAL); - TEST_NULL(url); - TEST_NNG_FAIL(nng_url_parse(&url, "http:www.google.com"), NNG_EINVAL); - TEST_NULL(url); + NUTS_FAIL(nng_url_parse(&url, "www.google.com"), NNG_EINVAL); + NUTS_NULL(url); + NUTS_FAIL(nng_url_parse(&url, "http:www.google.com"), NNG_EINVAL); + NUTS_NULL(url); } void test_url_bad_ipv6(void) { nng_url *url = NULL; - TEST_NNG_FAIL(nng_url_parse(&url, "http://[::1"), NNG_EINVAL); - TEST_NULL(url); - TEST_NNG_FAIL(nng_url_parse(&url, "http://[::1]bogus"), NNG_EINVAL); - TEST_NULL(url); + NUTS_FAIL(nng_url_parse(&url, "http://[::1"), NNG_EINVAL); + NUTS_NULL(url); + NUTS_FAIL(nng_url_parse(&url, "http://[::1]bogus"), NNG_EINVAL); + NUTS_NULL(url); } void test_url_canonify(void) { nng_url *url = NULL; - TEST_NNG_PASS(nng_url_parse( + NUTS_PASS(nng_url_parse( &url, "hTTp://www.EXAMPLE.com/bogus/.%2e/%7egarrett")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_hostname, "www.example.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/~garrett"); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_hostname, "www.example.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/~garrett"); nng_url_free(url); } @@ -347,12 +340,12 @@ void test_url_path_resolve(void) { nng_url *url = NULL; - TEST_NNG_PASS( + NUTS_PASS( nng_url_parse(&url, "http://www.x.com//abc/def/./x/..///./../y")); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_hostname, "www.x.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/abc/y"); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_hostname, "www.x.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/abc/y"); nng_url_free(url); } @@ -360,14 +353,14 @@ void test_url_query_info_pass(void) { nng_url *url = NULL; - TEST_NNG_PASS( + NUTS_PASS( nng_url_parse(&url, "http://www.x.com/?/abc/def/./x/.././../y")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_hostname, "www.x.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/"); - TEST_STREQUAL(url->u_query, "/abc/def/./x/.././../y"); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_hostname, "www.x.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/"); + NUTS_MATCH(url->u_query, "/abc/def/./x/.././../y"); nng_url_free(url); } @@ -375,22 +368,22 @@ void test_url_bad_utf8(void) { nng_url *url = NULL; - TEST_NNG_FAIL(nng_url_parse(&url, "http://x.com/x%80x"), NNG_EINVAL); - TEST_NULL(url); - TEST_NNG_FAIL(nng_url_parse(&url, "http://x.com/x%c0%81"), NNG_EINVAL); - TEST_NULL(url); + NUTS_FAIL(nng_url_parse(&url, "http://x.com/x%80x"), NNG_EINVAL); + NUTS_NULL(url); + NUTS_FAIL(nng_url_parse(&url, "http://x.com/x%c0%81"), NNG_EINVAL); + NUTS_NULL(url); } void test_url_good_utf8(void) { nng_url *url = NULL; - TEST_NNG_PASS(nng_url_parse(&url, "http://www.x.com/%c2%a2_cents")); - TEST_ASSERT(url != NULL); - TEST_STREQUAL(url->u_scheme, "http"); - TEST_STREQUAL(url->u_hostname, "www.x.com"); - TEST_STREQUAL(url->u_port, "80"); - TEST_STREQUAL(url->u_path, "/\xc2\xa2_cents"); + NUTS_PASS(nng_url_parse(&url, "http://www.x.com/%c2%a2_cents")); + NUTS_ASSERT(url != NULL); + NUTS_MATCH(url->u_scheme, "http"); + NUTS_MATCH(url->u_hostname, "www.x.com"); + NUTS_MATCH(url->u_port, "80"); + NUTS_MATCH(url->u_path, "/\xc2\xa2_cents"); nng_url_free(url); } @@ -402,55 +395,55 @@ test_url_decode(void) out[3] = 'x'; len = nni_url_decode(out, "abc", 3); - TEST_CHECK(len == 3); - TEST_CHECK(memcmp(out, "abc", 3) == 0); - TEST_CHECK(out[3] == 'x'); + NUTS_TRUE(len == 3); + NUTS_TRUE(memcmp(out, "abc", 3) == 0); + NUTS_TRUE(out[3] == 'x'); len = nni_url_decode(out, "x%00y", 3); // embedded NULL - TEST_CHECK(len == 3); - TEST_CHECK(memcmp(out, "x\x00y", 3) == 0); - TEST_CHECK(out[3] == 'x'); + NUTS_TRUE(len == 3); + NUTS_TRUE(memcmp(out, "x\x00y", 3) == 0); + NUTS_TRUE(out[3] == 'x'); len = nni_url_decode(out, "%3987", 3); - TEST_CHECK(len == 3); - TEST_CHECK(memcmp(out, "987", 3) == 0); - TEST_CHECK(out[3] == 'x'); + NUTS_TRUE(len == 3); + NUTS_TRUE(memcmp(out, "987", 3) == 0); + NUTS_TRUE(out[3] == 'x'); len = nni_url_decode(out, "78%39", 3); - TEST_CHECK(len == 3); - TEST_CHECK(memcmp(out, "789", 3) == 0); - TEST_CHECK(out[3] == 'x'); + NUTS_TRUE(len == 3); + NUTS_TRUE(memcmp(out, "789", 3) == 0); + NUTS_TRUE(out[3] == 'x'); - len = nni_url_decode(out, "", 5); - TEST_CHECK(len == 0); - TEST_CHECK(memcmp(out, "789", 3) == 0); - TEST_CHECK(out[3] == 'x'); + len = nni_url_decode(out, "", 5); + NUTS_TRUE(len == 0); + NUTS_TRUE(memcmp(out, "789", 3) == 0); + NUTS_TRUE(out[3] == 'x'); - len = nni_url_decode(out, "be", 2); - TEST_CHECK(len == 2); - TEST_CHECK(memcmp(out, "be9", 3) == 0); - TEST_CHECK(out[3] == 'x'); + len = nni_url_decode(out, "be", 2); + NUTS_TRUE(len == 2); + NUTS_TRUE(memcmp(out, "be9", 3) == 0); + NUTS_TRUE(out[3] == 'x'); - len = nni_url_decode(out, "78%39", 2); - TEST_CHECK(len == (size_t) -1); + len = nni_url_decode(out, "78%39", 2); + NUTS_TRUE(len == (size_t) -1); - len = nni_url_decode(out, "", 2); - TEST_CHECK(len == 0); + len = nni_url_decode(out, "", 2); + NUTS_TRUE(len == 0); - len = nni_url_decode(out, "78%", 5); - TEST_CHECK(len == (size_t) -1); + len = nni_url_decode(out, "78%", 5); + NUTS_TRUE(len == (size_t) -1); - len = nni_url_decode(out, "78%xy", 5); - TEST_CHECK(len == (size_t) -1); + len = nni_url_decode(out, "78%xy", 5); + NUTS_TRUE(len == (size_t) -1); - len = nni_url_decode(out, "78%1$", 5); - TEST_CHECK(len == (size_t) -1); + len = nni_url_decode(out, "78%1$", 5); + NUTS_TRUE(len == (size_t) -1); - len = nni_url_decode(out, "%%20", 5); - TEST_CHECK(len == (size_t) -1); + len = nni_url_decode(out, "%%20", 5); + NUTS_TRUE(len == (size_t) -1); } -TEST_LIST = { +NUTS_TESTS = { { "url host", test_url_host }, { "url host port", test_url_host_port }, { "url host port path", test_url_host_port_path }, |
