|
@@ -288,7 +288,6 @@ END_TEST
|
288
|
288
|
START_TEST (test_init_guess_fmt_set)
|
289
|
289
|
{
|
290
|
290
|
int ret;
|
291
|
|
- struct tm tm;
|
292
|
291
|
char res[] = "%Y/%m/%d";
|
293
|
292
|
ret = ttail_format_guess(ttail, "1988/10/22", NULL);
|
294
|
293
|
ck_assert_int_eq(ret, 11);
|
|
@@ -299,12 +298,147 @@ START_TEST (test_init_guess_fmt_set)
|
299
|
298
|
}
|
300
|
299
|
END_TEST
|
301
|
300
|
|
|
301
|
+/*
|
|
302
|
+ * ttail_set_dates() tests
|
|
303
|
+ */
|
|
304
|
+
|
|
305
|
+START_TEST (test_init_setdates_nothing)
|
|
306
|
+{
|
|
307
|
+ int ret;
|
|
308
|
+ char *arg[] = {NULL, NULL};
|
|
309
|
+ struct tm zero;
|
|
310
|
+
|
|
311
|
+ memset(&zero, 0, sizeof(struct tm));
|
|
312
|
+
|
|
313
|
+ ret = ttail_set_dates(ttail, arg);
|
|
314
|
+ ck_assert_int_eq(ret, 0);
|
|
315
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
|
|
316
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
|
|
317
|
+ ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
|
|
318
|
+ ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
|
|
319
|
+}
|
|
320
|
+END_TEST
|
|
321
|
+
|
|
322
|
+START_TEST (test_init_setdates_nofmt_min)
|
|
323
|
+{
|
|
324
|
+ int ret;
|
|
325
|
+ char *arg[] = {"88/10/22", NULL};
|
|
326
|
+ struct tm zero;
|
|
327
|
+ char *arg0;
|
|
328
|
+
|
|
329
|
+ arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
|
|
330
|
+ if(!arg0)
|
|
331
|
+ {
|
|
332
|
+ perror("Malloc failed for argument");
|
|
333
|
+ ck_abort_msg("Unable to allocate memory");
|
|
334
|
+ }
|
|
335
|
+ strcpy(arg0, arg[0]);
|
|
336
|
+ arg[0]=arg0;
|
|
337
|
+
|
|
338
|
+ memset(&zero, 0, sizeof(struct tm));
|
|
339
|
+
|
|
340
|
+ ret = ttail_set_dates(ttail, arg);
|
|
341
|
+ ck_assert_int_eq(ret, 0);
|
|
342
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
|
|
343
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
|
|
344
|
+ ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
|
|
345
|
+
|
|
346
|
+ ck_assert_int_eq(ttail->date_min.tm_year, 88);
|
|
347
|
+ ck_assert_int_eq(ttail->date_min.tm_mon, 9);
|
|
348
|
+ ck_assert_int_eq(ttail->date_min.tm_mday, 22);
|
|
349
|
+ ck_assert_int_eq(ttail->date_min.tm_hour, 0);
|
|
350
|
+ ck_assert_int_eq(ttail->date_min.tm_min, 0);
|
|
351
|
+ ck_assert_int_eq(ttail->date_min.tm_sec, 0);
|
|
352
|
+}
|
|
353
|
+END_TEST
|
|
354
|
+
|
|
355
|
+START_TEST (test_init_setdates_nofmt_max)
|
|
356
|
+{
|
|
357
|
+ int ret;
|
|
358
|
+ char *arg[] = {NULL, "88/10/22"};
|
|
359
|
+ struct tm zero;
|
|
360
|
+ char *arg1;
|
|
361
|
+
|
|
362
|
+ arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
|
|
363
|
+ if(!arg1)
|
|
364
|
+ {
|
|
365
|
+ perror("Malloc failed for argument");
|
|
366
|
+ ck_abort_msg("Unable to allocate memory");
|
|
367
|
+ }
|
|
368
|
+ strcpy(arg1, arg[1]);
|
|
369
|
+ arg[1]=arg1;
|
|
370
|
+
|
|
371
|
+ memset(&zero, 0, sizeof(struct tm));
|
|
372
|
+
|
|
373
|
+ ret = ttail_set_dates(ttail, arg);
|
|
374
|
+ ck_assert_int_eq(ret, 0);
|
|
375
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
|
|
376
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
|
|
377
|
+ ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
|
|
378
|
+
|
|
379
|
+ ck_assert_int_eq(ttail->date_max.tm_year, 88);
|
|
380
|
+ ck_assert_int_eq(ttail->date_max.tm_mon, 9);
|
|
381
|
+ ck_assert_int_eq(ttail->date_max.tm_mday, 22);
|
|
382
|
+ ck_assert_int_eq(ttail->date_max.tm_hour, 0);
|
|
383
|
+ ck_assert_int_eq(ttail->date_max.tm_min, 0);
|
|
384
|
+ ck_assert_int_eq(ttail->date_max.tm_sec, 0);
|
|
385
|
+}
|
|
386
|
+END_TEST
|
|
387
|
+
|
|
388
|
+START_TEST (test_init_setdates_nofmt_both)
|
|
389
|
+{
|
|
390
|
+ int ret;
|
|
391
|
+ char *arg[] = {"1988/10/22", "2088/10/22"};
|
|
392
|
+ struct tm zero;
|
|
393
|
+ char *arg0, *arg1;
|
|
394
|
+
|
|
395
|
+ arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
|
|
396
|
+ if(!arg0)
|
|
397
|
+ {
|
|
398
|
+ perror("Malloc failed for argument");
|
|
399
|
+ ck_abort_msg("Unable to allocate memory");
|
|
400
|
+ }
|
|
401
|
+ strcpy(arg0, arg[0]);
|
|
402
|
+ arg[0]=arg0;
|
|
403
|
+
|
|
404
|
+ arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
|
|
405
|
+ if(!arg1)
|
|
406
|
+ {
|
|
407
|
+ perror("Malloc failed for argument");
|
|
408
|
+ ck_abort_msg("Unable to allocate memory");
|
|
409
|
+ }
|
|
410
|
+ strcpy(arg1, arg[1]);
|
|
411
|
+ arg[1]=arg1;
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+ memset(&zero, 0, sizeof(struct tm));
|
|
415
|
+
|
|
416
|
+ ret = ttail_set_dates(ttail, arg);
|
|
417
|
+ ck_assert_int_eq(ret, 0);
|
|
418
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
|
|
419
|
+ ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
|
|
420
|
+
|
|
421
|
+ ck_assert_int_eq(ttail->date_min.tm_year, 88);
|
|
422
|
+ ck_assert_int_eq(ttail->date_min.tm_mon, 9);
|
|
423
|
+ ck_assert_int_eq(ttail->date_min.tm_mday, 22);
|
|
424
|
+ ck_assert_int_eq(ttail->date_min.tm_hour, 0);
|
|
425
|
+ ck_assert_int_eq(ttail->date_min.tm_min, 0);
|
|
426
|
+ ck_assert_int_eq(ttail->date_min.tm_sec, 0);
|
|
427
|
+
|
|
428
|
+ ck_assert_int_eq(ttail->date_max.tm_year, 188);
|
|
429
|
+ ck_assert_int_eq(ttail->date_max.tm_mon, 9);
|
|
430
|
+ ck_assert_int_eq(ttail->date_max.tm_mday, 22);
|
|
431
|
+ ck_assert_int_eq(ttail->date_max.tm_hour, 0);
|
|
432
|
+ ck_assert_int_eq(ttail->date_max.tm_min, 0);
|
|
433
|
+ ck_assert_int_eq(ttail->date_max.tm_sec, 0);
|
|
434
|
+}
|
|
435
|
+END_TEST
|
|
436
|
+
|
302
|
437
|
Suite * ttail_init_suite(void)
|
303
|
438
|
{
|
304
|
439
|
Suite *s;
|
305
|
|
- TCase *tc_init_logfile;
|
306
|
|
- TCase *tc_init_prefix;
|
307
|
|
- TCase *tc_init_fmt_guess;
|
|
440
|
+ TCase *tc_init_logfile, *tc_init_prefix ,*tc_init_fmt_guess, \
|
|
441
|
+ *tc_init_set_dates;
|
308
|
442
|
|
309
|
443
|
s = suite_create("ttail init checks");
|
310
|
444
|
|
|
@@ -336,6 +470,14 @@ Suite * ttail_init_suite(void)
|
336
|
470
|
tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess_notm);
|
337
|
471
|
tcase_add_test(tc_init_fmt_guess, test_init_guess_fmt_set);
|
338
|
472
|
|
|
473
|
+ tc_init_set_dates = tcase_create("dates min/max init checks");
|
|
474
|
+ tcase_add_checked_fixture(tc_init_set_dates,
|
|
475
|
+ setup_ttail_empty, teardown_ttail);
|
|
476
|
+ tcase_add_test(tc_init_fmt_guess, test_init_setdates_nothing);
|
|
477
|
+ tcase_add_test(tc_init_fmt_guess, test_init_setdates_nofmt_min);
|
|
478
|
+ tcase_add_test(tc_init_fmt_guess, test_init_setdates_nofmt_max);
|
|
479
|
+ tcase_add_test(tc_init_fmt_guess, test_init_setdates_nofmt_both);
|
|
480
|
+
|
339
|
481
|
suite_add_tcase(s, tc_init_logfile);
|
340
|
482
|
suite_add_tcase(s, tc_init_prefix);
|
341
|
483
|
suite_add_tcase(s, tc_init_fmt_guess);
|