コード例 #1
0
def test_binding_at_template_assignment():
    template0 = XMLTemplateParser("""
        <template name="template0" size="4">
        </template>
        """).parse()
    template1 = XMLTemplateParser("""
        <template name="template0">
            <layout name="layout0">
                <area name="area0">
                    <field name="field1_size" size="4"></field>
                    <field name="field1" size="{field1_size, byteorder=little}"></field>
                    <field name="field2" size="{field1_size, byteorder=big}"></field>
                </area>
            </layout>
        </template>""").parse()
    template_provider0 = TemplateProvider(template0)
    template_provider1 = TemplateProvider(template1)
    data_provider = DataProvider(io.BytesIO(bytes(4 * [0x0])))
    binalyzer = Binalyzer(template_provider0, data_provider)
    binalyzer.template = template_provider1.template
    binalyzer.data = io.BytesIO(bytes([0x04, 0x00, 0x00, 0x00]))
    field1_size = find_by_attr(template1, "field1_size")
    field1 = find_by_attr(template1, "field1")
    field2 = find_by_attr(template1, "field2")
    assert field1_size.size == 4
    assert field1_size.value == bytes([0x04, 0x00, 0x00, 0x00])
    assert field1.size == 0x4
    assert field2.size == 0x4000000
コード例 #2
0
def test_binalyzer_set_template():
    template_mock1 = Template(name="a")
    template_mock2 = Template(name="b")
    template_provider = TemplateProvider(template_mock1)
    binalyzer = Binalyzer()
    binalyzer.template_provider = template_provider
    binalyzer.template = template_mock2
    assert binalyzer.template.name == template_mock2.name
    assert binalyzer.template.name != template_mock1.name
コード例 #3
0
def test_count_array_access():
    a = Template(name="a")
    b = Template(name="b", parent=a)
    b.count = 3

    binalyzer = Binalyzer()
    binalyzer.template = a

    assert len(binalyzer.template.b) == 3
    assert binalyzer.template.b[0].name == "b-0"
    assert binalyzer.template.b[1].name == "b-1"
    assert binalyzer.template.b[2].name == "b-2"