Kaydet (Commit) 90044275 authored tarafından Thomas Heller's avatar Thomas Heller

Fix some simple ctypes tests.

üst 982479de
......@@ -7,12 +7,12 @@ class StringBufferTestCase(unittest.TestCase):
b = create_string_buffer(32)
self.failUnlessEqual(len(b), 32)
self.failUnlessEqual(sizeof(b), 32 * sizeof(c_char))
self.failUnless(type(b[0]) is str)
self.failUnless(type(b[0]) is str8)
b = create_string_buffer("abc")
self.failUnlessEqual(len(b), 4) # trailing nul char
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
self.failUnless(type(b[0]) is str)
self.failUnless(type(b[0]) is str8)
self.failUnlessEqual(b[0], "a")
self.failUnlessEqual(b[:], "abc\0")
......@@ -20,7 +20,7 @@ class StringBufferTestCase(unittest.TestCase):
b = create_string_buffer("abc")
self.failUnlessEqual(len(b), 4) # trailing nul char
self.failUnlessEqual(sizeof(b), 4 * sizeof(c_char))
self.failUnless(type(b[0]) is str)
self.failUnless(type(b[0]) is str8)
self.failUnlessEqual(b[0], "a")
self.failUnlessEqual(b[:], "abc\0")
......
......@@ -4,7 +4,7 @@ from binascii import hexlify
from ctypes import *
def bin(s):
return hexlify(buffer(s)).upper()
return str(hexlify(buffer(s))).upper()
# Each *simple* type that supports different byte orders has an
# __ctype_be__ attribute that specifies the same type in BIG ENDIAN
......
......@@ -12,10 +12,10 @@ def valid_ranges(*types):
for t in types:
fmt = t._type_
size = struct.calcsize(fmt)
a = struct.unpack(fmt, ("\x00"*32)[:size])[0]
b = struct.unpack(fmt, ("\xFF"*32)[:size])[0]
c = struct.unpack(fmt, ("\x7F"+"\x00"*32)[:size])[0]
d = struct.unpack(fmt, ("\x80"+"\xFF"*32)[:size])[0]
a = struct.unpack(fmt, (b"\x00"*32)[:size])[0]
b = struct.unpack(fmt, (b"\xFF"*32)[:size])[0]
c = struct.unpack(fmt, (b"\x7F"+b"\x00"*32)[:size])[0]
d = struct.unpack(fmt, (b"\x80"+b"\xFF"*32)[:size])[0]
result.append((min(a, b, c, d), max(a, b, c, d)))
return result
......@@ -174,13 +174,14 @@ class NumberTestCase(unittest.TestCase):
from ctypes import c_char
from array import array
a = array('c', 'x')
a = array('b', [0])
a[0] = ord('x')
v = c_char.from_address(a.buffer_info()[0])
self.failUnlessEqual(v.value, a[0])
self.failUnlessEqual(v.value, 'x')
self.failUnless(type(v) is c_char)
a[0] = '?'
self.failUnlessEqual(v.value, a[0])
a[0] = ord('?')
self.failUnlessEqual(v.value, '?')
# array does not support c_bool / 't'
# def test_bool_from_address(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment