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

Side by Side Diff: Lib/ctypes/test/test_libc.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_functions.py ('k') | Lib/ctypes/test/test_parameters.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 3
3 from ctypes import * 4 from ctypes import *
4 import _ctypes_test 5 import _ctypes_test
5 6
6 lib = CDLL(_ctypes_test.__file__) 7 lib = CDLL(getattr(_ctypes_test, '__file__', os.environ['TEST_EXECUTABLE']))
7 8
8 def three_way_cmp(x, y): 9 def three_way_cmp(x, y):
9 """Return -1 if x < y, 0 if x == y and 1 if x > y""" 10 """Return -1 if x < y, 0 if x == y and 1 if x > y"""
10 return (x > y) - (x < y) 11 return (x > y) - (x < y)
11 12
12 class LibTest(unittest.TestCase): 13 class LibTest(unittest.TestCase):
13 def test_sqrt(self): 14 def test_sqrt(self):
14 lib.my_sqrt.argtypes = c_double, 15 lib.my_sqrt.argtypes = c_double,
15 lib.my_sqrt.restype = c_double 16 lib.my_sqrt.restype = c_double
16 self.assertEqual(lib.my_sqrt(4.0), 2.0) 17 self.assertEqual(lib.my_sqrt(4.0), 2.0)
17 import math 18 import math
18 self.assertEqual(lib.my_sqrt(2.0), math.sqrt(2.0)) 19 self.assertEqual(lib.my_sqrt(2.0), math.sqrt(2.0))
19 20
20 def test_qsort(self): 21 def test_qsort(self):
21 comparefunc = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_char)) 22 comparefunc = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_char))
22 lib.my_qsort.argtypes = c_void_p, c_size_t, c_size_t, comparefunc 23 lib.my_qsort.argtypes = c_void_p, c_size_t, c_size_t, comparefunc
23 lib.my_qsort.restype = None 24 lib.my_qsort.restype = None
24 25
25 def sort(a, b): 26 def sort(a, b):
26 return three_way_cmp(a[0], b[0]) 27 return three_way_cmp(a[0], b[0])
27 28
28 chars = create_string_buffer(b"spam, spam, and spam") 29 chars = create_string_buffer(b"spam, spam, and spam")
29 lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort)) 30 lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort))
30 self.assertEqual(chars.raw, b" ,,aaaadmmmnpppsss\x00") 31 self.assertEqual(chars.raw, b" ,,aaaadmmmnpppsss\x00")
31 32
32 if __name__ == "__main__": 33 if __name__ == "__main__":
33 unittest.main() 34 unittest.main()
OLDNEW
« no previous file with comments | « Lib/ctypes/test/test_functions.py ('k') | Lib/ctypes/test/test_parameters.py » ('j') | no next file with comments »

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