diff options
author | Guido Günther <agx@sigxcpu.org> | 2025-02-22 17:17:32 +0100 |
---|---|---|
committer | Dan Williams <dan@ioncontrol.co> | 2025-03-28 20:53:52 +0000 |
commit | d8135be6e2c132e59d3fbe9d231afa88b1e5e2b2 (patch) | |
tree | ed611ac44eca5ef25cc3f7d4954fed760aca2781 /src/tests/test-modem-helpers.c | |
parent | 0c20d13b30a7f93625b48a5150f92ebd76ccb7b0 (diff) |
modem-helpers: Add helpers to parse channel lists
`CSCB` has the form
```
CSCB: [0|1],"<channel-list>","<data-coding-scheme>"
```
If the first parameter is `0` this specifies the accepted types if `1`
it specifies rejected.
So far seen in the wild were CSCB strings with accepted types only and a
coding scheme of "" so this is what we handle for the moment.
Signed-off-by: Guido Günther <agx@sigxcpu.org>
Diffstat (limited to 'src/tests/test-modem-helpers.c')
-rw-r--r-- | src/tests/test-modem-helpers.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 538aedfe..6692e56d 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4278,6 +4278,100 @@ test_ccwa_response (void) } /*****************************************************************************/ +/* Test +CSCB channel lists */ + +typedef struct { + const gchar *response; + const MMCellBroadcastChannels *channels; + guint len; + gboolean error; +} TestCscb; + +static void +common_test_cscb_response (const gchar *response, TestCscb *expected) +{ + GError *error = NULL; + GArray *result; + + g_debug ("Testing '%s'", response); + result = mm_3gpp_parse_cscb_response (response, &error); + + if (expected->error) { + g_assert (!result); + g_assert_nonnull (error); + g_error_free (error); + } else { + guint i; + + g_assert_no_error (error); + g_assert (result); + g_assert_cmpint (result->len, ==, expected->len); + for (i = 0; i < expected->len; i++) { + MMCellBroadcastChannels ch = g_array_index (result, MMCellBroadcastChannels, i); + + g_assert_cmpuint (ch.start, ==, expected->channels[i].start); + g_assert_cmpuint (ch.end, ==, expected->channels[i].end); + } + } +} + +static const MMCellBroadcastChannels cscb_one_channel[] = { + { .start = 0, .end = 0 }, +}; + +static const MMCellBroadcastChannels cscb_all_channels[] = { + { .start = 0, .end = 65535 }, +}; + +static const MMCellBroadcastChannels cscb_interval_channels[] = { + { .start = 0, .end = 1 }, + { .start = 100, .end = 200 }, +}; + +static const MMCellBroadcastChannels cscb_dell5821e_channels[] = { + { .start = 4383, .end = 4383 }, + { .start = 4400, .end = 4400 }, + { .start = 4370, .end = 4370 }, + { .start = 4371, .end = 4378 }, + { .start = 4384, .end = 4391 }, + { .start = 4396, .end = 4397 }, +}; + +static TestCscb test_cscb[] = { + { "\r\n+CSCB: 0, \"0\",\"\"\r\n\r\nOK\r\n", /* one channel */ + cscb_one_channel, + G_N_ELEMENTS (cscb_all_channels), + FALSE }, + { "+CSCB: 0,\"0-65535\",\"\"\r\n", /* all channels */ + cscb_all_channels, + G_N_ELEMENTS (cscb_all_channels), + FALSE }, + { "+CSCB: 0,\"0-1,100-200\",\"\"\r\n", /* intervals */ + cscb_interval_channels, + G_N_ELEMENTS (cscb_interval_channels), + FALSE }, + /* Dell 5821e/T77W968 defaults */ + { "+CSCB: 0, \"4383,4400,4370,4371-4378,4384-4391,4396-4397\",\"\"", + cscb_dell5821e_channels, + G_N_ELEMENTS (cscb_dell5821e_channels), + FALSE }, + { "+CSCB: 0,\"0-\",\"\"\r\n", /* broken interval */ + NULL, + 0, + TRUE }, +}; + +static void +test_cscb_response (void) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (test_cscb); i++) + common_test_cscb_response (test_cscb[i].response, &test_cscb[i]); +} + + +/*****************************************************************************/ /* Test +CLCC URCs */ static void @@ -4994,6 +5088,8 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_ccwa_indication, NULL)); g_test_suite_add (suite, TESTCASE (test_ccwa_response, NULL)); + g_test_suite_add (suite, TESTCASE (test_cscb_response, NULL)); + g_test_suite_add (suite, TESTCASE (test_clcc_response_empty, NULL)); g_test_suite_add (suite, TESTCASE (test_clcc_response_single, NULL)); g_test_suite_add (suite, TESTCASE (test_clcc_response_single_long, NULL)); |