Add a test case for the hidden subclass pointe return problem.
This commit is contained in:
1 parent
885a4090f5
commit
bc69e7e825
4 files changed
+24
No files matched your search
@@ -37,3 +37,16 @@ int SomeObject::get_int (double from_float)
|
||||
{
|
||||
return (int) from_float;
|
||||
}
|
||||
|
||||
|
||||
class HiddenClass : public Bar
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
Foo*
|
||||
get_hidden_subclass_pointer ()
|
||||
{
|
||||
return new HiddenClass;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ public:
|
||||
virtual ~Bar() {}
|
||||
};
|
||||
|
||||
// caller owns return
|
||||
Foo* get_hidden_subclass_pointer ();
|
||||
|
||||
class Zbr
|
||||
{
|
||||
|
||||
@@ -68,6 +68,10 @@ def my_module_gen(out_file):
|
||||
Bar.add_method(CppMethod(ReturnValue.new('std::string'), 'Hooray', [], is_static=True))
|
||||
mod.add_class(Bar)
|
||||
|
||||
## to test RTTI with a hidden subclass
|
||||
mod.add_function(Function(ReturnValue.new('Foo*', caller_owns_return=True),
|
||||
'get_hidden_subclass_pointer', []))
|
||||
|
||||
|
||||
## Zbr is a reference counted class
|
||||
Zbr = CppClass('Zbr', incref_method='Ref', decref_method='Unref')
|
||||
|
||||
@@ -133,5 +133,10 @@ class TestFoo(unittest.TestCase):
|
||||
foo2 = obj.get_foo_ptr()
|
||||
self.assertEqual(type(foo2), foo.Bar)
|
||||
|
||||
def test_type_narrowing_hidden_subclass(self):
|
||||
"""This test only works with GCC >= 3.0 (and not with other compilers)"""
|
||||
obj = foo.get_hidden_subclass_pointer()
|
||||
self.assertEqual(type(obj), foo.Bar)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user