summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2010-12-15 19:11:40 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2010-12-15 19:20:56 -0300
commitc53ec3c17e5c59b6b1cc245b19f83a0eba1085c3 (patch)
treeded114d4b516d62b91f7453b55563b8d81f65ac6 /tests
parent539b906eb241b3874d015695bffd072632783960 (diff)
downloadpyside-c53ec3c17e5c59b6b1cc245b19f83a0eba1085c3.tar.gz
pyside-c53ec3c17e5c59b6b1cc245b19f83a0eba1085c3.tar.xz
pyside-c53ec3c17e5c59b6b1cc245b19f83a0eba1085c3.zip
Updated the PySide test related to Python model returning data to C++.
Diffstat (limited to 'tests')
-rw-r--r--tests/pysidetest/modelview_test.py33
-rw-r--r--tests/pysidetest/testview.cpp7
-rw-r--r--tests/pysidetest/testview.h2
3 files changed, 29 insertions, 13 deletions
diff --git a/tests/pysidetest/modelview_test.py b/tests/pysidetest/modelview_test.py
index ebab200..8629b61 100644
--- a/tests/pysidetest/modelview_test.py
+++ b/tests/pysidetest/modelview_test.py
@@ -12,12 +12,15 @@ class MyObject(QObject):
pass
class ListModelKeepsReference(QAbstractListModel):
+ def __init__(self, parent=None):
+ QAbstractListModel.__init__(self, parent)
+ self.obj = MyObject()
+ self.obj.setObjectName(object_name)
+
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):
@@ -29,22 +32,38 @@ class ListModelDoesntKeepsReference(QAbstractListModel):
obj.setObjectName(object_name)
return obj
+class ListModelThatReturnsString(QAbstractListModel):
+ def rowCount(self, parent=QModelIndex()):
+ return 1
+
+ def data(self, index, role):
+ self.obj = 'string'
+ return self.obj
+ #return 'string'
+
+
class ModelViewTest(unittest.TestCase):
- def testListModelKeepsReference(self):
- model = ListModelKeepsReference()
+ def testListModelDoesntKeepsReference(self):
+ model = ListModelDoesntKeepsReference()
view = TestView(model)
obj = view.getData()
- self.assertEqual(type(obj), MyObject)
+ self.assertEqual(type(obj), QObject)
self.assertEqual(obj.objectName(), object_name)
- def testListModelDoesntKeepsReference(self):
- model = ListModelDoesntKeepsReference()
+ def testListModelKeepsReference(self):
+ model = ListModelKeepsReference()
view = TestView(model)
obj = view.getData()
self.assertEqual(type(obj), MyObject)
self.assertEqual(obj.objectName(), object_name)
+ def testListModelThatReturnsString(self):
+ model = ListModelThatReturnsString()
+ view = TestView(model)
+ obj = view.getData()
+ self.assertEqual(type(obj), unicode)
+ self.assertEqual(obj, 'string')
if __name__ == '__main__':
unittest.main()
diff --git a/tests/pysidetest/testview.cpp b/tests/pysidetest/testview.cpp
index c7e9c6d..22ef9dd 100644
--- a/tests/pysidetest/testview.cpp
+++ b/tests/pysidetest/testview.cpp
@@ -2,14 +2,11 @@
#include <QDebug>
#include <stdio.h>
-QObject*
+QVariant
TestView::getData()
{
QModelIndex index;
QVariant data = m_model->data(index);
- QObject* obj = 0;
- if (data.canConvert<QObject*>())
- obj = data.value<QObject*>();
- return obj;
+ return data;
}
diff --git a/tests/pysidetest/testview.h b/tests/pysidetest/testview.h
index 2ae4162..1a65ea4 100644
--- a/tests/pysidetest/testview.h
+++ b/tests/pysidetest/testview.h
@@ -14,7 +14,7 @@ class PYSIDE_API TestView : public QObject
public:
TestView(QAbstractListModel* model, QObject* parent = 0) : QObject(parent), m_model(model) {}
QAbstractListModel* model() { return m_model; }
- QObject* getData();
+ QVariant getData();
private:
QAbstractListModel* m_model;
};