write_bidir_filter_test.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. #ifndef BOOST_IOSTREAMS_TEST_WRITE_INOUT_FILTER_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_INOUT_FILTER_HPP_INCLUDED
  8. #include <fstream>
  9. #include <boost/iostreams/combine.hpp>
  10. #include <boost/iostreams/filtering_stream.hpp>
  11. #include <boost/test/test_tools.hpp>
  12. #include "detail/filters.hpp"
  13. #include "detail/sequence.hpp"
  14. #include "detail/temp_file.hpp"
  15. #include "detail/verification.hpp"
  16. void write_bidirectional_filter_test()
  17. {
  18. using namespace std;
  19. using namespace boost;
  20. using namespace boost::iostreams;
  21. using namespace boost::iostreams::test;
  22. lowercase_file lower;
  23. BOOST_IOS::openmode mode = out_mode | BOOST_IOS::trunc;
  24. {
  25. temp_file lower2;
  26. filebuf dest;
  27. filtering_stream<bidirectional> out;
  28. dest.open(lower2.name().c_str(), mode);
  29. out.push(combine(toupper_filter(), tolower_filter()));
  30. out.push(dest);
  31. write_data_in_chars(out);
  32. out.reset();
  33. dest.close();
  34. BOOST_CHECK_MESSAGE(
  35. compare_files(lower2.name(), lower.name()),
  36. "failed writing to a filtering_stream<bidirectional> in chars with an "
  37. "output filter"
  38. );
  39. }
  40. {
  41. // OutputFilter.
  42. temp_file lower2;
  43. filebuf dest;
  44. filtering_stream<bidirectional> out;
  45. out.push(combine(toupper_filter(), tolower_filter()));
  46. dest.open(lower2.name().c_str(), mode);
  47. out.push(dest);
  48. write_data_in_chunks(out);
  49. out.reset();
  50. dest.close();
  51. BOOST_CHECK_MESSAGE(
  52. compare_files(lower2.name(), lower.name()),
  53. "failed writing to a filtering_stream<bidirectional> in chunks with an "
  54. "output filter"
  55. );
  56. }
  57. {
  58. temp_file lower2;
  59. filebuf dest;
  60. filtering_stream<bidirectional> out;
  61. out.push(combine(toupper_filter(), tolower_multichar_filter()), 0);
  62. dest.open(lower2.name().c_str(), mode);
  63. out.push(dest);
  64. write_data_in_chars(out);
  65. out.reset();
  66. dest.close();
  67. BOOST_CHECK_MESSAGE(
  68. compare_files(lower2.name(), lower.name()),
  69. "failed writing to a filtering_stream<bidirectional> in chars "
  70. "with a multichar output filter with no buffer"
  71. );
  72. }
  73. {
  74. temp_file lower2;
  75. filebuf dest;
  76. filtering_stream<bidirectional> out;
  77. out.push(combine(toupper_filter(), tolower_multichar_filter()), 0);
  78. dest.open(lower2.name().c_str(), mode);
  79. out.push(dest);
  80. write_data_in_chunks(out);
  81. out.reset();
  82. dest.close();
  83. BOOST_CHECK_MESSAGE(
  84. compare_files(lower2.name(), lower.name()),
  85. "failed writing to a filtering_stream<bidirectional> in chunks "
  86. "with a multichar output filter with no buffer"
  87. );
  88. }
  89. {
  90. temp_file lower2;
  91. filebuf dest;
  92. filtering_stream<bidirectional> out;
  93. out.push(combine(toupper_filter(), tolower_multichar_filter()));
  94. dest.open(lower2.name().c_str(), mode);
  95. out.push(dest);
  96. write_data_in_chars(out);
  97. out.reset();
  98. dest.close();
  99. BOOST_CHECK_MESSAGE(
  100. compare_files(lower2.name(), lower.name()),
  101. "failed writing to a filtering_stream<bidirectional> in chars "
  102. "with a multichar output filter"
  103. );
  104. }
  105. {
  106. temp_file lower2;
  107. filebuf dest;
  108. filtering_stream<bidirectional> out;
  109. out.push(combine(toupper_filter(), tolower_multichar_filter()));
  110. dest.open(lower2.name().c_str(), mode);
  111. out.push(dest);
  112. write_data_in_chunks(out);
  113. out.reset();
  114. dest.close();
  115. BOOST_CHECK_MESSAGE(
  116. compare_files(lower2.name(), lower.name()),
  117. "failed writing to a filtering_stream<bidirectional> in chunks "
  118. "with a buffered output filter"
  119. );
  120. }
  121. }
  122. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_BIDIRECTIONAL_FILTER_HPP_INCLUDED