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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
/*
* Copyright Andrey Semashev 2020.
* 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)
*/
/*!
* \file util_manip_range.cpp
* \author Andrey Semashev
* \date 11.05.2020
*
* \brief This header contains tests for the range manipulator.
*/
#define BOOST_TEST_MODULE util_manip_range
#include <list>
#include <vector>
#include <string>
#include <sstream>
#include <boost/config.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/log/utility/manipulators/range.hpp>
#include "char_definitions.hpp"
namespace logging = boost::log;
struct my_int_wrapper
{
int n;
my_int_wrapper(int x = 0) BOOST_NOEXCEPT : n(x) {}
};
template< typename CharT, typename TraitsT >
inline std::basic_ostream< CharT, TraitsT >& operator<< (std::basic_ostream< CharT, TraitsT >& strm, my_int_wrapper miw)
{
if (BOOST_LIKELY(strm.good()))
strm << '{' << miw.n << '}';
return strm;
}
BOOST_AUTO_TEST_CASE_TEMPLATE(int_no_separator, CharT, char_types)
{
typedef CharT char_type;
typedef std::basic_ostringstream< char_type > ostream_type;
std::vector< int > data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
ostream_type strm_dump;
strm_dump << logging::range_manip(data);
ostream_type strm_correct;
strm_correct << "123";
BOOST_CHECK(equal_strings(strm_dump.str(), strm_correct.str()));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(int_char_separator, CharT, char_types)
{
typedef CharT char_type;
typedef std::basic_ostringstream< char_type > ostream_type;
std::vector< int > data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
ostream_type strm_dump;
strm_dump << logging::range_manip(data, ' ');
ostream_type strm_correct;
strm_correct << "1 2 3";
BOOST_CHECK(equal_strings(strm_dump.str(), strm_correct.str()));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(int_string_separator, CharT, char_types)
{
typedef CharT char_type;
typedef std::basic_ostringstream< char_type > ostream_type;
std::vector< int > data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
ostream_type strm_dump;
strm_dump << logging::range_manip(data, ", ");
ostream_type strm_correct;
strm_correct << "1, 2, 3";
BOOST_CHECK(equal_strings(strm_dump.str(), strm_correct.str()));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(int_std_string_separator, CharT, char_types)
{
typedef CharT char_type;
typedef std::basic_ostringstream< char_type > ostream_type;
typedef std::basic_string< char_type > string_type;
std::vector< int > data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
string_type separator;
separator.push_back(',');
separator.push_back(' ');
ostream_type strm_dump;
strm_dump << logging::range_manip(data, separator);
ostream_type strm_correct;
strm_correct << "1, 2, 3";
BOOST_CHECK(equal_strings(strm_dump.str(), strm_correct.str()));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(miw_string_separator, CharT, char_types)
{
typedef CharT char_type;
typedef std::basic_ostringstream< char_type > ostream_type;
std::list< my_int_wrapper > data;
data.push_back(my_int_wrapper(1));
data.push_back(my_int_wrapper(2));
data.push_back(my_int_wrapper(3));
ostream_type strm_dump;
strm_dump << logging::range_manip(data, ", ");
ostream_type strm_correct;
strm_correct << "{1}, {2}, {3}";
BOOST_CHECK(equal_strings(strm_dump.str(), strm_correct.str()));
}
BOOST_AUTO_TEST_CASE_TEMPLATE(array_int_string_separator, CharT, char_types)
{
typedef CharT char_type;
typedef std::basic_ostringstream< char_type > ostream_type;
int data[3] = { 1, 2, 3 };
ostream_type strm_dump;
strm_dump << logging::range_manip(data, ", ");
ostream_type strm_correct;
strm_correct << "1, 2, 3";
BOOST_CHECK(equal_strings(strm_dump.str(), strm_correct.str()));
}
|