From 1155542ecca6ab5d8ee00aececae453d980ac690 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 4 Feb 2011 19:07:04 -0300 Subject: Created unit test for signals. Test for types inside of namespace Test for types defined by typedef. Reviewer: Marcelo Lira Luciano Wolf --- tests/pysidetest/CMakeLists.txt | 4 ++ tests/pysidetest/signalandnamespace_test.py | 92 +++++++++++++++++++++++++++++ tests/pysidetest/testobject.h | 51 ++++++++++++++++ tests/pysidetest/typesystem_pysidetest.xml | 26 ++++++++ 4 files changed, 173 insertions(+) create mode 100644 tests/pysidetest/signalandnamespace_test.py diff --git a/tests/pysidetest/CMakeLists.txt b/tests/pysidetest/CMakeLists.txt index 03d55a5f0..964d70d07 100644 --- a/tests/pysidetest/CMakeLists.txt +++ b/tests/pysidetest/CMakeLists.txt @@ -23,6 +23,9 @@ qt4_wrap_cpp(pysidetest_MOC_SRC ${pysidetest_MOC_HEADERS}) set(testbinding_SRC ${CMAKE_CURRENT_BINARY_DIR}/testbinding/testobject_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_testobjectwithnamespace_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp2_testobjectwithoutnamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/testview_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/testbinding/testbinding_module_wrapper.cpp ) @@ -75,6 +78,7 @@ PYSIDE_TEST(delegatecreateseditor_test.py) PYSIDE_TEST(homonymoussignalandmethod_test.py) PYSIDE_TEST(list_signal_test.py) PYSIDE_TEST(modelview_test.py) +PYSIDE_TEST(signalandnamespace_test.py) PYSIDE_TEST(signalwithdefaultvalue_test.py) PYSIDE_TEST(signalemissionfrompython_test.py) PYSIDE_TEST(version_test.py) diff --git a/tests/pysidetest/signalandnamespace_test.py b/tests/pysidetest/signalandnamespace_test.py new file mode 100644 index 000000000..ae93cf385 --- /dev/null +++ b/tests/pysidetest/signalandnamespace_test.py @@ -0,0 +1,92 @@ +#!/usr/bin/python + +import unittest +from testbinding import PySideCPP, TestObjectWithoutNamespace + +class ModelViewTest(unittest.TestCase): + + def callback(self, o): + self._called = o + + def testWithoutNamespace(self): + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignal.connect(self.callback) + o.emitSignal.emit(o) + self.assert_(o == self._called) + + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignal.connect(self.callback) + o.callSignal(o) + self.assert_(o == self._called) + + def testWithNamespace(self): + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.emitSignalWithNamespace.emit(o) + self.assert_(o == self._called) + + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.callSignalWithNamespace(o) + self.assert_(o == self._called) + + + def testWithoutNamespace1(self): + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignal.connect(self.callback) + o.emitSignal.emit(o) + self.assert_(o == self._called) + + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignal.connect(self.callback) + o.callSignal(o) + self.assert_(o == self._called) + + def testWithNamespace1(self): + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.emitSignalWithNamespace.emit(o) + self.assert_(o == self._called) + + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithNamespace.connect(self.callback) + o.callSignalWithNamespace(o) + self.assert_(o == self._called) + + def testTypedfWithouNamespace(self): + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.emitSignalWithTypedef.emit(10) + self.assertEqual(10, self._called) + + self._called = None + o = PySideCPP.TestObjectWithNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.callSignalWithTypedef(10) + self.assertEqual(10, self._called) + + def testTypedefWithNamespace(self): + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.emitSignalWithTypedef.emit(10) + self.assertEqual(10, self._called) + + self._called = None + o = TestObjectWithoutNamespace(None) + o.emitSignalWithTypedef.connect(self.callback) + o.callSignalWithTypedef(10) + self.assertEqual(10, self._called) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/pysidetest/testobject.h b/tests/pysidetest/testobject.h index 8dcb4c06d..ca662d70e 100644 --- a/tests/pysidetest/testobject.h +++ b/tests/pysidetest/testobject.h @@ -2,6 +2,7 @@ #define TESTOBJECT_H #include +#include #ifdef pysidetest_EXPORTS #define PYSIDE_EXPORTS 1 #endif @@ -34,5 +35,55 @@ private: QList m_children; }; + +typedef int PySideInt; + + +namespace PySideCPP { + +class PYSIDE_API TestObjectWithNamespace : public QObject +{ + Q_OBJECT +public: + TestObjectWithNamespace(QObject* parent) : QObject(parent) {} + QString name() { return "TestObjectWithNamespace"; } + + void callSignal(TestObjectWithNamespace* obj) { emitSignal(obj); } + void callSignalWithNamespace(TestObjectWithNamespace* obj) { emitSignalWithNamespace(obj); } + void callSignalWithTypedef(int val) { emitSignalWithTypedef(val); } + +signals: + void emitSignal(TestObjectWithNamespace* obj); + void emitSignalWithNamespace(PySideCPP::TestObjectWithNamespace* obj); + void emitSignalWithTypedef(PySideInt val); +}; + + +} // Namespace PySideCPP + +namespace PySideCPP2 { + +typedef long PySideLong; + +class PYSIDE_API TestObjectWithoutNamespace : public QObject +{ + Q_OBJECT +public: + TestObjectWithoutNamespace(QObject* parent) : QObject(parent) {} + QString name() { return "TestObjectWithoutNamespace"; } + + void callSignal(TestObjectWithoutNamespace* obj) { emitSignal(obj); } + void callSignalWithNamespace(TestObjectWithoutNamespace* obj) { emitSignalWithNamespace(obj); } + void callSignalWithTypedef(long val) { emitSignalWithTypedef(val); } + +signals: + void emitSignal(TestObjectWithoutNamespace* obj); + void emitSignalWithNamespace(PySideCPP2::TestObjectWithoutNamespace* obj); + void emitSignalWithTypedef(PySideLong val); +}; + + +} // Namespace PySideCPP2 + #endif // TESTOBJECT_H diff --git a/tests/pysidetest/typesystem_pysidetest.xml b/tests/pysidetest/typesystem_pysidetest.xml index 9cc413039..52396203c 100644 --- a/tests/pysidetest/typesystem_pysidetest.xml +++ b/tests/pysidetest/typesystem_pysidetest.xml @@ -3,6 +3,32 @@ + + + qRegisterMetaType<PySideInt>("PySideInt"); + qRegisterMetaType<PySideCPP2::PySideLong>("PySideLong"); + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3