"Fossies" - the Fresh Open Source Software Archive  

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

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

database_tests.c  (vnstat-2.8):database_tests.c  (vnstat-2.9)
skipping to change at line 722 skipping to change at line 722
datalist_i = datalist_i->next; datalist_i = datalist_i->next;
i++; i++;
} }
dbdatalistfree(&datalist); dbdatalistfree(&datalist);
ret = db_close(); ret = db_close();
ck_assert_int_eq(ret, 1); ck_assert_int_eq(ret, 1);
} }
END_TEST END_TEST
START_TEST(showalert_shows_nothing_with_none_type)
{
int ret;
defaultcfg();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("something");
ck_assert_int_eq(ret, 1);
ret = db_addtraffic("something", 100, 200);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Non
e, AC_Total, 42);
ck_assert_int_eq(ret, 0);
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(showalert_can_alert_on_limit_and_show_things)
{
int ret;
defaultcfg();
suppress_output();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("something");
ck_assert_int_eq(ret, 1);
ret = db_setalias("something", "anything");
ck_assert_int_eq(ret, 1);
ret = db_addtraffic("something", 100, 200);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Hou
r, AC_Total, 250);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Day
, AC_Total, 250);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Mon
th, AC_Total, 250);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_Total, 250);
ck_assert_int_eq(ret, 1);
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
START_TEST(showalert_limit_and_conditions_matter)
{
int ret;
defaultcfg();
suppress_output();
ret = db_open_rw(1);
ck_assert_int_eq(ret, 1);
ret = db_addinterface("something");
ck_assert_int_eq(ret, 1);
ret = db_addtraffic("something", 100, 200);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_Total, 100);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_Total, 280);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_Total, 350);
ck_assert_int_eq(ret, 0);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_Total, 300);
ck_assert_int_eq(ret, 0);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_RX, 80);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_RX, 150);
ck_assert_int_eq(ret, 0);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_TX, 180);
ck_assert_int_eq(ret, 1);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_TX, 250);
ck_assert_int_eq(ret, 0);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_TX, 350);
ck_assert_int_eq(ret, 0);
ret = showalert("something", AO_Always_Output, AE_Exit_1_On_Limit, AT_Yea
r, AC_TX, 200);
ck_assert_int_eq(ret, 0);
ret = db_close();
ck_assert_int_eq(ret, 1);
}
END_TEST
void add_database_tests(Suite *s) void add_database_tests(Suite *s)
{ {
TCase *tc_db = tcase_create("Database"); TCase *tc_db = tcase_create("Database");
tcase_add_checked_fixture(tc_db, setup, teardown); tcase_add_checked_fixture(tc_db, setup, teardown);
tcase_add_unchecked_fixture(tc_db, setup, teardown); tcase_add_unchecked_fixture(tc_db, setup, teardown);
tcase_add_test(tc_db, initdb_activates_database); tcase_add_test(tc_db, initdb_activates_database);
tcase_add_test(tc_db, readdb_with_empty_file); tcase_add_test(tc_db, readdb_with_empty_file);
tcase_add_test(tc_db, readdb_with_empty_file_and_backup); tcase_add_test(tc_db, readdb_with_empty_file_and_backup);
tcase_add_test(tc_db, readdb_with_nonexisting_file); tcase_add_test(tc_db, readdb_with_nonexisting_file);
tcase_add_test(tc_db, readdb_with_existing_dbfile); tcase_add_test(tc_db, readdb_with_existing_dbfile);
skipping to change at line 755 skipping to change at line 865
tcase_add_test(tc_db, showbar_with_all_rx); tcase_add_test(tc_db, showbar_with_all_rx);
tcase_add_test(tc_db, showbar_with_all_tx); tcase_add_test(tc_db, showbar_with_all_tx);
tcase_add_test(tc_db, showbar_with_half_and_half); tcase_add_test(tc_db, showbar_with_half_and_half);
tcase_add_test(tc_db, showbar_with_one_tenth); tcase_add_test(tc_db, showbar_with_one_tenth);
tcase_add_test(tc_db, showbar_with_small_rx_shows_all_tx); tcase_add_test(tc_db, showbar_with_small_rx_shows_all_tx);
tcase_add_test(tc_db, showbar_with_max_smaller_than_real_max); tcase_add_test(tc_db, showbar_with_max_smaller_than_real_max);
tcase_add_test(tc_db, showbar_with_half_and_half_of_half); tcase_add_test(tc_db, showbar_with_half_and_half_of_half);
tcase_add_test(tc_db, importlegacydb_does_not_overwrite_existing_interfac e_data); tcase_add_test(tc_db, importlegacydb_does_not_overwrite_existing_interfac e_data);
tcase_add_test(tc_db, importlegacydb_can_detect_when_database_read_fails) ; tcase_add_test(tc_db, importlegacydb_can_detect_when_database_read_fails) ;
tcase_add_test(tc_db, importlegacydb_can_import_legacy_database); tcase_add_test(tc_db, importlegacydb_can_import_legacy_database);
tcase_add_test(tc_db, showalert_shows_nothing_with_none_type);
tcase_add_test(tc_db, showalert_can_alert_on_limit_and_show_things);
tcase_add_test(tc_db, showalert_limit_and_conditions_matter);
suite_add_tcase(s, tc_db); suite_add_tcase(s, tc_db);
} }
int writedb(DATA *data, const char *iface, const char *dirname, int newdb) int writedb(DATA *data, const char *iface, const char *dirname, int newdb)
{ {
FILE *testdb; FILE *testdb;
char file[512], backup[512]; char file[512], backup[512];
snprintf(file, 512, "%s/%s", dirname, iface); snprintf(file, 512, "%s/%s", dirname, iface);
snprintf(backup, 512, "%s/.%s", dirname, iface); snprintf(backup, 512, "%s/.%s", dirname, iface);
 End of changes. 2 change blocks. 
0 lines changed or deleted 128 lines changed or added

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