summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@openbossa.org>2011-02-04 19:07:04 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:53:55 -0300
commit1155542ecca6ab5d8ee00aececae453d980ac690 (patch)
tree1edfafbfd35c426b73255ed0814e1efb7a9412c0
parent4ebad6745f9c85dd4f074fe328e0dd36ca8d6c18 (diff)
Created unit test for signals.
Test for types inside of namespace Test for types defined by typedef. Reviewer: Marcelo Lira <marcelo.lira@openbossa.org> Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--tests/pysidetest/CMakeLists.txt4
-rw-r--r--tests/pysidetest/signalandnamespace_test.py92
-rw-r--r--tests/pysidetest/testobject.h51
-rw-r--r--tests/pysidetest/typesystem_pysidetest.xml26
4 files changed, 173 insertions, 0 deletions
diff --git a/tests/pysidetest/CMakeLists.txt b/tests/pysidetest/CMakeLists.txt
index 03d55a5f..964d70d0 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 00000000..ae93cf38
--- /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 8dcb4c06..ca662d70 100644
--- a/tests/pysidetest/testobject.h
+++ b/tests/pysidetest/testobject.h
@@ -2,6 +2,7 @@
#define TESTOBJECT_H
#include <QObject>
+#include <QMetaType>
#ifdef pysidetest_EXPORTS
#define PYSIDE_EXPORTS 1
#endif
@@ -34,5 +35,55 @@ private:
QList<QObject*> 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 9cc41303..52396203 100644
--- a/tests/pysidetest/typesystem_pysidetest.xml
+++ b/tests/pysidetest/typesystem_pysidetest.xml
@@ -3,6 +3,32 @@
<load-typesystem name="typesystem_core.xml" generate="no" />
<load-typesystem name="typesystem_gui.xml" generate="no"/>
<object-type name="TestObject" />
+
+ <inject-code>
+ qRegisterMetaType&lt;PySideInt>("PySideInt");
+ qRegisterMetaType&lt;PySideCPP2::PySideLong>("PySideLong");
+ </inject-code>
+
+ <namespace-type name="PySideCPP">
+ <object-type name="TestObjectWithNamespace" >
+ <modify-function signature="emitSignal(PySideCPP::TestObjectWithNamespace*)">
+ <modify-argument index="1">
+ <replace-type modified-type="TestObjectWithNamespace*"/>
+ </modify-argument>
+ </modify-function>
+ </object-type>
+ </namespace-type>
+
+ <namespace-type name="PySideCPP2" generate="no">
+ <object-type name="TestObjectWithoutNamespace" >
+ <modify-function signature="emitSignalWithNamespace(PySideCPP2::TestObjectWithoutNamespace*)">
+ <modify-argument index="1">
+ <replace-type modified-type="PySideCPP2::TestObjectWithoutNamespace*"/>
+ </modify-argument>
+ </modify-function>
+ </object-type>
+ </namespace-type>
+
<object-type name="TestView" >
<modify-function signature="TestView(QAbstractListModel*,QObject*)">
<modify-argument index="1">