aboutsummaryrefslogtreecommitdiffstats
path: root/tests/samplebinding
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-02-09 12:06:54 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-02-09 18:25:42 -0300
commit586cd6b6cf67e9c186d2c42d076cbf99f1836ba4 (patch)
treec21b9a884f4938f3a4e5708b05158c64cd76d662 /tests/samplebinding
parentdf7a5518466ce74ca3023b61ce1be21592f97252 (diff)
Adds tests for argument removal and type modification for virtual methods.
Reviewed by Lauro Moura <lauro.neto@openbossa.org>
Diffstat (limited to 'tests/samplebinding')
-rwxr-xr-xtests/samplebinding/injectcode_test.py21
-rw-r--r--tests/samplebinding/typesystem_sample.xml20
2 files changed, 40 insertions, 1 deletions
diff --git a/tests/samplebinding/injectcode_test.py b/tests/samplebinding/injectcode_test.py
index d328de16b..ffc8ff115 100755
--- a/tests/samplebinding/injectcode_test.py
+++ b/tests/samplebinding/injectcode_test.py
@@ -29,6 +29,13 @@
import unittest
from sample import InjectCode
+class MyInjectCode(InjectCode):
+ def __init__(self):
+ InjectCode.__init__(self)
+ self.multiplier = 2
+ def arrayMethod(self, values):
+ return self.multiplier * sum(values)
+
class InjectCodeTest(unittest.TestCase):
def testTypeNativeBeginning_TypeTargetBeginning(self):
@@ -68,5 +75,19 @@ class InjectCodeTest(unittest.TestCase):
result = ic.arrayMethod(values)
self.assertEqual(result, sum(values))
+ def testCallVirtualMethodWithArgumentRemovalAndArgumentTypeModification(self):
+ '''A virtual method has its first argument removed and the second modified.'''
+ ic = InjectCode()
+ values = (1, 2, 3, 4, 5)
+ result = ic.callArrayMethod(values)
+ self.assertEqual(result, sum(values))
+
+ def testCallReimplementedVirtualMethodWithArgumentRemovalAndArgumentTypeModification(self):
+ '''Calls a reimplemented virtual method that had its first argument removed and the second modified.'''
+ ic = MyInjectCode()
+ values = (1, 2, 3, 4, 5)
+ result = ic.callArrayMethod(values)
+ self.assertEqual(result, ic.multiplier * sum(values))
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index af48b085d..d6117a278 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -608,7 +608,25 @@
%PYARG_0 = %CONVERTTOPYTHON[int](%CPPSELF.%FUNCTION_NAME(numItems, cppItems));
</inject-code>
<inject-code class="native" position="beginning">
- // TODO
+ PyObject* __py_values__ = PyList_New(count);
+ for (int i = 0; i &lt; %1; i++)
+ PyList_SET_ITEM(__py_values__, i, %CONVERTTOPYTHON[int](%2[i]));
+ Shiboken::AutoDecRef %PYTHON_ARGUMENTS(Py_BuildValue("(O)", __py_values__));
+ </inject-code>
+ </modify-function>
+ <modify-function signature="callArrayMethod(int, int*) const">
+ <modify-argument index="1">
+ <remove-argument/>
+ </modify-argument>
+ <modify-argument index="2">
+ <replace-type modified-type="PySequence"/>
+ </modify-argument>
+ <inject-code class="target" position="beginning">
+ int numItems = PySequence_Size(%PYARG_1);
+ int cppItems[numItems];
+ for (int i = 0; i &lt; numItems; i++)
+ cppItems[i] = %CONVERTTOCPP[int](PySequence_GetItem(%PYARG_1, i));
+ %PYARG_0 = %CONVERTTOPYTHON[int](%CPPSELF.%FUNCTION_NAME(numItems, cppItems));
</inject-code>
</modify-function>