diff options
Diffstat (limited to 'tests/samplebinding')
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rw-r--r-- | tests/samplebinding/keep_reference_test.py | 10 | ||||
-rw-r--r-- | tests/samplebinding/modelview_test.py | 73 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 9 |
5 files changed, 88 insertions, 6 deletions
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index d3e27591f..052e246a8 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -42,6 +42,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/modifiedconstructor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/noimplicitconversion_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/nondefaultctor_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/objectmodel_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttype_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypelayout_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objectview_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index d027b0f57..90cae0835 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -20,6 +20,7 @@ #include "multiple_derived.h" #include "noimplicitconversion.h" #include "nondefaultctor.h" +#include "objectmodel.h" #include "objecttype.h" #include "objecttypelayout.h" #include "objecttypereference.h" diff --git a/tests/samplebinding/keep_reference_test.py b/tests/samplebinding/keep_reference_test.py index 13730553e..fd99a23ca 100644 --- a/tests/samplebinding/keep_reference_test.py +++ b/tests/samplebinding/keep_reference_test.py @@ -29,14 +29,14 @@ import unittest from sys import getrefcount -from sample import ObjectType, ObjectView +from sample import ObjectModel, ObjectView class TestKeepReference(unittest.TestCase): '''Test case for objects that keep references to other object without owning them (e.g. model/view relationships).''' def testReferenceCounting(self): '''Tests reference count of model-like object referred by view-like objects.''' - model1 = ObjectType() + model1 = ObjectModel() refcount1 = getrefcount(model1) view1 = ObjectView() view1.setModel(model1) @@ -46,13 +46,13 @@ class TestKeepReference(unittest.TestCase): view2.setModel(model1) self.assertEqual(getrefcount(view2.model()), refcount1 + 2) - model2 = ObjectType() + model2 = ObjectModel() view2.setModel(model2) self.assertEqual(getrefcount(view1.model()), refcount1 + 1) def testReferenceCountingWhenDeletingReferrer(self): '''Tests reference count of model-like object referred by deceased view-like object.''' - model = ObjectType() + model = ObjectModel() refcount1 = getrefcount(model) view = ObjectView() view.setModel(model) @@ -64,7 +64,7 @@ class TestKeepReference(unittest.TestCase): def testReferreedObjectSurvivalAfterContextEnd(self): '''Model-like object assigned to a view-like object must survive after get out of context.''' def createModelAndSetToView(view): - model = ObjectType() + model = ObjectModel() model.setObjectName('created model') view.setModel(model) view = ObjectView() diff --git a/tests/samplebinding/modelview_test.py b/tests/samplebinding/modelview_test.py new file mode 100644 index 000000000..9f86166d0 --- /dev/null +++ b/tests/samplebinding/modelview_test.py @@ -0,0 +1,73 @@ +#!/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 case for objects that keep references to other object without owning them (e.g. model/view relationships).''' + +import unittest +from sample import ObjectModel, ObjectType, ObjectView + + +object_name = 'test object' + +class MyObject(ObjectType): + pass + +class ListModelKeepsReference(ObjectModel): + def __init__(self, parent=None): + ObjectModel.__init__(self, parent) + self.obj = MyObject() + self.obj.setObjectName(object_name) + + def data(self): + return self.obj + +class ListModelDoesntKeepsReference(ObjectModel): + def data(self): + obj = MyObject() + obj.setObjectName(object_name) + return obj + + +class ModelViewTest(unittest.TestCase): + + def testListModelDoesntKeepsReference(self): + model = ListModelDoesntKeepsReference() + view = ObjectView(model) + obj = view.getRawModelData() + self.assertEqual(type(obj), ObjectType) + self.assertEqual(obj.objectName(), object_name) + + def testListModelKeepsReference(self): + model = ListModelKeepsReference() + view = ObjectView(model) + obj = view.getRawModelData() + self.assertEqual(type(obj), MyObject) + self.assertEqual(obj.objectName(), object_name) + + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index ba58c5f22..ae6f61b9d 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -236,13 +236,20 @@ </object-type> <object-type name="ObjectView"> - <modify-function signature="setModel(ObjectType*)"> + <modify-function signature="setModel(ObjectModel*)"> <modify-argument index="1"> <reference-count action="add"/> </modify-argument> </modify-function> </object-type> + <object-type name="ObjectModel"> + <modify-function signature="data() const"> + <modify-argument index="return"> + <define-ownership class="native" owner="c++"/> + </modify-argument> + </modify-function> + </object-type> <value-type name="Event"> <enum-type name="EventType"/> |