Go to the documentation of this file.
18 #define PATH1 "/s p a c e"
19 #define PATH2 "/foo bar/baz"
20 #define PARAM1 "param1"
21 #define PARAM2 "param two"
22 #define SCRIPT_CMD "\"" PATH1 PATH2 "\"" PARAM1 "\"" PARAM2 "\""
26 const int line_num,
int msglevel,
struct gc_arena *gc)
40 assert_int_equal(a.
argc, 3);
52 assert_int_equal(a.
argc, 3);
63 assert_int_equal(a.
argc, 1);
64 assert_string_equal(a.
argv[0],
"<p1:" PATH1 ">");
74 assert_false(
argv_printf(&a,
"tool --do %s",
"this\035--harmful"));
75 assert_int_equal(a.
argc, 0);
86 assert_int_equal(a.
argc, 1);
89 assert_int_equal(a.
argc, 2);
92 assert_int_equal(a.
argc, 5);
103 assert_int_equal(a.
argc, 1);
106 assert_int_equal(a.
argc, 2);
109 assert_int_equal(a.
argc, 3);
112 assert_int_equal(a.
argc, 4);
115 assert_int_equal(a.
argc, 2);
125 const char *args[] = {
126 "good_tools_have_good_names_even_though_it_might_impair_typing",
127 "--long-opt=looooooooooooooooooooooooooooooooooooooooooooooooong",
128 "--long-cat=loooooooooooooooooooooooooooooooooooooooooooooooooooonger",
129 "file_with_very_descriptive_filename_that_leaves_no_questions_open.jpg.exe"
132 argv_printf(&a,
"%s %s %s %s", args[0], args[1], args[2], args[3]);
133 assert_int_equal(a.
argc, 4);
134 for (i = 0; i < a.
argc; i++)
136 assert_string_equal(a.
argv[i], args[i]);
148 assert_int_equal(a.
argc, 3);
160 assert_int_equal(a.
argc, 7);
173 assert_int_equal(a.
argc, 5);
186 assert_string_equal(output,
"");
207 " [-1] [4294967295] [1]");
220 assert_int_equal(b.argc, 1);
221 assert_string_equal(b.argv[0],
PATH1);
236 assert_int_equal(b.
argc, a.
argc + 1);
237 for (i = 0; i < b.
argc; i++)
245 assert_string_equal(b.
argv[i], a.
argv[i - 1]);
257 const struct CMUnitTest tests[] = {
274 return cmocka_run_group_tests_name(
"argv", tests, NULL, NULL);
static void argv_parse_cmd__command_string__argc_correct(void **state)
static void argv_printf__empty_parameter__argc_correct(void **state)
static struct gc_arena gc_new(void)
static void argv_parse_cmd__command_and_extra_options__argc_correct(void **state)
static void argv_printf__long_args__data_correct(void **state)
bool argv_printf_cat(struct argv *argres, const char *format,...)
printf() inspired argv concatenation.
void argv_free(struct argv *a)
Frees all memory allocations allocated by the struct argv related functions.
void argv_parse_cmd(struct argv *argres, const char *cmdstr)
Parses a command string, tokenizes it and puts each element into a separate struct argv argument slot...
static void argv_printf_cat__used_twice__argc_correct(void **state)
static void argv_printf__combined_path_with_spaces__argc_correct(void **state)
int __wrap_parse_line(const char *line, char **p, const int n, const char *file, const int line_num, int msglevel, struct gc_arena *gc)
struct argv argv_insert_head(const struct argv *a, const char *head)
Inserts an argument string in front of all other argument slots.
static void argv_insert_head__non_empty_argv__head_added(void **state)
static void argv_printf__group_sep_in_arg__fail_no_ouput(void **state)
const char * argv_str(const struct argv *a, struct gc_arena *gc, const unsigned int flags)
Generate a single string with all the arguments in a struct argv concatenated.
static void argv_str__multiple_argv__correct_output(void **state)
Garbage collection arena used to keep track of dynamically allocated memory.
static void argv_printf__embedded_format_directive__replaced_in_output(void **state)
static void argv_printf_cat__multiple_spaces_in_format__parsed_as_one(void **state)
static void openvpn_unit_test_setup(void)
Sets up the environment for unit tests like making both stderr and stdout non-buffered to avoid messa...
struct argv argv_new(void)
Allocates a new struct argv and ensures it is initialised.
bool argv_printf(struct argv *argres, const char *format,...)
printf() variant which populates a struct argv.
static void gc_free(struct gc_arena *a)
static void argv_printf__multiple_spaces_in_format__parsed_as_one(void **state)
static void argv_insert_head__empty_argv__head_only(void **state)
static void argv_str__empty_argv__empty_output(void **state)