summaryrefslogtreecommitdiff
path: root/deps/uv/test/test-tty.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/uv/test/test-tty.c')
-rw-r--r--deps/uv/test/test-tty.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/deps/uv/test/test-tty.c b/deps/uv/test/test-tty.c
index 6aaeda8f59..3bbdfad780 100644
--- a/deps/uv/test/test-tty.c
+++ b/deps/uv/test/test-tty.c
@@ -96,9 +96,13 @@ TEST_IMPL(tty) {
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
ASSERT(r == 0);
+ ASSERT(uv_is_readable((uv_stream_t*) &tty_in));
+ ASSERT(!uv_is_writable((uv_stream_t*) &tty_in));
r = uv_tty_init(uv_default_loop(), &tty_out, ttyout_fd, 0); /* Writable. */
ASSERT(r == 0);
+ ASSERT(!uv_is_readable((uv_stream_t*) &tty_out));
+ ASSERT(uv_is_writable((uv_stream_t*) &tty_out));
r = uv_tty_get_winsize(&tty_out, &width, &height);
ASSERT(r == 0);
@@ -186,6 +190,8 @@ TEST_IMPL(tty_raw) {
r = uv_tty_init(uv_default_loop(), &tty_in, ttyin_fd, 1); /* Readable. */
ASSERT(r == 0);
+ ASSERT(uv_is_readable((uv_stream_t*) &tty_in));
+ ASSERT(!uv_is_writable((uv_stream_t*) &tty_in));
r = uv_read_start((uv_stream_t*)&tty_in, tty_raw_alloc, tty_raw_read);
ASSERT(r == 0);
@@ -242,6 +248,8 @@ TEST_IMPL(tty_empty_write) {
r = uv_tty_init(uv_default_loop(), &tty_out, ttyout_fd, 0); /* Writable. */
ASSERT(r == 0);
+ ASSERT(!uv_is_readable((uv_stream_t*) &tty_out));
+ ASSERT(uv_is_writable((uv_stream_t*) &tty_out));
bufs[0].len = 0;
bufs[0].base = &dummy[0];
@@ -309,6 +317,8 @@ TEST_IMPL(tty_file) {
#ifndef _WIN32
uv_loop_t loop;
uv_tty_t tty;
+ uv_tty_t tty_ro;
+ uv_tty_t tty_wo;
int fd;
ASSERT(0 == uv_loop_init(&loop));
@@ -334,13 +344,40 @@ TEST_IMPL(tty_file) {
ASSERT(0 == close(fd));
}
- fd = open("/dev/tty", O_RDONLY);
+ fd = open("/dev/tty", O_RDWR);
if (fd != -1) {
ASSERT(0 == uv_tty_init(&loop, &tty, fd, 1));
- ASSERT(0 == close(fd));
+ ASSERT(0 == close(fd)); /* TODO: it's indeterminate who owns fd now */
+ ASSERT(uv_is_readable((uv_stream_t*) &tty));
+ ASSERT(uv_is_writable((uv_stream_t*) &tty));
uv_close((uv_handle_t*) &tty, NULL);
+ ASSERT(!uv_is_readable((uv_stream_t*) &tty));
+ ASSERT(!uv_is_writable((uv_stream_t*) &tty));
+ }
+
+ fd = open("/dev/tty", O_RDONLY);
+ if (fd != -1) {
+ ASSERT(0 == uv_tty_init(&loop, &tty_ro, fd, 1));
+ ASSERT(0 == close(fd)); /* TODO: it's indeterminate who owns fd now */
+ ASSERT(uv_is_readable((uv_stream_t*) &tty_ro));
+ ASSERT(!uv_is_writable((uv_stream_t*) &tty_ro));
+ uv_close((uv_handle_t*) &tty_ro, NULL);
+ ASSERT(!uv_is_readable((uv_stream_t*) &tty_ro));
+ ASSERT(!uv_is_writable((uv_stream_t*) &tty_ro));
}
+ fd = open("/dev/tty", O_WRONLY);
+ if (fd != -1) {
+ ASSERT(0 == uv_tty_init(&loop, &tty_wo, fd, 0));
+ ASSERT(0 == close(fd)); /* TODO: it's indeterminate who owns fd now */
+ ASSERT(!uv_is_readable((uv_stream_t*) &tty_wo));
+ ASSERT(uv_is_writable((uv_stream_t*) &tty_wo));
+ uv_close((uv_handle_t*) &tty_wo, NULL);
+ ASSERT(!uv_is_readable((uv_stream_t*) &tty_wo));
+ ASSERT(!uv_is_writable((uv_stream_t*) &tty_wo));
+ }
+
+
ASSERT(0 == uv_run(&loop, UV_RUN_DEFAULT));
ASSERT(0 == uv_loop_close(&loop));
@@ -370,6 +407,10 @@ TEST_IMPL(tty_pty) {
ASSERT(0 == uv_tty_init(&loop, &slave_tty, slave_fd, 0));
ASSERT(0 == uv_tty_init(&loop, &master_tty, master_fd, 0));
+ ASSERT(uv_is_readable((uv_stream_t*) &slave_tty));
+ ASSERT(uv_is_writable((uv_stream_t*) &slave_tty));
+ ASSERT(uv_is_readable((uv_stream_t*) &master_tty));
+ ASSERT(uv_is_writable((uv_stream_t*) &master_tty));
/* Check if the file descriptor was reopened. If it is,
* UV_HANDLE_BLOCKING_WRITES (value 0x100000) isn't set on flags.
*/