mirror of
https://github.com/boostorg/function.git
synced 2025-07-23 01:17:14 +02:00
defarg_test.cpp: removed (it is incorrect)
function_n_test.cpp: function_test.cpp: Updated with tests of target_type() and casting [SVN r11361]
This commit is contained in:
@ -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 <boost/test/test_tools.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <functional>
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
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<int> one(&sub_ints);
|
||||
BOOST_TEST(one() == 1);
|
||||
}
|
||||
|
||||
static void
|
||||
test_one_arg()
|
||||
{
|
||||
function<int, int> minus_four(&sub_ints);
|
||||
BOOST_TEST(minus_four(7) == 3);
|
||||
}
|
||||
|
||||
static void
|
||||
test_two_args()
|
||||
{
|
||||
function<int, int, int> 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;
|
||||
}
|
@ -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<std::string, char*> id2(&identity_str);
|
||||
BOOST_TEST(id2("foo") == "foo");
|
||||
|
||||
add_to_obj add_to(5);
|
||||
function1<int, int> f2(add_to);
|
||||
BOOST_TEST(f2(3) == 8);
|
||||
BOOST_TEST(f2.target_type() == typeid(add_to_obj));
|
||||
function_cast<add_to_obj>(f2).value = 12;
|
||||
BOOST_TEST(f2(3) == 15);
|
||||
|
||||
const function1<int, int> cf2(add_to);
|
||||
BOOST_TEST(cf2(3) == 8);
|
||||
BOOST_TEST(cf2.target_type() == typeid(add_to_obj));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -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<std::string, char*> id2(&identity_str);
|
||||
BOOST_TEST(id2("foo") == "foo");
|
||||
|
||||
add_to_obj add_to(5);
|
||||
function<int, int> f2(add_to);
|
||||
BOOST_TEST(f2(3) == 8);
|
||||
BOOST_TEST(f2.target_type() == typeid(add_to_obj));
|
||||
function_cast<add_to_obj>(f2).value = 12;
|
||||
BOOST_TEST(f2(3) == 15);
|
||||
|
||||
const function<int, int> cf2(add_to);
|
||||
BOOST_TEST(cf2(3) == 8);
|
||||
BOOST_TEST(cf2.target_type() == typeid(add_to_obj));
|
||||
}
|
||||
|
||||
static void
|
||||
|
Reference in New Issue
Block a user