1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2004-2007 Jonathan Turkanis
3 // (C) Copyright 2012 Boris Schaeling
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
7 // See http://www.boost.org/libs/iostreams for documentation.
10 #include <boost/iostreams/device/file_descriptor.hpp>
11 #include <boost/iostreams/filtering_stream.hpp>
12 #include <boost/iostreams/get.hpp>
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
16 using namespace boost::iostreams
;
17 using boost::unit_test::test_suite
;
19 void read_from_file_descriptor_source_test()
22 ::CreatePipe(&handles
[0], &handles
[1], NULL
, 0);
24 char buffer
[2] = { 'a', 'b' };
26 ::WriteFile(handles
[1], buffer
, 2, &written
, NULL
);
27 ::CloseHandle(handles
[1]);
29 file_descriptor_source
is(handles
[0], close_handle
);
31 BOOST_CHECK_EQUAL('a', get(is
));
32 BOOST_CHECK_EQUAL('b', get(is
));
33 BOOST_CHECK_EQUAL(-1, get(is
));
34 BOOST_CHECK_EQUAL(-1, get(is
));
37 void read_from_filtering_istream_test()
40 ::CreatePipe(&handles
[0], &handles
[1], NULL
, 0);
42 char buffer
[2] = { 'a', 'b' };
44 ::WriteFile(handles
[1], buffer
, 2, &written
, NULL
);
45 ::CloseHandle(handles
[1]);
47 file_descriptor_source
source(handles
[0], close_handle
);
51 BOOST_CHECK_EQUAL('a', get(is
));
52 BOOST_CHECK_EQUAL('b', get(is
));
53 BOOST_CHECK_EQUAL(-1, get(is
));
54 BOOST_CHECK_EQUAL(-1, get(is
));
57 test_suite
* init_unit_test_suite(int, char* [])
59 test_suite
* test
= BOOST_TEST_SUITE("Windows pipe test");
60 test
->add(BOOST_TEST_CASE(&read_from_file_descriptor_source_test
));
61 test
->add(BOOST_TEST_CASE(&read_from_filtering_istream_test
));