diff options
author | Dan Williams <dan@ioncontrol.co> | 2025-05-15 10:13:22 -0500 |
---|---|---|
committer | Dan Williams <dan@ioncontrol.co> | 2025-05-23 08:31:04 -0500 |
commit | 757df26b295a9b9306fe3278b7f3730cc3a9c703 (patch) | |
tree | da03bcd23f88512dff7070ad9676ee047ba729d4 /src/tests/test-modem-helpers.c | |
parent | c5a2cd3157854b9f368717f72ebc852d6d8de954 (diff) |
broadband-modem,modem-helpers: move +CPIN response parsing to modem helpers
Unit test it better, plus remove code duplication in various plugins.
Signed-off-by: Dan Williams <dan@ioncontrol.co>
Diffstat (limited to 'src/tests/test-modem-helpers.c')
-rw-r--r-- | src/tests/test-modem-helpers.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index a3a42ad8..3421921b 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -5089,6 +5089,37 @@ test_string_to_access_tech (void) /*****************************************************************************/ +typedef struct { + const gchar *str; + const gboolean expect_prefix; + const MMModemLock expected_lock; +} TestCpinResponse; + +static const TestCpinResponse test_cpin_responses[] = { + { "+CME ERROR: 100", TRUE, MM_MODEM_LOCK_UNKNOWN }, + { "+CPIN: SIM PIN", TRUE, MM_MODEM_LOCK_SIM_PIN }, + { "+CPIN: SIM PUK2", TRUE, MM_MODEM_LOCK_SIM_PUK2 }, + { " SIM PUK", FALSE, MM_MODEM_LOCK_SIM_PUK }, + { " SIM PUK2", FALSE, MM_MODEM_LOCK_SIM_PUK2 }, + { "+CPIN: \"SIM PIN\"", TRUE, MM_MODEM_LOCK_SIM_PIN }, + { "+CPIN: PH-NET PIN", TRUE, MM_MODEM_LOCK_PH_NET_PIN }, +}; + +static void +test_cpin_response (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (test_cpin_responses); i++) { + MMModemLock lock; + + lock = mm_parse_cpin_response (test_cpin_responses[i].str, test_cpin_responses[i].expect_prefix); + g_assert_cmpint (lock, ==, test_cpin_responses[i].expected_lock); + } +} + +/*****************************************************************************/ + #define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (GTestFixtureFunc) t, NULL) int main (int argc, char **argv) @@ -5351,6 +5382,8 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_string_to_access_tech, NULL)); + g_test_suite_add (suite, TESTCASE (test_cpin_response, NULL)); + result = g_test_run (); reg_test_data_free (reg_data); |