aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-01-12 14:43:31 -0800
committerGarrett D'Amore <garrett@damore.org>2025-01-12 14:43:31 -0800
commit2ddaecdadb8a931188b3f3e6b8ad43b9cba45d0f (patch)
treeddab0fbc8bb631fc31c233e09cd83a561988158d /tests
parentd88484cafbf973d55dc95b7edcae5064efa8bad0 (diff)
downloadnng-2ddaecdadb8a931188b3f3e6b8ad43b9cba45d0f.tar.gz
nng-2ddaecdadb8a931188b3f3e6b8ad43b9cba45d0f.tar.bz2
nng-2ddaecdadb8a931188b3f3e6b8ad43b9cba45d0f.zip
api: extend usage of nng_err
This replaces the int, and we will expand this further, as this makes it clear that the int is actually an error code and helps in debuggers that can provide symbolic values.
Diffstat (limited to 'tests')
-rw-r--r--tests/cplusplus_pair.cc35
1 files changed, 18 insertions, 17 deletions
diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc
index 1148aaae..4481a4d7 100644
--- a/tests/cplusplus_pair.cc
+++ b/tests/cplusplus_pair.cc
@@ -7,10 +7,11 @@
// found online at https://opensource.org/licenses/MIT.
//
-#include "nng/nng.h"
-
#include <cstdio>
#include <cstring>
+#include <iostream>
+
+#include <nng/nng.h>
#define SOCKET_ADDRESS "inproc://c++"
@@ -22,58 +23,58 @@ main(int argc, char **argv)
nng_socket s1;
nng_socket s2;
- int rv;
+ nng_err rv;
size_t sz;
char buf[8];
(void) argc;
(void) argv;
nng_init(NULL);
- if ((rv = nng_pair1_open(&s1)) != 0) {
+ if ((rv = (nng_err) nng_pair1_open(&s1)) != 0) {
throw nng_strerror(rv);
}
- if ((rv = nng_pair1_open(&s2)) != 0) {
+ if ((rv = (nng_err) nng_pair1_open(&s2)) != 0) {
throw nng_strerror(rv);
}
- if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ if ((rv = (nng_err) nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
throw nng_strerror(rv);
}
- if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ if ((rv = (nng_err) nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
throw nng_strerror(rv);
}
- if ((rv = nng_send(s2, (void *) "ABC", 4, 0)) != 0) {
+ if ((rv = (nng_err) nng_send(s2, (void *) "ABC", 4, 0)) != 0) {
throw nng_strerror(rv);
}
sz = sizeof(buf);
- if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) {
+ if ((rv = (nng_err) nng_recv(s1, buf, &sz, 0)) != 0) {
throw nng_strerror(rv);
}
- if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) {
+ if ((sz != 4) || (std::strcmp(buf, "ABC") != 0)) {
throw "Contents did not match";
}
- if ((rv = nng_send(s1, (void *) "DEF", 4, 0)) != 0) {
+ if ((rv = (nng_err) nng_send(s1, (void *) "DEF", 4, 0)) != 0) {
throw nng_strerror(rv);
}
sz = sizeof(buf);
- if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) {
+ if ((rv = (nng_err) nng_recv(s2, buf, &sz, 0)) != 0) {
throw nng_strerror(rv);
}
- if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) {
+ if ((sz != 4) || (std::strcmp(buf, "DEF") != 0)) {
throw "Contents did not match";
}
- if ((rv = nng_socket_close(s1)) != 0) {
+ if ((rv = (nng_err) nng_socket_close(s1)) != 0) {
throw nng_strerror(rv);
}
- if ((rv = nng_socket_close(s2)) != 0) {
+ if ((rv = (nng_err) nng_socket_close(s2)) != 0) {
throw nng_strerror(rv);
}
- printf("Pass.\n");
+ std::cout << "Pass." << std::endl;
nng_fini();
#else
(void) argc;
(void) argv;
- printf("Skipped (protocol unconfigured).\n");
+ std::cout << "Skipped (protocol unconfigured)." << std::endl;
#endif
return (0);