aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2011-06-17 18:10:21 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:27 -0300
commit88a84ee6ae8cd12b2527576505f16774c9c542c1 (patch)
tree64449426c1b79c4647c9f94f09543d7eda4f046b /tests
parentc3eb8bb198b7cbc43236b1edbf7afbf096d8b8f6 (diff)
Fix refleak during the parent c++ object destruction.
Fixes bug #893. Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Renato Araújo <renato.filho@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/objecttype.h14
-rw-r--r--tests/samplebinding/objecttype_test.py18
-rw-r--r--tests/samplebinding/typesystem_sample.xml9
3 files changed, 40 insertions, 1 deletions
diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h
index a5abf7067..5cc029e85 100644
--- a/tests/libsample/objecttype.h
+++ b/tests/libsample/objecttype.h
@@ -107,6 +107,20 @@ public:
void callVirtualCreateChild();
virtual ObjectType* createChild(ObjectType* parent);
+ //return a parent from C++
+ ObjectType* getCppParent() {
+ if (!m_parent) {
+ ObjectType* parent = new ObjectType();
+ setParent(parent);
+ }
+ return m_parent;
+ }
+
+ void destroyCppParent() {
+ delete m_parent;
+ m_parent = 0;
+ }
+
private:
ObjectType(const ObjectType&);
ObjectType& operator=(const ObjectType&);
diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py
index 2a0dbbdb8..2448a7f68 100644
--- a/tests/samplebinding/objecttype_test.py
+++ b/tests/samplebinding/objecttype_test.py
@@ -26,8 +26,8 @@
'''Tests ObjectType class of object-type with privates copy constructor and = operator.'''
-import sys
import unittest
+import sys
from sample import ObjectType, Str
@@ -62,6 +62,22 @@ class ObjectTypeTest(unittest.TestCase):
o.setNullObject(None)
self.assertEqual(o.callId(), 1)
+ def testParentFromCpp(self):
+ o = ObjectType()
+ self.assertEqual(sys.getrefcount(o), 2)
+ o.getCppParent().setObjectName('parent')
+ self.assertEqual(sys.getrefcount(o), 3)
+ o.getCppParent().setObjectName('parent')
+ self.assertEqual(sys.getrefcount(o), 3)
+ o.getCppParent().setObjectName('parent')
+ self.assertEqual(sys.getrefcount(o), 3)
+ o.getCppParent().setObjectName('parent')
+ self.assertEqual(sys.getrefcount(o), 3)
+ o.getCppParent().setObjectName('parent')
+ self.assertEqual(sys.getrefcount(o), 3)
+ o.destroyCppParent()
+ self.assertEqual(sys.getrefcount(o), 2)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 2537b6047..d99ee0fbc 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -173,6 +173,15 @@
<!-- rename function to avoid Python signature conflit -->
<modify-function signature="setObject(const Null&amp;)" rename="setNullObject" />
+ <modify-function signature="getCppParent()">
+ <modify-argument index="this">
+ <parent index="return" action="add" />
+ </modify-argument>
+ <modify-argument index="return">
+ <define-ownership class="target" owner="default"/>
+ </modify-argument>
+ </modify-function>
+
<modify-function signature="event(Event*)">
<modify-argument index="1" invalidate-after-use="yes"/>
</modify-function>