diff options
Diffstat (limited to 'tests/minimalbinding')
-rw-r--r-- | tests/minimalbinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/minimalbinding/global.h | 1 | ||||
-rw-r--r-- | tests/minimalbinding/minbool_conversions.h | 10 | ||||
-rw-r--r-- | tests/minimalbinding/minbool_test.py | 59 | ||||
-rw-r--r-- | tests/minimalbinding/typesystem_minimal.xml | 7 |
5 files changed, 78 insertions, 0 deletions
diff --git a/tests/minimalbinding/CMakeLists.txt b/tests/minimalbinding/CMakeLists.txt index 2a78ae7a3..af93dd365 100644 --- a/tests/minimalbinding/CMakeLists.txt +++ b/tests/minimalbinding/CMakeLists.txt @@ -8,6 +8,7 @@ set(minimal_SRC ${CMAKE_CURRENT_BINARY_DIR}/minimal/minimal_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/obj_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/minimal/val_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/minimal/minbooluser_wrapper.cpp ) configure_file("${CMAKE_CURRENT_SOURCE_DIR}/minimal-binding.txt.in" diff --git a/tests/minimalbinding/global.h b/tests/minimalbinding/global.h index 112023202..c27c686b7 100644 --- a/tests/minimalbinding/global.h +++ b/tests/minimalbinding/global.h @@ -1,2 +1,3 @@ #include "obj.h" #include "val.h" +#include "minbool.h" diff --git a/tests/minimalbinding/minbool_conversions.h b/tests/minimalbinding/minbool_conversions.h new file mode 100644 index 000000000..f343a4711 --- /dev/null +++ b/tests/minimalbinding/minbool_conversions.h @@ -0,0 +1,10 @@ +namespace Shiboken { +template <> +struct Converter<MinBool> : public ValueTypeConverter<MinBool> +{ + static bool isConvertible(PyObject* pyObj) { return PyBool_Check(pyObj); } + using ValueTypeConverter<MinBool>::toPython; + static PyObject* toPython(const MinBool& holder) { return PyBool_FromLong(holder.value()); } + static MinBool toCpp(PyObject* pyobj) { return MinBool(pyobj == Py_True); } +}; +} diff --git a/tests/minimalbinding/minbool_test.py b/tests/minimalbinding/minbool_test.py new file mode 100644 index 000000000..0b183d7aa --- /dev/null +++ b/tests/minimalbinding/minbool_test.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# +# Contact: PySide team <contact@pyside.org> +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public License +# version 2.1 as published by the Free Software Foundation. Please +# review the following information to ensure the GNU Lesser General +# Public License version 2.1 requirements will be met: +# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +# # +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +# 02110-1301 USA + +import unittest + +from minimal import MinBoolUser + +class DerivedMinBoolUser (MinBoolUser): + def returnMyselfVirtual(self): + return MinBoolUser() + +class MinBoolTest(unittest.TestCase): + + def testMinBoolUser(self): + mbuTrue = MinBoolUser() + mbuFalse = MinBoolUser() + mbuTrue.setMinBool(True) + self.assertEqual(mbuFalse.minBool(), False) + self.assertEqual(mbuTrue.minBool(), True) + self.assertEqual(mbuTrue.callInvertedMinBool(), False) + + self.assertEqual(mbuTrue.minBool() == True, True) + self.assertEqual(False == mbuFalse.minBool(), True) + self.assertEqual(mbuTrue.minBool() == mbuFalse.minBool(), False) + + self.assertEqual(mbuFalse.minBool() != True, True) + self.assertEqual(True != mbuFalse.minBool(), True) + self.assertEqual(mbuTrue.minBool() != mbuFalse.minBool(), True) + + def testVirtuals(self): + dmbu = DerivedMinBoolUser() + self.assertEqual(dmbu.invertedMinBool(), True) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/minimalbinding/typesystem_minimal.xml b/tests/minimalbinding/typesystem_minimal.xml index da9d9b12a..c3e681177 100644 --- a/tests/minimalbinding/typesystem_minimal.xml +++ b/tests/minimalbinding/typesystem_minimal.xml @@ -2,7 +2,14 @@ <typesystem package="minimal"> <primitive-type name="bool"/> <primitive-type name="int"/> + + <primitive-type name="MinBool" target-lang-api-name="PyBool"> + <conversion-rule file="minbool_conversions.h"/> + <include file-name="minbool.h" location="global"/> + </primitive-type> + <object-type name="Obj"/> <value-type name="Val"/> + <value-type name="MinBoolUser"/> </typesystem> |