More boost::shared_ptr tests/fixes, seems stable now.
This commit is contained in:
1 parent
4f64044480
commit
a17ce14a6e
6 files changed
+88
-83
No files matched your search
@@ -47,6 +47,8 @@ class ClassThatTakesFoo
|
||||
public:
|
||||
ClassThatTakesFoo(boost::shared_ptr<Foo> foo) : m_foo(foo) {}
|
||||
boost::shared_ptr<Foo> get_foo () const { return m_foo; }
|
||||
|
||||
virtual boost::shared_ptr<Foo> get_modified_foo (boost::shared_ptr<Foo> foo) const { return m_foo; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ from pybindgen import cppclass
|
||||
|
||||
from pybindgen import param, retval
|
||||
|
||||
|
||||
import pybindgen.settings
|
||||
pybindgen.settings.deprecated_virtuals = False
|
||||
|
||||
|
||||
def my_module_gen(out_file):
|
||||
@@ -38,9 +39,12 @@ def my_module_gen(out_file):
|
||||
[param('boost::shared_ptr<Foo>', 'foo')])
|
||||
mod.add_function('function_that_returns_foo', retval('boost::shared_ptr<Foo>'), [])
|
||||
|
||||
cls = mod.add_class('ClassThatTakesFoo')
|
||||
cls = mod.add_class('ClassThatTakesFoo', allow_subclassing=True)
|
||||
cls.add_constructor([Parameter.new('boost::shared_ptr<Foo>', 'foo')])
|
||||
cls.add_method('get_foo', ReturnValue.new('boost::shared_ptr<Foo>'), [])
|
||||
cls.add_method('get_modified_foo', retval('boost::shared_ptr<Foo>'),
|
||||
[param('boost::shared_ptr<Foo>', 'foo')],
|
||||
is_virtual=True, is_const=True)
|
||||
|
||||
|
||||
|
||||
|
||||
+39
-1
@@ -68,7 +68,45 @@ class TestBar(unittest.TestCase):
|
||||
del f1, takes
|
||||
while gc.collect():
|
||||
pass
|
||||
self.assertEqual(bar.Foo.instance_count, count0) # the object stays alive
|
||||
self.assertEqual(bar.Foo.instance_count, count0)
|
||||
|
||||
|
||||
def test_class_takes_foo_subclassing(self):
|
||||
|
||||
count0 = bar.Foo.instance_count
|
||||
|
||||
|
||||
f = bar.Foo("hello45")
|
||||
self.assertEqual(bar.Foo.instance_count, count0 + 1)
|
||||
self.assertEqual(f.get_datum(), "hello45")
|
||||
|
||||
class Takes(bar.ClassThatTakesFoo):
|
||||
def get_modified_foo(self, foo):
|
||||
d = foo.get_datum()
|
||||
return bar.Foo(d+"xxx")
|
||||
|
||||
takes = Takes(f)
|
||||
del f
|
||||
while gc.collect():
|
||||
pass
|
||||
self.assertEqual(bar.Foo.instance_count, count0+1)
|
||||
|
||||
|
||||
f1 = takes.get_foo()
|
||||
self.assertEqual(f1.get_datum(), "hello45")
|
||||
|
||||
self.assertEqual(bar.Foo.instance_count, count0+1)
|
||||
|
||||
f2 = bar.Foo("helloyyy")
|
||||
self.assertEqual(bar.Foo.instance_count, count0+2)
|
||||
f3 = takes.get_modified_foo(f2)
|
||||
self.assertEqual(bar.Foo.instance_count, count0+3)
|
||||
self.assertEqual(f3.get_datum(), "helloyyyxxx")
|
||||
|
||||
del f1, f2, f3, takes
|
||||
while gc.collect():
|
||||
pass
|
||||
self.assertEqual(bar.Foo.instance_count, count0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in new issue
Block a user