diff options
Diffstat (limited to 'tests/samplebinding')
-rw-r--r-- | tests/samplebinding/null_conversions.h | 32 | ||||
-rw-r--r-- | tests/samplebinding/objecttype_test.py | 7 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 9 |
3 files changed, 48 insertions, 0 deletions
diff --git a/tests/samplebinding/null_conversions.h b/tests/samplebinding/null_conversions.h new file mode 100644 index 000000000..cbe159f85 --- /dev/null +++ b/tests/samplebinding/null_conversions.h @@ -0,0 +1,32 @@ +namespace Shiboken { +template<> +struct Converter<Null> +{ + static inline bool checkType(PyObject* pyObj) + { + return false; + } + + static inline bool isConvertible(PyObject* pyObj) + { + if (pyObj == 0 || pyObj == Py_None) + return true; + return false; + } + + static inline PyObject* toPython(void* cppobj) + { + Py_RETURN_NONE; + } + + static inline PyObject* toPython(const Null& cpx) + { + Py_RETURN_NONE; + } + + static inline Null toCpp(PyObject* pyobj) + { + return Null(pyobj == 0); + } +}; +} diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py index 958df1d59..2a0dbbdb8 100644 --- a/tests/samplebinding/objecttype_test.py +++ b/tests/samplebinding/objecttype_test.py @@ -55,6 +55,13 @@ class ObjectTypeTest(unittest.TestCase): o.setObjectName('object name') self.assertEqual(str(o.objectName()), 'object name') + def testNullOverload(self): + o = ObjectType() + o.setObject(None) + self.assertEqual(o.callId(), 0) + o.setNullObject(None) + self.assertEqual(o.callId(), 1) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 24b4ff875..b3e05d4ed 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -17,6 +17,11 @@ <include file-name="complex.h" location="global"/> </primitive-type> + <primitive-type name="Null"> + <conversion-rule file="null_conversions.h"/> + <include file-name="null.h" location="global"/> + </primitive-type> + <primitive-type name="OddBool" target-lang-api-name="PyBool"> <conversion-rule file="oddbool_conversions.h"/> <include file-name="oddbool.h" location="global"/> @@ -117,6 +122,9 @@ <value-type name="Derived::SomeInnerClass" /> <object-type name="ObjectType" hash-function="objectTypeHash"> + <!-- rename function to avoid Python signature conflit --> + <modify-function signature="setObject(const Null&)" rename="setNullObject" /> + <modify-function signature="event(Event*)"> <modify-argument index="1" invalidate-after-use="yes"/> </modify-function> @@ -199,6 +207,7 @@ </modify-function> </object-type> + <value-type name="Event"/> <value-type name="BlackBox"> |