summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-13 17:47:16 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-12-13 17:55:54 -0300
commit6b720050efa431975ee275bd9a613f680b4eddc8 (patch)
treecbd16acd8a0f11787c1c014f50293b8377dc3feb /tests
parent4630f41f6a827e3657b221af05606ce6c8c855ca (diff)
downloadpyside-6b720050efa431975ee275bd9a613f680b4eddc8.tar.gz
pyside-6b720050efa431975ee275bd9a613f680b4eddc8.tar.xz
pyside-6b720050efa431975ee275bd9a613f680b4eddc8.zip
Added test for Python written models returning new objects without keeping reference to them.
Reviewed by Lauro Moura <lauro.neto@openbossa.org> eviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/pysidetest/CMakeLists.txt4
-rw-r--r--tests/pysidetest/global.h1
-rw-r--r--tests/pysidetest/modelview_test.py51
-rw-r--r--tests/pysidetest/testview.cpp15
-rw-r--r--tests/pysidetest/testview.h23
-rw-r--r--tests/pysidetest/typesystem_pysidetest.xml7
6 files changed, 101 insertions, 0 deletions
diff --git a/tests/pysidetest/CMakeLists.txt b/tests/pysidetest/CMakeLists.txt
index d983ef8..07b03d5 100644
--- a/tests/pysidetest/CMakeLists.txt
+++ b/tests/pysidetest/CMakeLists.txt
@@ -12,16 +12,19 @@ add_definitions(-DRXX_ALLOCATOR_INIT_0)
set(pysidetest_SRC
testobject.cpp
+testview.cpp
)
set(pysidetest_MOC_HEADERS
testobject.h
+testview.h
)
qt4_wrap_cpp(pysidetest_MOC_SRC ${pysidetest_MOC_HEADERS})
set(testbinding_SRC
${CMAKE_CURRENT_BINARY_DIR}/testbinding/testobject_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/testbinding/testview_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/testbinding_module_wrapper.cpp
)
@@ -63,5 +66,6 @@ add_dependencies(testbinding pyside QtCore libpyside pysidetest)
PYSIDE_TEST(homonymoussignalandmethod_test.py)
+PYSIDE_TEST(modelview_test.py)
PYSIDE_TEST(version_test.py)
diff --git a/tests/pysidetest/global.h b/tests/pysidetest/global.h
index 22d3375..e55a773 100644
--- a/tests/pysidetest/global.h
+++ b/tests/pysidetest/global.h
@@ -1,2 +1,3 @@
#include "pyside_global.h"
#include "testobject.h"
+#include "testview.h"
diff --git a/tests/pysidetest/modelview_test.py b/tests/pysidetest/modelview_test.py
new file mode 100644
index 0000000..ebab200
--- /dev/null
+++ b/tests/pysidetest/modelview_test.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+
+import unittest
+from testbinding import TestView
+from PySide.QtCore import QAbstractListModel, QObject, QModelIndex
+
+'''Tests model/view relationship.'''
+
+object_name = 'test object'
+
+class MyObject(QObject):
+ pass
+
+class ListModelKeepsReference(QAbstractListModel):
+ def rowCount(self, parent=QModelIndex()):
+ return 1
+
+ def data(self, index, role):
+ self.obj = MyObject()
+ self.obj.setObjectName(object_name)
+ return self.obj
+
+class ListModelDoesntKeepsReference(QAbstractListModel):
+ def rowCount(self, parent=QModelIndex()):
+ return 1
+
+ def data(self, index, role):
+ obj = MyObject()
+ obj.setObjectName(object_name)
+ return obj
+
+class ModelViewTest(unittest.TestCase):
+
+ def testListModelKeepsReference(self):
+ model = ListModelKeepsReference()
+ view = TestView(model)
+ obj = view.getData()
+ self.assertEqual(type(obj), MyObject)
+ self.assertEqual(obj.objectName(), object_name)
+
+ def testListModelDoesntKeepsReference(self):
+ model = ListModelDoesntKeepsReference()
+ view = TestView(model)
+ obj = view.getData()
+ self.assertEqual(type(obj), MyObject)
+ self.assertEqual(obj.objectName(), object_name)
+
+
+if __name__ == '__main__':
+ unittest.main()
+
diff --git a/tests/pysidetest/testview.cpp b/tests/pysidetest/testview.cpp
new file mode 100644
index 0000000..c7e9c6d
--- /dev/null
+++ b/tests/pysidetest/testview.cpp
@@ -0,0 +1,15 @@
+#include "testview.h"
+#include <QDebug>
+#include <stdio.h>
+
+QObject*
+TestView::getData()
+{
+ QModelIndex index;
+ QVariant data = m_model->data(index);
+ QObject* obj = 0;
+ if (data.canConvert<QObject*>())
+ obj = data.value<QObject*>();
+ return obj;
+}
+
diff --git a/tests/pysidetest/testview.h b/tests/pysidetest/testview.h
new file mode 100644
index 0000000..2ae4162
--- /dev/null
+++ b/tests/pysidetest/testview.h
@@ -0,0 +1,23 @@
+#ifndef TESTVIEW_H
+#define TESTVIEW_H
+
+#include <QObject>
+#include <QAbstractListModel>
+#ifdef pysidetest_EXPORTS
+#define PYSIDE_EXPORTS 1
+#endif
+#include "pysidemacros.h"
+
+class PYSIDE_API TestView : public QObject
+{
+ Q_OBJECT
+public:
+ TestView(QAbstractListModel* model, QObject* parent = 0) : QObject(parent), m_model(model) {}
+ QAbstractListModel* model() { return m_model; }
+ QObject* getData();
+private:
+ QAbstractListModel* m_model;
+};
+
+#endif // TESTVIEW_H
+
diff --git a/tests/pysidetest/typesystem_pysidetest.xml b/tests/pysidetest/typesystem_pysidetest.xml
index a966362..afa764c 100644
--- a/tests/pysidetest/typesystem_pysidetest.xml
+++ b/tests/pysidetest/typesystem_pysidetest.xml
@@ -2,5 +2,12 @@
<typesystem package="testbinding">
<load-typesystem name="typesystem_core.xml" generate="no" />
<object-type name="TestObject" />
+ <object-type name="TestView" >
+ <modify-function signature="setModel(QObject*)">
+ <modify-argument index="1">
+ <reference-count action="add"/>
+ </modify-argument>
+ </modify-function>
+ </object-type>
</typesystem>