about summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-05-27 21:06:45 -0400
committerFedor Indutny <fedor@indutny.com>2016-05-27 21:06:45 -0400
commit9f6eff69114a493047ffdf1bb6f0e3c86b2119aa (patch)
tree8f76debcc351a9e52ced96419d81a71afd64ecb5 /test
parentad8e9d158cc420f99c2b7c89567bed4870a88777 (diff)
downloaduv_link_t-9f6eff69114a493047ffdf1bb6f0e3c86b2119aa.tar.gz
include: close callbacks
Diffstat (limited to 'test')
-rw-r--r--test/src/test-uv-link-observer-t.c30
-rw-r--r--test/src/test-uv-link-source-t.c13
2 files changed, 38 insertions, 5 deletions
diff --git a/test/src/test-uv-link-observer-t.c b/test/src/test-uv-link-observer-t.c
index eaba1ab..3c48908 100644
--- a/test/src/test-uv-link-observer-t.c
+++ b/test/src/test-uv-link-observer-t.c
@@ -7,9 +7,25 @@ static uv_link_t source;
 static uv_link_observer_t observer;
 
 static int observer_read_cb_called;
+static int fake_close_called;
+static int close_cb_called;
+
+static void fake_close(uv_link_t* link,
+                       uv_link_t* src,
+                       uv_link_close_cb cb) {
+  CHECK_EQ(link, &source, "fake_close link");
+  /* NOTE: `src` may not be a proper source here */
+
+  fake_close_called++;
+
+  /* Not 100% correct, since it is sync, but works here */
+  cb(src);
+}
 
 static uv_link_methods_t methods = {
-  /* no-op, won't be called */
+  .close = fake_close
+
+  /* rest are no-op, won't be called */
 };
 
 static void observer_read_cb(uv_link_observer_t* o,
@@ -23,6 +39,13 @@ static void observer_read_cb(uv_link_observer_t* o,
 }
 
 
+static void close_cb(uv_link_t* link) {
+  CHECK_EQ(link, &observer.link, "close_cb link");
+
+  close_cb_called++;
+}
+
+
 TEST_IMPL(uv_link_observer_t) {
   uv_buf_t buf;
 
@@ -39,6 +62,7 @@ TEST_IMPL(uv_link_observer_t) {
   uv_link_propagate_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);
+  uv_link_close(&observer.link, close_cb);
+  CHECK_EQ(fake_close_called, 1, "fake close count");
+  CHECK_EQ(close_cb_called, 1, "close_cb count");
 }
diff --git a/test/src/test-uv-link-source-t.c b/test/src/test-uv-link-source-t.c
index ba445a7..1d12ac0 100644
--- a/test/src/test-uv-link-source-t.c
+++ b/test/src/test-uv-link-source-t.c
@@ -12,6 +12,7 @@ static int test_arg;
 static int write_cb_called;
 static int alloc_cb_called;
 static int read_cb_called;
+static int close_cb_called;
 
 static void read_one() {
   char buf[1024];
@@ -103,6 +104,12 @@ static void test_reads() {
 }
 
 
+static void close_cb(uv_link_t* link) {
+  CHECK_EQ(link, &source.link, "close_cb link");
+  close_cb_called++;
+}
+
+
 TEST_IMPL(uv_link_source_t) {
   CHECK_NE(loop = uv_default_loop(), NULL, "uv_default_loop()");
 
@@ -117,8 +124,10 @@ TEST_IMPL(uv_link_source_t) {
   test_writes();
   test_reads();
 
-  uv_link_source_close(&source);
-  uv_close((uv_handle_t*) &pair_right, NULL);
+  uv_link_close(&source.link, close_cb);
+  CHECK_EQ(uv_run(loop, UV_RUN_DEFAULT), 0, "uv_run()");
+  CHECK_EQ(close_cb_called, 1, "close_cb count");
 
   CHECK_EQ(close(fds[0]), 0, "close(fds[0])");
+  CHECK_NE(close(fds[1]), 0, "close(fds[1]) must fail");
 }