MCPcopy Create free account
hub / github.com/Kitware/CMake / testWriteCallback

Function testWriteCallback

Tests/CMakeLib/testUVHandlePtr.cxx:98–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98static 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
145int testUVHandlePtr(int, char** const)
146{

Callers 1

testUVHandlePtrFunction · 0.85

Calls 7

cmGetPipesFunction · 0.85
uv_buf_initFunction · 0.85
uv_pipe_openFunction · 0.50
uv_writeFunction · 0.50
uv_runFunction · 0.50
initMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…