diff --git a/test/defarg_test.cpp b/test/defarg_test.cpp deleted file mode 100644 index a9ee0e1..0000000 --- a/test/defarg_test.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Boost.Function library - -// Copyright (C) 2001 Doug Gregor (gregod@cs.rpi.edu) -// -// Permission to copy, use, sell and distribute this software is granted -// provided this copyright notice appears in all copies. -// Permission to modify the code and to distribute modified code is granted -// provided this copyright notice appears in all copies, and a notice -// that the code was modified is included with the copyright notice. -// -// This software is provided "as is" without express or implied warranty, -// and with no claim as to its suitability for any purpose. - -// For more information, see http://www.boost.org - -#define BOOST_INCLUDE_MAIN -#include -#include -#include -#include -#include - -using namespace std; -using namespace boost; - -static int sub_ints(int x = 5, int y = 3, int z = 1) { return x-y-z; } - -static void -test_zero_args() -{ - function one(&sub_ints); - BOOST_TEST(one() == 1); -} - -static void -test_one_arg() -{ - function minus_four(&sub_ints); - BOOST_TEST(minus_four(7) == 3); -} - -static void -test_two_args() -{ - function sub(&sub_ints); - BOOST_TEST(sub(10, 2) == 7); -} - -int -test_main(int, char* []) -{ - test_zero_args(); - test_one_arg(); - test_two_args(); - return 0; -} diff --git a/test/function_n_test.cpp b/test/function_n_test.cpp index 93b13d3..77d643b 100644 --- a/test/function_n_test.cpp +++ b/test/function_n_test.cpp @@ -44,6 +44,15 @@ struct write_const_1_nonconst_2 void operator()() const { global_int = 1; } }; +struct add_to_obj +{ + add_to_obj(int v) : value(v) {} + + int operator()(int x) const { return value + x; } + + int value; +}; + static void test_zero_args() { @@ -514,6 +523,8 @@ test_zero_args() BOOST_TEST(i1); i1.clear(); BOOST_TEST(!i1); + + BOOST_TEST(i1.target_type() == typeid(void)); } static void @@ -529,6 +540,17 @@ test_one_arg() function1 id2(&identity_str); BOOST_TEST(id2("foo") == "foo"); + + add_to_obj add_to(5); + function1 f2(add_to); + BOOST_TEST(f2(3) == 8); + BOOST_TEST(f2.target_type() == typeid(add_to_obj)); + function_cast(f2).value = 12; + BOOST_TEST(f2(3) == 15); + + const function1 cf2(add_to); + BOOST_TEST(cf2(3) == 8); + BOOST_TEST(cf2.target_type() == typeid(add_to_obj)); } static void diff --git a/test/function_test.cpp b/test/function_test.cpp index e7da119..8ba6d98 100644 --- a/test/function_test.cpp +++ b/test/function_test.cpp @@ -44,6 +44,15 @@ struct write_const_1_nonconst_2 void operator()() const { global_int = 1; } }; +struct add_to_obj +{ + add_to_obj(int v) : value(v) {} + + int operator()(int x) const { return value + x; } + + int value; +}; + static void test_zero_args() { @@ -514,6 +523,8 @@ test_zero_args() BOOST_TEST(i1); i1.clear(); BOOST_TEST(!i1); + + BOOST_TEST(i1.target_type() == typeid(void)); } static void @@ -529,6 +540,17 @@ test_one_arg() function id2(&identity_str); BOOST_TEST(id2("foo") == "foo"); + + add_to_obj add_to(5); + function f2(add_to); + BOOST_TEST(f2(3) == 8); + BOOST_TEST(f2.target_type() == typeid(add_to_obj)); + function_cast(f2).value = 12; + BOOST_TEST(f2(3) == 15); + + const function cf2(add_to); + BOOST_TEST(cf2(3) == 8); + BOOST_TEST(cf2.target_type() == typeid(add_to_obj)); } static void