combine_test.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Distributed under the Boost Software License, Version 1.0.(See accompanying
  3. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  4. *
  5. * See http://www.boost.org/libs/iostreams for documentation.
  6. *
  7. * Verifies that the close() member functions of filters and devices
  8. * are called with the correct arguments in the correct order when
  9. * they are combined using combine().
  10. *
  11. * File: libs/iostreams/test/combine_test.cpp
  12. * Date: Sun Jan 06 01:37:37 MST 2008
  13. * Copyright: 2007-2008 CodeRage, LLC
  14. * Author: Jonathan Turkanis
  15. * Contact: turkanis at coderage dot com
  16. */
  17. #include <boost/iostreams/chain.hpp>
  18. #include <boost/iostreams/combine.hpp>
  19. #include <boost/test/test_tools.hpp>
  20. #include <boost/test/unit_test.hpp>
  21. #include "detail/closable.hpp"
  22. #include "detail/operation_sequence.hpp"
  23. using namespace boost::iostreams;
  24. using namespace boost::iostreams::test;
  25. using boost::unit_test::test_suite;
  26. namespace io = boost::iostreams;
  27. void combine_test()
  28. {
  29. // Combine a source and a sink
  30. {
  31. operation_sequence seq;
  32. chain<bidirectional> ch;
  33. ch.push(
  34. io::combine(
  35. closable_device<input>(seq.new_operation(1)),
  36. closable_device<output>(seq.new_operation(2))
  37. )
  38. );
  39. BOOST_CHECK_NO_THROW(ch.reset());
  40. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  41. }
  42. // Combine two bidirectional devices
  43. {
  44. operation_sequence seq;
  45. chain<bidirectional> ch;
  46. ch.push(
  47. io::combine(
  48. closable_device<bidirectional>(
  49. seq.new_operation(1),
  50. seq.new_operation(2)
  51. ),
  52. closable_device<bidirectional>(
  53. seq.new_operation(3),
  54. seq.new_operation(4)
  55. )
  56. )
  57. );
  58. BOOST_CHECK_NO_THROW(ch.reset());
  59. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  60. }
  61. // Combine two seekable devices
  62. {
  63. operation_sequence seq;
  64. chain<bidirectional> ch;
  65. ch.push(
  66. io::combine(
  67. closable_device<seekable>(seq.new_operation(1)),
  68. closable_device<seekable>(seq.new_operation(2))
  69. )
  70. );
  71. BOOST_CHECK_NO_THROW(ch.reset());
  72. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  73. }
  74. // Combine an input filter and an output filter
  75. {
  76. operation_sequence seq;
  77. chain<bidirectional> ch;
  78. ch.push(
  79. io::combine(
  80. closable_filter<input>(seq.new_operation(2)),
  81. closable_filter<output>(seq.new_operation(3))
  82. )
  83. );
  84. ch.push(
  85. closable_device<bidirectional>(
  86. seq.new_operation(1),
  87. seq.new_operation(4)
  88. )
  89. );
  90. BOOST_CHECK_NO_THROW(ch.reset());
  91. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  92. }
  93. // Combine two bidirectional filters
  94. {
  95. operation_sequence seq;
  96. chain<bidirectional> ch;
  97. ch.push(
  98. io::combine(
  99. closable_filter<bidirectional>(
  100. seq.new_operation(2),
  101. seq.new_operation(3)
  102. ),
  103. closable_filter<bidirectional>(
  104. seq.new_operation(4),
  105. seq.new_operation(5)
  106. )
  107. )
  108. );
  109. ch.push(
  110. closable_device<bidirectional>(
  111. seq.new_operation(1),
  112. seq.new_operation(6)
  113. )
  114. );
  115. BOOST_CHECK_NO_THROW(ch.reset());
  116. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  117. }
  118. // Combine two seekable filters
  119. {
  120. operation_sequence seq;
  121. chain<bidirectional> ch;
  122. ch.push(
  123. io::combine(
  124. closable_filter<seekable>(seq.new_operation(2)),
  125. closable_filter<seekable>(seq.new_operation(3))
  126. )
  127. );
  128. ch.push(
  129. closable_device<bidirectional>(
  130. seq.new_operation(1),
  131. seq.new_operation(4)
  132. )
  133. );
  134. BOOST_CHECK_NO_THROW(ch.reset());
  135. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  136. }
  137. // Combine a dual-use filter and an input filter
  138. {
  139. operation_sequence seq;
  140. chain<bidirectional> ch;
  141. operation dummy;
  142. ch.push(
  143. io::combine(
  144. closable_filter<input>(seq.new_operation(2)),
  145. closable_filter<dual_use>(
  146. dummy,
  147. seq.new_operation(3)
  148. )
  149. )
  150. );
  151. ch.push(
  152. closable_device<bidirectional>(
  153. seq.new_operation(1),
  154. seq.new_operation(4)
  155. )
  156. );
  157. BOOST_CHECK_NO_THROW(ch.reset());
  158. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  159. }
  160. // Combine a dual-use filter and an output filter
  161. {
  162. operation_sequence seq;
  163. chain<bidirectional> ch;
  164. operation dummy;
  165. ch.push(
  166. io::combine(
  167. closable_filter<dual_use>(
  168. seq.new_operation(2),
  169. dummy
  170. ),
  171. closable_filter<output>(seq.new_operation(3))
  172. )
  173. );
  174. ch.push(
  175. closable_device<bidirectional>(
  176. seq.new_operation(1),
  177. seq.new_operation(4)
  178. )
  179. );
  180. BOOST_CHECK_NO_THROW(ch.reset());
  181. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  182. }
  183. // Combine two dual-use filters
  184. {
  185. operation_sequence seq;
  186. chain<bidirectional> ch;
  187. operation dummy;
  188. ch.push(
  189. io::combine(
  190. closable_filter<dual_use>(
  191. seq.new_operation(2),
  192. dummy
  193. ),
  194. closable_filter<dual_use>(
  195. dummy,
  196. seq.new_operation(3)
  197. )
  198. )
  199. );
  200. ch.push(
  201. closable_device<bidirectional>(
  202. seq.new_operation(1),
  203. seq.new_operation(4)
  204. )
  205. );
  206. BOOST_CHECK_NO_THROW(ch.reset());
  207. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  208. }
  209. }
  210. test_suite* init_unit_test_suite(int, char* [])
  211. {
  212. test_suite* test = BOOST_TEST_SUITE("combine test");
  213. test->add(BOOST_TEST_CASE(&combine_test));
  214. return test;
  215. }