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