diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/src/test-common.h | 1 | ||||
-rw-r--r-- | test/src/test-list.h | 1 | ||||
-rw-r--r-- | test/src/test-uv-link-observer-t.c | 44 | ||||
-rw-r--r-- | test/test.gyp | 1 |
4 files changed, 47 insertions, 0 deletions
diff --git a/test/src/test-common.h b/test/src/test-common.h index 1a3e79d..a78bf9d 100644 --- a/test/src/test-common.h +++ b/test/src/test-common.h @@ -14,6 +14,7 @@ do { \ if ((VALUE)) break; \ fprintf(stderr, "Assertion failure: " #MESSAGE "\n"); \ + abort(); \ } while (0); #define CHECK_EQ(A, B, MESSAGE) CHECK((A) == (B), MESSAGE) diff --git a/test/src/test-list.h b/test/src/test-list.h index 4a1c8ff..35b1ab0 100644 --- a/test/src/test-list.h +++ b/test/src/test-list.h @@ -3,6 +3,7 @@ #define TEST_ENUM(V) \ V(uv_link_source_t) \ + V(uv_link_observer_t) \ #define TEST_DECL(N) void test__##N(); diff --git a/test/src/test-uv-link-observer-t.c b/test/src/test-uv-link-observer-t.c new file mode 100644 index 0000000..cb4026d --- /dev/null +++ b/test/src/test-uv-link-observer-t.c @@ -0,0 +1,44 @@ +#include <sys/socket.h> +#include <unistd.h> + +#include "test-common.h" + +static uv_loop_t* loop; +static uv_link_t source; +static uv_link_observer_t observer; + +static int observer_read_cb_called; + +static void observer_read_cb(uv_link_observer_t* o, + ssize_t nread, + const uv_buf_t* buf) { + CHECK_EQ(o, &observer, "o == &observer"); + CHECK_EQ(nread, 1, "nread == 1"); + CHECK_EQ(buf->base[0], 'x', "correct buf contents"); + + observer_read_cb_called++; +} + + +TEST_IMPL(uv_link_observer_t) { + uv_buf_t buf; + + loop = uv_default_loop(); + CHECK_NE(loop, NULL, "uv_default_loop()"); + + CHECK_EQ(uv_link_init(loop, &source), 0, "uv_link_init(source)"); + + CHECK_EQ(uv_link_observer_init(loop, &observer, &source), 0, + "uv_link_observer_init()"); + + observer.read_cb = observer_read_cb; + + uv_link_invoke_alloc_cb(&source, 1024, &buf); + + buf.base[0] = 'x'; + uv_link_invoke_read_cb(&source, 1, &buf); + CHECK_EQ(observer_read_cb_called, 1, "observer.read_cb must be called"); + + CHECK_EQ(uv_link_observer_close(&observer), 0, "uv_link_observer_close"); + uv_link_close(&source); +} diff --git a/test/test.gyp b/test/test.gyp index c63a046..ef59c95 100644 --- a/test/test.gyp +++ b/test/test.gyp @@ -15,6 +15,7 @@ "sources": [ "src/main.c", "src/test-uv-link-source-t.c", + "src/test-uv-link-observer-t.c", ], }], } |