diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-03-30 16:42:08 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:19 -0300 |
commit | 009daead512428205ac730012d4d81ec49fc47e6 (patch) | |
tree | 555dfbdf7f81d0526c780060a17f435c6d6f3930 | |
parent | 93787c322144f3c11acf261655b89a25176ce528 (diff) |
Added unit tests to simulate the QPainter::drawText overloads.
The classes Rect and RectF were added to help with the imitation.
-rw-r--r-- | tests/libsample/overload.h | 17 | ||||
-rw-r--r-- | tests/libsample/rect.h | 80 | ||||
-rw-r--r-- | tests/samplebinding/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/samplebinding/global.h | 1 | ||||
-rw-r--r-- | tests/samplebinding/overload_test.py | 37 | ||||
-rw-r--r-- | tests/samplebinding/typesystem_sample.xml | 4 |
6 files changed, 139 insertions, 2 deletions
diff --git a/tests/libsample/overload.h b/tests/libsample/overload.h index 3ffd0ac92..c170be4a4 100644 --- a/tests/libsample/overload.h +++ b/tests/libsample/overload.h @@ -23,10 +23,13 @@ #ifndef OVERLOAD_H #define OVERLOAD_H +#include "echo.h" #include "str.h" #include "size.h" #include "point.h" +#include "pointf.h" #include "polygon.h" +#include "rect.h" #include "libsamplemacros.h" @@ -37,7 +40,10 @@ public: Function0, Function1, Function2, - Function3 + Function3, + Function4, + Function5, + Function6 }; enum ParamEnum { @@ -74,6 +80,15 @@ public: FunctionEnum strBufferOverloads(const Str& arg0, const char* arg1 = 0, bool arg2 = true) { return Function0; } FunctionEnum strBufferOverloads(unsigned char* arg0, int arg1) { return Function1; } FunctionEnum strBufferOverloads() { return Function2; } + + // Similar to QPainter::drawText(...) + FunctionEnum drawText(const Point& a0, const Str& a1) { return Function0; } + FunctionEnum drawText(const PointF& a0, const Str& a1) { return Function1; } + FunctionEnum drawText(const Rect& a0, int a1, const Str& a2) { return Function2; } + FunctionEnum drawText(const RectF& a0, int a1, const Str& a2) { return Function3; } + FunctionEnum drawText(const RectF& a0, const Str& a1, const Echo& a2 = Echo()) { return Function4; } + FunctionEnum drawText(int a0, int a1, const Str& a2) { return Function5; } + FunctionEnum drawText(int a0, int a1, int a2, int a3, int a4, const Str& a5) { return Function6; } }; class LIBSAMPLE_API Overload2 : public Overload diff --git a/tests/libsample/rect.h b/tests/libsample/rect.h new file mode 100644 index 000000000..e74d8f47a --- /dev/null +++ b/tests/libsample/rect.h @@ -0,0 +1,80 @@ +/* + * This file is part of the Shiboken Python Binding Generator project. + * + * Copyright (C) 2011 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 RECT_H +#define RECT_H + +#include "libsamplemacros.h" + +class LIBSAMPLE_API Rect +{ +public: + Rect() + { + m_left = m_top = 0; + m_right = m_bottom = -1; + } + Rect(int left, int top, int right, int bottom) + : m_left(left), m_top(top), m_right(right), m_bottom(bottom) { } + ~Rect() {} + inline int left() const { return m_left; } + inline int top() const { return m_top; } + inline int right() const { return m_right; } + inline int bottom() const { return m_bottom; } +private: + int m_left; + int m_top; + int m_right; + int m_bottom; +}; + +class LIBSAMPLE_API RectF +{ +public: + RectF() + { + m_left = m_top = 0; + m_right = m_bottom = -1; + } + RectF(int left, int top, int right, int bottom) + : m_left(left), m_top(top), m_right(right), m_bottom(bottom) { } + RectF(const Rect& other) + { + m_left = other.left(); + m_top = other.top(); + m_right = other.right(); + m_bottom = other.bottom(); + } + ~RectF() {} + inline double left() const { return m_left; } + inline double top() const { return m_top; } + inline double right() const { return m_right; } + inline double bottom() const { return m_bottom; } +private: + double m_left; + double m_top; + double m_right; + double m_bottom; +}; + +#endif // RECT_H + diff --git a/tests/samplebinding/CMakeLists.txt b/tests/samplebinding/CMakeLists.txt index f4244efed..b62f2d049 100644 --- a/tests/samplebinding/CMakeLists.txt +++ b/tests/samplebinding/CMakeLists.txt @@ -67,6 +67,8 @@ ${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphicdaughter_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/protectedpolymorphicgranddaughter_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/protectedproperty_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/protectedvirtualdestructor_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/rect_wrapper.cpp +${CMAKE_CURRENT_BINARY_DIR}/sample/rectf_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/reference_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/sample_module_wrapper.cpp ${CMAKE_CURRENT_BINARY_DIR}/sample/samplenamespace_wrapper.cpp diff --git a/tests/samplebinding/global.h b/tests/samplebinding/global.h index f8781eef8..98738a38a 100644 --- a/tests/samplebinding/global.h +++ b/tests/samplebinding/global.h @@ -37,6 +37,7 @@ #include "privatector.h" #include "privatedtor.h" #include "protected.h" +#include "rect.h" #include "reference.h" #include "removednamespaces.h" #include "samplenamespace.h" diff --git a/tests/samplebinding/overload_test.py b/tests/samplebinding/overload_test.py index 58a4c99c5..14a30c88b 100644 --- a/tests/samplebinding/overload_test.py +++ b/tests/samplebinding/overload_test.py @@ -28,7 +28,7 @@ import unittest -from sample import Overload, Point, Polygon, Size +from sample import Echo, Overload, Point, PointF, Polygon, Rect, RectF, Size, Str class OverloadTest(unittest.TestCase): '''Test case for Overload class''' @@ -81,6 +81,41 @@ class OverloadTest(unittest.TestCase): self.assertEqual(overload.wrapperIntIntOverloads(Point(), 1, 2), Overload.Function0) self.assertEqual(overload.wrapperIntIntOverloads(Polygon(), 1, 2), Overload.Function1) + def testDrawTextPointAndStr(self): + overload = Overload() + self.assertEqual(overload.drawText(Point(), Str()), Overload.Function0) + self.assertEqual(overload.drawText(Point(), ''), Overload.Function0) + self.assertEqual(overload.drawText(PointF(), Str()), Overload.Function1) + self.assertEqual(overload.drawText(PointF(), ''), Overload.Function1) + + def testDrawTextRectIntStr(self): + overload = Overload() + self.assertEqual(overload.drawText(Rect(), 1, Str()), Overload.Function2) + self.assertEqual(overload.drawText(Rect(), 1, ''), Overload.Function2) + self.assertEqual(overload.drawText(RectF(), 1, Str()), Overload.Function3) + self.assertEqual(overload.drawText(RectF(), 1, ''), Overload.Function3) + + def testDrawTextRectFStrEcho(self): + overload = Overload() + self.assertEqual(overload.drawText(RectF(), Str()), Overload.Function4) + self.assertEqual(overload.drawText(RectF(), ''), Overload.Function4) + self.assertEqual(overload.drawText(RectF(), Str(), Echo()), Overload.Function4) + self.assertEqual(overload.drawText(RectF(), '', Echo()), Overload.Function4) + self.assertEqual(overload.drawText(Rect(), Str()), Overload.Function4) + self.assertEqual(overload.drawText(Rect(), ''), Overload.Function4) + self.assertEqual(overload.drawText(Rect(), Str(), Echo()), Overload.Function4) + self.assertEqual(overload.drawText(Rect(), '', Echo()), Overload.Function4) + + def testDrawTextIntIntStr(self): + overload = Overload() + self.assertEqual(overload.drawText(1, 2, Str()), Overload.Function5) + self.assertEqual(overload.drawText(1, 2, ''), Overload.Function5) + + def testDrawTextIntIntIntIntStr(self): + overload = Overload() + self.assertEqual(overload.drawText(1, 2, 3, 4, 5, Str()), Overload.Function6) + self.assertEqual(overload.drawText(1, 2, 3, 4, 5, ''), Overload.Function6) + if __name__ == '__main__': unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 35ef4220b..a3e4c830b 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -45,6 +45,7 @@ <include file-name="map" location="global"/> </container-type> <container-type name="List" type="list" /> + <add-function signature="cacheSize()" return-type="int"> <inject-code class="target"> %PYARG_0 = %CONVERTTOPYTHON[int](Shiboken::BindingManager::instance().getAllPyObjects().size()); @@ -1068,6 +1069,9 @@ </add-function> </value-type> + <value-type name="Rect" /> + <value-type name="RectF" /> + <value-type name="Polygon"> <modify-function signature="stealOwnershipFromPython(Point*)"> <modify-argument index="1"> |