diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/url.c | 95 |
1 files changed, 46 insertions, 49 deletions
diff --git a/tests/url.c b/tests/url.c index dba0664b..a4b4457b 100644 --- a/tests/url.c +++ b/tests/url.c @@ -12,17 +12,14 @@ #include "convey.h" -#include "core/nng_impl.h" -#include "core/url.h" - -//#include "stubs.h" +#include "nng.h" TestMain("URLs", { - nni_url *url; + nng_url *url; Convey("http://www.google.com", { - So(nni_url_parse(&url, "http://www.google.com") == 0); + So(nng_url_parse(&url, "http://www.google.com") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_host, "www.google.com") == 0); @@ -33,11 +30,11 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com:1234", { - So(nni_url_parse(&url, "http://www.google.com:1234") == 0); + So(nng_url_parse(&url, "http://www.google.com:1234") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_host, "www.google.com:1234") == 0); @@ -48,11 +45,11 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com:1234/somewhere", { - So(nni_url_parse( + So(nng_url_parse( &url, "http://www.google.com:1234/somewhere") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); @@ -64,10 +61,10 @@ TestMain("URLs", { So(url->u_userinfo == NULL); So(url->u_query == NULL); So(url->u_fragment == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://garrett@www.google.com:1234/somewhere", { - So(nni_url_parse(&url, + So(nng_url_parse(&url, "http://garrett@www.google.com:1234/somewhere") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); @@ -79,10 +76,10 @@ TestMain("URLs", { So(strcmp(url->u_rawpath, "/somewhere") == 0); So(url->u_query == NULL); So(url->u_fragment == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com/somewhere?result=yes", { - So(nni_url_parse(&url, + So(nng_url_parse(&url, "http://www.google.com/somewhere?result=yes") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); @@ -94,10 +91,10 @@ TestMain("URLs", { So(strcmp(url->u_rawpath, "/somewhere?result=yes") == 0); So(url->u_userinfo == NULL); So(url->u_fragment == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com/somewhere?result=yes#chapter1", { - So(nni_url_parse(&url, + So(nng_url_parse(&url, "http://www.google.com/" "somewhere?result=yes#chapter1") == 0); So(url != NULL); @@ -111,10 +108,10 @@ TestMain("URLs", { So(strcmp(url->u_rawpath, "/somewhere?result=yes#chapter1") == 0); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com/somewhere#chapter2", { - So(nni_url_parse( + So(nng_url_parse( &url, "http://www.google.com/somewhere#chapter2") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); @@ -126,10 +123,10 @@ TestMain("URLs", { So(strcmp(url->u_rawpath, "/somewhere#chapter2") == 0); So(url->u_query == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com#chapter3", { - So(nni_url_parse(&url, "http://www.google.com#chapter3") == 0); + So(nng_url_parse(&url, "http://www.google.com#chapter3") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_host, "www.google.com") == 0); @@ -140,10 +137,10 @@ TestMain("URLs", { So(strcmp(url->u_rawpath, "#chapter3") == 0); So(url->u_query == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://www.google.com?color=red", { - So(nni_url_parse(&url, "http://www.google.com?color=red") == + So(nng_url_parse(&url, "http://www.google.com?color=red") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); @@ -155,11 +152,11 @@ TestMain("URLs", { So(strcmp(url->u_rawpath, "?color=red") == 0); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://[::1]", { - So(nni_url_parse(&url, "http://[::1]") == 0); + So(nng_url_parse(&url, "http://[::1]") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_host, "[::1]") == 0); @@ -169,11 +166,11 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://[::1]:29", { - So(nni_url_parse(&url, "http://[::1]:29") == 0); + So(nng_url_parse(&url, "http://[::1]:29") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_host, "[::1]:29") == 0); @@ -183,10 +180,10 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("http://[::1]:29/bottles", { - So(nni_url_parse(&url, "http://[::1]:29/bottles") == 0); + So(nng_url_parse(&url, "http://[::1]:29/bottles") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_host, "[::1]:29") == 0); @@ -196,11 +193,11 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("tcp://:9876/", { - So(nni_url_parse(&url, "tcp://:9876/") == 0); + So(nng_url_parse(&url, "tcp://:9876/") == 0); So(url != NULL); So(strcmp(url->u_scheme, "tcp") == 0); So(strcmp(url->u_host, ":9876") == 0); @@ -210,11 +207,11 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("ws://", { - So(nni_url_parse(&url, "ws://") == 0); + So(nng_url_parse(&url, "ws://") == 0); So(url != NULL); So(strcmp(url->u_scheme, "ws") == 0); So(strcmp(url->u_host, "") == 0); @@ -224,11 +221,11 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(url->u_userinfo == NULL); - nni_url_free(url); + nng_url_free(url); }); Convey("ssh://user@host.example.com", { - So(nni_url_parse(&url, "ssh://user@host.example.com") == 0); + So(nng_url_parse(&url, "ssh://user@host.example.com") == 0); So(url != NULL); So(strcmp(url->u_scheme, "ssh") == 0); So(strcmp(url->u_host, "host.example.com") == 0); @@ -238,60 +235,60 @@ TestMain("URLs", { So(url->u_query == NULL); So(url->u_fragment == NULL); So(strcmp(url->u_userinfo, "user") == 0); - nni_url_free(url); + nng_url_free(url); }); Convey("Negative www.google.com", { url = NULL; - So(nni_url_parse(&url, "www.google.com") == NNG_EINVAL); + So(nng_url_parse(&url, "www.google.com") == NNG_EINVAL); So(url == NULL); }); Convey("Negative http:www.google.com", { url = NULL; - So(nni_url_parse(&url, "http:www.google.com") == NNG_EINVAL); + So(nng_url_parse(&url, "http:www.google.com") == NNG_EINVAL); So(url == NULL); }); Convey("Negative http://[::1", { url = NULL; - So(nni_url_parse(&url, "http://[::1") == NNG_EINVAL); + So(nng_url_parse(&url, "http://[::1") == NNG_EINVAL); So(url == NULL); }); Convey("Negative http://[::1]bogus", { url = NULL; - So(nni_url_parse(&url, "http://[::1]bogus") == NNG_EINVAL); + So(nng_url_parse(&url, "http://[::1]bogus") == NNG_EINVAL); So(url == NULL); }); Convey("Canonicalization works", { url = NULL; - So(nni_url_parse(&url, + So(nng_url_parse(&url, "hTTp://www.EXAMPLE.com/bogus/.%2e/%7egarrett") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_hostname, "www.example.com") == 0); So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "/~garrett") == 0); - nni_url_free(url); + nng_url_free(url); }); Convey("Path resolution works", { url = NULL; - So(nni_url_parse(&url, + So(nng_url_parse(&url, "http://www.x.com//abc/def/./x/..///./../y") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_hostname, "www.x.com") == 0); So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "/abc/y") == 0); - nni_url_free(url); + nng_url_free(url); }); Convey("Query info unmolested", { url = NULL; - So(nni_url_parse( + So(nng_url_parse( &url, "http://www.x.com/?/abc/def/./x/.././../y") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); @@ -299,25 +296,25 @@ TestMain("URLs", { So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "/") == 0); So(strcmp(url->u_query, "/abc/def/./x/.././../y") == 0); - nni_url_free(url); + nng_url_free(url); }); Convey("Bad UTF-8 fails", { url = NULL; - So(nni_url_parse(&url, "http://x.com/x%80x") == NNG_EINVAL); - So(nni_url_parse(&url, "http://x.com/x%c0%81") == NNG_EINVAL); + So(nng_url_parse(&url, "http://x.com/x%80x") == NNG_EINVAL); + So(nng_url_parse(&url, "http://x.com/x%c0%81") == NNG_EINVAL); }); Convey("Valid UTF-8 works", { url = NULL; - So(nni_url_parse(&url, "http://www.x.com/%c2%a2_centsign") == + So(nng_url_parse(&url, "http://www.x.com/%c2%a2_centsign") == 0); So(url != NULL); So(strcmp(url->u_scheme, "http") == 0); So(strcmp(url->u_hostname, "www.x.com") == 0); So(strcmp(url->u_port, "80") == 0); So(strcmp(url->u_path, "/\xc2\xa2_centsign") == 0); - nni_url_free(url); + nng_url_free(url); }); }) |
