aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-10-28 17:11:15 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:18:32 -0300
commit180d72b79e530810b0f6d9c63dfa02c4fba383e8 (patch)
tree0379365072271517a3d76ffa7c99c6dcee50b14b /tests/samplebinding
parent670cde3115f372b70768f14cf19d236f0d019f99 (diff)
Fixes code generation for typedefs of C++ primitive types.
Added unit tests that query for the Python types using their names.
Diffstat (limited to 'tests/samplebinding')
-rw-r--r--tests/samplebinding/typeconverters_test.py69
-rw-r--r--tests/samplebinding/typesystem_sample.xml9
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/samplebinding/typeconverters_test.py b/tests/samplebinding/typeconverters_test.py
new file mode 100644
index 000000000..e08bbd5f3
--- /dev/null
+++ b/tests/samplebinding/typeconverters_test.py
@@ -0,0 +1,69 @@
+#!/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
+
+'''Tests various usages of the type converters.'''
+
+import unittest
+import sample
+
+class GetPythonTypeByNameTest(unittest.TestCase):
+
+ '''Uses an added function with inject code that uses the libshiboken
+ function "Shiboken::Conversions::getPythonTypeObject(typeName)".'''
+
+ def testGetObjectType(self):
+ pyType1 = sample.getPythonType('ObjectType')
+ self.assertEqual(pyType1, sample.ObjectType)
+ pyType2 = sample.getPythonType('ObjectType*')
+ self.assertEqual(pyType2, sample.ObjectType)
+ self.assertEqual(pyType1, pyType2)
+
+ def testGetValueType(self):
+ pyType1 = sample.getPythonType('Point')
+ self.assertEqual(pyType1, sample.Point)
+ pyType2 = sample.getPythonType('Point*')
+ self.assertEqual(pyType2, sample.Point)
+ self.assertEqual(pyType1, pyType2)
+
+ def testGetUsersPrimitiveType(self):
+ pyType = sample.getPythonType('OddBool')
+ self.assertEqual(pyType, bool)
+
+ def testGetUsersPrimitiveTypeWithoutTargetLangApiName(self):
+ '''If the primitive type attribute "target-lang-api-name" is not set
+ there'll be no Python type associated with the C++ type.'''
+ pyType = sample.getPythonType('PStr')
+ self.assertEqual(pyType, None)
+
+ def testPrimitiveTypeAndTypedef(self):
+ pyType = sample.getPythonType('double')
+ self.assertEqual(pyType, float)
+ pyTypedef = sample.getPythonType('real')
+ self.assertEqual(pyType, pyTypedef)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index f823a1725..5b3c9777d 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -249,6 +249,15 @@
</inject-code>
</add-function>
+ <add-function signature="getPythonType(const char*)" return-type="PyObject">
+ <inject-code class="target" position="beginning">
+ %PYARG_0 = (PyObject*) Shiboken::Conversions::getPythonTypeObject(%1);
+ if (!%PYARG_0)
+ %PYARG_0 = Py_None;
+ Py_INCREF(%PYARG_0);
+ </inject-code>
+ </add-function>
+
<container-type name="std::pair" type="pair">
<include file-name="utility" location="global"/>
<conversion-rule file="pair_conversions.h">