From 8ad296769192cf4628710ac0b228be2aca6d8dad Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Wed, 23 Aug 2017 11:23:22 -0700 Subject: Implement dynamic option numbering. This permits option numbers to be allocated based on string name. Eventually all the option values will be replaced with option names. This will facilitate transports (ZeroTier) that may need further options. --- tests/pair1.c | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/pair1.c b/tests/pair1.c index d160acdd..adb50c88 100644 --- a/tests/pair1.c +++ b/tests/pair1.c @@ -106,8 +106,13 @@ TestMain("PAIRv1 protocol", { int rv; int i; nng_msg *msg; + int poly; - So(nng_setopt_int(s1, NNG_OPT_POLYAMOROUS, 1) == 0); + poly = nng_option_lookup("polyamorous"); + So(poly >= 0); + So(nng_option_name(poly) != NULL); + So(strcmp(nng_option_name(poly), "polyamorous") == 0); + So(nng_setopt_int(s1, poly, 1) == 0); So(nng_setopt_int(s1, NNG_OPT_RCVBUF, 1) == 0); So(nng_setopt_int(s1, NNG_OPT_SNDBUF, 1) == 0); @@ -155,14 +160,16 @@ TestMain("PAIRv1 protocol", { }); Convey("Cannot set polyamorous mode after connect", { + int poly; So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); nng_usleep(100000); + poly = nng_option_lookup("polyamorous"); + So(poly >= 0); + So(nng_option_name(poly) != NULL); + So(strcmp(nng_option_name(poly), "polyamorous") == 0); - So(nng_setopt_int(s1, NNG_OPT_POLYAMOROUS, 1) == - NNG_ESTATE); - So(nng_setopt_int(c1, NNG_OPT_POLYAMOROUS, 1) == - NNG_ESTATE); + So(nng_setopt_int(s1, poly, 1) == NNG_ESTATE); }); Convey("Monogamous raw mode works", { @@ -329,12 +336,18 @@ TestMain("PAIRv1 protocol", { int v; nng_pipe p1; nng_pipe p2; + int poly; - So(nng_getopt_int(s1, NNG_OPT_POLYAMOROUS, &v) == 0); + poly = nng_option_lookup("polyamorous"); + So(poly >= 0); + So(nng_option_name(poly) != NULL); + So(strcmp(nng_option_name(poly), "polyamorous") == 0); + + So(nng_getopt_int(s1, poly, &v) == 0); So(v == 0); - So(nng_setopt_int(s1, NNG_OPT_POLYAMOROUS, 1) == 0); - So(nng_getopt_int(s1, NNG_OPT_POLYAMOROUS, &v) == 0); + So(nng_setopt_int(s1, poly, 1) == 0); + So(nng_getopt_int(s1, poly, &v) == 0); So(v == 1); So(nng_listen(s1, addr, NULL, 0) == 0); @@ -389,8 +402,14 @@ TestMain("PAIRv1 protocol", { Convey("Polyamorous default works", { nng_msg *msg; + int poly; + + poly = nng_option_lookup("polyamorous"); + So(poly >= 0); + So(nng_option_name(poly) != NULL); + So(strcmp(nng_option_name(poly), "polyamorous") == 0); - So(nng_setopt_int(s1, NNG_OPT_POLYAMOROUS, 1) == 0); + So(nng_setopt_int(s1, poly, 1) == 0); So(nng_listen(s1, addr, NULL, 0) == 0); So(nng_dial(c1, addr, NULL, 0) == 0); @@ -421,12 +440,18 @@ TestMain("PAIRv1 protocol", { uint32_t hops; nng_pipe p1; nng_pipe p2; + int poly; + + poly = nng_option_lookup("polyamorous"); + So(poly >= 0); + So(nng_option_name(poly) != NULL); + So(strcmp(nng_option_name(poly), "polyamorous") == 0); - So(nng_getopt_int(s1, NNG_OPT_POLYAMOROUS, &v) == 0); + So(nng_getopt_int(s1, poly, &v) == 0); So(v == 0); - So(nng_setopt_int(s1, NNG_OPT_POLYAMOROUS, 1) == 0); - So(nng_getopt_int(s1, NNG_OPT_POLYAMOROUS, &v) == 0); + So(nng_setopt_int(s1, poly, 1) == 0); + So(nng_getopt_int(s1, poly, &v) == 0); So(v == 1); v = 0; -- cgit v1.2.3-70-g09d2