def test_FILE_object():
if sys.platform == "win32":
py.test.skip("testing FILE not implemented")
#
BFILE = new_struct_type("FILE")
BFILEP = new_pointer_type(BFILE)
BChar = new_primitive_type("char")
BCharP = new_pointer_type(BChar)
BInt = new_primitive_type("int")
BFunc = new_function_type((BCharP, BFILEP), BInt, False)
BFunc2 = new_function_type((BFILEP,), BInt, False)
ll = find_and_load_library('c')
fputs = ll.load_function(BFunc, "fputs")
fileno = ll.load_function(BFunc2, "fileno")
#
import posix
fdr, fdw = posix.pipe()
fw1 = posix.fdopen(fdw, 'wb', 256)
#
fw1p = cast(BFILEP, fw1)
fw1.write(b"X")
fw1.flush()
res = fputs(b"hello\n", fw1p)
assert res >= 0
res = fileno(fw1p)
assert (res == fdw) == (sys.version_info < (3,))
fw1.close()
#
data = posix.read(fdr, 256)
assert data == b"Xhello\n"
posix.close(fdr)
评论列表
文章目录