From f548708c9643481b023763aa25722a5a25a268e1 Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Thu, 12 Aug 2010 18:04:01 -0300 Subject: Create unit test to function with ambiguous signature in Python side. Reviewer: Hugo Parente Lima Luciano Wolf --- tests/libsample/null.h | 50 +++++++++++++++++++++++++++++++ tests/libsample/objecttype.cpp | 17 ++++++++++- tests/libsample/objecttype.h | 10 +++++++ tests/samplebinding/null_conversions.h | 32 ++++++++++++++++++++ tests/samplebinding/objecttype_test.py | 7 +++++ tests/samplebinding/typesystem_sample.xml | 9 ++++++ 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 tests/libsample/null.h create mode 100644 tests/samplebinding/null_conversions.h diff --git a/tests/libsample/null.h b/tests/libsample/null.h new file mode 100644 index 000000000..ffddaafa0 --- /dev/null +++ b/tests/libsample/null.h @@ -0,0 +1,50 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team + * + * 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. + * + * As a special exception to the GNU Lesser General Public License + * version 2.1, the object code form of a "work that uses the Library" + * may incorporate material from a header file that is part of the + * Library. You may distribute such object code under terms of your + * choice, provided that the incorporated material (i) does not exceed + * more than 5% of the total size of the Library; and (ii) is limited to + * numerical parameters, data structure layouts, accessors, macros, + * inline functions and templates. + * + * 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 + */ + +#ifndef NULL_H +#define NULL_H + +class Null +{ +public: + Null(bool value) : m_isNull(value) {} + Null() : m_isNull(false) {} + void setIsNull(bool flag) { m_isNull = flag; } + +private: + bool m_isNull; +}; + +#endif // STR_H + diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp index 4c608037e..d57dbeddd 100644 --- a/tests/libsample/objecttype.cpp +++ b/tests/libsample/objecttype.cpp @@ -40,7 +40,7 @@ using namespace std; -ObjectType::ObjectType(ObjectType* parent) : m_parent(0), m_layout(0) +ObjectType::ObjectType(ObjectType* parent) : m_parent(0), m_layout(0), m_call_id(-1) { setParent(parent); } @@ -260,3 +260,18 @@ ObjectType::setObjectNameWithSize(const Str& name, int size) setObjectNameWithSize("", size, name); } +void ObjectType::setObject(ObjectType *) +{ + m_call_id = 0; +} + +void ObjectType::setObject(const Null&) +{ + m_call_id = 1; +} + +int ObjectType::callId() const +{ + return m_call_id; +} + diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h index 18454a121..9c0bb2123 100644 --- a/tests/libsample/objecttype.h +++ b/tests/libsample/objecttype.h @@ -37,6 +37,7 @@ #include #include "str.h" +#include "null.h" #include "libsamplemacros.h" @@ -105,6 +106,11 @@ public: void setObjectNameWithSize(const char*, int size=9, const Str& name = Str("")); void setObjectNameWithSize(const Str& name = Str(""), int size=9); + //Function used to comfuse the generator when two values accept Null as arg + void setObject(ObjectType *); + void setObject(const Null&); + int callId() const; + private: ObjectType(const ObjectType&); @@ -117,6 +123,10 @@ private: ObjectTypeList m_children; ObjectTypeLayout* m_layout; + + + //used on overload null test + int m_call_id; }; LIBSAMPLE_API unsigned int objectTypeHash(const ObjectType* objectType); diff --git a/tests/samplebinding/null_conversions.h b/tests/samplebinding/null_conversions.h new file mode 100644 index 000000000..cbe159f85 --- /dev/null +++ b/tests/samplebinding/null_conversions.h @@ -0,0 +1,32 @@ +namespace Shiboken { +template<> +struct Converter +{ + static inline bool checkType(PyObject* pyObj) + { + return false; + } + + static inline bool isConvertible(PyObject* pyObj) + { + if (pyObj == 0 || pyObj == Py_None) + return true; + return false; + } + + static inline PyObject* toPython(void* cppobj) + { + Py_RETURN_NONE; + } + + static inline PyObject* toPython(const Null& cpx) + { + Py_RETURN_NONE; + } + + static inline Null toCpp(PyObject* pyobj) + { + return Null(pyobj == 0); + } +}; +} diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py index 958df1d59..2a0dbbdb8 100644 --- a/tests/samplebinding/objecttype_test.py +++ b/tests/samplebinding/objecttype_test.py @@ -55,6 +55,13 @@ class ObjectTypeTest(unittest.TestCase): o.setObjectName('object name') self.assertEqual(str(o.objectName()), 'object name') + def testNullOverload(self): + o = ObjectType() + o.setObject(None) + self.assertEqual(o.callId(), 0) + o.setNullObject(None) + self.assertEqual(o.callId(), 1) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 24b4ff875..b3e05d4ed 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -17,6 +17,11 @@ + + + + + @@ -117,6 +122,9 @@ + + + @@ -199,6 +207,7 @@ + -- cgit v1.2.3