xref: /btstack/test/hfp/hfp_at_parser_test.cpp (revision 1fd701e0cd0dd9097997d60e3a8cffebb9b214a3)
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         context.parser_state = HFP_PARSER_CMD_HEADER;
88         context.parser_item_index = 0;
89         context.line_size = 0;
90         context.ag_indicators_nr = 0;
91         context.remote_codecs_nr = 0;
92         memset(packet,0, sizeof(packet));
93     }
94 };
95 
96 TEST(HFPParser, HFP_HF_OK){
97     sprintf(packet, "\r\n%s\r\n", HFP_OK);
98     parse_hf(packet);
99     CHECK_EQUAL(HFP_CMD_OK, context.command);
100 }
101 
102 TEST(HFPParser, HFP_HF_SUPPORTED_FEATURES){
103     sprintf(packet, "\r\n%s:1007\r\n\r\nOK\r\n", HFP_SUPPORTED_FEATURES);
104     parse_hf(packet);
105     CHECK_EQUAL(HFP_CMD_OK, context.command);
106     CHECK_EQUAL(1007, context.remote_supported_features);
107 }
108 
109 TEST(HFPParser, HFP_CMD_INDICATORS_QUERY){
110     sprintf(packet, "\r\nAT%s?\r\n", HFP_INDICATOR);
111     parse_ag(packet);
112     CHECK_EQUAL(HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS, context.command);
113 }
114 
115 TEST(HFPParser, HFP_CMD_INDICATORS_RETRIEVE){
116     sprintf(packet, "\r\nAT%s=?\r\n", HFP_INDICATOR);
117     parse_ag(packet);
118     CHECK_EQUAL(HFP_CMD_RETRIEVE_AG_INDICATORS, context.command);
119 }
120 
121 TEST(HFPParser, HFP_HF_INDICATORS){
122     offset = 0;
123     offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR);
124     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
125     	if (pos != 0) {
126 			packet[offset++] = ',';
127 		}
128     	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);
129     }
130     offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n");
131     context.state = HFP_W4_RETRIEVE_INDICATORS;
132 
133     parse_hf(packet);
134     CHECK_EQUAL(HFP_CMD_OK, context.command);
135     CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr);
136     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
137         CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index);
138         STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name);
139         CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range);
140         CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range);
141     }
142 }
143 
144 TEST(HFPParser, HFP_HF_INDICATORS_RANGE){
145 	offset = 0;
146 	offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR);
147 	for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
148 		if (pos != 0) {
149 			packet[offset++] = ',';
150 		}
151 		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);
152 	}
153 	offset += snprintf(packet+offset, sizeof(packet)-offset, "\r\n\r\nOK\r\n");
154 	context.state = HFP_W4_RETRIEVE_INDICATORS;
155 
156 	parse_hf(packet);
157 	CHECK_EQUAL(HFP_CMD_OK, context.command);
158 	CHECK_EQUAL(hfp_ag_indicators_nr, context.ag_indicators_nr);
159 	for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
160 		CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index);
161 		STRCMP_EQUAL(hfp_ag_indicators[pos].name, context.ag_indicators[pos].name);
162 		CHECK_EQUAL(hfp_ag_indicators[pos].min_range, context.ag_indicators[pos].min_range);
163 		CHECK_EQUAL(hfp_ag_indicators[pos].max_range, context.ag_indicators[pos].max_range);
164 	}
165 }
166 
167 TEST(HFPParser, HFP_HF_INDICATOR_STATUS){
168     // send status
169     offset = 0;
170     offset += snprintf(packet, sizeof(packet), "%s:", HFP_INDICATOR);
171     for (pos = 0; pos < hfp_ag_indicators_nr - 1; pos++){
172         offset += snprintf(packet+offset, sizeof(packet)-offset, "%d,", hfp_ag_indicators[pos].status);
173     }
174     offset += snprintf(packet+offset, sizeof(packet)-offset, "%d\r\n\r\nOK\r\n", hfp_ag_indicators[pos].status);
175 
176     //context.command = HFP_CMD_RETRIEVE_AG_INDICATORS_STATUS;
177     context.state = HFP_W4_RETRIEVE_INDICATORS_STATUS;
178 
179     parse_hf(packet);
180     CHECK_EQUAL(HFP_CMD_OK, context.command);
181     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
182         CHECK_EQUAL(hfp_ag_indicators[pos].status, context.ag_indicators[pos].status);
183     }
184 }
185 
186 TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES_TEST){
187     sprintf(packet, "\r\nAT%s=?\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES);
188     parse_ag(packet);
189     CHECK_EQUAL(HFP_CMD_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, context.command);
190 }
191 
192 TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES_SET){
193     int action = 1;
194     int call_index = 2;
195     sprintf(packet, "\r\nAT%s=%u%u\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES, action, call_index);
196     parse_ag(packet);
197     CHECK_EQUAL(HFP_CMD_CALL_HOLD, context.command);
198     CHECK_EQUAL(action, context.ag_call_hold_action);
199     CHECK_EQUAL(call_index, context.call_index);
200 }
201 
202 TEST(HFPParser, HFP_HF_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES){
203     sprintf(packet, "\r\n%s:(1,1x,2,2x,3)\r\n\r\nOK\r\n", HFP_SUPPORT_CALL_HOLD_AND_MULTIPARTY_SERVICES);
204     parse_hf(packet);
205     CHECK_EQUAL(HFP_CMD_OK, context.command);
206     CHECK_EQUAL(5, context.remote_call_services_index);
207 
208     STRCMP_EQUAL("1", (char*)context.remote_call_services[0].name);
209     STRCMP_EQUAL("1x", (char*)context.remote_call_services[1].name);
210     STRCMP_EQUAL("2", (char*)context.remote_call_services[2].name);
211     STRCMP_EQUAL("2x", (char*)context.remote_call_services[3].name);
212     STRCMP_EQUAL("3", (char*)context.remote_call_services[4].name);
213 }
214 
215 TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_TEST){
216     sprintf(packet, "\r\nAT%s=?\r\n", HFP_GENERIC_STATUS_INDICATOR);
217     parse_ag(packet);
218     CHECK_EQUAL(HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS, context.command);
219 }
220 
221 TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_SET){
222     int param = 1;
223     sprintf(packet, "\r\nAT%s=%u\r\n", HFP_GENERIC_STATUS_INDICATOR, param);
224     parse_ag(packet);
225     CHECK_EQUAL(HFP_CMD_LIST_GENERIC_STATUS_INDICATORS, context.command);
226 }
227 
228 TEST(HFPParser, HFP_GENERIC_STATUS_INDICATOR_READ){
229     sprintf(packet, "\r\nAT%s?\r\n", HFP_GENERIC_STATUS_INDICATOR);
230     parse_ag(packet);
231     CHECK_EQUAL(HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE, context.command);
232 }
233 
234 TEST(HFPParser, HFP_HF_GENERIC_STATUS_INDICATOR_STATE){
235     sprintf(packet, "\r\n%s:0,1\r\n\r\nOK\r\n", HFP_GENERIC_STATUS_INDICATOR);
236     // context.command = HFP_CMD_RETRIEVE_GENERIC_STATUS_INDICATORS_STATE;
237     context.state = HFP_W4_RETRIEVE_INITITAL_STATE_GENERIC_STATUS_INDICATORS;
238 
239     parse_hf(packet);
240     CHECK_EQUAL(HFP_CMD_OK, context.command);
241     CHECK_EQUAL(1, context.generic_status_indicators[0].state);
242 }
243 
244 TEST(HFPParser, HFP_HF_AG_INDICATOR_STATUS_UPDATE){
245     context.ag_indicators_nr = hfp_ag_indicators_nr;
246     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
247 
248     uint8_t index = 4;
249     uint8_t status = 5;
250 
251     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
252 
253     parse_hf(packet);
254     CHECK_EQUAL(HFP_CMD_OK, context.command);
255     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
256 }
257 
258 TEST(HFPParser, HFP_HF_AG_QUERY_OPERATOR_SELECTION){
259     sprintf(packet, "\r\n%s:1,0,\"sunrise\"\r\n\r\nOK\r\n", HFP_QUERY_OPERATOR_SELECTION);
260 
261     context.command = HFP_CMD_QUERY_OPERATOR_SELECTION_NAME;
262 
263     parse_hf(packet);
264     CHECK_EQUAL(HFP_CMD_OK, context.command);
265     CHECK_EQUAL(0, context.operator_name_changed);
266     STRCMP_EQUAL( "sunrise", context.network_operator.name);
267 }
268 
269 TEST(HFPParser, HFP_HF_ERROR){
270     sprintf(packet, "\r\n%s\r\n", HFP_ERROR);
271 
272     parse_hf(packet);
273     CHECK_EQUAL(HFP_CMD_ERROR, context.command);
274 }
275 
276 TEST(HFPParser, HFP_HF_EXTENDED_AUDIO_GATEWAY_ERROR){
277     sprintf(packet, "\r\n%s:%d\r\n", HFP_EXTENDED_AUDIO_GATEWAY_ERROR, HFP_CME_ERROR_NO_NETWORK_SERVICE);
278 
279     parse_hf(packet);
280     CHECK_EQUAL(HFP_CMD_EXTENDED_AUDIO_GATEWAY_ERROR, context.command);
281     CHECK_EQUAL(HFP_CME_ERROR_NO_NETWORK_SERVICE, context.extended_audio_gateway_error_value);
282 }
283 
284 TEST(HFPParser, HFP_HF_AG_INDICATOR_CALLS_STATUS_UPDATE){
285     context.ag_indicators_nr = hfp_ag_indicators_nr;
286     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
287     uint8_t status = 1;
288 
289     // call status
290     uint8_t index = call_status_index;
291     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
292     parse_hf(packet);
293     CHECK_EQUAL(HFP_CMD_OK, context.command);
294     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
295 
296     // callsetup status
297     index = callsetup_status_index;
298     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
299     parse_hf(packet);
300     CHECK_EQUAL(HFP_CMD_OK, context.command);
301     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
302 
303     // callheld status
304     index = callheld_status_index;
305     sprintf(packet, "\r\n%s:%d,%d\r\n\r\nOK\r\n", HFP_TRANSFER_AG_INDICATOR_STATUS, index, status);
306     parse_hf(packet);
307     CHECK_EQUAL(HFP_CMD_OK, context.command);
308     CHECK_EQUAL(status, context.ag_indicators[index - 1].status);
309 }
310 
311 TEST(HFPParser, HFP_LIST_CURRENT_CALLS_1){
312     strcpy(packet, "\r\n+CLCC: 1,2,3,4,5,,129\r\n");
313     parse_hf(packet);
314     CHECK_EQUAL(HFP_CMD_LIST_CURRENT_CALLS, context.command);
315     CHECK_EQUAL(1, context.clcc_idx);
316     CHECK_EQUAL(2, context.clcc_dir);
317     CHECK_EQUAL(3, context.clcc_status);
318     CHECK_EQUAL(4, context.clcc_mode);
319     CHECK_EQUAL(5, context.clcc_mpty);
320     STRCMP_EQUAL("", context.bnip_number);
321     CHECK_EQUAL(129, context.bnip_type);
322 }
323 
324 TEST(HFPParser, HFP_LIST_CURRENT_CALLS_2){
325     strcpy(packet, "\r\n+CLCC: 1,2,3,4,5,"",129\r\n");
326     parse_hf(packet);
327     CHECK_EQUAL(HFP_CMD_LIST_CURRENT_CALLS, context.command);
328     CHECK_EQUAL(1, context.clcc_idx);
329     CHECK_EQUAL(2, context.clcc_dir);
330     CHECK_EQUAL(3, context.clcc_status);
331     CHECK_EQUAL(4, context.clcc_mode);
332     CHECK_EQUAL(5, context.clcc_mpty);
333     STRCMP_EQUAL("", context.bnip_number);
334     CHECK_EQUAL(129, context.bnip_type);
335 }
336 
337 TEST(HFPParser, HFP_AG_SUPPORTED_FEATURES){
338     sprintf(packet, "\r\nAT%s=159\r\n", HFP_SUPPORTED_FEATURES);
339     //context.keep_separator = 0;
340     parse_ag(packet);
341     CHECK_EQUAL(HFP_CMD_SUPPORTED_FEATURES, context.command);
342     CHECK_EQUAL(159, context.remote_supported_features);
343 }
344 
345 TEST(HFPParser, HFP_AG_AVAILABLE_CODECS){
346     sprintf(packet, "\r\nAT%s=0,1,2\r\n", HFP_AVAILABLE_CODECS);
347     parse_ag(packet);
348     CHECK_EQUAL(HFP_CMD_AVAILABLE_CODECS, context.command);
349     CHECK_EQUAL(3, context.remote_codecs_nr);
350     for (pos = 0; pos < 3; pos++){
351         CHECK_EQUAL(pos, context.remote_codecs[pos]);
352     }
353 }
354 
355 TEST(HFPParser, HFP_AG_GENERIC_STATUS_INDICATOR){
356     sprintf(packet, "\r\nAT%s=0,1,2,3,4\r\n", HFP_GENERIC_STATUS_INDICATOR);
357     parse_ag(packet);
358     CHECK_EQUAL(context.command, HFP_CMD_LIST_GENERIC_STATUS_INDICATORS);
359     CHECK_EQUAL(5, context.generic_status_indicators_nr);
360 
361     for (pos = 0; pos < context.generic_status_indicators_nr; pos++){
362         CHECK_EQUAL(pos, context.generic_status_indicators[pos].uuid);
363     }
364 }
365 
366 TEST(HFPParser, HFP_AG_ENABLE_INDICATOR_STATUS_UPDATE){
367     sprintf(packet, "\r\nAT%s=3,0,0,1\r\n", HFP_ENABLE_STATUS_UPDATE_FOR_AG_INDICATORS);
368     parse_ag(packet);
369     CHECK_EQUAL(HFP_CMD_ENABLE_INDICATOR_STATUS_UPDATE, context.command);
370     CHECK_EQUAL(1, context.enable_status_update_for_ag_indicators);
371 }
372 
373 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE){
374     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
375     context.ag_indicators_nr = hfp_ag_indicators_nr;
376     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
377 
378     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
379         CHECK_EQUAL(hfp_ag_indicators[pos].index,   hfp_ag_get_ag_indicators(&context)[pos].index );
380         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, hfp_ag_get_ag_indicators(&context)[pos].enabled);
381         CHECK_EQUAL(hfp_ag_indicators[pos].index,   context.ag_indicators[pos].index);
382         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, context.ag_indicators[pos].enabled);
383     }
384     sprintf(packet, "\r\nAT%s=0,0,0,0,0,0,0\r\n",
385         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
386     parse_ag(packet);
387     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
388 
389     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
390         if (hfp_ag_get_ag_indicators(&context)[pos].mandatory){
391             CHECK_EQUAL(1, hfp_ag_get_ag_indicators(&context)[pos].enabled);
392             CHECK_EQUAL(1, context.ag_indicators[pos].enabled);
393         } else {
394             CHECK_EQUAL(0, hfp_ag_get_ag_indicators(&context)[pos].enabled);
395             CHECK_EQUAL(0, context.ag_indicators[pos].enabled);
396         }
397     }
398 }
399 
400 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES3){
401     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
402     context.ag_indicators_nr = hfp_ag_indicators_nr;
403     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
404 
405     sprintf(packet, "\r\nAT%s=,1,,,,,1\r\n",
406         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
407     parse_ag(packet);
408 
409     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
410 
411     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
412         CHECK_EQUAL(hfp_ag_indicators[pos].index, hfp_ag_get_ag_indicators(&context)[pos].index );
413         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, hfp_ag_get_ag_indicators(&context)[pos].enabled);
414         CHECK_EQUAL(hfp_ag_indicators[pos].index, context.ag_indicators[pos].index );
415         CHECK_EQUAL(hfp_ag_indicators[pos].enabled, context.ag_indicators[pos].enabled);
416     }
417 }
418 
419 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES2){
420     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
421     context.ag_indicators_nr = hfp_ag_indicators_nr;
422     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
423 
424     sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
425         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
426     parse_ag(packet);
427 
428     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
429 
430     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
431         CHECK_EQUAL(1,hfp_ag_get_ag_indicators(&context)[pos].enabled);
432         CHECK_EQUAL(1, context.ag_indicators[pos].enabled);
433     }
434 }
435 
436 TEST(HFPParser, HFP_AG_ENABLE_INDIVIDUAL_INDICATOR_STATUS_UPDATE_OPT_VALUES1){
437     hfp_ag_init_ag_indicators(hfp_ag_indicators_nr, (hfp_ag_indicator_t *)&hfp_ag_indicators);
438     context.ag_indicators_nr = hfp_ag_indicators_nr;
439     memcpy(context.ag_indicators, hfp_ag_indicators, hfp_ag_indicators_nr * sizeof(hfp_ag_indicator_t));
440 
441     sprintf(packet, "\r\nAT%s=1,,,1,1,1,\r\n",
442         HFP_UPDATE_ENABLE_STATUS_FOR_INDIVIDUAL_AG_INDICATORS);
443     parse_ag(packet);
444 
445     CHECK_EQUAL(HFP_CMD_ENABLE_INDIVIDUAL_AG_INDICATOR_STATUS_UPDATE, context.command);
446 
447     for (pos = 0; pos < hfp_ag_indicators_nr; pos++){
448         CHECK_EQUAL(1, hfp_ag_get_ag_indicators(&context)[pos].enabled);
449         CHECK_EQUAL(1, context.ag_indicators[pos].enabled);
450     }
451 }
452 
453 TEST(HFPParser, HFP_AG_HF_QUERY_OPERATOR_SELECTION){
454     context.network_operator.format = 0xff;
455     sprintf(packet, "\r\nAT%s=3,0\r\n", HFP_QUERY_OPERATOR_SELECTION);
456 
457     parse_ag(packet);
458     CHECK_EQUAL(0, context.operator_name_changed);
459     CHECK_EQUAL(HFP_CMD_QUERY_OPERATOR_SELECTION_NAME_FORMAT, context.command);
460 
461     sprintf(packet, "\r\nAT%s?\r\n", HFP_QUERY_OPERATOR_SELECTION);
462 
463     parse_ag(packet);
464     CHECK_EQUAL(HFP_CMD_QUERY_OPERATOR_SELECTION_NAME, context.command);
465     CHECK_EQUAL(0, context.operator_name_changed);
466 }
467 
468 TEST(HFPParser, HFP_AG_EXTENDED_AUDIO_GATEWAY_ERROR){
469     sprintf(packet, "\r\nAT%s=1\r\n", HFP_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR);
470 
471     parse_ag(packet);
472     CHECK_EQUAL(HFP_CMD_ENABLE_EXTENDED_AUDIO_GATEWAY_ERROR, context.command );
473     CHECK_EQUAL(1, context.enable_extended_audio_gateway_error_report);
474 }
475 
476 TEST(HFPParser, HFP_AG_TRIGGER_CODEC_CONNECTION_SETUP){
477     sprintf(packet, "\r\nAT%s\r\n", HFP_TRIGGER_CODEC_CONNECTION_SETUP);
478     parse_ag(packet);
479     CHECK_EQUAL(HFP_CMD_TRIGGER_CODEC_CONNECTION_SETUP, context.command);
480 }
481 
482 TEST(HFPParser, HFP_AG_CONFIRM_COMMON_CODEC){
483     int codec = 2;
484     sprintf(packet, "\r\nAT%s=%d\r\n", HFP_CONFIRM_COMMON_CODEC, codec);
485 
486     parse_ag(packet);
487     CHECK_EQUAL(HFP_CMD_HF_CONFIRMED_CODEC, context.command );
488     CHECK_EQUAL(codec, context.codec_confirmed);
489 }
490 
491 TEST(HFPParser, HFP_AG_DIAL){
492     strcpy(packet, "\r\nATD00123456789;\r\n");
493 
494     parse_ag(packet);
495     CHECK_EQUAL(HFP_CMD_CALL_PHONE_NUMBER, context.command);
496     STRCMP_EQUAL("00123456789", (const char *) &context.line_buffer[3]);
497 }
498 
499 TEST(HFPParser, HFP_ANSWER_CALL){
500     sprintf(packet, "\r\n%s\r\n", HFP_ANSWER_CALL);
501     parse_ag(packet);
502     CHECK_EQUAL(HFP_CMD_CALL_ANSWERED, context.command);
503 }
504 
505 TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_QUERY){
506     sprintf(packet, "\r\nAT%s?\r\n", HFP_RESPONSE_AND_HOLD);
507     parse_ag(packet);
508     CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_QUERY, context.command);
509 }
510 
511 TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_COMMAND){
512     int param = 1;
513     sprintf(packet, "\r\nAT%s=%u\r\n", HFP_RESPONSE_AND_HOLD, param);
514     parse_ag(packet);
515     CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_COMMAND, context.command);
516     CHECK_EQUAL(param, context.ag_response_and_hold_action);
517 }
518 
519 TEST(HFPParser, HFP_CMD_RESPONSE_AND_HOLD_STATUS){
520     int status = 1;
521     sprintf(packet, "\r\n%s:%u\r\n", HFP_RESPONSE_AND_HOLD, status);
522     parse_hf(packet);
523     CHECK_EQUAL(HFP_CMD_RESPONSE_AND_HOLD_STATUS, context.command);
524 }
525 
526 TEST(HFPParser, HFP_CMD_ENABLE_CLIP){
527     int param = 1;
528     sprintf(packet, "\r\nAT%s=%u\r\n", HFP_ENABLE_CLIP, param);
529     parse_ag(packet);
530     CHECK_EQUAL(HFP_CMD_ENABLE_CLIP, context.command);
531     CHECK_EQUAL(param, context.clip_enabled);
532 }
533 
534 int main (int argc, const char * argv[]){
535     return CommandLineTestRunner::RunAllTests(argc, argv);
536 }
537