|
@@ -10,7 +10,10 @@ ttail_t *ttail;
|
10
|
10
|
#define __Fname_sz 5
|
11
|
11
|
#define FNAME_NO_EXIST 0
|
12
|
12
|
#define FNAME_EXIST 1
|
|
13
|
+
|
13
|
14
|
char *fname[__Fname_sz];
|
|
15
|
+/*date formats*/
|
|
16
|
+char *fmt[] = TTAIL_DEFAULT_FORMATS;
|
14
|
17
|
|
15
|
18
|
void teardown_ttail(void)
|
16
|
19
|
{
|
|
@@ -20,6 +23,9 @@ void setup_ttail_empty(void)
|
20
|
23
|
{
|
21
|
24
|
ttail = ttail_init(1, (char**)&"foo");
|
22
|
25
|
}
|
|
26
|
+/*
|
|
27
|
+ * ttail_add_logfile() tests
|
|
28
|
+ */
|
23
|
29
|
START_TEST (test_init_empty_logfilename)
|
24
|
30
|
{
|
25
|
31
|
ck_assert_msg(ttail->logfile_name == NULL,
|
|
@@ -149,6 +155,9 @@ START_TEST (test_init_multiple_logfilename)
|
149
|
155
|
}
|
150
|
156
|
END_TEST
|
151
|
157
|
|
|
158
|
+/*
|
|
159
|
+ * ttail_set_prefix() tests
|
|
160
|
+ */
|
152
|
161
|
START_TEST (test_init_prefix)
|
153
|
162
|
{
|
154
|
163
|
int ret;
|
|
@@ -192,11 +201,110 @@ START_TEST (test_init_againbad_prefix)
|
192
|
201
|
}
|
193
|
202
|
END_TEST
|
194
|
203
|
|
|
204
|
+/*
|
|
205
|
+ * ttail_format_guess() tests
|
|
206
|
+ */
|
|
207
|
+START_TEST (test_init_guess_date)
|
|
208
|
+{
|
|
209
|
+ int ret;
|
|
210
|
+ struct tm tm;
|
|
211
|
+ char res[] = "%Y/%m/%d";
|
|
212
|
+ ret = ttail_format_guess(ttail, "1988/10/22", &tm);
|
|
213
|
+ ck_assert_int_ne(ret, -1);
|
|
214
|
+ ck_assert_str_eq(fmt[ret], res);
|
|
215
|
+ ck_assert(ttail->fmt != NULL);
|
|
216
|
+ ck_assert_str_eq(ttail->fmt, res);
|
|
217
|
+ ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
|
|
218
|
+ ck_assert_int_eq(tm.tm_year, 88);
|
|
219
|
+ ck_assert_int_eq(tm.tm_mon, 9);
|
|
220
|
+ ck_assert_int_eq(tm.tm_mday, 22);
|
|
221
|
+ ck_assert_int_eq(tm.tm_hour, 0);
|
|
222
|
+ ck_assert_int_eq(tm.tm_min, 0);
|
|
223
|
+ ck_assert_int_eq(tm.tm_sec, 0);
|
|
224
|
+}
|
|
225
|
+END_TEST
|
|
226
|
+
|
|
227
|
+START_TEST (test_init_guess_datetime)
|
|
228
|
+{
|
|
229
|
+ int ret;
|
|
230
|
+ struct tm tm;
|
|
231
|
+ char res[] = "%Y/%m/%d:%H:%M";
|
|
232
|
+ ret = ttail_format_guess(ttail, "1988/10/22:22:10:00", &tm);
|
|
233
|
+ ck_assert_int_ne(ret, -1);
|
|
234
|
+ ck_assert_str_eq(fmt[ret], res);
|
|
235
|
+ ck_assert(ttail->fmt != NULL);
|
|
236
|
+ ck_assert_str_eq(ttail->fmt, res);
|
|
237
|
+ ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
|
|
238
|
+ ck_assert_int_eq(tm.tm_year, 88);
|
|
239
|
+ ck_assert_int_eq(tm.tm_mon, 9);
|
|
240
|
+ ck_assert_int_eq(tm.tm_mday, 22);
|
|
241
|
+ ck_assert_int_eq(tm.tm_hour, 22);
|
|
242
|
+ ck_assert_int_eq(tm.tm_min, 10);
|
|
243
|
+ ck_assert_int_eq(tm.tm_sec, 0);
|
|
244
|
+}
|
|
245
|
+END_TEST
|
|
246
|
+
|
|
247
|
+START_TEST (test_init_guess_noguess)
|
|
248
|
+{
|
|
249
|
+ int ret;
|
|
250
|
+ struct tm tm;
|
|
251
|
+ ret = ttail_format_guess(ttail, "notadate", &tm);
|
|
252
|
+ ck_assert_int_eq(ret, -1);
|
|
253
|
+ ck_assert(ttail->fmt == NULL);
|
|
254
|
+ ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
|
|
255
|
+ ck_assert_int_eq(tm.tm_year, 0);
|
|
256
|
+ ck_assert_int_eq(tm.tm_mon, 0);
|
|
257
|
+ ck_assert_int_eq(tm.tm_mday, 0);
|
|
258
|
+ ck_assert_int_eq(tm.tm_hour, 0);
|
|
259
|
+ ck_assert_int_eq(tm.tm_min, 0);
|
|
260
|
+ ck_assert_int_eq(tm.tm_sec, 0);
|
|
261
|
+}
|
|
262
|
+END_TEST
|
|
263
|
+
|
|
264
|
+START_TEST (test_init_guess_date_notm)
|
|
265
|
+{
|
|
266
|
+ int ret;
|
|
267
|
+ char res[] = "%Y/%m/%d";
|
|
268
|
+ ret = ttail_format_guess(ttail, "1988/10/22", NULL);
|
|
269
|
+ ck_assert_int_ne(ret, -1);
|
|
270
|
+ ck_assert_str_eq(fmt[ret], res);
|
|
271
|
+ ck_assert(ttail->fmt != NULL);
|
|
272
|
+ ck_assert_str_eq(ttail->fmt, res);
|
|
273
|
+ ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
|
|
274
|
+}
|
|
275
|
+END_TEST
|
|
276
|
+
|
|
277
|
+START_TEST (test_init_guess_noguess_notm)
|
|
278
|
+{
|
|
279
|
+ int ret;
|
|
280
|
+ struct tm tm;
|
|
281
|
+ ret = ttail_format_guess(ttail, "notadate", &tm);
|
|
282
|
+ ck_assert_int_eq(ret, -1);
|
|
283
|
+ ck_assert(ttail->fmt == NULL);
|
|
284
|
+ ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
|
|
285
|
+}
|
|
286
|
+END_TEST
|
|
287
|
+
|
|
288
|
+START_TEST (test_init_guess_fmt_set)
|
|
289
|
+{
|
|
290
|
+ int ret;
|
|
291
|
+ struct tm tm;
|
|
292
|
+ char res[] = "%Y/%m/%d";
|
|
293
|
+ ret = ttail_format_guess(ttail, "1988/10/22", NULL);
|
|
294
|
+ ck_assert_int_eq(ret, 11);
|
|
295
|
+ ret = ttail_format_guess(ttail, "1988/10/22", NULL);
|
|
296
|
+ ck_assert_int_eq(ret, -2);
|
|
297
|
+ ck_assert_str_eq(ttail->fmt, res);
|
|
298
|
+ ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
|
|
299
|
+}
|
|
300
|
+END_TEST
|
|
301
|
+
|
195
|
302
|
Suite * ttail_init_suite(void)
|
196
|
303
|
{
|
197
|
304
|
Suite *s;
|
198
|
305
|
TCase *tc_init_logfile;
|
199
|
306
|
TCase *tc_init_prefix;
|
|
307
|
+ TCase *tc_init_fmt_guess;
|
200
|
308
|
|
201
|
309
|
s = suite_create("ttail init checks");
|
202
|
310
|
|
|
@@ -218,8 +326,19 @@ Suite * ttail_init_suite(void)
|
218
|
326
|
tcase_add_test(tc_init_prefix, test_init_again_prefix);
|
219
|
327
|
tcase_add_test(tc_init_prefix, test_init_againbad_prefix);
|
220
|
328
|
|
|
329
|
+ tc_init_fmt_guess = tcase_create("date format guess init checks");
|
|
330
|
+ tcase_add_checked_fixture(tc_init_fmt_guess,
|
|
331
|
+ setup_ttail_empty, teardown_ttail);
|
|
332
|
+ tcase_add_test(tc_init_fmt_guess, test_init_guess_date);
|
|
333
|
+ tcase_add_test(tc_init_fmt_guess, test_init_guess_datetime);
|
|
334
|
+ tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess);
|
|
335
|
+ tcase_add_test(tc_init_fmt_guess, test_init_guess_date_notm);
|
|
336
|
+ tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess_notm);
|
|
337
|
+ tcase_add_test(tc_init_fmt_guess, test_init_guess_fmt_set);
|
|
338
|
+
|
221
|
339
|
suite_add_tcase(s, tc_init_logfile);
|
222
|
340
|
suite_add_tcase(s, tc_init_prefix);
|
|
341
|
+ suite_add_tcase(s, tc_init_fmt_guess);
|
223
|
342
|
return s;
|
224
|
343
|
}
|
225
|
344
|
|