aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-12-02 15:38:22 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-12-02 19:34:24 -0300
commit2dbe941b2b0e163e49cffe6626b1f47a06b8a7c8 (patch)
treeeaae92f5cc18ba02ee7187daacb9c123b1c5edd1 /tests
parent866f657323d75f2331101d56048bb94e1532b10e (diff)
Expanded protected method tests with cases of reimplemented grand parent and grand grand parent methods.
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/protected.h16
-rw-r--r--tests/samplebinding/CMakeLists.txt2
-rwxr-xr-xtests/samplebinding/protected_test.py63
-rw-r--r--tests/samplebinding/typesystem_sample.xml16
4 files changed, 94 insertions, 3 deletions
diff --git a/tests/libsample/protected.h b/tests/libsample/protected.h
index 3c6dc3fa7..23b2f5ca7 100644
--- a/tests/libsample/protected.h
+++ b/tests/libsample/protected.h
@@ -64,7 +64,7 @@ class LIBSAMPLE_API ProtectedPolymorphic
{
public:
explicit ProtectedPolymorphic(const char* name) : m_name(name) {}
- ~ProtectedPolymorphic() {}
+ virtual ~ProtectedPolymorphic() {}
const char* publicName() { return m_name; }
@@ -79,6 +79,20 @@ private:
const char* m_name;
};
+class LIBSAMPLE_API ProtectedPolymorphicDaughter : public ProtectedPolymorphic
+{
+public:
+ explicit ProtectedPolymorphicDaughter(const char* name) : ProtectedPolymorphic(name) {}
+ static ProtectedPolymorphicDaughter* create() { return new ProtectedPolymorphicDaughter("created"); }
+};
+
+class LIBSAMPLE_API ProtectedPolymorphicGrandDaughter: public ProtectedPolymorphicDaughter
+{
+public:
+ explicit ProtectedPolymorphicGrandDaughter(const char* name) : ProtectedPolymorphicDaughter(name) {}
+ static ProtectedPolymorphicGrandDaughter* create() { return new ProtectedPolymorphicGrandDaughter("created"); }
+};
+
class LIBSAMPLE_API ProtectedVirtualDestructor
{
public:
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 7c3d5948d..0a038815a 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -44,6 +44,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/polygon_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/privatedtor_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/protectednonpolymorphic_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphic_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphicdaughter_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphicgranddaughter_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/protectedvirtualdestructor_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/reference_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/sample_module_wrapper.cpp
diff --git a/tests/samplebinding/protected_test.py b/tests/samplebinding/protected_test.py
index b0b3b6f70..dd4175d87 100755
--- a/tests/samplebinding/protected_test.py
+++ b/tests/samplebinding/protected_test.py
@@ -29,15 +29,34 @@
import os
import unittest
-from sample import ProtectedNonPolymorphic, ProtectedPolymorphic, ProtectedVirtualDestructor
+from sample import ProtectedNonPolymorphic, ProtectedVirtualDestructor
+from sample import ProtectedPolymorphic, ProtectedPolymorphicDaughter, ProtectedPolymorphicGrandDaughter
from sample import Point
class ExtendedProtectedPolymorphic(ProtectedPolymorphic):
def __init__(self, name):
ProtectedPolymorphic.__init__(self, name)
+ self.protectedName_called = False
def protectedName(self):
+ self.protectedName_called = True
return 'Extended' + ProtectedPolymorphic.protectedName(self)
+class ExtendedProtectedPolymorphicDaughter(ProtectedPolymorphicDaughter):
+ def __init__(self, name):
+ self.protectedName_called = False
+ ProtectedPolymorphicDaughter.__init__(self, name)
+ def protectedName(self):
+ self.protectedName_called = True
+ return 'ExtendedDaughter' + ProtectedPolymorphicDaughter.protectedName(self)
+
+class ExtendedProtectedPolymorphicGrandDaughter(ProtectedPolymorphicGrandDaughter):
+ def __init__(self, name):
+ self.protectedName_called = False
+ ProtectedPolymorphicGrandDaughter.__init__(self, name)
+ def protectedName(self):
+ self.protectedName_called = True
+ return 'ExtendedGrandDaughter' + ProtectedPolymorphicGrandDaughter.protectedName(self)
+
class ExtendedProtectedVirtualDestructor(ProtectedVirtualDestructor):
def __init__(self):
ProtectedVirtualDestructor.__init__(self)
@@ -84,9 +103,49 @@ class ProtectedPolymorphicTest(unittest.TestCase):
def testReimplementedProtectedCall(self):
'''Calls a reimplemented virtual protected method.'''
- p = ExtendedProtectedPolymorphic('Poly')
+ original_name = 'Poly'
+ p = ExtendedProtectedPolymorphic(original_name)
+ name = p.callProtectedName()
+ self.assert_(p.protectedName_called)
+ self.assertEqual(p.protectedName(), name)
+ self.assertEqual(ProtectedPolymorphic.protectedName(p), original_name)
+
+class ProtectedPolymorphicDaugherTest(unittest.TestCase):
+ '''Test cases for protected method in a class inheriting for a class with virtual methods.'''
+
+ def testProtectedCallWithInstanceCreatedOnCpp(self):
+ '''Calls a virtual protected method from parent class on an instance created in C++.'''
+ p = ProtectedPolymorphicDaughter.create()
+ self.assertEqual(p.publicName(), p.protectedName())
+ self.assertEqual(p.callProtectedName(), p.protectedName())
+
+ def testReimplementedProtectedCall(self):
+ '''Calls a reimplemented virtual protected method from parent class.'''
+ original_name = 'Poly'
+ p = ExtendedProtectedPolymorphicDaughter(original_name)
+ name = p.callProtectedName()
+ self.assert_(p.protectedName_called)
+ self.assertEqual(p.protectedName(), name)
+ self.assertEqual(ProtectedPolymorphicDaughter.protectedName(p), original_name)
+
+class ProtectedPolymorphicGrandDaugherTest(unittest.TestCase):
+ '''Test cases for protected method in a class inheriting for a class that inherits from
+ another with protected virtual methods.'''
+
+ def testProtectedCallWithInstanceCreatedOnCpp(self):
+ '''Calls a virtual protected method from parent class on an instance created in C++.'''
+ p = ProtectedPolymorphicGrandDaughter.create()
+ self.assertEqual(p.publicName(), p.protectedName())
self.assertEqual(p.callProtectedName(), p.protectedName())
+ def testReimplementedProtectedCall(self):
+ '''Calls a reimplemented virtual protected method from parent class.'''
+ original_name = 'Poly'
+ p = ExtendedProtectedPolymorphicGrandDaughter(original_name)
+ name = p.callProtectedName()
+ self.assert_(p.protectedName_called)
+ self.assertEqual(p.protectedName(), name)
+ self.assertEqual(ProtectedPolymorphicGrandDaughter.protectedName(p), original_name)
class ProtectedVirtualDtorTest(unittest.TestCase):
'''Test cases for protected virtual destructor.'''
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 84eb62192..9ef1375d7 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -195,6 +195,22 @@
</modify-function>
</value-type>
+ <value-type name="ProtectedPolymorphicDaughter">
+ <modify-function signature="create()">
+ <modify-argument index="return">
+ <define-ownership owner="target"/>
+ </modify-argument>
+ </modify-function>
+ </value-type>
+
+ <value-type name="ProtectedPolymorphicGrandDaughter">
+ <modify-function signature="create()">
+ <modify-argument index="return">
+ <define-ownership owner="target"/>
+ </modify-argument>
+ </modify-function>
+ </value-type>
+
<value-type name="ProtectedVirtualDestructor">
<modify-function signature="create()">
<modify-argument index="return">