summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-01-20 15:57:48 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:51:47 -0300
commitda8c292b69c53f0a16bc405ed590ce5d4ecacf9b (patch)
treebe75a999617280c72a94f22517788c9957c8834a
parent4a2bfc9239c13272478185ce056e481d7aa1106b (diff)
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>
-rw-r--r--tests/pysidetest/CMakeLists.txt2
-rw-r--r--tests/pysidetest/signalemissionfrompython_test.py79
-rw-r--r--tests/pysidetest/signalwithdefaultvalue_test.py67
-rw-r--r--tests/pysidetest/testobject.cpp12
-rw-r--r--tests/pysidetest/testobject.h4
5 files changed, 164 insertions, 0 deletions
diff --git a/tests/pysidetest/CMakeLists.txt b/tests/pysidetest/CMakeLists.txt
index 0ce9da9b..75fbb6e4 100644
--- a/tests/pysidetest/CMakeLists.txt
+++ b/tests/pysidetest/CMakeLists.txt
@@ -76,5 +76,7 @@ PYSIDE_TEST(delegatecreateseditor_test.py)
PYSIDE_TEST(homonymoussignalandmethod_test.py)
PYSIDE_TEST(list_signal_test.py)
PYSIDE_TEST(modelview_test.py)
+PYSIDE_TEST(signalwithdefaultvalue_test.py)
+PYSIDE_TEST(signalemissionfrompython_test.py)
PYSIDE_TEST(version_test.py)
diff --git a/tests/pysidetest/signalemissionfrompython_test.py b/tests/pysidetest/signalemissionfrompython_test.py
new file mode 100644
index 00000000..9d130cb4
--- /dev/null
+++ b/tests/pysidetest/signalemissionfrompython_test.py
@@ -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()
+
diff --git a/tests/pysidetest/signalwithdefaultvalue_test.py b/tests/pysidetest/signalwithdefaultvalue_test.py
new file mode 100644
index 00000000..3a18bb71
--- /dev/null
+++ b/tests/pysidetest/signalwithdefaultvalue_test.py
@@ -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()
+
diff --git a/tests/pysidetest/testobject.cpp b/tests/pysidetest/testobject.cpp
index 717c4e3c..6911334f 100644
--- a/tests/pysidetest/testobject.cpp
+++ b/tests/pysidetest/testobject.cpp
@@ -12,3 +12,15 @@ TestObject::emitStaticMethodDoubleSignal()
emit staticMethodDouble();
}
+void
+TestObject::emitSignalWithDefaultValue_void()
+{
+ emit signalWithDefaultValue();
+}
+
+void
+TestObject::emitSignalWithDefaultValue_bool()
+{
+ emit signalWithDefaultValue(true);
+}
+
diff --git a/tests/pysidetest/testobject.h b/tests/pysidetest/testobject.h
index 65506b94..8dcb4c06 100644
--- a/tests/pysidetest/testobject.h
+++ b/tests/pysidetest/testobject.h
@@ -19,11 +19,15 @@ public:
void emitIdValueSignal();
void emitStaticMethodDoubleSignal();
+ void emitSignalWithDefaultValue_void();
+ void emitSignalWithDefaultValue_bool();
+
signals:
void idValue(int newValue);
void justASignal();
void staticMethodDouble();
void childrenChanged(const QList<QObject*>&);
+ void signalWithDefaultValue(bool value = false);
private:
int m_idValue;