libamxrt  0.4.2
Ambiorix Run Time Library
test_amxrt_args.h File Reference
#include <amxrt/amxrt.h>

Go to the source code of this file.

Functions

int test_args_setup (UNUSED void **state)
 
int test_args_teardown (UNUSED void **state)
 
void test_can_print_help (UNUSED void **state)
 
void test_can_print_extended_help (UNUSED void **state)
 
void test_can_add_include_dir (UNUSED void **state)
 
void test_can_add_import_dir (UNUSED void **state)
 
void test_can_add_backend (UNUSED void **state)
 
void test_can_add_uri (UNUSED void **state)
 
void test_can_accept_option (UNUSED void **state)
 
void test_can_overwrite_option (UNUSED void **state)
 
void test_ignores_invalid_options (UNUSED void **state)
 
void test_can_disable_auto_detect (UNUSED void **state)
 
void test_can_disable_auto_connect (UNUSED void **state)
 
void test_can_enable_daemonize (UNUSED void **state)
 
void test_can_enable_eventing (UNUSED void **state)
 
void test_can_enable_dump_config (UNUSED void **state)
 
void test_can_set_nice_level (UNUSED void **state)
 
void test_can_disable_pid_file_creation (UNUSED void **state)
 
void test_can_pass_odl_string (UNUSED void **state)
 
void test_can_enable_syslog (UNUSED void **state)
 
void test_can_add_required_objects (UNUSED void **state)
 
void test_can_add_forced_option (UNUSED void **state)
 
void test_can_add_custom_options (UNUSED void **state)
 
void test_cmd_line_parse_fails_after_reset (UNUSED void **state)
 
void test_can_set_usage_doc (UNUSED void **state)
 

Function Documentation

◆ test_args_setup()

int test_args_setup ( UNUSED void **  state)

Definition at line 62 of file test_amxrt_args.c.

62  {
63  amxrt_new();
64  return 0;
65 }
void amxrt_new(void)
Create the ambiorix runtime.
Definition: amxrt.c:313

◆ test_args_teardown()

int test_args_teardown ( UNUSED void **  state)

Definition at line 67 of file test_amxrt_args.c.

67  {
68  amxrt_delete();
69  return 0;
70 }
void amxrt_delete(void)
Clean-up ambiorix runtime.
Definition: amxrt.c:378

◆ test_can_accept_option()

void test_can_accept_option ( UNUSED void **  state)

Definition at line 168 of file test_amxrt_args.c.

168  {
169  char* argv[] = {"amxrt", "-o option=new_option", "-o", "text=hallo"};
170  amxc_var_t* config = amxrt_get_config();
171 
172  assert_null(GET_ARG(config, "option"));
173  assert_null(GET_ARG(config, "text"));
174 
175  optind = 1;
176  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
177 
178  assert_non_null(GET_ARG(config, "option"));
179  assert_non_null(GET_ARG(config, "text"));
180 
181  assert_string_equal(GET_CHAR(config, "option"), "new_option");
182  assert_string_equal(GET_CHAR(config, "text"), "hallo");
183 }
int amxrt_cmd_line_parse(int argc, char *argv[], amxrt_arg_fn_t fn)
Starts parsing the command line options.
Definition: amxrt_args.c:236
amxc_var_t * amxrt_get_config(void)
Gets the htable variant containing the configuration options.
Definition: amxrt.c:301
config
Definition: test.odl:54

◆ test_can_add_backend()

void test_can_add_backend ( UNUSED void **  state)

Definition at line 128 of file test_amxrt_args.c.

128  {
129  char* argv[] = { "amxrt", "-B", "/usr/bin/mods/amx/mod_amxb_test.so", "-B", "/usr/bin/mods/amx/mod_amxb_dummy.so" };
130  amxc_var_t* config = amxrt_get_config();
131  amxc_var_t* option = GET_ARG(config, AMXRT_COPT_BACKENDS);
132  const char* include_dirs[] = {
133  "/usr/bin/mods/amx/mod_amxb_test.so", "/usr/bin/mods/amx/mod_amxb_dummy.so"
134  };
135  int index = 0;
136 
137  assert_non_null(option);
138 
139  optind = 1;
140  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
141 
142  amxc_var_for_each(var, option) {
143  assert_string_equal(GET_CHAR(var, NULL), include_dirs[index]);
144  index++;
145  }
146 }
#define AMXRT_COPT_BACKENDS
Definition: amxrt.h:75

◆ test_can_add_custom_options()

void test_can_add_custom_options ( UNUSED void **  state)

Definition at line 354 of file test_amxrt_args.c.

354  {
355  char* argv1[] = {"amxrt", "-z"};
356 
357  amxrt_cmd_line_add_option(0, 'z', "zulu", no_argument, "testing", NULL);
358 
359  optind = 1;
360  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv1) / sizeof(argv1[0]), argv1, test_args), sizeof(argv1) / sizeof(argv1[0]));
361 }
int amxrt_cmd_line_add_option(int id, char short_option, const char *long_option, int has_args, const char *doc, const char *arg_doc)
Adds a command line option definition.
Definition: amxrt_args.c:206
static int test_args(UNUSED amxc_var_t *config, int arg_id, UNUSED const char *value)

◆ test_can_add_forced_option()

void test_can_add_forced_option ( UNUSED void **  state)

Definition at line 340 of file test_amxrt_args.c.

340  {
341 
342 }

◆ test_can_add_import_dir()

void test_can_add_import_dir ( UNUSED void **  state)

Definition at line 108 of file test_amxrt_args.c.

108  {
109  char* argv[] = { "amxrt", "-L", "/tmp/include/", "-L", "/etc/odl/" };
110  amxc_var_t* config = amxrt_get_config();
111  amxc_var_t* option = GET_ARG(config, AMXRT_COPT_LIBDIRS);
112  const char* include_dirs[] = {
113  ".", "/tmp/include/", "/etc/odl/"
114  };
115  int index = 0;
116 
117  assert_non_null(option);
118 
119  optind = 1;
120  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
121 
122  amxc_var_for_each(var, option) {
123  assert_string_equal(GET_CHAR(var, NULL), include_dirs[index]);
124  index++;
125  }
126 }
#define AMXRT_COPT_LIBDIRS
Definition: amxrt.h:79

◆ test_can_add_include_dir()

void test_can_add_include_dir ( UNUSED void **  state)

Definition at line 88 of file test_amxrt_args.c.

88  {
89  char* argv[] = { "amxrt", "-I", "/tmp/include/", "-I", "/etc/odl/" };
90  amxc_var_t* config = amxrt_get_config();
91  amxc_var_t* option = GET_ARG(config, AMXRT_COPT_INCDIRS);
92  const char* include_dirs[] = {
93  ".", "/tmp/include/", "/etc/odl/"
94  };
95  int index = 0;
96 
97  assert_non_null(option);
98 
99  optind = 1;
100  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
101 
102  amxc_var_for_each(var, option) {
103  assert_string_equal(GET_CHAR(var, NULL), include_dirs[index]);
104  index++;
105  }
106 }
#define AMXRT_COPT_INCDIRS
Definition: amxrt.h:78

◆ test_can_add_required_objects()

void test_can_add_required_objects ( UNUSED void **  state)

Definition at line 319 of file test_amxrt_args.c.

319  {
320  char* argv[] = { "amxrt", "-R", "NetModel.", "-R", "NetDev." };
321  amxc_var_t* config = amxrt_get_config();
322  amxc_var_t* option = GET_ARG(config, AMXRT_COPT_REQUIRES);
323  const char* include_dirs[] = {
324  "NetModel.", "NetDev."
325  };
326  int index = 0;
327 
328  assert_non_null(option);
329 
330  optind = 1;
331  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
332 
333  amxc_var_for_each(var, option) {
334  assert_string_equal(GET_CHAR(var, NULL), include_dirs[index]);
335  index++;
336  }
337 
338 }
#define AMXRT_COPT_REQUIRES
Definition: amxrt.h:99

◆ test_can_add_uri()

void test_can_add_uri ( UNUSED void **  state)

Definition at line 148 of file test_amxrt_args.c.

148  {
149  char* argv[] = { "amxrt", "-u", "dummy:/var/run/dummy.sock", "-u", "dummy:/var/run/ubus.sock" };
150  amxc_var_t* config = amxrt_get_config();
151  amxc_var_t* option = GET_ARG(config, AMXRT_COPT_URIS);
152  const char* include_dirs[] = {
153  "dummy:/var/run/dummy.sock", "dummy:/var/run/ubus.sock"
154  };
155  int index = 0;
156 
157  assert_non_null(option);
158 
159  optind = 1;
160  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
161 
162  amxc_var_for_each(var, option) {
163  assert_string_equal(GET_CHAR(var, NULL), include_dirs[index]);
164  index++;
165  }
166 }
#define AMXRT_COPT_URIS
Definition: amxrt.h:73

◆ test_can_disable_auto_connect()

void test_can_disable_auto_connect ( UNUSED void **  state)

Definition at line 223 of file test_amxrt_args.c.

223  {
224  char* argv[] = {"amxrt", "-C"};
225  amxc_var_t* config = amxrt_get_config();
226 
227  assert_non_null(GET_ARG(config, AMXRT_COPT_AUTO_CONNECT));
228  assert_true(GET_BOOL(config, AMXRT_COPT_AUTO_CONNECT));
229 
230  optind = 1;
231  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
232  assert_false(GET_BOOL(config, AMXRT_COPT_AUTO_CONNECT));
233 }
#define AMXRT_COPT_AUTO_CONNECT
Definition: amxrt.h:77

◆ test_can_disable_auto_detect()

void test_can_disable_auto_detect ( UNUSED void **  state)

Definition at line 211 of file test_amxrt_args.c.

211  {
212  char* argv[] = {"amxrt", "-A"};
213  amxc_var_t* config = amxrt_get_config();
214 
215  assert_non_null(GET_ARG(config, AMXRT_COPT_AUTO_DETECT));
216  assert_true(GET_BOOL(config, AMXRT_COPT_AUTO_DETECT));
217 
218  optind = 1;
219  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
220  assert_false(GET_BOOL(config, AMXRT_COPT_AUTO_DETECT));
221 }
#define AMXRT_COPT_AUTO_DETECT
Definition: amxrt.h:76

◆ test_can_disable_pid_file_creation()

void test_can_disable_pid_file_creation ( UNUSED void **  state)

Definition at line 283 of file test_amxrt_args.c.

283  {
284  char* argv[] = {"amxrt", "-N"};
285  amxc_var_t* config = amxrt_get_config();
286 
287  assert_non_null(GET_ARG(config, AMXRT_COPT_PID_FILE));
288  assert_true(GET_BOOL(config, AMXRT_COPT_PID_FILE));
289 
290  optind = 1;
291  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
292  assert_false(GET_BOOL(config, AMXRT_COPT_PID_FILE));
293 }
#define AMXRT_COPT_PID_FILE
Definition: amxrt.h:84

◆ test_can_enable_daemonize()

void test_can_enable_daemonize ( UNUSED void **  state)

Definition at line 235 of file test_amxrt_args.c.

235  {
236  char* argv[] = {"amxrt", "-D"};
237  amxc_var_t* config = amxrt_get_config();
238 
239  assert_non_null(GET_ARG(config, AMXRT_COPT_DAEMON));
240  assert_false(GET_BOOL(config, AMXRT_COPT_DAEMON));
241 
242  optind = 1;
243  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
244  assert_true(GET_BOOL(config, AMXRT_COPT_DAEMON));
245 }
#define AMXRT_COPT_DAEMON
Definition: amxrt.h:82

◆ test_can_enable_dump_config()

void test_can_enable_dump_config ( UNUSED void **  state)

Definition at line 259 of file test_amxrt_args.c.

259  {
260  char* argv[] = {"amxrt", "-d"};
261  amxc_var_t* config = amxrt_get_config();
262 
263  assert_non_null(GET_ARG(config, AMXRT_COPT_DUMP_CONFIG));
264  assert_false(GET_BOOL(config, AMXRT_COPT_DUMP_CONFIG));
265 
266  optind = 1;
267  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
268  assert_true(GET_BOOL(config, AMXRT_COPT_DUMP_CONFIG));
269 }
#define AMXRT_COPT_DUMP_CONFIG
Definition: amxrt.h:91

◆ test_can_enable_eventing()

void test_can_enable_eventing ( UNUSED void **  state)

Definition at line 247 of file test_amxrt_args.c.

247  {
248  char* argv[] = {"amxrt", "-E"};
249  amxc_var_t* config = amxrt_get_config();
250 
251  assert_non_null(GET_ARG(config, AMXRT_COPT_EVENT));
252  assert_false(GET_BOOL(config, AMXRT_COPT_EVENT));
253 
254  optind = 1;
255  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
256  assert_true(GET_BOOL(config, AMXRT_COPT_EVENT));
257 }
#define AMXRT_COPT_EVENT
Definition: amxrt.h:90

◆ test_can_enable_syslog()

void test_can_enable_syslog ( UNUSED void **  state)

Definition at line 307 of file test_amxrt_args.c.

307  {
308  char* argv[] = {"amxrt", "-l"};
309  amxc_var_t* config = amxrt_get_config();
310 
311  assert_non_null(GET_ARG(config, AMXRT_COPT_LOG));
312  assert_false(GET_BOOL(config, AMXRT_COPT_LOG));
313 
314  optind = 1;
315  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
316  assert_true(GET_BOOL(config, AMXRT_COPT_LOG));
317 }
#define AMXRT_COPT_LOG
Definition: amxrt.h:98

◆ test_can_overwrite_option()

void test_can_overwrite_option ( UNUSED void **  state)

Definition at line 185 of file test_amxrt_args.c.

185  {
186  char* argv[] = {"amxrt", "-o cfg-dir=my_cfg_dir", "-o", "daemon=no"};
187  amxc_var_t* config = amxrt_get_config();
188 
189  assert_non_null(GET_ARG(config, AMXRT_COPT_CFG_DIR));
190  assert_non_null(GET_ARG(config, AMXRT_COPT_DAEMON));
191 
192  optind = 1;
193  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
194  assert_string_equal(GET_CHAR(config, AMXRT_COPT_CFG_DIR), "my_cfg_dir");
195  assert_string_equal(GET_CHAR(config, AMXRT_COPT_DAEMON), "no");
196 }
#define AMXRT_COPT_CFG_DIR
Definition: amxrt.h:88

◆ test_can_pass_odl_string()

void test_can_pass_odl_string ( UNUSED void **  state)

Definition at line 295 of file test_amxrt_args.c.

295  {
296  char* argv[] = {"amxrt", "-O", "%%config { test = 123; }"};
297  amxc_var_t* config = amxrt_get_config();
298 
299  assert_null(GET_ARG(config, AMXRT_COPT_ODL));
300 
301  optind = 1;
302  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
303  assert_non_null(GET_ARG(config, AMXRT_COPT_ODL));
304  assert_string_equal(GET_CHAR(config, AMXRT_COPT_ODL), "%%config { test = 123; }");
305 }
#define AMXRT_COPT_ODL
Definition: amxrt.h:81

◆ test_can_print_extended_help()

void test_can_print_extended_help ( UNUSED void **  state)

Definition at line 81 of file test_amxrt_args.c.

81  {
82  char* argv[] = { "amxrt", "-H" };
83 
84  optind = 1;
85  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), -1);
86 }

◆ test_can_print_help()

void test_can_print_help ( UNUSED void **  state)

Definition at line 72 of file test_amxrt_args.c.

72  {
73  amxc_var_t* config = amxrt_get_config();
74  char* argv[] = { "amxrt", "-h" };
75 
76  amxc_var_add_key(cstring_t, config, "name", "amxrt");
77  optind = 1;
78  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), -1);
79 }

◆ test_can_set_nice_level()

void test_can_set_nice_level ( UNUSED void **  state)

Definition at line 271 of file test_amxrt_args.c.

271  {
272  char* argv[] = {"amxrt", "-p", "-5"};
273  amxc_var_t* config = amxrt_get_config();
274 
275  assert_non_null(GET_ARG(config, AMXRT_COPT_PRIORITY));
276  assert_int_equal(GET_INT32(config, AMXRT_COPT_PRIORITY), 0);
277 
278  optind = 1;
279  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv) / sizeof(argv[0]), argv, NULL), sizeof(argv) / sizeof(argv[0]));
280  assert_int_equal(GET_INT32(config, AMXRT_COPT_PRIORITY), -5);
281 }
#define AMXRT_COPT_PRIORITY
Definition: amxrt.h:83

◆ test_can_set_usage_doc()

void test_can_set_usage_doc ( UNUSED void **  state)

Definition at line 381 of file test_amxrt_args.c.

381  {
382  amxrt_cmd_line_set_usage_doc("Test usage");
386 }
void amxrt_cmd_line_set_usage_doc(const char *usage)
Set the overall usage documentation string.
Definition: amxrt_args.c:230
void amxrt_print_usage(void)
Prints the usage information and all available options to stdout.

◆ test_cmd_line_parse_fails_after_reset()

void test_cmd_line_parse_fails_after_reset ( UNUSED void **  state)

Definition at line 364 of file test_amxrt_args.c.

364  {
365  char* argv1[] = {"amxrt", "-z"};
366  char* argv2[] = {"amxrt", "-z", "-t"};
367 
369  amxrt_cmd_line_add_option(0, 'z', "zulu", no_argument, "testing", NULL);
370 
371  optind = 1;
372  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), -1);
373 
374  optind = 1;
375  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv1) / sizeof(argv1[0]), argv1, test_args), sizeof(argv1) / sizeof(argv1[0]));
376 
377  optind = 1;
378  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv2) / sizeof(argv2[0]), argv2, test_args), -1);
379 }
void amxrt_cmd_line_options_reset(void)
Removes all default options.
Definition: amxrt_args.c:200

◆ test_ignores_invalid_options()

void test_ignores_invalid_options ( UNUSED void **  state)

Definition at line 198 of file test_amxrt_args.c.

198  {
199  char* argv1[] = {"amxrt", "-o"};
200  char* argv2[] = {"amxrt", "-o option2"};
201  amxc_var_t* config = amxrt_get_config();
202 
203  optind = 1;
204  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv1) / sizeof(argv1[0]), argv1, NULL), -1);
205 
206  optind = 1;
207  assert_int_equal(amxrt_cmd_line_parse(sizeof(argv2) / sizeof(argv2[0]), argv2, NULL), sizeof(argv2) / sizeof(argv2[0]));
208  assert_null(GET_CHAR(config, "option2"));
209 }