diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f5ebfd9..b8c1f27 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -4,6 +4,8 @@ # Boost Parameter Library test Jamfile +import python ; + project boost/parameter : default-build off ; @@ -18,12 +20,16 @@ test-suite "parameter" [ run singular.cpp ] [ run mpl.cpp ] [ run preprocessor.cpp ] + [ run preprocessor_deduced.cpp ] [ run efficiency.cpp : : : : : release ] [ run maybe.cpp ] + [ run deduced.cpp ] [ compile ntp.cpp ] [ compile unwrap_cv_reference.cpp ] [ compile-fail duplicates.cpp ] [ compile-fail unnamed_fail.cpp ] [ compile compose.cpp ] + [ compile normalized_argument_types.cpp ] + [ bpl-test python_test ] ; diff --git a/test/python_test.cpp b/test/python_test.cpp new file mode 100755 index 0000000..a9612ae --- /dev/null +++ b/test/python_test.cpp @@ -0,0 +1,159 @@ +// Copyright Daniel Wallin 2006. 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 +#include +#include +#include + +namespace test { + +BOOST_PARAMETER_KEYWORD(tag, x) +BOOST_PARAMETER_KEYWORD(tag, y) +BOOST_PARAMETER_KEYWORD(tag, z) + +struct Xbase +{ + // We need the disable_if part for VC7.1/8.0. + template + Xbase( + Args const& args + , typename boost::disable_if< + boost::is_base_and_derived + >::type* = 0 + ) + : value(std::string(args[x | "foo"]) + args[y | "bar"]) + {} + + std::string value; +}; + +struct X : Xbase +{ + BOOST_PARAMETER_CONSTRUCTOR(X, (Xbase), tag, + (optional + (x, *) + (y, *) + ) + ) + + BOOST_PARAMETER_BASIC_MEMBER_FUNCTION((int), f, tag, + (required + (x, *) + (y, *) + ) + (optional + (z, *) + ) + ) + { + return args[x] + args[y] + args[z | 0]; + } + + BOOST_PARAMETER_BASIC_MEMBER_FUNCTION((std::string), g, tag, + (optional + (x, *) + (y, *) + ) + ) + { + return std::string(args[x | "foo"]) + args[y | "bar"]; + } + + BOOST_PARAMETER_MEMBER_FUNCTION((X&), h, tag, + (optional (x, *, "") (y, *, "")) + ) + { + return *this; + } + + template + X& operator()(A0 const& a0) + { + return *this; + } +}; + +} // namespace test + +struct f_fwd +{ + template + R operator()(boost::type, T& self, A0 const& a0, A1 const& a1, A2 const& a2) + { + return self.f(a0,a1,a2); + } +}; + +struct g_fwd +{ + template + R operator()(boost::type, T& self, A0 const& a0, A1 const& a1) + { + return self.g(a0,a1); + } +}; + +struct h_fwd +{ + template + R operator()(boost::type, T& self, A0 const& a0, A1 const& a1) + { + return self.h(a0,a1); + } +}; + +BOOST_PYTHON_MODULE(python_test_ext) +{ + namespace mpl = boost::mpl; + using namespace test; + using namespace boost::python; + + class_("X") + .def( + boost::parameter::python::init< + mpl::vector< + tag::x*(std::string), tag::y*(std::string) + > + >() + ) + .def( + "f" + , boost::parameter::python::function< + f_fwd + , mpl::vector< + int, tag::x(int), tag::y(int), tag::z*(int) + > + >() + ) + .def( + "g" + , boost::parameter::python::function< + g_fwd + , mpl::vector< + std::string, tag::x*(std::string), tag::y*(std::string) + > + >() + ) + .def( + "h" + , boost::parameter::python::function< + h_fwd + , mpl::vector< + X&, tag::x*(std::string), tag::y*(std::string) + > + >() + , return_arg<>() + ) + .def( + boost::parameter::python::call< + mpl::vector< + X&, tag::x(int) + > + >() [ return_arg<>() ] + ) + .def_readonly("value", &X::value); +} + diff --git a/test/python_test.py b/test/python_test.py new file mode 100644 index 0000000..ce3b81c --- /dev/null +++ b/test/python_test.py @@ -0,0 +1,41 @@ +# Copyright Daniel Wallin 2006. Distributed under 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) + +''' +>>> from python_test_ext import X +>>> x = X(y = 'baz') +>>> x.value +'foobaz' +>>> x.f(1,2) +3 +>>> x.f(1,2,3) +6 +>>> x.f(1,2, z = 3) +6 +>>> x.f(z = 3, y = 2, x = 1) +6 +>>> x.g() +'foobar' +>>> x.g(y = "baz") +'foobaz' +>>> x.g(x = "baz") +'bazbar' +>>> x.g(y = "foo", x = "bar") +'barfoo' +>>> y = x.h(x = "bar", y = "foo") +>>> assert x == y +>>> y = x(0) +>>> assert x == y +''' + +def run(args = None): + if args is not None: + import sys + sys.argv = args + import doctest, python_test + return doctest.testmod(python_test) + +if __name__ == '__main__': + import sys + sys.exit(run()[0])