From 62656e3397b2502a58b0603959c76dde7b167653 Mon Sep 17 00:00:00 2001 From: Milanka Ringwald Date: Fri, 23 Oct 2015 22:41:31 +0200 Subject: [PATCH] write test for hfp ag codecs connection --- src/hfp.c | 39 ++--- src/hfp_ag.c | 261 ++++++++++++++++++---------------- src/hfp_hf.c | 3 +- test/hfp/hfp_ag_client_test.c | 29 ++-- test/hfp/mock.c | 30 +++- test/hfp/test_sequences.c | 49 ++++--- 6 files changed, 237 insertions(+), 174 deletions(-) diff --git a/src/hfp.c b/src/hfp.c index 89e11c84d..96c1596bf 100644 --- a/src/hfp.c +++ b/src/hfp.c @@ -628,6 +628,7 @@ void process_command(hfp_connection_t * context){ if (strncmp((char *)context->line_buffer+offset, HFP_AVAILABLE_CODECS, strlen(HFP_AVAILABLE_CODECS)) == 0){ context->command = HFP_CMD_AVAILABLE_CODECS; + context->notify_ag_on_new_codecs = 1; return; } @@ -700,10 +701,10 @@ void process_command(hfp_connection_t * context){ // printf("HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP update command\n"); if (isHandsFree){ context->hf_trigger_codec_connection_setup = 1; - printf("TRIGGER_CODEC_CONNECTION_SETUP hf_trigger_codec_connection_setup = 1\n"); + printf("update command: hf_trigger_codec_connection_setup = 1\n"); } else { context->hf_trigger_codec_connection_setup = 1; - printf("TRIGGER_CODEC_CONNECTION_SETUP hf_trigger_codec_connection_setup = 1\n"); + printf("update command: hf_trigger_codec_connection_setup = 1\n"); } return; } @@ -842,18 +843,18 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){ switch (context->command){ case HFP_CMD_HF_CONFIRMED_CODEC: context->codec_confirmed = atoi((char*)context->line_buffer); - printf("hfp parse HFP_CMD_HF_CONFIRMED_CODEC %d\n", context->codec_confirmed); + log_info("hfp parse HFP_CMD_HF_CONFIRMED_CODEC %d\n", context->codec_confirmed); break; case HFP_CMD_AG_SUGGESTED_CODEC: context->suggested_codec = atoi((char*)context->line_buffer); - printf("hfp parse HFP_CMD_AG_SUGGESTED_CODEC %d\n", context->suggested_codec); + log_info("hfp parse HFP_CMD_AG_SUGGESTED_CODEC %d\n", context->suggested_codec); 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); + log_info("Parsed supported feature %d\n", context->remote_supported_features); break; case HFP_CMD_AVAILABLE_CODECS: - printf("Parsed codec %s\n", context->line_buffer); + log_info("Parsed codec %s\n", context->line_buffer); context->remote_codecs[context->parser_item_index] = (uint16_t)atoi((char*)context->line_buffer); context->parser_item_index++; context->remote_codecs_nr = context->parser_item_index; @@ -862,11 +863,11 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){ if (context->retrieve_ag_indicators == 1){ strcpy((char *)context->ag_indicators[context->parser_item_index].name, (char *)context->line_buffer); context->ag_indicators[context->parser_item_index].index = context->parser_item_index+1; - printf("Indicator %d: %s (", context->ag_indicators_nr+1, context->line_buffer); + log_info("Indicator %d: %s (", context->ag_indicators_nr+1, context->line_buffer); } if (context->retrieve_ag_indicators_status == 1){ - printf("Parsed Indicator %d with status: %s\n", context->parser_item_index+1, context->line_buffer); + log_info("Parsed Indicator %d with status: %s\n", context->parser_item_index+1, context->line_buffer); context->ag_indicators[context->parser_item_index].status = atoi((char *) context->line_buffer); context->parser_item_index++; break; @@ -875,32 +876,32 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){ case HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE: context->parser_item_index++; if (context->parser_item_index != 4) break; - printf("Parsed Enable indicators: %s\n", context->line_buffer); + log_info("Parsed Enable indicators: %s\n", context->line_buffer); value = atoi((char *)&context->line_buffer[0]); context->enable_status_update_for_ag_indicators = (uint8_t) value; break; case HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES: - printf("Parsed Support call hold: %s\n", context->line_buffer); + log_info("Parsed Support call hold: %s\n", context->line_buffer); if (context->line_size > 2 ) break; strcpy((char *)context->remote_call_services[context->remote_call_services_nr].name, (char *)context->line_buffer); context->remote_call_services_nr++; break; case HFP_CMD_GENERIC_STATUS_INDICATOR: - printf("parser HFP_CMD_GENERIC_STATUS_INDICATOR 1 (%d, %d, %d)\n", + log_info("parser HFP_CMD_GENERIC_STATUS_INDICATOR 1 (%d, %d, %d)\n", context->list_generic_status_indicators, context->retrieve_generic_status_indicators, context->retrieve_generic_status_indicators_state); if (context->retrieve_generic_status_indicators == 1 || context->list_generic_status_indicators == 1){ - printf("Parsed Generic status indicator: %s\n", context->line_buffer); + log_info("Parsed Generic status indicator: %s\n", context->line_buffer); context->generic_status_indicators[context->parser_item_index].uuid = (uint16_t)atoi((char*)context->line_buffer); context->parser_item_index++; context->generic_status_indicators_nr = context->parser_item_index; break; } - printf("parser HFP_CMD_GENERIC_STATUS_INDICATOR 2\n"); + log_info("parser HFP_CMD_GENERIC_STATUS_INDICATOR 2\n"); if (context->retrieve_generic_status_indicators_state == 1){ // HF parses inital AG gen. ind. state - printf("Parsed List generic status indicator %s state: ", context->line_buffer); + log_info("Parsed List generic status indicator %s state: ", context->line_buffer); context->parser_item_index = (uint8_t)atoi((char*)context->line_buffer); break; } @@ -908,7 +909,7 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){ case HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE: // AG parses new gen. ind. state - printf("Parsed Enable ag indicator state: %s\n", context->line_buffer); + log_info("Parsed Enable ag indicator state: %s\n", context->line_buffer); value = atoi((char *)&context->line_buffer[0]); if (!context->ag_indicators[context->parser_item_index].mandatory){ context->ag_indicators[context->parser_item_index].enabled = value; @@ -918,22 +919,22 @@ void hfp_parse(hfp_connection_t * context, uint8_t byte){ case HFP_CMD_TRANSFER_AG_INDICATOR_STATUS: // indicators are indexed starting with 1 context->parser_item_index = atoi((char *)&context->line_buffer[0]) - 1; - printf("Parsed status of the AG indicator %d, status ", context->parser_item_index); + log_info("Parsed status of the AG indicator %d, status ", context->parser_item_index); break; case HFP_CMD_QUERY_OPERATOR_SELECTION: if (context->operator_name_format == 1){ if (context->line_buffer[0] == '3'){ - printf("Parsed Set network operator format : %s, ", context->line_buffer); + log_info("Parsed Set network operator format : %s, ", context->line_buffer); break; } // TODO emit ERROR, wrong format - printf("ERROR Set network operator format: index %s not supported\n", context->line_buffer); + log_info("ERROR Set network operator format: index %s not supported\n", context->line_buffer); break; } if (context->operator_name == 1) { context->network_operator.mode = atoi((char *)&context->line_buffer[0]); - printf("Parsed network operator mode: %d, ", context->network_operator.mode); + log_info("Parsed network operator mode: %d, ", context->network_operator.mode); break; } break; diff --git a/src/hfp_ag.c b/src/hfp_ag.c index 29321773a..fd0028c0a 100644 --- a/src/hfp_ag.c +++ b/src/hfp_ag.c @@ -364,7 +364,7 @@ static uint8_t hfp_ag_suggest_codec(hfp_connection_t *context){ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * context){ - if (context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return; + if (context->state >= HFP_CODECS_CONNECTION_ESTABLISHED) return; printf(" AG run for context_service_level_connection \n"); switch(context->command){ @@ -388,6 +388,12 @@ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * c hfp_ag_retrieve_codec_cmd(context->rfcomm_cid); context->state = HFP_W4_RETRIEVE_INDICATORS; break; + case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED: + context->suggested_codec = hfp_ag_suggest_codec(context); + printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec); + hfp_ag_ok(context->rfcomm_cid); + break; + default: break; } @@ -423,9 +429,6 @@ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * c context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; hfp_emit_event(hfp_callback, HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED, 0); break; - case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED: - // TODO - break; default: break; } @@ -470,76 +473,102 @@ static void hfp_ag_run_for_context_service_level_connection(hfp_connection_t * c break; } break; + + default: + break; + } +} + +static int hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * context){ + if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return 0; + int done = 0; + printf(" SLC queries: "); + + switch(context->command){ + case HFP_CMD_AVAILABLE_CODECS: + context->suggested_codec = hfp_ag_suggest_codec(context); + printf("received BAC == new HF codecs, suggested codec %d\n", context->suggested_codec); + hfp_ag_ok(context->rfcomm_cid); + done = 1; + break; + case HFP_CMD_QUERY_OPERATOR_SELECTION: - if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) break; if (context->operator_name_format == 1){ if (context->network_operator.format != 0){ hfp_ag_error(context->rfcomm_cid); + done = 1; break; } hfp_ag_ok(context->rfcomm_cid); + done = 1; context->operator_name_format = 0; break; } if (context->operator_name == 1){ hfp_ag_report_network_operator_name_cmd(context->rfcomm_cid, context->network_operator); context->operator_name = 0; + done = 1; break; } break; - default: - break; - } -} - -static void hfp_ag_run_for_context_service_level_connection_queries(hfp_connection_t * context){ - if (context->state != HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return; - - printf(" AG run for service_level_connection_queries \n"); - if (context->enable_status_update_for_ag_indicators){ - int i; - for (i = 0; i < context->ag_indicators_nr; i++){ - if (context->ag_indicators[i].enabled == 0) continue; - if (context->ag_indicators[i].status_changed == 0) continue; - hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, context->ag_indicators[i]); - context->ag_indicators[i].status_changed = 0; - return; - } - } - - if (context->enable_extended_audio_gateway_error_report){ - if (context->extended_audio_gateway_error){ - hfp_ag_report_extended_audio_gateway_error(context->rfcomm_cid, context->extended_audio_gateway_error); - context->extended_audio_gateway_error = 0; - return; - } - } - - -} - -static void hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){ - if (context->state < HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return; - if (context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return; - printf(" AG run for context_codecs_connection \n"); - switch (context->state){ - case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED: - if (context->notify_ag_on_new_codecs){ // received BAC - printf(" received BAC \n"); - context->notify_ag_on_new_codecs = 0; - context->suggested_codec = hfp_ag_suggest_codec(context); - hfp_ag_ok(context->rfcomm_cid); - return; + case HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE:{ + int i; + for (i = 0; i < context->ag_indicators_nr; i++){ + if (context->ag_indicators[i].enabled == 0) continue; + if (context->ag_indicators[i].status_changed == 0) continue; + hfp_ag_transfer_ag_indicators_status_cmd(context->rfcomm_cid, context->ag_indicators[i]); + done = 1; + context->ag_indicators[i].status_changed = 0; + return done; + } + break; } - + case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP: if (context->hf_trigger_codec_connection_setup){ // received BCC printf(" received BCC \n"); context->hf_trigger_codec_connection_setup = 0; context->ag_trigger_codec_connection_setup = 1; + context->state = HFP_SLE_W2_EXCHANGE_COMMON_CODEC; hfp_ag_ok(context->rfcomm_cid); - return; + done = 1; + return done; } - + + if (context->ag_trigger_codec_connection_setup){ // received BCS + printf(" send BCS \n"); + context->ag_trigger_codec_connection_setup = 0; + context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; + context->suggested_codec = hfp_ag_suggest_codec(context); + hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec); + done = 1; + return done; + } + break; + case HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR: + if (context->extended_audio_gateway_error){ + hfp_ag_report_extended_audio_gateway_error(context->rfcomm_cid, context->extended_audio_gateway_error); + context->extended_audio_gateway_error = 0; + done = 1; + break; + } + case HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE: + printf("TODO\n"); + break; + default: + break; + } + return done; +} + + +static void hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context){ + if (context->state <= HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED) return; + if (context->state > HFP_CODECS_CONNECTION_ESTABLISHED) return; + + + printf(" AG run for context_codecs_connection: "); + switch (context->state){ + case HFP_SLE_W2_EXCHANGE_COMMON_CODEC: if (context->ag_trigger_codec_connection_setup){ // received BCS printf(" send BCS \n"); context->ag_trigger_codec_connection_setup = 0; @@ -548,80 +577,71 @@ static void hfp_ag_run_for_context_codecs_connection(hfp_connection_t * context) hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec); return; } - break; case HFP_SLE_W4_EXCHANGE_COMMON_CODEC: - if (context->notify_ag_on_new_codecs){ // received BAC - context->notify_ag_on_new_codecs = 0; - if (context->suggested_codec != hfp_ag_suggest_codec(context)){ - context->suggested_codec = hfp_ag_suggest_codec(context); - context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; - } - hfp_ag_ok(context->rfcomm_cid); - return; - } - - if (context->codec_confirmed != context->suggested_codec){ - context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; - hfp_ag_error(context->rfcomm_cid); - return; - } - context->negotiated_codec = context->codec_confirmed; - context->state = HFP_CODECS_CONNECTION_ESTABLISHED; - hfp_ag_ok(context->rfcomm_cid); - hfp_emit_event(hfp_callback, HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE, 0); - return; - - case HFP_CODECS_CONNECTION_ESTABLISHED: - if (context->notify_ag_on_new_codecs){ // received BAC - context->notify_ag_on_new_codecs = 0; - if (context->suggested_codec != hfp_ag_suggest_codec(context)){ - context->suggested_codec = hfp_ag_suggest_codec(context); - context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; - } - hfp_ag_ok(context->rfcomm_cid); - return; - } - if (context->ag_trigger_codec_connection_setup){ - context->ag_trigger_codec_connection_setup = 0; - if (context->negotiated_codec != hfp_ag_suggest_codec(context)){ - context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; - context->suggested_codec = hfp_ag_suggest_codec(context); - hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec); - } + switch(context->command){ + case HFP_CMD_AVAILABLE_CODECS: + if (context->notify_ag_on_new_codecs){ // received BAC + printf(" received BAC\n"); + context->notify_ag_on_new_codecs = 0; + if (context->suggested_codec != hfp_ag_suggest_codec(context)){ + context->suggested_codec = hfp_ag_suggest_codec(context); + context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; + } + hfp_ag_ok(context->rfcomm_cid); + return; + } + break; + case HFP_CMD_HF_CONFIRMED_CODEC: + printf(" received AT+BCS\n"); + if (context->codec_confirmed != context->suggested_codec){ + context->state = HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED; + hfp_ag_error(context->rfcomm_cid); + return; + } + context->negotiated_codec = context->codec_confirmed; + context->state = HFP_CODECS_CONNECTION_ESTABLISHED; + hfp_emit_event(hfp_callback, HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE, 0); + hfp_ag_ok(context->rfcomm_cid); + break; + default: + break; } break; + + case HFP_CODECS_CONNECTION_ESTABLISHED: + switch(context->command){ + case HFP_CMD_AVAILABLE_CODECS: + + if (context->notify_ag_on_new_codecs){ // received BAC + context->notify_ag_on_new_codecs = 0; + if (context->suggested_codec != hfp_ag_suggest_codec(context)){ + context->suggested_codec = hfp_ag_suggest_codec(context); + context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; + } + hfp_ag_ok(context->rfcomm_cid); + return; + } + break; + case HFP_CMD_AG_SUGGESTED_CODEC: + if (context->ag_trigger_codec_connection_setup){ + context->ag_trigger_codec_connection_setup = 0; + if (context->negotiated_codec != hfp_ag_suggest_codec(context)){ + context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; + context->suggested_codec = hfp_ag_suggest_codec(context); + hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec); + } + } + break; + default: + break; + } + default: break; } - switch(context->command){ - // START codec setup - case HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP: - switch (context->state){ - case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED: - hfp_ag_cmd_suggest_codec(context->rfcomm_cid, context->suggested_codec); - context->state = HFP_SLE_W4_EXCHANGE_COMMON_CODEC; - break; - default: - hfp_ag_error(context->rfcomm_cid); - break; - } - break; - case HFP_CMD_AVAILABLE_CODECS: - switch(context->state){ - case HFP_SERVICE_LEVEL_CONNECTION_ESTABLISHED: - case HFP_SLE_W2_EXCHANGE_COMMON_CODEC: - case HFP_SLE_W4_EXCHANGE_COMMON_CODEC: - context->notify_ag_on_new_codecs = 1; - break; - default: - break; - } - break; - default: - break; - } + } @@ -642,13 +662,13 @@ void hfp_run_for_context(hfp_connection_t *context){ context->send_error = 0; return; } - + int done; if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; hfp_ag_run_for_context_service_level_connection(context); if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; - hfp_ag_run_for_context_service_level_connection_queries(context); - if (!rfcomm_can_send_packet_now(context->rfcomm_cid)) return; + done = hfp_ag_run_for_context_service_level_connection_queries(context); + if (!rfcomm_can_send_packet_now(context->rfcomm_cid) || done) return; hfp_ag_run_for_context_codecs_connection(context); if (context->command == HFP_CMD_NONE){ @@ -697,7 +717,6 @@ static void hfp_run(){ static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ switch (packet_type){ case RFCOMM_DATA_PACKET: - printf("\nAG received: %s", packet); hfp_handle_rfcomm_event(packet_type, channel, packet, size); break; case HCI_EVENT_PACKET: diff --git a/src/hfp_hf.c b/src/hfp_hf.c index d330adebb..d69d62dae 100644 --- a/src/hfp_hf.c +++ b/src/hfp_hf.c @@ -606,7 +606,7 @@ static void hfp_handle_rfcomm_event(uint8_t packet_type, uint16_t channel, uint8 packet[size] = 0; int pos, i; - printf("AG response: %s\n", packet+2); + printf("\nHF received: %s", packet+2); for (pos = 0; pos < size ; pos++){ hfp_parse(context, packet[pos]); @@ -649,7 +649,6 @@ static void hfp_run(){ static void packet_handler(void * connection, uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ switch (packet_type){ case RFCOMM_DATA_PACKET: - printf("\nHF received: %s\n", packet); hfp_handle_rfcomm_event(packet_type, channel, packet, size); break; case HCI_EVENT_PACKET: diff --git a/test/hfp/hfp_ag_client_test.c b/test/hfp/hfp_ag_client_test.c index 3c3da1ab4..c15406175 100644 --- a/test/hfp/hfp_ag_client_test.c +++ b/test/hfp/hfp_ag_client_test.c @@ -113,12 +113,12 @@ int expected_rfcomm_command(const char * expected_cmd){ return 0; } -#define HFP_NOP_CMD "" + void simulate_test_sequence(char ** test_steps, int nr_test_steps){ int i = 0; for (i=0; i < nr_test_steps; i++){ char * cmd = test_steps[i]; - printf(" test step %d %s\n", i, cmd); + printf("\n --> Test step %d: ", i); if (memcmp(cmd, "AT", 2) == 0){ inject_rfcomm_command_to_ag((uint8_t*)cmd, strlen(cmd)); } else if (memcmp(cmd, "NOP", 3) == 0){ @@ -127,10 +127,11 @@ void simulate_test_sequence(char ** test_steps, int nr_test_steps){ } else { int expected_cmd = expected_rfcomm_command(cmd); if (!expected_cmd){ - printf("\nError: Expected:'%s', but got:'%s'", cmd, (char *)get_rfcomm_payload()); + printf("\nError: Expected:'%s', but got:'%s'\n", cmd, (char *)get_rfcomm_payload()); + CHECK_EQUAL(expected_cmd,1); return; } - printf("AG response verified %s\n", cmd); + printf("AG response verified %s\n\n", cmd); } } } @@ -144,13 +145,13 @@ void packet_handler(uint8_t * event, uint16_t event_size){ switch (event[2]) { case HFP_SUBEVENT_SERVICE_LEVEL_CONNECTION_ESTABLISHED: - printf("\n\n\n\n ** SLC established **\n\n\n\n\n"); + printf("\n** SLC established **\n\n"); service_level_connection_established = 1; codecs_connection_established = 0; audio_connection_established = 0; break; case HFP_SUBEVENT_CODECS_CONNECTION_COMPLETE: - printf("\n\n\n\n ** CC established **\n\n\n\n\n"); + printf("\n** CC established **\n\n"); codecs_connection_established = 1; audio_connection_established = 0; break; @@ -179,6 +180,8 @@ TEST_GROUP(HFPClient){ if (service_level_connection_established){ hfp_ag_release_service_level_connection(device_addr); CHECK_EQUAL(service_level_connection_released, 1); + service_level_connection_established = 0; + service_level_connection_released = 0; } } @@ -190,28 +193,34 @@ TEST_GROUP(HFPClient){ void setup_hfp_codecs_connection(char ** test_steps, int nr_test_steps){ codecs_connection_established = 0; - //hfp_ag_negotiate_codecs(device_addr); simulate_test_sequence((char **) test_steps, nr_test_steps); } }; TEST(HFPClient, HFCodecsConnectionEstablished){ - setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size()); - CHECK_EQUAL(service_level_connection_established, 1); + for (int i = 0; i < cc_tests_size(); i++){ + service_level_connection_established = 0; + setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size()); + CHECK_EQUAL(service_level_connection_established, 1); + setup_hfp_codecs_connection(hfp_cc_tests()[i].test, hfp_cc_tests()[i].len); CHECK_EQUAL(codecs_connection_established, 1); + teardown(); } } // TEST(HFPClient, HFServiceLevelConnectionCommands){ +// service_level_connection_established = 0; // setup_hfp_service_level_connection(default_slc_setup(), default_slc_setup_size()); +// CHECK_EQUAL(service_level_connection_established, 1); + // for (int i = 0; i < slc_cmds_tests_size(); i++){ // simulate_test_sequence(hfp_slc_cmds_tests()[i].test, hfp_slc_cmds_tests()[i].len); // } -// CHECK_EQUAL(service_level_connection_established, 1); + // } // TEST(HFPClient, HFServiceLevelConnectionEstablished){ diff --git a/test/hfp/mock.c b/test/hfp/mock.c index e8db31c7d..d23bdc24b 100644 --- a/test/hfp/mock.c +++ b/test/hfp/mock.c @@ -103,12 +103,30 @@ static void prepare_rfcomm_buffer(uint8_t * data, int len){ rfcomm_payload_len = pos; } +static void print_without_newlines(uint8_t *data, uint16_t len){ + int found_newline = 0; + int found_item = 0; + printf("\n"); + for (int i=0; i Send cmd to HF state machine: %s", data); + printf("Send cmd to HF state machine: %s", data); } else { - printf("\n\n ---> trigger HF state machine: %s", data); + printf("Trigger HF state machine: %s", data); } (*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len); } @@ -228,9 +246,9 @@ void inject_rfcomm_command_to_ag(uint8_t * data, int len){ prepare_rfcomm_buffer(data, len); if (memcmp((char*)data, "AT", 2) == 0){ - printf("\n\n ---> Send cmd to AG state machine: %s", data); + printf("Send cmd to AG state machine: %s\n", data); } else { - printf("\n\n ---> trigger AG state machine: %s", data); + printf("Trigger AG state machine: %s", data); } (*registered_rfcomm_packet_handler)(active_connection, RFCOMM_DATA_PACKET, rfcomm_cid, (uint8_t *) &rfcomm_payload[0], rfcomm_payload_len); } diff --git a/test/hfp/test_sequences.c b/test/hfp/test_sequences.c index a7f5a5b1d..a05952b45 100644 --- a/test/hfp/test_sequences.c +++ b/test/hfp/test_sequences.c @@ -82,6 +82,26 @@ const char * slc_cmds_test1[] = { "OK" }; +const char * slc_cmds_test2[] = { + "AT+BAC=1,3", + "OK" +}; + +const char * slc_cmds_test3[] = { + "AT+BAC=1,3", + "OK" +}; + +const char * slc_cmds_test4[] = { + "AT+BAC=1,3", + "OK" +}; + +const char * slc_cmds_test5[] = { + "AT+BAC=1,3", + "OK" +}; + hfp_test_item_t slc_cmds_tests[] = { TEST_SEQUENCE(slc_cmds_test1) }; @@ -89,58 +109,55 @@ hfp_test_item_t slc_cmds_tests[] = { const char * cc_test1[] = { "AT+BCC", "OK", + "NOP", "+BCS:1", "AT+BCS=1", "OK" }; const char * cc_test2[] = { - "AT+BCC", + "AT+BAC=1,2", + "OK", + "AT+BCC", "OK", - "NOP", "NOP+BCS:1", "AT+BCS=1", "OK" }; + const char * cc_test3[] = { "AT+BAC=1,2", "OK", "AT+BCC", "OK", - "+BCS:1", - "AT+BCS=1", - "OK" -}; - - -const char * cc_test4[] = { - "AT+BAC=1,2", - "OK", - "AT+BCC", - "OK", + "NOP", "+BCS:1", "AT+BAC=2,3", "OK", + "NOP", "+BCS:2", "AT+BCS=2", "OK" }; -const char * cc_test5[] = { +const char * cc_test4[] = { "AT+BCC", "OK", + "NOP", "+BCS:1", "AT+BAC=2,3", "OK", + "NOP", "+BCS:2", "AT+BCS=2", "OK" }; hfp_test_item_t cc_tests[] = { - TEST_SEQUENCE(cc_test1)//, - // TEST_SEQUENCE(cc_test2), + TEST_SEQUENCE(cc_test1), + TEST_SEQUENCE(cc_test2), + // TEST_SEQUENCE(cc_test3), // TEST_SEQUENCE(cc_test3) };