aboutsummaryrefslogtreecommitdiff
path: root/src/tests/test-modem-helpers.c
diff options
context:
space:
mode:
authorEric Caruso <ejcaruso@chromium.org>2020-10-16 11:22:37 -0700
committerEric Caruso <ejcaruso@chromium.org>2020-10-16 11:22:37 -0700
commit1800983b6c77b495a97eb4335541561456abfed5 (patch)
tree9882f6130f9ef91ec298eba2d1243e6a9d1ae668 /src/tests/test-modem-helpers.c
parentf013e94ff89680d1acd7dba12ff4a6a0fa7b58bf (diff)
mm-modem-helpers: add low_nybble_first argument to mm_bcd_to_string
All BCD-encoded strings used by MM currently have the low nybble of each byte come before the high nybble, but some strings (such as the EID string returned by QMI Get Slot Status) are meant to be read in order with the high nybble before the low one. As such, extend mm_bcd_to_string to decode both.
Diffstat (limited to 'src/tests/test-modem-helpers.c')
-rw-r--r--src/tests/test-modem-helpers.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c
index 78b3cd11..a6bc72d2 100644
--- a/src/tests/test-modem-helpers.c
+++ b/src/tests/test-modem-helpers.c
@@ -4429,20 +4429,22 @@ test_parse_uint_list (void)
typedef struct {
const guint8 bcd[10];
gsize bcd_len;
- const gchar *str;
+ const gchar *low_nybble_first_str;
+ const gchar *high_nybble_first_str;
} BcdToStringTest;
static const BcdToStringTest bcd_to_string_tests[] = {
- { { }, 0, "" },
- { { 0x01 }, 1, "10" },
- { { 0x1F }, 1, "" },
- { { 0xE2 }, 1, "2" },
- { { 0xD3 }, 1, "3" },
- { { 0xC4 }, 1, "4" },
- { { 0xB1, 0x23 }, 2, "1" },
- { { 0x01, 0x23, 0x45, 0x67 }, 4, "10325476" },
- { { 0x01, 0x23, 0x45, 0xA7 }, 4, "1032547" },
- { { 0x01, 0x23, 0x45, 0x67 }, 2, "1032" },
+ { { }, 0, "", "" },
+ { { 0x01 }, 1, "10", "01" },
+ { { 0x1F }, 1, "", "1" },
+ { { 0xE2 }, 1, "2", "" },
+ { { 0xD3 }, 1, "3", "" },
+ { { 0xC4 }, 1, "4", "" },
+ { { 0xB1, 0x23 }, 2, "1", "" },
+ { { 0x01, 0x2A }, 2, "10", "012" },
+ { { 0x01, 0x23, 0x45, 0x67 }, 4, "10325476", "01234567" },
+ { { 0x01, 0x23, 0x45, 0xA7 }, 4, "1032547", "012345" },
+ { { 0x01, 0x23, 0x45, 0x67 }, 2, "1032", "0123" },
};
static void
@@ -4454,8 +4456,15 @@ test_bcd_to_string (void *f, gpointer d)
gchar *str;
str = mm_bcd_to_string (bcd_to_string_tests[i].bcd,
- bcd_to_string_tests[i].bcd_len);
- g_assert_cmpstr (str, ==, bcd_to_string_tests[i].str);
+ bcd_to_string_tests[i].bcd_len,
+ TRUE /* low_nybble_first */);
+ g_assert_cmpstr (str, ==, bcd_to_string_tests[i].low_nybble_first_str);
+ g_free (str);
+
+ str = mm_bcd_to_string (bcd_to_string_tests[i].bcd,
+ bcd_to_string_tests[i].bcd_len,
+ FALSE /* low_nybble_first */);
+ g_assert_cmpstr (str, ==, bcd_to_string_tests[i].high_nybble_first_str);
g_free (str);
}
}