def test_fail_on_dynamic_length(self): union = UnionTemplate('NotLegal', 'dymagic', parent=None) union.add(UInt(2, 'bar', None)) struct = StructTemplate('Foo', 'foo', parent=None) struct.add(UInt(1, 'len', 22)) struct.add(Char('len', 'dymagic', 'foo')) self.assertRaises(Exception, union.add, struct)
def _check_length(self, length, *fields): union = UnionTemplate('Foo', 'foo', parent=None) for value in fields: union.add(value) self.assertEquals(union.get_static_length(), length)
def _get_foo_union(self): union = UnionTemplate('Foo', 'foo', parent=None) union.add(UInt(1, 'small', '0xff')) union.add(UInt(2, 'medium', '0xf00d')) union.add(UInt(4, 'large', None)) return union