Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(170128)

Side by Side Diff: Lib/ctypes/test/test_unicode.py

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/ctypes/test/test_stringptr.py ('k') | Lib/ctypes/test/test_values.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os
1 import unittest 2 import unittest
2 import ctypes 3 import ctypes
3 from ctypes.test import need_symbol 4 from ctypes.test import need_symbol
4 5
5 import _ctypes_test 6 import _ctypes_test
6 7
7 @need_symbol('c_wchar') 8 @need_symbol('c_wchar')
8 class UnicodeTestCase(unittest.TestCase): 9 class UnicodeTestCase(unittest.TestCase):
9 def test_wcslen(self): 10 def test_wcslen(self):
10 dll = ctypes.CDLL(_ctypes_test.__file__) 11 dll = ctypes.CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXE CUTABLE']))
11 wcslen = dll.my_wcslen 12 wcslen = dll.my_wcslen
12 wcslen.argtypes = [ctypes.c_wchar_p] 13 wcslen.argtypes = [ctypes.c_wchar_p]
13 14
14 self.assertEqual(wcslen("abc"), 3) 15 self.assertEqual(wcslen("abc"), 3)
15 self.assertEqual(wcslen("ab\u2070"), 3) 16 self.assertEqual(wcslen("ab\u2070"), 3)
16 self.assertRaises(ctypes.ArgumentError, wcslen, b"ab\xe4") 17 self.assertRaises(ctypes.ArgumentError, wcslen, b"ab\xe4")
17 18
18 def test_buffers(self): 19 def test_buffers(self):
19 buf = ctypes.create_unicode_buffer("abc") 20 buf = ctypes.create_unicode_buffer("abc")
20 self.assertEqual(len(buf), 3+1) 21 self.assertEqual(len(buf), 3+1)
21 22
22 buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc") 23 buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc")
23 self.assertEqual(buf[:], "ab\xe4\xf6\xfc\0") 24 self.assertEqual(buf[:], "ab\xe4\xf6\xfc\0")
24 self.assertEqual(buf[::], "ab\xe4\xf6\xfc\0") 25 self.assertEqual(buf[::], "ab\xe4\xf6\xfc\0")
25 self.assertEqual(buf[::-1], '\x00\xfc\xf6\xe4ba') 26 self.assertEqual(buf[::-1], '\x00\xfc\xf6\xe4ba')
26 self.assertEqual(buf[::2], 'a\xe4\xfc') 27 self.assertEqual(buf[::2], 'a\xe4\xfc')
27 self.assertEqual(buf[6:5:-1], "") 28 self.assertEqual(buf[6:5:-1], "")
28 29
29 func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p 30 func = ctypes.CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))._testfunc_p_p
30 31
31 class StringTestCase(UnicodeTestCase): 32 class StringTestCase(UnicodeTestCase):
32 def setUp(self): 33 def setUp(self):
33 func.argtypes = [ctypes.c_char_p] 34 func.argtypes = [ctypes.c_char_p]
34 func.restype = ctypes.c_char_p 35 func.restype = ctypes.c_char_p
35 36
36 def tearDown(self): 37 def tearDown(self):
37 func.argtypes = None 38 func.argtypes = None
38 func.restype = ctypes.c_int 39 func.restype = ctypes.c_int
39 40
40 def test_func(self): 41 def test_func(self):
41 self.assertEqual(func(b"abc\xe4"), b"abc\xe4") 42 self.assertEqual(func(b"abc\xe4"), b"abc\xe4")
42 43
43 def test_buffers(self): 44 def test_buffers(self):
44 buf = ctypes.create_string_buffer(b"abc") 45 buf = ctypes.create_string_buffer(b"abc")
45 self.assertEqual(len(buf), 3+1) 46 self.assertEqual(len(buf), 3+1)
46 47
47 buf = ctypes.create_string_buffer(b"ab\xe4\xf6\xfc") 48 buf = ctypes.create_string_buffer(b"ab\xe4\xf6\xfc")
48 self.assertEqual(buf[:], b"ab\xe4\xf6\xfc\0") 49 self.assertEqual(buf[:], b"ab\xe4\xf6\xfc\0")
49 self.assertEqual(buf[::], b"ab\xe4\xf6\xfc\0") 50 self.assertEqual(buf[::], b"ab\xe4\xf6\xfc\0")
50 self.assertEqual(buf[::-1], b'\x00\xfc\xf6\xe4ba') 51 self.assertEqual(buf[::-1], b'\x00\xfc\xf6\xe4ba')
51 self.assertEqual(buf[::2], b'a\xe4\xfc') 52 self.assertEqual(buf[::2], b'a\xe4\xfc')
52 self.assertEqual(buf[6:5:-1], b"") 53 self.assertEqual(buf[6:5:-1], b"")
53 54
54 55
55 if __name__ == '__main__': 56 if __name__ == '__main__':
56 unittest.main() 57 unittest.main()
OLDNEW
« no previous file with comments | « Lib/ctypes/test/test_stringptr.py ('k') | Lib/ctypes/test/test_values.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+