Now ttail is able to sort logfiles given as arguement. The sort function _ttail_file_sort place files with no valid date to the end of the file list and is able to detect if some files overlaps. No tests written...
		
			
				
	
	
		
			115 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			115 lines
		
	
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
| #include <check.h>
 | |
| #include <stdio.h>
 | |
| #include <libgen.h>
 | |
| 
 | |
| #include "ttail_check.h"
 | |
| #include "ttail.h"
 | |
| #include "ttail_init.h"
 | |
| #include "ttail_search.h"
 | |
| 
 | |
| /*
 | |
|  *	tests ttail_search_closest_files()
 | |
|  */
 | |
| 
 | |
| START_TEST (test_search_files1)
 | |
| {
 | |
| 	int ret;
 | |
| 	size_t i;
 | |
| 	struct tm tm;
 | |
| 	memset(&tm, 0, sizeof(tm));
 | |
| 	for(i=1;i<ttail->logfile_sz;i++)
 | |
| 	{
 | |
| 		fclose(ttail->logfile[i]);
 | |
| 		ttail->logfile[i] = NULL;
 | |
| 	}
 | |
| 	ttail->flag |= TTAIL_FLAG_PREFIX;
 | |
| 	ttail->prefix_sz = 0;
 | |
| 	ttail_set_fmt(ttail, "%B%n%d %H:%M");
 | |
| 	memcpy(&(ttail->date_min), &tm, sizeof(tm));
 | |
| 	ttail->flag |= TTAIL_FLAG_DATE_MIN;
 | |
| 
 | |
| 	ret = ttail_search_files_init(ttail);
 | |
| 	ck_assert_int_eq(ret,0);
 | |
| 
 | |
| 	ret = _ttail_search_closest_files(ttail);
 | |
| 	ck_assert_int_eq(ret, 0);
 | |
| 	ck_assert(ttail->session->file.off_min.id == 0);
 | |
| 	ck_assert(ttail->session->file.off_min.off == 0);
 | |
| }
 | |
| END_TEST
 | |
| 
 | |
| START_TEST (test_search_files2)
 | |
| {
 | |
| 	int ret;
 | |
| 	size_t i;
 | |
| 	struct tm tm;
 | |
| 	memset(&tm, 0, sizeof(tm));
 | |
| 	for(i=1;i<ttail->logfile_sz;i++)
 | |
| 	{
 | |
| 		fclose(ttail->logfile[i]);
 | |
| 		ttail->logfile[i] = NULL;
 | |
| 	}
 | |
| 	ttail->flag |= TTAIL_FLAG_PREFIX;
 | |
| 	ttail->prefix_sz = 0;
 | |
| 	ttail_set_fmt(ttail, "%B%n%d %H:%M");
 | |
| 
 | |
| 	tm.tm_year = -1;
 | |
| 	tm.tm_mon = 2;
 | |
| 	tm.tm_mday = 6;
 | |
| 	tm.tm_hour = 0;
 | |
| 	tm.tm_min = 29;
 | |
| 	tm.tm_sec = -1;
 | |
| 	memcpy(&(ttail->date_min), &tm, sizeof(tm));
 | |
| 	ttail->flag |= TTAIL_FLAG_DATE_MIN;
 | |
| 	
 | |
| 	ret = ttail_search_files_init(ttail);
 | |
| 	ck_assert_int_eq(ret,0);
 | |
| 
 | |
| 	ret = _ttail_search_closest_files(ttail);
 | |
| 	ck_assert_int_eq(ret, 0);
 | |
| 	ck_assert(ttail->session->file.off_min.id == 0);
 | |
| 	ck_assert_int_eq(ttail->session->file.off_min.off, 221);
 | |
| }
 | |
| END_TEST
 | |
| 
 | |
| START_TEST (test_search_files3)
 | |
| {
 | |
| 	int ret;
 | |
| 	size_t i;
 | |
| 	struct tm tm;
 | |
| 	memset(&tm, 0, sizeof(tm));
 | |
| 	for(i=1;i<ttail->logfile_sz-1;i++)
 | |
| 	{
 | |
| 		fclose(ttail->logfile[i]);
 | |
| 		ttail->logfile[i] = NULL;
 | |
| 	}
 | |
| 	ttail->flag |= TTAIL_FLAG_PREFIX;
 | |
| 	ttail->prefix_sz = 0;
 | |
| 	ttail_set_fmt(ttail, "%B%n%d %H:%M");
 | |
| 
 | |
| 	tm.tm_year = -1;
 | |
| 	tm.tm_mon = 2;
 | |
| 	tm.tm_mday = 6;
 | |
| 	tm.tm_hour = 1;
 | |
| 	tm.tm_min = 0;
 | |
| 	tm.tm_sec = -1;
 | |
| 	memcpy(&(ttail->date_min), &tm, sizeof(tm));
 | |
| 	ttail->flag |= TTAIL_FLAG_DATE_MIN;
 | |
| 
 | |
| 	ret = ttail_search_files_init(ttail);
 | |
| 	ck_assert_int_eq(ret,0);
 | |
| 
 | |
| 	ret = _ttail_search_closest_files(ttail);
 | |
| 	ck_assert_int_eq(ret, 0);
 | |
| 	ck_assert_int_eq(ttail->session->file.off_min.id, 1);
 | |
| 	ck_assert_int_eq(ttail->session->file.off_min.off, 0);
 | |
| }
 | |
| END_TEST
 | |
| 
 | |
| TTAIL_CHECK_START("ttail search_files checks", "ttail_logline2date() checks")
 | |
| 	TTAIL_SET_FIXTURE(setup_closest_fileinit, teardown_closest_fileinit);
 | |
| 	TTAIL_ADD_TEST(test_search_files1);
 | |
| 	TTAIL_ADD_TEST(test_search_files2);
 | |
| 	TTAIL_ADD_TEST(test_search_files3);
 | |
| TTAIL_CHECK_END
 | |
| 
 |