예제 #1
0
def test_optional_dynamic_field():
    class Dynamic(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
        _descriptor = [('a_len', prophy.u32),
                       ('a', prophy.array(prophy.u8, bound='a_len'))]
    with pytest.raises(Exception) as e:
        prophy.optional(Dynamic)
    assert "optional dynamic fields not implemented" == str(e.value)
예제 #2
0
def test_optional_dynamic_field():
    class Dynamic(prophy.with_metaclass(prophy.struct_generator,
                                        prophy.struct)):
        _descriptor = [('a_len', prophy.u32),
                       ('a', prophy.array(prophy.u8, bound='a_len'))]

    with pytest.raises(Exception) as e:
        prophy.optional(Dynamic)
    assert "optional dynamic fields not implemented" == str(e.value)
예제 #3
0
def test_optional_array():
    with pytest.raises(Exception) as e:
        prophy.optional(prophy.array(prophy.u8, size=3))
    assert "optional array not implemented" == str(e.value)

    with pytest.raises(Exception) as e:
        class S(prophy.with_metaclass(prophy.struct_generator, prophy.struct_packed)):
            _descriptor = [("a_len", prophy.optional(prophy.u32)),
                           ("a", prophy.array(prophy.u32, bound="a_len"))]
    assert "array S.a must not be bound to optional field" == str(e.value)

    with pytest.raises(Exception) as e:
        prophy.array(prophy.optional(prophy.u32))
    assert "array of optional type not allowed" == str(e.value)
예제 #4
0
 class DifferentStruct(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [
         ("x", prophy.u8),
         ("y", prophy.array(prophy.u32, size=1)),
         ("o", prophy.optional(prophy.u32)),
     ]
예제 #5
0
 class SameStruct(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [
         ("x", prophy.u8),
         ("y", prophy.u32),
         ("o", prophy.optional(prophy.u32)),
     ]
예제 #6
0
def test_optional_attributes():
    assert 1 == prophy.optional(prophy.i8)._SIZE
    assert False == prophy.optional(prophy.i8)._DYNAMIC
    assert False == prophy.optional(prophy.i8)._UNLIMITED
    assert 0 == prophy.optional(prophy.i8)._DEFAULT
    assert True == prophy.optional(prophy.i8)._OPTIONAL
    assert 1 == prophy.optional(prophy.i8)._ALIGNMENT
    assert None == prophy.optional(prophy.i8)._BOUND
    assert None == prophy.optional(prophy.i8)._PARTIAL_ALIGNMENT
예제 #7
0
def test_optional_attributes():
    assert 1 == prophy.optional(prophy.i8)._SIZE
    assert False == prophy.optional(prophy.i8)._DYNAMIC
    assert False == prophy.optional(prophy.i8)._UNLIMITED
    assert 0 == prophy.optional(prophy.i8)._DEFAULT
    assert True == prophy.optional(prophy.i8)._OPTIONAL
    assert 1 == prophy.optional(prophy.i8)._ALIGNMENT
    assert None == prophy.optional(prophy.i8)._BOUND
    assert None == prophy.optional(prophy.i8)._PARTIAL_ALIGNMENT
예제 #8
0
def test_optional_array():
    with pytest.raises(Exception) as e:
        prophy.optional(prophy.array(prophy.u8, size=3))
    assert "optional array not implemented" == e.value.message

    with pytest.raises(Exception) as e:

        class S(prophy.struct_packed):
            __metaclass__ = prophy.struct_generator
            _descriptor = [("a_len", prophy.optional(prophy.u32)),
                           ("a", prophy.array(prophy.u32, bound="a_len"))]

    assert "array must not be bound to optional field" == e.value.message

    with pytest.raises(Exception) as e:
        prophy.array(prophy.optional(prophy.u32))
    assert "array of optional type not allowed" == e.value.message
예제 #9
0
def test_optional_bytes():
    with pytest.raises(Exception) as e:
        prophy.optional(prophy.bytes(size=3))
    assert "optional bytes not implemented" == str(e.value)
예제 #10
0
 class U(prophy.with_metaclass(prophy.union_generator, prophy.union)):
     _descriptor = [("a", prophy.u32, 0),
                    ("b", prophy.optional(prophy.u32), 1),
                    ("c", prophy.u32, 2)]
예제 #11
0
 class O(prophy.struct_packed):
     __metaclass__ = prophy.struct_generator
     _descriptor = [("a", prophy.optional(prophy.u32)),
                    ("b", prophy.optional(S)), ("c", prophy.optional(U))]
예제 #12
0
 class O(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.optional(prophy.u32)),
                    ("b", prophy.optional(S)), ("c", prophy.optional(U))]
예제 #13
0
 class K(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.optional(U))]
예제 #14
0
 class X(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [('x', prophy.optional(prophy.u8)),
                    ('y', prophy.optional(prophy.u64))]
예제 #15
0
def test_optional_bytes():
    with pytest.raises(Exception) as e:
        prophy.optional(prophy.bytes(size=3))
    assert "optional bytes not implemented" == str(e.value)
예제 #16
0
 class B(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [('a', prophy.optional(A))]
예제 #17
0
 class U(prophy.union):
     __metaclass__ = prophy.union_generator
     _descriptor = [("a", prophy.u32, 0),
                    ("b", prophy.optional(prophy.u32), 1),
                    ("c", prophy.u32, 2)]
예제 #18
0
 class X(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("value", prophy.optional(_type))]
예제 #19
0
def test_optional_attributes():
    assert prophy.optional(prophy.i8)._SIZE == 1
    assert prophy.optional(prophy.i8)._DYNAMIC is False
    assert prophy.optional(prophy.i8)._UNLIMITED is False
    assert prophy.optional(prophy.i8)._DEFAULT == 0
    assert prophy.optional(prophy.i8)._OPTIONAL
    assert prophy.optional(prophy.i8)._ALIGNMENT == 1
    assert prophy.optional(prophy.i8)._BOUND is None
    assert prophy.optional(prophy.i8)._PARTIAL_ALIGNMENT is None

    assert prophy.optional(prophy.i8)._OPTIONAL_SIZE == 5
    assert prophy.optional(prophy.i8)._OPTIONAL_ALIGNMENT == 4
    assert prophy.optional(prophy.i64)._OPTIONAL_SIZE == 16
    assert prophy.optional(prophy.i64)._OPTIONAL_ALIGNMENT == 8
예제 #20
0
 class S(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a_len", prophy.optional(prophy.u32)),
                    ("a", prophy.array(prophy.u32, bound="a_len"))]
예제 #21
0
 class B(prophy.struct_packed):
     __metaclass__ = prophy.struct_generator
     _descriptor = [('a', prophy.optional(A))]