aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-09-02 18:49:49 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:18:27 -0300
commitf4800a705caacbbdada1074d5b5bfd1abf1316c3 (patch)
tree5c0cdb9e17869e87cc4a47d44ea9277a4c1a11dd /tests/samplebinding
parent7ae96ccd9b11f918b392accc7e5048c5c8905a0a (diff)
Added test for instantiated container type used as primitive-type.
Diffstat (limited to 'tests/samplebinding')
-rw-r--r--tests/samplebinding/pstrlist_test.py45
-rw-r--r--tests/samplebinding/typesystem_sample.xml60
2 files changed, 105 insertions, 0 deletions
diff --git a/tests/samplebinding/pstrlist_test.py b/tests/samplebinding/pstrlist_test.py
new file mode 100644
index 000000000..c78bb4af3
--- /dev/null
+++ b/tests/samplebinding/pstrlist_test.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Shiboken Python Bindings Generator project.
+#
+# Copyright (C) 2009 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
+import sample
+
+class PStrListTest(unittest.TestCase):
+
+ def testPStrList(self):
+ a = 'str0'
+ b = 'str1'
+ lst = sample.createPStrList(a, b)
+ self.assertEqual(lst, [a, b])
+
+ def testListOfPStr(self):
+ a = 'str0'
+ b = 'str1'
+ lst = sample.createListOfPStr(a, b)
+ self.assertEqual(lst, [a, b])
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index ba3a56eb6..ac865df69 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -100,6 +100,66 @@
</conversion-rule>
</primitive-type>
+ <primitive-type name="PStr">
+ <include file-name="str.h" location="global"/>
+ <conversion-rule>
+ <native-to-target>
+ return PyString_FromStringAndSize(%in.cstring(), %in.size());
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PyString">
+ const char* str = %CONVERTTOCPP[const char*](%in);
+ %out = %OUTTYPE(str);
+ </add-conversion>
+ <add-conversion type="Py_None">
+ %out = %OUTTYPE();
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
+ </primitive-type>
+
+ <primitive-type name="PStrList">
+ <include file-name="strlist.h" location="global"/>
+ <conversion-rule>
+ <native-to-target>
+ PyObject* %out = PyList_New((int) %in.size());
+ PStrList::const_iterator it = %in.begin();
+ for (int idx = 0; it != %in.end(); ++it, ++idx) {
+ PStr cppItem(*it);
+ PyList_SET_ITEM(%out, idx, %CONVERTTOPYTHON[PStr](cppItem));
+ }
+ return %out;
+ </native-to-target>
+ <target-to-native>
+ <add-conversion type="PySequence">
+ %OUTTYPE&amp; list = %out;
+ for (int i = 0; i &lt; PySequence_Fast_GET_SIZE(%in); i++) {
+ PyObject* pyItem = PySequence_Fast_GET_ITEM(%in, i);
+ PStr cppItem = %CONVERTTOCPP[PStr](pyItem);
+ list.push_back(cppItem);
+ }
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
+ </primitive-type>
+
+ <add-function signature="createPStrList(PStr, PStr)" return-type="PyObject">
+ <inject-code class="target">
+ PStrList %0;
+ %0.push_back(%1);
+ %0.push_back(%2);
+ %PYARG_0 = %CONVERTTOPYTHON[PStrList](%0);
+ </inject-code>
+ </add-function>
+ <add-function signature="createListOfPStr(PStr, PStr)" return-type="PyObject">
+ <inject-code class="target">
+ std::list&lt;PStr&gt; %0;
+ %0.push_back(%1);
+ %0.push_back(%2);
+ %PYARG_0 = %CONVERTTOPYTHON[std::list&lt;PStr&gt;](%0);
+ </inject-code>
+ </add-function>
+
<container-type name="std::pair" type="pair">
<include file-name="utility" location="global"/>
<conversion-rule file="pair_conversions.h">