Beispiel #1
0
def test_remove_field_not_found():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['not_a_field'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Beispiel #2
0
def test_change_union_to_struct():
    nodes = [model.Union("MyUnion", [model.UnionMember("field1", "u32", 1)])]
    patches = {'MyUnion': [patch.Action('struct', [])]}

    patch.patch(nodes, patches)

    assert [model.Struct('MyUnion', [model.StructMember('field1', 'u32' )])] == nodes
Beispiel #3
0
def test_make_field_static_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('static', ['field2', '3'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in e.value.message
Beispiel #4
0
def test_remove_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('remove', ['field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can remove field only in struct: MyStruct' in str(e.value)
Beispiel #5
0
def test_remove_field_not_found():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['not_a_field'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Beispiel #6
0
def test_make_field_static_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('static', ['field2', '3'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in e.value.message
Beispiel #7
0
def test_insert_field_no_3_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('insert', ['1', 'additional1', 'u8', 'extra'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 3 params: MyStruct' in str(e.value)
Beispiel #8
0
def test_make_field_dynamic_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("dynamic", ["field3", "field1"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", bound="field1"),
            ],
        )
    ] == nodes
Beispiel #9
0
def test_make_field_greedy_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("greedy", ["field3"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", unlimited=True),
            ],
        )
    ] == nodes
Beispiel #10
0
def test_remove_field_no_1_param():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("remove", ["field1", "extra_param"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Remove field must have 1 param: MyStruct" in str(e.value)
Beispiel #11
0
def test_remove_field_not_found():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("remove", ["not_a_field"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Member not found: MyStruct" in str(e.value)
Beispiel #12
0
def test_remove_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {"MyStruct": [patch.Action("remove", ["field2"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can remove field only in struct: MyStruct" in str(e.value)
Beispiel #13
0
def test_insert_field_index_not_an_int():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("insert", ["not_a_number", "additional1", "u8"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Index is not a number: MyStruct" in str(e.value)
Beispiel #14
0
def test_insert_field_no_3_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {"MyStruct": [patch.Action("insert", ["1", "additional1", "u8", "extra"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Change field must have 3 params: MyStruct" in str(e.value)
Beispiel #15
0
def test_insert_field():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {
        'MyStruct': [
            patch.Action('insert', ['1', 'additional1', 'u8']),
            patch.Action('insert', ['-1', 'additional2', 'u16']),
            patch.Action('insert', ['128', 'additional3', 'u64'])
        ]
    }

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('additional1', 'u8'),
            model.StructMember('field2', 'u32'),
            model.StructMember('additional2', 'u16'),
            model.StructMember('field3', 'u32'),
            model.StructMember('additional3', 'u64')
        ])
    ] == nodes
Beispiel #16
0
def test_make_field_static_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("static", ["field3", "3"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", size="3"),
            ],
        )
    ] == nodes
Beispiel #17
0
def test_change_field_type_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('type', ['field2', 'TheRealType'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct Action(action='type', params=['field2', 'TheRealType'])" == e.value.message
Beispiel #18
0
def test_make_field_static_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {"MyStruct": [patch.Action("static", ["field2", "3"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in str(e.value)
Beispiel #19
0
def test_insert_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('insert', ['1', 'additional1', 'u8'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can insert field only in struct: MyStruct' in str(e.value)
Beispiel #20
0
def test_make_field_limited_array():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", size="20"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("limited", ["field3", "field2"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32", bound="field2", size="20"),
            ],
        )
    ] == nodes
Beispiel #21
0
def test_insert_field_index_not_an_int():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('insert', ['not_a_number', 'additional1', 'u8'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Index is not a number: MyStruct' in str(e.value)
Beispiel #22
0
def test_change_field_type():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {"MyStruct": [patch.Action("type", ["field2", "TheRealType"])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "TheRealType"),
                model.StructMember("field3", "u32"),
            ],
        )
    ] == nodes
Beispiel #23
0
def test_remove_field_no_1_param():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['field1', 'extra_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Remove field must have 1 param: MyStruct' in str(e.value)
Beispiel #24
0
def test_make_field_limited_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in str(e.value)
Beispiel #25
0
def test_make_field_limited_array_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct" in str(e.value)
Beispiel #26
0
def test_remove_field_no_1_param():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {'MyStruct': [patch.Action('remove', ['field1', 'extra_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Remove field must have 1 param: MyStruct' in str(e.value)
Beispiel #27
0
def test_remove_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('remove', ['field2'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can remove field only in struct: MyStruct' in str(e.value)
Beispiel #28
0
def test_insert_field():
    nodes = [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("field2", "u32"),
                model.StructMember("field3", "u32"),
            ],
        )
    ]
    patches = {
        "MyStruct": [
            patch.Action("insert", ["1", "additional1", "u8"]),
            patch.Action("insert", ["-1", "additional2", "u16"]),
            patch.Action("insert", ["128", "additional3", "u64"]),
        ]
    }

    patch.patch(nodes, patches)

    assert [
        model.Struct(
            "MyStruct",
            [
                model.StructMember("field1", "u32"),
                model.StructMember("additional1", "u8"),
                model.StructMember("field2", "u32"),
                model.StructMember("additional2", "u16"),
                model.StructMember("field3", "u32"),
                model.StructMember("additional3", "u64"),
            ],
        )
    ] == nodes
Beispiel #29
0
def test_change_field_type_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {'MyStruct': [patch.Action('type', ['field2', 'TheRealType'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can change field only in struct: MyStruct Action(action='type', params=['field2', 'TheRealType'])" == str(e.value)
Beispiel #30
0
def test_insert_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {"MyStruct": [patch.Action("insert", ["1", "additional1", "u8"])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Can insert field only in struct: MyStruct" in str(e.value)
Beispiel #31
0
def test_rename_field_excessive_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]

    patches = {'MyStruct': [patch.Action('rename', 3 * ['too_much_params'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Rename must have 1 or 2 params: MyStruct' in str(e.value)
Beispiel #32
0
def test_rename_field_not_composite():
    nodes = [model.Enum("MyEnum", [model.EnumMember("val", "123")])]

    patches = {'MyEnum': [patch.Action('rename', ['field3', 'field69'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can rename fields only in composites: MyEnum' in str(e.value)
Beispiel #33
0
def test_change_union_to_struct_not_a_union():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32", 1),
                                      model.StructMember("field2", "u32", 2)])]
    patches = {'MyStruct': [patch.Action('struct', [])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can only change union to struct: MyStruct' in str(e.value)
Beispiel #34
0
def test_change_union_to_struct_excessive_params():
    nodes = [model.Union("MyUnion", [model.UnionMember("field1", "u32", 1),
                                    model.UnionMember("field2", "u32", 2)])]
    patches = {'MyUnion': [patch.Action('struct', ['surplus_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change union to struct takes no params: MyUnion' in str(e.value)
Beispiel #35
0
def test_change_union_to_struct():
    nodes = [model.Union("MyUnion", [model.UnionMember("field1", "u32", 1)])]
    patches = {'MyUnion': [patch.Action('struct', [])]}

    patch.patch(nodes, patches)

    assert [model.Struct('MyUnion',
                         [model.StructMember('field1', 'u32')])] == nodes
Beispiel #36
0
def test_rename_field_not_composite():
    nodes = [model.Enum("MyEnum", [model.EnumMember("val", "123")])]

    patches = {'MyEnum': [patch.Action('rename', ['field3', 'field69'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can rename fields only in composites: MyEnum' in str(e.value)
Beispiel #37
0
def test_rename_field_excessive_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]

    patches = {'MyStruct': [patch.Action('rename', 3 * ['too_much_params'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Rename must have 1 or 2 params: MyStruct' in str(e.value)
Beispiel #38
0
def test_insert_field_not_a_struct():
    nodes = [model.Typedef("MyStruct", "MyRealStruct")]
    patches = {
        'MyStruct': [patch.Action('insert', ['1', 'additional1', 'u8'])]
    }

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can insert field only in struct: MyStruct' in str(e.value)
Beispiel #39
0
def test_insert_field_index_not_an_int():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {
        'MyStruct':
        [patch.Action('insert', ['not_a_number', 'additional1', 'u8'])]
    }

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Index is not a number: MyStruct' in str(e.value)
Beispiel #40
0
def test_insert_field_no_3_params():
    nodes = [model.Struct("MyStruct", [model.StructMember("field1", "u32")])]
    patches = {
        'MyStruct':
        [patch.Action('insert', ['1', 'additional1', 'u8', 'extra'])]
    }

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 3 params: MyStruct' in str(e.value)
Beispiel #41
0
def main():
    opts = options.parse_options()

    if opts.version:
        print "prophyc {}".format(__version__)
        sys.exit(0)

    if not opts.input_files:
        sys.exit("prophyc: error: missing input file")

    if opts.isar:
        from prophyc.parsers.isar import IsarParser
        parser = IsarParser()
        parse_error = None
    elif opts.sack:
        if not module_exists("clang"):
            sys.exit("Sack input requires clang and it's not installed")
        from prophyc.parsers.sack import SackParser
        parser = SackParser(opts.include_dirs)
        parse_error = None
    else:
        from prophyc.parsers.prophy import ProphyParser, ParseError
        parser = ProphyParser()
        parse_error = ParseError

    serializers = []
    if opts.python_out:
        from prophyc.generators.python import PythonGenerator
        serializers.append(PythonGenerator(opts.python_out))
    if opts.cpp_out:
        from prophyc.generators.cpp import CppGenerator
        serializers.append(CppGenerator(opts.cpp_out))

    if not serializers:
        sys.exit("Missing output directives")

    for input_file in opts.input_files:
        try:
            nodes = parser.parse(input_file)
        except parse_error as e:
            sys.exit('\n'.join(e.errors))

        if opts.patch:
            from prophyc import patch
            patches = patch.parse(opts.patch)
            patch.patch(nodes, patches)
        model.topological_sort(nodes)
        model.cross_reference(nodes)
        model.evaluate_kinds(nodes)

        for serializer in serializers:
            basename = get_basename(input_file)
            serializer.serialize(nodes, basename)
Beispiel #42
0
def test_change_union_to_struct_excessive_params():
    nodes = [
        model.Union("MyUnion", [
            model.UnionMember("field1", "u32", 1),
            model.UnionMember("field2", "u32", 2)
        ])
    ]
    patches = {'MyUnion': [patch.Action('struct', ['surplus_param'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change union to struct takes no params: MyUnion' in str(e.value)
Beispiel #43
0
def test_change_union_to_struct_not_a_union():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('struct', [])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Can only change union to struct: MyStruct' in str(e.value)
Beispiel #44
0
def test_change_field_type_member_not_found():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('type', ['field4', 'TheRealType'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Beispiel #45
0
def test_make_field_limited_array_with_wrong_bound_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field4'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Array len member not found: MyStruct' in str(e.value)
Beispiel #46
0
def test_make_field_static_array_with_wrong_size_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('static', ['field3', 'wrong_size'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Size is not a number: MyStruct' in e.value.message
Beispiel #47
0
def test_fail_to_make_field_limited_array():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("after", "u32")
        ])
    ]

    patches = {'MyStruct': [patch.Action('limited', ['field2', 'after'])]}

    with pytest.raises(Exception, match="Array len member not found: "):
        patch.patch(nodes, patches)
Beispiel #48
0
def test_unknown_action():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('typo_or_something', [])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert "Unknown action: MyStruct Action(action='typo_or_something', params=[])" == e.value.message
Beispiel #49
0
def test_make_field_static_array_with_wrong_name_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('static', ['field4', '3'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Beispiel #50
0
def test_make_field_greedy_array_no_1_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]

    patches = {'MyStruct': [patch.Action('greedy', ['field2', 'extra_args'])]}
    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 1 params: MyStruct' in str(e.value)
Beispiel #51
0
def test_make_field_dynamic_array_member_not_found():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('dynamic', ['field4', 'field1'])]}

    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Member not found: MyStruct' in str(e.value)
Beispiel #52
0
def test_rename_node():
    nodes = [
        model.Struct("OldStruct", [model.StructMember("field", "u32")]),
        model.Enum("OldEnum", [model.EnumMember("val", "123")])
    ]

    patches = {
        'OldStruct': [patch.Action('rename', ['NewStruct'])],
        'OldEnum': [patch.Action('rename', ['NewEnum'])]
    }

    patch.patch(nodes, patches)

    assert nodes[0].name == 'NewStruct'
    assert nodes[1].name == 'NewEnum'
Beispiel #53
0
def test_remove_field():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('remove', ['field2'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field3', 'u32')
        ])
    ] == nodes
Beispiel #54
0
def test_make_field_static_array_no_2_params():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]

    patches = {'MyStruct': [patch.Action('static', ['field2'])]}
    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 2 params: MyStruct' in e.value.message

    patches = {'MyStruct': [patch.Action('static', ['field2', '3', 'extra'])]}
    with pytest.raises(Exception) as e:
        patch.patch(nodes, patches)
    assert 'Change field must have 2 params: MyStruct' in e.value.message
Beispiel #55
0
def test_make_field_limited_array():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32", size='20')
        ])
    ]
    patches = {'MyStruct': [patch.Action('limited', ['field3', 'field2'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field2', 'u32'),
            model.StructMember('field3', 'u32', bound='field2', size='20')
        ])
    ] == nodes
Beispiel #56
0
def test_change_field_type():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('type', ['field2', 'TheRealType'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field2', 'TheRealType'),
            model.StructMember('field3', 'u32')
        ])
    ] == nodes
Beispiel #57
0
def test_make_field_static_array():
    nodes = [
        model.Struct("MyStruct", [
            model.StructMember("field1", "u32"),
            model.StructMember("field2", "u32"),
            model.StructMember("field3", "u32")
        ])
    ]
    patches = {'MyStruct': [patch.Action('static', ['field3', '3'])]}

    patch.patch(nodes, patches)

    assert [
        model.Struct('MyStruct', [
            model.StructMember('field1', 'u32'),
            model.StructMember('field2', 'u32'),
            model.StructMember('field3', 'u32', size='3')
        ])
    ] == nodes