Esempio n. 1
0
def test_read_uint32_negative_offset():
    img = Image(Section(data=bytearray(10), start_address=0x1000))
    with pytest.raises(InvalidAddressError):
        img.read_numeric(0x0fff, "uint32_le")
Esempio n. 2
0
def test_read_write_float64():
    img = Image(Section(data=bytearray(32), start_address=0x1000))
    img.write_numeric(0x1000, 1234.5678, "float64_be")
    assert img.read_numeric(0x1000, "float64_be") == 1234.5678
    img.write_numeric(0x1000, 1234.5678, "float64_le")
    assert img.read_numeric(0x1000, "float64_le") == 1234.5678
Esempio n. 3
0
def test_read_write_int64():
    img = Image(Section(data=bytearray(32), start_address=0x1000))
    img.write_numeric(0x1000, -200000000000, "int64_be")
    assert img.read_numeric(0x1000, "int64_be") == -200000000000
    img.write_numeric(0x1000, -200000000000, "int64_le")
    assert img.read_numeric(0x1000, "int64_le") == -200000000000
Esempio n. 4
0
def test_read_write_uint32():
    img = Image(Section(data=bytearray(32), start_address=0x1000))
    img.write_numeric(0x1000, 0x55555555, "uint32_be")
    assert img.read_numeric(0x1000, "uint32_be") == 0x55555555
    img.write_numeric(0x1000, 0x55555555, "uint32_le")
    assert img.read_numeric(0x1000, "uint32_le") == 0x55555555
Esempio n. 5
0
def test_invalid_read_write_datatype_raises():
    img = Image(Section(data=bytearray(32), start_address=0x1000))
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "foobar_le")
Esempio n. 6
0
def test_read_write_datatypes_require_suffix():
    img = Image(Section(data=bytearray(32), start_address=0x1000))
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "uint8")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "int8")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "uint16")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "int16")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "uint32")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "int32")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "uint64")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "int64")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "float32")
    with pytest.raises(TypeError):
        img.read_numeric(0x1000, "float64")