Syntax error when using BOOST_CHECK_PREDICATE
Reading this article: http://www.ibm.com/developerworks/aix/library/au-ctools1_boost/?S_TACT=105AGY20&S_CMP=HP I'm using Boost 1.40.0 and Visual Studio 2005 with Visual C++ 8.0. I've entered Listing 14 with a few additional lines of logging code: #include "stdafx.h" #define BOOST_TEST_MODULE example #include <boost/test/included/unit_test.hpp> std::list<int> user_defined_func( ) { std::cout << "BEGIN: user_defined_func" << std::endl; std::list<int> l; l.push_back(8); l.push_back(0); std::cout << "END: user_defined_func" << std::endl; return l; } bool validate_list(std::list<int> &L1) { std::cout << "BEGIN: validate_list" << std::endl; std::list<int>::iterator it1 = L1.begin(); for(; it1 != L1.end(); ++it1) { if(*it1<= 1){ std::cout << "Validation failed because an item in the list was less than or equal to 1." << std::endl; std::cout << "END: validate_list" << std::endl; return false; } } std::cout << "Test passed because all of the items in the list were greater than or equal to 1" << std::endl; std::cout << "END: validate_list" << std::endl; return true; } BOOST_AUTO_TEST_SUITE( test ) BOOST_AUTO_TEST_CASE( test ) { std::list<int>& list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, list1 ); } BOOST_AUTO_TEST_SUITE_END() Now when I go to compile this, it ends up giving me an error: 1>------ Build started: Project: UnitTestTests, Configuration: Debug Win32 ------ 1>Compiling... 1>UnitTestTests.cpp 1>c:\program files (x86)\boost\boost_1_40\boost\test\impl\execution_monitor.ipp(904) : warning C4535: calling _set_se_translator() requires /EHa 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\config.hpp(90) : warning C4996: 'putenv': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _putenv. See online help for details. 1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdlib.h(900) : see declaration of 'putenv' 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\char_parameter.ipp(36) : warning C4244: 'argument' : conversion from 'boost::rtti::id_t' to 'const int', possible loss of data 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\named_parameter.ipp(41) : warning C4244: 'argument' : conversion from 'boost::rtti::id_t' to 'const int', possible loss of data 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\env\environment.ipp(82) : warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdlib.h(483) : see declaration of 'getenv' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2146: syntax error : missing ')' before identifier 'BOOST_PP_IIF_BOOST_PP_BOOL_0' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2780: '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 *,const Arg2 &,const char *,const Arg3 &,const char *,const Arg4 &,const char *)' : expects 16 arguments - 6 provided 1> c:\program files (x86)\boost\boost_1_40\boost\test\test_tools.hpp(523) : see declaration of 'boost::test_tools::tt_detail::check_frwd' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2780: '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 *,const Arg2 &,const char *,const Arg3 &,const char *)' : expects 14 arguments - 6 provided 1> c:\program files (x86)\boost\boost_1_40\boost\test\test_tools.hpp(523) : see declaration of 'boost::test_tools::tt_detail::check_frwd' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2780: '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 *,const Arg2 &,const char *)' : expects 12 arguments - 6 provided 1> c:\program files (x86)\boost\boost_1_40\boost\test\test_tools.hpp(523) : see declaration of 'boost::test_tools::tt_detail::check_frwd' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2780: '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 *)' : expects 10 arguments - 6 provided 1> c:\program files (x86)\boost\boost_1_40\boost\test\test_tools.hpp(523) : see declaration of 'boost::test_tools::tt_detail::check_frwd' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2780: '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 *)' : expects 8 arguments - 6 provided 1> c:\program files (x86)\boost\boost_1_40\boost\test\test_tools.hpp(523) : see declaration of 'boost::test_tools::tt_detail::check_frwd' 1>c:\users\andy\documents\visual studio 2005\projects\unittesttests\unittesttests\unittesttests.cpp(45) : error C2059: syntax error : ')' 1>Build log was saved at "file://c:\Users\andy\Documents\Visual Studio 2005\Projects\UnitTestTests\UnitTestTests\Debug\BuildLog.htm" It seems to have some real problems with the BOOST_CHECK_PREDICATE macro why is this? Thank you, Andrew J. Leer 1>UnitTestTests - 7 error(s), 5 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Andrew J. Leer <leeand00 <at> hotmail.com> writes:
BOOST_AUTO_TEST_CASE( test ) { std::list<int>& list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, list1 );
I believe this should be BOOST_CHECK_PREDICATE( validate_list, (list1) ); Gennadiy
Gennadiy, I tried changing what you stated
BOOST_AUTO_TEST_CASE( test ) { std::list<int>& list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, list1 );
I believe this should be BOOST_CHECK_PREDICATE( validate_list, (list1) );
However upon doing that I get another error (something to do with templates) 1>------ Rebuild All started: Project: UnitTestTests, Configuration: Debug Win32 ------ 1>Deleting intermediate and output files for project 'UnitTestTests', configuration 'Debug|Win32' 1>Compiling... 1>stdafx.cpp 1>Compiling... 1>UnitTestTests.cpp 1>c:\program files (x86)\boost\boost_1_40\boost\test\impl\execution_monitor.ipp(904) : warning C4535: calling _set_se_translator() requires /EHa 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\config.hpp(90) : warning C4996: 'putenv': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _putenv. See online help for details. 1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdlib.h(900) : see declaration of 'putenv' 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\char_parameter.ipp(36) : warning C4244: 'argument' : conversion from 'boost::rtti::id_t' to 'const int', possible loss of data 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\named_parameter.ipp(41) : warning C4244: 'argument' : conversion from 'boost::rtti::id_t' to 'const int', possible loss of data 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\env\environment.ipp(82) : warning C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 8\vc\include\stdlib.h(483) : see declaration of 'getenv' 1>c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\id_policy.hpp(88) : warning C4244: 'argument' : conversion from 'boost::rtti::id_t' to 'const int', possible loss of data 1> c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\id_policy.hpp(84) : while compiling class template member function 'boost::runtime::cla::dual_id_policy<MostDerived,PrimaryId,SecondId>::dual_id_policy(void)' 1> with 1> [ 1> MostDerived=boost::runtime::cla::dual_name_policy, 1> PrimaryId=boost::runtime::cla::string_name_policy, 1> SecondId=boost::runtime::cla::char_name_policy 1> ] 1> c:\program files (x86)\boost\boost_1_40\boost\test\utils\runtime\cla\dual_name_parameter.hpp(34) : see reference to class template instantiation 'boost::runtime::cla::dual_id_policy<MostDerived,PrimaryId,SecondId>' being compiled 1> with 1> [ 1> MostDerived=boost::runtime::cla::dual_name_policy, 1> PrimaryId=boost::runtime::cla::string_name_policy, 1> SecondId=boost::runtime::cla::char_name_policy 1> ] 1>c:\program files (x86)\boost\boost_1_40\boost\test\test_tools.hpp(523) : error C2664: 'bool (std::list<_Ty> &)' : cannot convert parameter 1 from 'const std::list<_Ty>' to 'std::list<_Ty> &' 1> with 1> [ 1> _Ty=int 1> ] 1> Conversion loses qualifiers 1> c:\users\xetex\documents\visual studio 2005\projects\unittesttestsexample14\unittesttests\unittesttests.cpp(45) : see reference to function template instantiation 'bool boost::test_tools::tt_detail::check_frwd<bool(__cdecl *)(std::list<_Ty> &),std::list<_Ty>>(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 *)' being compiled 1> with 1> [ 1> _Ty=int, 1> Pred=bool (__cdecl *)(std::list<int> &), 1> Arg0=std::list<int> 1> ] 1>Build log was saved at "file://c:\Users\XETEX\Documents\Visual Studio 2005\Projects\UnitTestTestsExample14\UnitTestTests\Debug\BuildLog.htm" 1>UnitTestTests - 1 error(s), 6 warning(s) ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== Thank you, Andrew J. Leer On Sun, Dec 13, 2009 at 6:19 AM, Gennadiy Rozental <rogeeff@gmail.com> wrote:
Andrew J. Leer <leeand00 <at> hotmail.com> writes:
BOOST_AUTO_TEST_CASE( test ) { std::list<int>& list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, list1 );
I believe this should be BOOST_CHECK_PREDICATE( validate_list, (list1) );
Gennadiy
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Andrew J. Leer wrote:
Gennadiy, I tried changing what you stated
BOOST_AUTO_TEST_CASE( test ) { std::list<int>& list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, list1 );
I believe this should be BOOST_CHECK_PREDICATE( validate_list, (list1) );
However upon doing that I get another error (something to do with templates)
Please post small example illustrating the problem. Gennadiy
Here is my example: #include "stdafx.h" #define BOOST_TEST_MODULE example #include <boost/test/included/unit_test.hpp> std::list<int>* user_defined_func( ) { std::cout << "BEGIN: user_defined_func" << std::endl; std::list<int>* l = new std::list<int>; l->push_back(8); l->push_back(0); std::cout << "END: user_defined_func" << std::endl; return l; } bool validate_list(std::list<int> &L1) { std::cout << "BEGIN: validate_list" << std::endl; std::list<int>::iterator it1 = L1.begin(); for(; it1 != L1.end(); ++it1) { if(*it1<= 1){ std::cout << "Validation failed because an item in the list was less than or equal to 1." << std::endl; std::cout << "END: validate_list" << std::endl; return false; } } std::cout << "Test passed because all of the items in the list were greater than or equal to 1" << std::endl; std::cout << "END: validate_list" << std::endl; return true; } BOOST_AUTO_TEST_SUITE( test ) BOOST_AUTO_TEST_CASE( test ) { std::list<int>* list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, (list1) ); } BOOST_AUTO_TEST_SUITE_END() Thank you, Andrew J. Leer On Sun, Jan 3, 2010 at 8:00 PM, Gennadiy Rozental <rogeeff@gmail.com> wrote:
Andrew J. Leer wrote:
Gennadiy, I tried changing what you stated
BOOST_AUTO_TEST_CASE( test ) { std::list<int>& list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, list1 );
I believe this should be BOOST_CHECK_PREDICATE( validate_list, (list1) );
However upon doing that I get another error (something to do with templates)
Please post small example illustrating the problem.
Gennadiy
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Andrew J. Leer <leeand00 <at> hotmail.com> writes:
bool validate_list(std::list<int> &L1) ...
BOOST_AUTO_TEST_SUITE( test ) BOOST_AUTO_TEST_CASE( test ) { std::list<int>* list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, (list1) ); } BOOST_AUTO_TEST_SUITE_END()
No surprises here: can't pass pointer to the function expecting reference. Gennadiy
Okay here's the new source, thanks Gennadiy for your time on this. #include "stdafx.h" #define BOOST_TEST_MODULE example #include <boost/test/included/unit_test.hpp> std::list<int>* user_defined_func( ) { std::cout << "BEGIN: user_defined_func" << std::endl; std::list<int>* l = new std::list<int>; l->push_back(8); l->push_back(2); std::cout << "END: user_defined_func" << std::endl; return l; } bool validate_list(std::list<int>* L1) { std::cout << "BEGIN: validate_list" << std::endl; std::list<int>::iterator it1 = L1->begin(); for(; it1 != L1->end(); ++it1) { std::cout << "*it1: " << *it1 << std::endl; if(*it1 <= 1){ std::cout << "Validation failed because an item in the list was less than or equal to 1." << std::endl; std::cout << "END: validate_list" << std::endl; return false; } } std::cout << "Test passed because all of the items in the list were greater than or equal to 1" << std::endl; std::cout << "END: validate_list" << std::endl; return true; } BOOST_AUTO_TEST_SUITE( test ) BOOST_AUTO_TEST_CASE( test ) { std::list<int>* list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, (list1) ); delete list1; } BOOST_AUTO_TEST_SUITE_END() On Tue, Feb 23, 2010 at 5:09 PM, Gennadiy Rozental <rogeeff@gmail.com> wrote:
Andrew J. Leer <leeand00 <at> hotmail.com> writes:
bool validate_list(std::list<int> &L1) ...
BOOST_AUTO_TEST_SUITE( test ) BOOST_AUTO_TEST_CASE( test ) { std::list<int>* list1 = user_defined_func(); BOOST_CHECK_PREDICATE( validate_list, (list1) ); } BOOST_AUTO_TEST_SUITE_END()
No surprises here: can't pass pointer to the function expecting reference.
Gennadiy
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Andrew J. Leer <leeand00 <at> hotmail.com> writes:
Okay here's the new source, thanks Gennadiy for your time on this.
Not sure what the example was illustrating, but it compiles fine for me (gcc 4.1). Gennadiy
participants (2)
-
Andrew J. Leer
-
Gennadiy Rozental