Browse Source

Bugfixes in logfile minmax + tests update

Yann Weber 7 years ago
parent
commit
876cc00dec
3 changed files with 15 additions and 10 deletions
  1. 0
    1
      src/ttail_search.c
  2. 3
    3
      src/ttail_search_files.c
  3. 12
    6
      tests/ttail_search_check.c

+ 0
- 1
src/ttail_search.c View File

@@ -37,7 +37,6 @@ int ttail_logline2date(ttail_t* ttail, const char* logline, struct tm* tm)
37 37
 	{
38 38
 		return 1;
39 39
 	}
40
-	fprintf(stderr, "FORMAT : %s\n", ttail->fmt);
41 40
 	ret = strptime(subst, ttail->fmt, tm);
42 41
 	return ret?0:1;
43 42
 }

+ 3
- 3
src/ttail_search_files.c View File

@@ -136,7 +136,7 @@ int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])
136 136
 	{
137 137
 		return 1;
138 138
 	}
139
-	if(!fseek(fp, 0, SEEK_SET))
139
+	if(fseek(fp, 0, SEEK_SET) < 0)
140 140
 	{
141 141
 		perror("Unable to manipulate fp");
142 142
 		return -1;
@@ -152,7 +152,7 @@ int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])
152 152
 			break;
153 153
 		}
154 154
 	}
155
-	if(!fseek(fp, -1, SEEK_END))
155
+	if(fseek(fp, -1, SEEK_END) < 0)
156 156
 	{
157 157
 		perror("Unable to manipulate fp");
158 158
 		return -1;
@@ -175,7 +175,7 @@ int _ttail_file_minmax(ttail_t* t, size_t id, struct tm tm[2])
175 175
 		{
176 176
 			return 1;
177 177
 		}
178
-		if(!fseek(fp, cur-1, SEEK_SET))
178
+		if(fseek(fp, cur-1, SEEK_SET) < 0)
179 179
 		{
180 180
 			perror("Unable to manipulate fp");
181 181
 			return -1;

+ 12
- 6
tests/ttail_search_check.c View File

@@ -152,17 +152,23 @@ END_TEST
152 152
 START_TEST (test_file_minmax1)
153 153
 {
154 154
 	int r;
155
-	/*
156 155
 	struct tm tm[2];
157
-	*/
158 156
 	printf("%ld\n", ttail->logfile_sz);
159
-	ttail->flag |= TTAIL_FLAG_FORMAT;
160
-	ttail_set_fmt(ttail, "%B%n%d %H:%M");
157
+	ttail->flag |= TTAIL_FLAG_PREFIX;
158
+	ttail->prefix_sz = 0;
159
+	ttail_set_fmt(ttail, "%b%n%d %H:%M");
161 160
 	r = _ttail_search_closest_files_init(ttail);
162 161
 	ck_assert_int_eq(r, 0);
163
-	/*
164 162
 	r = _ttail_file_minmax(ttail, 0, tm);
165
-	*/
163
+	ck_assert_int_eq(r, 0);
164
+	ck_assert_int_eq(tm[0].tm_mon, 2);
165
+	ck_assert_int_eq(tm[0].tm_mday, 6);
166
+	ck_assert_int_eq(tm[0].tm_hour, 0);
167
+	ck_assert_int_eq(tm[0].tm_min, 1);
168
+	ck_assert_int_eq(tm[1].tm_mon, 2);
169
+	ck_assert_int_eq(tm[1].tm_mday, 6);
170
+	ck_assert_int_eq(tm[1].tm_hour, 0);
171
+	ck_assert_int_eq(tm[1].tm_min, 29);
166 172
 }
167 173
 END_TEST
168 174
 

Loading…
Cancel
Save