aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-10-15 03:29:20 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-10-15 10:39:54 +0300
commitd24ef6058f2d60100be44507d46014ef30010493 (patch)
treeb355d18a2b0f963a6fad9af9f6fa67b2850d31cf /test
parenttest: add test utility "args" (diff)
downloadwinapi-common-d24ef6058f2d60100be44507d46014ef30010493.tar.gz
winapi-common-d24ef6058f2d60100be44507d46014ef30010493.zip
WIP: add simple Process class
Diffstat (limited to 'test')
-rw-r--r--test/unit_tests/process.cpp55
1 files changed, 55 insertions, 0 deletions
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 <Egor.Tensin@gmail.com>
+// 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 <winapi/cmd_line.hpp>
+#include <winapi/process.hpp>
+
+#include <boost/test/unit_test.hpp>
+
+#include <stdexcept>
+#include <string>
+
+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()