diff options
author | Aleksander Morgado <aleksandermj@chromium.org> | 2024-03-07 14:09:28 +0000 |
---|---|---|
committer | Aleksander Morgado <aleksandermj@chromium.org> | 2024-03-12 10:15:59 +0000 |
commit | 07f1f5864204dfdf455067def863fcd20c8c6a26 (patch) | |
tree | b2d3869a468de9bce1405b394b832aa711865806 /src/tests/test-modem-helpers.c | |
parent | 311d6f389e74899bc1790928bb44e8361e411a1b (diff) |
modem-helpers: rework AT string quote operation and add unit tests
Rework the AT string quote operation to build the output with the
GString helper, instead of manually calculating how many bytes we'll
need in the output. It just makes it clearer.
Diffstat (limited to 'src/tests/test-modem-helpers.c')
-rw-r--r-- | src/tests/test-modem-helpers.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 70716765..e7277df8 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -4546,6 +4546,34 @@ test_bcd_to_string (void *f, gpointer d) /*****************************************************************************/ typedef struct { + const gchar *input; + const gchar *expected; +} AtQuoteStringTest; + +static const AtQuoteStringTest at_quote_string_tests[] = { + { "", "\"\"" }, + { "internet", "\"internet\"" }, + { "\"internet", "\"\\22internet\"" }, /* double quote is \22 */ + { "\r\ninternet", "\"\\0D\\0Ainternet\"" }, /* CRLF is \0D\0A */ + { "\r\ninternet\r\n", "\"\\0D\\0Ainternet\\0D\\0A\"" }, /* CRLF is \0D\0A */ +}; + +static void +test_at_quote_string (void *f, gpointer d) +{ + guint i; + + for (i = 0; i < G_N_ELEMENTS (at_quote_string_tests); i++) { + g_autofree gchar *str = NULL; + + str = mm_at_quote_string (at_quote_string_tests[i].input); + g_assert_cmpstr (str, ==, at_quote_string_tests[i].expected); + } +} + +/*****************************************************************************/ + +typedef struct { const gchar *response; gboolean expected_error; guint expected_index; @@ -4855,6 +4883,8 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_bcd_to_string, NULL)); + g_test_suite_add (suite, TESTCASE (test_at_quote_string, NULL)); + g_test_suite_add (suite, TESTCASE (test_cpol_response, NULL)); result = g_test_run (); |