"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/config_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).

config_tests.c  (vnstat-2.7):config_tests.c  (vnstat-2.8)
#include "common.h" #include "common.h"
#include "vnstat_tests.h" #include "vnstat_tests.h"
#include "config_tests.h" #include "config_tests.h"
#include "cfg.h" #include "cfg.h"
#include "cfgoutput.h" #include "cfgoutput.h"
#include "ibw.h" #include "ibw.h"
START_TEST(validatecfg_default) START_TEST(validatecfg_default_all)
{ {
defaultcfg(); validatecfg(CT_All);
validatecfg(); }
END_TEST
START_TEST(validatecfg_default_cli)
{
validatecfg(CT_CLI);
}
END_TEST
START_TEST(validatecfg_default_daemon)
{
validatecfg(CT_Daemon);
}
END_TEST
START_TEST(validatecfg_default_image)
{
validatecfg(CT_Image);
} }
END_TEST END_TEST
START_TEST(validatecfg_does_not_modify_valid_changes) START_TEST(validatecfg_does_not_modify_valid_changes)
{ {
defaultcfg();
ck_assert_int_eq(cfg.listhours, LISTHOURS); ck_assert_int_eq(cfg.listhours, LISTHOURS);
cfg.listhours = 1; cfg.listhours = 1;
ck_assert_int_ne(cfg.listhours, LISTHOURS); ck_assert_int_ne(cfg.listhours, LISTHOURS);
validatecfg(); validatecfg(CT_All);
ck_assert_int_eq(cfg.listhours, 1); ck_assert_int_eq(cfg.listhours, 1);
} }
END_TEST END_TEST
START_TEST(validatecfg_restores_invalid_values_back_to_default) START_TEST(validatecfg_restores_invalid_values_back_to_default)
{ {
defaultcfg();
cfg.unitmode = 3; cfg.unitmode = 3;
cfg.savestatus = 2; cfg.savestatus = 2;
cfg.listhours = -1; cfg.listhours = -1;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_All);
ck_assert_int_eq(cfg.unitmode, UNITMODE); ck_assert_int_eq(cfg.unitmode, UNITMODE);
ck_assert_int_eq(cfg.savestatus, SAVESTATUS); ck_assert_int_eq(cfg.savestatus, SAVESTATUS);
ck_assert_int_eq(cfg.listhours, LISTHOURS); ck_assert_int_eq(cfg.listhours, LISTHOURS);
} }
END_TEST END_TEST
START_TEST(validatecfg_can_tune_updateinterval_to_avoid_rollover_issues) START_TEST(validatecfg_can_tune_updateinterval_to_avoid_rollover_issues)
{ {
noexit = 1;
defaultcfg();
cfg.updateinterval = 60; cfg.updateinterval = 60;
cfg.maxbw = 1000; cfg.maxbw = 1000;
cfg.bwdetection = 1; cfg.bwdetection = 1;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Daemon);
ck_assert_int_ne(cfg.updateinterval, 60); ck_assert_int_ne(cfg.updateinterval, 60);
ck_assert_int_eq(cfg.updateinterval, UPDATEINTERVAL); ck_assert_int_eq(cfg.updateinterval, UPDATEINTERVAL);
} }
END_TEST END_TEST
START_TEST(validatecfg_has_fallback_for_updateinterval_for_very_fast_interfaces) START_TEST(validatecfg_has_fallback_for_updateinterval_for_very_fast_interfaces)
{ {
noexit = 1;
defaultcfg();
cfg.updateinterval = 60; cfg.updateinterval = 60;
cfg.maxbw = 2000; cfg.maxbw = 2000;
cfg.bwdetection = 1; cfg.bwdetection = 1;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Daemon);
ck_assert_int_ne(cfg.updateinterval, 60); ck_assert_int_ne(cfg.updateinterval, 60);
ck_assert_int_ne(cfg.updateinterval, UPDATEINTERVAL); ck_assert_int_ne(cfg.updateinterval, UPDATEINTERVAL);
ck_assert_int_eq(cfg.updateinterval, (UPDATEINTERVAL / 2)); ck_assert_int_eq(cfg.updateinterval, (UPDATEINTERVAL / 2));
} }
END_TEST END_TEST
START_TEST(validatecfg_can_change_estimatestyle_for_images_depending_on_settings ) START_TEST(validatecfg_can_change_estimatestyle_for_images_depending_on_settings )
{ {
noexit = 1;
debug = 1; debug = 1;
defaultcfg();
cfg.barshowsrate = 0; cfg.barshowsrate = 0;
cfg.estimatebarvisible = 0; cfg.estimatebarvisible = 0;
cfg.estimatestyle = 1; cfg.estimatestyle = 1;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.barshowsrate, 0); ck_assert_int_eq(cfg.barshowsrate, 0);
ck_assert_int_eq(cfg.estimatebarvisible, 0); ck_assert_int_eq(cfg.estimatebarvisible, 0);
ck_assert_int_eq(cfg.estimatestyle, 1); ck_assert_int_eq(cfg.estimatestyle, 1);
cfg.barshowsrate = 1; cfg.barshowsrate = 1;
cfg.estimatebarvisible = 0; cfg.estimatebarvisible = 0;
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.barshowsrate, 1); ck_assert_int_eq(cfg.barshowsrate, 1);
ck_assert_int_eq(cfg.estimatebarvisible, 0); ck_assert_int_eq(cfg.estimatebarvisible, 0);
ck_assert_int_eq(cfg.estimatestyle, 1); ck_assert_int_eq(cfg.estimatestyle, 1);
cfg.barshowsrate = 0; cfg.barshowsrate = 0;
cfg.estimatebarvisible = 1; cfg.estimatebarvisible = 1;
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.barshowsrate, 0); ck_assert_int_eq(cfg.barshowsrate, 0);
ck_assert_int_eq(cfg.estimatebarvisible, 1); ck_assert_int_eq(cfg.estimatebarvisible, 1);
ck_assert_int_eq(cfg.estimatestyle, 1); ck_assert_int_eq(cfg.estimatestyle, 1);
cfg.barshowsrate = 1; cfg.barshowsrate = 1;
cfg.estimatebarvisible = 1; cfg.estimatebarvisible = 1;
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.barshowsrate, 1); ck_assert_int_eq(cfg.barshowsrate, 1);
ck_assert_int_eq(cfg.estimatebarvisible, 1); ck_assert_int_eq(cfg.estimatebarvisible, 1);
ck_assert_int_eq(cfg.estimatestyle, 0); ck_assert_int_eq(cfg.estimatestyle, 0);
} }
END_TEST END_TEST
START_TEST(validatecfg_limits_5_minute_result_count_to_available_data_amount) START_TEST(validatecfg_limits_5_minute_result_count_to_available_data_amount)
{ {
noexit = 1; cfg.fiveminutehours = 26;
defaultcfg();
cfg.fiveminutehours = 10;
cfg.fivegresultcount = 9001; cfg.fivegresultcount = 9001;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.fiveminutehours, 10); ck_assert_int_eq(cfg.fiveminutehours, 26);
ck_assert_int_eq(cfg.fivegresultcount, 120); ck_assert_int_eq(cfg.fivegresultcount, 312);
}
END_TEST
START_TEST(validatecfg_limits_5_minute_result_count_to_minimum_usable)
{
cfg.fiveminutehours = 12;
cfg.fivegresultcount = 9001;
suppress_output();
validatecfg(CT_Image);
ck_assert_int_eq(cfg.fiveminutehours, 12);
ck_assert_int_eq(cfg.fivegresultcount, 288);
} }
END_TEST END_TEST
START_TEST(validatecfg_limits_5_minute_result_count_to_not_be_too_much) START_TEST(validatecfg_limits_5_minute_result_count_to_not_be_too_much)
{ {
noexit = 1;
defaultcfg();
cfg.fiveminutehours = 9001; cfg.fiveminutehours = 9001;
cfg.fivegresultcount = 12345; cfg.fivegresultcount = 12345;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.fiveminutehours, 9001); ck_assert_int_eq(cfg.fiveminutehours, 9001);
ck_assert_int_eq(cfg.fivegresultcount, FIVEGRESULTCOUNT); ck_assert_int_eq(cfg.fivegresultcount, FIVEGRESULTCOUNT);
} }
END_TEST END_TEST
START_TEST(validatecfg_does_not_touch_5_minute_result_count_if_data_is_not_being _created) START_TEST(validatecfg_does_not_touch_5_minute_result_count_if_data_is_not_being _created)
{ {
noexit = 1;
defaultcfg();
cfg.fiveminutehours = 0; cfg.fiveminutehours = 0;
cfg.fivegresultcount = 1234; cfg.fivegresultcount = 1234;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.fiveminutehours, 0); ck_assert_int_eq(cfg.fiveminutehours, 0);
ck_assert_int_eq(cfg.fivegresultcount, 1234); ck_assert_int_eq(cfg.fivegresultcount, 1234);
} }
END_TEST END_TEST
START_TEST(validatecfg_is_not_stupid_with_5_minute_result_count_if_there_is_no_d ata_limit) START_TEST(validatecfg_is_not_stupid_with_5_minute_result_count_if_there_is_no_d ata_limit)
{ {
noexit = 1;
defaultcfg();
cfg.fiveminutehours = -1; cfg.fiveminutehours = -1;
cfg.fivegresultcount = 1242; cfg.fivegresultcount = 1242;
suppress_output(); suppress_output();
validatecfg(); validatecfg(CT_Image);
ck_assert_int_eq(cfg.fiveminutehours, -1); ck_assert_int_eq(cfg.fiveminutehours, -1);
ck_assert_int_eq(cfg.fivegresultcount, 1242); ck_assert_int_eq(cfg.fivegresultcount, 1242);
} }
END_TEST END_TEST
START_TEST(printcfgfile_default) START_TEST(printcfgfile_default)
{ {
defaultcfg();
ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name1", 1), 1);
ck_assert_int_eq(ibwadd("name2", 2), 1); ck_assert_int_eq(ibwadd("name2", 2), 1);
suppress_output(); suppress_output();
printcfgfile(); printcfgfile();
} }
END_TEST END_TEST
START_TEST(printcfgfile_experimental) START_TEST(printcfgfile_experimental)
{ {
defaultcfg();
cfg.experimental = 1; cfg.experimental = 1;
ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name1", 1), 1);
ck_assert_int_eq(ibwadd("name2", 2), 1); ck_assert_int_eq(ibwadd("name2", 2), 1);
suppress_output(); suppress_output();
printcfgfile(); printcfgfile();
} }
END_TEST END_TEST
START_TEST(loadcfg_included_default) START_TEST(loadcfg_included_default)
{ {
ck_assert_int_eq(loadcfg(CFGFILE), 1); ck_assert_int_eq(loadcfg(CFGFILE, CT_All), 1);
} }
END_TEST END_TEST
START_TEST(loadcfg_no_file) START_TEST(loadcfg_no_file)
{ {
ck_assert_int_eq(loadcfg(""), 1); ck_assert_int_eq(loadcfg("", CT_All), 1);
} }
END_TEST END_TEST
START_TEST(loadcfg_nonexistent_file) START_TEST(loadcfg_nonexistent_file)
{ {
suppress_output(); suppress_output();
ck_assert_int_eq(loadcfg("_nosuchfile_"), 0); ck_assert_int_eq(loadcfg("_nosuchfile_", CT_All), 0);
} }
END_TEST END_TEST
START_TEST(loadcfg_not_a_cfgfile) START_TEST(loadcfg_not_a_cfgfile)
{ {
ck_assert_int_eq(loadcfg("Makefile"), 1); ck_assert_int_eq(loadcfg("Makefile", CT_All), 1);
} }
END_TEST END_TEST
START_TEST(ibwloadcfg_included_default) START_TEST(ibwloadcfg_included_default)
{ {
ck_assert_int_eq(ibwloadcfg(CFGFILE), 1); ck_assert_int_eq(ibwloadcfg(CFGFILE), 1);
} }
END_TEST END_TEST
START_TEST(ibwloadcfg_no_file) START_TEST(ibwloadcfg_no_file)
skipping to change at line 251 skipping to change at line 261
int ret; int ret;
uint32_t limit; uint32_t limit;
cfg.maxbw = 10; cfg.maxbw = 10;
ibwflush(); ibwflush();
ret = ibwget("does_not_exist", &limit); ret = ibwget("does_not_exist", &limit);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 10); ck_assert_int_eq(limit, 10);
} }
END_TEST END_TEST
START_TEST(ibwget_with_empty_list_gives_speed_instead_of_maxbw_if_available)
{
int ret;
uint32_t limit;
linuxonly;
ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_sys_class_net("ethnotseen", 0, 0, 0, 0, 21);
cfg.maxbw = 12;
ibwflush();
ret = ibwget("ethnotseen", &limit);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 21);
}
END_TEST
START_TEST(ibwget_with_empty_list_gives_maxbw_for_tun_even_if_speed_is_available
)
{
int ret;
uint32_t limit;
linuxonly;
ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_sys_class_net("tun142", 0, 0, 0, 0, 10);
cfg.maxbw = 12;
ibwflush();
ret = ibwget("tun142", &limit);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 12);
}
END_TEST
START_TEST(ibwget_from_config) START_TEST(ibwget_from_config)
{ {
int ret; int ret;
uint32_t limit; uint32_t limit;
ck_assert_int_eq(loadcfg(CFGFILE), 1); ck_assert_int_eq(loadcfg(CFGFILE, CT_All), 1);
ck_assert_int_eq(ibwloadcfg(CFGFILE), 1);
cfg.maxbw = 10;
ret = ibwget("ethnone", &limit);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 8);
}
END_TEST
START_TEST(ibwget_from_config_ignores_detected_speed)
{
int ret;
uint32_t limit;
linuxonly;
ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_sys_class_net("ethnone", 0, 0, 0, 0, 42);
ck_assert_int_eq(loadcfg(CFGFILE, CT_All), 1);
ck_assert_int_eq(ibwloadcfg(CFGFILE), 1); ck_assert_int_eq(ibwloadcfg(CFGFILE), 1);
cfg.maxbw = 10; cfg.maxbw = 10;
ret = ibwget("ethnone", &limit); ret = ibwget("ethnone", &limit);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(limit, 8); ck_assert_int_eq(limit, 8);
} }
END_TEST END_TEST
START_TEST(ibwadd_single_success) START_TEST(ibwadd_single_success)
{ {
skipping to change at line 595 skipping to change at line 660
int ret; int ret;
struct cfgsetting cset[] = {{"unused", 0, 0, 0, 0}}; struct cfgsetting cset[] = {{"unused", 0, 0, 0, 0}};
ret = setcfgvalue(&cset[0], "nothing", "unused"); ret = setcfgvalue(&cset[0], "nothing", "unused");
ck_assert_int_eq(ret, 0); ck_assert_int_eq(ret, 0);
} }
END_TEST END_TEST
START_TEST(configlocale_does_not_crash) START_TEST(configlocale_does_not_crash)
{ {
defaultcfg();
unsetenv("LC_ALL"); unsetenv("LC_ALL");
snprintf(cfg.locale, 32, "en_US"); snprintf(cfg.locale, 32, "en_US");
configlocale(); configlocale();
snprintf(cfg.locale, 32, "-"); snprintf(cfg.locale, 32, "-");
configlocale(); configlocale();
setenv("LC_ALL", "en_US", 1); setenv("LC_ALL", "en_US", 1);
snprintf(cfg.locale, 32, "en_US"); snprintf(cfg.locale, 32, "en_US");
configlocale(); configlocale();
skipping to change at line 626 skipping to change at line 690
configlocale(); configlocale();
ck_assert_int_eq(cfg.utflocale, 1); ck_assert_int_eq(cfg.utflocale, 1);
} }
END_TEST END_TEST
void add_config_tests(Suite *s) void add_config_tests(Suite *s)
{ {
TCase *tc_config = tcase_create("Config"); TCase *tc_config = tcase_create("Config");
tcase_add_checked_fixture(tc_config, setup, teardown); tcase_add_checked_fixture(tc_config, setup, teardown);
tcase_add_unchecked_fixture(tc_config, setup, teardown); tcase_add_unchecked_fixture(tc_config, setup, teardown);
tcase_add_test(tc_config, validatecfg_default); tcase_add_test(tc_config, validatecfg_default_all);
tcase_add_test(tc_config, validatecfg_default_cli);
tcase_add_test(tc_config, validatecfg_default_daemon);
tcase_add_test(tc_config, validatecfg_default_image);
tcase_add_test(tc_config, validatecfg_does_not_modify_valid_changes); tcase_add_test(tc_config, validatecfg_does_not_modify_valid_changes);
tcase_add_test(tc_config, validatecfg_restores_invalid_values_back_to_def ault); tcase_add_test(tc_config, validatecfg_restores_invalid_values_back_to_def ault);
tcase_add_test(tc_config, validatecfg_can_tune_updateinterval_to_avoid_ro llover_issues); tcase_add_test(tc_config, validatecfg_can_tune_updateinterval_to_avoid_ro llover_issues);
tcase_add_test(tc_config, validatecfg_has_fallback_for_updateinterval_for _very_fast_interfaces); tcase_add_test(tc_config, validatecfg_has_fallback_for_updateinterval_for _very_fast_interfaces);
tcase_add_test(tc_config, validatecfg_can_change_estimatestyle_for_images _depending_on_settings); tcase_add_test(tc_config, validatecfg_can_change_estimatestyle_for_images _depending_on_settings);
tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_ava ilable_data_amount); tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_ava ilable_data_amount);
tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_min imum_usable);
tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_not _be_too_much); tcase_add_test(tc_config, validatecfg_limits_5_minute_result_count_to_not _be_too_much);
tcase_add_test(tc_config, validatecfg_does_not_touch_5_minute_result_coun t_if_data_is_not_being_created); tcase_add_test(tc_config, validatecfg_does_not_touch_5_minute_result_coun t_if_data_is_not_being_created);
tcase_add_test(tc_config, validatecfg_is_not_stupid_with_5_minute_result_ count_if_there_is_no_data_limit); tcase_add_test(tc_config, validatecfg_is_not_stupid_with_5_minute_result_ count_if_there_is_no_data_limit);
tcase_add_test(tc_config, printcfgfile_default); tcase_add_test(tc_config, printcfgfile_default);
tcase_add_test(tc_config, printcfgfile_experimental); tcase_add_test(tc_config, printcfgfile_experimental);
tcase_add_test(tc_config, loadcfg_included_default); tcase_add_test(tc_config, loadcfg_included_default);
tcase_add_test(tc_config, loadcfg_no_file); tcase_add_test(tc_config, loadcfg_no_file);
tcase_add_test(tc_config, loadcfg_nonexistent_file); tcase_add_test(tc_config, loadcfg_nonexistent_file);
tcase_add_test(tc_config, loadcfg_not_a_cfgfile); tcase_add_test(tc_config, loadcfg_not_a_cfgfile);
tcase_add_test(tc_config, ibwloadcfg_included_default); tcase_add_test(tc_config, ibwloadcfg_included_default);
tcase_add_test(tc_config, ibwloadcfg_no_file); tcase_add_test(tc_config, ibwloadcfg_no_file);
tcase_add_test(tc_config, ibwloadcfg_nonexistent_file); tcase_add_test(tc_config, ibwloadcfg_nonexistent_file);
tcase_add_test(tc_config, ibwloadcfg_not_a_cfgfile); tcase_add_test(tc_config, ibwloadcfg_not_a_cfgfile);
tcase_add_test(tc_config, ibwget_with_empty_list_and_no_maxbw); tcase_add_test(tc_config, ibwget_with_empty_list_and_no_maxbw);
tcase_add_test(tc_config, ibwget_with_empty_list_and_maxbw); tcase_add_test(tc_config, ibwget_with_empty_list_and_maxbw);
tcase_add_test(tc_config, ibwget_with_empty_list_gives_speed_instead_of_m
axbw_if_available);
tcase_add_test(tc_config, ibwget_with_empty_list_gives_maxbw_for_tun_even
_if_speed_is_available);
tcase_add_test(tc_config, ibwget_from_config); tcase_add_test(tc_config, ibwget_from_config);
tcase_add_test(tc_config, ibwget_from_config_ignores_detected_speed);
tcase_add_test(tc_config, ibwadd_single_success); tcase_add_test(tc_config, ibwadd_single_success);
tcase_add_test(tc_config, ibwadd_multi_success); tcase_add_test(tc_config, ibwadd_multi_success);
tcase_add_test(tc_config, ibwadd_update_success); tcase_add_test(tc_config, ibwadd_update_success);
tcase_add_test(tc_config, ibwflush_success); tcase_add_test(tc_config, ibwflush_success);
tcase_add_test(tc_config, ibwlist_empty); tcase_add_test(tc_config, ibwlist_empty);
tcase_add_test(tc_config, ibwlist_filled); tcase_add_test(tc_config, ibwlist_filled);
tcase_add_test(tc_config, extractcfgvalue_can_extract); tcase_add_test(tc_config, extractcfgvalue_can_extract);
tcase_add_test(tc_config, extractcfgvalue_can_really_extract); tcase_add_test(tc_config, extractcfgvalue_can_really_extract);
tcase_add_test(tc_config, extractcfgvalue_knows_when_not_to_extract); tcase_add_test(tc_config, extractcfgvalue_knows_when_not_to_extract);
tcase_add_test(tc_config, extractcfgvalue_really_knows_when_not_to_extrac t); tcase_add_test(tc_config, extractcfgvalue_really_knows_when_not_to_extrac t);
 End of changes. 37 change blocks. 
43 lines changed or deleted 117 lines changed or added

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