END_TEST START_TEST(ibwloadcfg_nonexistent_file) { suppress_output(); ck_assert_int_eq(ibwloadcfg("_nosuchfile_"), 0); }
END_TEST START_TEST(cacheshow_empty) { suppress_output(); cacheshow(); }
END_TEST START_TEST(rebuilddbtotal_rebuilds_total) { int i; initdb(); suppress_output(); disable_logprints(); cfg.flock = 1; strcpy(data.interface, "ethtest"); strcpy(data.nick, "ethtest"); data.totalrx = 1234; data.totaltx = 1234; for (i=0; i<12; i++) { data.month[i].rx = 1; data.month[i].tx = 2; data.month[i].used = 1; } ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb("ethtest", TESTDBDIR, 1), 1); rebuilddbtotal("ethtest", TESTDBDIR); ck_assert_int_eq(check_dbfile_exists("ethtest", sizeof(DATA)), 1); ck_assert_int_eq(check_dbfile_exists(".ethtest", sizeof(DATA)), 1); ck_assert_int_eq(data.totalrx, 12); ck_assert_int_eq(data.totaltx, 24); }
END_TEST START_TEST(cleartop10_clears_top10) { int i; initdb(); suppress_output(); disable_logprints(); cfg.flock = 1; strcpy(data.interface, "ethtest"); strcpy(data.nick, "ethtest"); for (i=0; i<10; i++) { data.top10[i].rx = 1; data.top10[i].tx = 1; data.top10[i].used = 1; } ck_assert_int_eq(clean_testdbdir(), 1); ck_assert_int_eq(writedb("ethtest", TESTDBDIR, 1), 1); cleartop10("ethtest", TESTDBDIR); ck_assert_int_eq(check_dbfile_exists("ethtest", sizeof(DATA)), 1); ck_assert_int_eq(check_dbfile_exists(".ethtest", sizeof(DATA)), 1); for (i=0; i<10; i++) { ck_assert_int_eq(data.top10[i].rx, 0); ck_assert_int_eq(data.top10[i].tx, 0); ck_assert_int_eq(data.top10[i].rxk, 0); ck_assert_int_eq(data.top10[i].txk, 0); ck_assert_int_eq(data.top10[i].used, 0); } }
void tui_ui_out::do_text (const char *string) { if (suppress_output ()) return; m_start_of_line++; if (m_line > 0) { /* Printing a source line, so suppress regular output -- the line was shown on the TUI's source window by tui_show_source above instead. */ if (strchr (string, '\n') != 0) { /* We've reached the end of the line, so go back to letting text output go to the console. */ m_line = 0; m_start_of_line = 0; } return; } if (strchr (string, '\n')) m_start_of_line = 0; cli_ui_out::do_text (string); }
END_TEST START_TEST(ibwlist_empty) { suppress_output(); ibwlist(); }
END_TEST START_TEST(showbar_with_zero_len_is_nothing) { int len; suppress_output(); len = showbar(1, 0, 2, 0, 3, 0); ck_assert_int_eq(len, 0); }
END_TEST START_TEST(database_outputs_do_not_crash) { int i; initdb(); defaultcfg(); strcpy(data.interface, "something"); strcpy(data.nick, "nothing"); data.totalrx = 1; data.totaltx = 2; data.currx = 3; data.curtx = 4; data.totalrxk = 5; data.totaltxk = 6; data.btime = 7; for (i=0; i<30; i++) { data.day[i].date = i+1; data.day[i].rx = data.day[i].tx = i*100; data.day[i].rxk = data.day[i].txk = i; data.day[i].used = 1; } for (i=0; i<10; i++) { data.top10[i].date = i+1; data.top10[i].rx = data.top10[i].tx = i*100; data.top10[i].rxk = data.top10[i].txk = i; data.top10[i].used = 1; } for (i=0; i<12; i++) { data.month[i].month = i+1; data.month[i].rx = data.month[i].tx = i*100; data.month[i].rxk = data.month[i].txk = i; data.month[i].used = 1; } for (i=0; i<24; i++) { data.hour[i].date = i+1; data.hour[i].rx = data.hour[i].tx = i*100; } suppress_output(); showdb(0); showdb(1); showdb(2); showdb(3); showdb(4); showdb(5); showdb(6); showdb(7); showdb(8); showdb(9); }
END_TEST START_TEST(showbar_with_big_max_and_small_numbers) { int len; suppress_output(); len = showbar(0, 1, 0, 2, 1000, 10); ck_assert_int_eq(len, 0); }
END_TEST START_TEST(showbar_with_max_smaller_than_real_max) { int len; suppress_output(); len = showbar(0, 1, 0, 2, 1, 10); ck_assert_int_eq(len, 0); }
END_TEST START_TEST(validatedb_with_invalid_totals) { initdb(); suppress_output(); strcpy(data.interface, "ethtest"); data.day[0].rx++; ck_assert_int_eq(validatedb(), 0); }
END_TEST START_TEST(ibwlist_filled) { cfg.maxbw = 0; ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); suppress_output(); ibwlist(); }
END_TEST START_TEST(printcfgfile_default) { defaultcfg(); ck_assert_int_eq(ibwadd("name1", 1), 1); ck_assert_int_eq(ibwadd("name2", 2), 1); suppress_output(); printcfgfile(); }
void tui_ui_out::do_field_fmt (int fldno, int width, ui_align align, const char *fldname, const char *format, va_list args) { if (suppress_output ()) return; m_start_of_line++; cli_ui_out::do_field_fmt (fldno, width, align, fldname, format, args); }
END_TEST START_TEST(getifinfo_not_found) { linuxonly; suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40); ck_assert_int_eq(getifinfo("ethunusual"), 0); }
END_TEST START_TEST(validatedb_with_top10_use) { initdb(); suppress_output(); strcpy(data.interface, "ethtest"); data.top10[0].used = 1; data.top10[1].used = 1; data.top10[2].used = 1; data.top10[5].used = 1; ck_assert_int_eq(validatedb(), 0); }
END_TEST START_TEST(cacheshow_filled) { initdb(); ck_assert_int_eq(cachecount(), 0); ck_assert_int_eq(cacheadd("name4", 0), 1); ck_assert_int_eq(cacheadd("name3", 0), 1); ck_assert_int_eq(cacheadd("name2", 0), 1); ck_assert_int_eq(cacheadd("name1", 0), 1); ck_assert_int_eq(cachecount(), 4); suppress_output(); cacheshow(); }
void tui_ui_out::do_field_int (int fldno, int width, ui_align alignment, const char *fldname, int value) { if (suppress_output ()) return; /* Don't print line number, keep it for later. */ if (m_start_of_line == 0 && strcmp (fldname, "line") == 0) { m_start_of_line++; m_line = value; return; } m_start_of_line++; cli_ui_out::do_field_int (fldno, width, alignment, fldname, value); }
void tui_ui_out::do_field_string (int fldno, int width, ui_align align, const char *fldname, const char *string, ui_out_style_kind style) { if (suppress_output ()) return; m_start_of_line++; if (fldname && m_line > 0 && strcmp (fldname, "fullname") == 0) { tui_show_source (string, m_line); return; } cli_ui_out::do_field_string (fldno, width, align, fldname, string, style); }
END_TEST START_TEST(getifinfo_success) { linuxonly; suppress_output(); ck_assert_int_eq(remove_directory(TESTDIR), 1); fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40); fake_proc_net_dev("a", "ethunusual", 1, 2, 3, 4); ck_assert_int_eq(getifinfo("ethunusual"), 1); ck_assert_str_eq(ifinfo.name, "ethunusual"); ck_assert_int_eq(ifinfo.filled, 1); ck_assert_int_eq(ifinfo.rx, 1); ck_assert_int_eq(ifinfo.tx, 2); ck_assert_int_eq(ifinfo.rxp, 3); ck_assert_int_eq(ifinfo.txp, 4); }
void tui_ui_out::do_text (const char *string) { if (suppress_output ()) return; m_start_of_line++; if (m_line > 0) { if (strchr (string, '\n') != 0) { m_line = -1; m_start_of_line = 0; } return; } if (strchr (string, '\n')) m_start_of_line = 0; cli_ui_out::do_text (string); }
END_TEST START_TEST(parseifinfo_hitting_maxbw_limit_causes_sync) { initdb(); data.btime = getbtime(); data.lastupdated -= 1; data.currx = 1024; data.curtx = 1024; strcpy(data.interface, "eth0"); ck_assert_int_eq(ibwadd("eth0", 10), 1); strcpy(ifinfo.name, "eth0"); ifinfo.filled = 1; ifinfo.rx = 123456789; ifinfo.tx = 123456789; ifinfo.rxp = ifinfo.txp = 0; debug = 1; suppress_output(); parseifinfo(0); ck_assert_int_eq(ifinfo.rx, 123456789); ck_assert_int_eq(ifinfo.tx, 123456789); ck_assert_int_eq(ifinfo.rxp, 0); ck_assert_int_eq(ifinfo.txp, 0); ck_assert_int_eq(data.day[0].rx, 0); ck_assert_int_eq(data.day[0].tx, 0); ck_assert_int_eq(data.day[0].rxk, 0); ck_assert_int_eq(data.day[0].txk, 0); ck_assert_int_eq(data.totalrx, 0); ck_assert_int_eq(data.totaltx, 0); ck_assert_int_eq(data.totalrxk, 0); ck_assert_int_eq(data.totaltxk, 0); ck_assert_int_eq(data.currx, 123456789); ck_assert_int_eq(data.curtx, 123456789); }