"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/parseargs_tests.c" between
vnstat-2.7.tar.gz and vnstat-2.8.tar.gz

About: vnStat is a console-based network traffic monitor (using the /proc filesystem).

parseargs_tests.c  (vnstat-2.7):parseargs_tests.c  (vnstat-2.8)
skipping to change at line 79 skipping to change at line 79
{ {
PARAMS p; PARAMS p;
char *argv[] = {"vnstat", "--debug", "--traffic", "12", "--add", "--renam e", "aname", "--config", char *argv[] = {"vnstat", "--debug", "--traffic", "12", "--add", "--renam e", "aname", "--config",
"does_nothing", "-l", "1", "--remove", "- i", "ethsomething", "--style", "0", "--dbdir", "does_nothing", "-l", "1", "--remove", "- i", "ethsomething", "--style", "0", "--dbdir",
"dbsomewhere", "-q", "-d", "1", "-m", "2" , "-t", "3", "-s", "-y", "4", "-hg", "-h", "5", "-5", "6", "dbsomewhere", "-q", "-d", "1", "-m", "2" , "-t", "3", "-s", "-y", "4", "-hg", "-h", "5", "-5", "6",
"--oneline", "b", "--xml", "h", "7", "--j son", "d", "7", "-ru", "--rateunit", "0", "--oneline", "b", "--xml", "h", "7", "--j son", "d", "7", "-ru", "--rateunit", "0",
"--force", "--setalias", "super", "--begi n", "2000-01-01", "--force", "--setalias", "super", "--begi n", "2000-01-01",
"--end", "2001-01-01", NULL}; "--end", "2001-01-01", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1; int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p); initparams(&p);
suppress_output(); suppress_output();
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
ck_assert_str_eq(p.interface, "ethsomething"); ck_assert_str_eq(p.interface, "ethsomething");
ck_assert_int_eq(p.defaultiface, 0); ck_assert_int_eq(p.defaultiface, 0);
ck_assert_int_eq(cfg.ostyle, 4); ck_assert_int_eq(cfg.ostyle, 4);
ck_assert_str_eq(cfg.dbdir, "dbsomewhere"); ck_assert_str_eq(cfg.dbdir, "dbsomewhere");
ck_assert_int_eq(p.query, 1); ck_assert_int_eq(p.query, 1);
ck_assert_int_eq(p.force, 1); ck_assert_int_eq(p.force, 1);
skipping to change at line 515 skipping to change at line 514
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
} }
END_TEST END_TEST
START_TEST(vnstat_parseargs_limit_changes_defaults) START_TEST(vnstat_parseargs_limit_changes_defaults)
{ {
PARAMS p; PARAMS p;
char *argv[] = {"vnstat", "--limit", "1234", NULL}; char *argv[] = {"vnstat", "--limit", "1234", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1; int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p); initparams(&p);
suppress_output(); suppress_output();
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
ck_assert_int_eq(cfg.listfivemins, 1234); ck_assert_int_eq(cfg.listfivemins, 1234);
ck_assert_int_eq(cfg.listhours, 1234); ck_assert_int_eq(cfg.listhours, 1234);
ck_assert_int_eq(cfg.listdays, 1234); ck_assert_int_eq(cfg.listdays, 1234);
ck_assert_int_eq(cfg.listmonths, 1234); ck_assert_int_eq(cfg.listmonths, 1234);
ck_assert_int_eq(cfg.listyears, 1234); ck_assert_int_eq(cfg.listyears, 1234);
ck_assert_int_eq(cfg.listtop, 1234); ck_assert_int_eq(cfg.listtop, 1234);
ck_assert_int_eq(cfg.listjsonxml, 1234); ck_assert_int_eq(cfg.listjsonxml, 1234);
} }
END_TEST END_TEST
START_TEST(vnstat_parseargs_limit_overrides) START_TEST(vnstat_parseargs_limit_overrides)
{ {
PARAMS p; PARAMS p;
char *argv[] = {"vnstat", "-d", "5", "--limit", "234", NULL}; char *argv[] = {"vnstat", "-d", "5", "--limit", "234", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1; int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p); initparams(&p);
suppress_output(); suppress_output();
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
ck_assert_int_eq(cfg.listfivemins, 234); ck_assert_int_eq(cfg.listfivemins, 234);
ck_assert_int_eq(cfg.listhours, 234); ck_assert_int_eq(cfg.listhours, 234);
ck_assert_int_eq(cfg.listdays, 234); ck_assert_int_eq(cfg.listdays, 234);
ck_assert_int_eq(cfg.listmonths, 234); ck_assert_int_eq(cfg.listmonths, 234);
ck_assert_int_eq(cfg.listyears, 234); ck_assert_int_eq(cfg.listyears, 234);
ck_assert_int_eq(cfg.listtop, 234); ck_assert_int_eq(cfg.listtop, 234);
ck_assert_int_eq(cfg.listjsonxml, 234); ck_assert_int_eq(cfg.listjsonxml, 234);
} }
END_TEST END_TEST
START_TEST(vnstat_parseargs_limit_overrides_regardless_of_position) START_TEST(vnstat_parseargs_limit_overrides_regardless_of_position)
{ {
PARAMS p; PARAMS p;
char *argv[] = {"vnstat", "--limit", "345", "-d", "5", NULL}; char *argv[] = {"vnstat", "--limit", "345", "-d", "5", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1; int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p); initparams(&p);
suppress_output(); suppress_output();
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
ck_assert_int_eq(cfg.listfivemins, 345); ck_assert_int_eq(cfg.listfivemins, 345);
ck_assert_int_eq(cfg.listhours, 345); ck_assert_int_eq(cfg.listhours, 345);
ck_assert_int_eq(cfg.listdays, 345); ck_assert_int_eq(cfg.listdays, 345);
ck_assert_int_eq(cfg.listmonths, 345); ck_assert_int_eq(cfg.listmonths, 345);
ck_assert_int_eq(cfg.listyears, 345); ck_assert_int_eq(cfg.listyears, 345);
ck_assert_int_eq(cfg.listtop, 345); ck_assert_int_eq(cfg.listtop, 345);
ck_assert_int_eq(cfg.listjsonxml, 345); ck_assert_int_eq(cfg.listjsonxml, 345);
} }
END_TEST END_TEST
START_TEST(vnstat_parseargs_iflist_gives_help) START_TEST(vnstat_parseargs_iflist_gives_help)
{ {
PARAMS p; PARAMS p;
char *argv[] = {"vnstat", "--iflist", "notknown", NULL}; char *argv[] = {"vnstat", "--iflist", "--help", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1; int argc = sizeof(argv) / sizeof(char *) - 1;
initparams(&p); initparams(&p);
suppress_output(); suppress_output();
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
} }
END_TEST END_TEST
START_TEST(vnstat_parseargs_iflist_without_parameters_and_no_interfaces) START_TEST(vnstat_parseargs_iflist_without_parameters_and_no_interfaces)
{ {
skipping to change at line 756 skipping to change at line 752
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("ethnothing"); ret = db_addinterface("ethnothing");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
suppress_output(); suppress_output();
parseargs(&p, argc, argv); parseargs(&p, argc, argv);
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(vnstat_parseargs_can_select_interface_without_parameter)
{
PARAMS p;
char *argv[] = {"vnstat", "ethsomething", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p);
suppress_output();
parseargs(&p, argc, argv);
ck_assert_str_eq(p.interface, "ethsomething");
ck_assert_int_eq(p.defaultiface, 0);
}
END_TEST
START_TEST(vnstat_parseargs_can_select_interface_without_parameter_even_if_there
_are_other_parameters)
{
PARAMS p;
char *argv[] = {"vnstat", "-d", "ethsomethingtoo", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p);
suppress_output();
ck_assert_int_ne(cfg.qmode, 1);
parseargs(&p, argc, argv);
ck_assert_str_eq(p.interface, "ethsomethingtoo");
ck_assert_int_eq(p.defaultiface, 0);
ck_assert_int_eq(cfg.qmode, 1);
}
END_TEST
START_TEST(vnstat_parseargs_can_select_interface_without_parameter_from_the_midd
le_of_the_parameter_list)
{
PARAMS p;
char *argv[] = {"vnstat", "-m", "ethsomethings", "-ru", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p);
suppress_output();
debug = 1;
ck_assert_int_ne(cfg.qmode, 2);
parseargs(&p, argc, argv);
ck_assert_str_eq(p.interface, "ethsomethings");
ck_assert_int_eq(p.defaultiface, 0);
ck_assert_int_eq(cfg.qmode, 2);
}
END_TEST
START_TEST(vnstat_parseargs_knows_when_interface_name_is_too_long_even_without_p
arameter)
{
PARAMS p;
char *argv[] = {"vnstat", "ethethethethethethethethethetheth", NULL};
int argc = sizeof(argv) / sizeof(char *) - 1;
defaultcfg();
initparams(&p);
suppress_output();
parseargs(&p, argc, argv);
ck_assert_int_eq(p.defaultiface, 1);
}
END_TEST
void add_parseargs_tests(Suite *s) void add_parseargs_tests(Suite *s)
{ {
TCase *tc_pa = tcase_create("ParseArgs"); TCase *tc_pa = tcase_create("ParseArgs");
tcase_add_checked_fixture(tc_pa, setup, teardown); tcase_add_checked_fixture(tc_pa, setup, teardown);
tcase_add_unchecked_fixture(tc_pa, setup, teardown); tcase_add_unchecked_fixture(tc_pa, setup, teardown);
tcase_add_test(tc_pa, vnstat_parseargs_does_nothing_without_args); tcase_add_test(tc_pa, vnstat_parseargs_does_nothing_without_args);
tcase_add_exit_test(tc_pa, vnstat_parseargs_can_help, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_help, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_can_longhelp, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_longhelp, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_can_show_version, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_can_show_version, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_detects_unknown_parameters, 1 ); tcase_add_exit_test(tc_pa, vnstat_parseargs_detects_unknown_parameters, 1 );
skipping to change at line 812 skipping to change at line 872
tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters_and _only_lo, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters_and _only_lo, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters, 0) ; tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_without_parameters, 0) ;
tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_with_verbose_mode, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_with_verbose_mode, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_with_parseable_mode, 0 ); tcase_add_exit_test(tc_pa, vnstat_parseargs_iflist_with_parseable_mode, 0 );
tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_gives_help, 1); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_gives_help, 1);
tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_no_database, 1) ; tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_no_database, 1) ;
tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_without_parameters_a nd_no_interfaces, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_without_parameters_a nd_no_interfaces, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_without_parameters, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_without_parameters, 0);
tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_verbose_mode, 0 ); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_verbose_mode, 0 );
tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_parseable_mode, 0); tcase_add_exit_test(tc_pa, vnstat_parseargs_dbiflist_with_parseable_mode, 0);
tcase_add_test(tc_pa, vnstat_parseargs_can_select_interface_without_param
eter);
tcase_add_test(tc_pa, vnstat_parseargs_can_select_interface_without_param
eter_even_if_there_are_other_parameters);
tcase_add_test(tc_pa, vnstat_parseargs_can_select_interface_without_param
eter_from_the_middle_of_the_parameter_list);
tcase_add_exit_test(tc_pa, vnstat_parseargs_knows_when_interface_name_is_
too_long_even_without_parameter, 1);
suite_add_tcase(s, tc_pa); suite_add_tcase(s, tc_pa);
} }
 End of changes. 7 change blocks. 
5 lines changed or deleted 76 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)