diff options
author | Hugo Lima <hugo.lima@openbossa.org> | 2009-11-30 17:20:34 -0200 |
---|---|---|
committer | Hugo Lima <hugo.lima@openbossa.org> | 2009-11-30 17:31:55 -0200 |
commit | fe71552f4f254d84f2563ee24f108f5dd2c559c6 (patch) | |
tree | d30b5c8248b564ba2f6cfc8cd4e83e350930459c /tests | |
parent | fdd64b248fb7bf6c6da3d3785e1ce2ec8d26bdbb (diff) |
Added tests for something like QLayout.
Reviewed by Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/libsample/objecttype.cpp | 10 | ||||
-rw-r--r-- | tests/libsample/objecttype.h | 8 | ||||
-rw-r--r-- | tests/libsample/objecttypelayout.cpp | 45 | ||||
-rw-r--r-- | tests/libsample/objecttypelayout.h | 53 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rwxr-xr-x | tests/samplebinding/objecttypelayout_test.py | 62 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 11 |
9 files changed, 191 insertions, 1 deletions
diff --git a/tests/libsample/CMakeLists.txt b/tests/libsample/CMakeLists.txt index 84a3061a1..8d4a890d5 100644 --- a/tests/libsample/CMakeLists.txt +++ b/tests/libsample/CMakeLists.txt @@ -15,6 +15,7 @@ modifications.cpp mapuser.cpp multiple_derived.cpp objecttype.cpp +objecttypelayout.cpp overload.cpp overloadsort.cpp pairuser.cpp diff --git a/tests/libsample/objecttype.cpp b/tests/libsample/objecttype.cpp index 867d61cce..ef72f11fe 100644 --- a/tests/libsample/objecttype.cpp +++ b/tests/libsample/objecttype.cpp @@ -33,6 +33,7 @@ */ #include "objecttype.h" +#include "objecttypelayout.h" #include <algorithm> using namespace std; @@ -116,3 +117,12 @@ ObjectType::event(Event* event) return true; } +void ObjectType::setObjectLayout(ObjectTypeLayout* layout) +{ + layout->setParent(this); + std::list<ObjectType*> objects = layout->objects(); + std::list<ObjectType*>::const_iterator it = objects.begin(); + for (; it != objects.end(); ++it) + (*it)->setParent(this); +} + diff --git a/tests/libsample/objecttype.h b/tests/libsample/objecttype.h index 7ed9c5e04..4435ab6c4 100644 --- a/tests/libsample/objecttype.h +++ b/tests/libsample/objecttype.h @@ -54,10 +54,13 @@ private: EventType m_eventType; }; +class ObjectTypeLayout; +class ObjectType; +typedef std::list<ObjectType*> ObjectTypeList; + class LIBSAMPLE_API ObjectType { public: - typedef std::list<ObjectType*> ObjectTypeList; ObjectType(ObjectType* parent = 0); virtual ~ObjectType(); @@ -78,6 +81,9 @@ public: // Returns true if the event is processed. virtual bool event(Event* event); + // This nonsense method emulate QWidget.setLayout method + // All layout objects will became children of this object. + void setObjectLayout(ObjectTypeLayout* layout); private: ObjectType(const ObjectType&); diff --git a/tests/libsample/objecttypelayout.cpp b/tests/libsample/objecttypelayout.cpp new file mode 100644 index 000000000..06c4555b4 --- /dev/null +++ b/tests/libsample/objecttypelayout.cpp @@ -0,0 +1,45 @@ +/* +* 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 "objecttypelayout.h" + +void ObjectTypeLayout::addObject(ObjectType* obj) +{ + m_objects.push_back(obj); +} + +std::list< ObjectType* > ObjectTypeLayout::objects() const +{ + return m_objects; +} diff --git a/tests/libsample/objecttypelayout.h b/tests/libsample/objecttypelayout.h new file mode 100644 index 000000000..7d25e09be --- /dev/null +++ b/tests/libsample/objecttypelayout.h @@ -0,0 +1,53 @@ +/* +* 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 OBJECTTYPELAYOUT_H +#define OBJECTTYPELAYOUT_H + +#include "libsamplemacros.h" +#include "objecttype.h" +#include <list> + +class ObjectType; + +class LIBSAMPLE_API ObjectTypeLayout : public ObjectType +{ +public: + void addObject(ObjectType* obj); + std::list<ObjectType*> objects() const; +private: + std::list<ObjectType*> m_objects; +}; + +#endif diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index a9d2118fd..1a87f6425 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -34,6 +34,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/mderived5_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/modifications_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/nondefaultctor_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/objecttype_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/objecttypelayout_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/oddbooluser_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/overload_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/pairuser_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index d08f0f6f0..58daebb44 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -14,6 +14,7 @@ #include "multiple_derived.h" #include "nondefaultctor.h" #include "objecttype.h" +#include "objecttypelayout.h" #include "oddbool.h" #include "overload.h" #include "pairuser.h" diff --git a/tests/samplebinding/objecttypelayout_test.py b/tests/samplebinding/objecttypelayout_test.py new file mode 100755 index 000000000..74f7f5c64 --- /dev/null +++ b/tests/samplebinding/objecttypelayout_test.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings 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. +# # +# 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 + +'''Tests ObjectTypeLayout class''' + +import sys +import unittest + +from sample import * + + +class ObjectTypeLayoutTest(unittest.TestCase): + '''Test cases ObjectTypeLayout class''' + + def testObjectTypeLayout(self): + + '''ObjectType.setLayout.''' + p1 = ObjectType.create() + c1 = ObjectType.create() + c2 = ObjectType.create() + c3 = ObjectType.create() + layout = ObjectTypeLayout() + layout.addObject(c1) + layout.addObject(c2) + layout.addObject(c3) + self.assertEqual(c1.parent(), None) + self.assertEqual(c2.parent(), None) + self.assertEqual(c3.parent(), None) + + p1.setObjectLayout(layout) + del p1 # This must kill c1, c2 and c3 + self.assertRaises(RuntimeError, c1.objectName) + self.assertRaises(RuntimeError, c2.objectName) + self.assertRaises(RuntimeError, c3.objectName) + self.assertRaises(RuntimeError, layout.objectName) + +if __name__ == '__main__': + unittest.main() + diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index ab4696d14..647eacf57 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -74,7 +74,18 @@ <parent index="this" action="add"/> </modify-argument> </modify-function> + <modify-function signature="setObjectLayout(ObjectTypeLayout*)"> + <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)); + } + </inject-code> + </modify-function> </object-type> + <object-type name="ObjectTypeLayout" /> + <value-type name="Event"/> <value-type name="BlackBox"> |