From 6a3fa57f21fd31b42178b0a5a4872b2341da58f9 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 16 Oct 2020 18:16:22 +0300 Subject: some more process creation tests --- test/unit_tests/process.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/test/unit_tests/process.cpp b/test/unit_tests/process.cpp index 57deef0..aa09bf4 100644 --- a/test/unit_tests/process.cpp +++ b/test/unit_tests/process.cpp @@ -4,6 +4,8 @@ // Distributed under the MIT License. #include +#include +#include #include #include #include @@ -15,6 +17,7 @@ #include using namespace winapi; +using namespace winapi::process; namespace { @@ -48,29 +51,43 @@ private: BOOST_AUTO_TEST_SUITE(process_tests) -BOOST_FIXTURE_TEST_CASE(create_echo, WithEchoExe) { +BOOST_FIXTURE_TEST_CASE(echo, WithEchoExe) { const CommandLine cmd_line{get_echo_exe()}; - auto process = Process::create(cmd_line); + const auto process = Process::create(cmd_line); process.wait(); - BOOST_TEST(true, "Successfully created test process"); + BOOST_TEST(process.get_exit_code() == 0); } -BOOST_FIXTURE_TEST_CASE(create_echo_with_args, WithEchoExe) { +BOOST_FIXTURE_TEST_CASE(echo_with_args, WithEchoExe) { const CommandLine cmd_line{get_echo_exe(), {"1", "2", "3"}}; - auto process = Process::create(cmd_line); + const auto process = Process::create(cmd_line); process.wait(); + BOOST_TEST(process.get_exit_code() == 0); } -BOOST_FIXTURE_TEST_CASE(create_echo_pipe, WithEchoExe) { - const CommandLine cmd_line{get_echo_exe(), {"1", "2", "3"}}; +BOOST_FIXTURE_TEST_CASE(echo_stdout_to_pipe, WithEchoExe) { + const CommandLine cmd_line{get_echo_exe(), {"aaa", "bbb", "ccc"}}; Process::IO io; Pipe stdout_pipe; - io.std_out = process::Stdout{stdout_pipe}; - auto process = Process::create(cmd_line, std::move(io)); + io.std_out = Stdout{stdout_pipe}; + const auto process = Process::create(cmd_line, std::move(io)); const auto output = stdout_pipe.read_end().read(); process.wait(); + BOOST_TEST(process.get_exit_code() == 0); + const auto utf8 = narrow(output); + BOOST_TEST(utf8 == "aaa\r\nbbb\r\nccc\r\n"); +} + +BOOST_FIXTURE_TEST_CASE(echo_stdout_to_file, WithEchoExe) { + const CommandLine cmd_line{get_echo_exe(), {"XXX", "YYY", "ZZZ"}}; + Process::IO io; + io.std_out = Stdout{CanonicalPath{"test.txt"}}; + const auto process = Process::create(cmd_line, std::move(io)); + process.wait(); + BOOST_TEST(process.get_exit_code() == 0); + const auto output = File::open_for_reading(CanonicalPath{"test.txt"}).read(); const auto utf8 = narrow(output); - BOOST_TEST(utf8 == "1\r\n2\r\n3\r\n"); + BOOST_TEST(utf8 == "XXX\r\nYYY\r\nZZZ\r\n"); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3