コード例 #1
0
def test_typechecks_type_another() -> None:
    ptr1 = Pointer32(SomeStruct, 0)
    ptr2 = Pointer32(UInt16, 0)
    ptr1_t = typeof(ptr1)
    ptr2_t = typeof(ptr2)

    assert not isinstance(ptr1_t, ptr2_t)
    assert not issubclass(ptr1_t, ptr2_t)

    assert not isinstance(ptr1, ptr2_t)
    with raises(TypeError):
        issubclass(ptr1, ptr2_t)  # type: ignore
コード例 #2
0
def test_create_new() -> None:
    ptr = Pointer32(SomeStruct, 0x1234)
    ptr_t = typeof(ptr)
    assert ptr_t.int_type() is UInt32
    assert ptr_t.ref_type() is SomeStruct
    assert sizeof(ptr_t) == 4
    assert sizeof(ptr) == 4
コード例 #3
0
def test_void_2() -> None:
    ptr = Pointer32(Void, 0x12)
    assert ptr.int_type() is UInt32
    assert ptr.ref_type() is Void
    assert sizeof(ptr) == 4

    ptr_t = typeof(ptr)
    assert ptr_t.int_type() is UInt32
    assert ptr_t.ref_type() is Void
    assert sizeof(ptr_t) == 4
コード例 #4
0
def test_typechecks_type() -> None:
    ptr = Pointer32(SomeStruct, 0)
    ptr_t = typeof(ptr)

    assert not isinstance(Pointer32, ptr_t)
    assert not issubclass(Pointer32, ptr_t)

    assert not isinstance(ptr_t, ptr_t)
    assert issubclass(ptr_t, ptr_t)

    assert isinstance(ptr, ptr_t)
    with raises(TypeError):
        issubclass(ptr, ptr_t)  # type: ignore

    assert not isinstance(0, ptr_t)
    with raises(TypeError):
        issubclass(0, ptr_t)  # type: ignore
コード例 #5
0
def test_init_another_2() -> None:
    ptr1 = Pointer32(SomeStruct, 0x1234)
    ptr2 = Pointer32(SomeStruct, ptr1)
    assert ptr2.get() == 0x1234
コード例 #6
0
def test_init_another_1() -> None:
    ptr_t = Pointer32[SomeStruct]
    ptr1 = Pointer32(SomeStruct, 0x1234)
    ptr2 = ptr_t(ptr1)
    assert ptr2.get() == 0x1234
コード例 #7
0
def test_init_int_2() -> None:
    ptr = Pointer32(SomeStruct, 0x1234)
    assert ptr.get() == 0x1234
コード例 #8
0
def test_init_bytes_2() -> None:
    ptr = Pointer32(SomeStruct, b'\x12\x34\x56\x78')
    assert ptr.get() == 0x78563412
コード例 #9
0
def test_name_2() -> None:
    data = Pointer32(UInt16, 0)
    ptr_t = typeof(data)
    assert type_name(ptr_t) == 'uint16_t *'
    assert type_name(data) == 'uint16_t *'
コード例 #10
0
 class StructA(Struct):
     ptr = Pointer32(ForwardRef)
コード例 #11
0
 class Container(Struct):
     ptr = Pointer32(SomeStruct)
コード例 #12
0
def test_bytes_cast() -> None:
    ptr = Pointer32(SomeStruct, 0x1234)
    assert bytes(ptr) == b'\x34\x12\x00\x00'
コード例 #13
0
def test_name_fwdred() -> None:
    data = Pointer32(ForwardRef, 0)
    ptr_t = typeof(data)
    assert type_name(ptr_t) == 'void *'
    assert type_name(data) == 'void *'
コード例 #14
0
def test_name_void() -> None:
    data = Pointer32(Void, 0)
    ptr_t = typeof(data)
    assert type_name(ptr_t) == 'void *'
    assert type_name(data) == 'void *'
コード例 #15
0
def test_init_none_2() -> None:
    ptr = Pointer32(SomeStruct)
    assert ptr.get() == 0
コード例 #16
0
def test_init_bad_2() -> None:
    with raises(TypeError):
        _ = Pointer32(SomeStruct, 'Bad value')  # type: ignore
コード例 #17
0
def test_int_cast() -> None:
    ptr = Pointer32(SomeStruct, 0x1234)
    assert int(ptr) == 0x1234