aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-02-17 16:44:17 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-02-17 17:03:02 -0300
commit16b2d0e370d4c7f69e846a90737ca56e010cf609 (patch)
treed726d22f733d0a8c47bd5682d498ba9a0a732715 /tests
parentfb265bc5c4f61bee40508168c891252bffc15f72 (diff)
Fixes QtGui type system to use 'reference-count' tag setModel methods.
Various setModel methods where changed from the incorrect parenting tag to the proper 'reference-count' tag. The return value of QAbstractItemView.model() was defined to have 'default' ownership, otherwise the Qt heuristics from the generator would set the returned pointer as a child belonging to the QAbstractItemView instance. The test case for this was expanded and changed to a more meaningful name. Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/qtgui/keep_reference_test.py75
-rwxr-xr-xtests/qtgui/parent_policy_test.py37
2 files changed, 75 insertions, 37 deletions
diff --git a/tests/qtgui/keep_reference_test.py b/tests/qtgui/keep_reference_test.py
new file mode 100755
index 000000000..d0962d5df
--- /dev/null
+++ b/tests/qtgui/keep_reference_test.py
@@ -0,0 +1,75 @@
+#!/usr/bin/env python
+
+import unittest
+
+from sys import getrefcount
+from helper import UsesQApplication
+from PySide.QtCore import QAbstractTableModel, QVariant
+from PySide.QtGui import QTableView
+
+class TestModel(QAbstractTableModel):
+ def __init__(self, parent=None):
+ QAbstractTableModel.__init__(self, parent)
+ def rowCount(self, parent):
+ return 0
+ def columnCount(self, parent):
+ return 0
+ def data(self, index, role):
+ return QVariant()
+
+class KeepReferenceTest(UsesQApplication):
+
+ def testModelWithoutParent(self):
+ view = QTableView()
+ model = TestModel()
+ view.setModel(model)
+ samemodel = view.model()
+ self.assertEqual(model, samemodel)
+
+ def testModelWithParent(self):
+ view = QTableView()
+ model = TestModel(self.app)
+ view.setModel(model)
+ samemodel = view.model()
+ self.assertEqual(model, samemodel)
+
+ def testReferenceCounting(self):
+ '''Tests reference count of model object referred by view objects.'''
+ model1 = TestModel()
+ refcount1 = getrefcount(model1)
+ view1 = QTableView()
+ view1.setModel(model1)
+ self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
+
+ view2 = QTableView()
+ view2.setModel(model1)
+ self.assertEqual(getrefcount(view2.model()), refcount1 + 2)
+
+ model2 = TestModel()
+ view2.setModel(model2)
+ self.assertEqual(getrefcount(view1.model()), refcount1 + 1)
+
+ def testReferenceCountingWhenDeletingReferrer(self):
+ '''Tests reference count of model object referred by deceased view object.'''
+ model = TestModel()
+ refcount1 = getrefcount(model)
+ view = QTableView()
+ view.setModel(model)
+ self.assertEqual(getrefcount(view.model()), refcount1 + 1)
+
+ del view
+ self.assertEqual(getrefcount(model), refcount1)
+
+ def testReferreedObjectSurvivalAfterContextEnd(self):
+ '''Model object assigned to a view object must survive after getting out of context.'''
+ def createModelAndSetToView(view):
+ model = TestModel()
+ model.setObjectName('created model')
+ view.setModel(model)
+ view = QTableView()
+ createModelAndSetToView(view)
+ model = view.model()
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/qtgui/parent_policy_test.py b/tests/qtgui/parent_policy_test.py
deleted file mode 100755
index e90da5a49..000000000
--- a/tests/qtgui/parent_policy_test.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-import unittest
-
-from helper import UsesQApplication
-from PySide.QtCore import QAbstractTableModel, QVariant
-from PySide.QtGui import QTableView
-
-class TestModel(QAbstractTableModel):
- def __init__(self, parent=None):
- QAbstractTableModel.__init__(self, parent)
- def rowCount(self, parent):
- return 0
- def columnCount(self, parent):
- return 0
- def data(self, index, role):
- return QVariant()
-
-class ParentPolicyTest(UsesQApplication):
-
- def testModelWithoutParent(self):
- view = QTableView()
- model = TestModel()
- view.setModel(model)
- samemodel = view.model()
- self.assertEqual(model, samemodel)
-
- def testModelWithParent(self):
- view = QTableView()
- model = TestModel(self.app)
- view.setModel(model)
- samemodel = view.model()
- self.assertEqual(model, samemodel)
-
-if __name__ == '__main__':
- unittest.main()
-