1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 39 #include <stdint.h> 40 #include <stdio.h> 41 #include <stdlib.h> 42 #include <string.h> 43 44 #include "CppUTest/TestHarness.h" 45 #include "CppUTest/CommandLineTestRunner.h" 46 47 #include "classic/hfp.h" 48 #include "classic/hfp_ag.h" 49 50 void hfp_parse(hfp_connection_t * context, uint8_t byte, int isHandsFree); 51 52 static hfp_connection_t context; 53 static int hfp_ag_indicators_nr = 7; 54 static hfp_ag_indicator_t hfp_ag_indicators[] = { 55 // index, name, min range, max range, status, mandatory, enabled, status changed 56 {1, "service", 0, 1, 1, 0, 0, 0}, 57 {2, "call", 0, 1, 0, 1, 1, 0}, 58 {3, "callsetup", 0, 3, 0, 1, 1, 0}, 59 {4, "battchg", 0, 5, 3, 0, 0, 0}, 60 {5, "signal", 0, 5, 5, 0, 0, 0}, 61 {6, "roam", 0, 1, 0, 0, 0, 0}, 62 {7, "callheld", 0, 2, 0, 1, 1, 0} 63 }; 64 static uint8_t call_status_index = 2; 65 static uint8_t callsetup_status_index = 3; 66 static uint8_t callheld_status_index = 7; 67 68 69 static void parse_ag(const char * packet){ 70 for (uint16_t pos = 0; pos < strlen(packet); pos++){ 71 hfp_parse(&context, packet[pos], 0); 72 } 73 } 74 75 static void parse_hf(const char * packet){ 76 for (uint16_t pos = 0; pos < strlen(packet); pos++){ 77 hfp_parse(&context, packet[pos], 1); 78 } 79 } 80 81 TEST_GROUP(HFPParser){ 82 char packet[200]; 83 int pos; 84 int offset; 85 86 void setup(void){ 87 memset(&context, 0, sizeof(hfp_connection_t)); 88 context.parser_state = HFP_PARSER_CMD_HEADER; 89 context.parser_item_index = 0; 90 context.line_size = 0; 91 context.ag_indicators_nr = 0; 92 context.remote_codecs_nr = 0; 93 context.bnip_number[0] = 0; 94 context.bnip_type = 0; 95 memset(packet,0, sizeof(packet)); 96 } 97 }; 98 99 TEST(HFPParser, HFP_HF_OK){ 100 sprintf(packet, "\r\n%s\r\n", HFP_OK); 101 parse_hf(packet); 102 CHECK_EQUAL(HFP_CMD_OK, context.command); 103 } 104 105 TEST(HFPParser, HFP_HF_SUPPORTED_FEATURES){ 106 sprintf(packet, "\r\n%s:1007\r\n\r\nOK\r\n", HFP_SUPPORTED_FEATURES); 107 parse_hf(packet); 108 CHECK_EQUAL(HFP_CMD_OK, context.command); 109 CHECK_EQUAL(1007, context.remote_supported_features); 110 } 111 112 TEST(HFPParser, HFP_CMD_INDICATORS_QUERY){ 113 sprintf(packet, "\r\nAT%s?\r\n", HFP_INDICATOR); 114 parse_ag(packet); 115 CHECK_EQUAL(HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS, context.command); 116 } 117 118 TEST(HFPParser, HFP_CMD_INDICATORS_RETRIEVE){ 119 sprintf(packet, "\r\nAT%s=?\r\n", HFP_INDICATOR); 120 parse_ag(packet); 121 CHECK_EQUAL(HFP_CMD_RETRIEVE_AG_INDICATORS, context.command); 122 } 123 124 TEST(HFPParser, HFP_HF_INDICATORS){ 125 offset = 0; 126 offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR); 127 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 128 if (pos != 0) { 129 packet[offset++] = ','; 130 } 131 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); 132 } 133 offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n"); 134 context.state = HFP_W4_RETRIEVE_INDICATORS; 135 136 parse_hf(packet); 137 CHECK_EQUAL(HFP_CMD_OK, context.command); 138 CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr); 139 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 140 CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index); 141 STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name); 142 CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range); 143 CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range); 144 } 145 } 146 147 TEST(HFPParser, HFP_HF_INDICATORS_RANGE){ 148 offset = 0; 149 offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR); 150 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 151 if (pos != 0) { 152 packet[offset++] = ','; 153 } 154 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); 155 } 156 offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n"); 157 context.state = HFP_W4_RETRIEVE_INDICATORS; 158 159 parse_hf(packet); 160 CHECK_EQUAL(HFP_CMD_OK, context.command); 161 CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr); 162 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 163 CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index); 164 STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name); 165 CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range); 166 CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range); 167 } 168 } 169 170 TEST(HFPParser, HFP_HF_INDICATOR_STATUS){ 171 // send status 172 offset = 0; 173 offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR); 174 for (pos = 0; pos < hfp_ag_indicators_nr - 1; pos++){ 175 offset += snprintf(packet+offset, sizeof(packet)-offset, "%d,", hfp_ag_indicators[pos].status); 176 } 177 offset += snprintf(packet+offset, sizeof(packet)-offset, "%d\r\n\r\nOK\r\n", hfp_ag_indicators[pos].status); 178 179 //context.command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS; 180 context.state = HFP_W4_RETRIEVE_INDICATORS_STATUS; 181 182 parse_hf(packet); 183 CHECK_EQUAL(HFP_CMD_OK, context.command); 184 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 185 CHECK_EQUAL(hfp_ag_indicators[pos].status, context.ag_indicators[pos].status); 186 } 187 } 188 189 TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES_TEST){ 190 sprintf(packet, "\r\nAT%s=?\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES); 191 parse_ag(packet); 192 CHECK_EQUAL(HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, context.command); 193 } 194 195 TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES_SET){ 196 int action = 1; 197 int call_index = 2; 198 sprintf(packet, "\r\nAT%s=%u%u\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, action, call_index); 199 parse_ag(packet); 200 CHECK_EQUAL(HFP_CMD_CALL_HOLD, context.command); 201 CHECK_EQUAL(action, context.ag_call_hold_action); 202 CHECK_EQUAL(call_index, context.call_index); 203 } 204 205 TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES){ 206 sprintf(packet, "\r\n%s:(1,1x,2,2x,3)\r\n\r\nOK\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES); 207 parse_hf(packet); 208 CHECK_EQUAL(HFP_CMD_OK, context.command); 209 CHECK_EQUAL(5, context.remote_call_services_index); 210 211 STRCMP_EQUAL("1", (char*)context.remote_call_services[0].name); 212 STRCMP_EQUAL("1x", (char*)context.remote_call_services[1].name); 213 STRCMP_EQUAL("2", (char*)context.remote_call_services[2].name); 214 STRCMP_EQUAL("2x", (char*)context.remote_call_services[3].name); 215 STRCMP_EQUAL("3", (char*)context.remote_call_services[4].name); 216 } 217 218 TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_TEST){ 219 sprintf(packet, "\r\nAT%s=?\r\n", HFP_GENERIC_STATUS_INDICATOR); 220 parse_ag(packet); 221 CHECK_EQUAL(HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS, context.command); 222 } 223 224 TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_SET){ 225 int param = 1; 226 sprintf(packet, "\r\nAT%s=%u\r\n", HFP_GENERIC_STATUS_INDICATOR, param); 227 parse_ag(packet); 228 CHECK_EQUAL(HFP_CMD_LIST_GENERIC_STATUS_INDICATORS, context.command); 229 } 230 231 TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_READ){ 232 sprintf(packet, "\r\nAT%s?\r\n", HFP_GENERIC_STATUS_INDICATOR); 233 parse_ag(packet); 234 CHECK_EQUAL(HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE, context.command); 235 } 236 237 TEST(HFPParser, HFP_HF_GENERIC_STATUS_INDICATOR_STATE){ 238 sprintf(packet, "\r\n%s:0,1\r\n\r\nOK\r\n", HFP_GENERIC_STATUS_INDICATOR); 239 // context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE; 240 context.state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS; 241 242 parse_hf(packet); 243 CHECK_EQUAL(HFP_CMD_OK, context.command); 244 CHECK_EQUAL(1, context.generic_status_indicators[0].state); 245 } 246 247 TEST(HFPParser, HFP_HF_AG_INDICATOR_STATUS_UPDATE){ 248 context.ag_indicators_nr = hfp_ag_indicators_nr; 249 memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t)); 250 251 uint8_t index = 4; 252 uint8_t status = 5; 253 254 sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status); 255 256 parse_hf(packet); 257 CHECK_EQUAL(HFP_CMD_OK, context.command); 258 CHECK_EQUAL(status, context.ag_indicators[index - 1].status); 259 } 260 261 TEST(HFPParser, HFP_HF_AG_QUERY_OPERATOR_SELECTION){ 262 sprintf(packet, "\r\n%s:1,0,\"sunrise\"\r\n\r\nOK\r\n", HFP_QUERY_OPERATOR_SELECTION); 263 264 context.command = HFP_CMD_QUERY_OPERATOR_SELECTION_NAME; 265 266 parse_hf(packet); 267 CHECK_EQUAL(HFP_CMD_OK, context.command); 268 CHECK_EQUAL(0, context.operator_name_changed); 269 STRCMP_EQUAL( "sunrise", context.network_operator.name); 270 } 271 272 TEST(HFPParser, HFP_HF_ERROR){ 273 sprintf(packet, "\r\n%s\r\n", HFP_ERROR); 274 275 parse_hf(packet); 276 CHECK_EQUAL(HFP_CMD_ERROR, context.command); 277 } 278 279 TEST(HFPParser, HFP_HF_EXTENDED_AUDIO_GATEWAY_ERROR){ 280 sprintf(packet, "\r\n%s:%d\r\n", HFP_EXTENDED_AUDIO_GATEWAY_ERROR, HFP_CME_ERROR_NO_NETWORK_SERVICE); 281 282 parse_hf(packet); 283 CHECK_EQUAL(HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR, context.command); 284 CHECK_EQUAL(HFP_CME_ERROR_NO_NETWORK_SERVICE, context.extended_audio_gateway_error_value); 285 } 286 287 TEST(HFPParser, HFP_HF_AG_INDICATOR_CALLS_STATUS_UPDATE){ 288 context.ag_indicators_nr = hfp_ag_indicators_nr; 289 memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t)); 290 uint8_t status = 1; 291 292 // call status 293 uint8_t index = call_status_index; 294 sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status); 295 parse_hf(packet); 296 CHECK_EQUAL(HFP_CMD_OK, context.command); 297 CHECK_EQUAL(status, context.ag_indicators[index - 1].status); 298 299 // callsetup status 300 index = callsetup_status_index; 301 sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status); 302 parse_hf(packet); 303 CHECK_EQUAL(HFP_CMD_OK, context.command); 304 CHECK_EQUAL(status, context.ag_indicators[index - 1].status); 305 306 // callheld status 307 index = callheld_status_index; 308 sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status); 309 parse_hf(packet); 310 CHECK_EQUAL(HFP_CMD_OK, context.command); 311 CHECK_EQUAL(status, context.ag_indicators[index - 1].status); 312 } 313 314 TEST(HFPParser, HFP_LIST_CURRENT_CALLS_1){ 315 strcpy(packet, "\r\n+CLCC: 1,2,3,4,5,,129\r\n"); 316 parse_hf(packet); 317 CHECK_EQUAL(HFP_CMD_LIST_CURRENT_CALLS, context.command); 318 CHECK_EQUAL(1, context.clcc_idx); 319 CHECK_EQUAL(2, context.clcc_dir); 320 CHECK_EQUAL(3, context.clcc_status); 321 CHECK_EQUAL(4, context.clcc_mode); 322 CHECK_EQUAL(5, context.clcc_mpty); 323 STRCMP_EQUAL("", context.bnip_number); 324 CHECK_EQUAL(129, context.bnip_type); 325 } 326 327 TEST(HFPParser, HFP_LIST_CURRENT_CALLS_2){ 328 strcpy(packet, "\r\n+CLCC: 1,2,3,4,5,"",129\r\n"); 329 parse_hf(packet); 330 CHECK_EQUAL(HFP_CMD_LIST_CURRENT_CALLS, context.command); 331 CHECK_EQUAL(1, context.clcc_idx); 332 CHECK_EQUAL(2, context.clcc_dir); 333 CHECK_EQUAL(3, context.clcc_status); 334 CHECK_EQUAL(4, context.clcc_mode); 335 CHECK_EQUAL(5, context.clcc_mpty); 336 STRCMP_EQUAL("", context.bnip_number); 337 CHECK_EQUAL(129, context.bnip_type); 338 } 339 340 TEST(HFPParser, HFP_AG_SUPPORTED_FEATURES){ 341 sprintf(packet, "\r\nAT%s=159\r\n", HFP_SUPPORTED_FEATURES); 342 //context.keep_separator = 0; 343 parse_ag(packet); 344 CHECK_EQUAL(HFP_CMD_SUPPORTED_FEATURES, context.command); 345 CHECK_EQUAL(159, context.remote_supported_features); 346 } 347 348 TEST(HFPParser, HFP_AG_AVAILABLE_CODECS){ 349 sprintf(packet, "\r\nAT%s=0,1,2\r\n", HFP_AVAILABLE_CODECS); 350 parse_ag(packet); 351 CHECK_EQUAL(HFP_CMD_AVAILABLE_CODECS, context.command); 352 CHECK_EQUAL(3, context.remote_codecs_nr); 353 for (pos = 0; pos < 3; pos++){ 354 CHECK_EQUAL(pos, context.remote_codecs[pos]); 355 } 356 } 357 358 TEST(HFPParser, HFP_AG_GENERIC_STATUS_INDICATOR){ 359 sprintf(packet, "\r\nAT%s=0,1,2,3,4\r\n", HFP_GENERIC_STATUS_INDICATOR); 360 parse_ag(packet); 361 CHECK_EQUAL(context.command, HFP_CMD_LIST_GENERIC_STATUS_INDICATORS); 362 CHECK_EQUAL(5, context.generic_status_indicators_nr); 363 364 for (pos = 0; pos < context.generic_status_indicators_nr; pos++){ 365 CHECK_EQUAL(pos, context.generic_status_indicators[pos].uuid); 366 } 367 } 368 369 TEST(HFPParser, HFP_AG_ENABLE_INDICATOR_STATUS_UPDATE){ 370 sprintf(packet, "\r\nAT%s=3,0,0,1\r\n", HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS); 371 parse_ag(packet); 372 CHECK_EQUAL(HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE, context.command); 373 CHECK_EQUAL(1, context.enable_status_update_for_ag_indicators); 374 } 375 376 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE){ 377 hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators); 378 context.ag_indicators_nr = hfp_ag_indicators_nr; 379 memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t)); 380 381 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 382 CHECK_EQUAL(hfp_ag_indicators[pos].index, hfp_ag_get_ag_indicators(&context)[pos].index ); 383 CHECK_EQUAL(hfp_ag_indicators[pos].enabled, hfp_ag_get_ag_indicators(&context)[pos].enabled); 384 CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index); 385 CHECK_EQUAL(hfp_ag_indicators[pos].enabled, context.ag_indicators[pos].enabled); 386 } 387 sprintf(packet, "\r\nAT%s=0,0,0,0,0,0,0\r\n", 388 HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS); 389 parse_ag(packet); 390 CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command); 391 392 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 393 if (hfp_ag_get_ag_indicators(&context)[pos].mandatory){ 394 CHECK_EQUAL(1, hfp_ag_get_ag_indicators(&context)[pos].enabled); 395 CHECK_EQUAL(1, context.ag_indicators[pos].enabled); 396 } else { 397 CHECK_EQUAL(0, hfp_ag_get_ag_indicators(&context)[pos].enabled); 398 CHECK_EQUAL(0, context.ag_indicators[pos].enabled); 399 } 400 } 401 } 402 403 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES3){ 404 hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators); 405 context.ag_indicators_nr = hfp_ag_indicators_nr; 406 memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t)); 407 408 sprintf(packet, "\r\nAT%s=,1,,,,,1\r\n", 409 HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS); 410 parse_ag(packet); 411 412 CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command); 413 414 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 415 CHECK_EQUAL(hfp_ag_indicators[pos].index, hfp_ag_get_ag_indicators(&context)[pos].index ); 416 CHECK_EQUAL(hfp_ag_indicators[pos].enabled, hfp_ag_get_ag_indicators(&context)[pos].enabled); 417 CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index ); 418 CHECK_EQUAL(hfp_ag_indicators[pos].enabled, context.ag_indicators[pos].enabled); 419 } 420 } 421 422 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES2){ 423 hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators); 424 context.ag_indicators_nr = hfp_ag_indicators_nr; 425 memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t)); 426 427 sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n", 428 HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS); 429 parse_ag(packet); 430 431 CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command); 432 433 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 434 CHECK_EQUAL(1,hfp_ag_get_ag_indicators(&context)[pos].enabled); 435 CHECK_EQUAL(1, context.ag_indicators[pos].enabled); 436 } 437 } 438 439 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES1){ 440 hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators); 441 context.ag_indicators_nr = hfp_ag_indicators_nr; 442 memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t)); 443 444 sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n", 445 HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS); 446 parse_ag(packet); 447 448 CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command); 449 450 for (pos = 0; pos < hfp_ag_indicators_nr; pos++){ 451 CHECK_EQUAL(1, hfp_ag_get_ag_indicators(&context)[pos].enabled); 452 CHECK_EQUAL(1, context.ag_indicators[pos].enabled); 453 } 454 } 455 456 TEST(HFPParser, HFP_AG_HF_QUERY_OPERATOR_SELECTION){ 457 context.network_operator.format = 0xff; 458 sprintf(packet, "\r\nAT%s=3,0\r\n", HFP_QUERY_OPERATOR_SELECTION); 459 460 parse_ag(packet); 461 CHECK_EQUAL(0, context.operator_name_changed); 462 CHECK_EQUAL(HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT, context.command); 463 464 sprintf(packet, "\r\nAT%s?\r\n", HFP_QUERY_OPERATOR_SELECTION); 465 466 parse_ag(packet); 467 CHECK_EQUAL(HFP_CMD_QUERY_OPERATOR_SELECTION_NAME, context.command); 468 CHECK_EQUAL(0, context.operator_name_changed); 469 } 470 471 TEST(HFPParser, HFP_AG_EXTENDED_AUDIO_GATEWAY_ERROR){ 472 sprintf(packet, "\r\nAT%s=1\r\n", HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR); 473 474 parse_ag(packet); 475 CHECK_EQUAL(HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, context.command ); 476 CHECK_EQUAL(1, context.enable_extended_audio_gateway_error_report); 477 } 478 479 TEST(HFPParser, HFP_AG_TRIGGER_CODEC_CONNECTION_SETUP){ 480 sprintf(packet, "\r\nAT%s\r\n", HFP_TRIGGER_CODEC_CONNECTION_SETUP); 481 parse_ag(packet); 482 CHECK_EQUAL(HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP, context.command); 483 } 484 485 TEST(HFPParser, HFP_AG_CONFIRM_COMMON_CODEC){ 486 int codec = 2; 487 sprintf(packet, "\r\nAT%s=%d\r\n", HFP_CONFIRM_COMMON_CODEC, codec); 488 489 parse_ag(packet); 490 CHECK_EQUAL(HFP_CMD_HF_CONFIRMED_CODEC, context.command ); 491 CHECK_EQUAL(codec, context.codec_confirmed); 492 } 493 494 TEST(HFPParser, HFP_AG_DIAL){ 495 strcpy(packet, "\r\nATD00123456789;\r\n"); 496 497 parse_ag(packet); 498 CHECK_EQUAL(HFP_CMD_CALL_PHONE_NUMBER, context.command); 499 STRCMP_EQUAL("00123456789", (const char *) &context.line_buffer[3]); 500 } 501 502 TEST(HFPParser, HFP_ANSWER_CALL){ 503 sprintf(packet, "\r\n%s\r\n", HFP_ANSWER_CALL); 504 parse_ag(packet); 505 CHECK_EQUAL(HFP_CMD_CALL_ANSWERED, context.command); 506 } 507 508 TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_QUERY){ 509 sprintf(packet, "\r\nAT%s?\r\n", HFP_RESPONSE_AND_HOLD); 510 parse_ag(packet); 511 CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_QUERY, context.command); 512 } 513 514 TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_COMMAND){ 515 int param = 1; 516 sprintf(packet, "\r\nAT%s=%u\r\n", HFP_RESPONSE_AND_HOLD, param); 517 parse_ag(packet); 518 CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_COMMAND, context.command); 519 CHECK_EQUAL(param, context.ag_response_and_hold_action); 520 } 521 522 TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_STATUS){ 523 int status = 1; 524 sprintf(packet, "\r\n%s:%u\r\n", HFP_RESPONSE_AND_HOLD, status); 525 parse_hf(packet); 526 CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_STATUS, context.command); 527 } 528 529 TEST(HFPParser, HFP_CMD_ENABLE_CLIP){ 530 int param = 1; 531 sprintf(packet, "\r\nAT%s=%u\r\n", HFP_ENABLE_CLIP, param); 532 parse_ag(packet); 533 CHECK_EQUAL(HFP_CMD_ENABLE_CLIP, context.command); 534 CHECK_EQUAL(param, context.clip_enabled); 535 } 536 537 TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_a){ 538 // default/minimal 539 parse_hf("\r\n+CLIP: \"+123456789\",145\r\n"); 540 CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command); 541 STRCMP_EQUAL("+123456789", context.bnip_number); 542 CHECK_EQUAL(145, context.bnip_type); 543 CHECK_EQUAL(false, context.clip_have_alpha); 544 } 545 546 TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_b){ 547 // iOS 548 parse_hf("\r\n+CLIP: \"+123456789\",145,,,\"BlueKitchen GmbH\"\r\n"); 549 CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command); 550 STRCMP_EQUAL("+123456789", context.bnip_number); 551 CHECK_EQUAL(145, context.bnip_type); 552 CHECK_EQUAL(true, context.clip_have_alpha); 553 STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer); 554 } 555 556 TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_c){ 557 // older iOS with additional ',' 558 parse_hf("\r\n+CLIP: \"+123456789\",145,,,,\"BlueKitchen GmbH\"\r\n"); 559 CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command); 560 STRCMP_EQUAL("+123456789", context.bnip_number); 561 CHECK_EQUAL(145, context.bnip_type); 562 CHECK_EQUAL(true, context.clip_have_alpha); 563 STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer); 564 } 565 566 TEST(HFPParser, HFP_CMD_AG_SENT_CLIP_INFORMATION_d){ 567 // BlackBerry, additional quotes 568 parse_hf("\r\n+CLIP: \"+123456789\",145,\"\",,\"BlueKitchen GmbH\"\r\n"); 569 CHECK_EQUAL(HFP_CMD_AG_SENT_CLIP_INFORMATION, context.command); 570 STRCMP_EQUAL("+123456789", context.bnip_number); 571 CHECK_EQUAL(145, context.bnip_type); 572 CHECK_EQUAL(true, context.clip_have_alpha); 573 STRCMP_EQUAL("BlueKitchen GmbH", (const char *)context.line_buffer); 574 } 575 576 int main (int argc, const char * argv[]){ 577 return CommandLineTestRunner::RunAllTests(argc, argv); 578 } 579