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