diff options
author | Fedor Indutny <fedor@indutny.com> | 2016-06-04 14:37:26 -0400 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2016-06-04 15:44:18 -0400 |
commit | af170cc9bbfbed228c386b64c1bb945ab4a502ed (patch) | |
tree | 901e5758c4ff05f72826c7e616591c7a548690e8 /test/src/test-strerror.c | |
parent | a66bb042e02bd1021a574c32a27fff087ab1c9f4 (diff) | |
download | uv_link_t-af170cc9bbfbed228c386b64c1bb945ab4a502ed.tar.gz |
api: experimental error reporting
Diffstat (limited to 'test/src/test-strerror.c')
-rw-r--r-- | test/src/test-strerror.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/test/src/test-strerror.c b/test/src/test-strerror.c new file mode 100644 index 0000000..d2e307c --- /dev/null +++ b/test/src/test-strerror.c @@ -0,0 +1,73 @@ +#include <sys/socket.h> +#include <unistd.h> + +#include "test-common.h" + +static uv_link_t a_link; +static uv_link_t b_link; + +static int close_cb_called; + + +static int faulty_try_write(uv_link_t* link, + const uv_buf_t bufs[], + unsigned int nbufs) { + return UV_ERRNO_MAX - 1; +} + + +const char* a_strerror(uv_link_t* l, int err) { + CHECK_EQ(l, &a_link, "link == a_link"); + return "a"; +} + + +const char* b_strerror(uv_link_t* l, int err) { + CHECK_EQ(l, &b_link, "link == b_link"); + return "b"; +} + + +static uv_link_methods_t a_methods = { + .try_write = faulty_try_write, + .strerror = a_strerror, + .close = uv_link_default_close +}; + + +static uv_link_methods_t b_methods = { + .try_write = faulty_try_write, + .strerror = b_strerror, + .close = uv_link_default_close, + + .alloc_cb_override = uv_link_default_alloc_cb_override, + .read_cb_override = uv_link_default_read_cb_override +}; + + +static void close_cb(uv_link_t* l) { + close_cb_called++; +} + + +TEST_IMPL(strerror) { + int err; + + CHECK_EQ(uv_link_init(&a_link, &a_methods), 0, "uv_link_init()"); + CHECK_EQ(uv_link_init(&b_link, &b_methods), 0, "uv_link_init()"); + CHECK_EQ(uv_link_chain(&a_link, &b_link), 0, "uv_link_chain()"); + + CHECK_EQ(uv_link_strerror(&b_link, UV_ERRNO_MAX - 1), NULL, + "unprefixed error should not be found"); + + err = uv_link_try_write(&b_link, NULL, 0); + CHECK_EQ(strcmp(uv_link_strerror(&b_link, err), "b"), 0, + "error description should match"); + + err = uv_link_try_write(&a_link, NULL, 0); + CHECK_EQ(strcmp(uv_link_strerror(&b_link, err), "a"), 0, + "error description should match"); + + uv_link_close(&b_link, close_cb); + CHECK_EQ(close_cb_called, 1, "close_cb must be called"); +} |