|
Boost : |
From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-10-01 15:19:13
I have some fancy manipulators that I want to test carefully.
(Just as I am learning the dental savings from flossing my teeth,
I am belatedly appreciating the benefits of Boost's excellent Test Tools :-))
Simply to show the problem, imagine I would like to be able to test the effect
of the std::ios::hex and setw() manipulators.
I have tried this (but without much expectation as BOOST_MESSAGE("message", i <<
hex); doesn't work (Gennady said he might make it in future)
int i = 15;
BOOST_CHECK_EQUAL(i << hex << uppercase, "F");
BOOST_CHECK_EQUAL(i << dec, "15");
So then I have tried passing the manipulator as a parameter to a procedure
toString
in the hope of doing:
BOOST_CHECK_EQUAL(toString(15, hex), "0xf");
string toString(int value, std::ios_base& (*)(std::ios_base&) manipulator)
{
ostringstream oss;
oss << manipulator; // hex for example.
cout << "value|" << value << "|" << ", toString |" << oss.str() << "|" <<
endl; // for testing
return oss.str();
} // toString
but I am obviously failing to specify the manipulator correctly as even
std::ios_base &(*)(std::ios_base&) manipulator = ios::hex;
won't compile (MSVC 7.1) error C2059: syntax error : ')'
(Despite this type
'std::ios_base &(*)(std::ios_base &)'
being mentioned in an error message
error C2297: '<<' : illegal, right operand has type
'std::ios_base &(*)(std::ios_base &)'
at BOOST_CHECK_EQUAL(i << dec, "15");
And of course I also want to be able to test using manipulators with
parameter(s)
like setw, preferably in combination
(two manipulator parameters, one like hex and one like setw(5) would be OK, with
some default null manipulators perhaps?)
Suggestions - please.
Paul
Paul A Bristow, Prizet Farmhouse, Kendal, Cumbria, LA8 8AB UK
+44 1539 561830 Mobile +44 7714 33 02 04
mailto:pbristow_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk