Added test cases for signal emission.
Signals are emitted from C++ and Python.
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org>
Lauro Moura <lauro.neto@openbossa.org>
This commit is contained in:
parent
4a2bfc9239
commit
da8c292b69
5 changed files with 164 additions and 0 deletions
|
|
@ -76,5 +76,7 @@ PYSIDE_TEST(delegatecreateseditor_test.py)
|
||||||
PYSIDE_TEST(homonymoussignalandmethod_test.py)
|
PYSIDE_TEST(homonymoussignalandmethod_test.py)
|
||||||
PYSIDE_TEST(list_signal_test.py)
|
PYSIDE_TEST(list_signal_test.py)
|
||||||
PYSIDE_TEST(modelview_test.py)
|
PYSIDE_TEST(modelview_test.py)
|
||||||
|
PYSIDE_TEST(signalwithdefaultvalue_test.py)
|
||||||
|
PYSIDE_TEST(signalemissionfrompython_test.py)
|
||||||
PYSIDE_TEST(version_test.py)
|
PYSIDE_TEST(version_test.py)
|
||||||
|
|
||||||
|
|
|
||||||
79
tests/pysidetest/signalemissionfrompython_test.py
Normal file
79
tests/pysidetest/signalemissionfrompython_test.py
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from testbinding import TestObject
|
||||||
|
from PySide.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
|
'''Tests the behaviour of signals with default values when emitted from Python.'''
|
||||||
|
|
||||||
|
class SignalEmissionFromPython(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.obj1 = TestObject(0)
|
||||||
|
self.obj2 = TestObject(0)
|
||||||
|
self.one_called = 0
|
||||||
|
self.two_called = 0
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
del self.obj1
|
||||||
|
del self.obj2
|
||||||
|
del self.one_called
|
||||||
|
del self.two_called
|
||||||
|
|
||||||
|
def testConnectNewStyleEmitVoidSignal(self):
|
||||||
|
def callbackOne():
|
||||||
|
self.one_called += 1
|
||||||
|
self.obj2.signalWithDefaultValue.emit()
|
||||||
|
def callbackTwo():
|
||||||
|
self.two_called += 1
|
||||||
|
self.obj1.signalWithDefaultValue.connect(callbackOne)
|
||||||
|
self.obj2.signalWithDefaultValue.connect(callbackTwo)
|
||||||
|
self.obj1.emitSignalWithDefaultValue_void()
|
||||||
|
self.obj2.emitSignalWithDefaultValue_void()
|
||||||
|
self.assertEqual(self.one_called, 1)
|
||||||
|
self.assertEqual(self.two_called, 2)
|
||||||
|
|
||||||
|
def testConnectOldStyleEmitVoidSignal(self):
|
||||||
|
def callbackOne():
|
||||||
|
self.one_called += 1
|
||||||
|
self.obj2.signalWithDefaultValue.emit()
|
||||||
|
def callbackTwo():
|
||||||
|
self.two_called += 1
|
||||||
|
QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne)
|
||||||
|
QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo)
|
||||||
|
self.obj1.emitSignalWithDefaultValue_void()
|
||||||
|
self.obj2.emitSignalWithDefaultValue_void()
|
||||||
|
self.assertEqual(self.one_called, 1)
|
||||||
|
self.assertEqual(self.two_called, 2)
|
||||||
|
|
||||||
|
def testConnectNewStyleEmitBoolSignal(self):
|
||||||
|
def callbackOne():
|
||||||
|
self.one_called += 1
|
||||||
|
self.obj2.signalWithDefaultValue[bool].emit(True)
|
||||||
|
def callbackTwo():
|
||||||
|
self.two_called += 1
|
||||||
|
self.obj1.signalWithDefaultValue.connect(callbackOne)
|
||||||
|
self.obj2.signalWithDefaultValue.connect(callbackTwo)
|
||||||
|
self.obj1.emitSignalWithDefaultValue_void()
|
||||||
|
self.obj2.emitSignalWithDefaultValue_void()
|
||||||
|
self.assertEqual(self.one_called, 1)
|
||||||
|
self.assertEqual(self.two_called, 2)
|
||||||
|
|
||||||
|
def testConnectOldStyleEmitBoolSignal(self):
|
||||||
|
def callbackOne():
|
||||||
|
self.one_called += 1
|
||||||
|
self.obj2.signalWithDefaultValue[bool].emit(True)
|
||||||
|
def callbackTwo():
|
||||||
|
self.two_called += 1
|
||||||
|
QObject.connect(self.obj1, SIGNAL('signalWithDefaultValue()'), callbackOne)
|
||||||
|
QObject.connect(self.obj2, SIGNAL('signalWithDefaultValue()'), callbackTwo)
|
||||||
|
self.obj1.emitSignalWithDefaultValue_void()
|
||||||
|
self.obj2.emitSignalWithDefaultValue_void()
|
||||||
|
self.assertEqual(self.one_called, 1)
|
||||||
|
self.assertEqual(self.two_called, 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
67
tests/pysidetest/signalwithdefaultvalue_test.py
Normal file
67
tests/pysidetest/signalwithdefaultvalue_test.py
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
from testbinding import TestObject
|
||||||
|
from PySide.QtCore import QObject, SIGNAL
|
||||||
|
|
||||||
|
'''Tests the behaviour of signals with default values.'''
|
||||||
|
|
||||||
|
class SignalWithDefaultValueTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.obj = TestObject(0)
|
||||||
|
self.void_called = False
|
||||||
|
self.bool_called = False
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
del self.obj
|
||||||
|
del self.void_called
|
||||||
|
del self.bool_called
|
||||||
|
|
||||||
|
def testConnectNewStyleEmitVoidSignal(self):
|
||||||
|
def callbackVoid():
|
||||||
|
self.void_called = True
|
||||||
|
def callbackBool(value):
|
||||||
|
self.bool_called = True
|
||||||
|
self.obj.signalWithDefaultValue.connect(callbackVoid)
|
||||||
|
self.obj.signalWithDefaultValue[bool].connect(callbackBool)
|
||||||
|
self.obj.emitSignalWithDefaultValue_void()
|
||||||
|
self.assert_(self.void_called)
|
||||||
|
self.assert_(self.bool_called)
|
||||||
|
|
||||||
|
def testConnectNewStyleEmitBoolSignal(self):
|
||||||
|
def callbackVoid():
|
||||||
|
self.void_called = True
|
||||||
|
def callbackBool(value):
|
||||||
|
self.bool_called = True
|
||||||
|
self.obj.signalWithDefaultValue.connect(callbackVoid)
|
||||||
|
self.obj.signalWithDefaultValue[bool].connect(callbackBool)
|
||||||
|
self.obj.emitSignalWithDefaultValue_bool()
|
||||||
|
self.assert_(self.void_called)
|
||||||
|
self.assert_(self.bool_called)
|
||||||
|
|
||||||
|
def testConnectOldStyleEmitVoidSignal(self):
|
||||||
|
def callbackVoid():
|
||||||
|
self.void_called = True
|
||||||
|
def callbackBool(value):
|
||||||
|
self.bool_called = True
|
||||||
|
QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid)
|
||||||
|
QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool)
|
||||||
|
self.obj.emitSignalWithDefaultValue_void()
|
||||||
|
self.assert_(self.void_called)
|
||||||
|
self.assert_(self.bool_called)
|
||||||
|
|
||||||
|
def testConnectOldStyleEmitBoolSignal(self):
|
||||||
|
def callbackVoid():
|
||||||
|
self.void_called = True
|
||||||
|
def callbackBool(value):
|
||||||
|
self.bool_called = True
|
||||||
|
QObject.connect(self.obj, SIGNAL('signalWithDefaultValue()'), callbackVoid)
|
||||||
|
QObject.connect(self.obj, SIGNAL('signalWithDefaultValue(bool)'), callbackBool)
|
||||||
|
self.obj.emitSignalWithDefaultValue_bool()
|
||||||
|
self.assert_(self.void_called)
|
||||||
|
self.assert_(self.bool_called)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
||||||
|
|
||||||
|
|
@ -12,3 +12,15 @@ TestObject::emitStaticMethodDoubleSignal()
|
||||||
emit staticMethodDouble();
|
emit staticMethodDouble();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TestObject::emitSignalWithDefaultValue_void()
|
||||||
|
{
|
||||||
|
emit signalWithDefaultValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TestObject::emitSignalWithDefaultValue_bool()
|
||||||
|
{
|
||||||
|
emit signalWithDefaultValue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,15 @@ public:
|
||||||
void emitIdValueSignal();
|
void emitIdValueSignal();
|
||||||
void emitStaticMethodDoubleSignal();
|
void emitStaticMethodDoubleSignal();
|
||||||
|
|
||||||
|
void emitSignalWithDefaultValue_void();
|
||||||
|
void emitSignalWithDefaultValue_bool();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void idValue(int newValue);
|
void idValue(int newValue);
|
||||||
void justASignal();
|
void justASignal();
|
||||||
void staticMethodDouble();
|
void staticMethodDouble();
|
||||||
void childrenChanged(const QList<QObject*>&);
|
void childrenChanged(const QList<QObject*>&);
|
||||||
|
void signalWithDefaultValue(bool value = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_idValue;
|
int m_idValue;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue