aboutsummaryrefslogtreecommitdiff
path: root/src/tests/test-modem-helpers.c
diff options
context:
space:
mode:
authorMichal Mazur <michamazur@google.com>2024-09-19 19:29:40 +0000
committerAleksander Morgado <aleksander@aleksander.es>2024-09-25 12:08:40 +0000
commita030eaef7639e491f085cdd0ee52a217b8b7bea9 (patch)
tree97a94697cbfdcca96fabc97264d93b08b3190a10 /src/tests/test-modem-helpers.c
parent257839c66ee6982eee9108b6661a5816b85ad885 (diff)
sim: add common helpers to parse operator name and mnc length
Diffstat (limited to 'src/tests/test-modem-helpers.c')
-rw-r--r--src/tests/test-modem-helpers.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index 176d0189..538aedfe 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -4689,6 +4689,89 @@ test_mm_split_string_groups (void)
/*****************************************************************************/
+typedef struct {
+ const guint8 bin_array[10];
+ gsize bin_len;
+ const gchar *expected_name;
+ gboolean expected_error;
+} TestSpnData;
+
+static const TestSpnData test_spn_data[] = {
+ { { 0, 'T', 'e', 's', 't', 0xff, 0xff, 0xff, 0xff, 0xff }, 10, "Test", FALSE },
+ { { 'T', 'e', 's', 't', 0xff, 0xff }, 6, "est", FALSE },
+ { { 0, 0, '$', 'T', 'e', 's', 't' }, 7, "@¤Test", FALSE },
+ { { 0 }, 0, "", TRUE },
+ { { 0, 0xff }, 2, "", TRUE },
+ { { 0xff, 0xff }, 2, "", TRUE },
+};
+
+static void
+test_spn_to_utf8 (void)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (test_spn_data); i++) {
+ gchar *result = NULL;
+ GError *error = NULL;
+
+ result = mm_sim_convert_spn_to_utf8 (test_spn_data[i].bin_array,
+ test_spn_data[i].bin_len,
+ &error);
+
+ if (test_spn_data[i].expected_error) {
+ g_assert (!result);
+ g_assert (error);
+ g_error_free (error);
+ } else {
+ g_assert (result);
+ g_assert_no_error (error);
+ g_assert_cmpstr (result, ==, test_spn_data[i].expected_name);
+ g_free (result);
+ }
+ }
+}
+
+typedef struct {
+ const guint8 bin_array[4];
+ gsize bin_len;
+ guint expected_length;
+ gboolean expected_error;
+} TestMncData;
+
+static const TestMncData test_mnc_data[] = {
+ { { 0 }, 0, 0, TRUE },
+ { { 0, 0, 0, 2 }, 3, 0, TRUE },
+ { { 0, 0, 0, 2 }, 5, 2, FALSE },
+ { { 0, 0, 0, 2 }, 4, 2, FALSE },
+ { { 0, 0, 0, 3 }, 4, 3, FALSE },
+ { { 0, 0, 0, 4 }, 4, 0, TRUE },
+};
+
+static void
+test_mnc_length (void)
+{
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS (test_mnc_data); i++) {
+ guint result;
+ GError *error = NULL;
+
+ result = mm_sim_validate_mnc_length (test_mnc_data[i].bin_array,
+ test_mnc_data[i].bin_len,
+ &error);
+
+ if (test_mnc_data[i].expected_error) {
+ g_assert (error);
+ g_error_free (error);
+ } else {
+ g_assert_no_error (error);
+ }
+ g_assert_cmpuint (result, ==, test_mnc_data[i].expected_length);
+ }
+}
+
+/*****************************************************************************/
+
#define TESTCASE(t, d) g_test_create_case (#t, 0, d, NULL, (GTestFixtureFunc) t, NULL)
int main (int argc, char **argv)
@@ -4929,6 +5012,9 @@ int main (int argc, char **argv)
g_test_suite_add (suite, TESTCASE (test_mm_split_string_groups, NULL));
+ g_test_suite_add (suite, TESTCASE (test_spn_to_utf8, NULL));
+ g_test_suite_add (suite, TESTCASE (test_mnc_length, NULL));
+
result = g_test_run ();
reg_test_data_free (reg_data);