"Fossies" - the Fresh Open Source Software Archive  

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

database_tests.c  (vnstat-2.7):database_tests.c  (vnstat-2.8)
skipping to change at line 166 skipping to change at line 166
data.top10[2].used = 1; data.top10[2].used = 1;
data.top10[5].used = 1; data.top10[5].used = 1;
ck_assert_int_eq(validatedb(&data), 0); ck_assert_int_eq(validatedb(&data), 0);
} }
END_TEST END_TEST
START_TEST(database_outputs_do_not_crash) START_TEST(database_outputs_do_not_crash)
{ {
int ret, i; int ret, i;
defaultcfg();
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("something"); ret = db_addinterface("something");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
for (i = 1; i < 100; i++) { for (i = 1; i < 100; i++) {
ret = db_addtraffic_dated("something", (uint64_t)i * 1234, (uint6 4_t)i * 2345, (uint64_t)i * 85000); ret = db_addtraffic_dated("something", (uint64_t)i * 1234, (uint6 4_t)i * 2345, (uint64_t)i * 85000);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
skipping to change at line 232 skipping to change at line 230
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(database_outputs_do_not_crash_without_traffic) START_TEST(database_outputs_do_not_crash_without_traffic)
{ {
int ret, i; int ret, i;
defaultcfg();
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("something"); ret = db_addinterface("something");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_addtraffic_dated("something", 0, 0, 85000); ret = db_addtraffic_dated("something", 0, 0, 85000);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_setupdated("something", 85000); ret = db_setupdated("something", 85000);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 296 skipping to change at line 292
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(database_outputs_do_not_crash_without_data) START_TEST(database_outputs_do_not_crash_without_data)
{ {
int ret, i; int ret, i;
defaultcfg();
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("something"); ret = db_addinterface("something");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
suppress_output(); suppress_output();
for (i = 0; i <= 4; i++) { for (i = 0; i <= 4; i++) {
cfg.ostyle = i; cfg.ostyle = i;
showdb("something", 0, "", ""); showdb("something", 0, "", "");
skipping to change at line 354 skipping to change at line 348
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(database_outputs_do_not_crash_without_data_if_totals_are_wrong) START_TEST(database_outputs_do_not_crash_without_data_if_totals_are_wrong)
{ {
int ret, i; int ret, i;
defaultcfg();
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("something"); ret = db_addinterface("something");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_settotal("something", 42, 84); ret = db_settotal("something", 42, 84);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = db_setupdated("something", 85000); ret = db_setupdated("something", 85000);
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
skipping to change at line 447 skipping to change at line 439
ck_assert_int_eq(len, 0); ck_assert_int_eq(len, 0);
} }
END_TEST END_TEST
START_TEST(showbar_with_all_rx) START_TEST(showbar_with_all_rx)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
cfg.rxchar[0] = 'r'; cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't'; cfg.txchar[0] = 't';
pipe = pipe_output(); pipe = pipe_output();
len = showbar(1, 0, 1, 10); len = showbar(1, 0, 1, 10);
ck_assert_int_eq(len, 10); ck_assert_int_eq(len, 10);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_str_eq(buffer, " rrrrrrrrrr"); ck_assert_str_eq(buffer, " rrrrrrrrrr");
} }
END_TEST END_TEST
START_TEST(showbar_with_all_tx) START_TEST(showbar_with_all_tx)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
cfg.rxchar[0] = 'r'; cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't'; cfg.txchar[0] = 't';
pipe = pipe_output(); pipe = pipe_output();
len = showbar(0, 1, 1, 10); len = showbar(0, 1, 1, 10);
ck_assert_int_eq(len, 10); ck_assert_int_eq(len, 10);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_str_eq(buffer, " tttttttttt"); ck_assert_str_eq(buffer, " tttttttttt");
} }
END_TEST END_TEST
START_TEST(showbar_with_half_and_half) START_TEST(showbar_with_half_and_half)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
cfg.rxchar[0] = 'r'; cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't'; cfg.txchar[0] = 't';
pipe = pipe_output(); pipe = pipe_output();
len = showbar(1, 1, 2, 10); len = showbar(1, 1, 2, 10);
ck_assert_int_eq(len, 10); ck_assert_int_eq(len, 10);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_str_eq(buffer, " rrrrrttttt"); ck_assert_str_eq(buffer, " rrrrrttttt");
} }
END_TEST END_TEST
START_TEST(showbar_with_one_tenth) START_TEST(showbar_with_one_tenth)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
cfg.rxchar[0] = 'r'; cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't'; cfg.txchar[0] = 't';
pipe = pipe_output(); pipe = pipe_output();
len = showbar(1, 9, 10, 10); len = showbar(1, 9, 10, 10);
ck_assert_int_eq(len, 10); ck_assert_int_eq(len, 10);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_str_eq(buffer, " rttttttttt"); ck_assert_str_eq(buffer, " rttttttttt");
} }
END_TEST END_TEST
START_TEST(showbar_with_small_rx_shows_all_tx) START_TEST(showbar_with_small_rx_shows_all_tx)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
cfg.rxchar[0] = 'r'; cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't'; cfg.txchar[0] = 't';
pipe = pipe_output(); pipe = pipe_output();
len = showbar(1, 1000, 1001, 10); len = showbar(1, 1000, 1001, 10);
ck_assert_int_eq(len, 10); ck_assert_int_eq(len, 10);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_str_eq(buffer, " tttttttttt"); ck_assert_str_eq(buffer, " tttttttttt");
} }
skipping to change at line 551 skipping to change at line 538
ck_assert_int_eq(len, 0); ck_assert_int_eq(len, 0);
} }
END_TEST END_TEST
START_TEST(showbar_with_half_and_half_of_half) START_TEST(showbar_with_half_and_half_of_half)
{ {
int pipe, len; int pipe, len;
char buffer[512]; char buffer[512];
memset(&buffer, '\0', sizeof(buffer)); memset(&buffer, '\0', sizeof(buffer));
defaultcfg();
cfg.rxchar[0] = 'r'; cfg.rxchar[0] = 'r';
cfg.txchar[0] = 't'; cfg.txchar[0] = 't';
pipe = pipe_output(); pipe = pipe_output();
len = showbar(1, 1, 4, 12); len = showbar(1, 1, 4, 12);
ck_assert_int_eq(len, 6); ck_assert_int_eq(len, 6);
fflush(stdout); fflush(stdout);
len = (int)read(pipe, buffer, 512); len = (int)read(pipe, buffer, 512);
ck_assert_str_eq(buffer, " rrrttt"); ck_assert_str_eq(buffer, " rrrttt");
} }
END_TEST END_TEST
START_TEST(importlegacydb_does_not_overwrite_existing_interface_data) START_TEST(importlegacydb_does_not_overwrite_existing_interface_data)
{ {
int ret; int ret;
defaultcfg();
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("ethtest"); ret = db_addinterface("ethtest");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = importlegacydb("ethtest", TESTDBDIR); ret = importlegacydb("ethtest", TESTDBDIR);
ck_assert_int_eq(ret, 0); ck_assert_int_eq(ret, 0);
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(importlegacydb_can_detect_when_database_read_fails) START_TEST(importlegacydb_can_detect_when_database_read_fails)
{ {
int ret; int ret;
defaultcfg();
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("ethsomethingelse"); ret = db_addinterface("ethsomethingelse");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(clean_testdbdir(), 1);
ck_assert_int_eq(create_zerosize_dbfile("ethtest"), 1); ck_assert_int_eq(create_zerosize_dbfile("ethtest"), 1);
ck_assert_int_eq(create_zerosize_dbfile(".ethtest"), 1); ck_assert_int_eq(create_zerosize_dbfile(".ethtest"), 1);
skipping to change at line 615 skipping to change at line 599
START_TEST(importlegacydb_can_import_legacy_database) START_TEST(importlegacydb_can_import_legacy_database)
{ {
int ret, i; int ret, i;
DATA data; DATA data;
interfaceinfo info; interfaceinfo info;
dbdatalist *datalist = NULL, *datalist_i = NULL; dbdatalist *datalist = NULL, *datalist_i = NULL;
dbdatalistinfo datainfo; dbdatalistinfo datainfo;
initdb(&data); initdb(&data);
defaultcfg();
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("ethsomethingelse"); ret = db_addinterface("ethsomethingelse");
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
ret = (int)db_getinterfacecount(); ret = (int)db_getinterfacecount();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
strcpy(data.interface, "ethtest"); strcpy(data.interface, "ethtest");
 End of changes. 13 change blocks. 
17 lines changed or deleted 0 lines changed or added

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