aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-16 18:16:22 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-16 21:20:25 +0300
commit6a3fa57f21fd31b42178b0a5a4872b2341da58f9 (patch)
treed44598e6d51318a6463f24dcbd480dbe2d66cb6c
parentadd path.hpp: CanonicalPath class, etc. (diff)
downloadwinapi-common-6a3fa57f21fd31b42178b0a5a4872b2341da58f9.tar.gz
winapi-common-6a3fa57f21fd31b42178b0a5a4872b2341da58f9.zip
some more process creation tests
-rw-r--r--test/unit_tests/process.cpp37
1 files 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 <winapi/cmd_line.hpp>
+#include <winapi/file.hpp>
+#include <winapi/path.hpp>
#include <winapi/pipe.hpp>
#include <winapi/process.hpp>
#include <winapi/utf8.hpp>
@@ -15,6 +17,7 @@
#include <utility>
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()