aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-10 00:59:19 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:10 -0300
commit9c6b541ceef3039e9e19a1d9a12223851a849cf6 (patch)
treef3bf84cc9b86205fa2f7d7d5951b1e2dff29fcdd /tests
parent711ee3d4169acca59b87df61b9ccb26d74a329b4 (diff)
Improved the generation of argument conversion in modified functions.
Added the SBK_UNUSED macro to libshiboken to prevent compilation warnings. An unit test was added. 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.cpp20
-rw-r--r--tests/libsample/modifications.h14
-rw-r--r--tests/samplebinding/modifications_test.py6
-rw-r--r--tests/samplebinding/typesystem_sample.xml15
4 files changed, 51 insertions, 4 deletions
diff --git a/tests/libsample/modifications.cpp b/tests/libsample/modifications.cpp
index 739ca5c7..d809e823 100644
--- a/tests/libsample/modifications.cpp
+++ b/tests/libsample/modifications.cpp
@@ -22,9 +22,21 @@
#include <iostream>
#include "modifications.h"
+#include "objecttype.h"
using namespace std;
+Modifications::Modifications()
+{
+ m_object = new ObjectType();
+ m_object->setObjectName("MyObject");
+}
+
+Modifications::~Modifications()
+{
+ delete m_object;
+}
+
std::pair<double, double>
Modifications::pointToPair(Point pt, bool* ok)
{
@@ -109,3 +121,11 @@ Modifications::sumPointCoordinates(const Point* point)
{
return point->x() + point->y();
}
+
+bool
+Modifications::nonConversionRuleForArgumentWithDefaultValue(ObjectType** object)
+{
+ if (object)
+ *object = m_object;
+ return true;
+}
diff --git a/tests/libsample/modifications.h b/tests/libsample/modifications.h
index c7a7748c..2acffa40 100644
--- a/tests/libsample/modifications.h
+++ b/tests/libsample/modifications.h
@@ -27,11 +27,13 @@
#include <utility>
#include "point.h"
+class ObjectType;
+
class LIBSAMPLE_API Modifications
{
public:
- Modifications() {}
- virtual ~Modifications() {}
+ Modifications();
+ virtual ~Modifications();
enum OverloadedModFunc {
OverloadedNone,
@@ -102,6 +104,13 @@ public:
// Mark the argument with a <no-null-pointer/> tag;
// the test implementation must expect point never to be null.
int sumPointCoordinates(const Point* point);
+
+ // Sets an ObjectType in the argument and returns true.
+ bool nonConversionRuleForArgumentWithDefaultValue(ObjectType** object = 0);
+ ObjectType* getObject() const { return m_object; }
+
+private:
+ ObjectType* m_object;
};
class LIBSAMPLE_API AbstractModifications : public Modifications
@@ -117,4 +126,3 @@ public:
};
#endif // MODIFICATIONS_H
-
diff --git a/tests/samplebinding/modifications_test.py b/tests/samplebinding/modifications_test.py
index 34480101..3cb502ce 100644
--- a/tests/samplebinding/modifications_test.py
+++ b/tests/samplebinding/modifications_test.py
@@ -148,5 +148,11 @@ class ModificationsTest(unittest.TestCase):
self.assertEqual(self.mods.sumPointCoordinates(point), 12 + 34)
self.assertRaises(TypeError, self.mods.sumPointCoordinates, None)
+ def testNonConversionRuleForArgumentWithDefaultValue(self):
+ status, obj = self.mods.nonConversionRuleForArgumentWithDefaultValue()
+ self.assert_(status)
+ self.assertEqual(obj, self.mods.getObject())
+ self.assertEqual(obj.objectName(), 'MyObject')
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index dc4faf35..4f1d5481 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -728,6 +728,19 @@
<no-null-pointer/>
</modify-argument>
</modify-function>
+ <modify-function signature="nonConversionRuleForArgumentWithDefaultValue(ObjectType**)">
+ <modify-argument index="1">
+ <remove-argument/>
+ </modify-argument>
+ <modify-argument index="return">
+ <replace-type modified-type="(status, object)"/>
+ </modify-argument>
+ <inject-code class="target" position="beginning">
+ ObjectType* tmpObject = 0;
+ %RETURN_TYPE %0 = %CPPSELF.%FUNCTION_NAME(&amp;tmpObject);
+ %PYARG_0 = Shiboken::makeTuple(%0, tmpObject);
+ </inject-code>
+ </modify-function>
</object-type>
<object-type name="AbstractModifications">
@@ -1761,4 +1774,4 @@
<!-- Do not fix this warning, the generator should be able to handle this situation for Object Types. -->
<suppress-warning text="Argument in position 1 of added function 'SampleNamespace::passReferenceToObjectType(ObjectType * arg__1)', has a type that is not a reference, while the argument in the corresponding position in C++ function 'SampleNamespace::passReferenceToObjectType(const ObjectType &amp; obj, int multiplier)' is a reference." />
-</typesystem> \ No newline at end of file
+</typesystem>