aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-05-26 01:58:55 -0400
committerFedor Indutny <fedor@indutny.com>2016-05-26 01:58:55 -0400
commita4e614177addfebb6f669e707dc5552c3d3ced1a (patch)
tree68c2018cf2a7f88879ad05585c16bdc40c4ac7b5 /test/src
parent563174a6894f4b4bdf3f90b28fde84d5dd6bfee8 (diff)
downloaduv_link_t-a4e614177addfebb6f669e707dc5552c3d3ced1a.tar.gz
test: uv_link_observer_t test
Diffstat (limited to 'test/src')
-rw-r--r--test/src/test-common.h1
-rw-r--r--test/src/test-list.h1
-rw-r--r--test/src/test-uv-link-observer-t.c44
3 files changed, 46 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);
+}