aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-15 22:33:31 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:12 -0300
commit4f782f5d0f97633261690a19de7dfa62eeec2741 (patch)
tree52d5aac8b160e288308d40ddcb86571929f8d73c /tests
parent9c5a9169cf0d710fe4cfab305e096623d8cbdaaf (diff)
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.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/libother/number.cpp11
-rw-r--r--tests/libother/number.h5
-rwxr-xr-xtests/otherbinding/usersprimitivefromothermodule_test.py47
-rw-r--r--tests/samplebinding/typesystem_sample.xml2
5 files changed, 64 insertions, 2 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 8430e0ec..6d8e4148 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 132624a5..e2d7a00b 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 9deeb680..79698733 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 00000000..480775ef
--- /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 <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 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 91771699..75d222b7 100644
--- a/tests/samplebinding/typesystem_sample.xml
+++ b/tests/samplebinding/typesystem_sample.xml
@@ -153,7 +153,7 @@
<add-function signature="passReferenceToObjectType(ObjectType*)" return-type="int">
<inject-code>
// 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);
</inject-code>
</add-function>