Ejemplo n.º 1
0
def test_greedy_array_exceptions():
    with pytest.raises(Exception) as e:
        class NotLast(prophy.with_metaclass(prophy.struct_generator, prophy.struct_packed)):
            _descriptor = [("y", prophy.array(prophy.u32)),
                           ("x", prophy.u32)]
    assert "unlimited field is not the last one" == str(e.value)

    with pytest.raises(Exception) as e:
        class GreedyComposite(prophy.with_metaclass(prophy.struct_generator, prophy.struct_packed)):
            _descriptor = [("x", prophy.array(prophy.u32))]
        prophy.array(GreedyComposite)
    assert "array with unlimited field disallowed" == str(e.value)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def test_array_static_attributes():
    A = prophy.array(prophy.u16, size=3)

    assert A._SIZE == 6
    assert A._DYNAMIC is False
    assert A._UNLIMITED is False
    assert A._OPTIONAL is False
    assert A._ALIGNMENT == 2
    assert A._BOUND is None
    assert A._PARTIAL_ALIGNMENT is None
Ejemplo n.º 4
0
def test_array_bound_attributes():
    A = prophy.array(prophy.u16, bound="a_len")

    assert A._SIZE == 0
    assert A._DYNAMIC is True
    assert A._UNLIMITED is False
    assert A._OPTIONAL is False
    assert A._ALIGNMENT == 2
    assert A._BOUND == "a_len"
    assert A._PARTIAL_ALIGNMENT is None
Ejemplo n.º 5
0
def test_array_greedy_attributes():
    A = prophy.array(prophy.u16)

    assert A._SIZE == 0
    assert A._DYNAMIC is True
    assert A._UNLIMITED is True
    assert A._OPTIONAL is False
    assert A._ALIGNMENT == 2
    assert A._BOUND is None
    assert A._PARTIAL_ALIGNMENT is None
Ejemplo n.º 6
0
def test_array_static_attributes():
    A = prophy.array(prophy.u16, size = 3)

    assert 6 == A._SIZE
    assert False == A._DYNAMIC
    assert False == A._UNLIMITED
    assert False == A._OPTIONAL
    assert 2 == A._ALIGNMENT
    assert None == A._BOUND
    assert A._PARTIAL_ALIGNMENT is None
Ejemplo n.º 7
0
def test_array_bound_attributes():
    A = prophy.array(prophy.u16, bound = "a_len")

    assert 0 == A._SIZE
    assert True == A._DYNAMIC
    assert False == A._UNLIMITED
    assert False == A._OPTIONAL
    assert 2 == A._ALIGNMENT
    assert "a_len" == A._BOUND
    assert A._PARTIAL_ALIGNMENT is None
Ejemplo n.º 8
0
def test_array_greedy_attributes():
    A = prophy.array(prophy.u16)

    assert 0 == A._SIZE
    assert True == A._DYNAMIC
    assert True == A._UNLIMITED
    assert False == A._OPTIONAL
    assert 2 == A._ALIGNMENT
    assert None == A._BOUND
    assert A._PARTIAL_ALIGNMENT is None
Ejemplo n.º 9
0
def test_fixed_scalar_array_exception():
    class D(prophy.with_metaclass(prophy.struct_generator, prophy.struct_packed)):
        _descriptor = [("a_len", prophy.u8),
                       ("a", prophy.array(prophy.u8, bound="a_len"))]

    class U(prophy.with_metaclass(prophy.struct_generator, prophy.struct_packed)):
        _descriptor = [("a", prophy.array(prophy.u8))]

    with pytest.raises(Exception, match="static/limited array of dynamic type not allowed"):
        prophy.array(D, size=2)

    with pytest.raises(Exception, match="static/limited array of dynamic type not allowed"):
        prophy.array(U, size=2)

    with pytest.raises(Exception, match="static/limited array of dynamic type not allowed"):
        prophy.array(D, bound="a_len", size=2)

    with pytest.raises(Exception, match="static/limited array of dynamic type not allowed"):
        prophy.array(U, bound="a_len", size=2)
Ejemplo n.º 10
0
 class XS(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("len", prophy.u8),
                    ("value", prophy.array(prophy.u8, bound="len",
                                           shift=2))]
Ejemplo n.º 11
0
 class ComplicatedStruct(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("a", NestedStruct), ("b", prophy.u32),
                    ("c", prophy.array(Struct, size=2)),
                    ("d", prophy.array(Union, size=2))]
Ejemplo n.º 12
0
 class X2(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("b_len", prophy.u8), ("a_len", prophy.u8),
                    ("a", prophy.array(prophy.u8, bound="a_len")),
                    ("b", prophy.array(prophy.u8, bound="b_len"))]
Ejemplo n.º 13
0
 class GreedyScalarArray(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("x", prophy.array(prophy.u32))]
Ejemplo n.º 14
0
 class Z(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("x", prophy.array(Y))]
Ejemplo n.º 15
0
 class SArraySized(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(S, size=3))]
Ejemplo n.º 16
0
def test_array_incorrect_attributes():
    with pytest.raises(prophy.ProphyError) as err:
        prophy.array(prophy.u16, anything=3)

    assert str(err.value) == "unknown arguments to array field"
Ejemplo n.º 17
0
 class Dynamic(prophy.struct):
     __metaclass__ = prophy.struct_generator
     _descriptor = [('a_len', prophy.u32),
                    ('a', prophy.array(prophy.u8, bound='a_len'))]
Ejemplo n.º 18
0
 class U(prophy.with_metaclass(prophy.union_generator, prophy.union)):
     _descriptor = [("a_len", prophy.u8, 0),
                    ("a", prophy.array(prophy.u32,
                                       bound="a_len",
                                       size=3), 1)]
Ejemplo n.º 19
0
 class B(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("num_of_x", prophy.u32),
                    ("x", prophy.array(A, bound="num_of_x"))]
Ejemplo n.º 20
0
 class C(prophy.struct_packed):
     __metaclass__ = prophy.struct_generator
     _descriptor = [('a_len', prophy.u32),
                    ('a', prophy.array(B, bound='a_len'))]
Ejemplo n.º 21
0
 class A(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("a_len", prophy.u16),
                    ("a", prophy.array(prophy.u16, bound="a_len")),
                    ("b", prophy.bytes())]
Ejemplo n.º 22
0
 class A(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("a", prophy.array(prophy.u8, size=3)),
                    ("b_len", prophy.u16),
                    ("b", prophy.array(prophy.u32, bound="b_len"))]
Ejemplo n.º 23
0
 class X(prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("x_len", prophy.u8),
                    ("x", prophy.array(prophy.u8, bound="x_len")),
                    ("y", prophy.u32),
                    ("z", prophy.u64)]
Ejemplo n.º 24
0
 class BoundCompositeArray(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("len", prophy.u32),
                    ("value", prophy.array(BoundScalarArray, bound="len"))]
Ejemplo n.º 25
0
 class ComplexComposite(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("y_len", prophy.u32), ("x", Composite),
                    ("y", prophy.array(Composite, bound="y_len"))]
Ejemplo n.º 26
0
 class S2(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(prophy.u32))]
Ejemplo n.º 27
0
 class Array(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("value_len", prophy.u8),
                    ("value", prophy.array(prophy.u8, size=1, shift=2))]
Ejemplo n.º 28
0
 class StructWithU(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("a_len", prophy.u8),
                    ("a", prophy.array(UVarLen, bound="a_len"))]
Ejemplo n.º 29
0
 class LengthFieldAfter(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(prophy.i32, bound="after")),
                    ("after", prophy.i32)]
Ejemplo n.º 30
0
def test_array_of_arrays_not_allowed():
    A = prophy.array(prophy.r32)
    with pytest.raises(prophy.ProphyError) as err:
        prophy.array(A, size=3)

    assert str(err.value) == "array of arrays not allowed"
Ejemplo n.º 31
0
 class LengthFieldNonexistent(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(prophy.i32,
                                       bound="nonexistent"))]
Ejemplo n.º 32
0
 class GreedyComplexCompositeArray(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("x", prophy.array(ComplexComposite))]
Ejemplo n.º 33
0
 class _(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("not_an_int", "not_an_int"),
                    ("a", prophy.array(prophy.i32, bound="not_an_int"))]
Ejemplo n.º 34
0
 class S(prophy.struct_packed):
     __metaclass__ = prophy.struct_generator
     _descriptor = [("a_len", prophy.optional(prophy.u32)),
                    ("a", prophy.array(prophy.u32, bound="a_len"))]
Ejemplo n.º 35
0
 class U(prophy.with_metaclass(prophy.union_generator, prophy.union)):
     _descriptor = [("a", prophy.array(prophy.u8, size=3), 0)]
Ejemplo n.º 36
0
 class LengthFieldIsNotAnInteger(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("not_an_int", "not_an_int"),
                    ("a", prophy.array(prophy.i32, bound="not_an_int"))]
Ejemplo n.º 37
0
 class NotLast(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("y", prophy.array(prophy.u32)), ("x", prophy.u32)]