summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorrenatofilho <renato.filho@openbossa.org>2010-09-24 11:25:41 -0300
committerrenatofilho <renato.filho@openbossa.org>2010-09-24 16:39:51 -0300
commit2e715ed74316704cba426e99ba7fe06ace038ed4 (patch)
treee48186f8d9e84c8360495140e56a435abea53b4d /tests
parenta94524af29c3d74960935de44a4b20fd4d5eddad (diff)
downloadshiboken-2e715ed74316704cba426e99ba7fe06ace038ed4.tar.gz
shiboken-2e715ed74316704cba426e99ba7fe06ace038ed4.tar.xz
shiboken-2e715ed74316704cba426e99ba7fe06ace038ed4.zip
Created unit test to unsafe parent (parent created from c++)
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com> Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/objecttype.cpp14
-rw-r--r--tests/libsample/objecttype.h5
-rw-r--r--tests/samplebinding/ownership_invalidate_parent_test.py9
-rw-r--r--tests/samplebinding/typesystem_sample.xml5
-rw-r--r--tests/samplebinding/unsafe_parent_test.py49
5 files changed, 80 insertions, 2 deletions
diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp
index c1407d23..e4fce71e 100644
--- a/tests/libsample/objecttype.cpp
+++ b/tests/libsample/objecttype.cpp
@@ -25,6 +25,7 @@
#include <algorithm>
#include <iostream>
#include <string>
+#include <assert.h>
using namespace std;
@@ -269,3 +270,16 @@ int ObjectType::callId() const
return m_call_id;
}
+
+void ObjectType::callVirtualCreateChild()
+{
+ ObjectType* fake_parent = new ObjectType();
+ ObjectType* fake_child = createChild(fake_parent);
+ assert(fake_child->isPython());
+ delete fake_parent;
+}
+
+ObjectType* ObjectType::createChild(ObjectType* parent)
+{
+ return new ObjectType(parent);
+}
diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h
index b09b402e..bb7787e4 100644
--- a/tests/libsample/objecttype.h
+++ b/tests/libsample/objecttype.h
@@ -102,6 +102,11 @@ public:
void setObject(const Null&);
int callId() const;
+ //Function used to create a parent from C++
+ virtual bool isPython() { return false; }
+ void callVirtualCreateChild();
+ virtual ObjectType* createChild(ObjectType* parent);
+
private:
ObjectType(const ObjectType&);
ObjectType& operator=(const ObjectType&);
diff --git a/tests/samplebinding/ownership_invalidate_parent_test.py b/tests/samplebinding/ownership_invalidate_parent_test.py
index b99951c4..509bfcf4 100644
--- a/tests/samplebinding/ownership_invalidate_parent_test.py
+++ b/tests/samplebinding/ownership_invalidate_parent_test.py
@@ -38,19 +38,24 @@ class InvalidateParentTest(unittest.TestCase):
'''Invalidate parent should invalidate children'''
parent = ObjectType.create()
child1 = ObjectType(parent)
+ child1.setObjectName("child1")
child2 = ObjectType.create()
+ child2.setObjectName("child2")
child2.setParent(parent)
grandchild1 = ObjectType(child1)
+ grandchild1.setObjectName("grandchild1")
grandchild2 = ObjectType.create()
+ grandchild2.setObjectName("grandchild2")
grandchild2.setParent(child2)
bbox = BlackBox()
bbox.keepObjectType(parent) # Should invalidate the parent
self.assertRaises(RuntimeError, parent.objectName)
- self.assertRaises(RuntimeError, child1.objectName)
+ # some children still valid they are wrapper classes
+ self.assertEqual(child1.objectName(), "child1")
self.assertRaises(RuntimeError, child2.objectName)
- self.assertRaises(RuntimeError, grandchild1.objectName)
+ self.assertEqual(grandchild1.objectName(), "grandchild1")
self.assertRaises(RuntimeError, grandchild2.objectName)
if __name__ == '__main__':
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 0706355a..ccf9c512 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -208,6 +208,11 @@
<parent index="this" action="add"/>
</modify-argument>
</modify-function>
+ <modify-function signature="createChild(ObjectType*)">
+ <modify-argument index="return">
+ <define-ownership owner="c++" />
+ </modify-argument>
+ </modify-function>
</object-type>
<object-type name="ObjectTypeLayout">
<modify-function signature="create()">
diff --git a/tests/samplebinding/unsafe_parent_test.py b/tests/samplebinding/unsafe_parent_test.py
new file mode 100644
index 00000000..cb0e4326
--- /dev/null
+++ b/tests/samplebinding/unsafe_parent_test.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Shiboken Python Bindings Generator project.
+#
+# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+#
+# Contact: PySide team <contact@pyside.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# version 2.1 as published by the Free Software Foundation. Please
+# review the following information to ensure the GNU Lesser General
+# Public License version 2.1 requirements will be met:
+# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+# #
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+'''Test cases for ...'''
+
+import sys
+import unittest
+
+from sample import ObjectType
+
+class DerivedObjectType(ObjectType):
+ def isPython(self):
+ return True
+
+ def createChild(self, parent):
+ return DerivedObjectType(parent)
+
+class ParentTest(unittest.TestCase):
+
+ def testUunsafeParent(self):
+ o = DerivedObjectType()
+ o.callVirtualCreateChild()
+
+if __name__ == '__main__':
+ unittest.main()
+