File: windows.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (96 lines) | stat: -rw-r--r-- 2,933 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
// 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();