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>
35 #include <senf/Utils/auto_unit_test.hh>
36 #include <boost/test/test_tools.hpp>
39 ///////////////////////////////cc.p////////////////////////////////////////
41 BOOST_AUTO_UNIT_TEST(formatEng)
45 # define CheckFormat(v,s) \
48 ss << senf::format::eng v; \
49 BOOST_CHECK_EQUAL( ss.str(), s ); \
54 CheckFormat( (0.0), " 0.000 " );
55 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.313+-022.634e+03" );
56 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.440+-000.211e-15" );
57 CheckFormat( (1.345e-3, 3.456), " 0.001+-003.456 " );
59 ss << std::setprecision(4) << std::uppercase << std::showpoint;
61 CheckFormat( (0.0), " 0.0E+00" );
62 CheckFormat( (-1.4431288e5, 2.26338e4), " -144.3+-022.6E+03" );
63 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.4+-000.2E-15" );
64 CheckFormat( (1.345e-3, 3.456), " 0.0+-003.5E+00" );
66 ss << std::showbase << std::internal << std::showpos << std::setfill('0');
68 CheckFormat( (0.0), "+00000000000000000.0 " );
69 CheckFormat( (-1.4431288e5, 2.26338e4), "-0000000144.3+-022.6k" );
70 CheckFormat( (1.4444e-13, 2.111111e-16), "+0000000144.4+-000.2f" );
71 CheckFormat( (1.345e-3, 3.456), "+0000000000.0+-003.5 " );
73 ss << std::left << std::noshowpos << std::setfill('*');
75 CheckFormat( (0.0), " 0.0 **************" );
76 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.3+-022.6k*******" );
77 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.4+-000.2f*******" );
78 CheckFormat( (1.345e-3, 3.456), " 0.0+-003.5 *******" );
82 CheckFormat( (0.0), "0.0" );
83 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.3+-22.6k" );
84 CheckFormat( (1.4444e-13, 2.111111e-16), "144.4+-0.2f" );
85 CheckFormat( (1.345e-3, 3.456), "0.0+-3.5" );
93 ss << senf::format::eng(1.23);
94 BOOST_CHECK_EQUAL(ss.str(), "1.230");
99 ss << std::setw(1) << senf::format::eng(1.23);
100 BOOST_CHECK_EQUAL( ss.str(), " 1.230 " );
104 std::stringstream ss;
105 ss << std::setw(25) << std::setprecision(5) << std::showpos << std::uppercase
106 << std::internal << senf::format::eng(12345,67);
107 BOOST_CHECK_EQUAL( ss.str(), "+ 12.35+-000.07E+03" );
111 std::stringstream ss;
112 ss << std::showbase << senf::format::eng(12345,67);
113 BOOST_CHECK_EQUAL( ss.str(), "12.345+-0.067k" );
117 BOOST_AUTO_UNIT_TEST(dumpint)
119 std::stringstream ss;
121 # define CheckFormat(v,s) \
124 ss << senf::format::dumpint(v); \
125 BOOST_CHECK_EQUAL( ss.str(), s ); \
128 CheckFormat( boost::int8_t(32), " 0x20 ( 32) ( )" );
129 CheckFormat( boost::uint16_t(1234), "0x04d2 ( 1234) (..)" );
134 ///////////////////////////////cc.e////////////////////////////////////////
141 // comment-column: 40
142 // c-file-style: "senf"
143 // indent-tabs-mode: nil
144 // ispell-local-dictionary: "american"
145 // compile-command: "scons -u test"