// 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 #include #include #include #include #include #include #include #include #include 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 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 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 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();