|
@@ -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)
|