File: windows.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (113 lines) | stat: -rw-r--r-- 3,576 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// 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)

#if defined(BOOST_FILESYSTEM_DYN_LINK)
#undef BOOST_FILESYSTEM_DYN_LINK
#endif

// 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(creation_flags)
{
    using boost::unit_test::framework::master_test_suite;
    const auto pth = master_test_suite().argv[1];
    asio::io_context ctx;
    bpv::process proc{ctx, pth, {"creation-flags"}};

    BOOST_CHECK_EQUAL(proc.wait() & ~EXTENDED_STARTUPINFO_PRESENT, 0);

    proc = bpv::process{ctx, master_test_suite().argv[1], {"creation-flags"}, bpv::windows::process_creation_flags<STARTF_TITLEISAPPID>()};
    BOOST_CHECK(proc.running());
    BOOST_CHECK_EQUAL(proc.wait() & ~EXTENDED_STARTUPINFO_PRESENT, STARTF_TITLEISAPPID);
}

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();