Ejemplo n.º 1
0
def test_stringz__dump_multibyte_with_bom():
    """Ensure multibyte encodings work with StringZ as well and the BOM isn't
    added before the null byte."""
    field = stringlike.StringZ(encoding="utf-16")

    if sys.byteorder == "little":
        assert field.to_bytes(
            "AbCd") == b"\xff\xfeA\x00b\x00C\x00d\x00\x00\x00"
    else:
        assert field.to_bytes(
            "AbCd") == b"\xfe\xff\x00A\x00b\x00C\x00d\x00\x00"
Ejemplo n.º 2
0
def test_stringz__dump_default_null_crashes():
    field = stringlike.StringZ(null_value=DEFAULT)
    with pytest.raises(errors.UnserializableValueError):
        field.to_bytes(None)
Ejemplo n.º 3
0
def test_stringz__load_default_null_crashes():
    field = stringlike.StringZ(null_value=DEFAULT)
    with pytest.raises(errors.CannotDetermineNullError):
        field.from_bytes(b"\x00")
Ejemplo n.º 4
0
def test_stringz__load_null_value(null_value):
    field = stringlike.StringZ(null_value=null_value)
    assert field.from_bytes(b"NULL\x00") is None
Ejemplo n.º 5
0
def test_stringz_load_multibyte():
    """Test loading multibyte strings with a terminating null."""
    field = stringlike.StringZ(encoding="utf-16")
    assert field.from_bytes(b"\xff\xfeA\x00b\x00C\x00d\x00\x00\x00") == "AbCd"
    assert field.from_bytes(b"\xfe\xff\x00A\x00b\x00C\x00d\x00\x00") == "AbCd"
Ejemplo n.º 6
0
def test_stringz__dump_multibyte():
    """Basic multibyte test dump."""
    field = stringlike.StringZ(encoding="utf-32-le")
    assert (field.to_bytes("AbC") ==
            b"A\x00\x00\x00b\x00\x00\x00C\x00\x00\x00\x00\x00\x00\x00")
Ejemplo n.º 7
0
def test_stringz__dump_basic():
    """Basic test of StringZ dumping."""
    field = stringlike.StringZ(encoding="utf-8")
    assert field.to_bytes(
        r"¯\_(ツ)_/¯") == b"\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf\0"
Ejemplo n.º 8
0
def test_stringz__load_eof_before_null():
    """Crash if we hit the end of the data before we get a null byte."""
    field = stringlike.StringZ(encoding="utf-8")
    with pytest.raises(errors.DeserializationError):
        assert field.from_bytes(b"\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf")
Ejemplo n.º 9
0
def test_stringz__load_basic():
    """Basic test of StringZ loading."""
    field = stringlike.StringZ(encoding="utf-8")
    assert field.from_bytes(
        b"\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf\0") == r"¯\_(ツ)_/¯"