summaryrefslogtreecommitdiffstats
path: root/tests/libsample
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-16 14:08:29 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-12-16 14:38:04 -0300
commit2d146fad966ae24940c65812cde4c28b645ecf6b (patch)
tree08267561ce65de16fc422d59f2dceaadfd4309f9 /tests/libsample
parentf728e59aa228d5b796b5641bea683333b10919e4 (diff)
downloadshiboken-2d146fad966ae24940c65812cde4c28b645ecf6b.tar.gz
shiboken-2d146fad966ae24940c65812cde4c28b645ecf6b.tar.xz
shiboken-2d146fad966ae24940c65812cde4c28b645ecf6b.zip
Added tests to check the release of ownership of objects returned from Python.
The ObjectModel test class was introduced to check if the transference of ownership of objects returned from Python to C++ through a virtual method is working properly. Also updated the other test that uses the ObjectView class. Reviewed by Lauro Moura <lauro.neto@openbossa.org> Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests/libsample')
-rw-r--r--tests/libsample/CMakeLists.txt1
-rw-r--r--tests/libsample/objectmodel.cpp36
-rw-r--r--tests/libsample/objectmodel.h46
-rw-r--r--tests/libsample/objectview.cpp8
-rw-r--r--tests/libsample/objectview.h11
5 files changed, 97 insertions, 5 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt
index 3452c576..b6cd1b92 100644
--- a/tests/libsample/CMakeLists.txt
+++ b/tests/libsample/CMakeLists.txt
@@ -16,6 +16,7 @@ modifications.cpp
mapuser.cpp
modified_constructor.cpp
multiple_derived.cpp
+objectmodel.cpp
objecttype.cpp
objecttypelayout.cpp
objectview.cpp
diff --git a/tests/libsample/objectmodel.cpp b/tests/libsample/objectmodel.cpp
new file mode 100644
index 00000000..93c25645
--- /dev/null
+++ b/tests/libsample/objectmodel.cpp
@@ -0,0 +1,36 @@
+/*
+ * 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 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
+ */
+
+#include "objectmodel.h"
+
+void
+ObjectModel::setData(ObjectType* data)
+{
+ m_data = data;
+}
+
+ObjectType*
+ObjectModel::data() const
+{
+ return m_data;
+}
+
diff --git a/tests/libsample/objectmodel.h b/tests/libsample/objectmodel.h
new file mode 100644
index 00000000..b226b1f9
--- /dev/null
+++ b/tests/libsample/objectmodel.h
@@ -0,0 +1,46 @@
+/*
+ * 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 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 OBJECTMODEL_H
+#define OBJECTMODEL_H
+
+#include "objecttype.h"
+#include "libsamplemacros.h"
+
+class LIBSAMPLE_API ObjectModel : public ObjectType
+{
+public:
+ ObjectModel(ObjectType* parent = 0)
+ : ObjectType(parent), m_data(0)
+ {}
+
+ void setData(ObjectType* data);
+ virtual ObjectType* data() const;
+
+private:
+ // The model holds only one piece of data.
+ // (This is just a test after all.)
+ ObjectType* m_data;
+};
+
+#endif // OBJECTMODEL_H
+
diff --git a/tests/libsample/objectview.cpp b/tests/libsample/objectview.cpp
index 835e7183..a5dbc0f1 100644
--- a/tests/libsample/objectview.cpp
+++ b/tests/libsample/objectview.cpp
@@ -21,7 +21,7 @@
*/
#include "objectview.h"
-#include "objecttype.h"
+#include "objectmodel.h"
#include "str.h"
Str
@@ -40,3 +40,9 @@ ObjectView::modifyModelData(Str& data)
}
+ObjectType*
+ObjectView::getRawModelData()
+{
+ return m_model->data();
+}
+
diff --git a/tests/libsample/objectview.h b/tests/libsample/objectview.h
index fd3d640b..3402b6d8 100644
--- a/tests/libsample/objectview.h
+++ b/tests/libsample/objectview.h
@@ -27,22 +27,25 @@
#include "libsamplemacros.h"
class Str;
+class ObjectModel;
class LIBSAMPLE_API ObjectView : public ObjectType
{
public:
- ObjectView(ObjectType* model = 0, ObjectType* parent = 0)
+ ObjectView(ObjectModel* model = 0, ObjectType* parent = 0)
: ObjectType(parent), m_model(model)
{}
- inline void setModel(ObjectType* model) { m_model = model; }
- inline ObjectType* model() const { return m_model; }
+ inline void setModel(ObjectModel* model) { m_model = model; }
+ inline ObjectModel* model() const { return m_model; }
Str displayModelData();
void modifyModelData(Str& data);
+ ObjectType* getRawModelData();
+
private:
- ObjectType* m_model;
+ ObjectModel* m_model;
};
#endif // OBJECTVIEW_H