diff options
author | Kyle Edwards <kyle.edwards@kitware.com> | 2023-06-09 16:55:35 (GMT) |
---|---|---|
committer | Kyle Edwards <kyle.edwards@kitware.com> | 2023-06-14 15:53:55 (GMT) |
commit | ec81d40be437a0ca2362f3b8c84dbfbf7fe6a2b3 (patch) | |
tree | d6aae0eadb9e5bcd169850fd78745503bdeec098 /Tests | |
parent | 3b6c5efc086836d5006a184052f642004695b445 (diff) | |
download | CMake-ec81d40be437a0ca2362f3b8c84dbfbf7fe6a2b3.zip CMake-ec81d40be437a0ca2362f3b8c84dbfbf7fe6a2b3.tar.gz CMake-ec81d40be437a0ca2362f3b8c84dbfbf7fe6a2b3.tar.bz2 |
cmUVPipeIStream: Add cmUVPipeIStream
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/CMakeLib/testUVStreambuf.cxx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Tests/CMakeLib/testUVStreambuf.cxx b/Tests/CMakeLib/testUVStreambuf.cxx index f9ed6af..c97e695 100644 --- a/Tests/CMakeLib/testUVStreambuf.cxx +++ b/Tests/CMakeLib/testUVStreambuf.cxx @@ -8,6 +8,7 @@ #include "cmGetPipes.h" #include "cmUVHandlePtr.h" +#include "cmUVStream.h" #include "cmUVStreambuf.h" #define TEST_STR_LINE_1 "This string must be exactly 128 characters long so" @@ -437,6 +438,40 @@ end: return success; } +bool testUVPipeIStream() +{ + int pipe[] = { -1, -1 }; + if (cmGetPipes(pipe) < 0) { + std::cout << "cmGetPipes() returned an error" << std::endl; + return false; + } + + cm::uv_loop_ptr loop; + loop.init(); + cm::uv_pipe_ptr pipeSink; + pipeSink.init(*loop, 0); + uv_pipe_open(pipeSink, pipe[1]); + + std::string str = "Hello world!\n"; + uv_write_t writeReq; + uv_buf_t buf; + buf.base = &str.front(); + buf.len = str.length(); + uv_write(&writeReq, pipeSink, &buf, 1, nullptr); + uv_run(loop, UV_RUN_DEFAULT); + + cmUVPipeIStream pin(*loop, pipe[0]); + std::string line; + std::getline(pin, line); + if (line != "Hello world!") { + std::cout << "Line was \"" << line << "\", should be \"Hello world!\"" + << std::endl; + return false; + } + + return true; +} + int testUVStreambuf(int argc, char** const argv) { if (argc < 2) { @@ -454,5 +489,10 @@ int testUVStreambuf(int argc, char** const argv) return -1; } + if (!testUVPipeIStream()) { + std::cout << "While executing testUVPipeIStream().\n"; + return -1; + } + return 0; } |