c_char, c_char_p objects and c_char array structure fields return

their value now as str, no longer str8.
This commit is contained in:
Thomas Heller 2007-07-13 12:52:51 +00:00
parent 27384da6e8
commit 19b52545df
7 changed files with 29 additions and 40 deletions

View file

@ -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 str8)
self.failUnless(type(b[0]) is str)
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 str8)
self.failUnless(type(b[0]) is str)
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 str8)
self.failUnless(type(b[0]) is str)
self.failUnlessEqual(b[0], "a")
self.failUnlessEqual(b[:], "abc\0")

View file

@ -29,14 +29,18 @@ class BytesTest(unittest.TestCase):
_fields_ = [("a", c_char * 3)]
X("abc")
X(b"abc")
x = X(b"abc")
self.assertEqual(x.a, "abc")
self.assertEqual(type(x.a), str)
def test_struct_W(self):
class X(Structure):
_fields_ = [("a", c_wchar * 3)]
X("abc")
X(b"abc")
x = X(b"abc")
self.assertEqual(x.a, "abc")
self.assertEqual(type(x.a), str)
if sys.platform == "win32":
def test_BSTR(self):

View file

@ -24,7 +24,7 @@ assigned from Python must be kept.
>>> array._objects
{'4': b'foo bar'}
>>> array[4]
s'foo bar'
'foo bar'
>>>
It gets more complicated when the ctypes instance itself is contained

View file

@ -69,7 +69,7 @@ class CallbackTracbackTestCase(unittest.TestCase):
out = self.capture_stderr(cb, "spam")
self.failUnlessEqual(out.splitlines()[-1],
"TypeError: "
"unsupported operand type(s) for /: 'int' and 'str8'")
"unsupported operand type(s) for /: 'int' and 'str'")
if __name__ == '__main__':
unittest.main()

View file

@ -22,7 +22,7 @@ class ReprTest(unittest.TestCase):
self.failUnlessEqual("<X object at", repr(typ(42))[:12])
def test_char(self):
self.failUnlessEqual("c_char(s'x')", repr(c_char('x')))
self.failUnlessEqual("c_char('x')", repr(c_char('x')))
self.failUnlessEqual("<X object at", repr(X('x'))[:12])
if __name__ == "__main__":

View file

@ -70,7 +70,7 @@ class SlicesTestCase(unittest.TestCase):
dll.my_strdup.errcheck = errcheck
try:
res = dll.my_strdup(s)
self.failUnlessEqual(res, s)
self.failUnlessEqual(res, str(s))
finally:
del dll.my_strdup.errcheck