ext/libuv/test/test-tty.c in libuv-3.1.1 vs ext/libuv/test/test-tty.c in libuv-3.1.2
- old
+ new
@@ -210,9 +210,96 @@
uv_run(loop, UV_RUN_DEFAULT);
MAKE_VALGRIND_HAPPY();
return 0;
}
+
+TEST_IMPL(tty_empty_write) {
+ int r;
+ int ttyout_fd;
+ uv_tty_t tty_out;
+ char dummy[1];
+ uv_buf_t bufs[1];
+ uv_loop_t* loop;
+
+ /* Make sure we have an FD that refers to a tty */
+ HANDLE handle;
+
+ loop = uv_default_loop();
+
+ handle = CreateFileA("conout$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ ASSERT(handle != INVALID_HANDLE_VALUE);
+ ttyout_fd = _open_osfhandle((intptr_t) handle, 0);
+
+ ASSERT(ttyout_fd >= 0);
+
+ ASSERT(UV_TTY == uv_guess_handle(ttyout_fd));
+
+ r = uv_tty_init(uv_default_loop(), &tty_out, ttyout_fd, 0); /* Writable. */
+ ASSERT(r == 0);
+
+ bufs[0].len = 0;
+ bufs[0].base = &dummy;
+
+ r = uv_try_write((uv_stream_t*) &tty_out, bufs, 1);
+ ASSERT(r == 0);
+
+ uv_close((uv_handle_t*) &tty_out, NULL);
+
+ uv_run(loop, UV_RUN_DEFAULT);
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
+
+TEST_IMPL(tty_large_write) {
+ int r;
+ int ttyout_fd;
+ uv_tty_t tty_out;
+ char dummy[10000];
+ uv_buf_t bufs[1];
+ uv_loop_t* loop;
+
+ /* Make sure we have an FD that refers to a tty */
+ HANDLE handle;
+
+ loop = uv_default_loop();
+
+ handle = CreateFileA("conout$",
+ GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ ASSERT(handle != INVALID_HANDLE_VALUE);
+ ttyout_fd = _open_osfhandle((intptr_t) handle, 0);
+
+ ASSERT(ttyout_fd >= 0);
+
+ ASSERT(UV_TTY == uv_guess_handle(ttyout_fd));
+
+ r = uv_tty_init(uv_default_loop(), &tty_out, ttyout_fd, 0); /* Writable. */
+ ASSERT(r == 0);
+
+ bufs[0] = uv_buf_init(dummy, sizeof(dummy));
+
+ r = uv_try_write((uv_stream_t*) &tty_out, bufs, 1);
+ ASSERT(r == 10000);
+
+ uv_close((uv_handle_t*) &tty_out, NULL);
+
+ uv_run(loop, UV_RUN_DEFAULT);
+
+ MAKE_VALGRIND_HAPPY();
+ return 0;
+}
#endif
TEST_IMPL(tty_file) {
#ifndef _WIN32