From 3b269d5de7a80ddc46cb12a3f54e4bd097cfaf76 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 17 Mar 2005 12:48:40 +0000 Subject: [PATCH] contains2_test added [SVN r27722] --- test/Jamfile | 3 +- test/Jamfile.v2 | 2 + test/contains2_test.cpp | 88 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 test/contains2_test.cpp diff --git a/test/Jamfile b/test/Jamfile index c9e2c5a..09d2d97 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -62,6 +62,7 @@ DEPENDS all : test ; [ run libs/function/test/function_ref_portable.cpp : : : : ] [ run libs/function/test/contains_test.cpp : : : : ] + + [ run libs/function/test/contains2_test.cpp : : : : ] ; } - \ No newline at end of file diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index cc0448a..8ab92b1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -56,6 +56,8 @@ import testing ; [ run libs/function/test/contains_test.cpp : : : : ] + [ run libs/function/test/contains2_test.cpp : : : : ] + ; } diff --git a/test/contains2_test.cpp b/test/contains2_test.cpp new file mode 100644 index 0000000..cf6d479 --- /dev/null +++ b/test/contains2_test.cpp @@ -0,0 +1,88 @@ +// Boost.Function library + +// Copyright Douglas Gregor 2004. +// Copyright 2005 Peter Dimov + +// Use, modification and distribution is subject to +// the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +static int forty_two() +{ + return 42; +} + +struct Seventeen +{ + int operator()() const + { + return 17; + } +}; + +bool operator==(const Seventeen&, const Seventeen&) +{ + return true; +} + +struct ReturnInt +{ + explicit ReturnInt(int value) : value(value) + { + } + + int operator()() const + { + return value; + } + + int value; +}; + +bool operator==(const ReturnInt& x, const ReturnInt& y) +{ + return x.value == y.value; +} + +bool operator!=(const ReturnInt& x, const ReturnInt& y) +{ + return x.value != y.value; +} + +int main() +{ + boost::function0 fn; + + fn = &forty_two; + + BOOST_TEST( fn() == 42 ); + + BOOST_TEST( fn.contains(&forty_two) ); + BOOST_TEST( !fn.contains( Seventeen() ) ); + BOOST_TEST( !fn.contains( ReturnInt(0) ) ); + BOOST_TEST( !fn.contains( ReturnInt(12) ) ); + + fn = Seventeen(); + + BOOST_TEST( fn() == 17 ); + + BOOST_TEST( !fn.contains( &forty_two ) ); + BOOST_TEST( fn.contains( Seventeen() ) ); + BOOST_TEST( !fn.contains( ReturnInt(0) ) ); + BOOST_TEST( !fn.contains( ReturnInt(12) ) ); + + fn = ReturnInt(12); + + BOOST_TEST( fn() == 12 ); + + BOOST_TEST( !fn.contains( &forty_two ) ); + BOOST_TEST( !fn.contains( Seventeen() ) ); + BOOST_TEST( !fn.contains( ReturnInt(0) ) ); + BOOST_TEST( fn.contains( ReturnInt(12) ) ); + + return boost::report_errors(); +}