#define BOOST_LEXICAL_CAST_ASSUME_C_LOCALE #define BOOST_TEST_MODULE FakeOStreamTest #include "string_stream.hh" #include #include #include #include namespace util { namespace { template void TestEqual(const T value) { StringStream strme; strme << value; BOOST_CHECK_EQUAL(boost::lexical_cast(value), strme.str()); } template void TestCorners() { TestEqual(std::numeric_limits::max()); TestEqual(std::numeric_limits::min()); TestEqual(static_cast(0)); TestEqual(static_cast(-1)); TestEqual(static_cast(1)); } BOOST_AUTO_TEST_CASE(Integer) { TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); TestCorners(); } enum TinyEnum { EnumValue }; BOOST_AUTO_TEST_CASE(EnumCase) { TestEqual(EnumValue); } BOOST_AUTO_TEST_CASE(Strings) { TestEqual("foo"); const char *a = "bar"; TestEqual(a); StringPiece piece("abcdef"); TestEqual(piece); TestEqual(StringPiece()); char non_const[3]; non_const[0] = 'b'; non_const[1] = 'c'; non_const[2] = 0; StringStream out; out << "a" << non_const << 'c'; BOOST_CHECK_EQUAL("abcc", out.str()); // Now test as a separate object. StringStream stream; stream << "a" << non_const << 'c' << piece; BOOST_CHECK_EQUAL("abccabcdef", stream.str()); } }} // namespaces