MOS Source Code
Loading...
Searching...
No Matches
test_cmdline_parser.c
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-3.0-or-later
2
3#include "test_engine_impl.h"
4
5#include <mos/lib/cmdline.h>
6
8{
9 char cmdline[256] = "one two three four five six seven eight nine ten";
10 const char *cmdlines[11] = { 0 };
11 size_t cmdlines_count = 0;
12 cmdline_parse_inplace(cmdline, strlen(cmdline), 10, &cmdlines_count, cmdlines);
13 MOS_TEST_CHECK(cmdlines_count, 10);
14 MOS_TEST_CHECK_STRING(cmdlines[0], "one");
15 MOS_TEST_CHECK_STRING(cmdlines[1], "two");
16 MOS_TEST_CHECK_STRING(cmdlines[2], "three");
17 MOS_TEST_CHECK_STRING(cmdlines[3], "four");
18 MOS_TEST_CHECK_STRING(cmdlines[4], "five");
19 MOS_TEST_CHECK_STRING(cmdlines[5], "six");
20 MOS_TEST_CHECK_STRING(cmdlines[6], "seven");
21 MOS_TEST_CHECK_STRING(cmdlines[7], "eight");
22 MOS_TEST_CHECK_STRING(cmdlines[8], "nine");
23 MOS_TEST_CHECK_STRING(cmdlines[9], "ten");
24 MOS_TEST_CHECK(cmdlines[10], NULL);
25}
26
28{
29 char cmdline[256] = "one=nana";
30 const char *cmdlines[2] = { 0 };
31 size_t cmdlines_count = 0;
32 cmdline_parse_inplace(cmdline, strlen(cmdline), 1, &cmdlines_count, cmdlines);
33 MOS_TEST_CHECK(cmdlines_count, 1);
34 MOS_TEST_CHECK_STRING(cmdlines[0], "one=nana");
35 MOS_TEST_CHECK(cmdlines[1], NULL);
36}
37
39{
40 char cmdline[256] = "one=nana1,nana2,nana3,nana4,false";
41 const char *cmdlines[2] = { 0 };
42 size_t cmdlines_count = 0;
43 cmdline_parse_inplace(cmdline, strlen(cmdline), 1, &cmdlines_count, cmdlines);
44 MOS_TEST_CHECK(cmdlines_count, 1);
45 MOS_TEST_CHECK_STRING(cmdlines[0], "one=nana1,nana2,nana3,nana4,false");
46 MOS_TEST_CHECK(cmdlines[1], NULL);
47}
48
50{
51 char cmdline[256] = "one=nana1,nana2,nana3,nana4,false two=nana1,nana2,nana3,nana4,false three=nana1,nana2,nana3,nana4,true";
52 const char *cmdlines[4] = { 0 };
53 size_t cmdlines_count = 0;
54 cmdline_parse_inplace(cmdline, strlen(cmdline), 3, &cmdlines_count, cmdlines);
55 MOS_TEST_CHECK(cmdlines_count, 3);
56 MOS_TEST_CHECK_STRING(cmdlines[0], "one=nana1,nana2,nana3,nana4,false");
57 MOS_TEST_CHECK_STRING(cmdlines[1], "two=nana1,nana2,nana3,nana4,false");
58 MOS_TEST_CHECK_STRING(cmdlines[2], "three=nana1,nana2,nana3,nana4,true");
59 MOS_TEST_CHECK(cmdlines[3], NULL);
60}
61
63{
64 char cmdline[256] = "one=\"nana1,nana2,nana3,nana4,false\" two=\"nana1,nana2,nana3,nana4,false\" three=\"nana1,nana2,nana3,nana4,true\"";
65 const char *cmdlines[4] = { 0 };
66 size_t cmdlines_count = 0;
67 cmdline_parse_inplace(cmdline, strlen(cmdline), 3, &cmdlines_count, cmdlines);
68 MOS_TEST_CHECK(cmdlines_count, 3);
69 MOS_TEST_CHECK_STRING(cmdlines[0], "one=\"nana1,nana2,nana3,nana4,false\"");
70 MOS_TEST_CHECK_STRING(cmdlines[1], "two=\"nana1,nana2,nana3,nana4,false\"");
71 MOS_TEST_CHECK_STRING(cmdlines[2], "three=\"nana1,nana2,nana3,nana4,true\"");
72 MOS_TEST_CHECK(cmdlines[3], NULL);
73}
74
76{
77 char cmdline[256] = "one=\"nana1 nana2 nana3 nana4 false\" two=\"nana1 nana2 nana3 nana4 false\" three=\"nana1 nana2 nana3 nana4 true\"";
78 const char *cmdlines[4] = { 0 };
79 size_t cmdlines_count = 0;
80 cmdline_parse_inplace(cmdline, strlen(cmdline), 3, &cmdlines_count, cmdlines);
81 MOS_TEST_CHECK(cmdlines_count, 3);
82 MOS_TEST_CHECK_STRING(cmdlines[0], "one=\"nana1 nana2 nana3 nana4 false\"");
83 MOS_TEST_CHECK_STRING(cmdlines[1], "two=\"nana1 nana2 nana3 nana4 false\"");
84 MOS_TEST_CHECK_STRING(cmdlines[2], "three=\"nana1 nana2 nana3 nana4 true\"");
85 MOS_TEST_CHECK(cmdlines[3], NULL);
86}
87
89{
90 char cmdline[256] = "one=\"nana1 nana2,nana3 nana4 false\" two=\"nana1 nana2,nana3 nana4 false\" three=\"nana1 nana2,nana3 nana4 true\"";
91 const char *cmdlines[4] = { 0 };
92 size_t cmdlines_count = 0;
93 cmdline_parse_inplace(cmdline, strlen(cmdline), 3, &cmdlines_count, cmdlines);
94 MOS_TEST_CHECK(cmdlines_count, 3);
95 MOS_TEST_CHECK_STRING(cmdlines[0], "one=\"nana1 nana2,nana3 nana4 false\"");
96 MOS_TEST_CHECK_STRING(cmdlines[1], "two=\"nana1 nana2,nana3 nana4 false\"");
97 MOS_TEST_CHECK_STRING(cmdlines[2], "three=\"nana1 nana2,nana3 nana4 true\"");
98 MOS_TEST_CHECK(cmdlines[3], NULL);
99}
100
102{
103 char cmdline[256] = "one=\"nana1=nana2,nana3=nana4 false\" two=\"nana1=nana2,nana3=nana4 false\" three=\"nana1=nana2,nana3=nana4 true\"";
104 const char *cmdlines[4] = { 0 };
105 size_t cmdlines_count = 0;
106 cmdline_parse_inplace(cmdline, strlen(cmdline), 3, &cmdlines_count, cmdlines);
107 MOS_TEST_CHECK(cmdlines_count, 3);
108 MOS_TEST_CHECK_STRING(cmdlines[0], "one=\"nana1=nana2,nana3=nana4 false\"");
109 MOS_TEST_CHECK_STRING(cmdlines[1], "two=\"nana1=nana2,nana3=nana4 false\"");
110 MOS_TEST_CHECK_STRING(cmdlines[2], "three=\"nana1=nana2,nana3=nana4 true\"");
111 MOS_TEST_CHECK(cmdlines[3], NULL);
112}
113
115{
116 char cmdline[256] =
117 "one=\"nana1=\\\"nana2\\\",nana3=\\\"nana4\\\" false\" two=\"nana1=\\\"nana2\\\",nana3=\\\"nana4\\\" false\" three=\"nana1=\\\"nana2\\\",nana3=\\\"nana4\\\" true\"";
118 const char *cmdlines[4] = { 0 };
119 size_t cmdlines_count = 0;
120 cmdline_parse_inplace(cmdline, strlen(cmdline), 3, &cmdlines_count, cmdlines);
121 MOS_TEST_CHECK(cmdlines_count, 3);
122 MOS_TEST_CHECK_STRING(cmdlines[0], "one=\"nana1=\\\"nana2\\\",nana3=\\\"nana4\\\" false\"");
123 MOS_TEST_CHECK_STRING(cmdlines[1], "two=\"nana1=\\\"nana2\\\",nana3=\\\"nana4\\\" false\"");
124 MOS_TEST_CHECK_STRING(cmdlines[2], "three=\"nana1=\\\"nana2\\\",nana3=\\\"nana4\\\" true\"");
125 MOS_TEST_CHECK(cmdlines[3], NULL);
126}
bool cmdline_parse_inplace(char *inbuf, size_t length, size_t cmdline_max, size_t *cmdlines_count, const char **cmdlines)
Definition cmdline.c:93
#define NULL
Definition pb_syshdr.h:46
static size_t strlen(const char *s)
Definition pb_syshdr.h:80
static void one_arg_with_an_option(mos_test_result_t *, bool *, bool *)
static void quoted_args_with_spaces_and_commas_and_equals(mos_test_result_t *, bool *, bool *)
static void quoted_args_with_spaces(mos_test_result_t *, bool *, bool *)
static void quoted_args_with_spaces_and_commas(mos_test_result_t *, bool *, bool *)
static void simple_cmdline(mos_test_result_t *, bool *, bool *)
static void quotation_with_escaped_quotation_marks(mos_test_result_t *, bool *, bool *)
static void one_arg_with_multiple_options(mos_test_result_t *, bool *, bool *)
static void quoted_args(mos_test_result_t *, bool *, bool *)
static void multi_args_with_multiple_options(mos_test_result_t *, bool *, bool *)
#define MOS_TEST_CHECK(actual, expected)
#define MOS_TEST_CHECK_STRING(actual, expected)
#define MOS_TEST_CASE(_TestName)