#include "test_harness.hpp" #ifdef COOP_TEST_HARNESS #include #include namespace coop { namespace { std::wstring temp_file(const wchar_t* name) { wchar_t dir[MAX_PATH] = {}; const DWORD n = GetTempPathW(MAX_PATH, dir); return (n != 0 && n < MAX_PATH) ? std::wstring(dir) + name : std::wstring(name); } } // namespace void TestHarness::init() { cmd_path_ = temp_file(L"coop_test_cmd.txt"); resp_path_ = temp_file(L"coop_test_resp.txt"); DeleteFileW(cmd_path_.c_str()); // drop any stale command from a previous run DeleteFileW(resp_path_.c_str()); } std::string TestHarness::poll_command() { std::ifstream f(cmd_path_.c_str()); // MSVC accepts a wide path if (!f) { return {}; } std::string line; std::getline(f, line); f.close(); DeleteFileW(cmd_path_.c_str()); // ack: the command has been taken return line; } void TestHarness::write_response(const std::string& resp) { std::ofstream f(resp_path_.c_str(), std::ios::trunc); f << resp; } } // namespace coop #endif // COOP_TEST_HARNESS