mirror of
https://github.com/boostorg/function.git
synced 2025-07-30 21:07:13 +02:00
Replace Boost.Test use with lwtest
This commit is contained in:
@ -25,11 +25,11 @@ import testing ;
|
|||||||
|
|
||||||
[ run libs/function/test/function_n_test.cpp : : : : ]
|
[ run libs/function/test/function_n_test.cpp : : : : ]
|
||||||
|
|
||||||
[ run libs/function/test/allocator_test.cpp ../../../libs/test/build//boost_test_exec_monitor : : : : ]
|
[ run libs/function/test/allocator_test.cpp ]
|
||||||
|
|
||||||
[ run libs/function/test/stateless_test.cpp ../../../libs/test/build//boost_test_exec_monitor : : : : ]
|
[ run libs/function/test/stateless_test.cpp ]
|
||||||
|
|
||||||
[ run libs/function/test/lambda_test.cpp ../../../libs/test/build//boost_test_exec_monitor : : : : ]
|
[ run libs/function/test/lambda_test.cpp ]
|
||||||
|
|
||||||
[ compile-fail libs/function/test/function_test_fail1.cpp : : : : ]
|
[ compile-fail libs/function/test/function_test_fail1.cpp : : : : ]
|
||||||
|
|
||||||
|
@ -7,10 +7,10 @@
|
|||||||
|
|
||||||
// For more information, see http://www.boost.org
|
// For more information, see http://www.boost.org
|
||||||
|
|
||||||
#include <boost/test/minimal.hpp>
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <boost/function.hpp>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost;
|
using namespace boost;
|
||||||
@ -74,20 +74,19 @@ struct DoNothing: base
|
|||||||
|
|
||||||
static void do_nothing() {}
|
static void do_nothing() {}
|
||||||
|
|
||||||
int
|
int main()
|
||||||
test_main(int, char*[])
|
|
||||||
{
|
{
|
||||||
function2<int, int, int> f;
|
function2<int, int, int> f;
|
||||||
f.assign( plus_int<disable_small_object_optimization>(), counting_allocator<int>() );
|
f.assign( plus_int<disable_small_object_optimization>(), counting_allocator<int>() );
|
||||||
f.clear();
|
f.clear();
|
||||||
BOOST_CHECK(alloc_count == 1);
|
BOOST_TEST_EQ( alloc_count, 1 );
|
||||||
BOOST_CHECK(dealloc_count == 1);
|
BOOST_TEST_EQ( dealloc_count, 1 );
|
||||||
alloc_count = 0;
|
alloc_count = 0;
|
||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
f.assign( plus_int<enable_small_object_optimization>(), counting_allocator<int>() );
|
f.assign( plus_int<enable_small_object_optimization>(), counting_allocator<int>() );
|
||||||
f.clear();
|
f.clear();
|
||||||
BOOST_CHECK(alloc_count == 0);
|
BOOST_TEST_EQ( alloc_count, 0 );
|
||||||
BOOST_CHECK(dealloc_count == 0);
|
BOOST_TEST_EQ( dealloc_count, 0 );
|
||||||
f.assign( plus_int<disable_small_object_optimization>(), std::allocator<int>() );
|
f.assign( plus_int<disable_small_object_optimization>(), std::allocator<int>() );
|
||||||
f.clear();
|
f.clear();
|
||||||
f.assign( plus_int<enable_small_object_optimization>(), std::allocator<int>() );
|
f.assign( plus_int<enable_small_object_optimization>(), std::allocator<int>() );
|
||||||
@ -97,8 +96,8 @@ test_main(int, char*[])
|
|||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
f.assign( &do_minus, counting_allocator<int>() );
|
f.assign( &do_minus, counting_allocator<int>() );
|
||||||
f.clear();
|
f.clear();
|
||||||
BOOST_CHECK(alloc_count == 0);
|
BOOST_TEST_EQ( alloc_count, 0 );
|
||||||
BOOST_CHECK(dealloc_count == 0);
|
BOOST_TEST_EQ( dealloc_count, 0 );
|
||||||
f.assign( &do_minus, std::allocator<int>() );
|
f.assign( &do_minus, std::allocator<int>() );
|
||||||
f.clear();
|
f.clear();
|
||||||
|
|
||||||
@ -107,14 +106,14 @@ test_main(int, char*[])
|
|||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
fv.assign( DoNothing<disable_small_object_optimization>(), counting_allocator<int>() );
|
fv.assign( DoNothing<disable_small_object_optimization>(), counting_allocator<int>() );
|
||||||
fv.clear();
|
fv.clear();
|
||||||
BOOST_CHECK(alloc_count == 1);
|
BOOST_TEST_EQ( alloc_count, 1 );
|
||||||
BOOST_CHECK(dealloc_count == 1);
|
BOOST_TEST_EQ( dealloc_count, 1 );
|
||||||
alloc_count = 0;
|
alloc_count = 0;
|
||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
fv.assign( DoNothing<enable_small_object_optimization>(), counting_allocator<int>() );
|
fv.assign( DoNothing<enable_small_object_optimization>(), counting_allocator<int>() );
|
||||||
fv.clear();
|
fv.clear();
|
||||||
BOOST_CHECK(alloc_count == 0);
|
BOOST_TEST_EQ( alloc_count, 0 );
|
||||||
BOOST_CHECK(dealloc_count == 0);
|
BOOST_TEST_EQ( dealloc_count, 0 );
|
||||||
fv.assign( DoNothing<disable_small_object_optimization>(), std::allocator<int>() );
|
fv.assign( DoNothing<disable_small_object_optimization>(), std::allocator<int>() );
|
||||||
fv.clear();
|
fv.clear();
|
||||||
fv.assign( DoNothing<enable_small_object_optimization>(), std::allocator<int>() );
|
fv.assign( DoNothing<enable_small_object_optimization>(), std::allocator<int>() );
|
||||||
@ -124,8 +123,8 @@ test_main(int, char*[])
|
|||||||
dealloc_count = 0;
|
dealloc_count = 0;
|
||||||
fv.assign( &do_nothing, counting_allocator<int>() );
|
fv.assign( &do_nothing, counting_allocator<int>() );
|
||||||
fv.clear();
|
fv.clear();
|
||||||
BOOST_CHECK(alloc_count == 0);
|
BOOST_TEST_EQ( alloc_count, 0 );
|
||||||
BOOST_CHECK(dealloc_count == 0);
|
BOOST_TEST_EQ( dealloc_count, 0 );
|
||||||
fv.assign( &do_nothing, std::allocator<int>() );
|
fv.assign( &do_nothing, std::allocator<int>() );
|
||||||
fv.clear();
|
fv.clear();
|
||||||
|
|
||||||
@ -133,5 +132,5 @@ test_main(int, char*[])
|
|||||||
fv.assign(&do_nothing, std::allocator<int>() );
|
fv.assign(&do_nothing, std::allocator<int>() );
|
||||||
fv2.assign(fv, std::allocator<int>() );
|
fv2.assign(fv, std::allocator<int>() );
|
||||||
|
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
@ -7,13 +7,13 @@
|
|||||||
|
|
||||||
// For more information, see http://www.boost.org
|
// For more information, see http://www.boost.org
|
||||||
|
|
||||||
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/lambda/lambda.hpp>
|
||||||
|
#include <boost/lambda/bind.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
#include <boost/test/minimal.hpp>
|
|
||||||
#include <boost/lambda/lambda.hpp>
|
|
||||||
#include <boost/lambda/bind.hpp>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
|
|
||||||
static unsigned
|
static unsigned
|
||||||
func_impl(int arg1, bool arg2, double arg3)
|
func_impl(int arg1, bool arg2, double arg3)
|
||||||
@ -22,17 +22,19 @@ func_impl(int arg1, bool arg2, double arg3)
|
|||||||
return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
|
return abs (static_cast<int>((arg2 ? arg1 : 2 * arg1) * arg3));
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_main(int, char*[])
|
int main()
|
||||||
{
|
{
|
||||||
using boost::function;
|
using boost::function;
|
||||||
using namespace boost::lambda;
|
using namespace boost::lambda;
|
||||||
|
|
||||||
function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
|
function <unsigned(bool, double)> f1 = bind(func_impl, 15, _1, _2);
|
||||||
|
BOOST_TEST_EQ( f1(true, 2.0), 30 );
|
||||||
|
|
||||||
function <unsigned(double)> f2 = boost::lambda::bind(f1, false, _1);
|
function <unsigned(double)> f2 = boost::lambda::bind(f1, false, _1);
|
||||||
|
BOOST_TEST_EQ( f2(2.0), 60 );
|
||||||
|
|
||||||
function <unsigned()> f3 = boost::lambda::bind(f2, 4.0);
|
function <unsigned()> f3 = boost::lambda::bind(f2, 4.0);
|
||||||
|
BOOST_TEST_EQ( f3(), 120 );
|
||||||
|
|
||||||
f3();
|
return boost::report_errors();
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,16 +7,18 @@
|
|||||||
|
|
||||||
// For more information, see http://www.boost.org
|
// For more information, see http://www.boost.org
|
||||||
|
|
||||||
#include <boost/test/minimal.hpp>
|
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
#include <new>
|
||||||
|
|
||||||
struct stateless_integer_add {
|
struct stateless_integer_add {
|
||||||
int operator()(int x, int y) const { return x+y; }
|
int operator()(int x, int y) const { return x+y; }
|
||||||
|
|
||||||
void* operator new(std::size_t)
|
void* operator new(std::size_t n)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Cannot allocate a stateless_integer_add");
|
BOOST_ERROR( "stateless_integer_add incorrectly allocated" );
|
||||||
|
return ::operator new( n );
|
||||||
}
|
}
|
||||||
|
|
||||||
void* operator new(std::size_t, void* p)
|
void* operator new(std::size_t, void* p)
|
||||||
@ -24,15 +26,17 @@ struct stateless_integer_add {
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void*) throw()
|
void operator delete(void* p) throw()
|
||||||
{
|
{
|
||||||
|
BOOST_ERROR( "stateless_integer_add incorrectly deallocated" );
|
||||||
|
return ::operator delete( p );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
int test_main(int, char*[])
|
int main()
|
||||||
{
|
{
|
||||||
boost::function2<int, int, int> f;
|
boost::function2<int, int, int> f;
|
||||||
f = stateless_integer_add();
|
f = stateless_integer_add();
|
||||||
|
|
||||||
return 0;
|
return boost::report_errors();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user