From baf2a5bf56620134d751b54a514159221d4e11d4 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Fri, 5 Aug 2011 23:44:23 -0300 Subject: 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. --- tests/libsample/CMakeLists.txt | 1 + tests/libsample/objecttypeholder.cpp | 46 ++++++++++++++++++++++ tests/libsample/objecttypeholder.h | 45 +++++++++++++++++++++ tests/samplebinding/CMakeLists.txt | 1 + tests/samplebinding/global.h | 1 + ...ecttypereferenceasvirtualmethodargument_test.py | 44 +++++++++++++++++++++ tests/samplebinding/typesystem_sample.xml | 2 + 7 files changed, 140 insertions(+) create mode 100644 tests/libsample/objecttypeholder.cpp create mode 100644 tests/libsample/objecttypeholder.h create mode 100644 tests/samplebinding/objecttypereferenceasvirtualmethodargument_test.py (limited to 'tests') 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 + * + * 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 + * + * 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 +# +# 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 @@ + + -- cgit v1.2.3