Skip to content

Commit 17716b6

Browse files
committed
Add test_return_function
1 parent b6b0568 commit 17716b6

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

test/Jamfile.v2

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ local check14 = [ check-target-builds mixed_cxxstd/<cxxstd>14 : : <build>no ] ;
5757

5858
run test_mixed_cxxstd.cpp mixed_cxxstd/<cxxstd>14 : : : <link>shared $(check14) : mixed_cxxstd_shared_14 ;
5959
run test_mixed_cxxstd.cpp mixed_cxxstd/<cxxstd>14 : : : <link>static $(check14) : mixed_cxxstd_static_14 ;
60+
61+
lib return_function : return_function.cpp : <link>shared:<define>RETURN_FUNCTION_DYN_LINK=1 ;
62+
63+
run test_return_function.cpp return_function : : : <link>shared : return_function_shared ;
64+
run test_return_function.cpp return_function : : : <link>static : return_function_static ;

test/return_function.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// Copyright 2018 Peter Dimov.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
5+
#include <boost/function.hpp>
6+
#include <boost/config.hpp>
7+
8+
#if defined(RETURN_FUNCTION_DYN_LINK)
9+
# define EXPORT BOOST_SYMBOL_EXPORT
10+
#else
11+
# define EXPORT
12+
#endif
13+
14+
int f( int x, int y )
15+
{
16+
return x + y;
17+
}
18+
19+
EXPORT boost::function<int(int, int)> get_fn_1()
20+
{
21+
return f;
22+
}
23+
24+
EXPORT boost::function2<int, int, int> get_fn_2()
25+
{
26+
return f;
27+
}

test/test_return_function.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// Copyright 2018 Peter Dimov.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
5+
#include <boost/function.hpp>
6+
#include <boost/core/lightweight_test.hpp>
7+
8+
//
9+
10+
boost::function<int(int, int)> get_fn_1();
11+
boost::function2<int, int, int> get_fn_2();
12+
13+
//
14+
15+
int main()
16+
{
17+
BOOST_TEST_EQ( get_fn_1()( 1, 2 ), 3 );
18+
BOOST_TEST_EQ( get_fn_2()( 1, 2 ), 3 );
19+
20+
return boost::report_errors();
21+
}

0 commit comments

Comments
 (0)