diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-20 17:31:24 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-02-20 18:20:32 -0300 |
commit | 92a957859814d40d86e7e1287ec1b9c2b717a923 (patch) | |
tree | ac5fd509990fc5e952dc5230ad37be34f039c74d /tests | |
parent | 75507160e33339291d391cbdd0893fc0c9d4d3f5 (diff) |
Adds test for C++ 'const char*' argument receiving a Python None as a null pointer.
The test function 'countCharacters(const char*)' now returns -1 when
receiving a null pointer.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/libsample/functions.cpp | 3 | ||||
-rwxr-xr-x | tests/samplebinding/receive_null_cstring_test.py | 49 |
2 files changed, 52 insertions, 0 deletions
diff --git a/tests/libsample/functions.cpp b/tests/libsample/functions.cpp index d02b7a19d..aebd9b83b 100644 --- a/tests/libsample/functions.cpp +++ b/tests/libsample/functions.cpp @@ -85,6 +85,8 @@ multiplyPair(std::pair<double, double> pair) int countCharacters(const char* text) { + if (!text) + return -1; int count; for(count = 0; text[count] != '\0'; count++) ; @@ -176,3 +178,4 @@ acceptDouble(double x) { return x; } + diff --git a/tests/samplebinding/receive_null_cstring_test.py b/tests/samplebinding/receive_null_cstring_test.py new file mode 100755 index 000000000..978433fda --- /dev/null +++ b/tests/samplebinding/receive_null_cstring_test.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# This file is part of the Shiboken Python Bindings Generator project. +# +# Copyright (C) 2010 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 a function that could receive a NULL pointer in a '[const] char*' parameter.''' + +import unittest + +from sample import countCharacters + +class ReceiveNullCStringTest(unittest.TestCase): + '''Test case for a function that could receive a NULL pointer in a '[const] char*' parameter.''' + + def testBasic(self): + '''The test function should be working for the basic cases.''' + a = '' + b = 'abc' + self.assertEqual(countCharacters(a), len(a)) + self.assertEqual(countCharacters(b), len(b)) + + def testReceiveNull(self): + '''The test function returns '-1' when receives a None value instead of a string.''' + self.assertEqual(countCharacters(None), -1) + +if __name__ == '__main__': + unittest.main() + |