diff --git a/tests/check_cmdline.c b/tests/check_cmdline.c index 7880fce..d7234c1 100644 --- a/tests/check_cmdline.c +++ b/tests/check_cmdline.c @@ -7,6 +7,13 @@ Suite * cmdline_suite(void); void setup_checked(void); void teardown_checked(void); +extern int optind; + +START_TEST(test_configfile) +{ +} +END_TEST + START_TEST(test_help) { char *argv[] = { "check_cmdline", "-h", NULL }; @@ -18,6 +25,87 @@ START_TEST(test_help) } END_TEST +START_TEST(test_quiet_stderr) +{ + char *argv[] = { "check_cmdline", "-q", NULL }; + int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1; + int ret; + + ck_assert_int_eq(cfg_get_program_quiet_stderr(), 0); + ck_assert_int_ne(cmdline_parse(argc, argv, &ret), 0); + ck_assert_int_eq(ret, 2); + ck_assert_int_ne(cfg_get_program_quiet_stderr(), 0); +} +END_TEST + +START_TEST(test_rtstatus_output) +{ + char *argv[] = { "check_cmdline", "-r", NULL }; + int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1; + int ret; + + ck_assert_int_eq(cfg_get_program_rtstatus_output(), 0); + ck_assert_int_eq(cfg_get_program_quiet_stderr(), 0); + ck_assert_int_ne(cmdline_parse(argc, argv, &ret), 0); + ck_assert_int_eq(ret, 2); + ck_assert_int_ne(cfg_get_program_rtstatus_output(), 0); + ck_assert_int_ne(cfg_get_program_quiet_stderr(), 0); +} +END_TEST + +START_TEST(test_shuffle) +{ +} +END_TEST + +START_TEST(test_version) +{ + char *argv[] = { "check_cmdline", "-V", NULL }; + int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1; + int ret; + + ck_assert_int_ne(cmdline_parse(argc, argv, &ret), 0); + ck_assert_int_eq(ret, 0); +} +END_TEST + +START_TEST(test_verbose) +{ + char *argv[] = { "check_cmdline", "-v", NULL }; + char *argv2[] = { "check_cmdline", "-v", "-v", NULL }; + char *argv3[] = { "check_cmdline", "-v", "-v", "-v", NULL }; + int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1; + int argc2 = (int)(sizeof(argv2) / sizeof(argv2[0])) - 1; + int argc3 = (int)(sizeof(argv3) / sizeof(argv3[0])) - 1; + int ret; + + ck_assert_uint_eq(cfg_get_program_verbosity(), 0); + ck_assert_int_ne(cmdline_parse(argc, argv, &ret), 0); + ck_assert_uint_eq(cfg_get_program_verbosity(), 1); + + optind = 1; + ck_assert_int_ne(cmdline_parse(argc2, argv2, &ret), 0); + ck_assert_uint_eq(cfg_get_program_verbosity(), 2); + + optind = 1; + ck_assert_int_ne(cmdline_parse(argc3, argv3, &ret), 0); + ck_assert_uint_eq(cfg_get_program_verbosity(), 3); + + ck_assert_int_eq(ret, 2); +} +END_TEST + +START_TEST(test_invalid) +{ + char *argv[] = { "check_cmdline", "-x", NULL }; + int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1; + int ret; + + ck_assert_int_ne(cmdline_parse(argc, argv, &ret), 0); + ck_assert_int_eq(ret, 2); +} +END_TEST + Suite * cmdline_suite(void) { @@ -28,7 +116,14 @@ cmdline_suite(void) tc_cmdline = tcase_create("CmdLine"); tcase_add_checked_fixture(tc_cmdline, setup_checked, teardown_checked); + tcase_add_test(tc_cmdline, test_configfile); tcase_add_test(tc_cmdline, test_help); + tcase_add_test(tc_cmdline, test_quiet_stderr); + tcase_add_test(tc_cmdline, test_rtstatus_output); + tcase_add_test(tc_cmdline, test_shuffle); + tcase_add_test(tc_cmdline, test_version); + tcase_add_test(tc_cmdline, test_verbose); + tcase_add_test(tc_cmdline, test_invalid); suite_add_tcase(s, tc_cmdline); return (s); @@ -39,6 +134,7 @@ setup_checked(void) { if (0 < cfg_init()) ck_abort_msg("setup_checked failed"); + optind = 1; } void