From d24ef6058f2d60100be44507d46014ef30010493 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Thu, 15 Oct 2020 03:29:20 +0300 Subject: WIP: add simple Process class --- test/unit_tests/process.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/unit_tests/process.cpp (limited to 'test') diff --git a/test/unit_tests/process.cpp b/test/unit_tests/process.cpp new file mode 100644 index 0000000..69327e1 --- /dev/null +++ b/test/unit_tests/process.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2020 Egor Tensin +// This file is part of the "winapi-common" project. +// For details, see https://github.com/egor-tensin/winapi-common. +// Distributed under the MIT License. + +#include +#include + +#include + +#include +#include + +namespace { + +class WhereTestExe { +public: + WhereTestExe() : m_test_exe(find_test_exe()) {} + + const std::string& get_test_exe() { return m_test_exe; } + +private: + static std::string find_test_exe() { + static const std::string param_prefix{"--test_exe="}; + const auto cmd_line = winapi::CommandLine::query(); + const auto& args = cmd_line.get_args(); + for (const auto& arg : args) { + if (arg.rfind(param_prefix, 0) == 0) { + return arg.substr(param_prefix.length()); + } + } + throw std::runtime_error{"couldn't find parameter --test_exe"}; + } + + const std::string m_test_exe; +}; + +} // namespace + +BOOST_AUTO_TEST_SUITE(process_tests) + +BOOST_AUTO_TEST_CASE(create_dir) { + const winapi::CommandLine cmd_line{"cmd.exe", {"/c", "dir"}}; + auto process = winapi::Process::create(cmd_line); + process.wait(); +} + +BOOST_FIXTURE_TEST_CASE(create_test_exe, WhereTestExe) { + const winapi::CommandLine cmd_line{get_test_exe()}; + auto process = winapi::Process::create(cmd_line); + process.wait(); + BOOST_TEST(true, "Successfully created test process"); +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3