The ctor redirects the stream to a temporary file.
| 8290 | public: |
| 8291 | // The ctor redirects the stream to a temporary file. |
| 8292 | CapturedStream(int fd) : fd_(fd), uncaptured_fd_(dup(fd)) { |
| 8293 | |
| 8294 | # if GTEST_OS_WINDOWS |
| 8295 | char temp_dir_path[MAX_PATH + 1] = { '\0' }; // NOLINT |
| 8296 | char temp_file_path[MAX_PATH + 1] = { '\0' }; // NOLINT |
| 8297 | |
| 8298 | ::GetTempPathA(sizeof(temp_dir_path), temp_dir_path); |
| 8299 | const UINT success = ::GetTempFileNameA(temp_dir_path, |
| 8300 | "gtest_redir", |
| 8301 | 0, // Generate unique file name. |
| 8302 | temp_file_path); |
| 8303 | GTEST_CHECK_(success != 0) |
| 8304 | << "Unable to create a temporary file in " << temp_dir_path; |
| 8305 | const int captured_fd = creat(temp_file_path, _S_IREAD | _S_IWRITE); |
| 8306 | GTEST_CHECK_(captured_fd != -1) << "Unable to open temporary file " |
| 8307 | << temp_file_path; |
| 8308 | filename_ = temp_file_path; |
| 8309 | # else |
| 8310 | // There's no guarantee that a test has write access to the |
| 8311 | // current directory, so we create the temporary file in the /tmp |
| 8312 | // directory instead. |
| 8313 | char name_template[] = "/tmp/captured_stream.XXXXXX"; |
| 8314 | const int captured_fd = mkstemp(name_template); |
| 8315 | filename_ = name_template; |
| 8316 | # endif // GTEST_OS_WINDOWS |
| 8317 | fflush(NULL); |
| 8318 | dup2(captured_fd, fd_); |
| 8319 | close(captured_fd); |
| 8320 | } |
| 8321 | |
| 8322 | ~CapturedStream() { |
| 8323 | remove(filename_.c_str()); |
nothing calls this directly
no outgoing calls
no test coverage detected