Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / process / test / windows_specific.cpp
1 // Copyright (c) 2006, 2007 Julio M. Merino Vidal
2 // Copyright (c) 2008 Ilya Sokolov, Boris Schaeling
3 // Copyright (c) 2009 Boris Schaeling
4 // Copyright (c) 2010 Felipe Tanus, Boris Schaeling
5 // Copyright (c) 2011, 2012 Jeff Flinn, Boris Schaeling
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
10 #define BOOST_TEST_MAIN
11 #define BOOST_TEST_IGNORE_SIGCHLD
12 #include <boost/test/included/unit_test.hpp>
13 #include <boost/process.hpp>
14 #include <boost/process/windows.hpp>
15 #include <boost/process/extend.hpp>
16 #include <boost/system/error_code.hpp>
17
18 #include <string>
19
20 namespace bp = boost::process;
21
22 BOOST_AUTO_TEST_CASE(show_window)
23 {
24     using boost::unit_test::framework::master_test_suite;
25
26     bp::ipstream is;
27
28     std::error_code ec;
29     bp::child c(
30         master_test_suite().argv[1],
31         "test", "--windows-print-showwindow",
32         bp::windows::show_normal,
33         bp::std_out>is,
34         ec
35     );
36     BOOST_REQUIRE(!ec);
37
38     int i;
39     is >> i;
40     BOOST_CHECK_EQUAL(i, SW_SHOWNORMAL);
41 }
42
43
44 #if ( BOOST_USE_WINAPI_VERSION >= BOOST_WINAPI_VERSION_WIN6 )
45
46 struct set_startup_info
47 {
48     int &cnt;
49     template<typename T>
50     void operator()(T &e) const
51     {
52         cnt++;
53         BOOST_CHECK_EQUAL(e.startup_info.cb, sizeof(::boost::detail::winapi::STARTUPINFOA_));
54         e.set_startup_info_ex();
55     }
56
57 };
58
59 struct check_startup_info
60 {
61     int &cnt;
62     template<typename T>
63     void operator()(T &e) const
64     {
65         cnt++;
66         BOOST_CHECK(e.creation_flags &  ::boost::detail::winapi::EXTENDED_STARTUPINFO_PRESENT_);
67         BOOST_CHECK_EQUAL(e.startup_info.cb, sizeof(::boost::detail::winapi::STARTUPINFOEXA_));
68     }
69
70 };
71
72 BOOST_AUTO_TEST_CASE(startup_info_ex)
73 {
74     using boost::unit_test::framework::master_test_suite;
75
76     bp::ipstream is;
77
78     int cnt = 0;
79
80     std::error_code ec;
81     bp::child c(
82         master_test_suite().argv[1],
83         bp::extend::on_setup(set_startup_info{cnt}),
84         bp::extend::on_success(check_startup_info{cnt}),
85         bp::std_out>is,
86         ec
87     );
88     BOOST_REQUIRE(!ec);
89     BOOST_CHECK_EQUAL(cnt, 2);
90 }
91
92 #endif