From 99f65fee91284340dff9ca486c54e6010bb124e2 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 21 Aug 2015 22:31:01 +0200 Subject: [PATCH] hfp: audio connection unit tests --- src/hfp.c | 5 +++++ test/hfp/hfp_ag_parser_test.c | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/hfp.c b/src/hfp.c index bfd946993..a03fa85ca 100644 --- a/src/hfp.c +++ b/src/hfp.c @@ -696,11 +696,13 @@ void process_command(hfp_connection_t * context){ if (strncmp((char *)context->line_buffer+offset, HFP_TRIGGER_CODEC_CONNECTION_SETUP, strlen(HFP_TRIGGER_CODEC_CONNECTION_SETUP)) == 0){ context->command = HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP; + context->trigger_codec_connection_setup = 1; return; } if (strncmp((char *)context->line_buffer+offset, HFP_CONFIRM_COMMON_CODEC, strlen(HFP_CONFIRM_COMMON_CODEC)) == 0){ context->command = HFP_CMD_CONFIRM_COMMON_CODEC; + return; } @@ -828,6 +830,9 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){ case HFP_PARSER_CMD_SEQUENCE: // parse comma separated sequence, ignore breacktes switch (context->command){ + case HFP_CMD_CONFIRM_COMMON_CODEC: + context->remote_codec_received = atoi((char*)context->line_buffer); + break; case HFP_CMD_SUPPORTED_FEATURES: context->remote_supported_features = atoi((char*)context->line_buffer); printf("Parsed supported feature %d\n", context->remote_supported_features); diff --git a/test/hfp/hfp_ag_parser_test.c b/test/hfp/hfp_ag_parser_test.c index f4b31c68c..959e74a21 100644 --- a/test/hfp/hfp_ag_parser_test.c +++ b/test/hfp/hfp_ag_parser_test.c @@ -222,6 +222,28 @@ TEST(HFPParser, HFP_AG_EXTENDED_AUDIO_GATEWAY_ERROR){ CHECK_EQUAL(context.enable_extended_audio_gateway_error_report, 1); } +TEST(HFPParser, HFP_AG_TRIGGER_CODEC_CONNECTION_SETUP){ + sprintf(packet, "\r\nAT%s\r\n", HFP_TRIGGER_CODEC_CONNECTION_SETUP); + + for (pos = 0; pos < strlen(packet); pos++){ + hfp_parse(&context, packet[pos]); + } + + CHECK_EQUAL(context.command, HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP); + CHECK_EQUAL(context.trigger_codec_connection_setup, 1); +} + +TEST(HFPParser, HFP_AG_CONFIRM_COMMON_CODEC){ + int codec = 2; + sprintf(packet, "\r\nAT%s=%d\r\n", HFP_CONFIRM_COMMON_CODEC, codec); + + for (pos = 0; pos < strlen(packet); pos++){ + hfp_parse(&context, packet[pos]); + } + + CHECK_EQUAL(context.command, HFP_CMD_CONFIRM_COMMON_CODEC); + CHECK_EQUAL(context.remote_codec_received, codec); +} int main (int argc, const char * argv[]){ return CommandLineTestRunner::RunAllTests(argc, argv);