Browse Source

* add test for matches

master
Alex 'AdUser' Z 9 years ago
parent
commit
9db094d688
  1. 2
      t/CMakeLists.txt
  2. 29
      t/t_matches.c

2
t/CMakeLists.txt

@ -3,5 +3,7 @@ enable_testing()
set(SRC_DIR "../src") set(SRC_DIR "../src")
add_executable("t_logfile" "t_logfile.c" "${SRC_DIR}/logfile.c") add_executable("t_logfile" "t_logfile.c" "${SRC_DIR}/logfile.c")
add_executable("t_matches" "t_matches.c" "${SRC_DIR}/matches.c")
add_test("tests/f2b_logfile_*" "t_logfile") add_test("tests/f2b_logfile_*" "t_logfile")
add_test("tests/f2b_matches_*" "t_matches")

29
t/t_matches.c

@ -0,0 +1,29 @@
#include "../src/common.h"
#include "../src/matches.h"
int main() {
f2b_matches_t matches;
size_t size = 15;
time_t now = time(NULL);
assert(f2b_matches_create(&matches, size) == true);
assert(matches.used == 0);
assert(matches.max == 15);
assert(matches.times != NULL);
for (size_t i = 0; i < size; i++)
assert(f2b_matches_append(&matches, now - 60 * i) == true);
assert(f2b_matches_append(&matches, 0) == false);
f2b_matches_expire(&matches, now - 60 * 4);
assert(matches.used == 4);
assert(matches.max == 15);
f2b_matches_destroy(&matches);
assert(matches.used == 0);
assert(matches.max == 0);
assert(matches.times == NULL);
return 0;
}
Loading…
Cancel
Save