Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
f5af466d
Commit
f5af466d
authored
Jul 11, 2007
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix one more ctypes test, and disable the tests that were segfaulting.
Thanks to Christian Heimes for finding these tests.
parent
c92159aa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
63 deletions
+69
-63
Lib/ctypes/test/test_functions.py
Lib/ctypes/test/test_functions.py
+11
-9
Lib/ctypes/test/test_python_api.py
Lib/ctypes/test/test_python_api.py
+18
-16
Lib/ctypes/test/test_slicing.py
Lib/ctypes/test/test_slicing.py
+40
-38
No files found.
Lib/ctypes/test/test_functions.py
View file @
f5af466d
...
...
@@ -160,15 +160,17 @@ class FunctionTestCase(unittest.TestCase):
result
=
f
(
1
,
2
,
3
,
4
,
5.0
,
6.0
,
21
)
self
.
failUnlessEqual
(
result
,
42
)
def
test_stringresult
(
self
):
f
=
dll
.
_testfunc_p_p
f
.
argtypes
=
None
f
.
restype
=
c_char_p
result
=
f
(
"123"
)
self
.
failUnlessEqual
(
result
,
"123"
)
result
=
f
(
None
)
self
.
failUnlessEqual
(
result
,
None
)
from
ctypes.test
import
is_resource_enabled
if
is_resource_enabled
(
"struni-crash"
):
def
test_stringresult
(
self
):
f
=
dll
.
_testfunc_p_p
f
.
argtypes
=
None
f
.
restype
=
c_char_p
result
=
f
(
"123"
)
self
.
failUnlessEqual
(
result
,
"123"
)
result
=
f
(
None
)
self
.
failUnlessEqual
(
result
,
None
)
def
test_pointers
(
self
):
f
=
dll
.
_testfunc_p_p
...
...
Lib/ctypes/test/test_python_api.py
View file @
f5af466d
...
...
@@ -41,17 +41,17 @@ class PythonAPITestCase(unittest.TestCase):
# This test is unreliable, because it is possible that code in
# unittest changes the refcount of the '42' integer. So, it
# is disabled by default.
def
test_Py
Int
_Long
(
self
):
def
test_Py
Long
_Long
(
self
):
ref42
=
grc
(
42
)
pythonapi
.
Py
Int
_FromLong
.
restype
=
py_object
self
.
failUnlessEqual
(
pythonapi
.
Py
Int
_FromLong
(
42
),
42
)
pythonapi
.
Py
Long
_FromLong
.
restype
=
py_object
self
.
failUnlessEqual
(
pythonapi
.
Py
Long
_FromLong
(
42
),
42
)
self
.
failUnlessEqual
(
grc
(
42
),
ref42
)
pythonapi
.
Py
Int
_AsLong
.
argtypes
=
(
py_object
,)
pythonapi
.
Py
Int
_AsLong
.
restype
=
c_long
pythonapi
.
Py
Long
_AsLong
.
argtypes
=
(
py_object
,)
pythonapi
.
Py
Long
_AsLong
.
restype
=
c_long
res
=
pythonapi
.
Py
Int
_AsLong
(
42
)
res
=
pythonapi
.
Py
Long
_AsLong
(
42
)
self
.
failUnlessEqual
(
grc
(
res
),
ref42
+
1
)
del
res
self
.
failUnlessEqual
(
grc
(
42
),
ref42
)
...
...
@@ -67,19 +67,21 @@ class PythonAPITestCase(unittest.TestCase):
del
pyobj
self
.
failUnlessEqual
(
grc
(
s
),
ref
)
def
test_PyOS_snprintf
(
self
):
PyOS_snprintf
=
pythonapi
.
PyOS_snprintf
PyOS_snprintf
.
argtypes
=
POINTER
(
c_char
),
c_size_t
,
c_char_p
from
ctypes.test
import
is_resource_enabled
if
is_resource_enabled
(
"struni-crash"
):
def
test_PyOS_snprintf
(
self
):
PyOS_snprintf
=
pythonapi
.
PyOS_snprintf
PyOS_snprintf
.
argtypes
=
POINTER
(
c_char
),
c_size_t
,
c_char_p
buf
=
c_buffer
(
256
)
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"Hello from %s"
,
"ctypes"
)
self
.
failUnlessEqual
(
buf
.
value
,
"Hello from ctypes"
)
buf
=
c_buffer
(
256
)
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"Hello from %s"
,
"ctypes"
)
self
.
failUnlessEqual
(
buf
.
value
,
"Hello from ctypes"
)
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"Hello from %s
"
,
"ctypes"
,
1
,
2
,
3
)
self
.
failUnlessEqual
(
buf
.
value
,
"Hello from ctypes"
)
PyOS_snprintf
(
buf
,
sizeof
(
buf
),
"Hello from %s (%d, %d, %d)
"
,
"ctypes"
,
1
,
2
,
3
)
self
.
failUnlessEqual
(
buf
.
value
,
"Hello from ctypes"
)
# not enough arguments
self
.
failUnlessRaises
(
TypeError
,
PyOS_snprintf
,
buf
)
# not enough arguments
self
.
failUnlessRaises
(
TypeError
,
PyOS_snprintf
,
buf
)
def
test_pyobject_repr
(
self
):
self
.
failUnlessEqual
(
repr
(
py_object
()),
"py_object(<NULL>)"
)
...
...
Lib/ctypes/test/test_slicing.py
View file @
f5af466d
...
...
@@ -34,45 +34,47 @@ class SlicesTestCase(unittest.TestCase):
# ValueError: Can only assign sequence of same size
self
.
assertRaises
(
ValueError
,
setslice
,
a
,
0
,
5
,
range
(
32
))
def
test_char_ptr
(
self
):
s
=
"abcdefghijklmnopqrstuvwxyz"
dll
=
CDLL
(
_ctypes_test
.
__file__
)
dll
.
my_strdup
.
restype
=
POINTER
(
c_char
)
dll
.
my_free
.
restype
=
None
res
=
dll
.
my_strdup
(
s
)
self
.
failUnlessEqual
(
res
[:
len
(
s
)],
s
)
import
operator
self
.
assertRaises
(
TypeError
,
operator
.
setslice
,
res
,
0
,
5
,
"abcde"
)
dll
.
my_free
(
res
)
dll
.
my_strdup
.
restype
=
POINTER
(
c_byte
)
res
=
dll
.
my_strdup
(
s
)
self
.
failUnlessEqual
(
res
[:
len
(
s
)],
list
(
range
(
ord
(
"a"
),
ord
(
"z"
)
+
1
)))
dll
.
my_free
(
res
)
def
test_char_ptr_with_free
(
self
):
dll
=
CDLL
(
_ctypes_test
.
__file__
)
s
=
"abcdefghijklmnopqrstuvwxyz"
class
allocated_c_char_p
(
c_char_p
):
pass
dll
.
my_free
.
restype
=
None
def
errcheck
(
result
,
func
,
args
):
retval
=
result
.
value
dll
.
my_free
(
result
)
return
retval
dll
.
my_strdup
.
restype
=
allocated_c_char_p
dll
.
my_strdup
.
errcheck
=
errcheck
try
:
from
ctypes.test
import
is_resource_enabled
if
is_resource_enabled
(
"struni-crash"
):
def
test_char_ptr
(
self
):
s
=
"abcdefghijklmnopqrstuvwxyz"
dll
=
CDLL
(
_ctypes_test
.
__file__
)
dll
.
my_strdup
.
restype
=
POINTER
(
c_char
)
dll
.
my_free
.
restype
=
None
res
=
dll
.
my_strdup
(
s
)
self
.
failUnlessEqual
(
res
,
s
)
finally
:
del
dll
.
my_strdup
.
errcheck
self
.
failUnlessEqual
(
res
[:
len
(
s
)],
s
)
import
operator
self
.
assertRaises
(
TypeError
,
operator
.
setslice
,
res
,
0
,
5
,
"abcde"
)
dll
.
my_free
(
res
)
dll
.
my_strdup
.
restype
=
POINTER
(
c_byte
)
res
=
dll
.
my_strdup
(
s
)
self
.
failUnlessEqual
(
res
[:
len
(
s
)],
list
(
range
(
ord
(
"a"
),
ord
(
"z"
)
+
1
)))
dll
.
my_free
(
res
)
def
test_char_ptr_with_free
(
self
):
dll
=
CDLL
(
_ctypes_test
.
__file__
)
s
=
"abcdefghijklmnopqrstuvwxyz"
class
allocated_c_char_p
(
c_char_p
):
pass
dll
.
my_free
.
restype
=
None
def
errcheck
(
result
,
func
,
args
):
retval
=
result
.
value
dll
.
my_free
(
result
)
return
retval
dll
.
my_strdup
.
restype
=
allocated_c_char_p
dll
.
my_strdup
.
errcheck
=
errcheck
try
:
res
=
dll
.
my_strdup
(
s
)
self
.
failUnlessEqual
(
res
,
s
)
finally
:
del
dll
.
my_strdup
.
errcheck
def
test_char_array
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment