aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorRenato Filho <renato.filho@openbossa.org>2010-05-10 13:41:56 -0300
committerRenato Filho <renato.filho@openbossa.org>2010-05-10 17:30:07 -0300
commit4452d5dbaa089ad8bf9ae169d6d7579a04215161 (patch)
treee4014e834dc31c298729c40b462227aee053f0f3 /tests
parente58db20b0fe32beb87365e74cf29fc45bb8ce603 (diff)
Created test to static metaobject.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>, Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/signals/static_metaobject_test.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/signals/static_metaobject_test.py b/tests/signals/static_metaobject_test.py
new file mode 100644
index 00000000..bce711f8
--- /dev/null
+++ b/tests/signals/static_metaobject_test.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python
+
+"""Tests covering signal emission and receiving to python slots"""
+
+import sys
+import unittest
+import functools
+
+from PySide.QtCore import *
+from helper import BasicPySlotCase, UsesQCoreApplication
+
+class MyObject(QObject):
+ def __init__(self, parent=None):
+ QObject.__init__(self, parent)
+ self._slotCalledCount = 0
+
+ def mySlot(self):
+ self._slotCalledCount = self._slotCalledCount + 1
+
+
+class StaticMetaObjectTest(UsesQCoreApplication):
+
+ def testSignalPropagation(self):
+ o = MyObject()
+ o2 = MyObject()
+
+ m = o.metaObject()
+ # SIGNAL foo not created yet
+ self.assertEqual(m.indexOfSignal("foo()"), -1)
+
+ o.connect(SIGNAL("foo()"), o2.mySlot)
+ # SIGNAL foo create after connect
+ self.assert_(m.indexOfSignal("foo()") > 0)
+
+ m = o2.metaObject()
+ # SIGNAL propagate to others objects of the same type
+ self.assert_(m.indexOfSignal("foo()") > 0)
+
+ del o
+ # SIGNAL foo continues registered after deletion of original object
+ self.assert_(m.indexOfSignal("foo()") > 0)
+
+ del o2
+ o = MyObject()
+ m = o.metaObject()
+ # new objects still have the SIGNAL foo registered
+ self.assert_(m.indexOfSignal("foo()") > 0)
+
+
+ def testSharedSignalEmission(self):
+ o = QObject()
+ m = MyObject()
+
+ o.connect(SIGNAL("foo2()"), m.mySlot)
+ m.connect(SIGNAL("foo2()"), m.mySlot)
+ o.emit(SIGNAL("foo2()"))
+ self.assertEqual(m._slotCalledCount, 1)
+ del o
+ m.emit(SIGNAL("foo2()"))
+ self.assertEqual(m._slotCalledCount, 2)
+
+if __name__ == '__main__':
+ unittest.main()