26 #include <boost/lexical_cast.hpp> 29 using boost::lexical_cast;
59 check_simpleInvocation();
60 check_delayedInvocation();
61 verify_typeHandling();
63 verify_errorHandling();
64 verify_pointerHandling();
70 check_simpleInvocation ()
72 string formatted =
_Fmt(
"--format-template--int=%04d--double=%+5.2f--string=%-9s--")
76 cout << formatted << endl;
77 CHECK (formatted ==
"--format-template--int=0012--double=+1.23--string=Lumiera --");
82 check_delayedInvocation ()
84 string formatString =
"%p %|20T_| %u";
85 _Fmt formatter (formatString);
87 uint val =
rani (100);
93 cout << formatter << endl;
98 verify_typeHandling ()
101 CHECK (
_Fmt(
"%d") % i ==
"-12" );
102 CHECK (
_Fmt(
"%6d") % i ==
" -12" );
103 CHECK (
_Fmt(
"%-6d") % i ==
"-12 " );
104 CHECK (
_Fmt(
"%+-6d") % -i ==
"+12 " );
105 CHECK (
_Fmt(
"%+06d") % -i ==
"+00012" );
106 CHECK (
_Fmt(
"%06X") % -i ==
"00000C" );
107 CHECK (
_Fmt(
"%#x") % -i ==
"0xc" );
110 CHECK (
_Fmt(
"%d") % u ==
"12" );
111 CHECK (
_Fmt(
"%6d") % u ==
" 12" );
112 CHECK (
_Fmt(
"%-6d") % u ==
"12 " );
113 CHECK (
_Fmt(
"%-+6d") % u ==
"12 " );
114 CHECK (
_Fmt(
"%+06d") % u ==
"000012" );
117 CHECK (
_Fmt(
"%6d") % sh ==
" -123" );
120 CHECK (
_Fmt(
"%6d") % ush ==
" 123" );
123 CHECK (
_Fmt(
"%6d") % l ==
" -123" );
126 CHECK (
_Fmt(
"%6d") % ul ==
" 123" );
129 CHECK (
_Fmt(
"%d") % ll ==
"5000000000" );
130 CHECK (
_Fmt(
"%5.3d") %ll ==
"5000000000" );
131 CHECK (
_Fmt(
"%10.3e") %ll ==
"5000000000" );
134 CHECK (
_Fmt(
"%d") % ull ==
"5000000000" );
137 CHECK (
_Fmt(
"%g") % f ==
"12.34" );
138 CHECK (
_Fmt(
"%d") % f ==
"12.34" );
139 CHECK (
_Fmt(
"%.3f") % f ==
"12.340" );
140 CHECK (
_Fmt(
"%.1e") % f ==
"1.2e+01");
141 CHECK (
_Fmt(
"%.0f") % f ==
"12" );
144 CHECK (
_Fmt(
"%g") % d ==
"-12.34" );
147 CHECK (
_Fmt(
"%d") % c ==
"@" );
148 CHECK (
_Fmt(
"%x") % c ==
"@" );
149 CHECK (
_Fmt(
"%o") % c ==
"@" );
150 CHECK (
_Fmt(
"%c") % c ==
"@" );
151 CHECK (
_Fmt(
"%s") % c ==
"@" );
152 CHECK (
_Fmt(
"%d") %
short(c) ==
"64" );
153 CHECK (
_Fmt(
"%x") %
short(c) ==
"40" );
154 CHECK (
_Fmt(
"%o") %
short(c) ==
"100" );
155 CHECK (
_Fmt(
"%c") %
short(c) ==
"6" );
156 CHECK (
_Fmt(
"%s") %
short(c) ==
"64" );
159 CHECK (
_Fmt(
"%d") % uint(uc) ==
"255" );
160 CHECK (
_Fmt(
"%x") % uint(uc) ==
"ff" );
161 CHECK (
_Fmt(
"%X") % uint(uc) ==
"FF" );
162 CHECK (
_Fmt(
"%c") % uint(uc) ==
"2" );
163 CHECK (
_Fmt(
"%s") % uint(uc) ==
"255" );
164 CHECK (
_Fmt(
"%d") % uc ==
"\xFF");
165 CHECK (
_Fmt(
"%x") % uc ==
"\xFF");
166 CHECK (
_Fmt(
"%X") % uc ==
"\xFF");
167 CHECK (
_Fmt(
"%c") % uc ==
"\xFF");
168 CHECK (
_Fmt(
"%s") % uc ==
"\xFF");
171 CHECK (
_Fmt(
"%c") % c ==
"\xFF");
173 string str(
"Lumiera");
174 CHECK (
_Fmt(
"%s") % str ==
"Lumiera" );
175 CHECK (
_Fmt(
"%10s") % str ==
" Lumiera" );
176 CHECK (
_Fmt(
"%7.4s") %str ==
" Lumi" );
177 CHECK (
_Fmt(
"%10c") % str ==
" L" );
179 const char* pch(
"edit");
180 CHECK (
_Fmt(
"%s") % pch ==
"edit" );
181 CHECK (
_Fmt(
"%10s") % pch ==
" edit" );
182 CHECK (
_Fmt(
"%7.3s") %pch ==
" edi" );
183 CHECK (
_Fmt(
"%10c") % pch ==
" e" );
186 CHECK (
_Fmt(
"%s") % lit ==
"your" );
187 CHECK (
_Fmt(
"%10s") % lit ==
" your" );
188 CHECK (
_Fmt(
"%7.2s") %lit ==
" yo" );
189 CHECK (
_Fmt(
"%10c") % lit ==
" y" );
192 CHECK (
_Fmt(
"%s") % sym ==
"freedom" );
193 CHECK (
_Fmt(
"%10s") % sym ==
" freedom" );
194 CHECK (
_Fmt(
"%7.5s") %sym ==
" freed" );
195 CHECK (
_Fmt(
"%10c") % sym ==
" f" );
211 using Silent::Silent;
215 operator string()
const 217 return _Fmt(
"Number-%03d") % i_;
224 using Verbose::Verbose;
226 operator string()
const 231 return Verbose::operator string();
248 string typeDisplay =
_Fmt(
"%s") % s;
249 cout << typeDisplay << endl;
250 CHECK (
contains (typeDisplay,
"test"));
251 CHECK (
contains (typeDisplay,
"FormatString_test"));
252 CHECK (
contains (typeDisplay,
"Silent"));
254 CHECK (
_Fmt(
"!!%s!!") % v ==
"!!Number-013!!");
255 CHECK (
_Fmt(
"!!%s!!") % x ==
"!!<string conversion failed: LUMIERA_ERROR_STATE:unforeseen state (encountered Fantomas).>!!");
260 CHECK (
_Fmt(
"!!%s!!") % rv ==
"!!<string conversion failed: LUMIERA_ERROR_STATE:unforeseen state (encountered Fantomas).>!!");
263 CHECK (
_Fmt(
"!!%s!!") % rv ==
"!!Number-042!!");
264 CHECK (
_Fmt(
"!!%s!!") % x ==
"!!Number-042!!");
267 CHECK (
_Fmt(
"!!%s!!") % sym ==
"!!42!!");
272 verify_errorHandling ()
274 cout <<
_Fmt(
"__nix_") % 1 % 2 << endl;
275 cout <<
_Fmt(
"__%d__") << endl;
276 cout <<
_Fmt(
"__%d__") % 1 << endl;
277 cout <<
_Fmt(
"__%d__") % 1 % 2 << endl;
279 const char* evil = NULL;
280 cout <<
_Fmt(
"__%d__") % evil << endl;
281 cout <<
_Fmt(
"__%d__") %
"dirt" << endl;
282 cout <<
_Fmt(
"__%d__") %
"1234" << endl;
283 cout <<
_Fmt(
"__%d__") %
"0xff" << endl;
290 verify_pointerHandling ()
292 int i(-12);
int * pi = & i;
293 uint u(12); uint * pu = & u;
294 short sh(-123);
short * psh = & sh;
295 ushort ush(123); ushort * push = &ush;
296 long l(-123);
long * pl = & l;
297 ulong ul(123); ulong * pul = & ul;
298 int64_t ll(5e+9); int64_t * pll = & ll;
299 uint64_t ull(ll); uint64_t * pull = &ull;
300 float f(12.34);
float * pf = & f;
301 double d(-12.34);
double * pd = & d;
302 uchar uc(0xff); uchar * puc = & uc;
303 string str(
"Lumiera");
string * pstr = &str;
305 CHECK (
_Fmt(
"%d") % i ==
_Fmt(
"%d") % pi);
306 CHECK (
_Fmt(
"%d") % u ==
_Fmt(
"%d") % pu);
307 CHECK (
_Fmt(
"%d") % sh ==
_Fmt(
"%d") % psh);
308 CHECK (
_Fmt(
"%d") % ush ==
_Fmt(
"%d") % push);
309 CHECK (
_Fmt(
"%d") % l ==
_Fmt(
"%d") % pl);
310 CHECK (
_Fmt(
"%d") % ul ==
_Fmt(
"%d") % pul);
311 CHECK (
_Fmt(
"%d") % ll ==
_Fmt(
"%d") % pll);
312 CHECK (
_Fmt(
"%d") % ull ==
_Fmt(
"%d") % pull);
313 CHECK (
_Fmt(
"%e") % f ==
_Fmt(
"%e") % pf);
314 CHECK (
_Fmt(
"%e") % d ==
_Fmt(
"%e") % pd);
315 CHECK (
_Fmt(
"%g") % uc ==
_Fmt(
"%g") % puc);
316 CHECK (
_Fmt(
"%s") % str ==
_Fmt(
"%s") % pstr);
319 char pc[2] = {
'a',
'\0'};
320 CHECK (
_Fmt(
"%g") % c ==
_Fmt(
"%g") % pc);
325 CHECK (
_Fmt(
"__%s__") % v ==
"__Number-042__");
326 CHECK (
_Fmt(
"__%s__") % pv ==
"__Number-042__");
327 CHECK (
_Fmt(
"__%s__") % vv !=
"__Number-042__");
329 string address = lexical_cast<
string>(pv);
330 CHECK (
_Fmt(
"__%s__") % vv ==
"__"+address+
"__");
334 CHECK (
_Fmt(
"__%s__") % pv ==
"__"+BOTTOM_INDICATOR+
"__");
335 CHECK (
_Fmt(
"__%s__") % vv ==
"__0__");
inline string literal This is a marker type to indicate that
int rani(uint bound=_iBOUND())
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
A front-end for using printf-style formatting.
Derived specific exceptions within Lumiera's exception hierarchy.
Token or Atom with distinct identity.
Marker types to indicate a literal string and a Symbol.
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Lumiera error handling (C++ interface).