aboutsummaryrefslogtreecommitdiffstats
path: root/tests/libsample
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-03 05:21:04 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-03 05:21:04 -0300
commit048498d28bf7a0451bfc490b9f1799d3d3751b40 (patch)
tree90102429b533478bda47213c8ad5b8d531d6204d /tests/libsample
parent22ae136011c64b3da8f272e6f55574413064efae (diff)
* added the ObjectType example which adds some cases similar to
those on Qt's QObject (object name, parent and children list), although no ownership test was added yet. * added method Abstract::getObjectId(Abstract*) as a case of an argument that should be converted to an abstract type. * added ListUser::multiplyPointList(std::list<Point*>&, double), which tests the conversion from a Python list of Point wrappers to a C++ list whose items will be altered.
Diffstat (limited to 'tests/libsample')
-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
8 files changed, 190 insertions, 5 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);