示例#1
0
 def test_sizeof(self):
     self.assertEqual(sizeof('int'), 4)
     define('INIT_THREAD_SIZE', 2048 * sizeof('long'))
     self.assertEqual(cstruct.DEFINES['INIT_THREAD_SIZE'], 16384)
     self.assertEqual(sizeof('struct Position'), 3)
     self.assertEqual(sizeof('struct Position'), len(Position))
     self.assertEqual(sizeof(Position), 3)
     self.assertRaises(KeyError, lambda: sizeof('bla'))
     self.assertRaises(KeyError, lambda: sizeof('struct Bla'))
示例#2
0
 def test_nested(self):
     data = os.urandom(sizeof("struct PartitionFlat") )
     flat = PartitionFlat(data)
     flat.unpack(data)
     nested = PartitionNested(data)
     nested.unpack(data)
     self.assertEqual(flat.status, nested.status)
     self.assertEqual(flat.startAddrHead, nested.start.addrHead)
     self.assertEqual(flat.startAddrCylSec, nested.start.addrCylSec)
     self.assertEqual(flat.partType, nested.partType)
     self.assertEqual(flat.endAddrHead, nested.end.addrHead)
     self.assertEqual(flat.endAddrCylSec, nested.end.addrCylSec)
     self.assertEqual(flat.startLBA, nested.startLBA)
     self.assertEqual(flat.endLBA, nested.endLBA)
示例#3
0
 def test_typedef(self):
     typedef('int', 'integer')
     self.assertEqual(sizeof('integer'), 4)
 def test_foo10_sizeof(self):
     self.assertEqual(sizeof("struct Foo10"), 24)
 def test_foo4_sizeof(self):
     self.assertEqual(sizeof("struct Foo4"), 4)
 def test_foo3_sizeof(self):
     self.assertEqual(sizeof("struct Foo3"), 16)
 def test_utmp_sizeof(self):
     self.assertEqual(sizeof("struct Utmp"), 384)
示例#8
0
 def test_sizeof(self):
     self.assertEqual(sizeof("struct Partition"), sizeof("struct PartitionFlat"))
     self.assertEqual(sizeof("struct Partition"), sizeof("struct PartitionNested"))
示例#9
0
import struct

class TestUnion(cstruct.CStruct):
    __byte_order__ = cstruct.LITTLE_ENDIAN
    __def__ = """
        union {
            uint8   a;
            uint8   a1;
            uint16  b;
            uint32  c;
            struct Partition d;
            struct Partition e[4];
        }
    """

define('INIT_THREAD_SIZE', 2048 * sizeof('long'))

# class TaskUnion(cstruct.CStruct):
#     __def__ = """
#         union {
#             struct task_struct task;
#             unsigned long stack[INIT_TASK_SIZE/sizeof(long)];
#         }
#     """

class TestCaseUnion(TestCase):

    # def test_sizeof(self):
    #     self.assertEqual(cstruct.DEFINES['INIT_THREAD_SIZE'], 16384)
    #     self.assertEqual(sizeof('struct TestUnion'), 64)
    #