| 96 | } |
| 97 | |
| 98 | static bool testWriteCallback() |
| 99 | { |
| 100 | int pipe[] = { -1, -1 }; |
| 101 | if (cmGetPipes(pipe) < 0) { |
| 102 | std::cout << "cmGetPipes() returned an error" << std::endl; |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | cm::uv_loop_ptr loop; |
| 107 | loop.init(); |
| 108 | |
| 109 | cm::uv_pipe_ptr pipeRead; |
| 110 | pipeRead.init(*loop, 0); |
| 111 | uv_pipe_open(pipeRead, pipe[0]); |
| 112 | |
| 113 | cm::uv_pipe_ptr pipeWrite; |
| 114 | pipeWrite.init(*loop, 0); |
| 115 | uv_pipe_open(pipeWrite, pipe[1]); |
| 116 | |
| 117 | char c = '.'; |
| 118 | uv_buf_t buf = uv_buf_init(&c, sizeof(c)); |
| 119 | int status = -1; |
| 120 | auto cb = std::make_shared<std::function<void(int)>>( |
| 121 | [&status](int s) { status = s; }); |
| 122 | |
| 123 | // Test getting a callback after the write is done. |
| 124 | cm::uv_write(pipeWrite, &buf, 1, cb); |
| 125 | uv_run(loop, UV_RUN_DEFAULT); |
| 126 | if (status != 0) { |
| 127 | std::cout << "cm::uv_write non-zero status: " << status << std::endl; |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | // Test deleting the callback before it is made. |
| 132 | status = -1; |
| 133 | cm::uv_write(pipeWrite, &buf, 1, cb); |
| 134 | cb.reset(); |
| 135 | uv_run(loop, UV_RUN_DEFAULT); |
| 136 | if (status != -1) { |
| 137 | std::cout << "cm::uv_write callback incorrectly called with status: " |
| 138 | << status << std::endl; |
| 139 | return false; |
| 140 | } |
| 141 | |
| 142 | return true; |
| 143 | } |
| 144 | |
| 145 | int testUVHandlePtr(int, char** const) |
| 146 | { |
no test coverage detected
searching dependent graphs…