[ctypes-commit] ctypes/ctypes/test test_byteswap.py,1.1.2.5,1.1.2.6
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2005-11-30 09:35:13
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv830 Modified Files: Tag: branch_1_0 test_byteswap.py Log Message: Add some testing ideas. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** test_byteswap.py 29 Nov 2005 20:36:57 -0000 1.1.2.5 --- test_byteswap.py 30 Nov 2005 09:35:03 -0000 1.1.2.6 *************** *** 129,132 **** --- 129,202 ---- self.failUnless(c_char.__ctype_be__ is c_char) + ''' + ################################################################ + + def test(): + from ctypes import BigEndianStructure + class PT(BigEndianStructure): + ## class PT(Structure): + _fields_ = [("x", c_int), + ("y", c_int), + ("b", c_char), + ## ("c", c_wchar), + ("c", c_byte), + ("d", c_ubyte), + ## ("e", POINTER(c_int)), + ## ("f", POINTER(POINTER(c_int))), + + ## ("float", c_float), + ## ("double", c_double), + + ("b1", c_byte, 3), + ("b2", c_byte, 3), + ("b3", c_byte, 2), + ("a", c_int * 3 * 3 * 3)] + + for desc in PT._fields_: + print getattr(PT, desc[0]) + + if __name__ == "__main__": + test() + + from ctypes import BigEndianStructure + + class SCSI_6(BigEndianStructure): + _pack_ = 1 + _fields_ = [("opcode", c_ubyte, 8), + + ("lun", c_ulong, 3), + ("blockaddr", c_ulong, 21), + ("transferlen", c_ulong, 8), + + ("controlbyte", c_ubyte, 8)] + print sizeof(SCSI_6) + + def bin(s): + from binascii import hexlify + return hexlify(str(buffer(s))) + + print bin(SCSI_6(-1)) + print bin(SCSI_6(0, -1)) + print bin(SCSI_6(0, 0, -1)) + print bin(SCSI_6(0, 0, 0, -1)) + print bin(SCSI_6(0, 0, 0, 0, -1)) + + class SCSI_12(BigEndianStructure): + _pack_ = 1 + _fields_ = [("opcode", c_ubyte, 8), + + ("lun", c_ubyte, 3), + ("_res1", c_ubyte, 4), + ("reladdr", c_ubyte, 1), + + ("blockaddr", c_ulong), + + ("_res2", c_ubyte), + ("_res3", c_ubyte), + ("_res4", c_ubyte), + + ("transferlen", c_ushort), + ("controlbyte", c_ubyte)] + ''' if __name__ == "__main__": |