[test] BOOST_*_EQUAL against constants
A common scenario in my tests is comparing some unsigned value against a constant (most often 0 or 1): BOOST_REQUIRE_EQUAL(cbRead, 0); However, this generates a warning on MSVC complaining about a signed/unsigned mismatch (full message included at end): c:\boost\test\test_tools.hpp(536) : warning C4389: '==' : signed/unsigned mismatch c:\boost\test\test_tools.hpp(560) : see reference to function template instantiation 'boost::test_tools::predicate_result boost::test_tools::tt_detail::equal_impl(const Left &,const Right &)' being compiled with [ Left=ULONG, Right=int ] I can obviously cast the 0 constant to an unsigned it but it's getting tedious doing this every time. Surely there must be a better way? Is there some way to force the comparison to interpret constants as being of whatever type they are being compared to? Thanks. Alex c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(536) : warning C4389: '==' : signed/unsigned mismatch c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(560) : see reference to function template instantiation 'boost::test_tools::predicate_result boost::test_tools::tt_detail::equal_impl(const Left &,const Right &)' being compiled with [ Left=ULONG, Right=int ] c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(575) : see reference to function template instantiation 'boost::test_tools::predicate_result boost::test_tools::tt_detail::equal_impl_frwd::call_impl(const Left &,const Right &,boost::mpl::false_) const' being compiled with [ Left=ULONG, Right=int ] c:\program files\boost\boost_1_38\boost\test\test_tools.hpp(523) : see reference to function template instantiation 'boost::test_tools::predicate_result boost::test_tools::tt_detail::equal_impl_frwd::operator ()(const Left &,const Right &) const' being compiled with [ Arg0=ULONG, Arg1=int, Left=ULONG, Right=int ] c:\users\awl03\documents\visual studio 2005\projects\swish_feature_write\test\provider\stream_write_test.cpp(202) : see reference to function template instantiation 'bool boost::test_tools::tt_detail::check_frwd(Pred,const boost::unit_test::lazy_ostream &,boost::test_tools::const_string,size_t,boost::test_tools::tt_detail::tool_level,boost::test_tools::tt_detail::check_type,const Arg0 &,const char *,const Arg1 &,const char *)' being compiled with [ Pred=boost::test_tools::tt_detail::equal_impl_frwd, Arg0=ULONG, Arg1=int ]
Alexander Lamaison
I can obviously cast the 0 constant to an unsigned it but it's getting tedious doing this every time. Surely there must be a better way?
1. Use 0U 2. Define ULONG uzero = 0; and use it in comparisons. 3. Define your own macros which take 2 args, cast to right type one of them and forward them to BOOST_CHECK_EQUAL.
Is there some way to force the comparison to interpret constants as being of whatever type they are being compared to?
How can I know which one is constant? What is the correct type out of 2? Type of left argument or right? I thought about automatic type promotion at some point, but never came up with reasonable design. Gennadiy
On Sun, 19 Jul 2009 01:54:18 +0000 (UTC), Gennadiy Rozental wrote:
Alexander Lamaison
writes: I can obviously cast the 0 constant to an unsigned it but it's getting tedious doing this every time. Surely there must be a better way?
1. Use 0U
0U?! How in 10 years of C/C++ have I managed to completely miss this? Thanks :D Alex
participants (2)
-
Alexander Lamaison
-
Gennadiy Rozental