xref: /btstack/test/hfp/hfp_at_parser_test.cpp (revision da8e14c5aa3783b6bb7dd63e71572a901bcf168b)
11d3bd1e5SMatthias Ringwald /*
21d3bd1e5SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
31d3bd1e5SMatthias Ringwald  *
41d3bd1e5SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
51d3bd1e5SMatthias Ringwald  * modification, are permitted provided that the following conditions
61d3bd1e5SMatthias Ringwald  * are met:
71d3bd1e5SMatthias Ringwald  *
81d3bd1e5SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
91d3bd1e5SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
101d3bd1e5SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
111d3bd1e5SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
121d3bd1e5SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
131d3bd1e5SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
141d3bd1e5SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
151d3bd1e5SMatthias Ringwald  *    from this software without specific prior written permission.
161d3bd1e5SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
171d3bd1e5SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
181d3bd1e5SMatthias Ringwald  *    monetary gain.
191d3bd1e5SMatthias Ringwald  *
201d3bd1e5SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
211d3bd1e5SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221d3bd1e5SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
231d3bd1e5SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
241d3bd1e5SMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
251d3bd1e5SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
261d3bd1e5SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
271d3bd1e5SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
281d3bd1e5SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
291d3bd1e5SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
301d3bd1e5SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311d3bd1e5SMatthias Ringwald  * SUCH DAMAGE.
321d3bd1e5SMatthias Ringwald  *
331d3bd1e5SMatthias Ringwald  * Please inquire about commercial licensing options at
341d3bd1e5SMatthias Ringwald  * [email protected]
351d3bd1e5SMatthias Ringwald  *
361d3bd1e5SMatthias Ringwald  */
371d3bd1e5SMatthias Ringwald 
381d3bd1e5SMatthias Ringwald 
391d3bd1e5SMatthias Ringwald #include <stdint.h>
401d3bd1e5SMatthias Ringwald #include <stdio.h>
411d3bd1e5SMatthias Ringwald #include <stdlib.h>
421d3bd1e5SMatthias Ringwald #include <string.h>
431d3bd1e5SMatthias Ringwald 
441d3bd1e5SMatthias Ringwald #include "CppUTest/TestHarness.h"
451d3bd1e5SMatthias Ringwald #include "CppUTest/CommandLineTestRunner.h"
461d3bd1e5SMatthias Ringwald 
471d3bd1e5SMatthias Ringwald #include "classic/hfp.h"
481d3bd1e5SMatthias Ringwald #include "classic/hfp_ag.h"
491d3bd1e5SMatthias Ringwald 
501d3bd1e5SMatthias Ringwald void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree);
511d3bd1e5SMatthias Ringwald 
521d3bd1e5SMatthias Ringwald static  hfp_connection_t context;
531d3bd1e5SMatthias Ringwald static int hfp_ag_indicators_nr = 7;
541d3bd1e5SMatthias Ringwald static hfp_ag_indicator_t hfp_ag_indicators[] = {
551d3bd1e5SMatthias Ringwald     // index, name, min range, max range, status, mandatory, enabled, status changed
561d3bd1e5SMatthias Ringwald     {1, "service",   0, 1, 1, 0, 0, 0},
571d3bd1e5SMatthias Ringwald     {2, "call",      0, 1, 0, 1, 1, 0},
581d3bd1e5SMatthias Ringwald     {3, "callsetup", 0, 3, 0, 1, 1, 0},
591d3bd1e5SMatthias Ringwald     {4, "battchg",   0, 5, 3, 0, 0, 0},
601d3bd1e5SMatthias Ringwald     {5, "signal",    0, 5, 5, 0, 0, 0},
611d3bd1e5SMatthias Ringwald     {6, "roam",      0, 1, 0, 0, 0, 0},
621d3bd1e5SMatthias Ringwald     {7, "callheld",  0, 2, 0, 1, 1, 0}
631d3bd1e5SMatthias Ringwald };
641d3bd1e5SMatthias Ringwald static uint8_t call_status_index = 2;
651d3bd1e5SMatthias Ringwald static uint8_t callsetup_status_index = 3;
661d3bd1e5SMatthias Ringwald static uint8_t callheld_status_index = 7;
671d3bd1e5SMatthias Ringwald 
681d3bd1e5SMatthias Ringwald 
691d3bd1e5SMatthias Ringwald static void parse_ag(const char * packet){
701d3bd1e5SMatthias Ringwald     for (uint16_t pos = 0; pos < strlen(packet); pos++){
711d3bd1e5SMatthias Ringwald         hfp_parse(&context, packet[pos], 0);
721d3bd1e5SMatthias Ringwald     }
731d3bd1e5SMatthias Ringwald }
741d3bd1e5SMatthias Ringwald 
751d3bd1e5SMatthias Ringwald static void parse_hf(const char * packet){
761d3bd1e5SMatthias Ringwald     for (uint16_t pos = 0; pos < strlen(packet); pos++){
771d3bd1e5SMatthias Ringwald         hfp_parse(&context, packet[pos], 1);
781d3bd1e5SMatthias Ringwald     }
791d3bd1e5SMatthias Ringwald }
801d3bd1e5SMatthias Ringwald 
811d3bd1e5SMatthias Ringwald TEST_GROUP(HFPParser){
821d3bd1e5SMatthias Ringwald     char packet[200];
831d3bd1e5SMatthias Ringwald     int pos;
841d3bd1e5SMatthias Ringwald     int offset;
851d3bd1e5SMatthias Ringwald 
861d3bd1e5SMatthias Ringwald     void setup(void){
87016a59dfSMatthias Ringwald         memset(&context, 0, sizeof(hfp_connection_t));
881d3bd1e5SMatthias Ringwald         context.parser_state = HFP_PARSER_CMD_HEADER;
891d3bd1e5SMatthias Ringwald         context.parser_item_index = 0;
901d3bd1e5SMatthias Ringwald         context.line_size = 0;
911d3bd1e5SMatthias Ringwald         context.ag_indicators_nr = 0;
921d3bd1e5SMatthias Ringwald         context.remote_codecs_nr = 0;
93016a59dfSMatthias Ringwald         context.bnip_number[0] = 0;
94016a59dfSMatthias Ringwald         context.bnip_type = 0;
951d3bd1e5SMatthias Ringwald         memset(packet,0, sizeof(packet));
961d3bd1e5SMatthias Ringwald     }
971d3bd1e5SMatthias Ringwald };
981d3bd1e5SMatthias Ringwald 
991d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_OK){
1001d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s\r\n", HFP_OK);
1011d3bd1e5SMatthias Ringwald     parse_hf(packet);
1021d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
1031d3bd1e5SMatthias Ringwald }
1041d3bd1e5SMatthias Ringwald 
1051d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_SUPPORTED_FEATURES){
1061d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:1007\r\n\r\nOK\r\n", HFP_SUPPORTED_FEATURES);
1071d3bd1e5SMatthias Ringwald     parse_hf(packet);
1081d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
1091d3bd1e5SMatthias Ringwald     CHECK_EQUAL(1007, context.remote_supported_features);
1101d3bd1e5SMatthias Ringwald }
1111d3bd1e5SMatthias Ringwald 
1121d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_CMD_INDICATORS_QUERY){
1131d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s?\r\n", HFP_INDICATOR);
1141d3bd1e5SMatthias Ringwald     parse_ag(packet);
1151d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS, context.command);
1161d3bd1e5SMatthias Ringwald }
1171d3bd1e5SMatthias Ringwald 
1181d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_CMD_INDICATORS_RETRIEVE){
1191d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=?\r\n", HFP_INDICATOR);
1201d3bd1e5SMatthias Ringwald     parse_ag(packet);
1211d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RETRIEVE_AG_INDICATORS, context.command);
1221d3bd1e5SMatthias Ringwald }
1231d3bd1e5SMatthias Ringwald 
1241d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_INDICATORS){
1251d3bd1e5SMatthias Ringwald     offset = 0;
1261d3bd1e5SMatthias Ringwald     offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR);
1271d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
1281d3bd1e5SMatthias Ringwald     	if (pos != 0) {
1291d3bd1e5SMatthias Ringwald 			packet[offset++] = ',';
1301d3bd1e5SMatthias Ringwald 		}
1311d3bd1e5SMatthias Ringwald     	offset += snprintf(packet+offset, sizeof(packet)-offset, "(\"%s\", (%d, %d)),", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range);
1321d3bd1e5SMatthias Ringwald     }
1331d3bd1e5SMatthias Ringwald     offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n");
1341d3bd1e5SMatthias Ringwald     context.state = HFP_W4_RETRIEVE_INDICATORS;
1351d3bd1e5SMatthias Ringwald 
1361d3bd1e5SMatthias Ringwald     parse_hf(packet);
1371d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
1381d3bd1e5SMatthias Ringwald     CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr);
1391d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
1401d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index);
1411d3bd1e5SMatthias Ringwald         STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name);
1421d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range);
1431d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range);
1441d3bd1e5SMatthias Ringwald     }
1451d3bd1e5SMatthias Ringwald }
1461d3bd1e5SMatthias Ringwald 
1471d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_INDICATORS_RANGE){
1481d3bd1e5SMatthias Ringwald 	offset = 0;
1491d3bd1e5SMatthias Ringwald 	offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR);
1501d3bd1e5SMatthias Ringwald 	for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
1511d3bd1e5SMatthias Ringwald 		if (pos != 0) {
1521d3bd1e5SMatthias Ringwald 			packet[offset++] = ',';
1531d3bd1e5SMatthias Ringwald 		}
1541d3bd1e5SMatthias Ringwald 		offset += snprintf(packet+offset, sizeof(packet)-offset, "(\"%s\", (%d-%d)),", hfp_ag_indicators[pos].name, hfp_ag_indicators[pos].min_range, hfp_ag_indicators[pos].max_range);
1551d3bd1e5SMatthias Ringwald 	}
1561d3bd1e5SMatthias Ringwald 	offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n");
1571d3bd1e5SMatthias Ringwald 	context.state = HFP_W4_RETRIEVE_INDICATORS;
1581d3bd1e5SMatthias Ringwald 
1591d3bd1e5SMatthias Ringwald 	parse_hf(packet);
1601d3bd1e5SMatthias Ringwald 	CHECK_EQUAL(HFP_CMD_OK, context.command);
1611d3bd1e5SMatthias Ringwald 	CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr);
1621d3bd1e5SMatthias Ringwald 	for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
1631d3bd1e5SMatthias Ringwald 		CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index);
1641d3bd1e5SMatthias Ringwald 		STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name);
1651d3bd1e5SMatthias Ringwald 		CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range);
1661d3bd1e5SMatthias Ringwald 		CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range);
1671d3bd1e5SMatthias Ringwald 	}
1681d3bd1e5SMatthias Ringwald }
1691d3bd1e5SMatthias Ringwald 
1701d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_INDICATOR_STATUS){
1711d3bd1e5SMatthias Ringwald     // send status
1721d3bd1e5SMatthias Ringwald     offset = 0;
1731d3bd1e5SMatthias Ringwald     offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR);
1741d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr - 1; pos++){
1751d3bd1e5SMatthias Ringwald         offset += snprintf(packet+offset, sizeof(packet)-offset, "%d,", hfp_ag_indicators[pos].status);
1761d3bd1e5SMatthias Ringwald     }
1771d3bd1e5SMatthias Ringwald     offset += snprintf(packet+offset, sizeof(packet)-offset, "%d\r\n\r\nOK\r\n", hfp_ag_indicators[pos].status);
1781d3bd1e5SMatthias Ringwald 
1791d3bd1e5SMatthias Ringwald     //context.command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
1801d3bd1e5SMatthias Ringwald     context.state = HFP_W4_RETRIEVE_INDICATORS_STATUS;
1811d3bd1e5SMatthias Ringwald 
1821d3bd1e5SMatthias Ringwald     parse_hf(packet);
1831d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
1841d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
1851d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].status, context.ag_indicators[pos].status);
1861d3bd1e5SMatthias Ringwald     }
1871d3bd1e5SMatthias Ringwald }
1881d3bd1e5SMatthias Ringwald 
1891d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES_TEST){
1901d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=?\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES);
1911d3bd1e5SMatthias Ringwald     parse_ag(packet);
1921d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, context.command);
1931d3bd1e5SMatthias Ringwald }
1941d3bd1e5SMatthias Ringwald 
1951d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES_SET){
1961d3bd1e5SMatthias Ringwald     int action = 1;
1971d3bd1e5SMatthias Ringwald     int call_index = 2;
1981d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=%u%u\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, action, call_index);
1991d3bd1e5SMatthias Ringwald     parse_ag(packet);
2001d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_CALL_HOLD, context.command);
2011d3bd1e5SMatthias Ringwald     CHECK_EQUAL(action, context.ag_call_hold_action);
2021d3bd1e5SMatthias Ringwald     CHECK_EQUAL(call_index, context.call_index);
2031d3bd1e5SMatthias Ringwald }
2041d3bd1e5SMatthias Ringwald 
2051d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES){
2061d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:(1,1x,2,2x,3)\r\n\r\nOK\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES);
2071d3bd1e5SMatthias Ringwald     parse_hf(packet);
2081d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
2091d3bd1e5SMatthias Ringwald     CHECK_EQUAL(5, context.remote_call_services_index);
2101d3bd1e5SMatthias Ringwald 
2111d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("1", (char*)context.remote_call_services[0].name);
2121d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("1x", (char*)context.remote_call_services[1].name);
2131d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("2", (char*)context.remote_call_services[2].name);
2141d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("2x", (char*)context.remote_call_services[3].name);
2151d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("3", (char*)context.remote_call_services[4].name);
2161d3bd1e5SMatthias Ringwald }
2171d3bd1e5SMatthias Ringwald 
2181d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_TEST){
2191d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=?\r\n", HFP_GENERIC_STATUS_INDICATOR);
2201d3bd1e5SMatthias Ringwald     parse_ag(packet);
2211d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS, context.command);
2221d3bd1e5SMatthias Ringwald }
2231d3bd1e5SMatthias Ringwald 
2241d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_SET){
2251d3bd1e5SMatthias Ringwald     int param = 1;
2261d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=%u\r\n", HFP_GENERIC_STATUS_INDICATOR, param);
2271d3bd1e5SMatthias Ringwald     parse_ag(packet);
2281d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_LIST_GENERIC_STATUS_INDICATORS, context.command);
2291d3bd1e5SMatthias Ringwald }
2301d3bd1e5SMatthias Ringwald 
2311d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_READ){
2321d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s?\r\n", HFP_GENERIC_STATUS_INDICATOR);
2331d3bd1e5SMatthias Ringwald     parse_ag(packet);
2341d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE, context.command);
2351d3bd1e5SMatthias Ringwald }
2361d3bd1e5SMatthias Ringwald 
2371d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_GENERIC_STATUS_INDICATOR_STATE){
2381d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:0,1\r\n\r\nOK\r\n", HFP_GENERIC_STATUS_INDICATOR);
2391d3bd1e5SMatthias Ringwald     // context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
2401d3bd1e5SMatthias Ringwald     context.state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
2411d3bd1e5SMatthias Ringwald 
2421d3bd1e5SMatthias Ringwald     parse_hf(packet);
2431d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
2441d3bd1e5SMatthias Ringwald     CHECK_EQUAL(1, context.generic_status_indicators[0].state);
2451d3bd1e5SMatthias Ringwald }
2461d3bd1e5SMatthias Ringwald 
2471d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_AG_INDICATOR_STATUS_UPDATE){
2481d3bd1e5SMatthias Ringwald     context.ag_indicators_nr = hfp_ag_indicators_nr;
2491d3bd1e5SMatthias Ringwald     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
2501d3bd1e5SMatthias Ringwald 
2511d3bd1e5SMatthias Ringwald     uint8_t index = 4;
2521d3bd1e5SMatthias Ringwald     uint8_t status = 5;
2531d3bd1e5SMatthias Ringwald 
2541d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
2551d3bd1e5SMatthias Ringwald 
2561d3bd1e5SMatthias Ringwald     parse_hf(packet);
2571d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
2581d3bd1e5SMatthias Ringwald     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
2591d3bd1e5SMatthias Ringwald }
2601d3bd1e5SMatthias Ringwald 
2611d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_AG_QUERY_OPERATOR_SELECTION){
2621d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:1,0,\"sunrise\"\r\n\r\nOK\r\n", HFP_QUERY_OPERATOR_SELECTION);
2631d3bd1e5SMatthias Ringwald 
2641d3bd1e5SMatthias Ringwald     context.command = HFP_CMD_QUERY_OPERATOR_SELECTION_NAME;
2651d3bd1e5SMatthias Ringwald 
2661d3bd1e5SMatthias Ringwald     parse_hf(packet);
2671d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
2681d3bd1e5SMatthias Ringwald     CHECK_EQUAL(0, context.operator_name_changed);
2691d3bd1e5SMatthias Ringwald     STRCMP_EQUAL( "sunrise", context.network_operator.name);
2701d3bd1e5SMatthias Ringwald }
2711d3bd1e5SMatthias Ringwald 
2721d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_ERROR){
2731d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s\r\n", HFP_ERROR);
2741d3bd1e5SMatthias Ringwald 
2751d3bd1e5SMatthias Ringwald     parse_hf(packet);
2761d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ERROR, context.command);
2771d3bd1e5SMatthias Ringwald }
2781d3bd1e5SMatthias Ringwald 
2791d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_EXTENDED_AUDIO_GATEWAY_ERROR){
2801d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:%d\r\n", HFP_EXTENDED_AUDIO_GATEWAY_ERROR, HFP_CME_ERROR_NO_NETWORK_SERVICE);
2811d3bd1e5SMatthias Ringwald 
2821d3bd1e5SMatthias Ringwald     parse_hf(packet);
2831d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR, context.command);
2841d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CME_ERROR_NO_NETWORK_SERVICE, context.extended_audio_gateway_error_value);
2851d3bd1e5SMatthias Ringwald }
2861d3bd1e5SMatthias Ringwald 
2871d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_HF_AG_INDICATOR_CALLS_STATUS_UPDATE){
2881d3bd1e5SMatthias Ringwald     context.ag_indicators_nr = hfp_ag_indicators_nr;
2891d3bd1e5SMatthias Ringwald     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
2901d3bd1e5SMatthias Ringwald     uint8_t status = 1;
2911d3bd1e5SMatthias Ringwald 
2921d3bd1e5SMatthias Ringwald     // call status
2931d3bd1e5SMatthias Ringwald     uint8_t index = call_status_index;
2941d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
2951d3bd1e5SMatthias Ringwald     parse_hf(packet);
2961d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
2971d3bd1e5SMatthias Ringwald     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
2981d3bd1e5SMatthias Ringwald 
2991d3bd1e5SMatthias Ringwald     // callsetup status
3001d3bd1e5SMatthias Ringwald     index = callsetup_status_index;
3011d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
3021d3bd1e5SMatthias Ringwald     parse_hf(packet);
3031d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
3041d3bd1e5SMatthias Ringwald     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
3051d3bd1e5SMatthias Ringwald 
3061d3bd1e5SMatthias Ringwald     // callheld status
3071d3bd1e5SMatthias Ringwald     index = callheld_status_index;
3081d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
3091d3bd1e5SMatthias Ringwald     parse_hf(packet);
3101d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_OK, context.command);
3111d3bd1e5SMatthias Ringwald     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
3121d3bd1e5SMatthias Ringwald }
3131d3bd1e5SMatthias Ringwald 
3141d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_LIST_CURRENT_CALLS_1){
3151d3bd1e5SMatthias Ringwald     strcpy(packet, "\r\n+CLCC: 1,2,3,4,5,,129\r\n");
3161d3bd1e5SMatthias Ringwald     parse_hf(packet);
3171d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_LIST_CURRENT_CALLS, context.command);
3181d3bd1e5SMatthias Ringwald     CHECK_EQUAL(1, context.clcc_idx);
3191d3bd1e5SMatthias Ringwald     CHECK_EQUAL(2, context.clcc_dir);
3201d3bd1e5SMatthias Ringwald     CHECK_EQUAL(3, context.clcc_status);
3211d3bd1e5SMatthias Ringwald     CHECK_EQUAL(4, context.clcc_mode);
3221d3bd1e5SMatthias Ringwald     CHECK_EQUAL(5, context.clcc_mpty);
3231d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("", context.bnip_number);
3241d3bd1e5SMatthias Ringwald     CHECK_EQUAL(129, context.bnip_type);
3251d3bd1e5SMatthias Ringwald }
3261d3bd1e5SMatthias Ringwald 
3271d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_LIST_CURRENT_CALLS_2){
3281d3bd1e5SMatthias Ringwald     strcpy(packet, "\r\n+CLCC: 1,2,3,4,5,"",129\r\n");
3291d3bd1e5SMatthias Ringwald     parse_hf(packet);
3301d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_LIST_CURRENT_CALLS, context.command);
3311d3bd1e5SMatthias Ringwald     CHECK_EQUAL(1, context.clcc_idx);
3321d3bd1e5SMatthias Ringwald     CHECK_EQUAL(2, context.clcc_dir);
3331d3bd1e5SMatthias Ringwald     CHECK_EQUAL(3, context.clcc_status);
3341d3bd1e5SMatthias Ringwald     CHECK_EQUAL(4, context.clcc_mode);
3351d3bd1e5SMatthias Ringwald     CHECK_EQUAL(5, context.clcc_mpty);
3361d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("", context.bnip_number);
3371d3bd1e5SMatthias Ringwald     CHECK_EQUAL(129, context.bnip_type);
3381d3bd1e5SMatthias Ringwald }
3391d3bd1e5SMatthias Ringwald 
3401d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_SUPPORTED_FEATURES){
3411d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=159\r\n", HFP_SUPPORTED_FEATURES);
3421d3bd1e5SMatthias Ringwald     //context.keep_separator = 0;
3431d3bd1e5SMatthias Ringwald     parse_ag(packet);
3441d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_SUPPORTED_FEATURES, context.command);
3451d3bd1e5SMatthias Ringwald     CHECK_EQUAL(159, context.remote_supported_features);
3461d3bd1e5SMatthias Ringwald }
3471d3bd1e5SMatthias Ringwald 
3481d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_AVAILABLE_CODECS){
3491d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=0,1,2\r\n", HFP_AVAILABLE_CODECS);
3501d3bd1e5SMatthias Ringwald     parse_ag(packet);
3511d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_AVAILABLE_CODECS, context.command);
3521d3bd1e5SMatthias Ringwald     CHECK_EQUAL(3, context.remote_codecs_nr);
3531d3bd1e5SMatthias Ringwald     for (pos = 0; pos < 3; pos++){
3541d3bd1e5SMatthias Ringwald         CHECK_EQUAL(pos, context.remote_codecs[pos]);
3551d3bd1e5SMatthias Ringwald     }
3561d3bd1e5SMatthias Ringwald }
3571d3bd1e5SMatthias Ringwald 
3581d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_GENERIC_STATUS_INDICATOR){
3591d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=0,1,2,3,4\r\n", HFP_GENERIC_STATUS_INDICATOR);
3601d3bd1e5SMatthias Ringwald     parse_ag(packet);
3611d3bd1e5SMatthias Ringwald     CHECK_EQUAL(context.command, HFP_CMD_LIST_GENERIC_STATUS_INDICATORS);
3621d3bd1e5SMatthias Ringwald     CHECK_EQUAL(5, context.generic_status_indicators_nr);
3631d3bd1e5SMatthias Ringwald 
3641d3bd1e5SMatthias Ringwald     for (pos = 0; pos < context.generic_status_indicators_nr; pos++){
3651d3bd1e5SMatthias Ringwald         CHECK_EQUAL(pos, context.generic_status_indicators[pos].uuid);
3661d3bd1e5SMatthias Ringwald     }
3671d3bd1e5SMatthias Ringwald }
3681d3bd1e5SMatthias Ringwald 
3691d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_ENABLE_INDICATOR_STATUS_UPDATE){
3701d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=3,0,0,1\r\n", HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS);
3711d3bd1e5SMatthias Ringwald     parse_ag(packet);
3721d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE, context.command);
3731d3bd1e5SMatthias Ringwald     CHECK_EQUAL(1, context.enable_status_update_for_ag_indicators);
3741d3bd1e5SMatthias Ringwald }
3751d3bd1e5SMatthias Ringwald 
3761d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE){
3771d3bd1e5SMatthias Ringwald     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
3781d3bd1e5SMatthias Ringwald     context.ag_indicators_nr = hfp_ag_indicators_nr;
3791d3bd1e5SMatthias Ringwald     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
3801d3bd1e5SMatthias Ringwald 
3811d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
3821d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].index,   hfp_ag_get_ag_indicators(&context)[pos].index );
3831d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, hfp_ag_get_ag_indicators(&context)[pos].enabled);
3841d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].index,   context.ag_indicators[pos].index);
3851d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, context.ag_indicators[pos].enabled);
3861d3bd1e5SMatthias Ringwald     }
3871d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=0,0,0,0,0,0,0\r\n",
3881d3bd1e5SMatthias Ringwald         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
3891d3bd1e5SMatthias Ringwald     parse_ag(packet);
3901d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
3911d3bd1e5SMatthias Ringwald 
3921d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
3931d3bd1e5SMatthias Ringwald         if (hfp_ag_get_ag_indicators(&context)[pos].mandatory){
3941d3bd1e5SMatthias Ringwald             CHECK_EQUAL(1, hfp_ag_get_ag_indicators(&context)[pos].enabled);
3951d3bd1e5SMatthias Ringwald             CHECK_EQUAL(1, context.ag_indicators[pos].enabled);
3961d3bd1e5SMatthias Ringwald         } else {
3971d3bd1e5SMatthias Ringwald             CHECK_EQUAL(0, hfp_ag_get_ag_indicators(&context)[pos].enabled);
3981d3bd1e5SMatthias Ringwald             CHECK_EQUAL(0, context.ag_indicators[pos].enabled);
3991d3bd1e5SMatthias Ringwald         }
4001d3bd1e5SMatthias Ringwald     }
4011d3bd1e5SMatthias Ringwald }
4021d3bd1e5SMatthias Ringwald 
4031d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES3){
4041d3bd1e5SMatthias Ringwald     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
4051d3bd1e5SMatthias Ringwald     context.ag_indicators_nr = hfp_ag_indicators_nr;
4061d3bd1e5SMatthias Ringwald     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
4071d3bd1e5SMatthias Ringwald 
4081d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=,1,,,,,1\r\n",
4091d3bd1e5SMatthias Ringwald         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
4101d3bd1e5SMatthias Ringwald     parse_ag(packet);
4111d3bd1e5SMatthias Ringwald 
4121d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
4131d3bd1e5SMatthias Ringwald 
4141d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
4151d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].index, hfp_ag_get_ag_indicators(&context)[pos].index );
4161d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, hfp_ag_get_ag_indicators(&context)[pos].enabled);
4171d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index );
4181d3bd1e5SMatthias Ringwald         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, context.ag_indicators[pos].enabled);
4191d3bd1e5SMatthias Ringwald     }
4201d3bd1e5SMatthias Ringwald }
4211d3bd1e5SMatthias Ringwald 
4221d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES2){
4231d3bd1e5SMatthias Ringwald     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
4241d3bd1e5SMatthias Ringwald     context.ag_indicators_nr = hfp_ag_indicators_nr;
4251d3bd1e5SMatthias Ringwald     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
4261d3bd1e5SMatthias Ringwald 
4271d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
4281d3bd1e5SMatthias Ringwald         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
4291d3bd1e5SMatthias Ringwald     parse_ag(packet);
4301d3bd1e5SMatthias Ringwald 
4311d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
4321d3bd1e5SMatthias Ringwald 
4331d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
4341d3bd1e5SMatthias Ringwald         CHECK_EQUAL(1,hfp_ag_get_ag_indicators(&context)[pos].enabled);
4351d3bd1e5SMatthias Ringwald         CHECK_EQUAL(1, context.ag_indicators[pos].enabled);
4361d3bd1e5SMatthias Ringwald     }
4371d3bd1e5SMatthias Ringwald }
4381d3bd1e5SMatthias Ringwald 
4391d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES1){
4401d3bd1e5SMatthias Ringwald     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
4411d3bd1e5SMatthias Ringwald     context.ag_indicators_nr = hfp_ag_indicators_nr;
4421d3bd1e5SMatthias Ringwald     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
4431d3bd1e5SMatthias Ringwald 
4441d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
4451d3bd1e5SMatthias Ringwald         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
4461d3bd1e5SMatthias Ringwald     parse_ag(packet);
4471d3bd1e5SMatthias Ringwald 
4481d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
4491d3bd1e5SMatthias Ringwald 
4501d3bd1e5SMatthias Ringwald     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
4511d3bd1e5SMatthias Ringwald         CHECK_EQUAL(1, hfp_ag_get_ag_indicators(&context)[pos].enabled);
4521d3bd1e5SMatthias Ringwald         CHECK_EQUAL(1, context.ag_indicators[pos].enabled);
4531d3bd1e5SMatthias Ringwald     }
4541d3bd1e5SMatthias Ringwald }
4551d3bd1e5SMatthias Ringwald 
4561d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_HF_QUERY_OPERATOR_SELECTION){
4571d3bd1e5SMatthias Ringwald     context.network_operator.format = 0xff;
4581d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=3,0\r\n", HFP_QUERY_OPERATOR_SELECTION);
4591d3bd1e5SMatthias Ringwald 
4601d3bd1e5SMatthias Ringwald     parse_ag(packet);
4611d3bd1e5SMatthias Ringwald     CHECK_EQUAL(0, context.operator_name_changed);
4621d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT, context.command);
4631d3bd1e5SMatthias Ringwald 
4641d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s?\r\n", HFP_QUERY_OPERATOR_SELECTION);
4651d3bd1e5SMatthias Ringwald 
4661d3bd1e5SMatthias Ringwald     parse_ag(packet);
4671d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_QUERY_OPERATOR_SELECTION_NAME, context.command);
4681d3bd1e5SMatthias Ringwald     CHECK_EQUAL(0, context.operator_name_changed);
4691d3bd1e5SMatthias Ringwald }
4701d3bd1e5SMatthias Ringwald 
4711d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_EXTENDED_AUDIO_GATEWAY_ERROR){
4721d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=1\r\n", HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR);
4731d3bd1e5SMatthias Ringwald 
4741d3bd1e5SMatthias Ringwald     parse_ag(packet);
4751d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, context.command );
4761d3bd1e5SMatthias Ringwald     CHECK_EQUAL(1, context.enable_extended_audio_gateway_error_report);
4771d3bd1e5SMatthias Ringwald }
4781d3bd1e5SMatthias Ringwald 
4791d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_TRIGGER_CODEC_CONNECTION_SETUP){
4801d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s\r\n", HFP_TRIGGER_CODEC_CONNECTION_SETUP);
4811d3bd1e5SMatthias Ringwald     parse_ag(packet);
4821d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP, context.command);
4831d3bd1e5SMatthias Ringwald }
4841d3bd1e5SMatthias Ringwald 
4851d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_CONFIRM_COMMON_CODEC){
4861d3bd1e5SMatthias Ringwald     int codec = 2;
4871d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=%d\r\n", HFP_CONFIRM_COMMON_CODEC, codec);
4881d3bd1e5SMatthias Ringwald 
4891d3bd1e5SMatthias Ringwald     parse_ag(packet);
4901d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_HF_CONFIRMED_CODEC, context.command );
4911d3bd1e5SMatthias Ringwald     CHECK_EQUAL(codec, context.codec_confirmed);
4921d3bd1e5SMatthias Ringwald }
4931d3bd1e5SMatthias Ringwald 
4941d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_AG_DIAL){
4951d3bd1e5SMatthias Ringwald     strcpy(packet, "\r\nATD00123456789;\r\n");
4961d3bd1e5SMatthias Ringwald 
4971d3bd1e5SMatthias Ringwald     parse_ag(packet);
4981d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_CALL_PHONE_NUMBER, context.command);
4991d3bd1e5SMatthias Ringwald     STRCMP_EQUAL("00123456789", (const char *) &context.line_buffer[3]);
5001d3bd1e5SMatthias Ringwald }
5011d3bd1e5SMatthias Ringwald 
5021d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_ANSWER_CALL){
5031d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s\r\n", HFP_ANSWER_CALL);
5041d3bd1e5SMatthias Ringwald     parse_ag(packet);
5051d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_CALL_ANSWERED, context.command);
5061d3bd1e5SMatthias Ringwald }
5071d3bd1e5SMatthias Ringwald 
5081d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_QUERY){
5091d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s?\r\n", HFP_RESPONSE_AND_HOLD);
5101d3bd1e5SMatthias Ringwald     parse_ag(packet);
5111d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_QUERY, context.command);
5121d3bd1e5SMatthias Ringwald }
5131d3bd1e5SMatthias Ringwald 
5141d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_COMMAND){
5151d3bd1e5SMatthias Ringwald     int param = 1;
5161d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=%u\r\n", HFP_RESPONSE_AND_HOLD, param);
5171d3bd1e5SMatthias Ringwald     parse_ag(packet);
5181d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_COMMAND, context.command);
5191d3bd1e5SMatthias Ringwald     CHECK_EQUAL(param, context.ag_response_and_hold_action);
5201d3bd1e5SMatthias Ringwald }
5211d3bd1e5SMatthias Ringwald 
5221d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_STATUS){
5231d3bd1e5SMatthias Ringwald     int status = 1;
5241d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\n%s:%u\r\n", HFP_RESPONSE_AND_HOLD, status);
5251d3bd1e5SMatthias Ringwald     parse_hf(packet);
5261d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_STATUS, context.command);
5271d3bd1e5SMatthias Ringwald }
5281d3bd1e5SMatthias Ringwald 
5291d3bd1e5SMatthias Ringwald TEST(HFPParser, HFP_CMD_ENABLE_CLIP){
5301d3bd1e5SMatthias Ringwald     int param = 1;
5311d3bd1e5SMatthias Ringwald     sprintf(packet, "\r\nAT%s=%u\r\n", HFP_ENABLE_CLIP, param);
5321d3bd1e5SMatthias Ringwald     parse_ag(packet);
5331d3bd1e5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_ENABLE_CLIP, context.command);
5341d3bd1e5SMatthias Ringwald     CHECK_EQUAL(param, context.clip_enabled);
5351d3bd1e5SMatthias Ringwald }
5361d3bd1e5SMatthias Ringwald 
537016a59dfSMatthias Ringwald TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_a){
538016a59dfSMatthias Ringwald     // default/minimal
539016a59dfSMatthias Ringwald     parse_hf("\r\n+CLIP: \"+123456789\",145\r\n");
540016a59dfSMatthias Ringwald     CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command);
541016a59dfSMatthias Ringwald     STRCMP_EQUAL("+123456789", context.bnip_number);
542016a59dfSMatthias Ringwald     CHECK_EQUAL(145, context.bnip_type);
543016a59dfSMatthias Ringwald     CHECK_EQUAL(false, context.clip_have_alpha);
544016a59dfSMatthias Ringwald }
545016a59dfSMatthias Ringwald 
546016a59dfSMatthias Ringwald TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_b){
547016a59dfSMatthias Ringwald     // iOS
548016a59dfSMatthias Ringwald     parse_hf("\r\n+CLIP: \"+123456789\",145,,,\"BlueKitchen GmbH\"\r\n");
549016a59dfSMatthias Ringwald     CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command);
550016a59dfSMatthias Ringwald     STRCMP_EQUAL("+123456789", context.bnip_number);
551016a59dfSMatthias Ringwald     CHECK_EQUAL(145, context.bnip_type);
552016a59dfSMatthias Ringwald     CHECK_EQUAL(true, context.clip_have_alpha);
553016a59dfSMatthias Ringwald     STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer);
554016a59dfSMatthias Ringwald }
555016a59dfSMatthias Ringwald 
556016a59dfSMatthias Ringwald TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_c){
557016a59dfSMatthias Ringwald     // older iOS with additional ','
558016a59dfSMatthias Ringwald     parse_hf("\r\n+CLIP: \"+123456789\",145,,,,\"BlueKitchen GmbH\"\r\n");
559016a59dfSMatthias Ringwald     CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command);
560016a59dfSMatthias Ringwald     STRCMP_EQUAL("+123456789", context.bnip_number);
561016a59dfSMatthias Ringwald     CHECK_EQUAL(145, context.bnip_type);
562016a59dfSMatthias Ringwald     CHECK_EQUAL(true, context.clip_have_alpha);
563016a59dfSMatthias Ringwald     STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer);
564016a59dfSMatthias Ringwald }
565016a59dfSMatthias Ringwald 
566016a59dfSMatthias Ringwald TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_d){
567016a59dfSMatthias Ringwald     // BlackBerry, additional quotes
568016a59dfSMatthias Ringwald     parse_hf("\r\n+CLIP: \"+123456789\",145,\"\",,\"BlueKitchen GmbH\"\r\n");
569016a59dfSMatthias Ringwald     CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command);
570016a59dfSMatthias Ringwald     STRCMP_EQUAL("+123456789", context.bnip_number);
571016a59dfSMatthias Ringwald     CHECK_EQUAL(145, context.bnip_type);
572016a59dfSMatthias Ringwald     CHECK_EQUAL(true, context.clip_have_alpha);
573016a59dfSMatthias Ringwald     STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer);
574016a59dfSMatthias Ringwald }
575016a59dfSMatthias Ringwald 
576*da8e14c5SMatthias Ringwald TEST(HFPParser, HFP_CMD_AG_SENT_CALL_WAITING_INFORMATION){
577*da8e14c5SMatthias Ringwald     parse_hf("\r\n+CCWA: \"+123456789\",145,\"\",1,\"BlueKitchen GmbH\"\r\n");
578*da8e14c5SMatthias Ringwald     CHECK_EQUAL(HFP_CMD_AG_SENT_CALL_WAITING_NOTIFICATION_UPDATE, context.command);
579*da8e14c5SMatthias Ringwald     STRCMP_EQUAL("+123456789", context.bnip_number);
580*da8e14c5SMatthias Ringwald     CHECK_EQUAL(145, context.bnip_type);
581*da8e14c5SMatthias Ringwald     CHECK_EQUAL(true, context.clip_have_alpha);
582*da8e14c5SMatthias Ringwald     STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer);
583*da8e14c5SMatthias Ringwald }
584*da8e14c5SMatthias Ringwald 
5851d3bd1e5SMatthias Ringwald int main (int argc, const char * argv[]){
5861d3bd1e5SMatthias Ringwald     return CommandLineTestRunner::RunAllTests(argc, argv);
5871d3bd1e5SMatthias Ringwald }
588