4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief Format.test unit tests */
26 //#include "Format.test.hh"
27 //#include "Format.test.ih"
33 #include <boost/cstdint.hpp>
36 #include <senf/Utils/auto_unit_test.hh>
37 #include <boost/test/test_tools.hpp>
40 ///////////////////////////////cc.p////////////////////////////////////////
42 SENF_AUTO_UNIT_TEST(formatEng)
46 # define CheckFormat(v,s) \
49 ss << senf::format::eng v; \
50 BOOST_CHECK_EQUAL( ss.str(), s ); \
55 CheckFormat( (0.0), " 0.000 " );
56 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.313+-022.634e+03" );
57 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.440+-000.211e-15" );
58 CheckFormat( (1.345e-3, 3.456), " 0.001+-003.456 " );
60 ss << std::setprecision(4) << std::uppercase << std::showpoint;
62 CheckFormat( (0.0), " 0.0E+00" );
63 CheckFormat( (-1.4431288e5, 2.26338e4), " -144.3+-022.6E+03" );
64 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.4+-000.2E-15" );
65 CheckFormat( (1.345e-3, 3.456), " 0.0+-003.5E+00" );
67 ss << std::showbase << std::internal << std::showpos << std::setfill('0');
69 CheckFormat( (0.0), "+00000000000000000.0 " );
70 CheckFormat( (-1.4431288e5, 2.26338e4), "-0000000144.3+-022.6k" );
71 CheckFormat( (1.4444e-13, 2.111111e-16), "+0000000144.4+-000.2f" );
72 CheckFormat( (1.345e-3, 3.456), "+0000000000.0+-003.5 " );
74 ss << std::left << std::noshowpos << std::setfill('*');
76 CheckFormat( (0.0), " 0.0 **************" );
77 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.3+-022.6k*******" );
78 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.4+-000.2f*******" );
79 CheckFormat( (1.345e-3, 3.456), " 0.0+-003.5 *******" );
83 CheckFormat( (0.0), "0.0" );
84 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.3+-22.6k" );
85 CheckFormat( (1.4444e-13, 2.111111e-16), "144.4+-0.2f" );
86 CheckFormat( (1.345e-3, 3.456), "0.0+-3.5" );
94 ss << senf::format::eng(1.23);
95 BOOST_CHECK_EQUAL(ss.str(), "1.230");
100 ss << std::setw(1) << senf::format::eng(1.23);
101 BOOST_CHECK_EQUAL( ss.str(), " 1.230 " );
105 std::stringstream ss;
106 ss << std::setw(25) << std::setprecision(5) << std::showpos << std::uppercase
107 << std::internal << senf::format::eng(12345,67);
108 BOOST_CHECK_EQUAL( ss.str(), "+ 12.35+-000.07E+03" );
112 std::stringstream ss;
113 ss << std::showbase << senf::format::eng(12345,67);
114 BOOST_CHECK_EQUAL( ss.str(), "12.345+-0.067k" );
117 // class member formatting
118 BOOST_CHECK_EQUAL( senf::str(senf::format::eng(12345, 67)
125 "+012.35+-000.07k" );
127 BOOST_CHECK_EQUAL( senf::str(senf::format::eng(12.345, 67)
132 " 12.35+-067.00E+00" );
135 SENF_AUTO_UNIT_TEST(dumpint)
137 std::stringstream ss;
139 # define CheckFormat(v,s) \
142 ss << senf::format::dumpint(v); \
143 BOOST_CHECK_EQUAL( ss.str(), s ); \
146 CheckFormat( boost::int8_t(32), " 0x20 ( 32) ( )" );
147 CheckFormat( boost::uint16_t(1234), "0x04d2 ( 1234) (..)" );
153 void f1(std::ostream & os) {
154 senf::format::IndentHelper indent;
155 os << indent << "f1\n";
157 void f2(std::ostream & os) {
158 senf::format::IndentHelper indent;
159 os << indent << "f2_1\n";
161 os << indent << "f2_2\n";
163 os << indent << "f2_3\n";
166 SENF_AUTO_UNIT_TEST(indent)
168 std::stringstream ss;
170 BOOST_CHECK_EQUAL( ss.str(),
177 ///////////////////////////////cc.e////////////////////////////////////////
184 // comment-column: 40
185 // c-file-style: "senf"
186 // indent-tabs-mode: nil
187 // ispell-local-dictionary: "american"
188 // compile-command: "scons -u test"