]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/io/test/ios_state_test.cpp
2 Copyright 2002, 2003 Daryle Walker
4 Copyright 2019 Glen Joseph Fernandes
7 Distributed under the Boost Software License, Version 1.0.
8 (http://www.boost.org/LICENSE_1_0.txt)
10 #include <boost/io/ios_state.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <boost/config.hpp>
19 #if defined(BOOST_GCC) || (defined(BOOST_CLANG) && defined(BOOST_GNU_STDLIB))
26 class backward_bool_names
27 : public std::numpunct
<char> {
28 typedef std::numpunct
<char> base_type
;
31 explicit backward_bool_names(std::size_t refs
= 0)
32 : base_type( refs
) { }
35 ~backward_bool_names() { }
37 base_type::string_type
do_truename() const {
41 base_type::string_type
do_falsename() const {
46 void saver_tests_1(int index
,
51 boost::io::ios_flags_saver
ifls(output
);
52 boost::io::ios_precision_saver
iprs(output
);
53 boost::io::ios_width_saver
iws(output
);
54 boost::io::ios_tie_saver
its(input
);
55 boost::io::ios_rdbuf_saver
irs(output
);
56 boost::io::ios_fill_saver
ifis(output
);
57 boost::io::ios_locale_saver
ils(output
);
58 boost::io::ios_iword_saver
iis(output
, index
);
59 boost::io::ios_pword_saver
ipws(output
, index
);
60 std::locale
loc(std::locale::classic(), new backward_bool_names
);
62 output
.rdbuf(err
.rdbuf());
63 output
.iword(index
) = 69L;
64 output
.pword(index
) = &err
;
65 output
.setf(std::ios_base::showpos
| std::ios_base::boolalpha
);
66 output
.setf(std::ios_base::internal
, std::ios_base::adjustfield
);
68 output
.precision( 9 );
69 output
<< "Hello world";
70 output
<< std::setw(10) << -16;
71 output
<< std::setw(15) << 34.5678901234;
74 BOOST_TEST(&err
== output
.pword(index
));
75 BOOST_TEST(69L == output
.iword(index
));
77 boost::io::ios_exception_saver
ies(output
);
78 boost::io::ios_iostate_saver
ias(output
);
79 output
.exceptions(std::ios_base::eofbit
| std::ios_base::badbit
);
80 output
.setstate(std::ios_base::eofbit
);
81 BOOST_ERROR("previous line should have thrown");
82 #if defined(BOOST_GCC) || (defined(BOOST_CLANG) && defined(BOOST_GNU_STDLIB))
83 } catch (std::exception
&) {
85 } catch (std::ios_base::failure
&) {
87 BOOST_TEST(output
.exceptions() == std::ios_base::goodbit
);
91 void saver_tests_2(int index
,
96 boost::io::ios_tie_saver
its(input
, &err
);
97 boost::io::ios_rdbuf_saver
irs(output
, err
.rdbuf());
98 boost::io::ios_iword_saver
iis(output
, index
, 69L);
99 boost::io::ios_pword_saver
ipws(output
, index
, &err
);
100 boost::io::ios_flags_saver
ifls(output
,
101 (output
.flags() & ~std::ios_base::adjustfield
) |
102 std::ios_base::showpos
|
103 std::ios_base::boolalpha
|
104 (std::ios_base::internal
& std::ios_base::adjustfield
));
105 boost::io::ios_precision_saver
iprs(output
, 9);
106 boost::io::ios_fill_saver
ifis(output
, '@');
107 output
<< "Hello world";
108 boost::io::ios_width_saver
iws(output
, 12);
109 output
<< -16 + 34.5678901234;
110 std::locale
loc(std::locale::classic(), new backward_bool_names
);
111 boost::io::ios_locale_saver
ils(output
, loc
);
113 BOOST_TEST(&err
== output
.pword(index
));
114 BOOST_TEST(69L == output
.iword(index
));
116 boost::io::ios_exception_saver
ies(output
, std::ios_base::eofbit
);
117 boost::io::ios_iostate_saver
ias(output
,
118 output
.rdstate() | std::ios_base::eofbit
);
119 BOOST_ERROR("previous line should have thrown");
120 #if defined(BOOST_GCC) || (defined(BOOST_CLANG) && defined(BOOST_GNU_STDLIB))
121 } catch (std::exception
&) {
123 } catch (std::ios_base::failure
&) {
125 BOOST_TEST(output
.exceptions() == std::ios_base::goodbit
);
131 int index
= std::ios_base::xalloc();
132 std::ostringstream out
;
133 std::ostringstream err
;
134 std::istringstream in
;
135 std::ios_base::fmtflags out_flags
= out
.flags();
136 std::streamsize out_precision
= out
.precision();
137 std::streamsize out_width
= out
.width();
138 std::ios_base::iostate out_iostate
= out
.rdstate();
139 std::ios_base::iostate out_exceptions
= out
.exceptions();
140 std::ostream
* in_tie
= in
.tie();
141 std::streambuf
* out_sb
= out
.rdbuf();
142 char out_fill
= out
.fill();
143 std::locale out_locale
= out
.getloc();
144 out
.iword(index
) = 42L;
145 out
.pword(index
) = &in
;
146 saver_tests_1(index
, in
, out
, err
);
147 BOOST_TEST(&in
== out
.pword(index
));
148 BOOST_TEST(42L == out
.iword(index
));
149 BOOST_TEST(out_locale
== out
.getloc());
150 BOOST_TEST(out_fill
== out
.fill());
151 BOOST_TEST(out_sb
== out
.rdbuf());
152 BOOST_TEST(in_tie
== in
.tie());
153 BOOST_TEST(out_exceptions
== out
.exceptions());
154 BOOST_TEST(out_iostate
== out
.rdstate());
155 BOOST_TEST(out_width
== out
.width());
156 BOOST_TEST(out_precision
== out
.precision());
157 BOOST_TEST(out_flags
== out
.flags());
158 saver_tests_2(index
, in
, out
, err
);
159 BOOST_TEST(&in
== out
.pword(index
));
160 BOOST_TEST(42L == out
.iword(index
));
161 BOOST_TEST(out_locale
== out
.getloc());
162 BOOST_TEST(out_fill
== out
.fill());
163 BOOST_TEST(out_sb
== out
.rdbuf());
164 BOOST_TEST(in_tie
== in
.tie());
165 BOOST_TEST(out_exceptions
== out
.exceptions());
166 BOOST_TEST(out_iostate
== out
.rdstate());
167 BOOST_TEST(out_width
== out
.width());
168 BOOST_TEST(out_precision
== out
.precision());
169 BOOST_TEST(out_flags
== out
.flags());
170 return boost::report_errors();