"Fossies" - the Fresh Open Source Software Archive  

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

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

cli_tests.c  (vnstat-2.8):cli_tests.c  (vnstat-2.9)
skipping to change at line 930 skipping to change at line 930
ret = db_settotal("ethfast", 80, 9001); ret = db_settotal("ethfast", 80, 9001);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
handleifselection(&p); handleifselection(&p);
/* first available interface is selected if none of the interfaces in dat abase are available */ /* first available interface is selected if none of the interfaces in dat abase are available */
ck_assert_str_eq(p.interface, "ethnone"); ck_assert_str_eq(p.interface, "ethnone");
} }
END_TEST END_TEST
START_TEST(showalerthelp_does_not_crash)
{
suppress_output();
showalerthelp();
}
END_TEST
START_TEST(parsealertargs_knows_which_parameters_belong_to_it)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "--days", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 0);
ck_assert_int_eq(p.alertexit, 0);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_helps_when_asked)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "--help", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 0);
ck_assert_int_eq(p.alertexit, 0);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_set_parameters)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
debug = 1;
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 3);
ck_assert_int_eq(p.alertlimit, 5120);
}
END_TEST
START_TEST(parsealertargs_can_validate_output)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "a", "2", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 0);
ck_assert_int_eq(p.alertexit, 0);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_output_range)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "4", "2", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 4);
ck_assert_int_eq(p.alertexit, 0);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_exit)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "b", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 0);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_exit_range)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "4", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 4);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_knows_first_useless_parameter_combination)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "0", "0", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 0);
ck_assert_int_eq(p.alertexit, 0);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_knows_second_useless_parameter_combination)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "0", "1", "y", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 0);
ck_assert_int_eq(p.alertexit, 1);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_type)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "a", "total", "5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 0);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_condition)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "y", "total_recall", "5", "KiB", NUL
L};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 0);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_knows_first_invalid_condition_combination)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "2", "3", "y", "rx_estimate", "5", "KiB", NULL
};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 2);
ck_assert_int_eq(p.alertexit, 3);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 4);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_knows_second_invalid_condition_combination)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "3", "2", "y", "tx_estimate", "5", "KiB", NULL
};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 3);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 5);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_limit_as_integer)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "y", "total", "5.5", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 3);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_limit_as_non_zero)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "y", "total", "0", "KiB", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 3);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_can_validate_limit_unit)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "y", "total", "5", "KeK", NULL};
defaultcfg();
initparams(&p);
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 3);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(parsealertargs_knows_the_64_bit_limit_regardless_of_used_unit)
{
int ret;
PARAMS p;
char *argv[] = {"--alert", "1", "2", "y", "total", "16", "EiB", NULL};
defaultcfg();
initparams(&p);
debug = 1;
suppress_output();
ret = parsealertargs(&p, argv);
ck_assert_int_eq(ret, 0);
ck_assert_int_eq(p.alertoutput, 1);
ck_assert_int_eq(p.alertexit, 2);
ck_assert_int_eq(p.alerttype, 4);
ck_assert_int_eq(p.alertcondition, 3);
ck_assert_int_eq(p.alertlimit, 0);
}
END_TEST
START_TEST(handleshowalert_requires_interface_to_be_specified)
{
PARAMS p;
defaultcfg();
initparams(&p);
suppress_output();
p.alert = 1;
p.defaultiface = 1;
handleshowalert(&p);
}
END_TEST
START_TEST(validateinterface_does_not_use_alias_if_interface_names_matches)
{
int ret;
PARAMS p;
defaultcfg();
initparams(&p);
strncpy_nt(p.interface, "eth0", 32);
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth0", "LAN");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth1");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth1", "eth0");
ck_assert_int_eq(ret, 1);
validateinterface(&p);
ck_assert_str_eq(p.interface, "eth0");
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(validateinterface_supports_interface_merges)
{
int ret;
PARAMS p;
defaultcfg();
initparams(&p);
strncpy_nt(p.interface, "eth0+eth1", 32);
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth0", "LAN");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth1");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth1", "Internet");
ck_assert_int_eq(ret, 1);
validateinterface(&p);
ck_assert_str_eq(p.interface, "eth0+eth1");
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(validateinterface_detects_if_not_all_interfaces_are_available_for_mer
ge)
{
int ret;
PARAMS p;
defaultcfg();
initparams(&p);
strncpy_nt(p.interface, "eth0+eth2", 32);
suppress_output();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth0", "LAN");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth1");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth1", "Internet");
ck_assert_int_eq(ret, 1);
validateinterface(&p);
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(validateinterface_detects_if_not_all_interfaces_are_unique_for_merge)
{
int ret;
PARAMS p;
defaultcfg();
initparams(&p);
strncpy_nt(p.interface, "eth0+eth0", 32);
suppress_output();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth0", "LAN");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth1");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth1", "Internet");
ck_assert_int_eq(ret, 1);
validateinterface(&p);
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(validateinterface_uses_all_matching_methods_if_no_match_for_exact_nam
e_is_found)
{
int ret;
PARAMS p;
defaultcfg();
initparams(&p);
debug = 1;
cfg.ifacematchmethod = 3;
strncpy_nt(p.interface, "inter", 32);
suppress_output();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth0", "LAN");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth1");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth1", "Internet");
ck_assert_int_eq(ret, 1);
validateinterface(&p);
ck_assert_str_eq(p.interface, "eth1");
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(validateinterface_knows_when_to_give_up_searching)
{
int ret;
PARAMS p;
defaultcfg();
initparams(&p);
debug = 1;
cfg.ifacematchmethod = 3;
strncpy_nt(p.interface, "outer", 32);
suppress_output();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth0", "LAN");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eth1");
ck_assert_int_eq(ret, 1);
ret = db_setalias("eth1", "Internet");
ck_assert_int_eq(ret, 1);
validateinterface(&p);
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
void add_cli_tests(Suite *s) void add_cli_tests(Suite *s)
{ {
TCase *tc_cli = tcase_create("CLI"); TCase *tc_cli = tcase_create("CLI");
tcase_add_checked_fixture(tc_cli, setup, teardown); tcase_add_checked_fixture(tc_cli, setup, teardown);
tcase_add_unchecked_fixture(tc_cli, setup, teardown); tcase_add_unchecked_fixture(tc_cli, setup, teardown);
tcase_add_test(tc_cli, vnstat_can_init_params); tcase_add_test(tc_cli, vnstat_can_init_params);
tcase_add_test(tc_cli, vnstat_showhelp_does_not_crash); tcase_add_test(tc_cli, vnstat_showhelp_does_not_crash);
tcase_add_test(tc_cli, vnstat_showlonghelp_does_not_crash); tcase_add_test(tc_cli, vnstat_showlonghelp_does_not_crash);
tcase_add_test(tc_cli, vnstat_handlers_do_nothing_by_default); tcase_add_test(tc_cli, vnstat_handlers_do_nothing_by_default);
tcase_add_exit_test(tc_cli, vnstat_handletrafficmeters_exists_when_interf ace_is_not_available, 1); tcase_add_exit_test(tc_cli, vnstat_handletrafficmeters_exists_when_interf ace_is_not_available, 1);
skipping to change at line 979 skipping to change at line 1542
tcase_add_test(tc_cli, handleifselection_does_nothing_when_interface_has_ already_been_selected); tcase_add_test(tc_cli, handleifselection_does_nothing_when_interface_has_ already_been_selected);
tcase_add_test(tc_cli, handleifselection_selects_default_interface_if_fie ld_is_filled); tcase_add_test(tc_cli, handleifselection_selects_default_interface_if_fie ld_is_filled);
tcase_add_exit_test(tc_cli, handleifselection_exits_when_no_suitable_inte rface_is_available_for_query, 1); tcase_add_exit_test(tc_cli, handleifselection_exits_when_no_suitable_inte rface_is_available_for_query, 1);
tcase_add_test(tc_cli, handleifselection_selects_only_interface_from_data base_for_query); tcase_add_test(tc_cli, handleifselection_selects_only_interface_from_data base_for_query);
tcase_add_test(tc_cli, handleifselection_selects_highest_traffic_interfac e_from_database_for_query); tcase_add_test(tc_cli, handleifselection_selects_highest_traffic_interfac e_from_database_for_query);
tcase_add_exit_test(tc_cli, handleifselection_exits_when_no_suitable_inte rface_is_available_for_traffic, 1); tcase_add_exit_test(tc_cli, handleifselection_exits_when_no_suitable_inte rface_is_available_for_traffic, 1);
tcase_add_test(tc_cli, handleifselection_can_select_interface_without_dat abase_for_traffic); tcase_add_test(tc_cli, handleifselection_can_select_interface_without_dat abase_for_traffic);
tcase_add_exit_test(tc_cli, handleifselection_exits_if_only_database_show s_interfaces_for_traffic, 1); tcase_add_exit_test(tc_cli, handleifselection_exits_if_only_database_show s_interfaces_for_traffic, 1);
tcase_add_test(tc_cli, handleifselection_selects_only_available_interface s_for_traffic); tcase_add_test(tc_cli, handleifselection_selects_only_available_interface s_for_traffic);
tcase_add_test(tc_cli, handleifselection_selects_only_available_interface s_and_can_ignore_database_for_traffic); tcase_add_test(tc_cli, handleifselection_selects_only_available_interface s_and_can_ignore_database_for_traffic);
tcase_add_test(tc_cli, showalerthelp_does_not_crash);
tcase_add_test(tc_cli, parsealertargs_knows_which_parameters_belong_to_it
);
tcase_add_test(tc_cli, parsealertargs_helps_when_asked);
tcase_add_test(tc_cli, parsealertargs_can_set_parameters);
tcase_add_test(tc_cli, parsealertargs_can_validate_output);
tcase_add_test(tc_cli, parsealertargs_can_validate_output_range);
tcase_add_test(tc_cli, parsealertargs_can_validate_exit);
tcase_add_test(tc_cli, parsealertargs_can_validate_exit_range);
tcase_add_test(tc_cli, parsealertargs_knows_first_useless_parameter_combi
nation);
tcase_add_test(tc_cli, parsealertargs_knows_second_useless_parameter_comb
ination);
tcase_add_test(tc_cli, parsealertargs_can_validate_type);
tcase_add_test(tc_cli, parsealertargs_can_validate_condition);
tcase_add_test(tc_cli, parsealertargs_knows_first_invalid_condition_combi
nation);
tcase_add_test(tc_cli, parsealertargs_knows_second_invalid_condition_comb
ination);
tcase_add_test(tc_cli, parsealertargs_can_validate_limit_as_integer);
tcase_add_test(tc_cli, parsealertargs_can_validate_limit_as_non_zero);
tcase_add_test(tc_cli, parsealertargs_can_validate_limit_unit);
tcase_add_test(tc_cli, parsealertargs_knows_the_64_bit_limit_regardless_o
f_used_unit);
tcase_add_exit_test(tc_cli, handleshowalert_requires_interface_to_be_spec
ified, 1);
tcase_add_test(tc_cli, validateinterface_does_not_use_alias_if_interface_
names_matches);
tcase_add_test(tc_cli, validateinterface_supports_interface_merges);
tcase_add_exit_test(tc_cli, validateinterface_detects_if_not_all_interfac
es_are_available_for_merge, 1);
tcase_add_exit_test(tc_cli, validateinterface_detects_if_not_all_interfac
es_are_unique_for_merge, 1);
tcase_add_test(tc_cli, validateinterface_uses_all_matching_methods_if_no_
match_for_exact_name_is_found);
tcase_add_exit_test(tc_cli, validateinterface_knows_when_to_give_up_searc
hing, 1);
suite_add_tcase(s, tc_cli); suite_add_tcase(s, tc_cli);
} }
 End of changes. 2 change blocks. 
0 lines changed or deleted 605 lines changed or added

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