4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Format.test unit tests */
31 //#include "Format.test.hh"
32 //#include "Format.test.ih"
38 #include <boost/cstdint.hpp>
41 #include <senf/Utils/auto_unit_test.hh>
42 #include <boost/test/test_tools.hpp>
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47 SENF_AUTO_UNIT_TEST(formatEng)
51 # define CheckFormat(v,s) \
54 ss << senf::format::eng v; \
55 BOOST_CHECK_EQUAL( ss.str(), s ); \
60 CheckFormat( (0.0), " 0.000 " );
61 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.313+-022.634e+03" );
62 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.440+-000.211e-15" );
63 CheckFormat( (1.345e-3, 3.456), " 0.001+-003.456 " );
65 ss << std::setprecision(4) << std::uppercase << std::showpoint;
67 CheckFormat( (0.0), " 0.0E+00" );
68 CheckFormat( (-1.4431288e5, 2.26338e4), " -144.3+-022.6E+03" );
69 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.4+-000.2E-15" );
70 CheckFormat( (1.345e-3, 3.456), " 0.0+-003.5E+00" );
72 ss << std::showbase << std::internal << std::showpos << std::setfill('0');
74 CheckFormat( (0.0), "+00000000000000000.0 " );
75 CheckFormat( (-1.4431288e5, 2.26338e4), "-0000000144.3+-022.6k" );
76 CheckFormat( (1.4444e-13, 2.111111e-16), "+0000000144.4+-000.2f" );
77 CheckFormat( (1.345e-3, 3.456), "+0000000000.0+-003.5 " );
79 ss << std::left << std::noshowpos << std::setfill('*');
81 CheckFormat( (0.0), " 0.0 **************" );
82 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.3+-022.6k*******" );
83 CheckFormat( (1.4444e-13, 2.111111e-16), " 144.4+-000.2f*******" );
84 CheckFormat( (1.345e-3, 3.456), " 0.0+-003.5 *******" );
88 CheckFormat( (0.0), "0.0" );
89 CheckFormat( (-1.4431288e5, 2.26338e4), "-144.3+-22.6k" );
90 CheckFormat( (1.4444e-13, 2.111111e-16), "144.4+-0.2f" );
91 CheckFormat( (1.345e-3, 3.456), "0.0+-3.5" );
99 ss << senf::format::eng(1.23);
100 BOOST_CHECK_EQUAL(ss.str(), "1.230");
104 std::stringstream ss;
105 ss << std::setw(1) << senf::format::eng(1.23);
106 BOOST_CHECK_EQUAL( ss.str(), " 1.230 " );
110 std::stringstream ss;
111 ss << std::setw(25) << std::setprecision(5) << std::showpos << std::uppercase
112 << std::internal << senf::format::eng(12345,67);
113 BOOST_CHECK_EQUAL( ss.str(), "+ 12.35+-000.07E+03" );
117 std::stringstream ss;
118 ss << std::showbase << senf::format::eng(12345,67);
119 BOOST_CHECK_EQUAL( ss.str(), "12.345+-0.067k" );
122 // class member formatting
123 BOOST_CHECK_EQUAL( senf::str(senf::format::eng(12345, 67)
130 "+012.35+-000.07k" );
132 BOOST_CHECK_EQUAL( senf::str(senf::format::eng(12.345, 67)
137 " 12.35+-067.00E+00" );
140 SENF_AUTO_UNIT_TEST(dumpint)
142 std::stringstream ss;
144 # define CheckFormat(v,s) \
147 ss << senf::format::dumpint(v); \
148 BOOST_CHECK_EQUAL( ss.str(), s ); \
151 CheckFormat( boost::int8_t(32), " 0x20 ( 32) ( )" );
152 CheckFormat( boost::uint16_t(1234), "0x04d2 ( 1234) (..)" );
158 void f1(std::ostream & os) {
159 senf::format::IndentHelper indent;
160 os << indent << "f1\n";
162 void f2(std::ostream & os) {
163 senf::format::IndentHelper indent;
164 os << indent << "f2_1\n";
166 os << indent << "f2_2\n";
168 os << indent << "f2_3\n";
171 SENF_AUTO_UNIT_TEST(indent)
173 std::stringstream ss;
175 BOOST_CHECK_EQUAL( ss.str(),
182 //-/////////////////////////////////////////////////////////////////////////////////////////////////
189 // comment-column: 40
190 // c-file-style: "senf"
191 // indent-tabs-mode: nil
192 // ispell-local-dictionary: "american"
193 // compile-command: "scons -u test"