From 4f782f5d0f97633261690a19de7dfa62eeec2741 Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Mon, 15 Aug 2011 22:33:31 -0300 Subject: Added a test for an user defined primitive type from a required module. Also sorted the tests order alphabetically and fixed inject code for SampleNamespaces' passReferenceToObjectType method. --- tests/CMakeLists.txt | 1 + tests/libother/number.cpp | 11 +++++ tests/libother/number.h | 5 ++- .../usersprimitivefromothermodule_test.py | 47 ++++++++++++++++++++++ tests/samplebinding/typesystem_sample.xml | 2 +- 5 files changed, 64 insertions(+), 2 deletions(-) create mode 100755 tests/otherbinding/usersprimitivefromothermodule_test.py (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8430e0eca..6d8e41489 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -25,6 +25,7 @@ else() samplebinding/*_test.py otherbinding/*_test.py) endif() +list(SORT TEST_FILES) set(test_blacklist "") diff --git a/tests/libother/number.cpp b/tests/libother/number.cpp index 132624a5b..e2d7a00b1 100644 --- a/tests/libother/number.cpp +++ b/tests/libother/number.cpp @@ -40,3 +40,14 @@ operator*(const Point& p, const Number& n) return Point(p.x() * n.value(), p.y() * n.value()); } +Complex +Number::toComplex() const +{ + return Complex(m_value); +} + +Number +Number::fromComplex(Complex cpx) +{ + return Number(cpx.real()); +} diff --git a/tests/libother/number.h b/tests/libother/number.h index 9deeb680d..796987331 100644 --- a/tests/libother/number.h +++ b/tests/libother/number.h @@ -26,6 +26,7 @@ #include "libothermacros.h" #include "str.h" #include "point.h" +#include "complex.h" class LIBOTHER_API Number { @@ -38,6 +39,9 @@ public: friend LIBOTHER_API Point operator*(const Point&, const Number&); + Complex toComplex() const; + static Number fromComplex(Complex cpx); + private: int m_value; }; @@ -45,4 +49,3 @@ private: LIBOTHER_API Point operator*(const Point&, const Number&); #endif // NUMBER_H - diff --git a/tests/otherbinding/usersprimitivefromothermodule_test.py b/tests/otherbinding/usersprimitivefromothermodule_test.py new file mode 100755 index 000000000..480775ef7 --- /dev/null +++ b/tests/otherbinding/usersprimitivefromothermodule_test.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +# +# Contact: PySide team +# +# 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 user defined primitive type from a required module.''' + +import unittest +from other import Number + +class UserDefinedPrimitiveTypeFromRequiredModuleTest(unittest.TestCase): + + def testUsersPrimitiveFromRequiredModuleAsArgument(self): + '''static Number Number::fromComplex(Complex)''' + cpx = complex(3.0, 1.2) + number = Number.fromComplex(cpx) + self.assertEqual(number.value(), int(cpx.real)) + + def testUsersPrimitiveFromRequiredModuleAsReturnValue(self): + '''Complex Number::toComplex()''' + number = Number(12) + cpx = number.toComplex() + self.assertEqual(number.value(), int(cpx.real)) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/samplebinding/typesystem_sample.xml b/tests/samplebinding/typesystem_sample.xml index 91771699f..75d222b7b 100644 --- a/tests/samplebinding/typesystem_sample.xml +++ b/tests/samplebinding/typesystem_sample.xml @@ -153,7 +153,7 @@ // The dot in "%1." must be replaced with a "->" by the generator. - double %0 = %1.objectName().size(); + %RETURN_TYPE %0 = %1.objectName().size(); %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); -- cgit v1.2.3