about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/common.h1
-rw-r--r--src/uv_link_t.c2
-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
-rw-r--r--test/test.gyp1
6 files changed, 49 insertions, 1 deletions
diff --git a/src/common.h b/src/common.h
index 93d101f..8e5f627 100644
--- a/src/common.h
+++ b/src/common.h
@@ -13,6 +13,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/src/uv_link_t.c b/src/uv_link_t.c
index 548d638..df23dcd 100644
--- a/src/uv_link_t.c
+++ b/src/uv_link_t.c
@@ -67,7 +67,7 @@ int uv_link_unchain(uv_link_t* from, uv_link_t* to) {
   from->saved_alloc_cb = NULL;
   from->saved_read_cb = NULL;
 
-  return from->read_stop(from);
+  return 0;
 }
 
 
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",
     ],
   }],
 }