]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/iostreams/test/counter_test.cpp
091dfe9f68b27b120342afa09685ea0a8f2fd579
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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
9 #include <boost/iostreams/copy.hpp>
10 #include <boost/iostreams/device/file.hpp>
11 #include <boost/iostreams/device/null.hpp>
12 #include <boost/iostreams/filter/counter.hpp>
13 #include <boost/iostreams/filtering_stream.hpp>
14 #include <boost/test/test_tools.hpp>
15 #include <boost/test/unit_test.hpp>
16 #include "detail/constants.hpp"
17 #include "detail/filters.hpp"
18 #include "detail/temp_file.hpp"
19 #include "detail/verification.hpp"
22 using namespace boost
;
23 using namespace boost::iostreams
;
24 using namespace boost::iostreams::test
;
25 using boost::unit_test::test_suite
;
32 in
.push(padding_filter('a'), 0);
34 in
.push(file_source(src
.name(), in_mode
));
36 counter
* first_counter
= BOOST_IOSTREAMS_COMPONENT(in
, 0, counter
);
37 counter
* second_counter
= BOOST_IOSTREAMS_COMPONENT(in
, 2, counter
);
41 int reps
= data_reps
< 50 ? data_reps
: 25; // Keep test short.
42 for (int w
= 0; w
< reps
; ++w
) {
43 int len
= data_length();
44 for (int z
= 0; z
< len
; ++z
) {
48 BOOST_CHECK(first_counter
->characters() == first_count
);
49 BOOST_CHECK(second_counter
->characters() == second_count
);
52 BOOST_CHECK(first_counter
->characters() == first_count
);
53 BOOST_CHECK(second_counter
->characters() == second_count
);
56 BOOST_CHECK(first_counter
->lines() == line_count
);
57 BOOST_CHECK(first_counter
->lines() == line_count
);
63 filtering_ostream out
;
65 out
.push(padding_filter('a'), 0);
67 out
.push(null_sink());
69 counter
* first_counter
= BOOST_IOSTREAMS_COMPONENT(out
, 0, counter
);
70 counter
* second_counter
= BOOST_IOSTREAMS_COMPONENT(out
, 2, counter
);
74 int reps
= data_reps
< 50 ? data_reps
: 25; // Keep test short.
75 const char* data
= narrow_data();
76 for (int w
= 0; w
< reps
; ++w
) {
77 int len
= data_length();
78 for (int z
= 0; z
< len
; ++z
) {
83 BOOST_CHECK(first_counter
->characters() == first_count
);
84 BOOST_CHECK(second_counter
->characters() == second_count
);
87 BOOST_CHECK(first_counter
->lines() == line_count
);
88 BOOST_CHECK(first_counter
->lines() == line_count
);
92 test_suite
* init_unit_test_suite(int, char* [])
94 test_suite
* test
= BOOST_TEST_SUITE("counter test");
95 test
->add(BOOST_TEST_CASE(&read_counter
));
96 test
->add(BOOST_TEST_CASE(&write_counter
));