| 1 |
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 3 |
/* |
| 4 |
* Copyright (C) 2025 Dan Williams <[email protected]> |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <config.h> |
| 8 |
|
| 9 |
#include "mbimcli-helpers-quectel.h" |
| 10 |
|
| 11 |
#define UNSET_CMD_TYPE 999 |
| 12 |
|
| 13 |
typedef struct { |
| 14 |
const gchar *name; |
| 15 |
const gchar *type_str; |
| 16 |
const gchar *cmd_str; |
| 17 |
const MbimQuectelCommandType expected_cmd_type; |
| 18 |
gboolean expect_error; |
| 19 |
} testcase; |
| 20 |
|
| 21 |
static void |
| 22 |
test_set_command_input_parse_common (gconstpointer user_data) |
| 23 |
{ |
| 24 |
const testcase *tc = user_data; |
| 25 |
g_autofree gchar *input_str = NULL; |
| 26 |
g_autofree gchar *parsed_cmd = NULL; |
| 27 |
MbimQuectelCommandType parsed_type = UNSET_CMD_TYPE; |
| 28 |
gboolean success; |
| 29 |
|
| 30 |
if (tc->type_str != NULL) { |
| 31 |
input_str = g_strdup_printf("%s,%s", tc->type_str, tc->cmd_str); |
| 32 |
} else { |
| 33 |
input_str = g_strdup (tc->cmd_str); |
| 34 |
} |
| 35 |
success = mbimcli_helpers_quectel_set_command_input_parse (input_str, |
| 36 |
&parsed_cmd, |
| 37 |
&parsed_type); |
| 38 |
g_assert (success != tc->expect_error); |
| 39 |
if (!tc->expect_error) { |
| 40 |
g_assert_cmpstr (parsed_cmd, ==, tc->cmd_str); |
| 41 |
} |
| 42 |
g_assert_cmpuint (parsed_type, ==, tc->expected_cmd_type); |
| 43 |
} |
| 44 |
|
| 45 |
int main (int argc, char **argv) |
| 46 |
{ |
| 47 |
gsize i; |
| 48 |
const testcase test_data[] = { |
| 49 |
/* Untyped AT commands */ |
| 50 |
{ |
| 51 |
.name = "no-type", |
| 52 |
.cmd_str = "at+cversion;+qgmr;+csub", |
| 53 |
.expected_cmd_type = UNSET_CMD_TYPE, |
| 54 |
}, |
| 55 |
{ |
| 56 |
.name = "no-type-commas", |
| 57 |
.cmd_str = "at+qcfg=\"usbcfg\",0x2C7C,0x6008,0x00FF", |
| 58 |
.expected_cmd_type = UNSET_CMD_TYPE, |
| 59 |
}, |
| 60 |
{ |
| 61 |
.name = "bad-no-type", |
| 62 |
.cmd_str = "bm+cversion;+qgmr;+csub", |
| 63 |
.expected_cmd_type = UNSET_CMD_TYPE, |
| 64 |
.expect_error = TRUE, |
| 65 |
}, |
| 66 |
/* AT-type AT commands */ |
| 67 |
{ |
| 68 |
.name = "at-type", |
| 69 |
.type_str = "at", |
| 70 |
.cmd_str = "at+cversion;+qgmr;+csub", |
| 71 |
.expected_cmd_type = MBIM_QUECTEL_COMMAND_TYPE_AT, |
| 72 |
}, |
| 73 |
{ |
| 74 |
.name = "at-type-commas", |
| 75 |
.type_str = "at", |
| 76 |
.cmd_str = "at+qcfg=\"usbcfg\",0x2C7C,0x6008,0x00FF", |
| 77 |
.expected_cmd_type = MBIM_QUECTEL_COMMAND_TYPE_AT, |
| 78 |
}, |
| 79 |
{ |
| 80 |
.name = "bad-at-type", |
| 81 |
.type_str = "at", |
| 82 |
.cmd_str = "bm+cversion;+qgmr;+csub", |
| 83 |
.expected_cmd_type = UNSET_CMD_TYPE, |
| 84 |
.expect_error = TRUE, |
| 85 |
}, |
| 86 |
}; |
| 87 |
|
| 88 |
g_test_init (&argc, &argv, NULL); |
| 89 |
|
| 90 |
for (i = 0; i < G_N_ELEMENTS(test_data); i++) { |
| 91 |
g_autofree gchar *test_desc; |
| 92 |
|
| 93 |
test_desc = g_strdup_printf("/mbimcli/quectel/set-command-input-parse/%s", test_data[i].name); |
| 94 |
g_test_add_data_func (test_desc, &test_data[i], test_set_command_input_parse_common); |
| 95 |
} |
| 96 |
|
| 97 |
return g_test_run (); |
| 98 |
} |