Boost logo

Boost :

From: Paul A. Bristow (boost_at_[hidden])
Date: 2003-10-10 14:37:58


| -----Original Message-----
| From: boost-bounces_at_[hidden]
| [mailto:boost-bounces_at_[hidden]]On Behalf Of Scott Woods
| Sent: Thursday, October 02, 2003 10:49 PM
| To: Boost mailing list
| Subject: Re: [boost] Boost Test tools to test manipulators

| like hex,setw(15)...
|
| i'm guessing that you want to add a function
| something like;
|
| template <typename T>
| string toString( T value, SMANIP(int) m )

template <typename T>
string toString(T value, std::_Smanip<std::streamsize> m)
{ // Convert T to string, using manipulator with one int parameter like setw,
setprecision
        // Note uses default stream values, unless overwritten by manipulator.
        ostringstream oss;
        oss << m << value;
        cout << "value|" << value << "|" << ", toString |" << oss.str() << "|" <<
endl; // for test only.
// Example: toString(99, setw(15))
        return oss.str();
}

works as you suggest, but after all the help from you I have regretfully
concluded that because the most important part is to test COMBINATIONS of
SEVERAL manipulators both std:: AND my own fancy ones, this approach of passing
manipulators is flawed.

So I have resorted to the uglier:
{
  int value = 15;
  ostringstream oss;
  setMyStreamDefaults; // xalloc ...
  oss << "" << hex << showbase << setw(10) << setprecision(4) //
std::manipulators
  << myManipulator1 << myManipulator2 // My own parameterless
  << myIntManipulator1(5) << myIntManipulator2(42)// some int parameter ones
  << value;
  BOOST_CHECK_EQUAL(oss.str(), " 0xf");
}

And fear a nasty macro coming on ...

But many thanks to you, and Brian McNamara.

However Gennadiy might like to add Brian's makeManip stuff to allow

  BOOST_MESSAGE("i = " << makeManip(cerr)(hex) << i );

in case anyone wants to do this.

It might also be nice to be able to write
  BOOST_CHECK_EQUAL("i = " << makeManip(cerr)(hex) << i, " 0xf");
or
  BOOST_CHECK_EQUAL_STRING("i = " << makeManip(cerr)(hex) << i, " 0xf");

(Although it wouldn't solve my particular problem).

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