How to make boost.test log wstring?

Boost.test logs to ostream, which does not have an operator for wstring. Consequently, I cannot test wstring values. How can I fix this?

On Fri, Feb 5, 2010 at 12:53 PM, Alexey Badalov <don_reba@inbox.ru> wrote:
Boost.test logs to ostream, which does not have an operator for wstring. Consequently, I cannot test wstring values. How can I fix this?
For the time being you can convert it to a UTF-8 encoded std::string, it will not be a perfect mapping, but may be accurate enough for your needs until someone else suggests something better.

Alexey Badalov <don_reba <at> inbox.ru> writes:
Boost.test logs to ostream, which does not have an operator for wstring. Consequently, I cannot test wstring values. How can I fix this?
You can send in a patch which will make Boost.Test work with both ostream and wostream. Also you cna write an operator << (ostream&,wstring const&) Gennadiy

"Gennadiy Rozental" <rogeeff@gmail.com> wrote in message news:loom.20100206T071834-814@post.gmane.org...
You can send in a patch which will make Boost.Test work with both ostream and wostream. Also you cna write an operator << (ostream&,wstring const&)
I tried to put the operator above "#include <boost/test/unit_test.hpp>", but the same error persists, and mine is not in the candidate operator overload list displayed in the message - only operators defined in <ostream> are listed. My operator lets me output wstrings to std::cout from test cases, but when "boost\test\test_tools.hpp" tries to do it, it does not compile. I am using boost 1.41.0 and vc9. Here is my code and the error: #include <iostream> #include <string> std::ostream & operator << (std::ostream & stream, const std::wstring & str) { return stream << "std::wstring"; } #define BOOST_TEST_MODULE const_string test #include <boost/test/unit_test.hpp> BOOST_AUTO_TEST_CASE(Test) { std::wstring wstr; std::cout << wstr; // OK BOOST_CHECK_EQUAL(wstr, wstr); // Error } test.cpp ...\boost\test\test_tools.hpp(326) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'const std::wstring' (or there is no acceptable conversion) ... while trying to match the argument list '(std::ostream, const std::wstring)' ...\boost\test\test_tools.hpp(318) : while compiling class template member function 'void boost::test_tools::print_log_value<T>::operator ()(std::ostream &,const T &)' with [ T=std::wstring ]

Alexey Badalov <don_reba <at> inbox.ru> writes:
"Gennadiy Rozental" <rogeeff <at> gmail.com> wrote in message news:loom.20100206T071834-814 <at> post.gmane.org...
You can send in a patch which will make Boost.Test work with both ostream and wostream. Also you cna write an operator << (ostream&,wstring const&)
I tried to put the operator above "#include <boost/test/unit_test.hpp>", but the same error persists, and mine is not in the candidate operator overload list displayed in the message - only operators defined in <ostream> are
Unfortunately I believe there only way to circumvent this it to define the operator in namespace std. Gennadiy

In article <hkhsvn$jor$1@ger.gmane.org>, don_reba@inbox.ru says...
Boost.test logs to ostream, which does not have an operator for wstring. Consequently, I cannot test wstring values. How can I fix this?
One alternative is to simply use BOOST_CHECK and the == operator: BOOST_CHECK(obj.get_wstring() == L"Expected"); Lacks the nice output, but it's quite easy.
participants (4)
-
Alexey Badalov
-
Gennadiy Rozental
-
Noah Roberts
-
OvermindDL1