mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 16:32:15 +00:00
* Make the library modular usable. * Switch to library requirements instead of source. As source puts extra source in install targets. * Add requires-b2 check to top-level build file. * Add missing test deps. * Bump B2 require to 5.2 * Fix duplicate def of boost.process.fs feature. * Add missing boost_test dependency. * Move inter-lib dependencies to a project variable and into the build targets. * Switch to /boost/test//included target for header only mode of Boost.Test. * Adjust doc build to avoid boost-root references. * Update build deps. * Fix link and build of deps.
97 lines
2.9 KiB
C++
97 lines
2.9 KiB
C++
// Copyright (c) 2022 Klemens D. Morgenstern
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
|
// Disable autolinking for unit tests.
|
|
#if !defined(BOOST_ALL_NO_LIB)
|
|
#define BOOST_ALL_NO_LIB 1
|
|
#endif // !defined(BOOST_ALL_NO_LIB)
|
|
|
|
// Test that header file is self-contained.
|
|
#include <boost/process/v2/process.hpp>
|
|
|
|
|
|
#include <boost/process/v2/windows/as_user_launcher.hpp>
|
|
#include <boost/process/v2/windows/creation_flags.hpp>
|
|
#include <boost/process/v2/windows/show_window.hpp>
|
|
#include <boost/process/v2/windows/with_logon_launcher.hpp>
|
|
#include <boost/process/v2/windows/with_token_launcher.hpp>
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
#include <boost/asio/io_context.hpp>
|
|
|
|
#include <fstream>
|
|
#include <thread>
|
|
|
|
namespace bpv = boost::process::v2;
|
|
namespace asio = boost::asio;
|
|
|
|
BOOST_AUTO_TEST_SUITE(windows);
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(show_window)
|
|
{
|
|
using boost::unit_test::framework::master_test_suite;
|
|
asio::io_context ctx;
|
|
const auto pth = master_test_suite().argv[1];
|
|
bpv::process proc{ctx, pth, {"showwindow"}};
|
|
|
|
BOOST_CHECK_EQUAL(proc.wait(), 0);
|
|
|
|
proc = bpv::process{ctx, pth, {"showwindow"}, bpv::windows::show_window_minimized_not_active};
|
|
BOOST_CHECK_EQUAL(proc.wait(), SW_SHOWMINNOACTIVE);
|
|
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(as_user_launcher)
|
|
{
|
|
using boost::unit_test::framework::master_test_suite;
|
|
const auto pth = master_test_suite().argv[1];
|
|
|
|
asio::io_context ctx;
|
|
std::vector<std::string> args = {"exit-code", "2"};
|
|
|
|
HANDLE token_handle = INVALID_HANDLE_VALUE;
|
|
BOOST_CHECK(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY, &token_handle) != 0);
|
|
bpv::error_code ec;
|
|
auto proc = bpv::windows::as_user_launcher(token_handle)(ctx, ec, pth, args);
|
|
BOOST_CHECK_EQUAL(proc.wait(), 2);
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(with_logon_launcher)
|
|
{
|
|
using boost::unit_test::framework::master_test_suite;
|
|
const auto pth = master_test_suite().argv[1];
|
|
|
|
asio::io_context ctx;
|
|
std::vector<std::string> args = {"exit-code", "42"};
|
|
|
|
bpv::error_code ec;
|
|
auto proc = bpv::windows::with_logon_launcher(L"idiot", L"changeme")(ctx, ec, pth, args);
|
|
BOOST_CHECK_EQUAL(ec.value(), ERROR_INVALID_PARAMETER);
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(with_token_launcher)
|
|
{
|
|
using boost::unit_test::framework::master_test_suite;
|
|
const auto pth = master_test_suite().argv[1];
|
|
|
|
asio::io_context ctx;
|
|
std::vector<std::string> args = {"exit-code", "2"};
|
|
|
|
HANDLE token_handle = INVALID_HANDLE_VALUE;
|
|
BOOST_CHECK(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY, &token_handle) != 0);
|
|
bpv::error_code ec;
|
|
auto proc = bpv::windows::with_token_launcher(nullptr)(ctx, ec, pth, args);
|
|
BOOST_CHECK_EQUAL(ec.value(), ERROR_INVALID_PARAMETER);
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END();
|
|
|