diff options
author | renatofilho <renato.filho@openbossa.org> | 2010-09-24 11:25:41 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:07:19 -0300 |
commit | 85f926e8fef29967393a11832ac26cafecc9b777 (patch) | |
tree | d547a700b60a3bfa3f27c5fbc7cdffe2a60fd27b /tests | |
parent | a0bd7044da2150e096ab197302b5c77a845c8682 (diff) |
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.cpp | 14 | ||||
-rw-r--r-- | tests/libsample/objecttype.h | 5 | ||||
-rw-r--r-- | tests/samplebinding/ownership_invalidate_parent_test.py | 9 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 5 | ||||
-rw-r--r-- | tests/samplebinding/unsafe_parent_test.py | 49 |
5 files changed, 80 insertions, 2 deletions
diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp index c1407d237..e4fce71e3 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 b09b402e7..bb7787e44 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 b99951c4b..509bfcf4d 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 0706355a5..ccf9c512b 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 000000000..cb0e43262 --- /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() + |