aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtCore/qthread_test.py
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-06-07 14:43:45 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-06-07 16:57:11 -0300
commitab918abc1e103e0ca86939f7d057e8a44ac8a4ef (patch)
tree53c6f57d089dcf5e145d766b1ceef704714046d8 /tests/QtCore/qthread_test.py
parent471486732b03cbb42b884158604a59d5a18e8a35 (diff)
Created new unittest model.
Separete unittest for module. Only run unittest for compiled modules. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>, Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests/QtCore/qthread_test.py')
-rw-r--r--tests/QtCore/qthread_test.py76
1 files changed, 76 insertions, 0 deletions
diff --git a/tests/QtCore/qthread_test.py b/tests/QtCore/qthread_test.py
new file mode 100644
index 000000000..410afb908
--- /dev/null
+++ b/tests/QtCore/qthread_test.py
@@ -0,0 +1,76 @@
+#!/usr/bin/python
+'''Test cases for QThread'''
+
+import unittest
+from PySide.QtCore import QThread, QCoreApplication, QObject, SIGNAL, QMutex, QTimer
+from PySide.QtCore import QEventLoop
+
+from helper import UsesQCoreApplication
+
+mutex = QMutex()
+
+class Dummy(QThread):
+ '''Dummy thread'''
+ def __init__(self, *args):
+ super(Dummy, self).__init__(*args)
+ self.called = False
+
+ def run(self):
+ #Start-quit sequence
+ mutex.lock()
+ self.called = True
+ mutex.unlock()
+
+class QThreadSimpleCase(UsesQCoreApplication):
+
+ def setUp(self):
+ UsesQCoreApplication.setUp(self)
+ self.called = False
+
+ def tearDown(self):
+ UsesQCoreApplication.tearDown(self)
+
+ def testThread(self):
+ #Basic QThread test
+ obj = Dummy()
+ obj.start()
+ obj.wait()
+
+ self.assert_(obj.called)
+
+ def cb(self, *args):
+ self.called = True
+ #self.exit_app_cb()
+
+ def abort_application(self):
+ self._thread.terminate()
+ self.app.quit()
+
+ def testSignalFinished(self):
+ #QThread.finished() (signal)
+ obj = Dummy()
+ QObject.connect(obj, SIGNAL('finished()'), self.cb)
+ mutex.lock()
+ obj.start()
+ mutex.unlock()
+
+ self._thread = obj
+ QTimer.singleShot(1000, self.abort_application)
+ self.app.exec_()
+
+ self.assert_(self.called)
+
+ def testSignalStarted(self):
+ #QThread.started() (signal)
+ obj = Dummy()
+ QObject.connect(obj, SIGNAL('started()'), self.cb)
+ obj.start()
+
+ self._thread = obj
+ QTimer.singleShot(1000, self.abort_application)
+ self.app.exec_()
+
+ self.assert_(self.called)
+
+if __name__ == '__main__':
+ unittest.main()