From a864099ba77157090c4cd12817245122c163ec24 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sat, 24 Oct 2020 21:33:44 +0300 Subject: rework Process API & tests * Add separate classes ProcessParameters & ShellParameters for Process::create() and Process::shell() methods. * Add a separate "worker" executable. It's used in tests via a fairly complicated scheme, receiving orders to execute via a shared memory region. * Add tests that utilize the Console API, reading console window's screen buffer directly, making for more reliable tests & broader coverage. --- test/unit_tests/fixtures.hpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'test/unit_tests/fixtures.hpp') diff --git a/test/unit_tests/fixtures.hpp b/test/unit_tests/fixtures.hpp index 293ad35..aaf6571 100644 --- a/test/unit_tests/fixtures.hpp +++ b/test/unit_tests/fixtures.hpp @@ -5,6 +5,8 @@ #pragma once +#include "shared/command.hpp" + #include #include #include @@ -34,18 +36,13 @@ private: RemoveFileGuard& operator=(const RemoveFileGuard&) = delete; }; -class WithEchoExe { +class WithParam { public: - WithEchoExe() : m_echo_exe(find_echo_exe()) {} + WithParam(const std::string& param_prefix) : m_value(find_param_value(param_prefix)) {} - const std::string& get_echo_exe() { return m_echo_exe; } + const std::string& get_value() { return m_value; } private: - static std::string find_echo_exe() { - static const std::string prefix{"--echo_exe="}; - return find_param_value(prefix); - } - static std::string find_param_value(const std::string& param_prefix) { const auto cmd_line = winapi::CommandLine::query(); const auto& args = cmd_line.get_args(); @@ -57,5 +54,21 @@ private: throw std::runtime_error{"couldn't find parameter " + param_prefix}; } - std::string m_echo_exe; + std::string m_value; +}; + +class WithEchoExe : public WithParam { +public: + WithEchoExe() : WithParam{"--echo_exe="} {} + + const std::string& get_echo_exe() { return get_value(); } +}; + +class WithWorkerExe : public WithParam { +public: + WithWorkerExe() : WithParam{"--worker_exe="}, m_cmd{worker::Command::create()} {} + + const std::string& get_worker_exe() { return get_value(); } + + worker::Command::Shared m_cmd; }; -- cgit v1.2.3