aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/libsample/CMakeLists.txt1
-rw-r--r--tests/libsample/abstract.h3
-rw-r--r--tests/libsample/listuser.cpp13
-rw-r--r--tests/libsample/listuser.h5
-rw-r--r--tests/libsample/objecttype.cpp91
-rw-r--r--tests/libsample/objecttype.h67
-rw-r--r--tests/libsample/str.cpp11
-rw-r--r--tests/libsample/str.h4
-rw-r--r--tests/samplebinding/CMakeLists.txt9
-rwxr-xr-xtests/samplebinding/derived_test.py6
-rw-r--r--tests/samplebinding/global.h1
-rwxr-xr-xtests/samplebinding/list_test.py12
-rwxr-xr-xtests/samplebinding/objecttype_test.py59
-rw-r--r--tests/samplebinding/typesystem_sample.xml2
14 files changed, 274 insertions, 10 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
index 82c4b1bbb..2e0be4dff 100644
--- a/tests/libsample/CMakeLists.txt
+++ b/tests/libsample/CMakeLists.txt
@@ -12,6 +12,7 @@ listuser.cpp
modifications.cpp
mapuser.cpp
multiple_derived.cpp
+objecttype.cpp
overload.cpp
pairuser.cpp
point.cpp
diff --git a/tests/libsample/abstract.h b/tests/libsample/abstract.h
index febb673ee..27c132683 100644
--- a/tests/libsample/abstract.h
+++ b/tests/libsample/abstract.h
@@ -53,6 +53,9 @@ public:
// factory method
static Abstract* createObject() { return 0; }
+ // method that receives an Object Type
+ static int getObjectId(Abstract* obj) { return obj->id(); }
+
virtual void pureVirtual() = 0;
virtual void unpureVirtual();
diff --git a/tests/libsample/listuser.cpp b/tests/libsample/listuser.cpp
index 3312e4110..8dc76f8ae 100644
--- a/tests/libsample/listuser.cpp
+++ b/tests/libsample/listuser.cpp
@@ -32,7 +32,6 @@
* 02110-1301 USA
*/
-#include <iostream>
#include <numeric>
#include <cstdlib>
#include "listuser.h"
@@ -42,14 +41,12 @@ using namespace std;
std::list<int>
ListUser::callCreateList()
{
- //cout << __PRETTY_FUNCTION__ << endl;
return createList();
}
std::list<int>
ListUser::createList()
{
- //cout << __PRETTY_FUNCTION__ << endl;
std::list<int> retval;
for (int i = 0; i < 4; i++)
retval.push_front(rand());
@@ -59,7 +56,6 @@ ListUser::createList()
std::list<Complex>
ListUser::createComplexList(Complex cpx0, Complex cpx1)
{
- //cout << __PRETTY_FUNCTION__ << endl;
std::list<Complex> retval;
retval.push_back(cpx0);
retval.push_back(cpx1);
@@ -78,3 +74,12 @@ ListUser::sumList(std::list<double> vallist)
return std::accumulate(vallist.begin(), vallist.end(), 0.0);
}
+void
+ListUser::multiplyPointList(PointList& points, double multiplier)
+{
+ for(PointList::iterator piter = points.begin(); piter != points.end(); piter++) {
+ (*piter)->setX((*piter)->x() * multiplier);
+ (*piter)->setY((*piter)->y() * multiplier);
+ }
+}
+
diff --git a/tests/libsample/listuser.h b/tests/libsample/listuser.h
index 9c669fe6f..b57ce76b9 100644
--- a/tests/libsample/listuser.h
+++ b/tests/libsample/listuser.h
@@ -37,10 +37,13 @@
#include <list>
#include "complex.h"
+#include "point.h"
class ListUser
{
public:
+ typedef std::list<Point*> PointList;
+
ListUser() {}
ListUser(const ListUser& other) : m_lst(other.m_lst) {}
~ListUser() {}
@@ -53,6 +56,8 @@ public:
double sumList(std::list<int> vallist);
double sumList(std::list<double> vallist);
+ static void multiplyPointList(PointList& points, double multiplier);
+
void setList(std::list<int> lst) { m_lst = lst; }
std::list<int> getList() { return m_lst; }
diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp
new file mode 100644
index 000000000..cc4733040
--- /dev/null
+++ b/tests/libsample/objecttype.cpp
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2009 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 "objecttype.h"
+
+using namespace std;
+
+ObjectType::ObjectType(ObjectType* parent) : m_parent(0)
+{
+ m_objectName = new Str("");
+ setParent(parent);
+}
+
+ObjectType::~ObjectType()
+{
+ while (!m_children.empty()) {
+ delete m_children.back();
+ m_children.pop_back();
+ }
+
+ delete m_objectName;
+}
+
+void
+ObjectType::setParent(ObjectType* parent)
+{
+ if (m_parent == parent)
+ return;
+
+ if (m_parent) {
+ for(ObjectTypeList::iterator child_iter = m_parent->m_children.begin();
+ child_iter != m_parent->m_children.end(); child_iter++) {
+ if (this == *child_iter)
+ m_parent->m_children.erase(child_iter);
+ }
+ }
+
+ m_parent = parent;
+ if (m_parent)
+ m_parent->m_children.push_back(this);
+}
+
+void
+ObjectType::setObjectName(const Str& name)
+{
+ delete m_objectName;
+ m_objectName = new Str(name);
+}
+
+Str
+ObjectType::objectName() const
+{
+ return *m_objectName;
+}
+
+bool ObjectType::event()
+{
+ return true;
+}
+
diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h
new file mode 100644
index 000000000..e5383524b
--- /dev/null
+++ b/tests/libsample/objecttype.h
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the Shiboken Python Binding Generator project.
+ *
+ * Copyright (C) 2009 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
+ */
+
+#ifndef OBJECTTYPE_H
+#define OBJECTTYPE_H
+
+#include <list>
+#include "str.h"
+
+class ObjectType
+{
+public:
+ typedef std::list<ObjectType*> ObjectTypeList;
+
+ ObjectType(ObjectType* parent = 0);
+ virtual ~ObjectType();
+
+ void setParent(ObjectType* parent);
+ ObjectType* parent() const { return m_parent; }
+ const ObjectTypeList& children() const { return m_children; }
+
+ Str objectName() const;
+ void setObjectName(const Str& name);
+
+ virtual bool event();
+
+private:
+ ObjectType(const ObjectType&);
+ ObjectType& operator=(const ObjectType&);
+
+ Str* m_objectName;
+ ObjectType* m_parent;
+ ObjectTypeList m_children;
+};
+#endif // OBJECTTYPE_H
+
diff --git a/tests/libsample/str.cpp b/tests/libsample/str.cpp
index fcf70fde8..8502a0350 100644
--- a/tests/libsample/str.cpp
+++ b/tests/libsample/str.cpp
@@ -88,6 +88,17 @@ Str::arg(const Str& s) const
return result;
}
+Str&
+Str::append(const Str& s)
+{
+ char* tmp = m_str;
+ m_str = (char*) malloc (m_size + s.size() + 1);
+ strncpy(m_str, tmp, m_size + 1);
+ strncat(m_str, s.cstring(), s.size());
+ m_size = m_size + s.size();
+ return *this;
+}
+
const char*
Str::cstring() const
{
diff --git a/tests/libsample/str.h b/tests/libsample/str.h
index 43396e633..26967901a 100644
--- a/tests/libsample/str.h
+++ b/tests/libsample/str.h
@@ -39,11 +39,13 @@ class Str
{
public:
Str(const Str& s);
- Str(const char* cstr = 0);
+ Str(const char* cstr = "");
~Str();
Str arg(const Str& s) const;
+ Str& append(const Str& s);
+
const char* cstring() const;
char get_char(int pos) const;
bool set_char(int pos, char ch);
diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt
index 2405f3bf6..774eddf45 100644
--- a/tests/samplebinding/CMakeLists.txt
+++ b/tests/samplebinding/CMakeLists.txt
@@ -8,15 +8,16 @@ set(sample_SRC
${CMAKE_CURRENT_BINARY_DIR}/sample/abstractmodifications_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/abstract_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/collector_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
-${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/mapuser_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/mbase2_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/mbase_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/mderived_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/nondefaultctor_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/sample/objecttype_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp
diff --git a/tests/samplebinding/derived_test.py b/tests/samplebinding/derived_test.py
index 77d1931cd..5077bd591 100755
--- a/tests/samplebinding/derived_test.py
+++ b/tests/samplebinding/derived_test.py
@@ -132,6 +132,12 @@ class DerivedTest(unittest.TestCase):
self.assertEqual(d.defaultValue(3), 3.1)
self.assertEqual(d.defaultValue(), 0.1)
+ def testCallToMethodWithAbstractArgument(self):
+ '''Call to method that expects an Abstract argument.'''
+ objId = 123
+ d = Derived(objId)
+ self.assertEqual(Abstract.getObjectId(d), objId)
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h
index ba36da17a..d119e9939 100644
--- a/tests/samplebinding/global.h
+++ b/tests/samplebinding/global.h
@@ -10,6 +10,7 @@
#include "modifications.h"
#include "multiple_derived.h"
#include "nondefaultctor.h"
+#include "objecttype.h"
#include "oddbool.h"
#include "overload.h"
#include "pairuser.h"
diff --git a/tests/samplebinding/list_test.py b/tests/samplebinding/list_test.py
index fc1fc80d8..ca13b2554 100755
--- a/tests/samplebinding/list_test.py
+++ b/tests/samplebinding/list_test.py
@@ -29,7 +29,7 @@
import sys
import unittest
-from sample import ListUser
+from sample import ListUser, Point
class ExtendedListUser(ListUser):
def __init__(self):
@@ -93,6 +93,16 @@ class ListConversionTest(unittest.TestCase):
self.assertNotEqual(result, lst)
self.assertEqual(result, list(lst))
+ def testConversionOfListOfObjectsPassedAsArgument(self):
+ '''Calls method with a Python list of wrapped objects to be converted to a C++ list.'''
+ mult = 3
+ pts0 = (Point(1.0, 2.0), Point(3.3, 4.4), Point(5, 6))
+ pts1 = (Point(1.0, 2.0), Point(3.3, 4.4), Point(5, 6))
+ ListUser.multiplyPointList(pts1, mult)
+ for pt0, pt1 in zip(pts0, pts1):
+ self.assertEqual(pt0.x() * mult, pt1.x())
+ self.assertEqual(pt0.y() * mult, pt1.y())
+
if __name__ == '__main__':
unittest.main()
diff --git a/tests/samplebinding/objecttype_test.py b/tests/samplebinding/objecttype_test.py
new file mode 100755
index 000000000..6b310265c
--- /dev/null
+++ b/tests/samplebinding/objecttype_test.py
@@ -0,0 +1,59 @@
+#!/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 <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
+
+'''Tests ObjectType class of object-type with privates copy constructor and = operator.'''
+
+import sys
+import unittest
+
+from sample import ObjectType, Str
+
+class ObjectTypeTest(unittest.TestCase):
+ '''Test cases ObjectType class of object-type with privates copy constructor and = operator.'''
+
+ def testObjectTypeSetObjectNameWithStrVariable(self):
+ '''ObjectType.setObjectName with Str variable as argument.'''
+ s = Str('object name')
+ o = ObjectType()
+ o.setObjectName(s)
+ self.assertEqual(str(o.objectName()), str(s))
+
+ def testObjectTypeSetObjectNameWithStrInstantiation(self):
+ '''ObjectType.setObjectName with Str instantiation as argument.'''
+ s = 'object name'
+ o = ObjectType()
+ o.setObjectName(Str(s))
+ self.assertEqual(str(o.objectName()), s)
+
+ def testObjectTypeSetObjectNameWithPythonString(self):
+ '''ObjectType.setObjectName with Python string as argument.'''
+ o = ObjectType()
+ o.setObjectName('object name')
+ self.assertEqual(str(o.objectName()), 'object name')
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml
index 2a56455d7..55b58c9da 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -56,6 +56,8 @@
<object-type name="Derived"/>
+ <object-type name="ObjectType"/>
+
<template name="boolptr_at_end_fix_beginning">
bool __ok__;
%0 = Shiboken::Converter&lt; %RETURN_TYPE &gt;::toPython(