Created test to static metaobject.
Reviewer: Marcelo Lira <marcelo.lira@openbossa.org>,
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
e58db20b0f
commit
4452d5dbaa
2 changed files with 68 additions and 0 deletions
|
|
@ -65,5 +65,10 @@ private:
|
||||||
void updateMetaObject();
|
void updateMetaObject();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PYSIDE_API inline void deleteDynamicQMetaObject(void* data)
|
||||||
|
{
|
||||||
|
delete reinterpret_cast<DynamicQMetaObject*>(data);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
63
tests/signals/static_metaobject_test.py
Normal file
63
tests/signals/static_metaobject_test.py
Normal file
|
|
@ -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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue