diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-07 13:23:59 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-07 13:48:56 -0300 |
commit | 0e532bfaf3d4eb710aa5999764942337b9342304 (patch) | |
tree | 14f6befe555df4500e298b0464d4f229260787cf /tests | |
parent | fbf30507a2317bf88472ab5c67dd2abd1636bc18 (diff) |
Adds Overflow check to integer types conversions.
Unit tests were added also.
Reviewed by Hugo Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/functions.cpp | 6 | ||||
-rw-r--r-- | tests/libsample/functions.h | 2 | ||||
-rwxr-xr-x | tests/samplebinding/overflow_test.py | 50 |
3 files changed, 58 insertions, 0 deletions
diff --git a/tests/libsample/functions.cpp b/tests/libsample/functions.cpp index 15fb6fb14..8a7416bc6 100644 --- a/tests/libsample/functions.cpp +++ b/tests/libsample/functions.cpp @@ -135,3 +135,9 @@ returnNullValueTypePointer() return 0; } +unsigned int +doubleUnsignedInt(unsigned int value) +{ + return value * 2; +} + diff --git a/tests/libsample/functions.h b/tests/libsample/functions.h index f6cf81b18..2629d3907 100644 --- a/tests/libsample/functions.h +++ b/tests/libsample/functions.h @@ -72,5 +72,7 @@ LIBSAMPLE_API Event* returnNullValueTypePointer(); LIBSAMPLE_API GlobalOverloadFuncEnum overloadedFunc(int val); LIBSAMPLE_API GlobalOverloadFuncEnum overloadedFunc(double val); +LIBSAMPLE_API unsigned int doubleUnsignedInt(unsigned int value); + #endif // FUNCTIONS_H diff --git a/tests/samplebinding/overflow_test.py b/tests/samplebinding/overflow_test.py new file mode 100755 index 000000000..b53e4f3b5 --- /dev/null +++ b/tests/samplebinding/overflow_test.py @@ -0,0 +1,50 @@ +#!/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 + +'''Test case for overflowing C++ numeric types.''' + +import sys +import unittest + +from sample import doubleUnsignedInt + +class OverflowTest(unittest.TestCase): + '''Test case for overflowing C++ numeric types.''' + + def testUnsignedInt(self): + '''C++ function receives an unsigned int argument and raise OverflowError if the value is negative.''' + val = 100 + self.assertEqual(doubleUnsignedInt(val), 2 * val) + val *= -1 + self.assertRaises(OverflowError, doubleUnsignedInt, val) + + def testOverflow(self): + '''Calls function with unsigned int parameter using an overflowing value.''' + self.assertRaises(OverflowError, doubleUnsignedInt, 42415335332353253) + +if __name__ == '__main__': + unittest.main() + |