From 876cc00dec4b455d56a6a177d5b1160bb4c54207 Mon Sep 17 00:00:00 2001 From: Yann Weber Date: Thu, 9 Mar 2017 13:00:34 +0100 Subject: [PATCH] Bugfixes in logfile minmax + tests update --- src/ttail_search.c | 1 - src/ttail_search_files.c | 6 +++--- tests/ttail_search_check.c | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ttail_search.c b/src/ttail_search.c index c35dd7d..eabc7ec 100644 --- a/src/ttail_search.c +++ b/src/ttail_search.c @@ -37,7 +37,6 @@ int ttail_logline2date(ttail_t* ttail, const char* logline, struct tm* tm) { return 1; } - fprintf(stderr, "FORMAT : %s\n", ttail->fmt); ret = strptime(subst, ttail->fmt, tm); return ret?0:1; } diff --git a/src/ttail_search_files.c b/src/ttail_search_files.c index c9120ae..cc0c469 100644 --- a/src/ttail_search_files.c +++ b/src/ttail_search_files.c @@ -136,7 +136,7 @@ int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2]) { return 1; } - if(!fseek(fp, 0, SEEK_SET)) + if(fseek(fp, 0, SEEK_SET) < 0) { perror("Unable to manipulate fp"); return -1; @@ -152,7 +152,7 @@ int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2]) break; } } - if(!fseek(fp, -1, SEEK_END)) + if(fseek(fp, -1, SEEK_END) < 0) { perror("Unable to manipulate fp"); return -1; @@ -175,7 +175,7 @@ int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2]) { return 1; } - if(!fseek(fp, cur-1, SEEK_SET)) + if(fseek(fp, cur-1, SEEK_SET) < 0) { perror("Unable to manipulate fp"); return -1; diff --git a/tests/ttail_search_check.c b/tests/ttail_search_check.c index fc2dfb5..9cfef8d 100644 --- a/tests/ttail_search_check.c +++ b/tests/ttail_search_check.c @@ -152,17 +152,23 @@ END_TEST START_TEST (test_file_minmax1) { int r; - /* struct tm tm[2]; - */ printf("%ld\n", ttail->logfile_sz); - ttail->flag |= TTAIL_FLAG_FORMAT; - ttail_set_fmt(ttail, "%B%n%d %H:%M"); + ttail->flag |= TTAIL_FLAG_PREFIX; + ttail->prefix_sz = 0; + ttail_set_fmt(ttail, "%b%n%d %H:%M"); r = _ttail_search_closest_files_init(ttail); ck_assert_int_eq(r, 0); - /* r = _ttail_file_minmax(ttail, 0, tm); - */ + ck_assert_int_eq(r, 0); + ck_assert_int_eq(tm[0].tm_mon, 2); + ck_assert_int_eq(tm[0].tm_mday, 6); + ck_assert_int_eq(tm[0].tm_hour, 0); + ck_assert_int_eq(tm[0].tm_min, 1); + ck_assert_int_eq(tm[1].tm_mon, 2); + ck_assert_int_eq(tm[1].tm_mday, 6); + ck_assert_int_eq(tm[1].tm_hour, 0); + ck_assert_int_eq(tm[1].tm_min, 29); } END_TEST