aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-03-23 17:43:46 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:15:19 -0300
commit2f541a1684db694e9662f482c0fedd91509a948e (patch)
treea3a29741fc2c73f22b9b9d4aea0cef1977ffd476
parent4a262bcb91b7b620f434397fe2f7cb1454950397 (diff)
Added test for bug 489.
http://bugs.pyside.org/show_bug.cgi?id=489 Reviewed by Lauro Moura <lauro.neto@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
-rw-r--r--tests/libsample/overload.h6
-rw-r--r--tests/samplebinding/overloadwithdefault_test.py58
-rw-r--r--tests/samplebinding/typesystem_sample.xml40
3 files changed, 104 insertions, 0 deletions
diff --git a/tests/libsample/overload.h b/tests/libsample/overload.h
index 0660f3799..46a578859 100644
--- a/tests/libsample/overload.h
+++ b/tests/libsample/overload.h
@@ -23,6 +23,7 @@
#ifndef OVERLOAD_H
#define OVERLOAD_H
+#include "str.h"
#include "size.h"
#include "point.h"
@@ -60,6 +61,11 @@ public:
void singleOverload(Point* x) {}
Point* singleOverload() {return new Point();}
+
+ // Similar to QImage constructor
+ FunctionEnum strBufferOverloads(const Str& arg0, const char* arg1 = 0, bool arg2 = true) { return Function0; }
+ FunctionEnum strBufferOverloads(unsigned char* arg0, int arg1) { return Function1; }
+ FunctionEnum strBufferOverloads() { return Function2; }
};
class LIBSAMPLE_API Overload2 : public Overload
diff --git a/tests/samplebinding/overloadwithdefault_test.py b/tests/samplebinding/overloadwithdefault_test.py
new file mode 100644
index 000000000..d7d23c50d
--- /dev/null
+++ b/tests/samplebinding/overloadwithdefault_test.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# This file is part of the Shiboken Python Bindings Generator project.
+#
+# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+#
+# Contact: PySide team <contact@pyside.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public License
+# version 2.1 as published by the Free Software Foundation. Please
+# review the following information to ensure the GNU Lesser General
+# Public License version 2.1 requirements will be met:
+# http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+# 02110-1301 USA
+
+import unittest
+
+from sample import Overload, Str
+
+class OverloadTest(unittest.TestCase):
+
+ def testNoArgument(self):
+ overload = Overload()
+ self.assertEqual(overload.strBufferOverloads(), Overload.Function2)
+
+ def testStrArgument(self):
+ overload = Overload()
+ self.assertEqual(overload.strBufferOverloads(Str('')), Overload.Function0)
+ self.assertEqual(overload.strBufferOverloads(Str(''), ''), Overload.Function0)
+ self.assertEqual(overload.strBufferOverloads(Str(''), '', False), Overload.Function0)
+
+ def testStringArgumentAsStr(self):
+ overload = Overload()
+ self.assertEqual(overload.strBufferOverloads('', ''), Overload.Function0)
+ self.assertEqual(overload.strBufferOverloads('', '', False), Overload.Function0)
+
+ def testStringArgumentAsBuffer(self):
+ overload = Overload()
+ self.assertEqual(overload.strBufferOverloads('', 0), Overload.Function1)
+
+ def testBufferArgument(self):
+ overload = Overload()
+ self.assertEqual(overload.strBufferOverloads(buffer(''), 0), Overload.Function1)
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 85187c53f..35ef4220b 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -1118,8 +1118,48 @@
<define-ownership owner="c++"/>
</modify-argument>
</modify-function>
+
+ <template name="buffer_argument">
+ unsigned char* %out;
+ if (PyObject_CheckReadBuffer(%PYARG_1)) {
+ PyBufferProcs* bufferProcs = %PYARG_1->ob_type->tp_as_buffer;
+ void* ptr;
+ bufferProcs->bf_getreadbuffer(%PYARG_1, 0, &amp;ptr);
+ %out = (unsigned char*) ptr;
+ } else {
+ PyErr_SetString(PyExc_TypeError, "The object must support buffer protocol with just one segment.");
+ }
+ </template>
+
+ <modify-function signature="strBufferOverloads(unsigned char*,int)">
+ <modify-argument index="1">
+ <replace-type modified-type="PyObject"/>
+ <conversion-rule class="native">
+ <insert-template name="buffer_argument" />
+ </conversion-rule>
+ </modify-argument>
+ </modify-function>
+ <!--
+ This added function simulates the solution given to PySide's QImage
+ constructor problem, as seen in PySide/bbba1cc4, and described in
+ bug #489 [http://bugs.pyside.org/show_bug.cgi?id=489].
+ This is not the best solution, just one that works. The proper way
+ to handle it would be to fix the overload decisor.
+ -->
+ <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" />
+ </insert-template>
+ PyThreadState* _save = PyEval_SaveThread();
+ %RETURN_TYPE cppResult = %CPPSELF.%FUNCTION_NAME(%1_out, %2);
+ PyEval_RestoreThread(_save);
+ %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](cppResult);
+ </inject-code>
+ </add-function>
</object-type>
<object-type name="Overload2" />
+
<object-type name="Collector" stream="yes"/>
<value-type name="IntWrapper" />