From 12307a1afd2bb82901a03db9d3024288a4128563 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Fri, 29 Nov 2024 13:09:13 -0500 Subject: tests: Convert device test to NUTS This also adds more tests for additional test cases (aio, and more validations of incompatible device configurations). --- tests/CMakeLists.txt | 1 - tests/device.c | 108 --------------------------------------------------- 2 files changed, 109 deletions(-) delete mode 100644 tests/device.c (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f41379e0..9d976dd9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -124,7 +124,6 @@ else () endmacro(add_nng_test3) endif () -add_nng_test(device 5) add_nng_test(files 5) add_nng_test1(httpclient 60 NNG_SUPP_HTTP) add_nng_test1(httpserver 30 NNG_SUPP_HTTP) diff --git a/tests/device.c b/tests/device.c deleted file mode 100644 index 53f51ba3..00000000 --- a/tests/device.c +++ /dev/null @@ -1,108 +0,0 @@ -// -// Copyright 2024 Staysail Systems, Inc. -// Copyright 2018 Capitar IT Group BV -// -// This software is supplied under the terms of the MIT License, a -// copy of which should be located in the distribution where this -// file was obtained (LICENSE.txt). A copy of the license may also be -// found online at https://opensource.org/licenses/MIT. -// - -#include - -#include -#include - -#include "convey.h" -#include "stubs.h" - -#define APPENDSTR(m, s) nng_msg_append(m, s, strlen(s)) -#define CHECKSTR(m, s) \ - So(nng_msg_len(m) == strlen(s)); \ - So(memcmp(nng_msg_body(m), s, strlen(s)) == 0) - -struct dev_data { - nng_socket s1; - nng_socket s2; -}; - -void -dodev(void *arg) -{ - struct dev_data *d = arg; - - nng_device(d->s1, d->s2); -} - -#define SECOND(x) ((x) *1000) - -Main({ - Test("PAIRv1 device", { - const char *addr1 = "inproc://dev1"; - const char *addr2 = "inproc://dev2"; - - Convey("We cannot create cooked mode device", { - nng_socket s1; - So(nng_pair1_open(&s1) == 0); - Reset({ nng_close(s1); }); - So(nng_device(s1, s1) == NNG_EINVAL); - }); - Convey("We can create a PAIRv1 device", { - nng_socket dev1; - nng_socket dev2; - nng_socket end1; - nng_socket end2; - nng_duration tmo; - nng_msg *msg; - nng_thread *thr; - - So(nng_pair1_open_raw(&dev1) == 0); - So(nng_pair1_open_raw(&dev2) == 0); - - struct dev_data ddata; - ddata.s1 = dev1; - ddata.s2 = dev2; - - So(nng_thread_create(&thr, dodev, &ddata) == 0); - Reset({ - nng_close(dev1); - nng_close(dev2); - nng_thread_destroy(thr); - }); - - So(nng_listen(dev1, addr1, NULL, 0) == 0); - So(nng_listen(dev2, addr2, NULL, 0) == 0); - - So(nng_pair1_open(&end1) == 0); - So(nng_pair1_open(&end2) == 0); - - So(nng_dial(end1, addr1, NULL, 0) == 0); - So(nng_dial(end2, addr2, NULL, 0) == 0); - - tmo = SECOND(1); - So(nng_socket_set_ms(end1, NNG_OPT_RECVTIMEO, tmo) == - 0); - So(nng_socket_set_ms(end2, NNG_OPT_RECVTIMEO, tmo) == - 0); - - nng_msleep(100); - Convey("Device can send and receive", { - So(nng_msg_alloc(&msg, 0) == 0); - APPENDSTR(msg, "ALPHA"); - So(nng_sendmsg(end1, msg, 0) == 0); - So(nng_recvmsg(end2, &msg, 0) == 0); - CHECKSTR(msg, "ALPHA"); - nng_msg_free(msg); - - So(nng_msg_alloc(&msg, 0) == 0); - APPENDSTR(msg, "OMEGA"); - - So(nng_sendmsg(end2, msg, 0) == 0); - So(nng_recvmsg(end1, &msg, 0) == 0); - - CHECKSTR(msg, "OMEGA"); - nng_msg_free(msg); - }); - }); - }); -}) -- cgit v1.2.3-70-g09d2