Browse Source

Tests update

Yann Weber 7 years ago
parent
commit
6ed34f4e0f
2 changed files with 28 additions and 22 deletions
  1. 13
    13
      tests/ttail_argparse_check.c
  2. 15
    9
      tests/ttail_search_check.c

+ 13
- 13
tests/ttail_argparse_check.c View File

190
 START_TEST (test_argparse_file_non_exist)
190
 START_TEST (test_argparse_file_non_exist)
191
 {
191
 {
192
 	ttail_t *t;
192
 	ttail_t *t;
193
-	char *args[3] = {"foo", "-l", NULL};
193
+	char *args[4] = {"foo", "-d", "Mar 6 13:37", NULL};
194
 
194
 
195
-	args[2] = fname[FNAME_NO_EXIST];
196
-	t = ttail_init(3, args);
195
+	args[3] = fname[FNAME_NO_EXIST];
196
+	t = ttail_init(4, args);
197
 	ck_assert_msg(t != NULL, "init failed");
197
 	ck_assert_msg(t != NULL, "init failed");
198
 
198
 
199
 	ck_assert_msg(t->logfile_sz == 1,
199
 	ck_assert_msg(t->logfile_sz == 1,
200
 		"ttail_t.logfile_sz should be 1");
200
 		"ttail_t.logfile_sz should be 1");
201
-	ck_assert_msg(strcmp(t->logfile_name[0], args[2]) == 0,
201
+	ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
202
 		"ttail_t.logfile_name[0] does not contain the filename");
202
 		"ttail_t.logfile_name[0] does not contain the filename");
203
 	ck_assert_msg(t->logfile[0] == NULL,
203
 	ck_assert_msg(t->logfile[0] == NULL,
204
 		"ttail_t.logfile[0] should be NULL");
204
 		"ttail_t.logfile[0] should be NULL");
211
 START_TEST (test_argparse_file_exist)
211
 START_TEST (test_argparse_file_exist)
212
 {
212
 {
213
 	ttail_t *t;
213
 	ttail_t *t;
214
-	char *args[3] = {"foo", "-l", NULL};
214
+	char *args[4] = {"foo", "-d", "Mar 10 13:37", NULL};
215
 
215
 
216
-	args[2] = fname[FNAME_EXIST];
216
+	args[3] = fname[FNAME_EXIST];
217
 
217
 
218
-	t = ttail_init(3, args);
218
+	t = ttail_init(4, args);
219
 	ck_assert_msg(t != NULL, "init failed");
219
 	ck_assert_msg(t != NULL, "init failed");
220
 
220
 
221
 	ck_assert_msg(t->logfile_sz == 1,
221
 	ck_assert_msg(t->logfile_sz == 1,
222
 		"ttail_t.logfile_sz should be 1");
222
 		"ttail_t.logfile_sz should be 1");
223
-	ck_assert_msg(strcmp(t->logfile_name[0], args[2]) == 0,
223
+	ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
224
 		"ttail_t.logfile_name[0] does not contain the filename");
224
 		"ttail_t.logfile_name[0] does not contain the filename");
225
 	ck_assert_msg(t->logfile[0] != NULL,
225
 	ck_assert_msg(t->logfile[0] != NULL,
226
 		"ttail_t.logfile[0] shouldn't be NULL");
226
 		"ttail_t.logfile[0] shouldn't be NULL");
234
 {
234
 {
235
 	ttail_t *t;
235
 	ttail_t *t;
236
 	int i;
236
 	int i;
237
-	char *args[11] = {"foo", "-l", NULL, "-l", NULL,
238
-		"-l", NULL, "-l", NULL, "-l", NULL};
237
+	char *args[8] = {"foo", "-d", "mar 10 13:37", NULL, NULL, NULL, NULL,
238
+		NULL};
239
 	
239
 	
240
 	for(i=0; i<__Fname_sz; i++)
240
 	for(i=0; i<__Fname_sz; i++)
241
 	{
241
 	{
242
-		args[(i*2)+2] = fname[i];
242
+		args[i+3] = fname[i];
243
 	}
243
 	}
244
 
244
 
245
-	t = ttail_init(11, args);
245
+	t = ttail_init(8, args);
246
 	ck_assert_msg(t != NULL, "init failed");
246
 	ck_assert_msg(t != NULL, "init failed");
247
 	
247
 	
248
 	ck_assert_msg(t->logfile_sz == __Fname_sz,
248
 	ck_assert_msg(t->logfile_sz == __Fname_sz,
250
 
250
 
251
 	for(i=0;i<__Fname_sz; i++)
251
 	for(i=0;i<__Fname_sz; i++)
252
 	{
252
 	{
253
-		ck_assert_msg(strcmp(t->logfile_name[i], args[(i*2)+2]) == 0,
253
+		ck_assert_msg(strcmp(t->logfile_name[i], args[i+3]) == 0,
254
 			"some filename corrupted in ttail_t.logfile_name");
254
 			"some filename corrupted in ttail_t.logfile_name");
255
 		if(i%2)
255
 		if(i%2)
256
 		{
256
 		{

+ 15
- 9
tests/ttail_search_check.c View File

319
 	ttail->flag |= TTAIL_FLAG_PREFIX;
319
 	ttail->flag |= TTAIL_FLAG_PREFIX;
320
 	ttail->prefix_sz = 0;
320
 	ttail->prefix_sz = 0;
321
 	ttail_set_fmt(ttail, "%B%n%d %H:%M");
321
 	ttail_set_fmt(ttail, "%B%n%d %H:%M");
322
+	memcpy(&(ttail->date_min), &tm, sizeof(tm));
323
+	ttail->flag |= TTAIL_FLAG_DATE_MIN;
322
 
324
 
323
-	ret = _ttail_search_closest_files(ttail, &tm);
325
+	ret = _ttail_search_closest_files(ttail);
324
 	ck_assert_int_eq(ret, 0);
326
 	ck_assert_int_eq(ret, 0);
325
-	ck_assert(ttail->session->file.id == 0);
326
-	ck_assert(ttail->session->file.off == 0);
327
+	ck_assert(ttail->session->file.off_min.id == 0);
328
+	ck_assert(ttail->session->file.off_min.off == 0);
327
 }
329
 }
328
 END_TEST
330
 END_TEST
329
 
331
 
348
 	tm.tm_hour = 0;
350
 	tm.tm_hour = 0;
349
 	tm.tm_min = 29;
351
 	tm.tm_min = 29;
350
 	tm.tm_sec = -1;
352
 	tm.tm_sec = -1;
353
+	memcpy(&(ttail->date_min), &tm, sizeof(tm));
354
+	ttail->flag |= TTAIL_FLAG_DATE_MIN;
351
 	
355
 	
352
-	ret = _ttail_search_closest_files(ttail, &tm);
356
+	ret = _ttail_search_closest_files(ttail);
353
 	ck_assert_int_eq(ret, 0);
357
 	ck_assert_int_eq(ret, 0);
354
-	ck_assert(ttail->session->file.id == 0);
355
-	ck_assert_int_eq(ttail->session->file.off, 221);
358
+	ck_assert(ttail->session->file.off_min.id == 0);
359
+	ck_assert_int_eq(ttail->session->file.off_min.off, 221);
356
 }
360
 }
357
 END_TEST
361
 END_TEST
358
 
362
 
377
 	tm.tm_hour = 1;
381
 	tm.tm_hour = 1;
378
 	tm.tm_min = 0;
382
 	tm.tm_min = 0;
379
 	tm.tm_sec = -1;
383
 	tm.tm_sec = -1;
384
+	memcpy(&(ttail->date_min), &tm, sizeof(tm));
385
+	ttail->flag |= TTAIL_FLAG_DATE_MIN;
380
 
386
 
381
-	ret = _ttail_search_closest_files(ttail, &tm);
387
+	ret = _ttail_search_closest_files(ttail);
382
 	ck_assert_int_eq(ret, 0);
388
 	ck_assert_int_eq(ret, 0);
383
-	ck_assert_int_eq(ttail->session->file.id, 5);
384
-	ck_assert_int_eq(ttail->session->file.off, 0);
389
+	ck_assert_int_eq(ttail->session->file.off_min.id, 5);
390
+	ck_assert_int_eq(ttail->session->file.off_min.off, 0);
385
 }
391
 }
386
 END_TEST
392
 END_TEST
387
 
393
 

Loading…
Cancel
Save