RFCOMM: Slightly refactor and correct constants

This commit is contained in:
Josh Wu
2024-01-31 23:56:34 +08:00
parent 071fc2723a
commit 6a34c9f224
2 changed files with 69 additions and 99 deletions

View File

@@ -15,7 +15,11 @@
# -----------------------------------------------------------------------------
# Imports
# -----------------------------------------------------------------------------
from bumble.rfcomm import RFCOMM_Frame
import asyncio
import pytest
from . import test_utils
from bumble.rfcomm import RFCOMM_Frame, Server, Client, DLC
# -----------------------------------------------------------------------------
@@ -43,6 +47,29 @@ def test_frames():
basic_frame_check(frame)
# -----------------------------------------------------------------------------
@pytest.mark.asyncio
async def test_basic_connection():
devices = test_utils.TwoDevices()
await devices.setup_connection()
accept_future: asyncio.Future[DLC] = asyncio.get_running_loop().create_future()
channel = Server(devices[0]).listen(acceptor=accept_future.set_result)
multiplexer = await Client(devices.connections[1]).start()
dlcs = await asyncio.gather(accept_future, multiplexer.open_dlc(channel))
queues = [asyncio.Queue(), asyncio.Queue()]
for dlc, queue in zip(dlcs, queues):
dlc.sink = queue.put_nowait
dlcs[0].write(b'The quick brown fox jumps over the lazy dog')
assert await queues[1].get() == b'The quick brown fox jumps over the lazy dog'
dlcs[1].write(b'Lorem ipsum dolor sit amet')
assert await queues[0].get() == b'Lorem ipsum dolor sit amet'
# -----------------------------------------------------------------------------
if __name__ == '__main__':
test_frames()