diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-08-11 19:37:11 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:18:26 -0300 |
commit | 6b2b4f0cf9157e044965acba63fb6b5ee1e9cf15 (patch) | |
tree | bc96a4a47a6c804921c804993dc0aaf53e9233b0 /tests/samplebinding | |
parent | b8bd47404fd3860bdb282750a1e5919921ca80df (diff) |
New converters for user added primitive types.
Win32 fix for zero length type converter array.
Diffstat (limited to 'tests/samplebinding')
-rw-r--r-- | tests/samplebinding/oddbool_test.py | 6 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 76 |
2 files changed, 74 insertions, 8 deletions
diff --git a/tests/samplebinding/oddbool_test.py b/tests/samplebinding/oddbool_test.py index 43727d65b..12b7a5a49 100644 --- a/tests/samplebinding/oddbool_test.py +++ b/tests/samplebinding/oddbool_test.py @@ -62,6 +62,12 @@ class OddBoolTest(unittest.TestCase): self.assertTrue(obu.oddBool()) obu = OddBoolUser(False) self.assertFalse(obu.oddBool()) + cpx = complex(1.0, 0.0) + obu = OddBoolUser(cpx) + self.assertTrue(obu.oddBool()) + cpx = complex(0.0, 0.0) + obu = OddBoolUser(cpx) + self.assertFalse(obu.oddBool()) if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 122456184..ec4ace7d7 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -19,25 +19,85 @@ <primitive-type name="std::string"/> <primitive-type name="std::size_t" target-lang-api-name="PyLong"> + <conversion-rule> + <native-to-target> + return PyLong_FromSize_t(%in); + </native-to-target> + <target-to-native> + <add-conversion type="PyLong"> + %out = %OUTTYPE(PyLong_AsSsize_t(%in)); + </add-conversion> + </target-to-native> + </conversion-rule> </primitive-type> + <primitive-type name="Complex" target-lang-api-name="PyComplex"> - <conversion-rule file="complex_conversions.h"/> <include file-name="complex.h" location="global"/> + <conversion-rule file="complex_conversions.h"> + <native-to-target> + return PyComplex_FromDoubles(%in.real(), %in.imag()); + </native-to-target> + <target-to-native> + <!-- The 'check' attribute can be derived from the 'type' attribute, + it is defined here to test the CHECKTYPE type system variable. --> + <add-conversion type="PyComplex" check="%CHECKTYPE[Complex](%in)"> + double real = PyComplex_RealAsDouble(%in); + double imag = PyComplex_ImagAsDouble(%in); + %out = %OUTTYPE(real, imag); + </add-conversion> + </target-to-native> + </conversion-rule> </primitive-type> <primitive-type name="Null"> - <conversion-rule file="null_conversions.h"/> <include file-name="null.h" location="global"/> + <conversion-rule file="null_conversions.h"> + <native-to-target> + SBK_UNUSED(%in); + Py_RETURN_NONE; + </native-to-target> + <target-to-native> + <add-conversion type="PyObject" check="%in == 0 || %in == Py_None"> + %out = %OUTTYPE(%in == 0); + </add-conversion> + </target-to-native> + </conversion-rule> </primitive-type> - <primitive-type name="HANDLE"> - <conversion-rule file="handle_conversions.h"/> + <primitive-type name="HANDLE" target-lang-api-name="PyComplex"> <include file-name="handle.h" location="local"/> + <conversion-rule file="handle_conversions.h"> + <native-to-target> + return PyCObject_FromVoidPtr(%in, 0); + </native-to-target> + <target-to-native> + <add-conversion type="PyCObject"> + %out = (%OUTTYPE)PyCObject_AsVoidPtr(%in); + </add-conversion> + </target-to-native> + </conversion-rule> </primitive-type> <primitive-type name="OddBool" target-lang-api-name="PyBool" default-constructor="OddBool(false)"> - <conversion-rule file="oddbool_conversions.h"/> <include file-name="oddbool.h" location="global"/> + <include file-name="complex.h" location="global"/> + <conversion-rule file="oddbool_conversions.h"> + <native-to-target> + return PyBool_FromLong(%in.value()); + </native-to-target> + <target-to-native> + <add-conversion type="PyBool"> + // Tests CONVERTTOCPP macro with C++ primitive type. + bool b = %CONVERTTOCPP[bool](%in); + %out = %OUTTYPE(b); + </add-conversion> + <add-conversion type="PyComplex"> + // Tests CONVERTTOCPP macro with user's primitive type. + Complex cpx = %CONVERTTOCPP[Complex](%in); + %out = %OUTTYPE(cpx.real() != 0.0 || cpx.imag() != 0.0); + </add-conversion> + </target-to-native> + </conversion-rule> </primitive-type> <container-type name="std::pair" type="pair"> @@ -1559,10 +1619,10 @@ <value-type name="ByteArray" hash-function="ByteArray::hash"> <conversion-rule file="bytearray_conversions.h"> <target-to-native> - <add-conversion type='Py_None' check='%in == Py_None'> + <add-conversion type="Py_None"> %out = %OUTTYPE(); </add-conversion> - <add-conversion type='PyString' check='PyString_Check(%in)'> + <add-conversion type="PyString"> %out = %OUTTYPE(PyString_AS_STRING(%in), PyString_GET_SIZE(%in)); </add-conversion> </target-to-native> @@ -1811,7 +1871,7 @@ </inject-code> <conversion-rule class="target" file="date_conversions.h"> <target-to-native> - <add-conversion type='PyDate' check='PyDate_ImportAndCheck(%in)'> + <add-conversion type="PyDate" check="PyDate_ImportAndCheck(%in)"> int day = PyDateTime_GET_DAY(%in); int month = PyDateTime_GET_MONTH(%in); int year = PyDateTime_GET_YEAR(%in); |