diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-08-05 23:44:23 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:08 -0300 |
commit | baf2a5bf56620134d751b54a514159221d4e11d4 (patch) | |
tree | 9a73ccfd86b059a4ce2d6033d60c0d28715b66f2 | |
parent | 50aef1dd4836b5019c60d31c54501ebcd37f72cd (diff) |
Added a test dealing with a reference to an Object Type passed to Python.
The test is for an Object Type that didn't existed in Python and is
passed to it as C++ reference through a virtual method.
-rw-r--r-- | tests/libsample/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/libsample/objecttypeholder.cpp | 46 | ||||
-rw-r--r-- | tests/libsample/objecttypeholder.h | 45 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rw-r--r-- | tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py | 44 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 2 |
7 files changed, 140 insertions, 0 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt index 317a7d054..cc568c986 100644 --- a/tests/libsample/CMakeLists.txt +++ b/tests/libsample/CMakeLists.txt @@ -19,6 +19,7 @@ modified_constructor.cpp multiple_derived.cpp objectmodel.cpp objecttype.cpp +objecttypeholder.cpp objecttypelayout.cpp objecttypeoperators.cpp objectview.cpp diff --git a/tests/libsample/objecttypeholder.cpp b/tests/libsample/objecttypeholder.cpp new file mode 100644 index 000000000..ac466793c --- /dev/null +++ b/tests/libsample/objecttypeholder.cpp @@ -0,0 +1,46 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team <contact@pyside.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "objecttypeholder.h" + +ObjectTypeHolder::ObjectTypeHolder(const char* objectName) +{ + m_objectType = new ObjectType(); + m_objectType->setObjectName(objectName); +} + +ObjectTypeHolder::~ObjectTypeHolder() +{ + delete m_objectType; +} + +Str +ObjectTypeHolder::passObjectTypeAsReference(const ObjectType& objectType) +{ + return objectType.objectName(); +} + +Str +ObjectTypeHolder::callPassObjectTypeAsReference() +{ + return passObjectTypeAsReference(*m_objectType); +} diff --git a/tests/libsample/objecttypeholder.h b/tests/libsample/objecttypeholder.h new file mode 100644 index 000000000..e8be24817 --- /dev/null +++ b/tests/libsample/objecttypeholder.h @@ -0,0 +1,45 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + * + * Contact: PySide team <contact@pyside.org> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef OBJECTTYPEHOLDER_H +#define OBJECTTYPEHOLDER_H + +#include "libsamplemacros.h" +#include "objecttype.h" +#include "str.h" + +class LIBSAMPLE_API ObjectTypeHolder +{ +public: + explicit ObjectTypeHolder(const char* objectName); + virtual ~ObjectTypeHolder(); + + ObjectType* getObjecType() { return m_objectType; } + + virtual Str passObjectTypeAsReference(const ObjectType& objectType); + Str callPassObjectTypeAsReference(); + +private: + ObjectType* m_objectType; +}; + +#endif diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index f63ecf981..382b9d13e 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -47,6 +47,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/noimplicitconversion_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/nondefaultctor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objectmodel_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttype_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypeholder_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypelayout_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypeoperators_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objectview_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index 164e992a9..8b9b44ec4 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -24,6 +24,7 @@ #include "nondefaultctor.h" #include "objectmodel.h" #include "objecttype.h" +#include "objecttypeholder.h" #include "objecttypelayout.h" #include "objecttypereference.h" #include "objecttypeoperators.h" diff --git a/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py b/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py new file mode 100644 index 000000000..5a48a5d2a --- /dev/null +++ b/tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py @@ -0,0 +1,44 @@ +#!/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 ObjectTypeHolder + +class TestObjectTypeReferenceAsVirtualMethodArgument(unittest.TestCase): + + def testBasic(self): + holder = ObjectTypeHolder('TheObjectFromC++') + self.assertEqual(holder.callPassObjectTypeAsReference(), 'TheObjectFromC++') + + def testExtended(self): + class Holder(ObjectTypeHolder): + def passObjectTypeAsReference(self, objectType): + return objectType.objectName().prepend(('ThisIs')) + holder = Holder('TheObjectFromC++') + self.assertEqual(holder.callPassObjectTypeAsReference(), 'ThisIsTheObjectFromC++') + +if __name__ == '__main__': + unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 27c265f3f..add18c289 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -298,6 +298,8 @@ </modify-function> </object-type> + <value-type name="ObjectTypeHolder"/> + <object-type name="ObjectModel"> <enum-type name="MethodCalled" /> <modify-function signature="data() const"> |