This adds minimal packet exchange to test the SLC establishment. --- v1->v2: Fix ERROR:unit/test-hfp.c:734:hf_update_indicator: assertion failed (val == 1): (0 == 1) unit/test-hfp.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/unit/test-hfp.c b/unit/test-hfp.c index b4af99d53..b79034642 100644 --- a/unit/test-hfp.c +++ b/unit/test-hfp.c @@ -104,6 +104,14 @@ struct test_data { data.test_handler = test_hf_handler; \ } while (0) +static void print_debug(const char *str, void *user_data) +{ + const char *prefix = user_data; + + if (tester_use_debug()) + tester_debug("%s%s", prefix, str); +} + static void test_free(gconstpointer user_data) { const struct test_data *data = user_data; @@ -680,6 +688,110 @@ static void test_hf_robustness(gconstpointer data) context_quit(context); } +#define MINIMAL_SLC_SESSION \ + raw_pdu('\r', '\n', '+', 'B', 'R', 'S', 'F', ':', \ + ' ', '0', '\r', '\n'), \ + frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \ + raw_pdu('\r', '\n', '+', 'C', 'I', 'N', 'D', ':', ' '), \ + frg_pdu('(', '\"', 's', 'e', 'r', 'v', 'i', 'c', 'e'), \ + frg_pdu('\"', '(', '0', ',', '1', ')', ')', ','), \ + frg_pdu('(', '\"', 'c', 'a', 'l', 'l', '\"'), \ + frg_pdu('(', '0', ',', '1', ')', ')', ','), \ + frg_pdu('(', '\"', 'c', 'a', 'l', 'l', 's', 'e', 't'), \ + frg_pdu('u', 'p', '\"', ',', '(', '0', '-', '3', ')'), \ + frg_pdu(')', ','), \ + frg_pdu('(', '\"', 'c', 'a', 'l', 'l', 'h', 'e', 'l'), \ + frg_pdu('d', '\"', ',', '(', '0', '-', '2', ')', ')'), \ + frg_pdu(',', '(', '\"', 's', 'i', 'g', 'n', 'a', 'l'), \ + frg_pdu('\"', '(', '0', '-', '5', ')', ')', ','), \ + frg_pdu('(', '\"', 'r', 'o', 'a', 'm', '\"', ',', '('), \ + frg_pdu('0', ',', '1', ')', ')', ','), \ + frg_pdu('(', '\"', 'b', 'a', 't', 't', 'c', 'h', 'g'), \ + frg_pdu('\"', '(', '0', '-', '5', ')', ')', ','), \ + frg_pdu('\r', '\n'), \ + frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \ + raw_pdu('\r', '\n', '+', 'C', 'I', 'N', 'D', ':', ' '), \ + frg_pdu('0', ',', '0', ',', '0', ',', '0', ',', '5'), \ + frg_pdu(',', '0', ',', '5', '\r', '\n'), \ + frg_pdu('\r', '\n', 'O', 'K', '\r', '\n'), \ + raw_pdu('\r', '\n', 'O', 'K', '\r', '\n') + +static void hf_session_ready_cb(enum hfp_result res, enum hfp_error cme_err, + void *user_data) +{ + struct context *context = user_data; + + g_assert_cmpint(res, ==, HFP_RESULT_OK); + + context->data->response_func(res, cme_err, context); +} + +static void hf_update_indicator(enum hfp_indicator indicator, uint32_t val, + void *user_data) +{ + switch (indicator) { + case HFP_INDICATOR_SERVICE: + g_assert_cmpint(val, ==, 0); + break; + case HFP_INDICATOR_CALL: + g_assert_cmpint(val, ==, 0); + break; + case HFP_INDICATOR_CALLSETUP: + g_assert_cmpint(val, ==, 0); + break; + case HFP_INDICATOR_CALLHELD: + g_assert_cmpint(val, ==, 0); + break; + case HFP_INDICATOR_SIGNAL: + g_assert_cmpint(val, ==, 5); + break; + case HFP_INDICATOR_ROAM: + g_assert_cmpint(val, ==, 0); + break; + case HFP_INDICATOR_BATTCHG: + g_assert_cmpint(val, ==, 5); + break; + case HFP_INDICATOR_LAST: + default: + tester_test_failed(); + } +} + +static struct hfp_hf_callbacks hf_session_callbacks = { + .session_ready = hf_session_ready_cb, + .update_indicator = hf_update_indicator, +}; + +static void test_hf_session_done(enum hfp_result res, enum hfp_error cme_err, + void *user_data) +{ + struct context *context = user_data; + + hfp_hf_disconnect(context->hfp_hf); +} + +static void test_hf_session(gconstpointer data) +{ + struct context *context = create_context(data); + bool ret; + + context->hfp_hf = hfp_hf_new(context->fd_client); + g_assert(context->hfp_hf); + + ret = hfp_hf_set_debug(context->hfp_hf, print_debug, "hfp-hf:", NULL); + g_assert(ret); + + ret = hfp_hf_set_close_on_unref(context->hfp_hf, true); + g_assert(ret); + + ret = hfp_hf_session_register(context->hfp_hf, &hf_session_callbacks, + context); + g_assert(ret); + + ret = hfp_hf_session(context->hfp_hf); + g_assert(ret); +} + int main(int argc, char *argv[]) { tester_init(&argc, &argv); @@ -850,5 +962,10 @@ int main(int argc, char *argv[]) frg_pdu('1', ',', '2', 'x', '\r', '\n'), data_end()); + define_hf_test("/hfp_hf/test_session_minimal", test_hf_session, + NULL, test_hf_session_done, + MINIMAL_SLC_SESSION, + data_end()); + return tester_run(); } -- 2.43.0