Skip to content

Commit

Permalink
split Test_IStream
Browse files Browse the repository at this point in the history
  • Loading branch information
junkmd authored Jun 30, 2024
1 parent fb9ccdf commit 9309b51
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions comtypes/test/test_istream.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,41 @@
from comtypes.gen.PortableDeviceApiLib import IStream


class Test_IStream(ut.TestCase):
def test_istream(self):
# Create an IStream
stream: IStream = POINTER(IStream)() # type: ignore
comtypes._ole32.CreateStreamOnHGlobal(None, c_bool(True), byref(stream))
def _create_stream() -> IStream:
# Create an IStream
stream = POINTER(IStream)() # type: ignore
comtypes._ole32.CreateStreamOnHGlobal(None, c_bool(True), byref(stream))
return stream # type: ignore


class Test_RemoteWrite(ut.TestCase):
def test_RemoteWrite(self):
stream = _create_stream()
test_data = "Some data".encode("utf-8")
pv = (c_ubyte * len(test_data)).from_buffer(bytearray(test_data))

written = stream.RemoteWrite(pv, len(test_data))

# Verification
self.assertEqual(written, len(test_data))
# make sure the data actually gets written before trying to read back
stream.Commit(0)


class Test_RemoteRead(ut.TestCase):
def test_RemoteRead(self):
stream = _create_stream()
test_data = "Some data".encode("utf-8")
pv = (c_ubyte * len(test_data)).from_buffer(bytearray(test_data))
stream.RemoteWrite(pv, len(test_data))

# Make sure the data actually gets written before trying to read back
stream.Commit(0)
# Move the stream back to the beginning
STREAM_SEEK_SET = 0
stream.RemoteSeek(0, STREAM_SEEK_SET)

read_buffer_size = 1024
buffer_size = 1024

read_buffer, data_read = stream.RemoteRead(read_buffer_size)
read_buffer, data_read = stream.RemoteRead(buffer_size)

# Verification
self.assertEqual(data_read, len(test_data))
Expand Down

0 comments on commit 9309b51

Please sign in to comment.