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

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

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 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_returnfuncptrs.py ('k') | Lib/ctypes/test/test_stringptr.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 from ctypes import * 3 from ctypes import *
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 class SlicesTestCase(unittest.TestCase): 8 class SlicesTestCase(unittest.TestCase):
8 def test_getslice_cint(self): 9 def test_getslice_cint(self):
9 a = (c_int * 100)(*range(1100, 1200)) 10 a = (c_int * 100)(*range(1100, 1200))
10 b = list(range(1100, 1200)) 11 b = list(range(1100, 1200))
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 ["a", "b", "c", "d", "e"]) 56 ["a", "b", "c", "d", "e"])
56 # TypeError: int expected instead of float instance 57 # TypeError: int expected instead of float instance
57 self.assertRaises(TypeError, setitem, a, slice(0, 5), 58 self.assertRaises(TypeError, setitem, a, slice(0, 5),
58 [1, 2, 3, 4, 3.14]) 59 [1, 2, 3, 4, 3.14])
59 # ValueError: Can only assign sequence of same size 60 # ValueError: Can only assign sequence of same size
60 self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32)) 61 self.assertRaises(ValueError, setitem, a, slice(0, 5), range(32))
61 62
62 def test_char_ptr(self): 63 def test_char_ptr(self):
63 s = b"abcdefghijklmnopqrstuvwxyz" 64 s = b"abcdefghijklmnopqrstuvwxyz"
64 65
65 dll = CDLL(_ctypes_test.__file__) 66 dll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))
66 dll.my_strdup.restype = POINTER(c_char) 67 dll.my_strdup.restype = POINTER(c_char)
67 dll.my_free.restype = None 68 dll.my_free.restype = None
68 res = dll.my_strdup(s) 69 res = dll.my_strdup(s)
69 self.assertEqual(res[:len(s)], s) 70 self.assertEqual(res[:len(s)], s)
70 self.assertEqual(res[:3], s[:3]) 71 self.assertEqual(res[:3], s[:3])
71 self.assertEqual(res[:len(s):], s) 72 self.assertEqual(res[:len(s):], s)
72 self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) 73 self.assertEqual(res[len(s)-1:-1:-1], s[::-1])
73 self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) 74 self.assertEqual(res[len(s)-1:5:-7], s[:5:-7])
74 self.assertEqual(res[0:-1:-1], s[0::-1]) 75 self.assertEqual(res[0:-1:-1], s[0::-1])
75 76
(...skipping 11 matching lines...) Expand all
87 res, slice(0, 5), "abcde") 88 res, slice(0, 5), "abcde")
88 dll.my_free(res) 89 dll.my_free(res)
89 90
90 dll.my_strdup.restype = POINTER(c_byte) 91 dll.my_strdup.restype = POINTER(c_byte)
91 res = dll.my_strdup(s) 92 res = dll.my_strdup(s)
92 self.assertEqual(res[:len(s)], list(range(ord("a"), ord("z")+1))) 93 self.assertEqual(res[:len(s)], list(range(ord("a"), ord("z")+1)))
93 self.assertEqual(res[:len(s):], list(range(ord("a"), ord("z")+1))) 94 self.assertEqual(res[:len(s):], list(range(ord("a"), ord("z")+1)))
94 dll.my_free(res) 95 dll.my_free(res)
95 96
96 def test_char_ptr_with_free(self): 97 def test_char_ptr_with_free(self):
97 dll = CDLL(_ctypes_test.__file__) 98 dll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))
98 s = b"abcdefghijklmnopqrstuvwxyz" 99 s = b"abcdefghijklmnopqrstuvwxyz"
99 100
100 class allocated_c_char_p(c_char_p): 101 class allocated_c_char_p(c_char_p):
101 pass 102 pass
102 103
103 dll.my_free.restype = None 104 dll.my_free.restype = None
104 def errcheck(result, func, args): 105 def errcheck(result, func, args):
105 retval = result.value 106 retval = result.value
106 dll.my_free(result) 107 dll.my_free(result)
107 return retval 108 return retval
(...skipping 15 matching lines...) Expand all
123 self.assertEqual(p[::], s) 124 self.assertEqual(p[::], s)
124 self.assertEqual(p[::-1], s[::-1]) 125 self.assertEqual(p[::-1], s[::-1])
125 self.assertEqual(p[5::-2], s[5::-2]) 126 self.assertEqual(p[5::-2], s[5::-2])
126 self.assertEqual(p[2:5:-3], s[2:5:-3]) 127 self.assertEqual(p[2:5:-3], s[2:5:-3])
127 128
128 129
129 @need_symbol('c_wchar') 130 @need_symbol('c_wchar')
130 def test_wchar_ptr(self): 131 def test_wchar_ptr(self):
131 s = "abcdefghijklmnopqrstuvwxyz\0" 132 s = "abcdefghijklmnopqrstuvwxyz\0"
132 133
133 dll = CDLL(_ctypes_test.__file__) 134 dll = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE ']))
134 dll.my_wcsdup.restype = POINTER(c_wchar) 135 dll.my_wcsdup.restype = POINTER(c_wchar)
135 dll.my_wcsdup.argtypes = POINTER(c_wchar), 136 dll.my_wcsdup.argtypes = POINTER(c_wchar),
136 dll.my_free.restype = None 137 dll.my_free.restype = None
137 res = dll.my_wcsdup(s) 138 res = dll.my_wcsdup(s)
138 self.assertEqual(res[:len(s)], s) 139 self.assertEqual(res[:len(s)], s)
139 self.assertEqual(res[:len(s):], s) 140 self.assertEqual(res[:len(s):], s)
140 self.assertEqual(res[len(s)-1:-1:-1], s[::-1]) 141 self.assertEqual(res[len(s)-1:-1:-1], s[::-1])
141 self.assertEqual(res[len(s)-1:5:-7], s[:5:-7]) 142 self.assertEqual(res[len(s)-1:5:-7], s[:5:-7])
142 143
143 import operator 144 import operator
(...skipping 14 matching lines...) Expand all
158 self.assertEqual(res[:len(s)-1], tmpl) 159 self.assertEqual(res[:len(s)-1], tmpl)
159 self.assertEqual(res[:len(s)-1:], tmpl) 160 self.assertEqual(res[:len(s)-1:], tmpl)
160 self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1]) 161 self.assertEqual(res[len(s)-2:-1:-1], tmpl[::-1])
161 self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7]) 162 self.assertEqual(res[len(s)-2:5:-7], tmpl[:5:-7])
162 dll.my_free(res) 163 dll.my_free(res)
163 164
164 ################################################################ 165 ################################################################
165 166
166 if __name__ == "__main__": 167 if __name__ == "__main__":
167 unittest.main() 168 unittest.main()
OLDNEW
« no previous file with comments | « Lib/ctypes/test/test_returnfuncptrs.py ('k') | Lib/ctypes/test/test_stringptr.py » ('j') | no next file with comments »

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