aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-08-30 11:19:22 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2010-08-30 17:44:16 -0300
commit1eda671a34eba38e7e74e592e4ae88fa6803bcba (patch)
treea7abd551d478f100579067b948e1a17103aedcfb /tests
parent3dc673c7bcbad1613b9d3d6ff3dd4a73be41915d (diff)
Fix the type resolver algorithm.
The new algorithm do the following: - Try to use type_info on the object the get the object real name. - Try to find a type resolver with the name returned by type_info. - If a type resolver was found, get the python type. - Else, ask binding manager to resolve the type walking on all possible subclasses found in the inheritance tree. The binding manager has a graph representing the class inheritance tree. Note: This commit break the libshiboken ABI, but not the API. Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Renato Ara├║jo <renato.araujo@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/libother/CMakeLists.txt1
-rw-r--r--tests/libother/othermultiplederived.cpp56
-rw-r--r--tests/libother/othermultiplederived.h6
-rw-r--r--tests/libsample/multiple_derived.h5
-rw-r--r--tests/samplebinding/typediscovery_test.py13
5 files changed, 77 insertions, 4 deletions
diff --git a/tests/libother/CMakeLists.txt b/tests/libother/CMakeLists.txt
index 96ab6cab..9b3cf555 100644
--- a/tests/libother/CMakeLists.txt
+++ b/tests/libother/CMakeLists.txt
@@ -4,6 +4,7 @@ set(libother_SRC
number.cpp
otherderived.cpp
otherobjecttype.cpp
+othermultiplederived.cpp
)
add_definitions("-DLIBOTHER_BUILD")
diff --git a/tests/libother/othermultiplederived.cpp b/tests/libother/othermultiplederived.cpp
new file mode 100644
index 00000000..fadaa02b
--- /dev/null
+++ b/tests/libother/othermultiplederived.cpp
@@ -0,0 +1,56 @@
+/*
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2010 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.
+ *
+ * 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 "othermultiplederived.h"
+
+VirtualMethods OtherMultipleDerived::returnUselessClass()
+{
+ return VirtualMethods();
+}
+
+Base1* OtherMultipleDerived::createObject(const std::string& objName)
+{
+ if (objName == "Base1")
+ return new Base1;
+ else if (objName == "MDerived1")
+ return new MDerived1;
+ else if (objName == "SonOfMDerived1")
+ return new SonOfMDerived1;
+ else if (objName == "MDerived3")
+ return new MDerived3;
+ else if (objName == "OtherMultipleDerived")
+ return new OtherMultipleDerived;
+ return 0;
+}
+
diff --git a/tests/libother/othermultiplederived.h b/tests/libother/othermultiplederived.h
index cefc7256..33260b6e 100644
--- a/tests/libother/othermultiplederived.h
+++ b/tests/libother/othermultiplederived.h
@@ -37,14 +37,16 @@
#include "libothermacros.h"
#include "multiple_derived.h"
+#include "virtualmethods.h"
class ObjectType;
-class OtherMultipleDerived : public MDerived1
+class LIBOTHER_API OtherMultipleDerived : public MDerived1
{
public:
// this will use CppCopier from other module (bug#142)
- inline VirtualMethods returnUselessClass() { return VirtualMethods(); }
+ VirtualMethods returnUselessClass();
+ static Base1* createObject(const std::string& objName);
};
#endif
diff --git a/tests/libsample/multiple_derived.h b/tests/libsample/multiple_derived.h
index ffbe5feb..98ccb4de 100644
--- a/tests/libsample/multiple_derived.h
+++ b/tests/libsample/multiple_derived.h
@@ -36,6 +36,7 @@
#define MDERIVED_H
#include "libsamplemacros.h"
+#include <string>
class Base1
{
@@ -97,7 +98,7 @@ class Base3
{
public:
explicit Base3(int val = 3) : m_value(val) {}
- ~Base3() {}
+ virtual ~Base3() {}
int base3Method() { return m_value; }
private:
int m_value;
@@ -107,7 +108,7 @@ class Base4
{
public:
Base4() : m_value(4) {}
- ~Base4() {}
+ virtual ~Base4() {}
int base4Method() { return m_value; }
private:
int m_value;
diff --git a/tests/samplebinding/typediscovery_test.py b/tests/samplebinding/typediscovery_test.py
index 3c1bfdb9..f7d5433c 100644
--- a/tests/samplebinding/typediscovery_test.py
+++ b/tests/samplebinding/typediscovery_test.py
@@ -29,6 +29,7 @@
import unittest
from sample import *
+from other import *
class TypeDiscoveryTest(unittest.TestCase):
@@ -42,6 +43,18 @@ class TypeDiscoveryTest(unittest.TestCase):
a = Derived.triggerAnotherImpossibleTypeDiscovery()
self.assertEqual(type(a), Derived)
+ def testMultipleInheritance(self):
+ obj = OtherMultipleDerived.createObject("Base1");
+ self.assertEqual(type(obj), Base1)
+ obj = OtherMultipleDerived.createObject("MDerived1");
+ self.assertEqual(type(obj), MDerived1)
+ obj = OtherMultipleDerived.createObject("SonOfMDerived1");
+ self.assertEqual(type(obj), SonOfMDerived1)
+ obj = OtherMultipleDerived.createObject("MDerived3");
+ self.assertEqual(type(obj), MDerived3)
+ obj = OtherMultipleDerived.createObject("OtherMultipleDerived");
+ self.assertEqual(type(obj), OtherMultipleDerived)
+
if __name__ == '__main__':
unittest.main()