aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/QtGui/CMakeLists.txt1
-rw-r--r--tests/QtGui/qvalidator_test.py85
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()