write_output_filter_test.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_OUTPUT_FILTER_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_FILTER_HPP_INCLUDED
  8. #include <fstream>
  9. #include <boost/iostreams/device/file.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_output_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. {
  24. temp_file dest;
  25. filtering_ostream out;
  26. out.push(tolower_filter());
  27. out.push(file_sink(dest.name(), out_mode));
  28. write_data_in_chars(out);
  29. out.reset();
  30. BOOST_CHECK_MESSAGE(
  31. compare_files(dest.name(), lower.name()),
  32. "failed writing to a filtering_ostream in chars with an "
  33. "output filter"
  34. );
  35. }
  36. {
  37. temp_file dest;
  38. filtering_ostream out;
  39. out.push(tolower_filter());
  40. out.push(file_sink(dest.name(), out_mode));
  41. write_data_in_chunks(out);
  42. out.reset();
  43. BOOST_CHECK_MESSAGE(
  44. compare_files(dest.name(), lower.name()),
  45. "failed writing to a filtering_ostream in chunks with an "
  46. "output filter"
  47. );
  48. }
  49. {
  50. temp_file dest;
  51. filtering_ostream out;
  52. out.push(tolower_multichar_filter(), 0);
  53. out.push(file_sink(dest.name(), out_mode));
  54. write_data_in_chars(out);
  55. out.reset();
  56. BOOST_CHECK_MESSAGE(
  57. compare_files(dest.name(), lower.name()),
  58. "failed writing to a filtering_ostream in chars with a "
  59. "multichar output filter with no buffer"
  60. );
  61. }
  62. {
  63. temp_file dest;
  64. filtering_ostream out;
  65. out.push(tolower_multichar_filter(), 0);
  66. out.push(file_sink(dest.name(), out_mode));
  67. write_data_in_chunks(out);
  68. out.reset();
  69. BOOST_CHECK_MESSAGE(
  70. compare_files(dest.name(), lower.name()),
  71. "failed writing to a filtering_ostream in chunks with a "
  72. "multichar output filter with no buffer"
  73. );
  74. }
  75. {
  76. temp_file dest;
  77. filtering_ostream out;
  78. out.push(tolower_multichar_filter());
  79. out.push(file_sink(dest.name(), out_mode));
  80. write_data_in_chars(out);
  81. out.reset();
  82. BOOST_CHECK_MESSAGE(
  83. compare_files(dest.name(), lower.name()),
  84. "failed writing to a filtering_ostream in chars with a "
  85. "multichar output filter"
  86. );
  87. }
  88. {
  89. temp_file dest;
  90. filtering_ostream out;
  91. out.push(tolower_multichar_filter());
  92. out.push(file_sink(dest.name(), out_mode));
  93. write_data_in_chunks(out);
  94. out.reset();
  95. BOOST_CHECK_MESSAGE(
  96. compare_files(dest.name(), lower.name()),
  97. "failed writing to a filtering_ostream in chunks with a "
  98. "multichar output filter"
  99. );
  100. }
  101. }
  102. #endif // #ifndef BOOST_IOSTREAMS_TEST_WRITE_OUTPUT_FILTER_HPP_INCLUDED