aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-10-06 12:26:42 -0700
committerGarrett D'Amore <garrett@damore.org>2017-10-06 12:26:42 -0700
commit52d37858451ad23f077294fc78b1a3f56255c32f (patch)
tree25bbdd0e995ca3af389697801f284d583e70a130 /tests
parentb0f31f578b0669b598d3ded3a625685b125bef1d (diff)
downloadnng-52d37858451ad23f077294fc78b1a3f56255c32f.tar.gz
nng-52d37858451ad23f077294fc78b1a3f56255c32f.tar.bz2
nng-52d37858451ad23f077294fc78b1a3f56255c32f.zip
Add NNG_OPT_DOMAIN and NNG_OPT_SOCKNAME support for legacy compat.
The NNG_OPT_SOCKNAME option is settable, to a limit of 64 bytes. The NNG_OPT_DOMAIN is read-only, but changes to match the setting of the NNG_OPT_RAW field. New applications should not use the NNG_OPT_DOMAIN option -- it is provided solely for use with the legacy NN_DOMAIN option in the compatibility layer.
Diffstat (limited to 'tests')
-rw-r--r--tests/sock.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/sock.c b/tests/sock.c
index f2afde4c..e21e687d 100644
--- a/tests/sock.c
+++ b/tests/sock.c
@@ -109,6 +109,48 @@ TestMain("Socket Operations", {
NNG_EREADONLY);
So(nng_setopt(s1, NNG_OPT_LOCADDR, "a", 1) ==
NNG_EREADONLY);
+ So(nng_setopt_int(s1, NNG_OPT_DOMAIN, 3) ==
+ NNG_EREADONLY);
+ });
+
+ Convey("Sockname option works", {
+ char name[128]; // 64 is max
+ size_t sz;
+ sz = sizeof(name);
+ So(nng_getopt(
+ s1, NNG_OPT_SOCKNAME, name, &sz) == 0);
+ So(sz > 0 && sz < 64);
+ So(sz == nni_strnlen(name, 64) + 1);
+ So(atoi(name) == (unsigned) s1);
+
+ So(nng_setopt(
+ s1, NNG_OPT_SOCKNAME, "hello", 6) == 0);
+ sz = sizeof(name);
+ So(nng_getopt(
+ s1, NNG_OPT_SOCKNAME, name, &sz) == 0);
+ So(sz == 6);
+ So(strcmp(name, "hello") == 0);
+
+ memset(name, 'A', 64);
+ name[64] = '\0';
+ So(nng_setopt(s1, NNG_OPT_SOCKNAME, name,
+ strlen(name)) == NNG_EINVAL);
+
+ So(nng_getopt(
+ s1, NNG_OPT_SOCKNAME, name, &sz) == 0);
+ So(sz == 6);
+ So(strcmp(name, "hello") == 0);
+ });
+
+ Convey("Domain option works", {
+ int dom;
+ So(nng_getopt_int(s1, NNG_OPT_DOMAIN, &dom) ==
+ 0);
+ So(dom == 1); // NN_AF_SP
+ So(nng_setopt_int(s1, NNG_OPT_RAW, 1) == 0);
+ So(nng_getopt_int(s1, NNG_OPT_DOMAIN, &dom) ==
+ 0);
+ So(dom == 2); // NN_AF_SP_RAW
});
Convey("URL option works", {