buffer_size_test.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "detail/filters.hpp" // Must come before operations.hpp for VC6.
  7. #include <boost/iostreams/categories.hpp>
  8. #include <boost/iostreams/constants.hpp>
  9. #include <boost/iostreams/device/null.hpp>
  10. #include <boost/iostreams/operations.hpp>
  11. #include <boost/test/test_tools.hpp>
  12. #include <boost/test/unit_test.hpp>
  13. using namespace std;
  14. using namespace boost::iostreams;
  15. using namespace boost::iostreams::test;
  16. using boost::unit_test::test_suite;
  17. struct optimally_buffered_filter {
  18. typedef char char_type;
  19. struct category
  20. : input_filter_tag,
  21. optimally_buffered_tag
  22. { };
  23. std::streamsize optimal_buffer_size() const
  24. { return default_filter_buffer_size + 1; }
  25. };
  26. void buffer_size_test()
  27. {
  28. // Test device buffer sizes.
  29. BOOST_CHECK_MESSAGE(
  30. optimal_buffer_size(null_source()) == default_device_buffer_size,
  31. "wrong buffer size for sourcer"
  32. );
  33. BOOST_CHECK_MESSAGE(
  34. optimal_buffer_size(null_sink()) == default_device_buffer_size,
  35. "wrong buffer size for sink"
  36. );
  37. // Test filter buffer sizes.
  38. BOOST_CHECK_MESSAGE(
  39. optimal_buffer_size(toupper_filter()) == default_filter_buffer_size,
  40. "wrong buffer size for input filter"
  41. );
  42. BOOST_CHECK_MESSAGE(
  43. optimal_buffer_size(tolower_filter()) == default_filter_buffer_size,
  44. "wrong buffer size for output filter"
  45. );
  46. BOOST_CHECK_MESSAGE(
  47. optimal_buffer_size(toupper_multichar_filter())
  48. ==
  49. default_filter_buffer_size,
  50. "wrong buffer size for multi-character input filter"
  51. );
  52. BOOST_CHECK_MESSAGE(
  53. optimal_buffer_size(tolower_multichar_filter())
  54. ==
  55. default_filter_buffer_size,
  56. "wrong buffer size for multi-character output filter"
  57. );
  58. // Test custom buffer size.
  59. BOOST_CHECK_MESSAGE(
  60. optimal_buffer_size(optimally_buffered_filter())
  61. ==
  62. optimally_buffered_filter().optimal_buffer_size(),
  63. "wrong buffer size for multi-character output filter"
  64. );
  65. }
  66. test_suite* init_unit_test_suite(int, char* [])
  67. {
  68. test_suite* test = BOOST_TEST_SUITE("buffer_size test");
  69. test->add(BOOST_TEST_CASE(&buffer_size_test));
  70. return test;
  71. }