Revision: 561
http://svn.sourceforge.net/pygccxml/?rev=561&view=rev
Author: roman_yakovenko
Date: 2006-09-20 00:43:39 -0700 (Wed, 20 Sep 2006)
Log Message:
-----------
adding new use case for smart ptr
Modified Paths:
--------------
pyplusplus_dev/unittests/smart_ptrs/bindings.cpp
pyplusplus_dev/unittests/smart_ptrs/classes.hpp
pyplusplus_dev/unittests/smart_ptrs/test.py
Modified: pyplusplus_dev/unittests/smart_ptrs/bindings.cpp
===================================================================
--- pyplusplus_dev/unittests/smart_ptrs/bindings.cpp 2006-09-20 06:02:54 UTC (rev 560)
+++ pyplusplus_dev/unittests/smart_ptrs/bindings.cpp 2006-09-20 07:43:39 UTC (rev 561)
@@ -80,6 +80,7 @@
.def( "get_value", bp::pure_virtual( &base_i::get_value ) );
bp::implicitly_convertible< smart_ptr_t< base_wrapper_t >, smart_ptr_t< base_i > >();
+ bp::register_ptr_to_python< smart_ptr_t< base_i > >();
bp::class_< derived_wrapper_t, bp::bases< base_i >, smart_ptr_t<derived_wrapper_t> >( "derived_t" )
.def( "get_value", &derived_t::get_value, &derived_wrapper_t::default_get_value );
@@ -87,10 +88,11 @@
bp::implicitly_convertible< smart_ptr_t< derived_wrapper_t >, smart_ptr_t< derived_t > >();
bp::implicitly_convertible< smart_ptr_t< derived_t >, smart_ptr_t< base_i > >();
bp::implicitly_convertible< derived_ptr_t, smart_ptr_t< derived_t > >();
- boost::python::register_ptr_to_python< derived_ptr_t >();
+ bp::register_ptr_to_python< derived_ptr_t >();
bp::def( "const_ref_get_value", &::const_ref_get_value );
bp::def( "ref_get_value", &::ref_get_value );
bp::def( "val_get_value", &::val_get_value );
bp::def( "create_derived", &::create_derived );
+ bp::def( "create_base", &::create_base );
}
Modified: pyplusplus_dev/unittests/smart_ptrs/classes.hpp
===================================================================
--- pyplusplus_dev/unittests/smart_ptrs/classes.hpp 2006-09-20 06:02:54 UTC (rev 560)
+++ pyplusplus_dev/unittests/smart_ptrs/classes.hpp 2006-09-20 07:43:39 UTC (rev 561)
@@ -61,6 +61,11 @@
return derived_ptr_t( new derived_t() );
}
+smart_ptr_t< base_i > create_base(){
+ return smart_ptr_t< base_i >( new derived_t() );
+}
+
+
//Next function could be exposed, but it could not be solved
//This is the explanation David Abrahams gave:
//Naturally; there is no instance of smart_ptr_t<base_i> anywhere in the
Modified: pyplusplus_dev/unittests/smart_ptrs/test.py
===================================================================
--- pyplusplus_dev/unittests/smart_ptrs/test.py 2006-09-20 06:02:54 UTC (rev 560)
+++ pyplusplus_dev/unittests/smart_ptrs/test.py 2006-09-20 07:43:39 UTC (rev 561)
@@ -26,6 +26,9 @@
except Exception, error:
self.failUnless( error.__class__.__name__ == 'ArgumentError' )
+ def __test_ref_fine( self, inst, val ):
+ self.assertEqual( custom_sptr.ref_get_value( inst ), val )
+
def __test_val( self, inst, val ):
self.assertEqual( custom_sptr.val_get_value( inst ), val )
@@ -49,6 +52,13 @@
def test_created_derived( self ):
self.__test_impl( custom_sptr.create_derived(), 11 )
+ def test_created_base( self ):
+ inst = custom_sptr.create_base()
+ val = 11
+ self.__test_ref_fine( inst, val )
+ self.__test_val( inst, val )
+ self.__test_const_ref( inst, val )
+
def create_suite():
suite = unittest.TestSuite()
suite.addTest( unittest.makeSuite(tester_t))
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|