diff options
| author | Garrett D'Amore <garrett@damore.org> | 2021-07-07 15:51:00 -0700 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2021-07-07 15:51:00 -0700 |
| commit | ae4def5faad10a89da77abe694e48df50f54cec4 (patch) | |
| tree | bbc8e77d95b2690893150f39105b81bb98cd6664 /tests | |
| parent | 886ef5bc75e1e1f7b549692ede55cdfc8e85ef8c (diff) | |
| download | nng-ae4def5faad10a89da77abe694e48df50f54cec4.tar.gz nng-ae4def5faad10a89da77abe694e48df50f54cec4.tar.bz2 nng-ae4def5faad10a89da77abe694e48df50f54cec4.zip | |
Add test cases for nng_msg_reserve, etc. Convert message tests to NUTS.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | tests/message.c | 266 |
2 files changed, 1 insertions, 268 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5fcd4323..1b818832 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> +# Copyright 2021 Staysail Systems, Inc. <info@staysail.tech> # Copyright 2018 Capitar IT Group BV <info@capitar.com> # Copyright (c) 2012 Martin Sustrik All rights reserved. # Copyright (c) 2013 GoPivotal, Inc. All rights reserved. @@ -132,7 +132,6 @@ add_nng_test(inproc 5) add_nng_test(ipc 5) add_nng_test(ipcsupp 10) add_nng_test(ipcwinsec 5) -add_nng_test(message 5) add_nng_test(multistress 60) add_nng_test(nonblock 60) add_nng_test(options 5) diff --git a/tests/message.c b/tests/message.c deleted file mode 100644 index 1eda09b1..00000000 --- a/tests/message.c +++ /dev/null @@ -1,266 +0,0 @@ -// -// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech> -// Copyright 2018 Capitar IT Group BV <info@capitar.com> -// -// 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 <string.h> - -#include <nng/nng.h> - -#include "convey.h" - -static uint8_t dat123[] = { 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3 }; - -TestMain("Message Tests", { - nng_msg *msg; - - Convey("Given an empty message", { - So(nng_msg_alloc(&msg, 0) == 0); - - Reset({ nng_msg_free(msg); }); - - Convey("Get opt returns ENOTSUP", { - So(nng_msg_getopt(msg, 0, NULL, NULL) == NNG_ENOTSUP); - }); - - Convey("Lengths are empty", { - So(nng_msg_len(msg) == 0); - So(nng_msg_header_len(msg) == 0); - }); - - Convey("We can append to the header", { - So(nng_msg_header_append(msg, "pad", 4) == 0); - So(nng_msg_header_len(msg) == 4); - So(strcmp(nng_msg_header(msg), "pad") == 0); - }); - - Convey("We can append to the body", { - So(nng_msg_append(msg, "123", 4) == 0); - So(nng_msg_len(msg) == 4); - So(strcmp(nng_msg_body(msg), "123") == 0); - }); - - Convey("We can insert to the header", { - So(nng_msg_header_append(msg, "def", 4) == 0); - So(nng_msg_header_insert(msg, "abc", 3) == 0); - So(nng_msg_header_len(msg) == 7); - So(strcmp(nng_msg_header(msg), "abcdef") == 0); - - Convey("We can delete from the front", { - So(nng_msg_header_trim(msg, 2) == 0); - So(nng_msg_header_len(msg) == 5); - So(strcmp(nng_msg_header(msg), "cdef") == 0); - }); - - Convey("We can delete from the back", { - So(nng_msg_header_chop(msg, 5) == 0); - So(nng_msg_header_len(msg) == 2); - So(memcmp(nng_msg_header(msg), "ab", 2) == 0); - }); - }); - - Convey("We can insert to the body", { - So(nng_msg_append(msg, "xyz", 4) == 0); - So(nng_msg_insert(msg, "uvw", 3) == 0); - So(nng_msg_len(msg) == 7); - So(strcmp(nng_msg_body(msg), "uvwxyz") == 0); - - Convey("We can delete from the front", { - So(nng_msg_trim(msg, 2) == 0); - So(nng_msg_len(msg) == 5); - So(strcmp(nng_msg_body(msg), "wxyz") == 0); - }); - - Convey("We can delete from the back", { - So(nng_msg_chop(msg, 5) == 0); - So(nng_msg_len(msg) == 2); - So(memcmp(nng_msg_body(msg), "uv", 2) == 0); - }); - }); - - Convey("Clearing the header works", { - So(nng_msg_header_append(msg, "bogus", 6) == 0); - So(nng_msg_header_len(msg) == 6); - nng_msg_header_clear(msg); - So(nng_msg_header_len(msg) == 0); - }); - - Convey("Clearing the body works", { - nng_msg_header_append(msg, "bogus", 6); - So(nng_msg_append(msg, "bogus", 6) == 0); - So(nng_msg_len(msg) == 6); - nng_msg_clear(msg); - So(nng_msg_len(msg) == 0); - // It shouldn't clear the header - So(nng_msg_header_len(msg) == 6); - }); - - Convey("We cannot delete more header than exists", { - So(nng_msg_header_append( - msg, "short", strlen("short") + 1) == 0); - So(nng_msg_header_trim(msg, 16) == NNG_EINVAL); - So(nng_msg_header_len(msg) == strlen("short") + 1); - So(nng_msg_header_chop(msg, 16) == NNG_EINVAL); - So(nng_msg_header_len(msg) == strlen("short") + 1); - So(strcmp(nng_msg_header(msg), "short") == 0); - }); - - Convey("We cannot delete more body than exists", { - So(nng_msg_append(msg, "short", strlen("short") + 1) == - 0); - So(nng_msg_trim(msg, 16) == NNG_EINVAL); - So(nng_msg_len(msg) == strlen("short") + 1); - So(nng_msg_chop(msg, 16) == NNG_EINVAL); - So(nng_msg_len(msg) == strlen("short") + 1); - So(strcmp(nng_msg_body(msg), "short") == 0); - }); - - Convey("Pipe retrievals work", { - nng_pipe p = NNG_PIPE_INITIALIZER; - nng_pipe p0 = NNG_PIPE_INITIALIZER; - - So(nng_pipe_id(p0) < 0); - p = nng_msg_get_pipe(msg); - So(nng_pipe_id(p) < 0); - memset(&p, 0x22, sizeof(p)); - nng_msg_set_pipe(msg, p); - p = nng_msg_get_pipe(msg); - So(nng_pipe_id(p) != nng_pipe_id(p0)); - So(nng_pipe_id(p) == 0x22222222); - }); - - Convey("Message realloc works", { - So(nng_msg_append(msg, "abc", 4) == 0); - So(nng_msg_realloc(msg, 1500) == 0); - So(nng_msg_len(msg) == 1500); - So(strcmp(nng_msg_body(msg), "abc") == 0); - So(nng_msg_realloc(msg, 2) == 0); - So(nng_msg_len(msg) == 2); - So(memcmp(nng_msg_body(msg), "abc", 3) == 0); - So(nng_msg_append(msg, "CDEF", strlen("CDEF") + 1) == - 0); - So(nng_msg_len(msg) == strlen("abCDEF") + 1); - So(strcmp(nng_msg_body(msg), "abCDEF") == 0); - }); - - Convey("Inserting a lot of data works", { - char chunk[1024]; - memset(chunk, '+', sizeof(chunk)); - So(nng_msg_append(msg, "abc", strlen("abc") + 1) == 0); - So(nng_msg_len(msg) == strlen("abc") + 1); - So(nng_msg_insert(msg, chunk, sizeof(chunk)) == 0); - So(nng_msg_len(msg) == - strlen("abc") + 1 + sizeof(chunk)); - So(memcmp(chunk, nng_msg_body(msg), sizeof(chunk)) == - 0); - So(strcmp((char *) nng_msg_body(msg) + sizeof(chunk), - "abc") == 0); - So(nng_msg_trim(msg, sizeof(chunk) - 2) == 0); - So(strcmp(nng_msg_body(msg), "++abc") == 0); - }); - - Convey("Message dup works", { - nng_msg *m2; - - So(nng_msg_header_append( - msg, "front", strlen("front") + 1) == 0); - So(nng_msg_append(msg, "back", strlen("back") + 1) == - 0); - - So(nng_msg_dup(&m2, msg) == 0); - Reset({ nng_msg_free(m2); }); - - So(nng_msg_len(msg) == strlen("front")); - So(nng_msg_len(m2) == strlen("front")); - So(nng_msg_header_len(msg) == nng_msg_header_len(m2)); - - So(nng_msg_insert(msg, "way", 3) == 0); - So(nng_msg_len(msg) == strlen("wayback") + 1); - So(nng_msg_len(m2) == strlen("back") + 1); - So(strcmp(nng_msg_body(msg), "wayback") == 0); - So(strcmp(nng_msg_body(m2), "back") == 0); - So(nng_msg_chop(m2, 1) == 0); - So(nng_msg_append( - m2, "2basics", strlen("2basics") + 1) == 0); - So(nng_msg_len(msg) == strlen("wayback") + 1); - So(strcmp(nng_msg_body(msg), "wayback") == 0); - So(nng_msg_len(m2) == strlen("back2basics") + 1); - So(strcmp(nng_msg_body(m2), "back2basics") == 0); - }); - - Convey("Message dup copies pipe", { - nng_pipe p = NNG_PIPE_INITIALIZER; - nng_msg *m2; - memset(&p, 0x22, sizeof(p)); - nng_msg_set_pipe(msg, p); - So(nng_msg_dup(&m2, msg) == 0); - Reset({ nng_msg_free(m2); }); - p = nng_msg_get_pipe(m2); - So(nng_pipe_id(p) == 0x22222222); - }); - - Convey("Uint32 body operations work", { - uint32_t v; - So(nng_msg_append_u32(msg, 2) == 0); - So(nng_msg_insert_u32(msg, 1) == 0); - So(nng_msg_append_u32(msg, 3) == 0); - So(nng_msg_insert_u32(msg, 0) == 0); - So(nng_msg_trim_u32(msg, &v) == 0); - So(v == 0); - So(nng_msg_len(msg) == sizeof(dat123)); - So(memcmp(nng_msg_body(msg), dat123, sizeof(dat123)) == - 0); - So(nng_msg_trim_u32(msg, &v) == 0); - So(v == 1); - So(nng_msg_chop_u32(msg, &v) == 0); - So(v == 3); - So(nng_msg_trim_u32(msg, &v) == 0); - So(v == 2); - So(nng_msg_trim_u32(msg, &v) == NNG_EINVAL); - So(nng_msg_trim_u32(msg, &v) == NNG_EINVAL); - - Convey("Single byte is inadequate", { - nng_msg_clear(msg); - So(nng_msg_append(msg, &v, 1) == 0); - So(nng_msg_trim_u32(msg, &v) == NNG_EINVAL); - So(nng_msg_trim_u32(msg, &v) == NNG_EINVAL); - }); - }); - - Convey("Uint32 header operations work", { - uint32_t v; - So(nng_msg_header_append_u32(msg, 2) == 0); - So(nng_msg_header_insert_u32(msg, 1) == 0); - So(nng_msg_header_append_u32(msg, 3) == 0); - So(nng_msg_header_insert_u32(msg, 0) == 0); - So(nng_msg_header_trim_u32(msg, &v) == 0); - So(v == 0); - So(nng_msg_header_len(msg) == sizeof(dat123)); - So(nng_msg_len(msg) == 0); - So(memcmp(nng_msg_header(msg), dat123, - sizeof(dat123)) == 0); - So(nng_msg_header_trim_u32(msg, &v) == 0); - So(v == 1); - So(nng_msg_header_chop_u32(msg, &v) == 0); - So(v == 3); - So(nng_msg_header_trim_u32(msg, &v) == 0); - So(v == 2); - So(nng_msg_header_trim_u32(msg, &v) == NNG_EINVAL); - So(nng_msg_header_trim_u32(msg, &v) == NNG_EINVAL); - - Convey("Single byte is inadequate", { - nng_msg_header_clear(msg); - So(nng_msg_header_append(msg, &v, 1) == 0); - So(nng_msg_header_trim_u32(msg, &v) == - NNG_EINVAL); - So(nng_msg_header_trim_u32(msg, &v) == - NNG_EINVAL); - }); - }); - }); -}) |
