123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- #ifndef _ttail_check_h__
- #define _ttail_check_h__
-
- #include <check.h>
- #include <errno.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <libgen.h>
-
- #include "ttail.h"
- #include "ttail_init.h"
-
- ttail_t *ttail;
- #define __Fname_sz 5
- #define FNAME_NO_EXIST 0
- #define FNAME_EXIST 1
-
- char *fname[__Fname_sz];
- /*date formats*/
- char *fmt[] = TTAIL_DEFAULT_FORMATS;
- /* logfiles samples */
- char *samples[6] = { "./samples/1.log", "./samples/2.log", "./samples/3.log",\
- "./samples/4.log", "./samples/5.log", "./samples/1.1.log"};
- off_t samples_sz[6] = { 442, 0, 893, 2587, 2310, 220 };
-
- void teardown_ttail(void)
- {
- ttail_free(ttail);
- }
-
- void setup_ttail_empty(void)
- {
- ttail = ttail_init(1, (char**)&"foo");
- }
-
- void setup_fname(void)
- {
- int i;
- FILE *fp;
- for(i=0;i<__Fname_sz;i++)
- {
- fname[i] = NULL;
- }
-
- for(i=0; i<__Fname_sz; i++)
- {
- fname[i] = tempnam(NULL, "ttail_check");
- if(i%2)
- {
- if((fp=fopen(fname[i], "w+")) == NULL)
- {
- perror("Unable to create file for testing");
- ck_abort_msg("Unable to create file for testing");
- }
- if(fclose(fp))
- {
- perror("Unable to close file for testing");
- ck_abort_msg("Unable to close file for testing");
-
- }
- }
- }
- }
-
- void teardown_fname(void)
- {
- int i;
- for(i=0; i<__Fname_sz; i++)
- {
- unlink(fname[i]);
- if(fname[i] != NULL)
- {
- free(fname[i]);
- }
- }
- }
-
- void setup_file_line(void)
- {
- setup_ttail_empty();
- ttail_add_logfile(ttail, samples[0]);
- }
-
- void teardown_closest(void)
- {
-
- ttail_free(ttail);
- }
-
- void setup_closest(void)
- {
- ttail = ttail_init(1, (char**)&"foo");
- }
-
- void setup_closest_fileinit(void)
- {
- size_t i;
- setup_closest();
- for(i=0; i<6; i++)
- {
- ttail_add_logfile(ttail, samples[i]);
- }
- }
-
- void teardown_closest_fileinit(void)
- {
- _ttail_search_file_free(ttail);
- teardown_closest();
- }
-
- /**@brief Start a ttail test
- *@param const char* suite_str test suite string
- *@param const char* tc_str test case string
- */
- #define TTAIL_CHECK_START(suite_str, tc_str) \
- Suite * ttail_test_suite(void) \
- {\
- Suite *s;\
- TCase *tc;\
- s = suite_create(suite_str);\
- tc = tcase_create(tc_str);
-
-
- /**@brief Set the setup & teardown fixture
- *@param void (*setup)()
- *@param void (*teardown)()
- */
- #define TTAIL_SET_FIXTURE(setup, teardown) \
- tcase_add_checked_fixture(tc, setup, teardown)
- /**@brief Add a test function defined using START_TEST(name) { ... } END_TEST
- */
- #define TTAIL_ADD_TEST(test) tcase_add_test(tc, test)
-
- /**@brief End a ttail test */
- #define TTAIL_CHECK_END \
- suite_add_tcase(s, tc);\
- return s;\
- }\
- \
- int main(int argc, char **argv) {\
- int n_fail;\
- SRunner *sr;\
- chdir(dirname(argv[0])); /* move in ./tests dir */ \
- sr = srunner_create(ttail_test_suite());\
- srunner_set_fork_status(sr, CK_FORK);\
- srunner_run_all(sr, CK_VERBOSE);\
- n_fail = srunner_ntests_failed(sr);\
- srunner_free(sr);\
- return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
- }
-
- #endif
|