BOOST_CHECK_EQUAL and std::wstring

I am using the Boost unit test suite for the first time, but am having a problem using BOOST_CHECK_EQUAL with wide strings. For example: std::wstring str1 = L"unit"; std::wstring str2 = L"test"; BOOST_CHECK_EQUAL(str1, str2); This produces the following error: c:\boost\include\boost-1_33_1\boost\test\test_tools.hpp(274) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion) Any help would be appreciated.

Rob Caldecott a écrit :
I am using the Boost unit test suite for the first time, but am having a problem using BOOST_CHECK_EQUAL with wide strings. For example:
std::wstring str1 = L"unit";
std::wstring str2 = L"test";
BOOST_CHECK_EQUAL(str1, str2);
This produces the following error:
c:\boost\include\boost-1_33_1\boost\test\test_tools.hpp(274) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion)
Boost::test may want to display the values of those wide strings on a narrow stream if the test fails, thus your error. Try adding something like namespace std { inline std::ostream& operator<<(std::ostream& out, const std::wstring& value) { out << ConvertWstringToString(value); return out; } } With some appropriate definition for ConvertWstringToString. -- Loïc

"Loïc Joly"
wrote in message news:ebd5k9$18p$1@sea.gmane.org... Rob Caldecott a écrit : I am using the Boost unit test suite for the first time, but am having a problem using BOOST_CHECK_EQUAL with wide strings. For example:
std::wstring str1 = L"unit";
std::wstring str2 = L"test";
BOOST_CHECK_EQUAL(str1, str2);
This produces the following error:
c:\boost\include\boost-1_33_1\boost\test\test_tools.hpp(274) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion)
Boost::test may want to display the values of those wide strings on a narrow stream if the test fails, thus your error.
Try adding something like
namespace std { inline std::ostream& operator<<(std::ostream& out, const std::wstring& value) { out << ConvertWstringToString(value); return out; }
}
This sound about right. I plan to revisit wide strings/streams support next release to allow users to select at compile time what kind of character type to use throughout the framework. Gennadiy
participants (3)
-
Gennadiy Rozental
-
Loïc Joly
-
Rob Caldecott