From 485288fb1888814f641b2df56860171783d326fb Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Fri, 8 Apr 2011 16:22:38 -0300 Subject: Added tests for conversion operator that returns a constant reference type. This is related to bug #716: http://bugs.pyside.org/show_bug.cgi?id=716 Reviewed by Hugo Parente Reviewed by Luciano Wolf --- tests/libsample/modelindex.h | 66 +++++++++++++++++++++++++++++++ tests/samplebinding/CMakeLists.txt | 3 ++ tests/samplebinding/global.h | 1 + tests/samplebinding/modelindex_test.py | 49 +++++++++++++++++++++++ tests/samplebinding/typesystem_sample.xml | 10 +++++ 5 files changed, 129 insertions(+) create mode 100644 tests/libsample/modelindex.h create mode 100644 tests/samplebinding/modelindex_test.py (limited to 'tests') diff --git a/tests/libsample/modelindex.h b/tests/libsample/modelindex.h new file mode 100644 index 000000000..2654a58d9 --- /dev/null +++ b/tests/libsample/modelindex.h @@ -0,0 +1,66 @@ +/* + * 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 MODELINDEX_H +#define MODELINDEX_H + +#include "libsamplemacros.h" + +class ModelIndex +{ +public: + ModelIndex() : m_value(0) {} + ModelIndex(const ModelIndex& other) { m_value = other.m_value; } + inline void setValue(int value) { m_value = value; } + inline int value() const { return m_value; } + static int getValue(const ModelIndex& index) { return index.value(); } +private: + int m_value; +}; + +class ReferentModelIndex +{ +public: + ReferentModelIndex() {} + ReferentModelIndex(const ModelIndex& index) : m_index(index) {} + ReferentModelIndex(const ReferentModelIndex& other) { m_index = other.m_index; } + inline void setValue(int value) { m_index.setValue(value); } + inline int value() const { return m_index.value(); } + operator const ModelIndex&() const { return m_index; } +private: + ModelIndex m_index; +}; + +class PersistentModelIndex +{ +public: + PersistentModelIndex() {} + PersistentModelIndex(const ModelIndex& index) : m_index(index) {} + PersistentModelIndex(const PersistentModelIndex& other) { m_index = other.m_index; } + inline void setValue(int value) { m_index.setValue(value); } + inline int value() const { return m_index.value(); } + operator ModelIndex() const { return m_index; } +private: + ModelIndex m_index; +}; + +#endif diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index b62f2d049..04ee3b398 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -39,6 +39,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/mderived2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/mderived3_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/mderived4_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/mderived5_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/modelindex_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/modifiedconstructor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/noimplicitconversion_wrapper.cpp @@ -54,6 +55,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/overload2_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pen_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/persistentmodelindex_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/point_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pointf_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pointerholder_wrapper.cpp @@ -70,6 +72,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/protectedvirtualdestructor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/rect_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/rectf_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/reference_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/referentmodelindex_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_someclass_someinnerclass_okthisisrecursiveenough_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index 98738a38a..850518494 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -15,6 +15,7 @@ #include "list.h" #include "listuser.h" #include "mapuser.h" +#include "modelindex.h" #include "modifications.h" #include "modified_constructor.h" #include "multiple_derived.h" diff --git a/tests/samplebinding/modelindex_test.py b/tests/samplebinding/modelindex_test.py new file mode 100644 index 000000000..31503b97d --- /dev/null +++ b/tests/samplebinding/modelindex_test.py @@ -0,0 +1,49 @@ +#!/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 ModelIndex, ReferentModelIndex, PersistentModelIndex + +class TestCastOperator(unittest.TestCase): + + def testCastOperatorReturningValue(self): + index = PersistentModelIndex() + index.setValue(123) + self.assertEqual(index.value(), 123) + self.assertEqual(index.value(), ModelIndex.getValue(index)) + + def testCastOperatorReturningReference(self): + index = ReferentModelIndex() + index.setValue(123) + self.assertEqual(index.value(), 123) + self.assertEqual(index.value(), ModelIndex.getValue(index)) + + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index eeaf3c218..338719372 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -1473,6 +1473,16 @@ + + + + + + + + + + -- cgit v1.2.3