read_input_filter_test.hpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_READ_INPUT_FILTER_HPP_INCLUDED
  7. #define BOOST_IOSTREAMS_TEST_READ_INPUT_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 read_input_filter_test()
  17. {
  18. using namespace std;
  19. using namespace boost;
  20. using namespace boost::iostreams;
  21. using namespace boost::iostreams::test;
  22. test_file test;
  23. uppercase_file upper;
  24. {
  25. filtering_istream first;
  26. first.push(toupper_filter());
  27. first.push(file_source(test.name()));
  28. ifstream second(upper.name().c_str());
  29. BOOST_CHECK_MESSAGE(
  30. compare_streams_in_chars(first, second),
  31. "failed reading from a filtering_istream in chars with an "
  32. "input filter"
  33. );
  34. }
  35. {
  36. filtering_istream first;
  37. first.push(toupper_filter());
  38. first.push(file_source(test.name()));
  39. ifstream second(upper.name().c_str());
  40. BOOST_CHECK_MESSAGE(
  41. compare_streams_in_chunks(first, second),
  42. "failed reading from a filtering_istream in chunks with an "
  43. "input filter"
  44. );
  45. }
  46. {
  47. filtering_istream first;
  48. first.push(toupper_multichar_filter(), 0);
  49. first.push(file_source(test.name()));
  50. ifstream second(upper.name().c_str());
  51. BOOST_CHECK_MESSAGE(
  52. compare_streams_in_chars(first, second),
  53. "failed reading from a filtering_istream in chars with a "
  54. "multichar input filter with no buffer"
  55. );
  56. }
  57. {
  58. filtering_istream first;
  59. first.push(toupper_multichar_filter(), 0);
  60. first.push(file_source(test.name()));
  61. ifstream second(upper.name().c_str());
  62. BOOST_CHECK_MESSAGE(
  63. compare_streams_in_chunks(first, second),
  64. "failed reading from a filtering_istream in chunks with a "
  65. "multichar input filter with no buffer"
  66. );
  67. }
  68. {
  69. test_file src;
  70. filtering_istream first;
  71. first.push(toupper_multichar_filter());
  72. first.push(file_source(src.name()));
  73. ifstream second(upper.name().c_str());
  74. BOOST_CHECK_MESSAGE(
  75. compare_streams_in_chars(first, second),
  76. "failed reading from a filtering_istream in chars with a "
  77. "multichar input filter"
  78. );
  79. }
  80. {
  81. test_file src;
  82. filtering_istream first;
  83. first.push(toupper_multichar_filter());
  84. first.push(file_source(src.name()));
  85. ifstream second(upper.name().c_str());
  86. BOOST_CHECK_MESSAGE(
  87. compare_streams_in_chunks(first, second),
  88. "failed reading from a filtering_istream in chunks with a "
  89. "multichar input filter"
  90. );
  91. }
  92. }
  93. #endif // #ifndef BOOST_IOSTREAMS_TEST_READ_INPUT_FILTER_HPP_INCLUDED