From 973c7d0970d5151f1b5d40b01ce0f2334c226b7c Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Sat, 25 Mar 2017 00:47:50 +0100 Subject: helpers: new parser for AT+IFC=? Instead of having the parser return separate list of supported flow controls for TE and TA, we simplify it by only returning those settings that apply to both TE and TA. This logic isn't perfect either, though, as some settings (e.g. '3' in TE in some modems, specifying a different XON/XOFF behavior) may not have a corresponding setting in the other end. The most common cases we care about (i.e. standard XON/XOFF, RTS/CTS) should be properly reported with this logic. --- src/tests/test-modem-helpers.c | 100 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) (limited to 'src/tests/test-modem-helpers.c') diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index ae0eec99..b59c5900 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -32,6 +32,93 @@ #define g_assert_cmpfloat_tolerance(val1, val2, tolerance) \ g_assert_cmpfloat (fabs (val1 - val2), <, tolerance) +/*****************************************************************************/ +/* Test IFC=? responses */ + +static void +test_ifc_response (const gchar *str, + const MMFlowControl expected) +{ + MMFlowControl mask; + GError *error = NULL; + + mask = mm_parse_ifc_test_response (str, &error); + g_assert_no_error (error); + g_assert_cmpuint (mask, ==, expected); +} + +static void +test_ifc_response_all_simple (void) +{ + test_ifc_response ("+IFC (0,1,2),(0,1,2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_XON_XOFF | MM_FLOW_CONTROL_RTS_CTS)); +} + +static void +test_ifc_response_all_groups (void) +{ + test_ifc_response ("+IFC (0-2),(0-2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_XON_XOFF | MM_FLOW_CONTROL_RTS_CTS)); +} + +static void +test_ifc_response_none_only (void) +{ + test_ifc_response ("+IFC (0),(0)", MM_FLOW_CONTROL_NONE); +} + +static void +test_ifc_response_xon_xoff_only (void) +{ + test_ifc_response ("+IFC (1),(1)", MM_FLOW_CONTROL_XON_XOFF); +} + +static void +test_ifc_response_rts_cts_only (void) +{ + test_ifc_response ("+IFC (2),(2)", MM_FLOW_CONTROL_RTS_CTS); +} + +static void +test_ifc_response_no_xon_xoff (void) +{ + test_ifc_response ("+IFC (0,2),(0,2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_RTS_CTS)); +} + +static void +test_ifc_response_no_xon_xoff_in_ta (void) +{ + test_ifc_response ("+IFC (0,1,2),(0,2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_RTS_CTS)); +} + +static void +test_ifc_response_no_xon_xoff_in_te (void) +{ + test_ifc_response ("+IFC (0,2),(0,1,2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_RTS_CTS)); +} + +static void +test_ifc_response_no_rts_cts_simple (void) +{ + test_ifc_response ("+IFC (0,1),(0,1)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_XON_XOFF)); +} + +static void +test_ifc_response_no_rts_cts_groups (void) +{ + test_ifc_response ("+IFC (0-1),(0-1)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_XON_XOFF)); +} + +static void +test_ifc_response_all_simple_and_unknown (void) +{ + test_ifc_response ("+IFC (0,1,2,3),(0,1,2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_XON_XOFF | MM_FLOW_CONTROL_RTS_CTS)); +} + +static void +test_ifc_response_all_groups_and_unknown (void) +{ + test_ifc_response ("+IFC (0-3),(0-2)", (MM_FLOW_CONTROL_NONE | MM_FLOW_CONTROL_XON_XOFF | MM_FLOW_CONTROL_RTS_CTS)); +} + /*****************************************************************************/ /* Test WS46=? responses */ @@ -3536,6 +3623,19 @@ int main (int argc, char **argv) suite = g_test_get_root (); reg_data = reg_test_data_new (); + g_test_suite_add (suite, TESTCASE (test_ifc_response_all_simple, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_all_groups, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_none_only, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_xon_xoff_only, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_rts_cts_only, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_no_xon_xoff, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_no_xon_xoff_in_ta, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_no_xon_xoff_in_te, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_no_rts_cts_simple, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_no_rts_cts_groups, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_all_simple_and_unknown, NULL)); + g_test_suite_add (suite, TESTCASE (test_ifc_response_all_groups_and_unknown, NULL)); + g_test_suite_add (suite, TESTCASE (test_ws46_response_generic_2g3g4g, NULL)); g_test_suite_add (suite, TESTCASE (test_ws46_response_generic_2g3g, NULL)); g_test_suite_add (suite, TESTCASE (test_ws46_response_generic_2g3g_v2, NULL)); -- cgit v1.2.3-70-g09d2