예제 #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)
예제 #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)
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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
예제 #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)
예제 #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))]
예제 #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))]
예제 #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"))]
예제 #13
0
 class GreedyScalarArray(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("x", prophy.array(prophy.u32))]
예제 #14
0
 class Z(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("x", prophy.array(Y))]
예제 #15
0
 class SArraySized(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(S, size=3))]
예제 #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"
예제 #17
0
 class Dynamic(prophy.struct):
     __metaclass__ = prophy.struct_generator
     _descriptor = [('a_len', prophy.u32),
                    ('a', prophy.array(prophy.u8, bound='a_len'))]
예제 #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)]
예제 #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"))]
예제 #20
0
 class C(prophy.struct_packed):
     __metaclass__ = prophy.struct_generator
     _descriptor = [('a_len', prophy.u32),
                    ('a', prophy.array(B, bound='a_len'))]
예제 #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())]
예제 #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"))]
예제 #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)]
예제 #24
0
 class BoundCompositeArray(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("len", prophy.u32),
                    ("value", prophy.array(BoundScalarArray, bound="len"))]
예제 #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"))]
예제 #26
0
 class S2(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(prophy.u32))]
예제 #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))]
예제 #28
0
 class StructWithU(
         prophy.with_metaclass(prophy.struct_generator, prophy.struct)):
     _descriptor = [("a_len", prophy.u8),
                    ("a", prophy.array(UVarLen, bound="a_len"))]
예제 #29
0
 class LengthFieldAfter(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(prophy.i32, bound="after")),
                    ("after", prophy.i32)]
예제 #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"
예제 #31
0
 class LengthFieldNonexistent(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("a", prophy.array(prophy.i32,
                                       bound="nonexistent"))]
예제 #32
0
 class GreedyComplexCompositeArray(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("x", prophy.array(ComplexComposite))]
예제 #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"))]
예제 #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"))]
예제 #35
0
 class U(prophy.with_metaclass(prophy.union_generator, prophy.union)):
     _descriptor = [("a", prophy.array(prophy.u8, size=3), 0)]
예제 #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"))]
예제 #37
0
 class NotLast(
         prophy.with_metaclass(prophy.struct_generator,
                               prophy.struct_packed)):
     _descriptor = [("y", prophy.array(prophy.u32)), ("x", prophy.u32)]