From a4e614177addfebb6f669e707dc5552c3d3ced1a Mon Sep 17 00:00:00 2001 From: Fedor Indutny Date: Thu, 26 May 2016 01:58:55 -0400 Subject: test: uv_link_observer_t test --- test/src/test-common.h | 1 + test/src/test-list.h | 1 + test/src/test-uv-link-observer-t.c | 44 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 test/src/test-uv-link-observer-t.c (limited to 'test/src') 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 +#include + +#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); +} -- cgit 1.4.1-2-gfad0