diff options
author | Lauro Neto <lauro.neto@openbossa.org> | 2009-12-16 15:47:30 -0300 |
---|---|---|
committer | Lauro Neto <lauro.neto@openbossa.org> | 2009-12-16 21:14:24 -0300 |
commit | fb040f76c1752d929f48101a9205223f2d32a98d (patch) | |
tree | 3f971b7f1ffb38d38586d91673d7e862cfe48985 /tests | |
parent | ffd0b47222e9a46615c9f86a3eb9aa034579acee (diff) |
Signal emission tests with non QtGui tests
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/signals/signal_emission_test.py | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/tests/signals/signal_emission_test.py b/tests/signals/signal_emission_test.py index b79b033d9..57b71948f 100644 --- a/tests/signals/signal_emission_test.py +++ b/tests/signals/signal_emission_test.py @@ -5,10 +5,11 @@ import sys import unittest -from PySide.QtCore import QObject, QTimer, QCoreApplication, SIGNAL, SLOT, QProcess +from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine +from PySide.QtCore import QTimer, QThread try: - from PySide.QtGui import QSpinBox, QPushButton, QApplication + from PySide.QtGui import QSpinBox, QPushButton except ImportError: QSpinBox = object QPushButton = object @@ -135,6 +136,70 @@ class MoreArgsOnEmit(UsesQCoreApplication): process = QProcess() self.assertRaises(TypeError, process.emit, SIGNAL('finished(int)'), 55, 55) +class Dummy(QObject): + '''Dummy class''' + pass + + +class PythonSignalToCppSlots(UsesQCoreApplication): + '''Connect python signals to C++ slots''' + + def testWithoutArgs(self): + '''Connect python signal to QTimeLine.toggleDirection()''' + timeline = QTimeLine() + dummy = Dummy() + QObject.connect(dummy, SIGNAL('dummy()'), + timeline, SLOT('toggleDirection()')) + + orig_dir = timeline.direction() + dummy.emit(SIGNAL('dummy()')) + new_dir = timeline.direction() + + if orig_dir == QTimeLine.Forward: + self.assertEqual(new_dir, QTimeLine.Backward) + else: + self.assertEqual(new_dir, QTimeLine.Forward) + + def testWithArgs(self): + '''Connect python signals to QTimeLine.setCurrentTime(int)''' + timeline = QTimeLine() + dummy = Dummy() + + QObject.connect(dummy, SIGNAL('dummy(int)'), + timeline, SLOT('setCurrentTime(int)')) + + current = timeline.currentTime() + dummy.emit(SIGNAL('dummy(int)'), current+42) + self.assertEqual(timeline.currentTime(), current+42) + +class CppSignalsToCppSlots(UsesQCoreApplication): + '''Connection between C++ slots and signals''' + + def testWithoutArgs(self): + '''Connect QThread.started() to QTimeLine.togglePaused()''' + thread = QThread() + timeline = QTimeLine() + + QObject.connect(thread, SIGNAL('started()'), + timeline, SLOT('toggleDirection()')) + QObject.connect(thread, SIGNAL('started()'), + self.exit_app_cb) + + orig_dir = timeline.direction() + + timer = QTimer.singleShot(1000, self.exit_app_cb) # Just for safety + + thread.start() + self.app.exec_() + thread.wait() + + new_dir = timeline.direction() + + if orig_dir == QTimeLine.Forward: + self.assertEqual(new_dir, QTimeLine.Backward) + else: + self.assertEqual(new_dir, QTimeLine.Forward) + if __name__ == '__main__': unittest.main() |