aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-02-05 11:42:19 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-02-10 08:42:23 -0300
commit18e0f058e4d293ba9c75f73529e946c46eb89873 (patch)
tree827c764e20fbd7c16625fb15ea8c4260f174388d /tests/samplebinding
parent54b41b60e7c1b5bf2597cf1cc3ca4da428f2437e (diff)
Adds tests for reference counting in model/view style relationships.
Diffstat (limited to 'tests/samplebinding')
-rw-r--r--tests/samplebinding/CMakeLists.txt1
-rw-r--r--tests/samplebinding/global.h1
-rwxr-xr-xtests/samplebinding/keep_reference_test.py76
-rw-r--r--tests/samplebinding/typesystem_sample.xml2
4 files changed, 80 insertions, 0 deletions
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index de24c02fe..179761e0d 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -37,6 +37,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/nondefaultctor_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
${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp
diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h
index b11098631..b442623e2 100644
--- a/tests/samplebinding/global.h
+++ b/tests/samplebinding/global.h
@@ -16,6 +16,7 @@
#include "nondefaultctor.h"
#include "objecttype.h"
#include "objecttypelayout.h"
+#include "objectview.h"
#include "oddbool.h"
#include "overload.h"
#include "pairuser.h"
diff --git a/tests/samplebinding/keep_reference_test.py b/tests/samplebinding/keep_reference_test.py
new file mode 100755
index 000000000..13730553e
--- /dev/null
+++ b/tests/samplebinding/keep_reference_test.py
@@ -0,0 +1,76 @@
+#!/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 sys import getrefcount
+
+from sample import ObjectType, 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()
+ refcount1 = getrefcount(model1)
+ view1 = ObjectView()
+ view1.setModel(model1)
+ self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
+
+ view2 = ObjectView()
+ view2.setModel(model1)
+ self.assertEqual(getrefcount(view2.model()), refcount1 + 2)
+
+ model2 = ObjectType()
+ 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()
+ refcount1 = getrefcount(model)
+ view = ObjectView()
+ view.setModel(model)
+ self.assertEqual(getrefcount(view.model()), refcount1 + 1)
+
+ del view
+ self.assertEqual(getrefcount(model), refcount1)
+
+ 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.setObjectName('created model')
+ view.setModel(model)
+ view = ObjectView()
+ createModelAndSetToView(view)
+ model = view.model()
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index a722276ea..9d06a2803 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -138,6 +138,8 @@
</modify-function>
</object-type>
+ <object-type name="ObjectView"/>
+
<value-type name="Event"/>
<value-type name="BlackBox">