"Fossies" - the Fresh Open Source Software Archive  

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

cli_tests.c  (vnstat-2.7):cli_tests.c  (vnstat-2.8)
skipping to change at line 58 skipping to change at line 58
handletrafficmeters(&p); handletrafficmeters(&p);
ck_assert_int_eq(memcmp(&p, &b, sizeof(PARAMS)), 0); ck_assert_int_eq(memcmp(&p, &b, sizeof(PARAMS)), 0);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_exists_when_interface_is_not_available) START_TEST(vnstat_handletrafficmeters_exists_when_interface_is_not_available)
{ {
PARAMS p; PARAMS p;
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
defaultcfg();
initparams(&p); initparams(&p);
strncpy_nt(cfg.iface, "ethfoo", 32); strncpy_nt(cfg.iface, "ethfoo", 32);
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
strncpy_nt(p.definterface, cfg.iface, 32); strncpy_nt(p.definterface, cfg.iface, 32);
p.livetraffic = 1; p.livetraffic = 1;
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
skipping to change at line 86 skipping to change at line 85
suppress_output(); suppress_output();
handleremoveinterface(&p); handleremoveinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handleremoveinterface_exits_if_given_interface_does_not_exist) START_TEST(vnstat_handleremoveinterface_exits_if_given_interface_does_not_exist)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.removeiface = 1; p.removeiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "unknown", 32); strncpy_nt(p.interface, "unknown", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("known"); ret = db_addinterface("known");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 108 skipping to change at line 106
suppress_output(); suppress_output();
handleremoveinterface(&p); handleremoveinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handleremoveinterface_exits_if_force_is_not_used) START_TEST(vnstat_handleremoveinterface_exits_if_force_is_not_used)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.removeiface = 1; p.removeiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
p.force = 0; p.force = 0;
strncpy_nt(p.interface, "known", 32); strncpy_nt(p.interface, "known", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("known"); ret = db_addinterface("known");
skipping to change at line 131 skipping to change at line 128
suppress_output(); suppress_output();
handleremoveinterface(&p); handleremoveinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handleremoveinterface_removes_interface) START_TEST(vnstat_handleremoveinterface_removes_interface)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.removeiface = 1; p.removeiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
p.force = 1; p.force = 1;
strncpy_nt(p.interface, "known", 32); strncpy_nt(p.interface, "known", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("known"); ret = db_addinterface("known");
skipping to change at line 183 skipping to change at line 179
suppress_output(); suppress_output();
handlerenameinterface(&p); handlerenameinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handlerenameinterface_exits_if_given_interface_does_not_exist) START_TEST(vnstat_handlerenameinterface_exits_if_given_interface_does_not_exist)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.renameiface = 1; p.renameiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.interface, "oldname", 32);
strncpy_nt(p.newifname, "newname", 32); strncpy_nt(p.newifname, "newname", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("somename"); ret = db_addinterface("somename");
skipping to change at line 206 skipping to change at line 201
suppress_output(); suppress_output();
handlerenameinterface(&p); handlerenameinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handlerenameinterface_exits_if_new_interface_name_already_exis t) START_TEST(vnstat_handlerenameinterface_exits_if_new_interface_name_already_exis t)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.renameiface = 1; p.renameiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.interface, "oldname", 32);
strncpy_nt(p.newifname, "newname", 32); strncpy_nt(p.newifname, "newname", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("oldname"); ret = db_addinterface("oldname");
skipping to change at line 232 skipping to change at line 226
suppress_output(); suppress_output();
handlerenameinterface(&p); handlerenameinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handlerenameinterface_exits_if_force_is_not_used) START_TEST(vnstat_handlerenameinterface_exits_if_force_is_not_used)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.renameiface = 1; p.renameiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
p.force = 0; p.force = 0;
strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.interface, "oldname", 32);
strncpy_nt(p.newifname, "newname", 32); strncpy_nt(p.newifname, "newname", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 257 skipping to change at line 250
suppress_output(); suppress_output();
handlerenameinterface(&p); handlerenameinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handlerenameinterface_renames_interface) START_TEST(vnstat_handlerenameinterface_renames_interface)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.renameiface = 1; p.renameiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
p.force = 1; p.force = 1;
strncpy_nt(p.interface, "oldname", 32); strncpy_nt(p.interface, "oldname", 32);
strncpy_nt(p.newifname, "newname", 32); strncpy_nt(p.newifname, "newname", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 304 skipping to change at line 296
suppress_output(); suppress_output();
handleaddinterface(&p); handleaddinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handleaddinterface_exits_if_interface_already_exist_in_databas e) START_TEST(vnstat_handleaddinterface_exits_if_interface_already_exist_in_databas e)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.addiface = 1; p.addiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "newiface", 32); strncpy_nt(p.interface, "newiface", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("newiface"); ret = db_addinterface("newiface");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 326 skipping to change at line 317
suppress_output(); suppress_output();
handleaddinterface(&p); handleaddinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handleaddinterface_exits_if_interface_does_not_exist) START_TEST(vnstat_handleaddinterface_exits_if_interface_does_not_exist)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.addiface = 1; p.addiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "newiface", 32); strncpy_nt(p.interface, "newiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "notnewiface", 0, 0, 0, 0); fake_proc_net_dev("w", "notnewiface", 0, 0, 0, 0);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 348 skipping to change at line 338
suppress_output(); suppress_output();
handleaddinterface(&p); handleaddinterface(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handleaddinterface_adds_interface) START_TEST(vnstat_handleaddinterface_adds_interface)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.addiface = 1; p.addiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.spacecheck = 0; cfg.spacecheck = 0;
strncpy_nt(p.interface, "newiface", 32); strncpy_nt(p.interface, "newiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "newiface", 0, 0, 0, 0); fake_proc_net_dev("w", "newiface", 0, 0, 0, 0);
ret = db_open_rw(1); ret = db_open_rw(1);
skipping to change at line 377 skipping to change at line 366
ret = (int)db_getinterfacecountbyname("newiface"); ret = (int)db_getinterfacecountbyname("newiface");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(vnstat_handleaddinterface_can_be_forced_to_add_interface_that_does_no t_exist) START_TEST(vnstat_handleaddinterface_can_be_forced_to_add_interface_that_does_no t_exist)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.addiface = 1; p.addiface = 1;
p.defaultiface = 0; p.defaultiface = 0;
p.force = 1; p.force = 1;
cfg.spacecheck = 0; cfg.spacecheck = 0;
strncpy_nt(p.interface, "newiface", 32); strncpy_nt(p.interface, "newiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "notnewiface", 0, 0, 0, 0); fake_proc_net_dev("w", "notnewiface", 0, 0, 0, 0);
skipping to change at line 417 skipping to change at line 405
suppress_output(); suppress_output();
handlesetalias(&p); handlesetalias(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handlesetalias_exits_if_given_interface_does_not_exist) START_TEST(vnstat_handlesetalias_exits_if_given_interface_does_not_exist)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.setalias = 1; p.setalias = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "ethiface", 32); strncpy_nt(p.interface, "ethiface", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("somename"); ret = db_addinterface("somename");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 439 skipping to change at line 426
suppress_output(); suppress_output();
handlesetalias(&p); handlesetalias(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handlesetalias_sets_alias) START_TEST(vnstat_handlesetalias_sets_alias)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
interfaceinfo info; interfaceinfo info;
defaultcfg();
initparams(&p); initparams(&p);
p.setalias = 1; p.setalias = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "ethiface", 32); strncpy_nt(p.interface, "ethiface", 32);
strncpy_nt(p.alias, "The Internet", 32); strncpy_nt(p.alias, "The Internet", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("ethiface"); ret = db_addinterface("ethiface");
skipping to change at line 470 skipping to change at line 456
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_str_eq(info.alias, "The Internet"); ck_assert_str_eq(info.alias, "The Internet");
} }
END_TEST END_TEST
START_TEST(vnstat_handlesetalias_clears_alias) START_TEST(vnstat_handlesetalias_clears_alias)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
interfaceinfo info; interfaceinfo info;
defaultcfg();
initparams(&p); initparams(&p);
p.setalias = 1; p.setalias = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "ethiface", 32); strncpy_nt(p.interface, "ethiface", 32);
strncpy_nt(p.alias, "", 32); strncpy_nt(p.alias, "", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("ethiface"); ret = db_addinterface("ethiface");
skipping to change at line 505 skipping to change at line 490
ck_assert_str_eq(info.alias, ""); ck_assert_str_eq(info.alias, "");
} }
END_TEST END_TEST
START_TEST(vnstat_handleaddinterface_can_also_set_alias_after_adding_interface) START_TEST(vnstat_handleaddinterface_can_also_set_alias_after_adding_interface)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
interfaceinfo info; interfaceinfo info;
defaultcfg();
initparams(&p); initparams(&p);
p.addiface = 1; p.addiface = 1;
p.setalias = 1; p.setalias = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.spacecheck = 0; cfg.spacecheck = 0;
strncpy_nt(p.interface, "newiface", 32); strncpy_nt(p.interface, "newiface", 32);
strncpy_nt(p.alias, "The Interface", 32); strncpy_nt(p.alias, "The Interface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "newiface", 0, 0, 0, 0); fake_proc_net_dev("w", "newiface", 0, 0, 0, 0);
skipping to change at line 538 skipping to change at line 522
ret = db_getinterfaceinfo("newiface", &info); ret = db_getinterfaceinfo("newiface", &info);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_str_eq(info.alias, "The Interface"); ck_assert_str_eq(info.alias, "The Interface");
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_exits_when_interface_is_not_available) START_TEST(vnstat_handletrafficmeters_exits_when_interface_is_not_available)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.traffic = 1; p.traffic = 1;
p.defaultiface = 1; p.defaultiface = 1;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0); fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_exits_when_interface_is_not_available_with _configuration_tips) START_TEST(vnstat_handletrafficmeters_exits_when_interface_is_not_available_with _configuration_tips)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.traffic = 1; p.traffic = 1;
p.defaultiface = 1; p.defaultiface = 1;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
strncpy_nt(cfg.cfgfile, "I_do_not_have_a_config_file_here.something", 512 ); strncpy_nt(cfg.cfgfile, "I_do_not_have_a_config_file_here.something", 512 );
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0); fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_exits_when_specific_interface_is_not_avail able) START_TEST(vnstat_handletrafficmeters_exits_when_specific_interface_is_not_avail able)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.traffic = 1; p.traffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0); fake_proc_net_dev("w", "otheriface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_can_calculate_traffic) START_TEST(vnstat_handletrafficmeters_can_calculate_traffic)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.traffic = 1; p.traffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.qmode = 1; cfg.qmode = 1;
cfg.sampletime = 0; cfg.sampletime = 0;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_can_handle_interface_merge_using_first_int erface) START_TEST(vnstat_handletrafficmeters_can_handle_interface_merge_using_first_int erface)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.traffic = 1; p.traffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.qmode = 1; cfg.qmode = 1;
cfg.sampletime = 0; cfg.sampletime = 0;
strncpy_nt(p.interface, "someiface+anotherinterface", 32); strncpy_nt(p.interface, "someiface+anotherinterface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_can_calculate_traffic_and_output_json) START_TEST(vnstat_handletrafficmeters_can_calculate_traffic_and_output_json)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.traffic = 1; p.traffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.qmode = 10; cfg.qmode = 10;
cfg.sampletime = 0; cfg.sampletime = 0;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash) START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.livetraffic = 1; p.livetraffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.qmode = 1; cfg.qmode = 1;
cfg.ostyle = 0; cfg.ostyle = 0;
cfg.sampletime = 0; cfg.sampletime = 0;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash_with_interface_ merge) START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash_with_interface_ merge)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.livetraffic = 1; p.livetraffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.qmode = 1; cfg.qmode = 1;
cfg.ostyle = 0; cfg.ostyle = 0;
cfg.sampletime = 0; cfg.sampletime = 0;
strncpy_nt(p.interface, "someiface+anotherinterface", 32); strncpy_nt(p.interface, "someiface+anotherinterface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash_with_json) START_TEST(vnstat_handletrafficmeters_livetraffic_does_not_crash_with_json)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.livetraffic = 1; p.livetraffic = 1;
p.defaultiface = 0; p.defaultiface = 0;
cfg.qmode = 10; cfg.qmode = 10;
cfg.sampletime = 0; cfg.sampletime = 0;
strncpy_nt(p.interface, "someiface", 32); strncpy_nt(p.interface, "someiface", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "someiface", 0, 0, 0, 0); fake_proc_net_dev("w", "someiface", 0, 0, 0, 0);
suppress_output(); suppress_output();
handletrafficmeters(&p); handletrafficmeters(&p);
} }
END_TEST END_TEST
START_TEST(handleifselection_does_nothing_when_interface_has_already_been_select ed) START_TEST(handleifselection_does_nothing_when_interface_has_already_been_select ed)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 0; p.defaultiface = 0;
strncpy_nt(p.interface, "myiface", 32); strncpy_nt(p.interface, "myiface", 32);
handleifselection(&p); handleifselection(&p);
ck_assert_str_eq(p.interface, "myiface"); ck_assert_str_eq(p.interface, "myiface");
} }
END_TEST END_TEST
START_TEST(handleifselection_selects_default_interface_if_field_is_filled) START_TEST(handleifselection_selects_default_interface_if_field_is_filled)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
strncpy_nt(p.definterface, "myiface", 32); strncpy_nt(p.definterface, "myiface", 32);
handleifselection(&p); handleifselection(&p);
ck_assert_str_eq(p.interface, "myiface"); ck_assert_str_eq(p.interface, "myiface");
ck_assert_str_eq(p.definterface, "myiface"); ck_assert_str_eq(p.definterface, "myiface");
} }
END_TEST END_TEST
START_TEST(handleifselection_exits_when_no_suitable_interface_is_available_for_q uery) START_TEST(handleifselection_exits_when_no_suitable_interface_is_available_for_q uery)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 1; p.query = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
/* no interfaces added to database */ /* no interfaces added to database */
suppress_output(); suppress_output();
handleifselection(&p); handleifselection(&p);
} }
END_TEST END_TEST
START_TEST(handleifselection_selects_only_interface_from_database_for_query) START_TEST(handleifselection_selects_only_interface_from_database_for_query)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 1; p.query = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("lettherebemagic"); ret = db_addinterface("lettherebemagic");
skipping to change at line 783 skipping to change at line 754
handleifselection(&p); handleifselection(&p);
ck_assert_str_eq(p.interface, "lettherebemagic"); ck_assert_str_eq(p.interface, "lettherebemagic");
} }
END_TEST END_TEST
START_TEST(handleifselection_selects_highest_traffic_interface_from_database_for _query) START_TEST(handleifselection_selects_highest_traffic_interface_from_database_for _query)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 1; p.query = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addinterface("ethslow"); ret = db_addinterface("ethslow");
skipping to change at line 821 skipping to change at line 791
handleifselection(&p); handleifselection(&p);
/* interface with most traffic in database is selected */ /* interface with most traffic in database is selected */
ck_assert_str_eq(p.interface, "ethfast"); ck_assert_str_eq(p.interface, "ethfast");
} }
END_TEST END_TEST
START_TEST(handleifselection_exits_when_no_suitable_interface_is_available_for_t raffic) START_TEST(handleifselection_exits_when_no_suitable_interface_is_available_for_t raffic)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 0; p.query = 0;
p.traffic = 1; p.traffic = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
/* database not available and interface listing provides nothing */ /* database not available and interface listing provides nothing */
suppress_output(); suppress_output();
handleifselection(&p); handleifselection(&p);
} }
END_TEST END_TEST
START_TEST(handleifselection_can_select_interface_without_database_for_traffic) START_TEST(handleifselection_can_select_interface_without_database_for_traffic)
{ {
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 0; p.query = 0;
p.traffic = 1; p.traffic = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "firstinterface", 0, 0, 0, 0); fake_proc_net_dev("w", "firstinterface", 0, 0, 0, 0);
fake_proc_net_dev("a", "secondinterface", 0, 0, 0, 0); fake_proc_net_dev("a", "secondinterface", 0, 0, 0, 0);
skipping to change at line 865 skipping to change at line 833
/* first available interface is selected */ /* first available interface is selected */
ck_assert_str_eq(p.interface, "firstinterface"); ck_assert_str_eq(p.interface, "firstinterface");
} }
END_TEST END_TEST
START_TEST(handleifselection_exits_if_only_database_shows_interfaces_for_traffic ) START_TEST(handleifselection_exits_if_only_database_shows_interfaces_for_traffic )
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 0; p.query = 0;
p.traffic = 1; p.traffic = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ret = db_open_rw(1); ret = db_open_rw(1);
skipping to change at line 893 skipping to change at line 860
suppress_output(); suppress_output();
handleifselection(&p); handleifselection(&p);
} }
END_TEST END_TEST
START_TEST(handleifselection_selects_only_available_interfaces_for_traffic) START_TEST(handleifselection_selects_only_available_interfaces_for_traffic)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 0; p.query = 0;
p.traffic = 1; p.traffic = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "ethnone", 0, 0, 0, 0); fake_proc_net_dev("w", "ethnone", 0, 0, 0, 0);
fake_proc_net_dev("a", "ethslow", 0, 0, 0, 0); fake_proc_net_dev("a", "ethslow", 0, 0, 0, 0);
skipping to change at line 931 skipping to change at line 897
/* interface with most traffic in database the is also available is selec ted */ /* interface with most traffic in database the is also available is selec ted */
ck_assert_str_eq(p.interface, "ethslow"); ck_assert_str_eq(p.interface, "ethslow");
} }
END_TEST END_TEST
START_TEST(handleifselection_selects_only_available_interfaces_and_can_ignore_da tabase_for_traffic) START_TEST(handleifselection_selects_only_available_interfaces_and_can_ignore_da tabase_for_traffic)
{ {
int ret; int ret;
PARAMS p; PARAMS p;
defaultcfg();
initparams(&p); initparams(&p);
p.defaultiface = 1; p.defaultiface = 1;
p.query = 0; p.query = 0;
p.traffic = 1; p.traffic = 1;
strncpy_nt(p.interface, "default", 32); strncpy_nt(p.interface, "default", 32);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
fake_proc_net_dev("w", "ethnone", 0, 0, 0, 0); fake_proc_net_dev("w", "ethnone", 0, 0, 0, 0);
fake_proc_net_dev("a", "ethall", 0, 0, 0, 0); fake_proc_net_dev("a", "ethall", 0, 0, 0, 0);
 End of changes. 35 change blocks. 
35 lines changed or deleted 0 lines changed or added

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