"Fossies" - the Fresh Open Source Software Archive  

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

daemon_tests.c  (vnstat-2.7):daemon_tests.c  (vnstat-2.8)
skipping to change at line 23 skipping to change at line 23
START_TEST(debugtimestamp_does_not_exit) START_TEST(debugtimestamp_does_not_exit)
{ {
suppress_output(); suppress_output();
debugtimestamp(); debugtimestamp();
} }
END_TEST END_TEST
START_TEST(initdstate_does_not_crash) START_TEST(initdstate_does_not_crash)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
} }
END_TEST END_TEST
START_TEST(addinterfaces_does_nothing_with_no_files) START_TEST(addinterfaces_does_nothing_with_no_files)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
ck_assert_int_eq(addinterfaces(&s), 0); ck_assert_int_eq(addinterfaces(&s), 0);
} }
END_TEST END_TEST
START_TEST(addinterfaces_adds_interfaces) START_TEST(addinterfaces_adds_interfaces)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4);
fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0);
fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8);
fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); fake_proc_net_dev("a", "sit0", 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 80 skipping to change at line 77
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(addinterfaces_adds_only_new_interfaces) START_TEST(addinterfaces_adds_only_new_interfaces)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4);
fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0);
fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8);
fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); fake_proc_net_dev("a", "sit0", 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 139 skipping to change at line 135
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(addinterfaces_adds_to_cache_when_running) START_TEST(addinterfaces_adds_to_cache_when_running)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4);
fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
skipping to change at line 199 skipping to change at line 194
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(preparedatabase_exits_with_no_database_dir) START_TEST(preparedatabase_exits_with_no_database_dir)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
preparedatabase(&s); preparedatabase(&s);
} }
END_TEST END_TEST
START_TEST(preparedatabase_exits_with_no_database) START_TEST(preparedatabase_exits_with_no_database)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
preparedatabase(&s); preparedatabase(&s);
} }
END_TEST END_TEST
START_TEST(preparedatabase_exits_with_no_database_and_noadd) START_TEST(preparedatabase_exits_with_no_database_and_noadd)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.noadd = 1; s.noadd = 1;
suppress_output(); suppress_output();
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
preparedatabase(&s); preparedatabase(&s);
} }
END_TEST END_TEST
START_TEST(preparedatabase_with_no_database_creates_database) START_TEST(preparedatabase_with_no_database_creates_database)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
fake_proc_net_dev("w", "ethone", 1, 2, 3, 4); fake_proc_net_dev("w", "ethone", 1, 2, 3, 4);
fake_proc_net_dev("a", "lo0", 0, 0, 0, 0); fake_proc_net_dev("a", "lo0", 0, 0, 0, 0);
fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8); fake_proc_net_dev("a", "ethtwo", 5, 6, 7, 8);
fake_proc_net_dev("a", "sit0", 0, 0, 0, 0); fake_proc_net_dev("a", "sit0", 0, 0, 0, 0);
ret = db_open_rw(1); ret = db_open_rw(1);
skipping to change at line 283 skipping to change at line 274
{ {
intsignal = 1; intsignal = 1;
setsignaltraps(); setsignaltraps();
ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(intsignal, 0);
} }
END_TEST END_TEST
START_TEST(filldatabaselist_exits_with_no_database_dir) START_TEST(filldatabaselist_exits_with_no_database_dir)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
filldatabaselist(&s); filldatabaselist(&s);
} }
END_TEST END_TEST
START_TEST(filldatabaselist_does_not_exit_with_empty_database_dir) START_TEST(filldatabaselist_does_not_exit_with_empty_database_dir)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
s.sync = 1; s.sync = 1;
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
filldatabaselist(&s); filldatabaselist(&s);
ck_assert_int_eq(s.dbifcount, 0); ck_assert_int_eq(s.dbifcount, 0);
ck_assert_int_eq(s.sync, 0); ck_assert_int_eq(s.sync, 0);
ck_assert_int_eq(s.updateinterval, 120); ck_assert_int_eq(s.updateinterval, 120);
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(filldatabaselist_adds_databases) START_TEST(filldatabaselist_adds_databases)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
s.sync = 1; s.sync = 1;
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
ck_assert_int_eq(create_zerosize_dbfile("name1"), 1); ck_assert_int_eq(create_zerosize_dbfile("name1"), 1);
ck_assert_int_eq(create_zerosize_dbfile("name2"), 1); ck_assert_int_eq(create_zerosize_dbfile("name2"), 1);
ck_assert_int_eq(check_dbfile_exists("name1", 0), 1); ck_assert_int_eq(check_dbfile_exists("name1", 0), 1);
skipping to change at line 362 skipping to change at line 350
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(adjustsaveinterval_with_empty_cache) START_TEST(adjustsaveinterval_with_empty_cache)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.saveinterval = 0; s.saveinterval = 0;
ck_assert_int_eq(datacache_activecount(&s.dcache), 0); ck_assert_int_eq(datacache_activecount(&s.dcache), 0);
adjustsaveinterval(&s); adjustsaveinterval(&s);
ck_assert_int_eq(s.saveinterval, cfg.offsaveinterval * 60); ck_assert_int_eq(s.saveinterval, cfg.offsaveinterval * 60);
} }
END_TEST END_TEST
START_TEST(adjustsaveinterval_with_filled_cache) START_TEST(adjustsaveinterval_with_filled_cache)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.saveinterval = 0; s.saveinterval = 0;
ret = datacache_add(&s.dcache, "name1", 0); ret = datacache_add(&s.dcache, "name1", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(datacache_activecount(&s.dcache), 1); ck_assert_int_eq(datacache_activecount(&s.dcache), 1);
adjustsaveinterval(&s); adjustsaveinterval(&s);
ck_assert_int_eq(s.saveinterval, cfg.saveinterval * 60); ck_assert_int_eq(s.saveinterval, cfg.saveinterval * 60);
skipping to change at line 459 skipping to change at line 445
initdstate(&s); initdstate(&s);
processdatacache(&s); processdatacache(&s);
} }
END_TEST END_TEST
START_TEST(processdatacache_can_process_things) START_TEST(processdatacache_can_process_things)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
debug = 1; debug = 1;
s.iflisthash = 42; s.iflisthash = 42;
s.bootdetected = 1; s.bootdetected = 1;
s.dodbsave = 1; s.dodbsave = 1;
s.cleanuphour = getcurrenthour() + 1; s.cleanuphour = getcurrenthour() + 1;
skipping to change at line 507 skipping to change at line 492
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(handleintsignals_handles_no_signal) START_TEST(handleintsignals_handles_no_signal)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.running = 1; s.running = 1;
s.dbifcount = 1; s.dbifcount = 1;
intsignal = 0; intsignal = 0;
handleintsignals(&s); handleintsignals(&s);
ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(intsignal, 0);
ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.running, 1);
ck_assert_int_eq(s.dbifcount, 1); ck_assert_int_eq(s.dbifcount, 1);
} }
END_TEST END_TEST
START_TEST(handleintsignals_handles_42) START_TEST(handleintsignals_handles_42)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.running = 1; s.running = 1;
s.dbifcount = 1; s.dbifcount = 1;
intsignal = 42; intsignal = 42;
handleintsignals(&s); handleintsignals(&s);
ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(intsignal, 0);
ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.running, 1);
ck_assert_int_eq(s.dbifcount, 1); ck_assert_int_eq(s.dbifcount, 1);
} }
END_TEST END_TEST
START_TEST(handleintsignals_handles_unknown_signal) START_TEST(handleintsignals_handles_unknown_signal)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.running = 1; s.running = 1;
s.dbifcount = 1; s.dbifcount = 1;
disable_logprints(); disable_logprints();
intsignal = 43; intsignal = 43;
handleintsignals(&s); handleintsignals(&s);
ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(intsignal, 0);
ck_assert_int_eq(s.running, 1); ck_assert_int_eq(s.running, 1);
ck_assert_int_eq(s.dbifcount, 1); ck_assert_int_eq(s.dbifcount, 1);
} }
END_TEST END_TEST
START_TEST(handleintsignals_handles_sigterm) START_TEST(handleintsignals_handles_sigterm)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.running = 1; s.running = 1;
s.dbifcount = 1; s.dbifcount = 1;
disable_logprints(); disable_logprints();
intsignal = SIGTERM; intsignal = SIGTERM;
handleintsignals(&s); handleintsignals(&s);
ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(intsignal, 0);
ck_assert_int_eq(s.running, 0); ck_assert_int_eq(s.running, 0);
ck_assert_int_eq(s.dbifcount, 1); ck_assert_int_eq(s.dbifcount, 1);
} }
END_TEST END_TEST
START_TEST(handleintsignals_handles_sigint) START_TEST(handleintsignals_handles_sigint)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.running = 1; s.running = 1;
s.dbifcount = 1; s.dbifcount = 1;
disable_logprints(); disable_logprints();
s.running = 1; s.running = 1;
intsignal = SIGINT; intsignal = SIGINT;
handleintsignals(&s); handleintsignals(&s);
ck_assert_int_eq(intsignal, 0); ck_assert_int_eq(intsignal, 0);
ck_assert_int_eq(s.running, 0); ck_assert_int_eq(s.running, 0);
ck_assert_int_eq(s.dbifcount, 1); ck_assert_int_eq(s.dbifcount, 1);
} }
END_TEST END_TEST
START_TEST(handleintsignals_handles_sighup) START_TEST(handleintsignals_handles_sighup)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
s.running = 1; s.running = 1;
s.dbifcount = 1; s.dbifcount = 1;
disable_logprints(); disable_logprints();
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("eth0"); ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 629 skipping to change at line 608
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(preparedirs_with_no_dir) START_TEST(preparedirs_with_no_dir)
{ {
char logdir[500], piddir[500]; char logdir[500], piddir[500];
DSTATE s; DSTATE s;
initdstate(&s); initdstate(&s);
defaultcfg();
cfg.uselogging = 1; cfg.uselogging = 1;
s.rundaemon = 1; s.rundaemon = 1;
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
snprintf(logdir, 500, "%s/log/vnstat", TESTDIR); snprintf(logdir, 500, "%s/log/vnstat", TESTDIR);
snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR); snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR);
snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir); snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir);
snprintf(cfg.pidfile, 512, "%s/vnstat.pid", piddir); snprintf(cfg.pidfile, 512, "%s/vnstat.pid", piddir);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(direxists(TESTDBDIR), 0);
skipping to change at line 655 skipping to change at line 633
ck_assert_int_eq(direxists(piddir), 1); ck_assert_int_eq(direxists(piddir), 1);
} }
END_TEST END_TEST
START_TEST(preparedirs_with_dir) START_TEST(preparedirs_with_dir)
{ {
char logdir[500], piddir[500]; char logdir[500], piddir[500];
DSTATE s; DSTATE s;
initdstate(&s); initdstate(&s);
defaultcfg();
cfg.uselogging = 1; cfg.uselogging = 1;
s.rundaemon = 1; s.rundaemon = 1;
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
snprintf(logdir, 500, "%s/log/vnstat", TESTDIR); snprintf(logdir, 500, "%s/log/vnstat", TESTDIR);
snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR); snprintf(piddir, 500, "%s/pid/vnstat", TESTDIR);
snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir); snprintf(cfg.logfile, 512, "%s/vnstat.log", logdir);
snprintf(cfg.pidfile, 512, "%s/vnstat.pid", piddir); snprintf(cfg.pidfile, 512, "%s/vnstat.pid", piddir);
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(direxists(TESTDBDIR), 0); ck_assert_int_eq(direxists(TESTDBDIR), 0);
skipping to change at line 732 skipping to change at line 709
free(ifacelist); free(ifacelist);
} }
END_TEST END_TEST
START_TEST(interfacechangecheck_with_filled_cache) START_TEST(interfacechangecheck_with_filled_cache)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
datacache *iterator; datacache *iterator;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
s.iflisthash = 123; s.iflisthash = 123;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethbasic", 0); ret = datacache_add(&s.dcache, "ethbasic", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = datacache_add(&s.dcache, "ethactive", 0); ret = datacache_add(&s.dcache, "ethactive", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 786 skipping to change at line 762
ck_assert_int_eq(simplehash("1", 1), 50); ck_assert_int_eq(simplehash("1", 1), 50);
ck_assert_int_eq(simplehash("12", 2), 101); ck_assert_int_eq(simplehash("12", 2), 101);
} }
END_TEST END_TEST
START_TEST(initcachevalues_does_not_init_without_database) START_TEST(initcachevalues_does_not_init_without_database)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ret = datacache_add(&s.dcache, "eth0", 0); ret = datacache_add(&s.dcache, "eth0", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = initcachevalues(&s, &s.dcache); ret = initcachevalues(&s, &s.dcache);
ck_assert_int_eq(ret, 0); ck_assert_int_eq(ret, 0);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(initcachevalues_does_init) START_TEST(initcachevalues_does_init)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ck_assert_int_eq(remove_directory(TESTDIR), 1); ck_assert_int_eq(remove_directory(TESTDIR), 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
strncpy_nt(cfg.dbdir, TESTDBDIR, 512); strncpy_nt(cfg.dbdir, TESTDBDIR, 512);
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("eth0"); ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 852 skipping to change at line 826
ck_assert_int_ge(ret, 0); ck_assert_int_ge(ret, 0);
ck_assert_int_le(ret, 23); ck_assert_int_le(ret, 23);
} }
END_TEST END_TEST
START_TEST(waittimesync_does_not_wait_unless_configured_to_do_so) START_TEST(waittimesync_does_not_wait_unless_configured_to_do_so)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
cfg.timesyncwait = 0; cfg.timesyncwait = 0;
ret = waittimesync(&s); ret = waittimesync(&s);
ck_assert_int_eq(ret, 0); ck_assert_int_eq(ret, 0);
} }
END_TEST END_TEST
START_TEST(waittimesync_does_not_wait_with_no_interfaces) START_TEST(waittimesync_does_not_wait_with_no_interfaces)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
ret = waittimesync(&s); ret = waittimesync(&s);
ck_assert_int_eq(ret, 0); ck_assert_int_eq(ret, 0);
ck_assert_int_eq(s.prevdbsave, 0); ck_assert_int_eq(s.prevdbsave, 0);
} }
END_TEST END_TEST
START_TEST(waittimesync_does_not_wait_with_new_interfaces) START_TEST(waittimesync_does_not_wait_with_new_interfaces)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
cfg.timesyncwait = 60; cfg.timesyncwait = 60;
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("eth0"); ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
/* 'updated' needs to be slightly adjusted in order to be sure to never t rigger an error */ /* 'updated' needs to be slightly adjusted in order to be sure to never t rigger an error */
skipping to change at line 916 skipping to change at line 887
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(waittimesync_knows_when_to_wait) START_TEST(waittimesync_knows_when_to_wait)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
cfg.timesyncwait = 60; cfg.timesyncwait = 60;
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("eth0"); ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_exec("update interface set updated=datetime('now', '+7 days', 'l ocaltime') where id=1;"); ret = db_exec("update interface set updated=datetime('now', '+7 days', 'l ocaltime') where id=1;");
skipping to change at line 952 skipping to change at line 922
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(waittimesync_knows_when_to_give_up) START_TEST(waittimesync_knows_when_to_give_up)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
cfg.timesyncwait = 60; cfg.timesyncwait = 60;
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("eth0"); ret = db_addinterface("eth0");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_exec("update interface set updated=datetime('now', '+7 days', 'l ocaltime') where id=1;"); ret = db_exec("update interface set updated=datetime('now', '+7 days', 'l ocaltime') where id=1;");
skipping to change at line 989 skipping to change at line 958
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(detectboot_sets_btime_if_missing_from_database) START_TEST(detectboot_sets_btime_if_missing_from_database)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
char *buffer; char *buffer;
defaultcfg();
initdstate(&s); initdstate(&s);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_exec("delete from info where name='btime';"); ret = db_exec("delete from info where name='btime';");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
buffer = db_getinfo("btime"); buffer = db_getinfo("btime");
ck_assert_int_eq((int)strlen(buffer), 0); ck_assert_int_eq((int)strlen(buffer), 0);
skipping to change at line 1021 skipping to change at line 989
} }
END_TEST END_TEST
START_TEST(detectboot_sets_btime_for_new_database) START_TEST(detectboot_sets_btime_for_new_database)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
char *buffer; char *buffer;
char temp[64]; char temp[64];
defaultcfg();
initdstate(&s); initdstate(&s);
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
buffer = db_getinfo("btime"); buffer = db_getinfo("btime");
ck_assert_int_ne((int)strlen(buffer), 0); ck_assert_int_ne((int)strlen(buffer), 0);
strncpy_nt(temp, buffer, 64); strncpy_nt(temp, buffer, 64);
ck_assert_str_eq(buffer, temp); ck_assert_str_eq(buffer, temp);
skipping to change at line 1055 skipping to change at line 1022
} }
END_TEST END_TEST
START_TEST(detectboot_can_detect_boot) START_TEST(detectboot_can_detect_boot)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
char *buffer; char *buffer;
char temp[64]; char temp[64];
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
ret = db_open_rw(1); ret = db_open_rw(1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
db_setinfo("btime", "1", 1); db_setinfo("btime", "1", 1);
buffer = db_getinfo("btime"); buffer = db_getinfo("btime");
ck_assert_int_ne((int)strlen(buffer), 0); ck_assert_int_ne((int)strlen(buffer), 0);
skipping to change at line 1089 skipping to change at line 1055
ck_assert_str_ne(buffer, temp); ck_assert_str_ne(buffer, temp);
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(handledatabaseerror_exits_on_fatal_error) START_TEST(handledatabaseerror_exits_on_fatal_error)
{ {
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
db_errcode = SQLITE_ERROR; db_errcode = SQLITE_ERROR;
handledatabaseerror(&s); handledatabaseerror(&s);
} }
END_TEST END_TEST
START_TEST(handledatabaseerror_does_not_exit_if_limit_is_not_exceeded) START_TEST(handledatabaseerror_does_not_exit_if_limit_is_not_exceeded)
{ {
int i; int i;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ck_assert_int_eq(s.dbretrycount, 0); ck_assert_int_eq(s.dbretrycount, 0);
db_errcode = SQLITE_BUSY; db_errcode = SQLITE_BUSY;
handledatabaseerror(&s); handledatabaseerror(&s);
ck_assert_int_eq(s.dbretrycount, 1); ck_assert_int_eq(s.dbretrycount, 1);
skipping to change at line 1125 skipping to change at line 1089
} }
ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT); ck_assert_int_eq(s.dbretrycount, DBRETRYLIMIT);
} }
END_TEST END_TEST
START_TEST(handledatabaseerror_exits_if_limit_is_exceeded) START_TEST(handledatabaseerror_exits_if_limit_is_exceeded)
{ {
int i; int i;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ck_assert_int_eq(s.dbretrycount, 0); ck_assert_int_eq(s.dbretrycount, 0);
db_errcode = SQLITE_BUSY; db_errcode = SQLITE_BUSY;
handledatabaseerror(&s); handledatabaseerror(&s);
ck_assert_int_eq(s.dbretrycount, 1); ck_assert_int_eq(s.dbretrycount, 1);
for (i = 1; i < DBRETRYLIMIT + 1; i++) { for (i = 1; i < DBRETRYLIMIT + 1; i++) {
handledatabaseerror(&s); handledatabaseerror(&s);
} }
} }
END_TEST END_TEST
START_TEST(cleanremovedinterfaces_allows_interfaces_to_be_removed) START_TEST(cleanremovedinterfaces_allows_interfaces_to_be_removed)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethnotindb1", 0); ret = datacache_add(&s.dcache, "ethnotindb1", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = datacache_add(&s.dcache, "ethindb1", 0); ret = datacache_add(&s.dcache, "ethindb1", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = datacache_add(&s.dcache, "ethnotindb2", 0); ret = datacache_add(&s.dcache, "ethnotindb2", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 1193 skipping to change at line 1155
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_syncs_when_needed) START_TEST(processifinfo_syncs_when_needed)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
ifinfo.rx = 11; ifinfo.rx = 11;
ifinfo.tx = 22; ifinfo.tx = 22;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethsomething", 1); ret = datacache_add(&s.dcache, "ethsomething", 1);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(s.dcache->syncneeded, 1); ck_assert_int_eq(s.dcache->syncneeded, 1);
ck_assert_int_eq(s.dcache->currx, 0); ck_assert_int_eq(s.dcache->currx, 0);
skipping to change at line 1221 skipping to change at line 1182
ck_assert_int_eq(s.dcache->curtx, 22); ck_assert_int_eq(s.dcache->curtx, 22);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_skips_update_if_timestamps_make_no_sense) START_TEST(processifinfo_skips_update_if_timestamps_make_no_sense)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
ifinfo.rx = 11; ifinfo.rx = 11;
ifinfo.tx = 22; ifinfo.tx = 22;
ifinfo.timestamp = 250; ifinfo.timestamp = 250;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethsomething", 0); ret = datacache_add(&s.dcache, "ethsomething", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->syncneeded, 0);
skipping to change at line 1251 skipping to change at line 1211
ck_assert_int_eq(s.dcache->curtx, 0); ck_assert_int_eq(s.dcache->curtx, 0);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_exits_if_timestamps_really_make_no_sense) START_TEST(processifinfo_exits_if_timestamps_really_make_no_sense)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
disable_logprints(); disable_logprints();
ifinfo.rx = 11; ifinfo.rx = 11;
ifinfo.tx = 22; ifinfo.tx = 22;
ifinfo.timestamp = 250; ifinfo.timestamp = 250;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethsomething", 0); ret = datacache_add(&s.dcache, "ethsomething", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 1275 skipping to change at line 1234
s.dcache->updated = 100000; s.dcache->updated = 100000;
processifinfo(&s, &s.dcache); processifinfo(&s, &s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_syncs_if_timestamps_match) START_TEST(processifinfo_syncs_if_timestamps_match)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
ifinfo.rx = 11; ifinfo.rx = 11;
ifinfo.tx = 22; ifinfo.tx = 22;
ifinfo.timestamp = 250; ifinfo.timestamp = 250;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethsomething", 0); ret = datacache_add(&s.dcache, "ethsomething", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(s.dcache->syncneeded, 0); ck_assert_int_eq(s.dcache->syncneeded, 0);
skipping to change at line 1306 skipping to change at line 1264
ck_assert_ptr_eq(s.dcache->log, NULL); ck_assert_ptr_eq(s.dcache->log, NULL);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_adds_traffic) START_TEST(processifinfo_adds_traffic)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
ifinfo.rx = 11; ifinfo.rx = 11;
ifinfo.tx = 22; ifinfo.tx = 22;
ifinfo.timestamp = 250; ifinfo.timestamp = 250;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethsomething", 0); ret = datacache_add(&s.dcache, "ethsomething", 0);
skipping to change at line 1342 skipping to change at line 1299
ck_assert_ptr_ne(s.dcache->log, NULL); ck_assert_ptr_ne(s.dcache->log, NULL);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_does_not_add_traffic_when_over_limit) START_TEST(processifinfo_does_not_add_traffic_when_over_limit)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
ifinfo.rx = 1111111; ifinfo.rx = 1111111;
ifinfo.tx = 2222222; ifinfo.tx = 2222222;
ifinfo.timestamp = 250; ifinfo.timestamp = 250;
cfg.trafficlessentries = 0; cfg.trafficlessentries = 0;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
skipping to change at line 1379 skipping to change at line 1335
ck_assert_ptr_eq(s.dcache->log, NULL); ck_assert_ptr_eq(s.dcache->log, NULL);
datacache_clear(&s.dcache); datacache_clear(&s.dcache);
} }
END_TEST END_TEST
START_TEST(processifinfo_adds_zero_traffic_when_over_limit) START_TEST(processifinfo_adds_zero_traffic_when_over_limit)
{ {
int ret; int ret;
DSTATE s; DSTATE s;
defaultcfg();
initdstate(&s); initdstate(&s);
suppress_output(); suppress_output();
debug = 1; debug = 1;
ifinfo.rx = 1111111; ifinfo.rx = 1111111;
ifinfo.tx = 2222222; ifinfo.tx = 2222222;
ifinfo.timestamp = 250; ifinfo.timestamp = 250;
cfg.trafficlessentries = 1; cfg.trafficlessentries = 1;
ck_assert_int_eq(datacache_count(&s.dcache), 0); ck_assert_int_eq(datacache_count(&s.dcache), 0);
skipping to change at line 1428 skipping to change at line 1383
dcache = NULL; dcache = NULL;
datacache_status(&dcache); datacache_status(&dcache);
} }
END_TEST END_TEST
START_TEST(datacache_status_can_show_limits) START_TEST(datacache_status_can_show_limits)
{ {
int ret; int ret;
datacache *dcache; datacache *dcache;
defaultcfg();
disable_logprints(); disable_logprints();
dcache = NULL; dcache = NULL;
ret = datacache_add(&dcache, "ethdefault", 0); ret = datacache_add(&dcache, "ethdefault", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = datacache_add(&dcache, "ethslow", 0); ret = datacache_add(&dcache, "ethslow", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = datacache_add(&dcache, "ethfast", 0); ret = datacache_add(&dcache, "ethfast", 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = datacache_add(&dcache, "ethnolimit", 0); ret = datacache_add(&dcache, "ethnolimit", 0);
skipping to change at line 1459 skipping to change at line 1413
datacache_clear(&dcache); datacache_clear(&dcache);
} }
END_TEST END_TEST
START_TEST(datacache_status_has_no_issues_with_large_number_of_interfaces) START_TEST(datacache_status_has_no_issues_with_large_number_of_interfaces)
{ {
int i, ret; int i, ret;
char buffer[8]; char buffer[8];
datacache *dcache; datacache *dcache;
defaultcfg();
disable_logprints(); disable_logprints();
dcache = NULL; dcache = NULL;
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
snprintf(buffer, 8, "eth%d", i); snprintf(buffer, 8, "eth%d", i);
ret = datacache_add(&dcache, buffer, 0); ret = datacache_add(&dcache, buffer, 0);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = ibwadd(buffer, (uint32_t)i); ret = ibwadd(buffer, (uint32_t)i);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
datacache_status(&dcache); datacache_status(&dcache);
datacache_clear(&dcache); datacache_clear(&dcache);
} }
END_TEST END_TEST
START_TEST(rescandatabaseforinterfaces_does_nothing_if_database_has_no_interface
s)
{
int ret;
DSTATE s;
initdstate(&s);
ck_assert_int_eq(datacache_count(&s.dcache), 0);
ck_assert_int_eq(s.dbifcount, 0);
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(db_getinterfacecount(), 0);
rescandatabaseforinterfaces(&s);
ck_assert_int_eq(datacache_count(&s.dcache), 0);
ck_assert_int_eq(s.dbifcount, 0);
ck_assert_int_eq(db_getinterfacecount(), 0);
ret = db_close();
ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache);
}
END_TEST
START_TEST(rescandatabaseforinterfaces_does_nothing_if_interface_lists_are_the_s
ame)
{
int ret;
DSTATE s;
initdstate(&s);
ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethtwo", 0);
ck_assert_int_eq(ret, 1);
ret = datacache_add(&s.dcache, "eththree", 0);
ck_assert_int_eq(ret, 1);
ret = datacache_add(&s.dcache, "ethone", 0);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(datacache_count(&s.dcache), 3);
s.dbifcount = 3;
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(db_getinterfacecount(), 0);
ret = db_addinterface("ethtwo");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("ethone");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eththree");
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(db_getinterfacecount(), 3);
rescandatabaseforinterfaces(&s);
ck_assert_int_eq(datacache_count(&s.dcache), 3);
ck_assert_int_eq(s.dbifcount, 3);
ck_assert_int_eq(db_getinterfacecount(), 3);
ret = db_close();
ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache);
}
END_TEST
START_TEST(rescandatabaseforinterfaces_adds_missing_interfaces_to_update_list)
{
int ret;
DSTATE s;
initdstate(&s);
disable_logprints();
ck_assert_int_eq(datacache_count(&s.dcache), 0);
ret = datacache_add(&s.dcache, "ethone", 0);
ck_assert_int_eq(ret, 1);
ret = datacache_add(&s.dcache, "ethfour", 0);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(datacache_count(&s.dcache), 2);
s.dbifcount = 2;
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(db_getinterfacecount(), 0);
ret = db_addinterface("ethtwo");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("ethone");
ck_assert_int_eq(ret, 1);
ret = db_addinterface("eththree");
ck_assert_int_eq(ret, 1);
ck_assert_int_eq(db_getinterfacecount(), 3);
rescandatabaseforinterfaces(&s);
ck_assert_int_eq(datacache_count(&s.dcache), 4);
ck_assert_int_eq(s.dbifcount, 4);
ck_assert_int_eq(db_getinterfacecount(), 3);
ret = db_close();
ck_assert_int_eq(ret, 1);
datacache_clear(&s.dcache);
}
END_TEST
void add_daemon_tests(Suite *s) void add_daemon_tests(Suite *s)
{ {
TCase *tc_daemon = tcase_create("Daemon"); TCase *tc_daemon = tcase_create("Daemon");
tcase_add_checked_fixture(tc_daemon, setup, teardown); tcase_add_checked_fixture(tc_daemon, setup, teardown);
tcase_add_unchecked_fixture(tc_daemon, setup, teardown); tcase_add_unchecked_fixture(tc_daemon, setup, teardown);
tcase_add_test(tc_daemon, debugtimestamp_does_not_exit); tcase_add_test(tc_daemon, debugtimestamp_does_not_exit);
tcase_add_test(tc_daemon, initdstate_does_not_crash); tcase_add_test(tc_daemon, initdstate_does_not_crash);
tcase_add_test(tc_daemon, addinterfaces_does_nothing_with_no_files); tcase_add_test(tc_daemon, addinterfaces_does_nothing_with_no_files);
tcase_add_test(tc_daemon, addinterfaces_adds_interfaces); tcase_add_test(tc_daemon, addinterfaces_adds_interfaces);
tcase_add_test(tc_daemon, addinterfaces_adds_only_new_interfaces); tcase_add_test(tc_daemon, addinterfaces_adds_only_new_interfaces);
skipping to change at line 1542 skipping to change at line 1603
tcase_add_test(tc_daemon, processifinfo_syncs_when_needed); tcase_add_test(tc_daemon, processifinfo_syncs_when_needed);
tcase_add_test(tc_daemon, processifinfo_skips_update_if_timestamps_make_n o_sense); tcase_add_test(tc_daemon, processifinfo_skips_update_if_timestamps_make_n o_sense);
tcase_add_exit_test(tc_daemon, processifinfo_exits_if_timestamps_really_m ake_no_sense, 1); tcase_add_exit_test(tc_daemon, processifinfo_exits_if_timestamps_really_m ake_no_sense, 1);
tcase_add_test(tc_daemon, processifinfo_syncs_if_timestamps_match); tcase_add_test(tc_daemon, processifinfo_syncs_if_timestamps_match);
tcase_add_test(tc_daemon, processifinfo_adds_traffic); tcase_add_test(tc_daemon, processifinfo_adds_traffic);
tcase_add_test(tc_daemon, processifinfo_does_not_add_traffic_when_over_li mit); tcase_add_test(tc_daemon, processifinfo_does_not_add_traffic_when_over_li mit);
tcase_add_test(tc_daemon, processifinfo_adds_zero_traffic_when_over_limit ); tcase_add_test(tc_daemon, processifinfo_adds_zero_traffic_when_over_limit );
tcase_add_test(tc_daemon, datacache_status_can_handle_nothing); tcase_add_test(tc_daemon, datacache_status_can_handle_nothing);
tcase_add_test(tc_daemon, datacache_status_can_show_limits); tcase_add_test(tc_daemon, datacache_status_can_show_limits);
tcase_add_test(tc_daemon, datacache_status_has_no_issues_with_large_numbe r_of_interfaces); tcase_add_test(tc_daemon, datacache_status_has_no_issues_with_large_numbe r_of_interfaces);
tcase_add_test(tc_daemon, rescandatabaseforinterfaces_does_nothing_if_dat
abase_has_no_interfaces);
tcase_add_test(tc_daemon, rescandatabaseforinterfaces_does_nothing_if_int
erface_lists_are_the_same);
tcase_add_test(tc_daemon, rescandatabaseforinterfaces_adds_missing_interf
aces_to_update_list);
suite_add_tcase(s, tc_daemon); suite_add_tcase(s, tc_daemon);
} }
 End of changes. 49 change blocks. 
47 lines changed or deleted 116 lines changed or added

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