summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-01-05 14:44:10 -0800
committerGarrett D'Amore <garrett@damore.org>2018-01-05 15:17:27 -0800
commit1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f (patch)
tree95fc90338cbe38a46e561511604cf8ed079934fd /tests
parent224dae56a379aa309fca261d61e7e356b14a536f (diff)
downloadnng-1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f.tar.gz
nng-1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f.tar.bz2
nng-1b2f22fd68a2e50cabdfe2e036096cc9e7a05a1f.zip
Convert existing websocket and http code to use new URL framework.
This also fixes a use-after-free bug in the HTTP framework, where the handler could be deleted why callbacks were still using it. (We now reference count the handlers.)
Diffstat (limited to 'tests')
-rw-r--r--tests/tcp.c48
-rw-r--r--tests/url.c10
-rw-r--r--tests/ws.c4
-rw-r--r--tests/wss.c4
4 files changed, 35 insertions, 31 deletions
diff --git a/tests/tcp.c b/tests/tcp.c
index fdcf458c..5860eb03 100644
--- a/tests/tcp.c
+++ b/tests/tcp.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 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
// copy of which should be located in the distribution where this
@@ -23,31 +23,27 @@
static int
check_props_v4(nng_msg *msg, nng_listener l, nng_dialer d)
{
- nng_pipe p;
- size_t z;
+ nng_pipe p;
+ size_t z;
+ nng_sockaddr la;
+ nng_sockaddr ra;
+
p = nng_msg_get_pipe(msg);
So(p > 0);
-
- Convey("Local address property works", {
- nng_sockaddr la;
- z = sizeof(nng_sockaddr);
- So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0);
- So(z == sizeof(la));
- So(la.s_un.s_family == NNG_AF_INET);
- So(la.s_un.s_in.sa_port == htons(trantest_port - 1));
- So(la.s_un.s_in.sa_port != 0);
- So(la.s_un.s_in.sa_addr == htonl(0x7f000001));
- });
-
- Convey("Remote address property works", {
- nng_sockaddr ra;
- z = sizeof(nng_sockaddr);
- So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0);
- So(z == sizeof(ra));
- So(ra.s_un.s_family == NNG_AF_INET);
- So(ra.s_un.s_in.sa_port != 0);
- So(ra.s_un.s_in.sa_addr == htonl(0x7f000001));
- });
+ z = sizeof(nng_sockaddr);
+ So(nng_pipe_getopt(p, NNG_OPT_LOCADDR, &la, &z) == 0);
+ So(z == sizeof(la));
+ So(la.s_un.s_family == NNG_AF_INET);
+ So(la.s_un.s_in.sa_port == htons(trantest_port - 1));
+ So(la.s_un.s_in.sa_port != 0);
+ So(la.s_un.s_in.sa_addr == htonl(0x7f000001));
+
+ z = sizeof(nng_sockaddr);
+ So(nng_pipe_getopt(p, NNG_OPT_REMADDR, &ra, &z) == 0);
+ So(z == sizeof(ra));
+ So(ra.s_un.s_family == NNG_AF_INET);
+ So(ra.s_un.s_in.sa_port != 0);
+ So(ra.s_un.s_in.sa_addr == htonl(0x7f000001));
return (0);
}
@@ -94,8 +90,6 @@ TestMain("TCP Transport", {
NNG_EADDRINVAL);
So(nng_dial(s1, "tcp://127.0.x.1.32", NULL, 0) ==
NNG_EADDRINVAL);
- So(nng_listen(s1, "tcp://127.0.0.1", NULL, 0) ==
- NNG_EADDRINVAL);
So(nng_listen(s1, "tcp://127.0.0.1.32", NULL, 0) ==
NNG_EADDRINVAL);
So(nng_listen(s1, "tcp://127.0.x.1.32", NULL, 0) ==
diff --git a/tests/url.c b/tests/url.c
index 019a1519..6fb35596 100644
--- a/tests/url.c
+++ b/tests/url.c
@@ -29,6 +29,7 @@ TestMain("URLs", {
So(strcmp(url->u_hostname, "www.google.com") == 0);
So(strcmp(url->u_port, "") == 0);
So(strcmp(url->u_path, "") == 0);
+ So(strcmp(url->u_rawpath, "") == 0);
So(url->u_query == NULL);
So(url->u_fragment == NULL);
So(url->u_userinfo == NULL);
@@ -43,6 +44,7 @@ TestMain("URLs", {
So(strcmp(url->u_hostname, "www.google.com") == 0);
So(strcmp(url->u_port, "1234") == 0);
So(strcmp(url->u_path, "") == 0);
+ So(strcmp(url->u_rawpath, "") == 0);
So(url->u_query == NULL);
So(url->u_fragment == NULL);
So(url->u_userinfo == NULL);
@@ -58,6 +60,7 @@ TestMain("URLs", {
So(strcmp(url->u_hostname, "www.google.com") == 0);
So(strcmp(url->u_port, "1234") == 0);
So(strcmp(url->u_path, "/somewhere") == 0);
+ So(strcmp(url->u_rawpath, "/somewhere") == 0);
So(url->u_userinfo == NULL);
So(url->u_query == NULL);
So(url->u_fragment == NULL);
@@ -73,6 +76,7 @@ TestMain("URLs", {
So(strcmp(url->u_hostname, "www.google.com") == 0);
So(strcmp(url->u_port, "1234") == 0);
So(strcmp(url->u_path, "/somewhere") == 0);
+ So(strcmp(url->u_rawpath, "/somewhere") == 0);
So(url->u_query == NULL);
So(url->u_fragment == NULL);
nni_url_free(url);
@@ -87,6 +91,7 @@ TestMain("URLs", {
So(strcmp(url->u_port, "") == 0);
So(strcmp(url->u_path, "/somewhere") == 0);
So(strcmp(url->u_query, "result=yes") == 0);
+ So(strcmp(url->u_rawpath, "/somewhere?result=yes") == 0);
So(url->u_userinfo == NULL);
So(url->u_fragment == NULL);
nni_url_free(url);
@@ -103,6 +108,8 @@ TestMain("URLs", {
So(strcmp(url->u_path, "/somewhere") == 0);
So(strcmp(url->u_query, "result=yes") == 0);
So(strcmp(url->u_fragment, "chapter1") == 0);
+ So(strcmp(url->u_rawpath, "/somewhere?result=yes#chapter1") ==
+ 0);
So(url->u_userinfo == NULL);
nni_url_free(url);
});
@@ -116,6 +123,7 @@ TestMain("URLs", {
So(strcmp(url->u_port, "") == 0);
So(strcmp(url->u_path, "/somewhere") == 0);
So(strcmp(url->u_fragment, "chapter2") == 0);
+ So(strcmp(url->u_rawpath, "/somewhere#chapter2") == 0);
So(url->u_query == NULL);
So(url->u_userinfo == NULL);
nni_url_free(url);
@@ -129,6 +137,7 @@ TestMain("URLs", {
So(strcmp(url->u_path, "") == 0);
So(strcmp(url->u_port, "") == 0);
So(strcmp(url->u_fragment, "chapter3") == 0);
+ So(strcmp(url->u_rawpath, "#chapter3") == 0);
So(url->u_query == NULL);
So(url->u_userinfo == NULL);
nni_url_free(url);
@@ -143,6 +152,7 @@ TestMain("URLs", {
So(strcmp(url->u_path, "") == 0);
So(strcmp(url->u_port, "") == 0);
So(strcmp(url->u_query, "color=red") == 0);
+ So(strcmp(url->u_rawpath, "?color=red") == 0);
So(url->u_fragment == NULL);
So(url->u_userinfo == NULL);
nni_url_free(url);
diff --git a/tests/ws.c b/tests/ws.c
index 386c0690..38db4738 100644
--- a/tests/ws.c
+++ b/tests/ws.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 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
// copy of which should be located in the distribution where this
diff --git a/tests/wss.c b/tests/wss.c
index 38b333b9..5394ad59 100644
--- a/tests/wss.c
+++ b/tests/wss.c
@@ -1,6 +1,6 @@
//
-// Copyright 2017 Garrett D'Amore <garrett@damore.org>
-// Copyright 2017 Capitar IT Group BV <info@capitar.com>
+// Copyright 2018 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
// copy of which should be located in the distribution where this