From 4466eddf64fbfa5d62c20a6782f99b01369fb47d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Wed, 9 Sep 2009 15:33:08 -0300 Subject: Create multiple heritance tests. --- tests/libsample/CMakeLists.txt | 1 + tests/libsample/multiple_derived.cpp | 69 ++++++++++++++++++++++++++++ tests/libsample/multiple_derived.h | 68 +++++++++++++++++++++++++++ tests/samplebinding/CMakeLists.txt | 3 ++ tests/samplebinding/global.h | 1 + tests/samplebinding/multiple_derived_test.py | 53 +++++++++++++++++++++ tests/samplebinding/typesystem_sample.xml | 4 ++ 7 files changed, 199 insertions(+) create mode 100644 tests/libsample/multiple_derived.cpp create mode 100644 tests/libsample/multiple_derived.h create mode 100755 tests/samplebinding/multiple_derived_test.py (limited to 'tests') diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt index 0fe198ead..3a3aef497 100644 --- a/tests/libsample/CMakeLists.txt +++ b/tests/libsample/CMakeLists.txt @@ -10,6 +10,7 @@ kindergarten.cpp listuser.cpp modifications.cpp mapuser.cpp +multiple_derived.cpp pairuser.cpp point.cpp reference.cpp diff --git a/tests/libsample/multiple_derived.cpp b/tests/libsample/multiple_derived.cpp new file mode 100644 index 000000000..3e0bec13e --- /dev/null +++ b/tests/libsample/multiple_derived.cpp @@ -0,0 +1,69 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2009 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 + */ + +#include +#include "multiple_derived.h" + +MDerived::MDerived() +{ +} + +MDerived::~MDerived() +{ +} + +const char* MDerived::name() +{ + return "MDerived"; +} + +// Base2 methods +const char* MDerived::funcName() +{ + return "MDerived.funcName"; +} + +MDerived* MDerived::transformFromBase2(MBase2 *self) +{ + MDerived* a = dynamic_cast(self); + return a; +} + +MDerived* MDerived::transformFromBase(MBase *self) +{ + MDerived* a = dynamic_cast(self); + return a; +} + + diff --git a/tests/libsample/multiple_derived.h b/tests/libsample/multiple_derived.h new file mode 100644 index 000000000..d73ca5cfa --- /dev/null +++ b/tests/libsample/multiple_derived.h @@ -0,0 +1,68 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2009 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 MDERIVED_H +#define MDERIVED_H + +class MBase +{ +public: + ~MBase() {} + virtual const char *name() { return "Base"; } +}; + +class MBase2 +{ +public: + ~MBase2() {} + virtual const char *funcName() { return "Base2.funcName"; } +}; + +class MDerived : public MBase, public MBase2 +{ +public: + MDerived(); + virtual ~MDerived(); + + // Base methods + const char* name(); + + // Base2 methods + const char* funcName(); + + MDerived* transformFromBase2(MBase2 *self); + MDerived* transformFromBase(MBase *self); +}; +#endif // MDERIVED_H + diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index ea684c710..fc2a47b92 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -7,6 +7,9 @@ ${CMAKE_CURRENT_SOURCE_DIR}/typesystem_sample.xml set(sample_SRC ${CMAKE_CURRENT_BINARY_DIR}/sample/abstractmodifications_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/abstract_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/mbase_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/mbase2_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/mderived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/derived_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/implicitconv_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/listuser_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index 5717f7e14..4e9ee4510 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -8,6 +8,7 @@ #include "pairuser.h" #include "listuser.h" #include "mapuser.h" +#include "multiple_derived.h" #include "samplenamespace.h" #include "modifications.h" #include "implicitconv.h" diff --git a/tests/samplebinding/multiple_derived_test.py b/tests/samplebinding/multiple_derived_test.py new file mode 100755 index 000000000..20830d7e9 --- /dev/null +++ b/tests/samplebinding/multiple_derived_test.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2009 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 + +'''Test cases for std::list container conversions''' + +import sys +import unittest + +from sample import MBase, MBase2, MDerived + +class MultipleDerivedTest(unittest.TestCase): + '''Test case for multiple inheritance ''' + + def testType(self): + k = MDerived() + self.assert_(isinstance(k, MDerived)) + self.assert_(isinstance(k, MBase)) + self.assert_(isinstance(k, MBase2)) + + def testCast(self): + k = MDerived() + + b = k.transformFromBase(k) + self.assertEqual(k, b) + + b2 = k.transformFromBase2(k) + self.assertEqual(k, b2) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index dc0d64d77..d9b9adeb7 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -223,6 +223,10 @@ + + + + -- cgit v1.2.3