2 * Copyright Andrey Semashev 2020.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file util_manip_range.cpp
9 * \author Andrey Semashev
12 * \brief This header contains tests for the range manipulator.
15 #define BOOST_TEST_MODULE util_manip_range
21 #include <boost/config.hpp>
22 #include <boost/test/unit_test.hpp>
23 #include <boost/log/utility/manipulators/range.hpp>
24 #include "char_definitions.hpp"
26 namespace logging
= boost::log
;
32 my_int_wrapper(int x
= 0) BOOST_NOEXCEPT
: n(x
) {}
35 template< typename CharT
, typename TraitsT
>
36 inline std::basic_ostream
< CharT
, TraitsT
>& operator<< (std::basic_ostream
< CharT
, TraitsT
>& strm
, my_int_wrapper miw
)
38 if (BOOST_LIKELY(strm
.good()))
39 strm
<< '{' << miw
.n
<< '}';
44 BOOST_AUTO_TEST_CASE_TEMPLATE(int_no_separator
, CharT
, char_types
)
46 typedef CharT char_type
;
47 typedef std::basic_ostringstream
< char_type
> ostream_type
;
49 std::vector
< int > data
;
54 ostream_type strm_dump
;
55 strm_dump
<< logging::range_manip(data
);
57 ostream_type strm_correct
;
58 strm_correct
<< "123";
60 BOOST_CHECK(equal_strings(strm_dump
.str(), strm_correct
.str()));
63 BOOST_AUTO_TEST_CASE_TEMPLATE(int_char_separator
, CharT
, char_types
)
65 typedef CharT char_type
;
66 typedef std::basic_ostringstream
< char_type
> ostream_type
;
68 std::vector
< int > data
;
73 ostream_type strm_dump
;
74 strm_dump
<< logging::range_manip(data
, ' ');
76 ostream_type strm_correct
;
77 strm_correct
<< "1 2 3";
79 BOOST_CHECK(equal_strings(strm_dump
.str(), strm_correct
.str()));
82 BOOST_AUTO_TEST_CASE_TEMPLATE(int_string_separator
, CharT
, char_types
)
84 typedef CharT char_type
;
85 typedef std::basic_ostringstream
< char_type
> ostream_type
;
87 std::vector
< int > data
;
92 ostream_type strm_dump
;
93 strm_dump
<< logging::range_manip(data
, ", ");
95 ostream_type strm_correct
;
96 strm_correct
<< "1, 2, 3";
98 BOOST_CHECK(equal_strings(strm_dump
.str(), strm_correct
.str()));
101 BOOST_AUTO_TEST_CASE_TEMPLATE(int_std_string_separator
, CharT
, char_types
)
103 typedef CharT char_type
;
104 typedef std::basic_ostringstream
< char_type
> ostream_type
;
105 typedef std::basic_string
< char_type
> string_type
;
107 std::vector
< int > data
;
112 string_type separator
;
113 separator
.push_back(',');
114 separator
.push_back(' ');
116 ostream_type strm_dump
;
117 strm_dump
<< logging::range_manip(data
, separator
);
119 ostream_type strm_correct
;
120 strm_correct
<< "1, 2, 3";
122 BOOST_CHECK(equal_strings(strm_dump
.str(), strm_correct
.str()));
125 BOOST_AUTO_TEST_CASE_TEMPLATE(miw_string_separator
, CharT
, char_types
)
127 typedef CharT char_type
;
128 typedef std::basic_ostringstream
< char_type
> ostream_type
;
130 std::list
< my_int_wrapper
> data
;
131 data
.push_back(my_int_wrapper(1));
132 data
.push_back(my_int_wrapper(2));
133 data
.push_back(my_int_wrapper(3));
135 ostream_type strm_dump
;
136 strm_dump
<< logging::range_manip(data
, ", ");
138 ostream_type strm_correct
;
139 strm_correct
<< "{1}, {2}, {3}";
141 BOOST_CHECK(equal_strings(strm_dump
.str(), strm_correct
.str()));
144 BOOST_AUTO_TEST_CASE_TEMPLATE(array_int_string_separator
, CharT
, char_types
)
146 typedef CharT char_type
;
147 typedef std::basic_ostringstream
< char_type
> ostream_type
;
149 int data
[3] = { 1, 2, 3 };
151 ostream_type strm_dump
;
152 strm_dump
<< logging::range_manip(data
, ", ");
154 ostream_type strm_correct
;
155 strm_correct
<< "1, 2, 3";
157 BOOST_CHECK(equal_strings(strm_dump
.str(), strm_correct
.str()));