diff options
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/test-modem-helpers.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index c6fef40a..14f32961 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -3060,6 +3060,49 @@ test_cgcontrdp_response (void) /*****************************************************************************/ +typedef struct { + gchar *str; + gint expected_number_list[9]; +} TestParseNumberList; + +static const TestParseNumberList test_parse_number_list_item [] = { + { "1-6", { 1, 2, 3, 4, 5, 6, -1 } }, + { "0,1,2,4,6", { 0, 1, 2, 4, 6, -1 } }, + { "1,3-5,7,9-11", { 1, 3, 4, 5, 7, 9, 10, 11, -1 } }, + { "9-11,7,3-5", { 3, 4, 5, 7, 9, 10, 11, -1 } }, + { "", { -1 } }, + { NULL, { -1 } }, +}; + +static void +test_parse_uint_list (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (test_parse_number_list_item); i++) { + GArray *array; + GError *error = NULL; + guint j; + + array = mm_parse_uint_list (test_parse_number_list_item[i].str, &error); + g_assert_no_error (error); + if (test_parse_number_list_item[i].expected_number_list[0] == -1) { + g_assert (!array); + continue; + } + + g_assert (array); + for (j = 0; j < array->len; j++) { + g_assert_cmpint (test_parse_number_list_item[i].expected_number_list[j], !=, -1); + g_assert_cmpuint (test_parse_number_list_item[i].expected_number_list[j], ==, g_array_index (array, guint, j)); + } + g_assert_cmpint (test_parse_number_list_item[i].expected_number_list[array->len], ==, -1); + g_array_unref (array); + } +} + +/*****************************************************************************/ + void _mm_log (const char *loc, const char *func, @@ -3245,6 +3288,8 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_cgcontrdp_response, NULL)); + g_test_suite_add (suite, TESTCASE (test_parse_uint_list, NULL)); + result = g_test_run (); reg_test_data_free (reg_data); |