function_n_test:

function_test:
  - Add testcases using ref() wrapper


[SVN r11873]
This commit is contained in:
Douglas Gregor
2001-12-03 16:25:00 +00:00
parent 2265421357
commit 1512df77b1
2 changed files with 61 additions and 0 deletions

View File

@ -604,6 +604,35 @@ test_member_functions()
BOOST_TEST(f2(five, 4) == 9); BOOST_TEST(f2(five, 4) == 9);
} }
struct add_with_throw_on_copy {
int operator()(int x, int y) const { return x+y; }
add_with_throw_on_copy() {}
add_with_throw_on_copy(const add_with_throw_on_copy&)
{
throw std::runtime_error("But this CAN'T throw");
}
add_with_throw_on_copy& operator=(const add_with_throw_on_copy&)
{
throw std::runtime_error("But this CAN'T throw");
}
};
static void
test_ref()
{
add_with_throw_on_copy atc;
try {
boost::function2<int, int, int> f(ref(atc));
BOOST_TEST(f(1, 3) == 4);
}
catch(std::runtime_error e) {
BOOST_ERROR("Nonthrowing constructor threw an exception");
}
};
int test_main(int, char* []) int test_main(int, char* [])
{ {
test_zero_args(); test_zero_args();
@ -611,5 +640,6 @@ int test_main(int, char* [])
test_two_args(); test_two_args();
test_emptiness(); test_emptiness();
test_member_functions(); test_member_functions();
test_ref();
return 0; return 0;
} }

View File

@ -603,6 +603,35 @@ test_member_functions()
BOOST_TEST(f2(five, 4) == 9); BOOST_TEST(f2(five, 4) == 9);
} }
struct add_with_throw_on_copy {
int operator()(int x, int y) const { return x+y; }
add_with_throw_on_copy() {}
add_with_throw_on_copy(const add_with_throw_on_copy&)
{
throw std::runtime_error("But this CAN'T throw");
}
add_with_throw_on_copy& operator=(const add_with_throw_on_copy&)
{
throw std::runtime_error("But this CAN'T throw");
}
};
static void
test_ref()
{
add_with_throw_on_copy atc;
try {
boost::function<int, int, int> f(ref(atc));
BOOST_TEST(f(1, 3) == 4);
}
catch(std::runtime_error e) {
BOOST_ERROR("Nonthrowing constructor threw an exception");
}
};
int test_main(int, char* []) int test_main(int, char* [])
{ {
test_zero_args(); test_zero_args();
@ -610,5 +639,7 @@ int test_main(int, char* [])
test_two_args(); test_two_args();
test_emptiness(); test_emptiness();
test_member_functions(); test_member_functions();
test_ref();
return 0; return 0;
} }