aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtGui/qlayout_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/QtGui/qlayout_test.py')
-rw-r--r--tests/QtGui/qlayout_test.py31
1 files changed, 27 insertions, 4 deletions
diff --git a/tests/QtGui/qlayout_test.py b/tests/QtGui/qlayout_test.py
index ae773bb0a..88c37aa4d 100644
--- a/tests/QtGui/qlayout_test.py
+++ b/tests/QtGui/qlayout_test.py
@@ -2,7 +2,7 @@ import unittest
import sys
from helper import UsesQApplication
-from PySide.QtGui import QLayout, QWidget, QPushButton, QWidgetItem
+from PySide.QtGui import QLayout, QWidget, QPushButton, QWidgetItem, QHBoxLayout
class MyLayout(QLayout):
def __init__(self, parent=None):
@@ -29,24 +29,47 @@ class MyLayout(QLayout):
-#Test if a layout implemented in python, the QWidget.setLayout works
-#fine because this implement som layout functions used in glue code of
+#Test if a layout implemented in python, the QWidget.setLayout works
+#fine because this implement som layout functions used in glue code of
#QWidget, then in c++ when call a virtual function this need call the QLayout
#function implemented in python
class QLayoutTest(UsesQApplication):
-
def testOwnershipTransfer(self):
b = QPushButton("teste")
l = MyLayout()
+
l.addWidget(b)
self.assertEqual(sys.getrefcount(b), 2)
w = QWidget()
+
+ #transfer ref
+ w.setLayout(l)
+
+ self.assertEqual(sys.getrefcount(b), 3)
+
+
+ def testReferenceTransfer(self):
+ b = QPushButton("teste")
+ l = QHBoxLayout()
+
+ # keep ref
+ l.addWidget(b)
+ self.assertEqual(sys.getrefcount(b), 3)
+
+ w = QWidget()
+
+ # transfer ref
w.setLayout(l)
self.assertEqual(sys.getrefcount(b), 3)
+ # release ref
+ del w
+
+ self.assertEqual(sys.getrefcount(b), 2)
+
if __name__ == '__main__':
unittest.main()