|
28 | 28 |
|
29 | 29 | using namespace ::testing; // NOLINT
|
30 | 30 |
|
| 31 | +std::string GetLastErrorStr() |
| 32 | +{ |
| 33 | + LPVOID lp_msg_buf; |
| 34 | + DWORD err_code = GetLastError(); |
| 35 | + std::string result_str("Error code:" + std::to_string(err_code) + ". Error message: "); |
| 36 | + |
| 37 | + DWORD buff_len = FormatMessage( |
| 38 | + FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 39 | + FORMAT_MESSAGE_FROM_SYSTEM | |
| 40 | + FORMAT_MESSAGE_IGNORE_INSERTS, |
| 41 | + NULL, |
| 42 | + err_code, |
| 43 | + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 44 | + (LPTSTR) &lp_msg_buf, |
| 45 | + 0, NULL); |
| 46 | + if (buff_len) { |
| 47 | + LPCSTR lpc_msg_str = (LPCSTR)(lp_msg_buf); |
| 48 | + result_str.append(std::string(lpc_msg_str, lpc_msg_str + buff_len)); |
| 49 | + } |
| 50 | + LocalFree(lp_msg_buf); |
| 51 | + return result_str; |
| 52 | +} |
| 53 | + |
31 | 54 | struct Process
|
32 | 55 | {
|
33 | 56 | PROCESS_INFORMATION process_info;
|
@@ -148,13 +171,15 @@ void stop_execution(
|
148 | 171 | switch (signum) {
|
149 | 172 | // According to the
|
150 | 173 | // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/signal?view=msvc-170
|
151 |
| - // SIGINT and SIGBREAK is not supported for any Win32 application. |
| 174 | + // SIGINT is not supported for any Win32 application. |
152 | 175 | // Need to use native Windows control event instead.
|
153 | 176 | case SIGINT:
|
154 |
| - EXPECT_TRUE(GenerateConsoleCtrlEvent(CTRL_C_EVENT, handle.process_info.dwProcessId)); |
| 177 | + EXPECT_TRUE(GenerateConsoleCtrlEvent(CTRL_C_EVENT, handle.process_info.dwProcessId)) << |
| 178 | + GetLastErrorStr(); |
155 | 179 | break;
|
156 | 180 | case SIGBREAK:
|
157 |
| - EXPECT_TRUE(GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, handle.process_info.dwProcessId)); |
| 181 | + EXPECT_TRUE(GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, handle.process_info.dwProcessId)) << |
| 182 | + GetLastErrorStr(); |
158 | 183 | break;
|
159 | 184 | case SIGTERM:
|
160 | 185 | // The CTRL_CLOSE_EVENT is analog of the SIGTERM from POSIX. Windows sends CTRL_CLOSE_EVENT
|
|
0 commit comments