From 43bcbf771e822acffe8244edf96e42e13f06909b Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Wed, 20 Feb 2002 05:18:12 +0000 Subject: [PATCH] added more-rigorous tests [SVN r12866] --- test/m1.cpp | 40 ++++++++++++++++++++++++++++++++++++---- test/newtest.py | 12 ++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/test/m1.cpp b/test/m1.cpp index b42742ab..723b471d 100644 --- a/test/m1.cpp +++ b/test/m1.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -141,6 +141,26 @@ int f(simple const& s) return strlen(s.s); } +int f_mutable_ref(simple& s) +{ + return strlen(s.s); +} + +int f_mutable_ptr(simple* s) +{ + return strlen(s->s); +} + +int f_const_ptr(simple const* s) +{ + return strlen(s->s); +} + +int f2(SimpleObject const& s) +{ + return strlen(s.x.s); +} + // A trivial passthru function for simple objects simple const& g(simple const& x) { @@ -188,7 +208,7 @@ BOOST_PYTHON_MODULE_INIT(m1) using boost::python::module; using boost::python::class_; using boost::python::converter::from_python_converter; - using boost::python::reference_from_python; + using boost::python::lvalue_from_python; using boost::python::value_from_python; using boost::python::type_from_python; using boost::python::get_member; @@ -205,14 +225,21 @@ BOOST_PYTHON_MODULE_INIT(m1) static from_python_converter c3( &(boost::python::type_from_python<&NoddyType>::convertible), noddy_to_int_ref); - static boost::python::reference_from_python< + static boost::python::lvalue_from_python< &SimpleType , simple , SimpleObject +#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300 + , boost::python::get_member +#else , extract_simple_object +#endif > unwrap_simple; + static boost::python::lvalue_from_python<&SimpleType, SimpleObject> + unwrap_simple2; + module m1("m1"); typedef boost::python::objects::pointer_holder_generator< @@ -229,9 +256,14 @@ BOOST_PYTHON_MODULE_INIT(m1) .def("new_noddy", new_noddy) .def("new_simple", new_simple) - // Expose f() + // Expose f() in all its variations .def("f", f) + .def("f_mutable_ref", f_mutable_ref) + .def("f_mutable_ptr", f_mutable_ptr) + .def("f_const_ptr", f_const_ptr) + .def("f2", f2) + // Expose g() .def("g", g , return_value_policy() ) diff --git a/test/newtest.py b/test/newtest.py index 4e6de142..b89764d1 100644 --- a/test/newtest.py +++ b/test/newtest.py @@ -57,6 +57,18 @@ try: wrap_int_ref(n) >>> f(g(s)) 12 +>>> f_mutable_ref(g(s)) +12 + +>>> f_const_ptr(g(s)) +12 + +>>> f_mutable_ptr(g(s)) +12 + +>>> f2(g(s)) +12 + Create an extension class which wraps "complicated" (init1 and get_n) are a complicated constructor and member function, respectively.