aboutsummaryrefslogtreecommitdiff
path: root/tests/cplusplus_pair.cc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/cplusplus_pair.cc')
-rw-r--r--tests/cplusplus_pair.cc99
1 files changed, 54 insertions, 45 deletions
diff --git a/tests/cplusplus_pair.cc b/tests/cplusplus_pair.cc
index 54a99737..11ce1912 100644
--- a/tests/cplusplus_pair.cc
+++ b/tests/cplusplus_pair.cc
@@ -8,59 +8,68 @@
//
#include "nng.h"
+#include "protocol/pair1/pair.h"
#include <cstring>
+#include <iostream>
#define SOCKET_ADDRESS "inproc://c++"
int
main(int argc, char **argv)
{
- nng_socket s1;
- nng_socket s2;
- int rv;
- size_t sz;
- char buf[8];
- if ((rv = nng_pair0_open(&s1)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_pair0_open(&s2)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_send(s2, (void *)"ABC", 4, 0)) != 0) {
- throw nng_strerror(rv);
- }
- sz = sizeof (buf);
- if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) {
- throw "Contents did not match";
- }
- if ((rv = nng_send(s1, (void *)"DEF", 4, 0)) != 0) {
- throw nng_strerror(rv);
- }
- sz = sizeof (buf);
- if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) {
- throw nng_strerror(rv);
- }
- if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) {
- throw "Contents did not match";
- }
- if ((rv = nng_close(s1)) != 0) {
- throw nng_strerror(rv);
- }
- if ((rv = nng_close(s2)) != 0) {
- throw nng_strerror(rv);
- }
+#if defined(NNG_HAVE_PAIR1)
- return (0);
-}
+ nng_socket s1;
+ nng_socket s2;
+ int rv;
+ size_t sz;
+ char buf[8];
+
+ if ((rv = nng_pair1_open(&s1)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_pair1_open(&s2)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_listen(s1, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_dial(s2, SOCKET_ADDRESS, NULL, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_send(s2, (void *) "ABC", 4, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ sz = sizeof(buf);
+ if ((rv = nng_recv(s1, buf, &sz, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((sz != 4) || (memcmp(buf, "ABC", 4) != 0)) {
+ throw "Contents did not match";
+ }
+ if ((rv = nng_send(s1, (void *) "DEF", 4, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ sz = sizeof(buf);
+ if ((rv = nng_recv(s2, buf, &sz, 0)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((sz != 4) || (memcmp(buf, "DEF", 4) != 0)) {
+ throw "Contents did not match";
+ }
+ if ((rv = nng_close(s1)) != 0) {
+ throw nng_strerror(rv);
+ }
+ if ((rv = nng_close(s2)) != 0) {
+ throw nng_strerror(rv);
+ }
+ std::cout << "Pass." << std::endl;
+#else
+ std::cout << "Skipped (protocol unconfigured)." << std::endl;
+#endif
+
+ return (0);
+}