Browse Source

Spliting ttail init tests

Yann Weber 7 years ago
parent
commit
1218a70822

+ 0
- 10
tests/ttail_argparse_empty.c View File

@@ -7,19 +7,9 @@
7 7
 #include "ttail.h"
8 8
 #include "ttail_init.h"
9 9
 
10
-ttail_t *ttail;
11
-
12
-void teardown_ttail(void)
13
-{
14
-	ttail_free(ttail);
15
-}
16 10
 /*
17 11
  * Empty argument parsing test case
18 12
  */
19
-void setup_ttail_empty(void)
20
-{
21
-	ttail = ttail_init(1, (char**)&"foo");
22
-}
23 13
 START_TEST (test_argparse_empty_logfilename)
24 14
 {
25 15
 	ck_assert_msg(ttail->logfile_name == NULL,

+ 0
- 48
tests/ttail_argparse_files.c View File

@@ -7,58 +7,10 @@
7 7
 #include "ttail.h"
8 8
 #include "ttail_init.h"
9 9
 
10
-ttail_t *ttail;
11
-#define __Fname_sz 5
12
-#define FNAME_NO_EXIST 0
13
-#define FNAME_EXIST 1
14
-char *fname[__Fname_sz];
15
-
16 10
 /*
17 11
  * file argument parsing
18 12
  */
19 13
 
20
-void setup_fname(void)
21
-{
22
-	int i;
23
-	FILE *fp;
24
-	for(i=0;i<__Fname_sz;i++)
25
-	{
26
-		fname[i] = NULL;
27
-	}
28
-
29
-	for(i=0; i<__Fname_sz; i++)
30
-	{
31
-		fname[i] = tempnam(NULL, "ttail_check");
32
-		if(i%2)
33
-		{
34
-			if((fp=fopen(fname[i], "w+")) == NULL)
35
-			{
36
-				perror("Unable to create file for testing");
37
-				ck_abort_msg("Unable to create file for testing");
38
-			}
39
-			if(fclose(fp))
40
-			{
41
-				perror("Unable to close file for testing");
42
-				ck_abort_msg("Unable to close file for testing");
43
-
44
-			}
45
-		}
46
-	}
47
-}
48
-
49
-void teardown_fname(void)
50
-{
51
-	int i;
52
-	for(i=0; i<__Fname_sz; i++)
53
-	{
54
-		unlink(fname[i]);
55
-		if(fname[i] != NULL)
56
-		{
57
-			free(fname[i]);
58
-		}
59
-	}
60
-}
61
-
62 14
 START_TEST (test_argparse_file_non_exist)
63 15
 {
64 16
 	ttail_t *t;

+ 63
- 0
tests/ttail_check.h View File

@@ -10,6 +10,69 @@
10 10
 #include "ttail.h"
11 11
 #include "ttail_init.h"
12 12
 
13
+ttail_t *ttail;
14
+#define __Fname_sz 5
15
+#define FNAME_NO_EXIST 0
16
+#define FNAME_EXIST 1
17
+
18
+char *fname[__Fname_sz];
19
+/*date formats*/
20
+char *fmt[] = TTAIL_DEFAULT_FORMATS;
21
+
22
+void teardown_ttail(void)
23
+{
24
+	ttail_free(ttail);
25
+}
26
+
27
+void setup_ttail_empty(void)
28
+{
29
+	ttail = ttail_init(1, (char**)&"foo");
30
+}
31
+
32
+void setup_fname(void)
33
+{
34
+	int i;
35
+	FILE *fp;
36
+	for(i=0;i<__Fname_sz;i++)
37
+	{
38
+		fname[i] = NULL;
39
+	}
40
+
41
+	for(i=0; i<__Fname_sz; i++)
42
+	{
43
+		fname[i] = tempnam(NULL, "ttail_check");
44
+		if(i%2)
45
+		{
46
+			if((fp=fopen(fname[i], "w+")) == NULL)
47
+			{
48
+				perror("Unable to create file for testing");
49
+				ck_abort_msg("Unable to create file for testing");
50
+			}
51
+			if(fclose(fp))
52
+			{
53
+				perror("Unable to close file for testing");
54
+				ck_abort_msg("Unable to close file for testing");
55
+
56
+			}
57
+		}
58
+	}
59
+}
60
+
61
+void teardown_fname(void)
62
+{
63
+	int i;
64
+	for(i=0; i<__Fname_sz; i++)
65
+	{
66
+		unlink(fname[i]);
67
+		if(fname[i] != NULL)
68
+		{
69
+			free(fname[i]);
70
+		}
71
+	}
72
+}
73
+
74
+
75
+
13 76
 
14 77
 #define TTAIL_CHECK_MAIN(suite) int main(int argc, char **argv) {\
15 78
 	int n_fail;\

+ 6
- 540
tests/ttail_init_check.c View File

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

+ 51
- 0
tests/ttail_init_format.c View File

@@ -0,0 +1,51 @@
1
+#include <check.h>
2
+#include <errno.h>
3
+#include <stdio.h>
4
+#include <unistd.h>
5
+
6
+#include "ttail_check.h"
7
+#include "ttail.h"
8
+#include "ttail_init.h"
9
+
10
+/*
11
+ * ttail_set_fmt() checks
12
+ */
13
+START_TEST (test_init_fmt)
14
+{
15
+	int ret;
16
+	ret = ttail_set_fmt(ttail, "%B");
17
+	ck_assert_int_eq(ret, 0);
18
+	ck_assert_int_eq(ttail->flag & TTAIL_FLAG_FORMAT, TTAIL_FLAG_FORMAT);
19
+	ck_assert_str_eq(ttail->fmt, "%B");
20
+}
21
+END_TEST
22
+
23
+START_TEST (test_init_fmt_again)
24
+{
25
+	int ret;
26
+	ttail_set_fmt(ttail, "%B");
27
+	ret = ttail_set_fmt(ttail, "%b");
28
+	ck_assert_int_eq(ret, -1);
29
+	ck_assert_int_eq(ttail->flag & TTAIL_FLAG_FORMAT, TTAIL_FLAG_FORMAT);
30
+	ck_assert_str_eq(ttail->fmt, "%B");
31
+}
32
+END_TEST
33
+
34
+Suite * ttail_init_suite(void)
35
+{
36
+	Suite *s;
37
+	TCase	*tc_init_fmt;
38
+
39
+	s = suite_create("ttail init checks");
40
+
41
+	tc_init_fmt = tcase_create("date format init checks");
42
+	tcase_add_checked_fixture(tc_init_fmt,
43
+		setup_ttail_empty, teardown_ttail);
44
+	tcase_add_test(tc_init_fmt, test_init_fmt);
45
+	tcase_add_test(tc_init_fmt, test_init_fmt_again);
46
+
47
+	suite_add_tcase(s, tc_init_fmt);
48
+	return s;
49
+}
50
+
51
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 149
- 0
tests/ttail_init_format_guess.c View File

@@ -0,0 +1,149 @@
1
+#include <check.h>
2
+#include <errno.h>
3
+#include <stdio.h>
4
+#include <unistd.h>
5
+
6
+#include "ttail_check.h"
7
+#include "ttail.h"
8
+#include "ttail_init.h"
9
+
10
+/*
11
+ * ttail_format_guess() tests
12
+ */
13
+START_TEST (test_init_guess_date)
14
+{
15
+	int ret;
16
+	struct tm tm;
17
+	char res[] = "%Y/%m/%d";
18
+	ret = ttail_format_guess(ttail, "1988/10/22", &tm);
19
+	ck_assert_int_ne(ret, -1);
20
+	ck_assert_str_eq(fmt[ret], res);
21
+	ck_assert(ttail->fmt != NULL);
22
+	ck_assert_str_eq(ttail->fmt, res);
23
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
24
+	ck_assert_int_eq(tm.tm_year, 88);
25
+	ck_assert_int_eq(tm.tm_mon, 9);
26
+	ck_assert_int_eq(tm.tm_mday, 22);
27
+	ck_assert_int_eq(tm.tm_hour, 0);
28
+	ck_assert_int_eq(tm.tm_min, 0);
29
+	ck_assert_int_eq(tm.tm_sec, 0);
30
+}
31
+END_TEST
32
+
33
+START_TEST (test_init_guess_datetime)
34
+{
35
+	int ret;
36
+	struct tm tm;
37
+	char res[] = "%Y/%m/%d:%H:%M";
38
+	ret = ttail_format_guess(ttail, "1988/10/22:22:10:00", &tm);
39
+	ck_assert_int_ne(ret, -1);
40
+	ck_assert_str_eq(fmt[ret], res);
41
+	ck_assert(ttail->fmt != NULL);
42
+	ck_assert_str_eq(ttail->fmt, res);
43
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
44
+	ck_assert_int_eq(tm.tm_year, 88);
45
+	ck_assert_int_eq(tm.tm_mon, 9);
46
+	ck_assert_int_eq(tm.tm_mday, 22);
47
+	ck_assert_int_eq(tm.tm_hour, 22);
48
+	ck_assert_int_eq(tm.tm_min, 10);
49
+	ck_assert_int_eq(tm.tm_sec, 0);
50
+}
51
+END_TEST
52
+
53
+START_TEST (test_init_guess_datetime2)
54
+{
55
+	int ret;
56
+	struct tm tm;
57
+	char res[] = "%B%n%d %H:%M:%S";
58
+	ret = ttail_format_guess(ttail, "Mar  6 00:01:39 pilgrim dhclient", &tm);
59
+	ck_assert_int_ne(ret, -1);
60
+	ck_assert_str_eq(fmt[ret], res);
61
+	ck_assert(ttail->fmt != NULL);
62
+	ck_assert_str_eq(ttail->fmt, res);
63
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
64
+	ck_assert_int_eq(tm.tm_year, 0);
65
+	ck_assert_int_eq(tm.tm_mon, 2);
66
+	ck_assert_int_eq(tm.tm_mday, 6);
67
+	ck_assert_int_eq(tm.tm_hour, 0);
68
+	ck_assert_int_eq(tm.tm_min, 1);
69
+	ck_assert_int_eq(tm.tm_sec, 39);
70
+}
71
+END_TEST
72
+
73
+START_TEST (test_init_guess_noguess)
74
+{
75
+	int ret;
76
+	struct tm tm;
77
+	ret = ttail_format_guess(ttail, "notadate", &tm);
78
+	ck_assert_int_eq(ret, -1);
79
+	ck_assert(ttail->fmt == NULL);
80
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
81
+	ck_assert_int_eq(tm.tm_year, 0);
82
+	ck_assert_int_eq(tm.tm_mon, 0);
83
+	ck_assert_int_eq(tm.tm_mday, 0);
84
+	ck_assert_int_eq(tm.tm_hour, 0);
85
+	ck_assert_int_eq(tm.tm_min, 0);
86
+	ck_assert_int_eq(tm.tm_sec, 0);
87
+}
88
+END_TEST
89
+
90
+START_TEST (test_init_guess_date_notm)
91
+{
92
+	int ret;
93
+	char res[] = "%Y/%m/%d";
94
+	ret = ttail_format_guess(ttail, "1988/10/22", NULL);
95
+	ck_assert_int_ne(ret, -1);
96
+	ck_assert_str_eq(fmt[ret], res);
97
+	ck_assert(ttail->fmt != NULL);
98
+	ck_assert_str_eq(ttail->fmt, res);
99
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
100
+}
101
+END_TEST
102
+
103
+START_TEST (test_init_guess_noguess_notm)
104
+{
105
+	int ret;
106
+	struct tm tm;
107
+	ret = ttail_format_guess(ttail, "notadate", &tm);
108
+	ck_assert_int_eq(ret, -1);
109
+	ck_assert(ttail->fmt == NULL);
110
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == 0);
111
+}
112
+END_TEST
113
+
114
+START_TEST (test_init_guess_fmt_set)
115
+{
116
+	int ret;
117
+	char res[] = "%Y/%m/%d";
118
+	ret = ttail_format_guess(ttail, "1988/10/22", NULL);
119
+	ck_assert_str_eq(fmt[ret], res);
120
+	ret = ttail_format_guess(ttail, "1988/10/22", NULL);
121
+	ck_assert_int_eq(ret, -2);
122
+	ck_assert_str_eq(ttail->fmt, res);
123
+	ck_assert((ttail->flag & TTAIL_FLAG_FORMAT) == TTAIL_FLAG_FORMAT);
124
+}
125
+END_TEST
126
+
127
+Suite * ttail_init_suite(void)
128
+{
129
+	Suite *s;
130
+	TCase	*tc_init_fmt_guess;
131
+
132
+	s = suite_create("ttail init checks");
133
+
134
+	tc_init_fmt_guess = tcase_create("date format guess init checks");
135
+	tcase_add_checked_fixture(tc_init_fmt_guess,
136
+		setup_ttail_empty, teardown_ttail);
137
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_date);
138
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_datetime);
139
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_datetime2);
140
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess);
141
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_date_notm);
142
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_noguess_notm);
143
+	tcase_add_test(tc_init_fmt_guess, test_init_guess_fmt_set);
144
+
145
+	suite_add_tcase(s, tc_init_fmt_guess);
146
+	return s;
147
+}
148
+
149
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 164
- 0
tests/ttail_init_logfile.c View File

@@ -0,0 +1,164 @@
1
+#include <check.h>
2
+#include <errno.h>
3
+#include <stdio.h>
4
+#include <unistd.h>
5
+
6
+#include "ttail_check.h"
7
+#include "ttail.h"
8
+#include "ttail_init.h"
9
+
10
+/*
11
+ * ttail_add_logfile() tests
12
+ */
13
+START_TEST (test_init_empty_logfilename)
14
+{
15
+	ck_assert_msg(ttail->logfile_name == NULL,
16
+		"ttail_t.logfile_name should be NULL");
17
+}
18
+END_TEST
19
+
20
+START_TEST (test_init_nonexist_logfilename)
21
+{
22
+	char *fname;
23
+	int ret;
24
+	/** @todo replace by mkstemp */
25
+	fname = tempnam(NULL, "ttail_check");
26
+
27
+	ret = ttail_add_logfile(ttail, fname);
28
+	ck_assert_int_eq(ret, 1);
29
+	ck_assert(ttail->logfile_name != NULL);
30
+	ck_assert_str_eq(ttail->logfile_name[0], fname);
31
+	ck_assert(ttail->logfile[0] == NULL);
32
+	free(fname);
33
+}
34
+END_TEST
35
+
36
+START_TEST (test_init_exist_logfilename)
37
+{
38
+	char *fname;
39
+	int ret;
40
+	FILE *fp;
41
+	fname = tempnam(NULL, "ttail_check");
42
+	if(!(fp = fopen(fname, "w+")))
43
+	{
44
+		perror("Unable to create file for testing");
45
+		ck_abort_msg("Unable to create file for testing");
46
+	}
47
+	if(fclose(fp))
48
+	{
49
+		perror("Unable to close file for testing");
50
+		ck_abort_msg("Unabe to close file for testing");
51
+	}
52
+
53
+	ret = ttail_add_logfile(ttail, fname);
54
+	ck_assert_int_eq(ret, 0);
55
+	ck_assert(ttail->logfile_name != NULL);
56
+	ck_assert_str_eq(ttail->logfile_name[0], fname);
57
+	ck_assert(ttail->logfile[0] != NULL);
58
+	free(fname);
59
+}
60
+END_TEST
61
+
62
+START_TEST (test_init_same_exist_logfilename)
63
+{
64
+	char *fname;
65
+	int ret;
66
+	FILE *fp;
67
+	fname = tempnam(NULL, "ttail_check");
68
+	if(!(fp = fopen(fname, "w+")))
69
+	{
70
+		perror("Unable to create file for testing");
71
+		ck_abort_msg("Unable to create file for testing");
72
+	}
73
+	if(fclose(fp))
74
+	{
75
+		perror("Unable to close file for testing");
76
+		ck_abort_msg("Unabe to close file for testing");
77
+	}
78
+
79
+	ret = ttail_add_logfile(ttail, fname);
80
+	ck_assert_int_eq(ret, 0);
81
+	ret = ttail_add_logfile(ttail, fname);
82
+	ck_assert_int_eq(ret, -1);
83
+	ck_assert_int_eq(ttail->logfile_sz, 1);
84
+	ck_assert(ttail->logfile_name != NULL);
85
+	ck_assert_str_eq(ttail->logfile_name[0], fname);
86
+	ck_assert(ttail->logfile[0] != NULL);
87
+	free(fname);
88
+}
89
+END_TEST
90
+
91
+START_TEST (test_init_same_nonexist_logfilename)
92
+{
93
+	char *fname;
94
+	int ret;
95
+	fname = tempnam(NULL, "ttail_check");
96
+
97
+	ret = ttail_add_logfile(ttail, fname);
98
+	ck_assert_int_eq(ret, 1);
99
+	ret = ttail_add_logfile(ttail, fname);
100
+	ck_assert_int_eq(ret, -1);
101
+	ck_assert_int_eq(ttail->logfile_sz, 1);
102
+	ck_assert(ttail->logfile_name != NULL);
103
+	ck_assert_str_eq(ttail->logfile_name[0], fname);
104
+	ck_assert(ttail->logfile[0] == NULL);
105
+	free(fname);
106
+}
107
+END_TEST
108
+
109
+START_TEST (test_init_multiple_logfilename)
110
+{
111
+	char *fname[20];
112
+	int ret;
113
+	int i, j;
114
+	for(i=0;i<20;i++)
115
+	{
116
+		fname[i] = tempnam(NULL, "ttail_check");
117
+	}
118
+	
119
+	for(i=0; i<20; i++)
120
+	{
121
+		for(j=0; j<i; j++)
122
+		{
123
+			ret = ttail_add_logfile(ttail, fname[j]);
124
+			ck_assert_int_eq(ret, -1);
125
+			ck_assert_int_eq(ttail->logfile_sz, i);
126
+		}
127
+		ret = ttail_add_logfile(ttail, fname[i]);
128
+		ck_assert_int_eq(ret, 1);
129
+		ck_assert_int_eq(ttail->logfile_sz, i+1);
130
+		for(j=0; j<i+1; j++)
131
+		{
132
+			ck_assert_str_eq(ttail->logfile_name[j], fname[j]);
133
+			ck_assert(ttail->logfile[j] == NULL);
134
+		}
135
+	}
136
+	for(i=0; i<20; i++)
137
+	{
138
+		free(fname[i]);
139
+	}
140
+}
141
+END_TEST
142
+
143
+Suite * ttail_init_suite(void)
144
+{
145
+	Suite *s;
146
+	TCase	*tc_init_logfile;
147
+
148
+	s = suite_create("ttail init checks");
149
+
150
+	tc_init_logfile = tcase_create("logfile init checks");
151
+	tcase_add_checked_fixture(tc_init_logfile,
152
+		setup_ttail_empty, teardown_ttail);
153
+	tcase_add_test(tc_init_logfile, test_init_empty_logfilename);
154
+	tcase_add_test(tc_init_logfile, test_init_nonexist_logfilename);
155
+	tcase_add_test(tc_init_logfile, test_init_exist_logfilename);
156
+	tcase_add_test(tc_init_logfile, test_init_same_exist_logfilename);
157
+	tcase_add_test(tc_init_logfile, test_init_same_nonexist_logfilename);
158
+	tcase_add_test(tc_init_logfile, test_init_multiple_logfilename);
159
+
160
+	suite_add_tcase(s, tc_init_logfile);
161
+	return s;
162
+}
163
+
164
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 75
- 0
tests/ttail_init_re_prefix.c View File

@@ -0,0 +1,75 @@
1
+#include <check.h>
2
+#include <errno.h>
3
+#include <stdio.h>
4
+#include <unistd.h>
5
+
6
+#include "ttail_check.h"
7
+#include "ttail.h"
8
+#include "ttail_init.h"
9
+
10
+/*
11
+ * ttail_set_prefix() tests
12
+ */
13
+START_TEST (test_init_prefix)
14
+{
15
+	int ret;
16
+	ret = ttail_set_prefix(ttail, "^[^ ]+ ");
17
+	ck_assert_int_eq(ret, 0);
18
+	ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
19
+}
20
+END_TEST
21
+
22
+START_TEST (test_init_bad_prefix)
23
+{
24
+	int ret;
25
+	ret = ttail_set_prefix(ttail, "^[^ + ");
26
+	ck_assert_int_eq(ret, -1);
27
+	ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == 0);
28
+}
29
+END_TEST
30
+
31
+START_TEST (test_init_again_prefix)
32
+{
33
+	int ret;
34
+	ret = ttail_set_prefix(ttail, "^[^ ]+ ");
35
+	ck_assert_int_eq(ret, 0);
36
+	ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
37
+	ret = ttail_set_prefix(ttail, "^[^ + ");
38
+	ck_assert_int_eq(ret, 1);
39
+	ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
40
+}
41
+END_TEST
42
+
43
+START_TEST (test_init_againbad_prefix)
44
+{
45
+	int ret;
46
+	ret = ttail_set_prefix(ttail, "^[^ + ");
47
+	ck_assert_int_eq(ret, -1);
48
+	ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == 0);
49
+
50
+	ret = ttail_set_prefix(ttail, "^[^ ]+ ");
51
+	ck_assert_int_eq(ret, 0);
52
+	ck_assert((ttail->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
53
+}
54
+END_TEST
55
+
56
+Suite * ttail_init_suite(void)
57
+{
58
+	Suite *s;
59
+	TCase	*tc_init_prefix;
60
+
61
+	s = suite_create("ttail init checks");
62
+
63
+	tc_init_prefix = tcase_create("date prefix regex init checks");
64
+	tcase_add_checked_fixture(tc_init_prefix,
65
+		setup_ttail_empty, teardown_ttail);
66
+	tcase_add_test(tc_init_prefix, test_init_prefix);
67
+	tcase_add_test(tc_init_prefix, test_init_bad_prefix);
68
+	tcase_add_test(tc_init_prefix, test_init_again_prefix);
69
+	tcase_add_test(tc_init_prefix, test_init_againbad_prefix);
70
+
71
+	suite_add_tcase(s, tc_init_prefix);
72
+	return s;
73
+}
74
+
75
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 164
- 0
tests/ttail_init_set_dates.c View File

@@ -0,0 +1,164 @@
1
+#include <check.h>
2
+#include <errno.h>
3
+#include <stdio.h>
4
+#include <unistd.h>
5
+
6
+#include "ttail_check.h"
7
+#include "ttail.h"
8
+#include "ttail_init.h"
9
+
10
+/*
11
+ * ttail_set_dates() tests
12
+ */
13
+START_TEST (test_init_setdates_nothing)
14
+{
15
+	int ret;
16
+	char *arg[] = {NULL, NULL};
17
+	struct tm zero;
18
+
19
+	memset(&zero, -1, sizeof(struct tm));
20
+
21
+	ret = ttail_set_dates(ttail, arg);
22
+	ck_assert_int_eq(ret, 0);
23
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
24
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
25
+	ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
26
+	ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
27
+}
28
+END_TEST
29
+
30
+START_TEST (test_init_setdates_nofmt_min)
31
+{
32
+	int ret;
33
+	char *arg[] = {"88/10/22", NULL};
34
+	struct tm zero;
35
+	char *arg0;
36
+
37
+	arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
38
+	if(!arg0)
39
+	{
40
+		perror("Malloc failed for argument");
41
+		ck_abort_msg("Unable to allocate memory");
42
+	}
43
+	strcpy(arg0, arg[0]);
44
+	arg[0]=arg0;
45
+
46
+	memset(&zero, -1, sizeof(struct tm));
47
+
48
+	ret = ttail_set_dates(ttail, arg);
49
+	ck_assert_int_eq(ret, 0);
50
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
51
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == 0);
52
+	ck_assert(memcmp(&zero, &(ttail->date_max), sizeof(struct tm)) == 0);
53
+
54
+	ck_assert_int_eq(ttail->date_min.tm_year, 88);
55
+	ck_assert_int_eq(ttail->date_min.tm_mon, 9);
56
+	ck_assert_int_eq(ttail->date_min.tm_mday, 22);
57
+	ck_assert_int_eq(ttail->date_min.tm_hour, 0);
58
+	ck_assert_int_eq(ttail->date_min.tm_min, 0);
59
+	ck_assert_int_eq(ttail->date_min.tm_sec, 0);
60
+}
61
+END_TEST
62
+
63
+START_TEST (test_init_setdates_nofmt_max)
64
+{
65
+	int ret;
66
+	char *arg[] = {NULL, "88/10/22"};
67
+	struct tm zero;
68
+	char *arg1;
69
+
70
+	arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
71
+	if(!arg1)
72
+	{
73
+		perror("Malloc failed for argument");
74
+		ck_abort_msg("Unable to allocate memory");
75
+	}
76
+	strcpy(arg1, arg[1]);
77
+	arg[1]=arg1;
78
+
79
+	memset(&zero, -1, sizeof(struct tm));
80
+
81
+	ret = ttail_set_dates(ttail, arg);
82
+	ck_assert_int_eq(ret, 0);
83
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == 0);
84
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
85
+	ck_assert(memcmp(&zero, &(ttail->date_min), sizeof(struct tm)) == 0);
86
+
87
+	ck_assert_int_eq(ttail->date_max.tm_year, 88);
88
+	ck_assert_int_eq(ttail->date_max.tm_mon, 9);
89
+	ck_assert_int_eq(ttail->date_max.tm_mday, 22);
90
+	ck_assert_int_eq(ttail->date_max.tm_hour, 0);
91
+	ck_assert_int_eq(ttail->date_max.tm_min, 0);
92
+	ck_assert_int_eq(ttail->date_max.tm_sec, 0);
93
+}
94
+END_TEST
95
+
96
+START_TEST (test_init_setdates_nofmt_both)
97
+{
98
+	int ret;
99
+	char *arg[] = {"1988/10/22", "2088/10/22"};
100
+	struct tm zero;
101
+	char *arg0, *arg1;
102
+
103
+	arg0 = malloc(sizeof(char)*(strlen(arg[0])+1));
104
+	if(!arg0)
105
+	{
106
+		perror("Malloc failed for argument");
107
+		ck_abort_msg("Unable to allocate memory");
108
+	}
109
+	strcpy(arg0, arg[0]);
110
+	arg[0]=arg0;
111
+
112
+	arg1 = malloc(sizeof(char)*(strlen(arg[1])+1));
113
+	if(!arg1)
114
+	{
115
+		perror("Malloc failed for argument");
116
+		ck_abort_msg("Unable to allocate memory");
117
+	}
118
+	strcpy(arg1, arg[1]);
119
+	arg[1]=arg1;
120
+
121
+
122
+	memset(&zero, 0, sizeof(struct tm));
123
+
124
+	ret = ttail_set_dates(ttail, arg);
125
+	ck_assert_int_eq(ret, 0);
126
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MIN) == TTAIL_FLAG_DATE_MIN);
127
+	ck_assert((ttail->flag & TTAIL_FLAG_DATE_MAX) == TTAIL_FLAG_DATE_MAX);
128
+
129
+	ck_assert_int_eq(ttail->date_min.tm_year, 88);
130
+	ck_assert_int_eq(ttail->date_min.tm_mon, 9);
131
+	ck_assert_int_eq(ttail->date_min.tm_mday, 22);
132
+	ck_assert_int_eq(ttail->date_min.tm_hour, 0);
133
+	ck_assert_int_eq(ttail->date_min.tm_min, 0);
134
+	ck_assert_int_eq(ttail->date_min.tm_sec, 0);
135
+
136
+	ck_assert_int_eq(ttail->date_max.tm_year, 188);
137
+	ck_assert_int_eq(ttail->date_max.tm_mon, 9);
138
+	ck_assert_int_eq(ttail->date_max.tm_mday, 22);
139
+	ck_assert_int_eq(ttail->date_max.tm_hour, -1);
140
+	ck_assert_int_eq(ttail->date_max.tm_min, -1);
141
+	ck_assert_int_eq(ttail->date_max.tm_sec, -1);
142
+}
143
+END_TEST
144
+
145
+Suite * ttail_init_suite(void)
146
+{
147
+	Suite *s;
148
+	TCase	*tc_init_set_dates;
149
+
150
+	s = suite_create("ttail init checks");
151
+
152
+	tc_init_set_dates = tcase_create("dates min/max init checks");
153
+	tcase_add_checked_fixture(tc_init_set_dates,
154
+		setup_ttail_empty, teardown_ttail);
155
+	tcase_add_test(tc_init_set_dates, test_init_setdates_nothing);
156
+	tcase_add_test(tc_init_set_dates, test_init_setdates_nofmt_min);
157
+	tcase_add_test(tc_init_set_dates, test_init_setdates_nofmt_max);
158
+	tcase_add_test(tc_init_set_dates, test_init_setdates_nofmt_both);
159
+
160
+	suite_add_tcase(s, tc_init_set_dates);
161
+	return s;
162
+}
163
+
164
+TTAIL_CHECK_MAIN(ttail_init_suite)

Loading…
Cancel
Save