def test_simple_struct(self): Data = struct.pack("<IB", 0xAABBCCDD, 0xEE) O = unpack(S0, Data) self.assertEqual(pack(S0, O), Data) Data = struct.pack("<IIB", 0xAABBCCDD, 0, 0xEE) O = unpack(S1, Data) self.assertEqual(pack(S1, O), Data)
def test_array(self): Ref = (0, 1, 2, 3) O = pack(ArrayTy(UI64, 4), Ref) self.assertEqual(O, struct.pack("<QQQQ", *Ref)) Data = struct.pack("<IB", 0xAABBCCDD, 0xEE) O = unpack(S0, Data) P = pack(ArrayTy(S0, 2), [O, O]) self.assertEqual(len(P), 2 * 8)
def test_ptr(self): self.assertEqual(pack(PointerTy(UI8, "<Q"), 10), struct.pack("<Q", 10))
def test_union(self): Ref = [0xAA, 0xBB, 0xCC, 0xDD] Data = struct.pack("<BBBB", *Ref) self.assertEqual(pack(U0, Ref), Data) self.assertEqual(pack(U0, 0xDDCCBBAA), Data) self.assertEqual(pack(U0, unpack(SIpAddr, Data)), Data)
def test_ui(self): self.assertEqual(pack(UI32, 0xAABBCCDD), struct.pack("<I", 0xAABBCCDD)) self.assertEqual(pack(UI8, 10), bytes((10, )))