[Boost-users] How to make boost.test log wstring?

410 views
Skip to first unread message

Alexey Badalov

unread,
Feb 5, 2010, 2:53:24 PM2/5/10
to boost...@lists.boost.org
Boost.test logs to ostream, which does not have an operator for wstring.
Consequently, I cannot test wstring values. How can I fix this?


_______________________________________________
Boost-users mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

OvermindDL1

unread,
Feb 5, 2010, 11:10:58 PM2/5/10
to boost...@lists.boost.org
On Fri, Feb 5, 2010 at 12:53 PM, Alexey Badalov <don_...@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.

Gennadiy Rozental

unread,
Feb 6, 2010, 1:20:39 AM2/6/10
to boost...@lists.boost.org
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

Alexey Badalov

unread,
Feb 6, 2010, 4:54:39 AM2/6/10
to boost...@lists.boost.org

"Gennadiy Rozental" <rog...@gmail.com> wrote in message
news:loom.2010020...@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
]

Gennadiy Rozental

unread,
Feb 6, 2010, 10:38:24 AM2/6/10
to boost...@lists.boost.org
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

Alexey Badalov

unread,
Feb 6, 2010, 11:14:27 AM2/6/10
to boost...@lists.boost.org
> Unfortunately I believe there only way to circumvent this it to define the
> operator in namespace std.

Ah, totally forgot this can be a problem. Thanks, it works now.

Noah Roberts

unread,
Feb 9, 2010, 1:08:49 PM2/9/10
to boost...@lists.boost.org
In article <hkhsvn$jor$1...@ger.gmane.org>, don_...@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.

Reply all
Reply to author
Forward
0 new messages