diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-01 18:33:45 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-01 18:55:38 -0300 |
commit | 0f8b230fd2dbc1c618ce8fcc84efa5d741ce1a0f (patch) | |
tree | 698d2e7cc8595683eab2b81ac547944358a3f4c6 /tests | |
parent | 95ee90a0c334b587860d4e54b7bf8c079379d7c6 (diff) |
Improved tests for the QLayout-like ObjectTypeLayout.
In the new test case an ObjectType uses a layout that contains another
layout, both created in C++, and then get deleted. Custom code was used
to achieve the correct parentship handling
Reviewed by Hugo Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/objecttypelayout.h | 1 | ||||
-rwxr-xr-x | tests/samplebinding/objecttypelayout_test.py | 103 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 31 |
3 files changed, 129 insertions, 6 deletions
diff --git a/tests/libsample/objecttypelayout.h b/tests/libsample/objecttypelayout.h index ba39fd330..5662ac339 100644 --- a/tests/libsample/objecttypelayout.h +++ b/tests/libsample/objecttypelayout.h @@ -48,6 +48,7 @@ public: std::list<ObjectType*> objects() const; virtual bool isLayoutType() { return true; } + static ObjectTypeLayout* create() { return new ObjectTypeLayout(); } private: std::list<ObjectType*> m_objects; diff --git a/tests/samplebinding/objecttypelayout_test.py b/tests/samplebinding/objecttypelayout_test.py index a21b03d00..444ee8b5d 100755 --- a/tests/samplebinding/objecttypelayout_test.py +++ b/tests/samplebinding/objecttypelayout_test.py @@ -141,6 +141,51 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l1.parent(), p1) self.assertEqual(l2.parent(), l1) + del p1 + + self.assertRaises(RuntimeError, c1.objectName) + self.assertRaises(RuntimeError, c2.objectName) + self.assertRaises(RuntimeError, c3.objectName) + self.assertRaises(RuntimeError, c4.objectName) + self.assertRaises(RuntimeError, l1.objectName) + self.assertRaises(RuntimeError, l2.objectName) + + def testObjectTypeLayoutInsideAnotherLayoutAndEveryoneCreatedInCpp(self): + '''Adds one ObjectTypeLayout to another and sets the parent to an ObjectType. All the objects are created in C++.''' + p1 = ObjectType.create() + + l1 = ObjectTypeLayout.create() + c1 = ObjectType.create() + l1.addObject(c1) + c2 = ObjectType.create() + l1.addObject(c2) + + l2 = ObjectTypeLayout.create() + c3 = ObjectType.create() + l2.addObject(c3) + c4 = ObjectType.create() + l2.addObject(c4) + + l1.addObject(l2) + + p1.setLayout(l1) + + self.assertEqual(c1.parent(), p1) + self.assertEqual(c2.parent(), p1) + self.assertEqual(c3.parent(), p1) + self.assertEqual(c4.parent(), p1) + self.assertEqual(l1.parent(), p1) + self.assertEqual(l2.parent(), l1) + + del p1 + + self.assertRaises(RuntimeError, c1.objectName) + self.assertRaises(RuntimeError, c2.objectName) + self.assertRaises(RuntimeError, c3.objectName) + self.assertRaises(RuntimeError, c4.objectName) + self.assertRaises(RuntimeError, l1.objectName) + self.assertRaises(RuntimeError, l2.objectName) + def testTransferNestedLayoutsBetweenObjects(self): '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object.''' p1 = ObjectType() @@ -179,6 +224,64 @@ class ObjectTypeLayoutTest(unittest.TestCase): self.assertEqual(l1.parent(), p2) self.assertEqual(l2.parent(), l1) + del p2 + + self.assertRaises(RuntimeError, c1.objectName) + self.assertRaises(RuntimeError, c2.objectName) + self.assertRaises(RuntimeError, c3.objectName) + self.assertRaises(RuntimeError, c4.objectName) + self.assertRaises(RuntimeError, l1.objectName) + self.assertRaises(RuntimeError, l2.objectName) + + def testTransferNestedLayoutsBetweenObjectsAndEveryoneCreatedInCpp(self): + '''Adds one ObjectTypeLayout to another, sets the parent to an ObjectType and then transfer it to another object. + All the objects are created in C++.''' + p1 = ObjectType.create() + p2 = ObjectType.create() + + l1 = ObjectTypeLayout.create() + c1 = ObjectType.create() + l1.addObject(c1) + c2 = ObjectType.create() + l1.addObject(c2) + + l2 = ObjectTypeLayout.create() + c3 = ObjectType.create() + l2.addObject(c3) + c4 = ObjectType.create() + l2.addObject(c4) + + l1.addObject(l2) + + p1.setLayout(l1) + + self.assertEqual(c1.parent(), p1) + self.assertEqual(c2.parent(), p1) + self.assertEqual(c3.parent(), p1) + self.assertEqual(c4.parent(), p1) + self.assertEqual(l1.parent(), p1) + self.assertEqual(l2.parent(), l1) + + p2.setLayout(l1) + del p1 + + self.assertEqual(c1.parent(), p2) + self.assertEqual(c2.parent(), p2) + self.assertEqual(c3.parent(), p2) + self.assertEqual(c4.parent(), p2) + self.assertEqual(l1.parent(), p2) + self.assertEqual(l2.parent(), l1) + + del p2 + + self.assertRaises(RuntimeError, c1.objectName) + self.assertRaises(RuntimeError, c2.objectName) + self.assertRaises(RuntimeError, c3.objectName) + self.assertRaises(RuntimeError, c4.objectName) + self.assertRaises(RuntimeError, l1.objectName) + self.assertRaises(RuntimeError, l2.objectName) + + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 9129d31c6..fc993ebdf 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -79,16 +79,29 @@ <parent index="1" action="add"/> </modify-argument> </modify-function> + <inject-code class="native" position="beginning"> + static void reparent_layout_items(PyObject* parent, PyObject* layout) + { + const ObjectTypeList& objChildren = PyObjectTypeLayout_cptr(layout)->objects(); + ObjectTypeList::const_iterator it = objChildren.begin(); + for (; it != objChildren.end(); ++it) { + if ((*it)->isLayoutType()) { + ObjectTypeLayout* l = reinterpret_cast<ObjectTypeLayout*>(*it); + reparent_layout_items(parent, %CONVERTTOPYTHON[ObjectTypeLayout*](l)); + Shiboken::setParent(layout, %CONVERTTOPYTHON[ObjectTypeLayout*](l)); + } else { + Shiboken::setParent(parent, %CONVERTTOPYTHON[ObjectType*](*it)); + } + } + } + </inject-code> <modify-function signature="setLayout(ObjectTypeLayout*)"> <modify-argument index="1"> <parent index="this" action="add"/> </modify-argument> <inject-code class="target" position="end"> - const ObjectTypeList& objChildren = %CPPSELF.children(); - ObjectTypeList::const_iterator it = objChildren.begin(); - for (; it != objChildren.end(); ++it) { - Shiboken::setParent(%PYSELF, %CONVERTTOPYTHON[ObjectType*](*it)); - } + if (%PYARG_1 != Py_None) + reparent_layout_items(%PYSELF, %PYARG_1); </inject-code> </modify-function> <modify-function signature="takeChild(ObjectType*)"> @@ -117,7 +130,13 @@ </inject-code> </modify-function> </object-type> - <object-type name="ObjectTypeLayout" /> + <object-type name="ObjectTypeLayout"> + <modify-function signature="create()"> + <modify-argument index="return"> + <define-ownership owner="target"/> + </modify-argument> + </modify-function> + </object-type> <value-type name="Event"/> |