invert_test.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2004-2007 Jonathan Turkanis
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  5. // See http://www.boost.org/libs/iostreams for documentation.
  6. #include <boost/iostreams/device/file.hpp>
  7. #include <boost/iostreams/filter/test.hpp>
  8. #include <boost/iostreams/invert.hpp>
  9. #include <boost/test/test_tools.hpp>
  10. #include <boost/test/unit_test.hpp>
  11. #include "detail/closable.hpp"
  12. #include "detail/filters.hpp"
  13. #include "detail/operation_sequence.hpp"
  14. #include "detail/temp_file.hpp"
  15. using namespace boost::iostreams;
  16. using namespace boost::iostreams::test;
  17. using boost::unit_test::test_suite;
  18. namespace io = boost::iostreams;
  19. void read_write_test()
  20. {
  21. test_file test;
  22. lowercase_file lower;
  23. uppercase_file upper;
  24. BOOST_CHECK( test_input_filter(
  25. invert(tolower_filter()),
  26. file_source(test.name(), in_mode),
  27. file_source(lower.name(), in_mode) ) );
  28. BOOST_CHECK( test_output_filter(
  29. invert(toupper_filter()),
  30. file_source(test.name(), in_mode),
  31. file_source(upper.name(), in_mode) ) );
  32. }
  33. void close_test()
  34. {
  35. // Invert an output filter
  36. {
  37. operation_sequence seq;
  38. chain<input> ch;
  39. ch.push(io::invert(closable_filter<output>(seq.new_operation(2))));
  40. ch.push(closable_device<input>(seq.new_operation(1)));
  41. BOOST_CHECK_NO_THROW(ch.reset());
  42. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  43. }
  44. // Invert an input filter
  45. {
  46. operation_sequence seq;
  47. chain<output> ch;
  48. ch.push(io::invert(closable_filter<input>(seq.new_operation(1))));
  49. ch.push(closable_device<output>(seq.new_operation(2)));
  50. BOOST_CHECK_NO_THROW(ch.reset());
  51. BOOST_CHECK_OPERATION_SEQUENCE(seq);
  52. }
  53. }
  54. test_suite* init_unit_test_suite(int, char* [])
  55. {
  56. test_suite* test = BOOST_TEST_SUITE("reverse test");
  57. test->add(BOOST_TEST_CASE(&read_write_test));
  58. test->add(BOOST_TEST_CASE(&close_test));
  59. return test;
  60. }