mirror of
https://github.com/boostorg/process.git
synced 2026-01-20 04:42:24 +00:00
Squash after invalid branch & merge conflict. * Fixed file_descriptor move assignment operator to return a reference to 'this'. Issue # 219 * Returning *this instead of erroneous *this. Issue # 219 * Removed unneeded WNOHANG. * Closes boostorg/process#190 * Closes boostorg/process#121 * Attempting to fix wchar_t build error on circle. * Closes boostorg/process#197. * Changed child(pid_t) signature. * Multiple fixes. * Closes boostorg/process#189. * Closes boostorg/process#191. * Added missing work guard on windows. * Trying to catch windows early complete. * Increased log level on windows. * Multiple windows test fixes * Removed overly constraint tests. * fix missing headers * Closes klemens-morgenstern/boost-process#218 * Update executor.hpp explicit cast to int to silence this: `error: non-constant-expression cannot be narrowed from type 'unsigned long' to 'int' in initializer list [-Wc++11-narrowing]` * Fix posix implementation of move constructor/assignment in file_descriptor * Adjust docs `@boost` relative paths * Fixed UB for large environment names. * Closes boostorg/process#207. * Drone setup * Added include for filesystem::fstream. * Disabled useless tests. * Fixed environment length checks. * Pipe test & warning fixes. * Disabled warnings & added windows include fix. * More test fixes. * Removed some tests from apple build. * Removed some tests from apple build. * Disabled OSX tests via build script & fixed windows examples. * TSA fix attempt. Co-authored-by: James Baker <james.baker@bullochtech.com> Co-authored-by: silent <silent@symica.com> Co-authored-by: ikrijan <62850248+ikrijan@users.noreply.github.com> Co-authored-by: Shauren <shauren.trinity@gmail.com> Co-authored-by: alandefreitas <alandefreitas@gmail.com>
147 lines
3.5 KiB
C++
147 lines
3.5 KiB
C++
// Copyright (c) 2016 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)
|
|
|
|
|
|
#define BOOST_TEST_MAIN
|
|
|
|
#include <boost/test/included/unit_test.hpp>
|
|
#include <iostream>
|
|
#include <thread>
|
|
#include <vector>
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
#include <boost/process/async_pipe.hpp>
|
|
#include <boost/process/pipe.hpp>
|
|
#include <boost/asio/read.hpp>
|
|
#include <boost/asio/read_until.hpp>
|
|
#include <boost/asio/write.hpp>
|
|
#include <boost/asio/streambuf.hpp>
|
|
|
|
using namespace std;
|
|
namespace bp = boost::process;
|
|
namespace asio = boost::asio;
|
|
|
|
BOOST_AUTO_TEST_SUITE( async );
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(plain_async, *boost::unit_test::timeout(5))
|
|
{
|
|
asio::io_context ios;
|
|
bp::async_pipe pipe{ios};
|
|
|
|
std::string st = "test-string\n";
|
|
|
|
asio::streambuf buf;
|
|
|
|
asio::async_write(pipe, asio::buffer(st), [](const boost::system::error_code &, std::size_t){});
|
|
asio::async_read_until(pipe, buf, '\n', [](const boost::system::error_code &, std::size_t){});
|
|
|
|
ios.run();
|
|
|
|
std::string line;
|
|
std::istream istr(&buf);
|
|
BOOST_CHECK(std::getline(istr, line));
|
|
|
|
line.resize(11);
|
|
BOOST_CHECK_EQUAL(line, "test-string");
|
|
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(closed_transform)
|
|
{
|
|
asio::io_context ios;
|
|
|
|
bp::async_pipe ap{ios};
|
|
|
|
BOOST_CHECK(ap.is_open());
|
|
bp::pipe p2 = static_cast<bp::pipe>(ap);
|
|
BOOST_CHECK(p2.is_open());
|
|
|
|
ap.close();
|
|
BOOST_CHECK(!ap.is_open());
|
|
|
|
bp::pipe p = static_cast<bp::pipe>(ap);
|
|
BOOST_CHECK(!p.is_open());
|
|
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(multithreaded_async_pipe)
|
|
{
|
|
asio::io_context ioc;
|
|
|
|
std::vector<std::thread> threads;
|
|
for (int i = 0; i < std::thread::hardware_concurrency(); i++)
|
|
{
|
|
threads.emplace_back([&ioc]
|
|
{
|
|
std::vector<bp::async_pipe*> pipes;
|
|
for (size_t i = 0; i < 100; i++)
|
|
pipes.push_back(new bp::async_pipe(ioc));
|
|
for (auto &p : pipes)
|
|
delete p;
|
|
});
|
|
}
|
|
for (auto &t : threads)
|
|
t.join();
|
|
}
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(move_pipe)
|
|
{
|
|
asio::io_context ios;
|
|
|
|
bp::async_pipe ap{ios};
|
|
BOOST_TEST_CHECKPOINT("First move");
|
|
bp::async_pipe ap2{std::move(ap)};
|
|
#if defined(BOOST_WINDOWS_API)
|
|
BOOST_CHECK_EQUAL(ap.native_source(), ::boost::winapi::INVALID_HANDLE_VALUE_);
|
|
BOOST_CHECK_EQUAL(ap.native_sink (), ::boost::winapi::INVALID_HANDLE_VALUE_);
|
|
#elif defined(BOOST_POSIX_API)
|
|
BOOST_CHECK_EQUAL(ap.native_source(), -1);
|
|
BOOST_CHECK_EQUAL(ap.native_sink (), -1);
|
|
#endif
|
|
|
|
BOOST_TEST_CHECKPOINT("Second move");
|
|
ap = std::move(ap2);
|
|
|
|
{
|
|
BOOST_TEST_CHECKPOINT("Third move, from closed");
|
|
bp::async_pipe ap_inv{ios};
|
|
ap_inv.close();
|
|
ap = std::move(ap_inv);
|
|
}
|
|
|
|
{
|
|
BOOST_TEST_CHECKPOINT("Fourth move, from closed");
|
|
bp::async_pipe ap_inv{ios};
|
|
ap_inv.close();
|
|
const auto ap3 = std::move(ap_inv);
|
|
}
|
|
/*
|
|
{
|
|
//copy an a closed pipe
|
|
BOOST_TEST_CHECKPOINT("Copy assign");
|
|
BOOST_TEST_CHECKPOINT("Fourth move, from closed");
|
|
bp::async_pipe ap_inv{ios};
|
|
ap_inv.close();
|
|
ap = ap_inv; //copy an invalid pipe
|
|
}
|
|
|
|
{
|
|
//copy an a closed pipe
|
|
BOOST_TEST_CHECKPOINT("Copy assign");
|
|
BOOST_TEST_CHECKPOINT("Fourth move, from closed");
|
|
bp::async_pipe ap_inv{ios};
|
|
ap_inv.close();
|
|
BOOST_TEST_CHECKPOINT("Copy construct");
|
|
bp::async_pipe ap4{ap_inv};
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END(); |