diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-08-04 12:18:02 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:08 -0300 |
commit | eda3572089e71e0c5065831438c4999486838547 (patch) | |
tree | 97439d75bbadd025b57125c209a8b3821e2d49f4 /tests/samplebinding/bytearray_conversions.h | |
parent | 19713b8e3f7e9ba04653b3b4beff5cc26408af44 (diff) |
Added tests for custom conversion and buffer protocol.
It it inspired by some of PySide's QByteArray tests.
Diffstat (limited to 'tests/samplebinding/bytearray_conversions.h')
-rw-r--r-- | tests/samplebinding/bytearray_conversions.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/samplebinding/bytearray_conversions.h b/tests/samplebinding/bytearray_conversions.h new file mode 100644 index 000000000..79a070d7b --- /dev/null +++ b/tests/samplebinding/bytearray_conversions.h @@ -0,0 +1,28 @@ +namespace Shiboken { +inline bool Converter<ByteArray>::checkType(PyObject* pyObj) +{ + return ValueTypeConverter<ByteArray>::checkType(pyObj); +} +inline bool Converter<ByteArray>::isConvertible(PyObject* pyObj) +{ + if (ValueTypeConverter<ByteArray>::isConvertible(pyObj)) + return true; + SbkObjectType* shiboType = reinterpret_cast<SbkObjectType*>(SbkType<ByteArray>()); + return Shiboken::Converter<const char*>::checkType(pyObj) + || (ObjectType::isExternalConvertible(shiboType, pyObj)); +} +inline ByteArray Converter<ByteArray>::toCpp(PyObject* pyObj) +{ + if (pyObj == Py_None) + return ByteArray(); + else if (PyObject_TypeCheck(pyObj, SbkType<ByteArray>())) + return *Converter<ByteArray*>::toCpp(pyObj); + else if (PyString_Check(pyObj)) + return ByteArray(PyString_AS_STRING(pyObj), PyString_GET_SIZE(pyObj)); + return ValueTypeConverter<ByteArray>::toCpp(pyObj); +} +inline PyObject* Converter<ByteArray>::toPython(const ByteArray& cppObj) +{ + return ValueTypeConverter<ByteArray>::toPython(cppObj); +} +} |