diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2010-11-11 17:45:16 -0200 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2010-11-11 18:13:50 -0200 |
commit | 655219636b1500e82d543914045f4cc7ba7db95f (patch) | |
tree | 631b9309a21711d69f912fc8ec7a82b706e67e99 /tests | |
parent | 7013bd760e1ad46b31c019e0a11df504d6e2563e (diff) |
Fix bug#436 - "Using a custom QValidator generates a segfault"
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/QtGui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/QtGui/qvalidator_test.py | 85 |
2 files changed, 86 insertions, 0 deletions
diff --git a/tests/QtGui/CMakeLists.txt b/tests/QtGui/CMakeLists.txt index 7ff2f7e4b..9086829f8 100644 --- a/tests/QtGui/CMakeLists.txt +++ b/tests/QtGui/CMakeLists.txt @@ -71,6 +71,7 @@ PYSIDE_TEST(qtextedit_signal_test.py) PYSIDE_TEST(qtoolbar_test.py) PYSIDE_TEST(qtoolbox_test.py) PYSIDE_TEST(qvariant_test.py) +PYSIDE_TEST(qvalidator_test.py) PYSIDE_TEST(qwidget_setlayout_test.py) PYSIDE_TEST(qwidget_test.py) PYSIDE_TEST(reference_count_test.py) diff --git a/tests/QtGui/qvalidator_test.py b/tests/QtGui/qvalidator_test.py new file mode 100644 index 000000000..52dbc8b0e --- /dev/null +++ b/tests/QtGui/qvalidator_test.py @@ -0,0 +1,85 @@ +from PySide.QtCore import * +from PySide.QtGui import * + +import unittest +from helper import UsesQApplication + +class MyValidator1(QValidator): + def fixUp(self, input): + return "fixed" + + def validate(self, input, pos): + return (QValidator.Acceptable, "fixed", 1) + +class MyValidator2(QValidator): + def fixUp(self, input): + return "fixed" + + def validate(self, input, pos): + return (QValidator.Acceptable, "fixed") + +class MyValidator3(QValidator): + def fixUp(self, input): + return "fixed" + + def validate(self, input, pos): + return (QValidator.Acceptable,) + +class MyValidator4(QValidator): + def fixUp(self, input): + return "fixed" + + def validate(self, input, pos): + return QValidator.Acceptable + +class QValidatorTest(UsesQApplication): + def testValidator1(self): + line = QLineEdit() + line.setValidator(MyValidator1()) + line.show() + line.setText("foo") + + QTimer.singleShot(0, line.close) + self.app.exec_() + + self.assertEqual(line.text(), "fixed") + self.assertEqual(line.cursorPosition(), 1) + + def testValidator2(self): + line = QLineEdit() + line.setValidator(MyValidator2()) + line.show() + line.setText("foo") + + QTimer.singleShot(0, line.close) + self.app.exec_() + + self.assertEqual(line.text(), "fixed") + self.assertEqual(line.cursorPosition(), 3) + + def testValidator3(self): + line = QLineEdit() + line.setValidator(MyValidator3()) + line.show() + line.setText("foo") + + QTimer.singleShot(0, line.close) + self.app.exec_() + + self.assertEqual(line.text(), "foo") + self.assertEqual(line.cursorPosition(), 3) + + def testValidator4(self): + line = QLineEdit() + line.setValidator(MyValidator4()) + line.show() + line.setText("foo") + + QTimer.singleShot(0, line.close) + self.app.exec_() + + self.assertEqual(line.text(), "foo") + self.assertEqual(line.cursorPosition(), 3) + +if __name__ == '__main__': + unittest.main() |