aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLauro Neto <lauro.neto@openbossa.org>2009-11-25 19:12:02 -0300
committerHugo Lima <hugo.lima@openbossa.org>2009-11-27 16:24:06 -0200
commitcd074d305fddf1a3aced9513909adcf9ce632975 (patch)
tree54a3236553c95c8d78e7c117b6612884ae82e76d /tests
parent9dbb330536497b07e803dda7c6368d7e875b2c3b (diff)
Adding test for deleting parent
Diffstat (limited to 'tests')
-rwxr-xr-xtests/samplebinding/ownership_delete_parent_test.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/tests/samplebinding/ownership_delete_parent_test.py b/tests/samplebinding/ownership_delete_parent_test.py
new file mode 100755
index 000000000..1e70a905e
--- /dev/null
+++ b/tests/samplebinding/ownership_delete_parent_test.py
@@ -0,0 +1,79 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Shiboken Python Bindings Generator project.
+#
+# Copyright (C) 2009 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
+
+'''Tests for destroying/invalidating the parent'''
+
+import sys
+import unittest
+
+from sample import ObjectType
+
+
+class DeleteParentTest(unittest.TestCase):
+ '''Test case for deleting an parent object'''
+
+ def testParentDestructor(self):
+ '''Delete parent object should invalidate child'''
+ parent = ObjectType()
+ child = ObjectType(parent)
+
+ refcount_before = sys.getrefcount(child)
+
+ del parent
+ self.assertRaises(RuntimeError, child.objectName)
+ self.assertEqual(sys.getrefcount(child), refcount_before-1)
+
+ def testParentDestructorMultipleChildren(self):
+ '''Delete parent object should invalidate all children'''
+ parent = ObjectType()
+ children = [ObjectType(parent) for _ in range(10)]
+
+ refcount_before = map(sys.getrefcount, children)
+
+ del parent
+ for i, child in enumerate(children):
+ self.assertRaises(RuntimeError, child.objectName)
+ self.assertEqual(sys.getrefcount(child), refcount_before[i]-1)
+
+ def testRecursiveParentDelete(self):
+ '''Delete parent should invalidate grandchildren'''
+
+ parent = ObjectType()
+ child = ObjectType(parent)
+ grandchild = ObjectType(child)
+
+ refcount_before = sys.getrefcount(child)
+ grand_refcount_before = sys.getrefcount(grandchild)
+
+ del parent
+ self.assertRaises(RuntimeError, child.objectName)
+ self.assertEqual(sys.getrefcount(child), refcount_before-1)
+ self.assertRaises(RuntimeError, grandchild.objectName)
+ self.assertEqual(sys.getrefcount(grandchild), grand_refcount_before-1)
+
+
+if __name__ == '__main__':
+ unittest.main()