aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-03 14:35:35 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:08 -0300
commitf2e0002c8ebc7a68fca731bfbde1d32415f5a240 (patch)
tree54bd01c50ada4bb89e71f24a2dedb7cb7c91dc64 /tests
parent699f6db172df37631dec7a884a25df8cc62343b8 (diff)
Fixed type system variable replacement for arguments removed with conversion rule.
Also added an array argument modification test, and moved AutoArrayPointer from libpyside to libshiboken. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/modifications.cpp8
-rw-r--r--tests/libsample/modifications.h2
-rw-r--r--tests/samplebinding/modifications_test.py15
-rw-r--r--tests/samplebinding/typesystem_sample.xml61
4 files changed, 49 insertions, 37 deletions
diff --git a/tests/libsample/modifications.cpp b/tests/libsample/modifications.cpp
index 8d353981..00a0cdf0 100644
--- a/tests/libsample/modifications.cpp
+++ b/tests/libsample/modifications.cpp
@@ -88,3 +88,11 @@ Modifications::className()
return "Modifications";
}
+Point
+Modifications::sumPointArray(int arraySize, const Point pointArray[])
+{
+ Point point;
+ for (int i = 0; i < arraySize; ++i)
+ point = point + pointArray[i];
+ return point;
+}
diff --git a/tests/libsample/modifications.h b/tests/libsample/modifications.h
index 639d0921..5f7b5899 100644
--- a/tests/libsample/modifications.h
+++ b/tests/libsample/modifications.h
@@ -93,6 +93,8 @@ public:
// change the name of this virtual method
virtual const char* className();
+
+ Point sumPointArray(int arraySize, const Point pointArray[]);
};
class LIBSAMPLE_API AbstractModifications : public Modifications
diff --git a/tests/samplebinding/modifications_test.py b/tests/samplebinding/modifications_test.py
index 9a33c25e..b23165ff 100644
--- a/tests/samplebinding/modifications_test.py
+++ b/tests/samplebinding/modifications_test.py
@@ -24,9 +24,8 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
-'''Test cases for method modifications performed as described on typesystem. '''
+'''Test cases for method modifications performed as described on type system. '''
-import sys
import unittest
from sample import Modifications, Point
@@ -40,7 +39,7 @@ class ExtModifications(Modifications):
class ModificationsTest(unittest.TestCase):
- '''Test cases for method modifications performed as described on typesystem. '''
+ '''Test cases for method modifications performed as described on type system. '''
def setUp(self):
self.mods = Modifications()
@@ -105,7 +104,7 @@ class ModificationsTest(unittest.TestCase):
self.assertEqual(self.mods.timesTen(), 100)
def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates1(self):
- '''Test modifications to method signature and return value using typesystem templates (case 1).'''
+ '''Test modifications to method signature and return value using type system templates (case 1).'''
result, ok = self.mods.pointToPair(Point(2, 5))
self.assertEqual(type(ok), bool)
self.assertEqual(type(result), tuple)
@@ -116,7 +115,7 @@ class ModificationsTest(unittest.TestCase):
self.assertEqual(result[1], 5.0)
def testArgumentRemovalAndReturnTypeModificationWithTypesystemTemplates2(self):
- '''Test modifications to method signature and return value using typesystem templates (case 2).'''
+ '''Test modifications to method signature and return value using type system templates (case 2).'''
result, ok = self.mods.multiplyPointCoordsPlusValue(Point(2, 5), 4.1)
self.assertEqual(type(ok), bool)
self.assertEqual(type(result), float)
@@ -134,6 +133,10 @@ class ModificationsTest(unittest.TestCase):
self.assertRaises(TypeError, self.mods.overloaded, 1, True, Point(2, 3), Point(4, 5))
self.assertEqual(self.mods.over(1, True, Point(2, 3), Point(4, 5)), Modifications.Overloaded_ibPP)
+ def testPointArrayModification(self):
+ points = (Point(1, 1), Point(2, 2))
+ summedPoint = Point(1, 1) + Point(2, 2)
+ self.assertEqual(self.mods.sumPointArray(points), summedPoint)
+
if __name__ == '__main__':
unittest.main()
-
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 5184526e..9624ba27 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -664,6 +664,23 @@
<!-- change the name of this virtual method -->
<modify-function signature="className()" rename="name"/>
+
+ <modify-function signature="sumPointArray(int, const Point*)">
+ <modify-argument index="1">
+ <remove-argument/>
+ <conversion-rule class="native">
+ int %out = PySequence_Size(%PYARG_1);
+ </conversion-rule>
+ </modify-argument>
+ <modify-argument index="2">
+ <replace-type modified-type="PySequence" />
+ <conversion-rule class="native">
+ Shiboken::AutoArrayPointer&lt;Point&gt; %out(%1);
+ for (int i = 0; i &lt; %1; ++i)
+ %out[i] = %CONVERTTOCPP[Point](PySequence_Fast_GET_ITEM(%PYARG_1, i));
+ </conversion-rule>
+ </modify-argument>
+ </modify-function>
</object-type>
<object-type name="AbstractModifications">
@@ -936,22 +953,8 @@
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](retval);
}
</inject-code>
-
</modify-function>
- <inject-code class="native" position="beginning">
- // simple class to avoid mem leak inside conversion rule used in arrayMethod
- template&lt;typename T>
- struct ArrayDeleter {
- ArrayDeleter(T* ptr) : m_ptr(ptr) {}
- ~ArrayDeleter() { delete[] m_ptr; }
- operator T*() { return m_ptr; }
- private:
- T* m_ptr;
- ArrayDeleter(const ArrayDeleter&amp;);
- ArrayDeleter&amp; operator=(ArrayDeleter&amp;);
- };
- </inject-code>
<modify-function signature="arrayMethod(int, int*) const">
<modify-argument index="1">
<remove-argument/>
@@ -959,24 +962,20 @@
int %out = PySequence_Size(%PYARG_1);
</conversion-rule>
</modify-argument>
-
<modify-argument index="2">
- <replace-type modified-type="PySequence"/>
-
- <conversion-rule class="native">
+ <replace-type modified-type="PySequence"/>
+ <conversion-rule class="native">
int numItems = PySequence_Size(%PYARG_1);
- ArrayDeleter&lt;int> %out(new int[numItems]);
- for (int i=0; i &lt; numItems; i++)
- %out[i] = %CONVERTTOCPP[int](PySequence_GetItem(%PYARG_1, i));
- </conversion-rule>
-
- <conversion-rule class="target">
- PyObject *%out = PyList_New(count);
- for (int i=0; i &lt; count; i++)
+ Shiboken::AutoArrayPointer&lt;int&gt; %out(numItems);
+ for (int i = 0; i &lt; numItems; ++i)
+ %out[i] = %CONVERTTOCPP[int](PySequence_Fast_GET_ITEM(%PYARG_1, i));
+ </conversion-rule>
+ <conversion-rule class="target">
+ PyObject* %out = PyList_New(count);
+ for (int i = 0; i &lt; count; ++i)
PyList_SET_ITEM(%out, i, %CONVERTTOPYTHON[int](%in[i]));
- </conversion-rule>
- </modify-argument>
-
+ </conversion-rule>
+ </modify-argument>
</modify-function>
<modify-function signature="callArrayMethod(int, int*) const">
@@ -1356,10 +1355,10 @@
<add-function signature="strBufferOverloads(Str&amp;,int)" return-type="Overload::FunctionEnum">
<inject-code class="target" position="beginning">
<insert-template name="buffer_argument">
- <replace from="%out" to="%1_out" />
+ <replace from="%out" to="argOut" />
</insert-template>
PyThreadState* _save = PyEval_SaveThread();
- %RETURN_TYPE cppResult = %CPPSELF.%FUNCTION_NAME(%1_out, %2);
+ %RETURN_TYPE cppResult = %CPPSELF.%FUNCTION_NAME(argOut, %2);
PyEval_RestoreThread(_save);
%PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](cppResult);
</inject-code>