From 569d1ab60e9b2227b2f4ed407718d17cc179d265 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Mon, 14 Jun 2010 14:59:26 -0300 Subject: Fixed parent function return ownership. Fixed QMainWindow functions ownership. Fixes #241. Reviewer: Hugo Parente Lima , Marcelo Lira --- tests/QtGui/qmainwindow_test.py | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/QtGui/qmainwindow_test.py b/tests/QtGui/qmainwindow_test.py index fce145d53..372018cb3 100644 --- a/tests/QtGui/qmainwindow_test.py +++ b/tests/QtGui/qmainwindow_test.py @@ -17,6 +17,14 @@ class MainWindow(QtGui.QMainWindow): pointerToolbar = self.addToolBar("Pointer type") pointerToolbar.addWidget(pointerButton) +class MyButton(QtGui.QPushButton): + def __init__(self, parent=None): + QtGui.QPushButton.__init__(self) + self._called = False + + def myCallback(self): + self._called = True + class TestMainWindow(UsesQApplication): @@ -26,6 +34,40 @@ class TestMainWindow(UsesQApplication): QtCore.QTimer.singleShot(1000, self.app.quit) self.app.exec_() + def testRefCountToNull(self): + w = QtGui.QMainWindow() + c = QtGui.QWidget() + self.assertEqual(sys.getrefcount(c), 2) + w.setCentralWidget(c) + self.assertEqual(sys.getrefcount(c), 3) + w.setCentralWidget(None) + self.assertEqual(sys.getrefcount(c), 2) + + def testRefCountToAnother(self): + w = QtGui.QMainWindow() + c = QtGui.QWidget() + self.assertEqual(sys.getrefcount(c), 2) + w.setCentralWidget(c) + self.assertEqual(sys.getrefcount(c), 3) + + c2 = QtGui.QWidget() + w.setCentralWidget(c2) + self.assertEqual(sys.getrefcount(c), 2) + self.assertEqual(sys.getrefcount(c2), 3) + + def testSignalDisconect(self): + w = QtGui.QMainWindow() + b = MyButton("button") + b.clicked.connect(b.myCallback) + w.setCentralWidget(b) + + b = MyButton("button") + b.clicked.connect(b.myCallback) + w.setCentralWidget(b) + + b.click() + self.assertEqual(b._called, True) + if __name__ == '__main__': unittest.main() -- cgit v1.2.3