diff options
author | Dan Williams <dcbw@redhat.com> | 2013-09-09 13:00:43 -0500 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-09-10 09:42:36 +0200 |
commit | 11a7e3dfdf0642c451bfd7c214f4b52640ef661a (patch) | |
tree | 1d51d13aeb7ffc5383b65969dabfa7086a8e1269 /src/tests/test-modem-helpers.c | |
parent | ac343d390ba804ebd58c5477f45c69c1b8402edd (diff) |
core: add helper for parsing and validating the ICCID
Diffstat (limited to 'src/tests/test-modem-helpers.c')
-rw-r--r-- | src/tests/test-modem-helpers.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index b8cd2d44..28d9b12a 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -1523,6 +1523,83 @@ test_cind_response_moto_v3m (void *f, gpointer d) } /*****************************************************************************/ +/* Test ICCID parsing */ + +static void +test_iccid_parse_quoted_swap_19_digit (void *f, gpointer d) +{ + const char *raw_iccid = "\"984402003576012594F9\""; + const char *expected = "8944200053671052499"; + char *parsed; + GError *error = NULL; + + parsed = mm_3gpp_parse_iccid (raw_iccid, TRUE, &error); + g_assert_no_error (error); + g_assert_cmpstr (parsed, ==, expected); +} + +static void +test_iccid_parse_unquoted_swap_20_digit (void *f, gpointer d) +{ + const char *raw_iccid = "98231420326409614067"; + const char *expected = "89324102234690160476"; + char *parsed; + GError *error = NULL; + + parsed = mm_3gpp_parse_iccid (raw_iccid, TRUE, &error); + g_assert_no_error (error); + g_assert_cmpstr (parsed, ==, expected); +} + +static void +test_iccid_parse_unquoted_unswapped_19_digit (void *f, gpointer d) +{ + const char *raw_iccid = "8944200053671052499F"; + const char *expected = "8944200053671052499"; + char *parsed; + GError *error = NULL; + + parsed = mm_3gpp_parse_iccid (raw_iccid, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (parsed, ==, expected); +} + +static void +test_iccid_parse_quoted_unswapped_20_digit (void *f, gpointer d) +{ + const char *raw_iccid = "\"89324102234690160476\""; + const char *expected = "89324102234690160476"; + char *parsed; + GError *error = NULL; + + parsed = mm_3gpp_parse_iccid (raw_iccid, FALSE, &error); + g_assert_no_error (error); + g_assert_cmpstr (parsed, ==, expected); +} + +static void +test_iccid_parse_short (void *f, gpointer d) +{ + const char *raw_iccid = "982314203264096"; + char *parsed; + GError *error = NULL; + + parsed = mm_3gpp_parse_iccid (raw_iccid, TRUE, &error); + g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED); +} + +static void +test_iccid_parse_invalid_chars (void *f, gpointer d) +{ + const char *raw_iccid = "98231420326ab9614067"; + char *parsed; + GError *error = NULL; + + parsed = mm_3gpp_parse_iccid (raw_iccid, TRUE, &error); + g_assert_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED); +} + +/*****************************************************************************/ /* Test CGDCONT test responses */ static void @@ -2315,6 +2392,13 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_cind_response_linktop_lw273, NULL)); g_test_suite_add (suite, TESTCASE (test_cind_response_moto_v3m, NULL)); + g_test_suite_add (suite, TESTCASE (test_iccid_parse_quoted_swap_19_digit, NULL)); + g_test_suite_add (suite, TESTCASE (test_iccid_parse_unquoted_swap_20_digit, NULL)); + g_test_suite_add (suite, TESTCASE (test_iccid_parse_unquoted_unswapped_19_digit, NULL)); + g_test_suite_add (suite, TESTCASE (test_iccid_parse_quoted_unswapped_20_digit, NULL)); + g_test_suite_add (suite, TESTCASE (test_iccid_parse_short, NULL)); + g_test_suite_add (suite, TESTCASE (test_iccid_parse_invalid_chars, NULL)); + while (item->devid) { g_test_suite_add (suite, TESTCASE (test_devid_item, (gconstpointer) item)); item++; |