aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-18 17:00:32 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:12 -0300
commite5fb8ee50dbcb0eab68260efe95c985ddc979e00 (patch)
tree73d8cb3b7b5a7e6a048dfbd9c058249bad19e860 /tests
parentb7169ca7fe92c5874076ff47f9b4ec7954acc480 (diff)
Fixed generator to consider conversion rules for the return type of wrapper methods.
Tests were added. Reviewed by Hugo Parente <hugo.lima@openbossa.org> Reviewed by Lauro Moura <lauro.neto@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/modifications.cpp14
-rw-r--r--tests/libsample/modifications.h4
-rw-r--r--tests/samplebinding/modifications_test.py57
-rw-r--r--tests/samplebinding/typesystem_sample.xml43
4 files changed, 118 insertions, 0 deletions
diff --git a/tests/libsample/modifications.cpp b/tests/libsample/modifications.cpp
index d809e823..95880d22 100644
--- a/tests/libsample/modifications.cpp
+++ b/tests/libsample/modifications.cpp
@@ -122,6 +122,20 @@ Modifications::sumPointCoordinates(const Point* point)
return point->x() + point->y();
}
+double
+Modifications::differenceOfPointCoordinates(const Point* pt, bool* ok)
+{
+ if (!pt) {
+ *ok = false;
+ return 0.0;
+ }
+ *ok = true;
+ double result = pt->x() - pt->y();
+ if (result < 0)
+ result = result * -1.0;
+ return result;
+}
+
bool
Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType** object)
{
diff --git a/tests/libsample/modifications.h b/tests/libsample/modifications.h
index f1726147..7d5c9123 100644
--- a/tests/libsample/modifications.h
+++ b/tests/libsample/modifications.h
@@ -106,6 +106,10 @@ public:
// the test implementation must expect point never to be null.
int sumPointCoordinates(const Point* point);
+ // Modify the return value of a virtual method.
+ virtual double differenceOfPointCoordinates(const Point* pt, bool* ok);
+ double callDifferenceOfPointCoordinates(const Point* pt, bool* ok) { return differenceOfPointCoordinates(pt, ok); }
+
// Sets an ObjectType in the argument and returns true.
bool nonConversionRuleForArgumentWithDefaultValue(ObjectType** object = 0);
ObjectType* getObject() const { return m_object; }
diff --git a/tests/samplebinding/modifications_test.py b/tests/samplebinding/modifications_test.py
index bc7b38df..a18bd7a1 100644
--- a/tests/samplebinding/modifications_test.py
+++ b/tests/samplebinding/modifications_test.py
@@ -33,10 +33,16 @@ from sample import Modifications, Point, ByteArray
class ExtModifications(Modifications):
def __init__(self):
Modifications.__init__(self)
+ self.multiplier = 3.0
+ self.increment = 10.0
def name(self):
return 'ExtModifications'
+ def differenceOfPointCoordinates(self, point):
+ ok, res = Modifications.differenceOfPointCoordinates(self, point)
+ return ok, res * self.multiplier + self.increment
+
class ModificationsTest(unittest.TestCase):
'''Test cases for method modifications performed as described on type system. '''
@@ -158,5 +164,56 @@ class ModificationsTest(unittest.TestCase):
self.assertTrue(Modifications.invertBoolean(False))
self.assertFalse(Modifications.invertBoolean(True))
+ def testConversionRuleForReturnType(self):
+ x, y = 11, 2
+ diff = float(abs(x - y))
+ point = Point(x, y)
+
+ ok, res = self.mods.differenceOfPointCoordinates(point)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, diff)
+
+ ok, res = self.mods.callDifferenceOfPointCoordinates(point)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, diff)
+
+ ok, res = self.mods.differenceOfPointCoordinates(None)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, 0.0)
+
+ ok, res = self.mods.callDifferenceOfPointCoordinates(None)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, 0.0)
+
+ def testConversionRuleForReturnTypeOnExtendedClass(self):
+ x, y = 11, 2
+ diff = float(abs(x - y))
+ point = Point(x, y)
+ em = ExtModifications()
+
+ ok, res = em.differenceOfPointCoordinates(point)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, diff * em.multiplier + em.increment)
+
+ ok, res = em.callDifferenceOfPointCoordinates(point)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, diff * em.multiplier + em.increment)
+
+ ok, res = em.differenceOfPointCoordinates(None)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, em.increment)
+
+ ok, res = em.callDifferenceOfPointCoordinates(None)
+ self.assertTrue(isinstance(ok, bool))
+ self.assertTrue(isinstance(res, float))
+ self.assertEqual(res, em.increment)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 75d222b7..2fef355f 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -731,6 +731,49 @@
<no-null-pointer/>
</modify-argument>
</modify-function>
+ <template name="differenceOfPointCoordinates_arg2">
+ bool _status;
+ bool* %2 = &amp;_status;
+ </template>
+ <template name="differenceOfPointCoordinates_returnTarget">
+ %PYARG_0 = PyTuple_New(2);
+ PyTuple_SET_ITEM(%PYARG_0, 0, %CONVERTTOPYTHON[bool](*%2));
+ PyTuple_SET_ITEM(%PYARG_0, 1, %CONVERTTOPYTHON[%RETURN_TYPE](%0));
+ </template>
+ <modify-function signature="differenceOfPointCoordinates(const Point*, bool*)">
+ <modify-argument index="2">
+ <remove-argument/>
+ <conversion-rule class="native">
+ <insert-template name="differenceOfPointCoordinates_arg2"/>
+ </conversion-rule>
+ </modify-argument>
+ <modify-argument index="return">
+ <replace-type modified-type="PySequence"/>
+ <conversion-rule class="native">
+ Shiboken::AutoDecRef _py_ok_(PySequence_GetItem(%PYARG_0, 0));
+ Shiboken::AutoDecRef _py_ret_(PySequence_GetItem(%PYARG_0, 1));
+ *%2 = %CONVERTTOCPP[bool](_py_ok_);
+ %RETURN_TYPE %out = %CONVERTTOCPP[%RETURN_TYPE](_py_ret_);
+ </conversion-rule>
+ <conversion-rule class="target">
+ <insert-template name="differenceOfPointCoordinates_returnTarget"/>
+ </conversion-rule>
+ </modify-argument>
+ </modify-function>
+ <modify-function signature="callDifferenceOfPointCoordinates(const Point*, bool*)">
+ <modify-argument index="2">
+ <remove-argument/>
+ <conversion-rule class="native">
+ <insert-template name="differenceOfPointCoordinates_arg2"/>
+ </conversion-rule>
+ </modify-argument>
+ <modify-argument index="return">
+ <replace-type modified-type="PySequence"/>
+ <conversion-rule class="target">
+ <insert-template name="differenceOfPointCoordinates_returnTarget"/>
+ </conversion-rule>
+ </modify-argument>
+ </modify-function>
<modify-function signature="nonConversionRuleForArgumentWithDefaultValue(ObjectType**)">
<modify-argument index="1">
<remove-argument/>