mirror of
https://github.com/google/bumble.git
synced 2026-05-10 04:18:03 +00:00
Add tests for batched HFP commands/responses; reformat
This commit is contained in:
@@ -818,7 +818,9 @@ class HfProtocol(pyee.EventEmitter):
|
||||
elif response.code in UNSOLICITED_CODES:
|
||||
self.unsolicited_queue.put_nowait(response)
|
||||
else:
|
||||
logger.warning(f"dropping unexpected response with code '{response.code}'")
|
||||
logger.warning(
|
||||
f"dropping unexpected response with code '{response.code}'"
|
||||
)
|
||||
|
||||
async def execute_command(
|
||||
self,
|
||||
@@ -1245,6 +1247,7 @@ class AgProtocol(pyee.EventEmitter):
|
||||
# Append to the read buffer.
|
||||
self.read_buffer.extend(data)
|
||||
|
||||
while self.read_buffer:
|
||||
# Locate the trailer.
|
||||
trailer = self.read_buffer.find(b'\r')
|
||||
if trailer == -1:
|
||||
|
||||
@@ -569,6 +569,38 @@ async def test_sco_setup():
|
||||
await asyncio.gather(*sco_disconnection_futures)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@pytest.mark.asyncio
|
||||
async def test_hf_batched_response(
|
||||
hfp_connections: Tuple[hfp.HfProtocol, hfp.AgProtocol]
|
||||
):
|
||||
hf, ag = hfp_connections
|
||||
|
||||
ag.send_response = lambda str: None
|
||||
ag.dlc.write(b'\r\n+BIND: (1,2)\r\n\r\nOK\r\n')
|
||||
|
||||
await hf.execute_command("AT+BIND=?", response_type=hfp.AtResponseType.SINGLE)
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
@pytest.mark.asyncio
|
||||
async def test_ag_batched_commands(
|
||||
hfp_connections: Tuple[hfp.HfProtocol, hfp.AgProtocol]
|
||||
):
|
||||
hf, ag = hfp_connections
|
||||
|
||||
answer_future = asyncio.get_running_loop().create_future()
|
||||
ag.on('answer', lambda: answer_future.set_result(None))
|
||||
|
||||
hang_up_future = asyncio.get_running_loop().create_future()
|
||||
ag.on('hang_up', lambda: hang_up_future.set_result(None))
|
||||
|
||||
hf.dlc.write(b'ATA\rAT+CHUP\r')
|
||||
|
||||
await answer_future
|
||||
await hang_up_future
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
async def run():
|
||||
await test_slc()
|
||||
|
||||
Reference in New Issue
Block a user