From f8f40296280bcd6543c1cd449499ce2dfad11234 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 2 Mar 2004 18:42:12 +0000 Subject: [PATCH] bind_stateful_test.cpp added. [SVN r22424] --- test/Jamfile | 1 + test/Jamfile.v2 | 1 + test/bind_stateful_test.cpp | 182 ++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 test/bind_stateful_test.cpp diff --git a/test/Jamfile b/test/Jamfile index 3e4155c..0826df5 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -21,6 +21,7 @@ DEPENDS all : bind ; [ run bind_eq_test.cpp ] [ run bind_const_test.cpp ] [ run bind_cv_test.cpp ] + [ run bind_stateful_test.cpp ] [ run mem_fn_test.cpp ] [ run mem_fn_void_test.cpp ] [ run mem_fn_derived_test.cpp ] diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 513e579..b8c8efc 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -15,6 +15,7 @@ test-suite "bind" [ run bind_eq_test.cpp ] [ run bind_const_test.cpp ] [ run bind_cv_test.cpp ] + [ run bind_stateful_test.cpp ] [ run mem_fn_test.cpp ] [ run mem_fn_void_test.cpp ] [ run mem_fn_derived_test.cpp ] diff --git a/test/bind_stateful_test.cpp b/test/bind_stateful_test.cpp new file mode 100644 index 0000000..9604b9a --- /dev/null +++ b/test/bind_stateful_test.cpp @@ -0,0 +1,182 @@ +#include + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// +// bind_stateful_test.cpp +// +// Copyright (c) 2004 Peter Dimov +// +// Permission to copy, use, modify, sell and distribute this software +// is granted provided this copyright notice appears in all copies. +// This software is provided "as is" without express or implied +// warranty, and with no claim as to its suitability for any purpose. +// + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + +#include + +class X +{ +private: + + int state_; + +public: + + X(): state_(0) + { + } + + int operator()() + { + return state_ += 17041; + } + + int operator()(int x1) + { + return state_ += x1; + } + + int operator()(int x1, int x2) + { + return state_ += x1+x2; + } + + int operator()(int x1, int x2, int x3) + { + return state_ += x1+x2+x3; + } + + int operator()(int x1, int x2, int x3, int x4) + { + return state_ += x1+x2+x3+x4; + } + + int operator()(int x1, int x2, int x3, int x4, int x5) + { + return state_ += x1+x2+x3+x4+x5; + } + + int operator()(int x1, int x2, int x3, int x4, int x5, int x6) + { + return state_ += x1+x2+x3+x4+x5+x6; + } + + int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7) + { + return state_ += x1+x2+x3+x4+x5+x6+x7; + } + + int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) + { + return state_ += x1+x2+x3+x4+x5+x6+x7+x8; + } + + int operator()(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9) + { + return state_ += x1+x2+x3+x4+x5+x6+x7+x8+x9; + } +}; + +int f0(int & state_) +{ + return state_ += 17041; +} + +int f1(int & state_, int x1) +{ + return state_ += x1; +} + +int f2(int & state_, int x1, int x2) +{ + return state_ += x1+x2; +} + +int f3(int & state_, int x1, int x2, int x3) +{ + return state_ += x1+x2+x3; +} + +int f4(int & state_, int x1, int x2, int x3, int x4) +{ + return state_ += x1+x2+x3+x4; +} + +int f5(int & state_, int x1, int x2, int x3, int x4, int x5) +{ + return state_ += x1+x2+x3+x4+x5; +} + +int f6(int & state_, int x1, int x2, int x3, int x4, int x5, int x6) +{ + return state_ += x1+x2+x3+x4+x5+x6; +} + +int f7(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7) +{ + return state_ += x1+x2+x3+x4+x5+x6+x7; +} + +int f8(int & state_, int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8) +{ + return state_ += x1+x2+x3+x4+x5+x6+x7+x8; +} + +template void test(F f, int r) +{ + BOOST_TEST( f() == r ); + BOOST_TEST( f() == 2*r ); + BOOST_TEST( f() == 3*r ); +} + +void stateful_function_object_test() +{ + test( boost::bind( X() ), 17041 ); + test( boost::bind( X(), 1 ), 1 ); + test( boost::bind( X(), 1, 2 ), 1+2 ); + test( boost::bind( X(), 1, 2, 3 ), 1+2+3 ); + test( boost::bind( X(), 1, 2, 3, 4 ), 1+2+3+4 ); + test( boost::bind( X(), 1, 2, 3, 4, 5 ), 1+2+3+4+5 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 ); + test( boost::bind( X(), 1, 2, 3, 4, 5, 6, 7, 8, 9 ), 1+2+3+4+5+6+7+8+9 ); +} + +void stateful_function_test() +{ + test( boost::bind( f0, 0 ), 17041 ); + test( boost::bind( f1, 0, 1 ), 1 ); + test( boost::bind( f2, 0, 1, 2 ), 1+2 ); + test( boost::bind( f3, 0, 1, 2, 3 ), 1+2+3 ); + test( boost::bind( f4, 0, 1, 2, 3, 4 ), 1+2+3+4 ); + test( boost::bind( f5, 0, 1, 2, 3, 4, 5 ), 1+2+3+4+5 ); + test( boost::bind( f6, 0, 1, 2, 3, 4, 5, 6 ), 1+2+3+4+5+6 ); + test( boost::bind( f7, 0, 1, 2, 3, 4, 5, 6, 7 ), 1+2+3+4+5+6+7 ); + test( boost::bind( f8, 0, 1, 2, 3, 4, 5, 6, 7, 8 ), 1+2+3+4+5+6+7+8 ); +} + +int main() +{ + stateful_function_object_test(); + stateful_function_test(); + return boost::report_errors(); +}