timed tail for logfiles. Display loglines given a minimum date and/or a maximum date.
c
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ttail_init_check.c 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. #include <check.h>
  2. #include <errno.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include "ttail.h"
  6. #include "ttail_init.h"
  7. ttail_t *ttail;
  8. #define __Fname_sz 5
  9. #define FNAME_NO_EXIST 0
  10. #define FNAME_EXIST 1
  11. char *fname[__Fname_sz];
  12. /*date formats*/
  13. char *fmt[] = TTAIL_DEFAULT_FORMATS;
  14. void teardown_ttail(void)
  15. {
  16. ttail_free(ttail);
  17. }
  18. void setup_ttail_empty(void)
  19. {
  20. ttail = ttail_init(1, (char**)&"foo");
  21. }
  22. /*
  23. * ttail_add_logfile() tests
  24. */
  25. START_TEST (test_init_empty_logfilename)
  26. {
  27. ck_assert_msg(ttail->logfile_name == NULL,
  28. "ttail_t.logfile_name should be NULL");
  29. }
  30. END_TEST
  31. START_TEST (test_init_nonexist_logfilename)
  32. {
  33. char *fname;
  34. int ret;
  35. /** @todo replace by mkstemp */
  36. fname = tempnam(NULL, "ttail_check");
  37. ret = ttail_add_logfile(ttail, fname);
  38. ck_assert_int_eq(ret, 1);
  39. ck_assert(ttail->logfile_name != NULL);
  40. ck_assert_str_eq(ttail->logfile_name[0], fname);
  41. ck_assert(ttail->logfile[0] == NULL);
  42. free(fname);
  43. }
  44. END_TEST
  45. START_TEST (test_init_exist_logfilename)
  46. {
  47. char *fname;
  48. int ret;
  49. FILE *fp;
  50. fname = tempnam(NULL, "ttail_check");
  51. if(!(fp = fopen(fname, "w+")))
  52. {
  53. perror("Unable to create file for testing");
  54. ck_abort_msg("Unable to create file for testing");
  55. }
  56. if(fclose(fp))
  57. {
  58. perror("Unable to close file for testing");
  59. ck_abort_msg("Unabe to close file for testing");
  60. }
  61. ret = ttail_add_logfile(ttail, fname);
  62. ck_assert_int_eq(ret, 0);
  63. ck_assert(ttail->logfile_name != NULL);
  64. ck_assert_str_eq(ttail->logfile_name[0], fname);
  65. ck_assert(ttail->logfile[0] != NULL);
  66. free(fname);
  67. }
  68. END_TEST
  69. START_TEST (test_init_same_exist_logfilename)
  70. {
  71. char *fname;
  72. int ret;
  73. FILE *fp;
  74. fname = tempnam(NULL, "ttail_check");
  75. if(!(fp = fopen(fname, "w+")))
  76. {
  77. perror("Unable to create file for testing");
  78. ck_abort_msg("Unable to create file for testing");
  79. }
  80. if(fclose(fp))
  81. {
  82. perror("Unable to close file for testing");
  83. ck_abort_msg("Unabe to close file for testing");
  84. }
  85. ret = ttail_add_logfile(ttail, fname);
  86. ck_assert_int_eq(ret, 0);
  87. ret = ttail_add_logfile(ttail, fname);
  88. ck_assert_int_eq(ret, -1);
  89. ck_assert_int_eq(ttail->logfile_sz, 1);
  90. ck_assert(ttail->logfile_name != NULL);
  91. ck_assert_str_eq(ttail->logfile_name[0], fname);
  92. ck_assert(ttail->logfile[0] != NULL);
  93. free(fname);
  94. }
  95. END_TEST
  96. START_TEST (test_init_same_nonexist_logfilename)
  97. {
  98. char *fname;
  99. int ret;
  100. fname = tempnam(NULL, "ttail_check");
  101. ret = ttail_add_logfile(ttail, fname);
  102. ck_assert_int_eq(ret, 1);
  103. ret = ttail_add_logfile(ttail, fname);
  104. ck_assert_int_eq(ret, -1);
  105. ck_assert_int_eq(ttail->logfile_sz, 1);
  106. ck_assert(ttail->logfile_name != NULL);
  107. ck_assert_str_eq(ttail->logfile_name[0], fname);
  108. ck_assert(ttail->logfile[0] == NULL);
  109. free(fname);
  110. }
  111. END_TEST
  112. START_TEST (test_init_multiple_logfilename)
  113. {
  114. char *fname[20];
  115. int ret;
  116. int i, j;
  117. for(i=0;i<20;i++)
  118. {
  119. fname[i] = tempnam(NULL, "ttail_check");
  120. }
  121. for(i=0; i<20; i++)
  122. {
  123. for(j=0; j<i; j++)
  124. {
  125. ret = ttail_add_logfile(ttail, fname[j]);
  126. ck_assert_int_eq(ret, -1);
  127. ck_assert_int_eq(ttail->logfile_sz, i);
  128. }
  129. ret = ttail_add_logfile(ttail, fname[i]);
  130. ck_assert_int_eq(ret, 1);
  131. ck_assert_int_eq(ttail->logfile_sz, i+1);
  132. for(j=0; j<i+1; j++)
  133. {
  134. ck_assert_str_eq(ttail->logfile_name[j], fname[j]);
  135. ck_assert(ttail->logfile[j] == NULL);
  136. }
  137. }
  138. for(i=0; i<20; i++)
  139. {
  140. free(fname[i]);
  141. }
  142. }
  143. END_TEST
  144. /*
  145. * ttail_set_prefix() tests
  146. */
  147. START_TEST (test_init_prefix)
  148. {
  149. int ret;
  150. ret = ttail_set_prefix(ttail, "^[^ ]+ ");
  151. ck_assert_int_eq(ret, 0);
  152. ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
  153. }
  154. END_TEST
  155. START_TEST (test_init_bad_prefix)
  156. {
  157. int ret;
  158. ret = ttail_set_prefix(ttail, "^[^ + ");
  159. ck_assert_int_eq(ret, -1);
  160. ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == 0);
  161. }
  162. END_TEST
  163. START_TEST (test_init_again_prefix)
  164. {
  165. int ret;
  166. ret = ttail_set_prefix(ttail, "^[^ ]+ ");
  167. ck_assert_int_eq(ret, 0);
  168. ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
  169. ret = ttail_set_prefix(ttail, "^[^ + ");
  170. ck_assert_int_eq(ret, 1);
  171. ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
  172. }
  173. END_TEST
  174. START_TEST (test_init_againbad_prefix)
  175. {
  176. int ret;
  177. ret = ttail_set_prefix(ttail, "^[^ + ");
  178. ck_assert_int_eq(ret, -1);
  179. ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == 0);
  180. ret = ttail_set_prefix(ttail, "^[^ ]+ ");
  181. ck_assert_int_eq(ret, 0);
  182. ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
  183. }
  184. END_TEST
  185. /*
  186. * ttail_set_fmt() checks
  187. */
  188. START_TEST (test_init_fmt)
  189. {
  190. int ret;
  191. ret = ttail_set_fmt(ttail, "%B");
  192. ck_assert_int_eq(ret, 0);
  193. ck_assert_int_eq(ttail->flag & TTAIL_FLAG_FORMAT, TTAIL_FLAG_FORMAT);
  194. ck_assert_str_eq(ttail->fmt, "%B");
  195. }
  196. END_TEST
  197. START_TEST (test_init_fmt_again)
  198. {
  199. int ret;
  200. ttail_set_fmt(ttail, "%B");
  201. ret = ttail_set_fmt(ttail, "%b");
  202. ck_assert_int_eq(ret, -1);
  203. ck_assert_int_eq(ttail->flag & TTAIL_FLAG_FORMAT, TTAIL_FLAG_FORMAT);
  204. ck_assert_str_eq(ttail->fmt, "%B");
  205. }
  206. END_TEST
  207. /*
  208. * ttail_format_guess() tests
  209. */
  210. START_TEST (test_init_guess_date)
  211. {
  212. int ret;
  213. struct tm tm;
  214. char res[] = "%Y/%m/%d";
  215. ret = ttail_format_guess(ttail, "1988/10/22", &tm);
  216. ck_assert_int_ne(ret, -1);
  217. ck_assert_str_eq(fmt[ret], res);
  218. ck_assert(ttail->fmt != NULL);
  219. ck_assert_str_eq(ttail->fmt, res);
  220. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  221. ck_assert_int_eq(tm.tm_year, 88);
  222. ck_assert_int_eq(tm.tm_mon, 9);
  223. ck_assert_int_eq(tm.tm_mday, 22);
  224. ck_assert_int_eq(tm.tm_hour, 0);
  225. ck_assert_int_eq(tm.tm_min, 0);
  226. ck_assert_int_eq(tm.tm_sec, 0);
  227. }
  228. END_TEST
  229. START_TEST (test_init_guess_datetime)
  230. {
  231. int ret;
  232. struct tm tm;
  233. char res[] = "%Y/%m/%d:%H:%M";
  234. ret = ttail_format_guess(ttail, "1988/10/22:22:10:00", &tm);
  235. ck_assert_int_ne(ret, -1);
  236. ck_assert_str_eq(fmt[ret], res);
  237. ck_assert(ttail->fmt != NULL);
  238. ck_assert_str_eq(ttail->fmt, res);
  239. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  240. ck_assert_int_eq(tm.tm_year, 88);
  241. ck_assert_int_eq(tm.tm_mon, 9);
  242. ck_assert_int_eq(tm.tm_mday, 22);
  243. ck_assert_int_eq(tm.tm_hour, 22);
  244. ck_assert_int_eq(tm.tm_min, 10);
  245. ck_assert_int_eq(tm.tm_sec, 0);
  246. }
  247. END_TEST
  248. START_TEST (test_init_guess_datetime2)
  249. {
  250. int ret;
  251. struct tm tm;
  252. char res[] = "%B%n%d %H:%M:%S";
  253. ret = ttail_format_guess(ttail, "Mar 6 00:01:39 pilgrim dhclient", &tm);
  254. ck_assert_int_ne(ret, -1);
  255. ck_assert_str_eq(fmt[ret], res);
  256. ck_assert(ttail->fmt != NULL);
  257. ck_assert_str_eq(ttail->fmt, res);
  258. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  259. ck_assert_int_eq(tm.tm_year, 0);
  260. ck_assert_int_eq(tm.tm_mon, 2);
  261. ck_assert_int_eq(tm.tm_mday, 6);
  262. ck_assert_int_eq(tm.tm_hour, 0);
  263. ck_assert_int_eq(tm.tm_min, 1);
  264. ck_assert_int_eq(tm.tm_sec, 39);
  265. }
  266. END_TEST
  267. START_TEST (test_init_guess_noguess)
  268. {
  269. int ret;
  270. struct tm tm;
  271. ret = ttail_format_guess(ttail, "notadate", &tm);
  272. ck_assert_int_eq(ret, -1);
  273. ck_assert(ttail->fmt == NULL);
  274. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
  275. ck_assert_int_eq(tm.tm_year, 0);
  276. ck_assert_int_eq(tm.tm_mon, 0);
  277. ck_assert_int_eq(tm.tm_mday, 0);
  278. ck_assert_int_eq(tm.tm_hour, 0);
  279. ck_assert_int_eq(tm.tm_min, 0);
  280. ck_assert_int_eq(tm.tm_sec, 0);
  281. }
  282. END_TEST
  283. START_TEST (test_init_guess_date_notm)
  284. {
  285. int ret;
  286. char res[] = "%Y/%m/%d";
  287. ret = ttail_format_guess(ttail, "1988/10/22", NULL);
  288. ck_assert_int_ne(ret, -1);
  289. ck_assert_str_eq(fmt[ret], res);
  290. ck_assert(ttail->fmt != NULL);
  291. ck_assert_str_eq(ttail->fmt, res);
  292. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  293. }
  294. END_TEST
  295. START_TEST (test_init_guess_noguess_notm)
  296. {
  297. int ret;
  298. struct tm tm;
  299. ret = ttail_format_guess(ttail, "notadate", &tm);
  300. ck_assert_int_eq(ret, -1);
  301. ck_assert(ttail->fmt == NULL);
  302. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
  303. }
  304. END_TEST
  305. START_TEST (test_init_guess_fmt_set)
  306. {
  307. int ret;
  308. char res[] = "%Y/%m/%d";
  309. ret = ttail_format_guess(ttail, "1988/10/22", NULL);
  310. ck_assert_str_eq(fmt[ret], res);
  311. ret = ttail_format_guess(ttail, "1988/10/22", NULL);
  312. ck_assert_int_eq(ret, -2);
  313. ck_assert_str_eq(ttail->fmt, res);
  314. ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
  315. }
  316. END_TEST
  317. /*
  318. * ttail_set_dates() tests
  319. */
  320. START_TEST (test_init_setdates_nothing)
  321. {
  322. int ret;
  323. char *arg[] = {NULL, NULL};
  324. struct tm zero;
  325. memset(&zero, -1, sizeof(struct tm));
  326. ret = ttail_set_dates(ttail, arg);
  327. ck_assert_int_eq(ret, 0);
  328. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
  329. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
  330. ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
  331. ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
  332. }
  333. END_TEST
  334. START_TEST (test_init_setdates_nofmt_min)
  335. {
  336. int ret;
  337. char *arg[] = {"88/10/22", NULL};
  338. struct tm zero;
  339. char *arg0;
  340. arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
  341. if(!arg0)
  342. {
  343. perror("Malloc failed for argument");
  344. ck_abort_msg("Unable to allocate memory");
  345. }
  346. strcpy(arg0, arg[0]);
  347. arg[0]=arg0;
  348. memset(&zero, -1, sizeof(struct tm));
  349. ret = ttail_set_dates(ttail, arg);
  350. ck_assert_int_eq(ret, 0);
  351. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
  352. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
  353. ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
  354. ck_assert_int_eq(ttail->date_min.tm_year, 88);
  355. ck_assert_int_eq(ttail->date_min.tm_mon, 9);
  356. ck_assert_int_eq(ttail->date_min.tm_mday, 22);
  357. ck_assert_int_eq(ttail->date_min.tm_hour, 0);
  358. ck_assert_int_eq(ttail->date_min.tm_min, 0);
  359. ck_assert_int_eq(ttail->date_min.tm_sec, 0);
  360. }
  361. END_TEST
  362. START_TEST (test_init_setdates_nofmt_max)
  363. {
  364. int ret;
  365. char *arg[] = {NULL, "88/10/22"};
  366. struct tm zero;
  367. char *arg1;
  368. arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
  369. if(!arg1)
  370. {
  371. perror("Malloc failed for argument");
  372. ck_abort_msg("Unable to allocate memory");
  373. }
  374. strcpy(arg1, arg[1]);
  375. arg[1]=arg1;
  376. memset(&zero, -1, sizeof(struct tm));
  377. ret = ttail_set_dates(ttail, arg);
  378. ck_assert_int_eq(ret, 0);
  379. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
  380. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
  381. ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
  382. ck_assert_int_eq(ttail->date_max.tm_year, 88);
  383. ck_assert_int_eq(ttail->date_max.tm_mon, 9);
  384. ck_assert_int_eq(ttail->date_max.tm_mday, 22);
  385. ck_assert_int_eq(ttail->date_max.tm_hour, 0);
  386. ck_assert_int_eq(ttail->date_max.tm_min, 0);
  387. ck_assert_int_eq(ttail->date_max.tm_sec, 0);
  388. }
  389. END_TEST
  390. START_TEST (test_init_setdates_nofmt_both)
  391. {
  392. int ret;
  393. char *arg[] = {"1988/10/22", "2088/10/22"};
  394. struct tm zero;
  395. char *arg0, *arg1;
  396. arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
  397. if(!arg0)
  398. {
  399. perror("Malloc failed for argument");
  400. ck_abort_msg("Unable to allocate memory");
  401. }
  402. strcpy(arg0, arg[0]);
  403. arg[0]=arg0;
  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. memset(&zero, 0, sizeof(struct tm));
  413. ret = ttail_set_dates(ttail, arg);
  414. ck_assert_int_eq(ret, 0);
  415. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
  416. ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
  417. ck_assert_int_eq(ttail->date_min.tm_year, 88);
  418. ck_assert_int_eq(ttail->date_min.tm_mon, 9);
  419. ck_assert_int_eq(ttail->date_min.tm_mday, 22);
  420. ck_assert_int_eq(ttail->date_min.tm_hour, 0);
  421. ck_assert_int_eq(ttail->date_min.tm_min, 0);
  422. ck_assert_int_eq(ttail->date_min.tm_sec, 0);
  423. ck_assert_int_eq(ttail->date_max.tm_year, 188);
  424. ck_assert_int_eq(ttail->date_max.tm_mon, 9);
  425. ck_assert_int_eq(ttail->date_max.tm_mday, 22);
  426. ck_assert_int_eq(ttail->date_max.tm_hour, -1);
  427. ck_assert_int_eq(ttail->date_max.tm_min, -1);
  428. ck_assert_int_eq(ttail->date_max.tm_sec, -1);
  429. }
  430. END_TEST
  431. START_TEST (test_init_check_bad1)
  432. {
  433. ck_assert_int_eq(ttail_init_check(ttail), -1);
  434. }
  435. END_TEST
  436. START_TEST (test_init_check_bad2)
  437. {
  438. ttail->flag |= TTAIL_FLAG_DATE_MAX;
  439. ck_assert_int_eq(ttail_init_check(ttail), -1);
  440. }
  441. END_TEST
  442. START_TEST (test_init_check1)
  443. {
  444. char *arg[] = {"88/10/22", NULL};
  445. struct tm zero;
  446. char *arg0;
  447. arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
  448. if(!arg0)
  449. {
  450. perror("Malloc failed for argument");
  451. ck_abort_msg("Unable to allocate memory");
  452. }
  453. strcpy(arg0, arg[0]);
  454. arg[0]=arg0;
  455. memset(&zero, 0, sizeof(struct tm));
  456. ttail_set_dates(ttail, arg);
  457. ck_assert_int_eq(ttail_init_check(ttail), 0);
  458. }
  459. END_TEST
  460. Suite * ttail_init_suite(void)
  461. {
  462. Suite *s;
  463. TCase *tc_init_logfile, *tc_init_prefix , *tc_init_fmt, \
  464. *tc_init_fmt_guess, *tc_init_set_dates, *tc_init_check;
  465. s = suite_create("ttail init checks");
  466. tc_init_logfile = tcase_create("logfile init checks");
  467. tcase_add_checked_fixture(tc_init_logfile,
  468. setup_ttail_empty, teardown_ttail);
  469. tcase_add_test(tc_init_logfile, test_init_empty_logfilename);
  470. tcase_add_test(tc_init_logfile, test_init_nonexist_logfilename);
  471. tcase_add_test(tc_init_logfile, test_init_exist_logfilename);
  472. tcase_add_test(tc_init_logfile, test_init_same_exist_logfilename);
  473. tcase_add_test(tc_init_logfile, test_init_same_nonexist_logfilename);
  474. tcase_add_test(tc_init_logfile, test_init_multiple_logfilename);
  475. tc_init_prefix = tcase_create("date prefix regex init checks");
  476. tcase_add_checked_fixture(tc_init_prefix,
  477. setup_ttail_empty, teardown_ttail);
  478. tcase_add_test(tc_init_prefix, test_init_prefix);
  479. tcase_add_test(tc_init_prefix, test_init_bad_prefix);
  480. tcase_add_test(tc_init_prefix, test_init_again_prefix);
  481. tcase_add_test(tc_init_prefix, test_init_againbad_prefix);
  482. tc_init_fmt = tcase_create("date format init checks");
  483. tcase_add_checked_fixture(tc_init_fmt,
  484. setup_ttail_empty, teardown_ttail);
  485. tcase_add_test(tc_init_fmt, test_init_fmt);
  486. tcase_add_test(tc_init_fmt, test_init_fmt_again);
  487. tc_init_fmt_guess = tcase_create("date format guess init checks");
  488. tcase_add_checked_fixture(tc_init_fmt_guess,
  489. setup_ttail_empty, teardown_ttail);
  490. tcase_add_test(tc_init_fmt_guess, test_init_guess_date);
  491. tcase_add_test(tc_init_fmt_guess, test_init_guess_datetime);
  492. tcase_add_test(tc_init_fmt_guess, test_init_guess_datetime2);
  493. tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess);
  494. tcase_add_test(tc_init_fmt_guess, test_init_guess_date_notm);
  495. tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess_notm);
  496. tcase_add_test(tc_init_fmt_guess, test_init_guess_fmt_set);
  497. tc_init_set_dates = tcase_create("dates min/max init checks");
  498. tcase_add_checked_fixture(tc_init_set_dates,
  499. setup_ttail_empty, teardown_ttail);
  500. tcase_add_test(tc_init_set_dates, test_init_setdates_nothing);
  501. tcase_add_test(tc_init_set_dates, test_init_setdates_nofmt_min);
  502. tcase_add_test(tc_init_set_dates, test_init_setdates_nofmt_max);
  503. tcase_add_test(tc_init_set_dates, test_init_setdates_nofmt_both);
  504. tc_init_check = tcase_create("ttail_init_check() checks");
  505. tcase_add_checked_fixture(tc_init_check,
  506. setup_ttail_empty, teardown_ttail);
  507. tcase_add_test(tc_init_fmt_guess, test_init_check_bad1);
  508. tcase_add_test(tc_init_fmt_guess, test_init_check_bad2);
  509. tcase_add_test(tc_init_fmt_guess, test_init_check1);
  510. suite_add_tcase(s, tc_init_logfile);
  511. suite_add_tcase(s, tc_init_prefix);
  512. suite_add_tcase(s, tc_init_fmt);
  513. suite_add_tcase(s, tc_init_fmt_guess);
  514. suite_add_tcase(s, tc_init_set_dates);
  515. suite_add_tcase(s, tc_init_check);
  516. return s;
  517. }
  518. int main(void)
  519. {
  520. int number_failed = 0;
  521. SRunner *sr;
  522. sr = srunner_create(ttail_init_suite());
  523. srunner_set_fork_status(sr, CK_FORK);
  524. srunner_run_all(sr,CK_VERBOSE);
  525. number_failed = srunner_ntests_failed(sr);
  526. srunner_free(sr);
  527. return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
  528. }