aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-05 13:55:56 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:08 -0300
commit50aef1dd4836b5019c60d31c54501ebcd37f72cd (patch)
tree3e9f41435c3ee0da5fdb5ee32b5b9900ad5a5259 /tests
parent08f29f0d8f456eb1f994b05c21fd04468c95329c (diff)
Improved guessCPythonCheckFunction method to produce an AbstractMetaType for known types.
This is in opposition of simply returning a string with a custom type check. The details are in the docstring in ShibokenGenerator header. Also added a new modification test and refactored here and there in the sample binding type system.
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/modifications.cpp7
-rw-r--r--tests/libsample/modifications.h3
-rw-r--r--tests/samplebinding/modifications_test.py7
-rw-r--r--tests/samplebinding/typesystem_sample.xml27
4 files changed, 37 insertions, 7 deletions
diff --git a/tests/libsample/modifications.cpp b/tests/libsample/modifications.cpp
index 00a0cdf0c..72c3f40ed 100644
--- a/tests/libsample/modifications.cpp
+++ b/tests/libsample/modifications.cpp
@@ -96,3 +96,10 @@ Modifications::sumPointArray(int arraySize, const Point pointArray[])
point = point + pointArray[i];
return point;
}
+
+int
+Modifications::getSize(const void* data, int size)
+{
+ (void)data;
+ return size;
+}
diff --git a/tests/libsample/modifications.h b/tests/libsample/modifications.h
index 5f7b58995..1b6fb8240 100644
--- a/tests/libsample/modifications.h
+++ b/tests/libsample/modifications.h
@@ -95,6 +95,9 @@ public:
virtual const char* className();
Point sumPointArray(int arraySize, const Point pointArray[]);
+
+ // Replace 'const void*' by 'ByteArray&'.
+ int getSize(const void* data, int size);
};
class LIBSAMPLE_API AbstractModifications : public Modifications
diff --git a/tests/samplebinding/modifications_test.py b/tests/samplebinding/modifications_test.py
index b23165ff6..b37d74635 100644
--- a/tests/samplebinding/modifications_test.py
+++ b/tests/samplebinding/modifications_test.py
@@ -28,7 +28,7 @@
import unittest
-from sample import Modifications, Point
+from sample import Modifications, Point, ByteArray
class ExtModifications(Modifications):
def __init__(self):
@@ -138,5 +138,10 @@ class ModificationsTest(unittest.TestCase):
summedPoint = Point(1, 1) + Point(2, 2)
self.assertEqual(self.mods.sumPointArray(points), summedPoint)
+ def testTypeSystemVariableReplacementInFunctionModification(self):
+ ba = ByteArray('12345')
+ self.assertEqual(self.mods.getSize(ba), len(ba))
+ self.assertEqual(self.mods.getSize(ba, 20), 20)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index be0f8fe88..27c265f3f 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -697,6 +697,21 @@
</conversion-rule>
</modify-argument>
</modify-function>
+ <modify-function signature="getSize(const void*,int)">
+ <modify-argument index="1">
+ <replace-type modified-type="ByteArray&amp;"/>
+ </modify-argument>
+ <modify-argument index="2">
+ <replace-default-expression with="-1"/>
+ </modify-argument>
+ <inject-code class="target" position="beginning">
+ int size = (%2 &lt; 0) ? %1.size() : %2;
+ %BEGIN_ALLOW_THREADS
+ %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME((const void*) %1.data(), size);
+ %END_ALLOW_THREADS
+ %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0);
+ </inject-code>
+ </modify-function>
</object-type>
<object-type name="AbstractModifications">
@@ -833,9 +848,9 @@
</modify-function>
<template name="fix_int*,int*,int*,int*">
int a0, a1, a2, a3;
- PyThreadState* _save = PyEval_SaveThread(); // Py_BEGIN_ALLOW_THREADS
+ %BEGIN_ALLOW_THREADS
%CPPSELF->::%TYPE::%FUNCTION_NAME(&amp;a0, &amp;a1, &amp;a2, &amp;a3);
- PyEval_RestoreThread(_save); // Py_END_ALLOW_THREADS
+ %END_ALLOW_THREADS
%PYARG_0 = Shiboken::makeTuple(a0, a1, a2, a3);
</template>
<template name="fix_native_return_int*,int*,int*,int*">
@@ -1373,10 +1388,10 @@
<insert-template name="buffer_argument">
<replace from="%out" to="argOut" />
</insert-template>
- PyThreadState* _save = PyEval_SaveThread();
- %RETURN_TYPE cppResult = %CPPSELF.%FUNCTION_NAME(argOut, %2);
- PyEval_RestoreThread(_save);
- %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](cppResult);
+ %BEGIN_ALLOW_THREADS
+ %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(argOut, %2);
+ %END_ALLOW_THREADS
+ %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0);
</inject-code>
</add-function>
</object-type>