summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-02 11:03:13 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-02 11:03:13 (GMT)
commit1c24bd02520a647415de5c220834d7bec265a8d0 (patch)
treeaee2e4580a0fb8b3027733119d4836566ac8b2d5 /Lib
parent5a2da3b3adc6d36fcebac0c4aeceffa1ff4e4d33 (diff)
downloadcpython-1c24bd02520a647415de5c220834d7bec265a8d0.zip
cpython-1c24bd02520a647415de5c220834d7bec265a8d0.tar.gz
cpython-1c24bd02520a647415de5c220834d7bec265a8d0.tar.bz2
Issue #8870: PyUnicode_AsWideCharString() doesn't count the trailing nul character
And write unit tests for PyUnicode_AsWideChar() and PyUnicode_AsWideCharString().
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_unicode.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/Lib/test/test_unicode.py b/Lib/test/test_unicode.py
index f6c38dd..2ac79fb 100644
--- a/Lib/test/test_unicode.py
+++ b/Lib/test/test_unicode.py
@@ -1394,6 +1394,45 @@ class UnicodeTest(string_tests.CommonTest,
'string, got a non-ASCII byte: 0xe9$',
format_unicode, b'unicode\xe9=%s', 'ascii')
+ # Test PyUnicode_AsWideChar()
+ def test_aswidechar(self):
+ from _testcapi import test_aswidechar
+ from ctypes import c_wchar, sizeof
+
+ wchar, size = test_aswidechar('abcdef', 2)
+ self.assertEquals(size, 2)
+ self.assertEquals(wchar, 'ab')
+
+ wchar, size = test_aswidechar('abc', 3)
+ self.assertEquals(size, 3)
+ self.assertEquals(wchar, 'abc')
+
+ wchar, size = test_aswidechar('abc', 4)
+ self.assertEquals(size, 3)
+ self.assertEquals(wchar, 'abc\0')
+
+ wchar, size = test_aswidechar('abc', 10)
+ self.assertEquals(size, 3)
+ self.assertEquals(wchar, 'abc\0')
+
+ wchar, size = test_aswidechar('abc\0def', 20)
+ self.assertEquals(size, 7)
+ self.assertEquals(wchar, 'abc\0def\0')
+
+ # Test PyUnicode_AsWideCharString()
+ def test_aswidecharstring(self):
+ from _testcapi import test_aswidecharstring
+ from ctypes import c_wchar, sizeof
+
+ wchar, size = test_aswidecharstring('abc')
+ self.assertEquals(size, 3)
+ self.assertEquals(wchar, 'abc\0')
+
+ wchar, size = test_aswidecharstring('abc\0def')
+ self.assertEquals(size, 7)
+ self.assertEquals(wchar, 'abc\0def\0')
+
+
def test_main():
support.run_unittest(__name__)