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
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
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
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
def test_init_another_2() -> None: ptr1 = Pointer32(SomeStruct, 0x1234) ptr2 = Pointer32(SomeStruct, ptr1) assert ptr2.get() == 0x1234
def test_init_another_1() -> None: ptr_t = Pointer32[SomeStruct] ptr1 = Pointer32(SomeStruct, 0x1234) ptr2 = ptr_t(ptr1) assert ptr2.get() == 0x1234
def test_init_int_2() -> None: ptr = Pointer32(SomeStruct, 0x1234) assert ptr.get() == 0x1234
def test_init_bytes_2() -> None: ptr = Pointer32(SomeStruct, b'\x12\x34\x56\x78') assert ptr.get() == 0x78563412
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 *'
class StructA(Struct): ptr = Pointer32(ForwardRef)
class Container(Struct): ptr = Pointer32(SomeStruct)
def test_bytes_cast() -> None: ptr = Pointer32(SomeStruct, 0x1234) assert bytes(ptr) == b'\x34\x12\x00\x00'
def test_name_fwdred() -> None: data = Pointer32(ForwardRef, 0) ptr_t = typeof(data) assert type_name(ptr_t) == 'void *' assert type_name(data) == 'void *'
def test_name_void() -> None: data = Pointer32(Void, 0) ptr_t = typeof(data) assert type_name(ptr_t) == 'void *' assert type_name(data) == 'void *'
def test_init_none_2() -> None: ptr = Pointer32(SomeStruct) assert ptr.get() == 0
def test_init_bad_2() -> None: with raises(TypeError): _ = Pointer32(SomeStruct, 'Bad value') # type: ignore
def test_int_cast() -> None: ptr = Pointer32(SomeStruct, 0x1234) assert int(ptr) == 0x1234