Browse Source

New tests organisation

tests/Makfile.am is now generated using tests/regen.sh .
bootstrap.sh has been updated.
Argument parsing tests are splitted
Yann Weber 7 years ago
parent
commit
fe2367eb13

+ 2
- 1
bootstrap.sh View File

@@ -2,8 +2,9 @@
2 2
 
3 3
 [ "$1" = "clean" ] && [ -f "Makefile" ] && make distclean # pour les .o
4 4
 
5
-rm -fR configure aclocal.m4 autom4te.cache src/Makefile.in tests/Makefile.in Makefile.in compile depcomp install-sh missing
5
+rm -fR configure aclocal.m4 autom4te.cache src/Makefile.in tests/Makefile.in Makefile.in compile depcomp install-sh missing tests/Makefile.am
6 6
 
7 7
 [ "$1" = "clean" ] && exit 0
8 8
 
9
+./tests/regen.sh
9 10
 aclocal && automake -a -c && autoconf

+ 0
- 14
tests/Makefile.am View File

@@ -1,14 +0,0 @@
1
-TESTS = ttail_argparse_check ttail_init_check ttail_search_check
2
-check_PROGRAMS = ttail_argparse_check ttail_init_check ttail_search_check
3
-
4
-ttail_argparse_check_SOURCES = ttail_argparse_check.c
5
-ttail_argparse_check_CFLAGS = @CHECK_CFLAGS@
6
-ttail_argparse_check_LDADD =  $(top_builddir)/src/libttail.a @CHECK_LIBS@
7
-
8
-ttail_init_check_SOURCES = ttail_init_check.c
9
-ttail_init_check_CFLAGS = @CHECK_CFLAGS@
10
-ttail_init_check_LDADD =  $(top_builddir)/src/libttail.a @CHECK_LIBS@
11
-
12
-ttail_search_check_SOURCES = ttail_search_check.c
13
-ttail_search_check_CFLAGS = @CHECK_CFLAGS@
14
-ttail_search_check_LDADD =  $(top_builddir)/src/libttail.a @CHECK_LIBS@

+ 17
- 0
tests/regen.sh View File

@@ -0,0 +1,17 @@
1
+#!/bin/bash
2
+
3
+cd $(dirname "$0")
4
+echo "Generating $(pwd)/Makefile.am"
5
+
6
+progs="$(echo *.c | sed -e 's/\.c / /g' -e 's/\.c$//')"
7
+echo "TESTS = $progs
8
+check_PROGRAMS = $progs" > Makefile.am
9
+
10
+for p in $progs
11
+do
12
+	echo "
13
+${p}_SOURCES = ${p}.c
14
+${p}_CFLAGS = @CHECK_CFLAGS@
15
+${p}_LDADD = \$(top_builddir)/src/libttail.a @CHECK_LIBS@
16
+"
17
+done >> Makefile.am

+ 97
- 0
tests/ttail_argparse_badarg.c View File

@@ -0,0 +1,97 @@
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
+ * Bad arguments
12
+ */
13
+
14
+START_TEST (test_argparse_bad1)
15
+{
16
+	ttail_t *t;
17
+	char *args[] = {"foo", "--sdfsdf"};
18
+	t = ttail_init(2, args);
19
+	ck_assert(t == NULL);
20
+}
21
+END_TEST
22
+
23
+START_TEST (test_argparse_bad2)
24
+{
25
+	ttail_t *t;
26
+	char *args[] = {"foo", "-x"};
27
+	t = ttail_init(2, args);
28
+	ck_assert(t == NULL);
29
+}
30
+END_TEST
31
+
32
+START_TEST (test_argparse_bad3)
33
+{
34
+	ttail_t *t;
35
+	char *args[] = {"foo", "-p"};
36
+	t = ttail_init(2, args);
37
+	ck_assert(t == NULL);
38
+}
39
+END_TEST
40
+
41
+START_TEST (test_argparse_bad4)
42
+{
43
+	ttail_t *t;
44
+	char *args[] = {"foo", "-f"};
45
+	t = ttail_init(2, args);
46
+	ck_assert(t == NULL);
47
+}
48
+END_TEST
49
+
50
+START_TEST (test_argparse_bad5)
51
+{
52
+	ttail_t *t;
53
+	char *args[] = {"foo", "-d"};
54
+	t = ttail_init(2, args);
55
+	ck_assert(t == NULL);
56
+}
57
+END_TEST
58
+
59
+START_TEST (test_argparse_bad6)
60
+{
61
+	ttail_t *t;
62
+	char *args[] = {"foo", "-m"};
63
+	t = ttail_init(2, args);
64
+	ck_assert(t == NULL);
65
+}
66
+END_TEST
67
+
68
+START_TEST (test_argparse_bad7)
69
+{
70
+	ttail_t *t;
71
+	char *args[] = {"foo", "-l"};
72
+	t = ttail_init(2, args);
73
+	ck_assert(t == NULL);
74
+}
75
+END_TEST
76
+
77
+Suite * ttail_init_suite(void)
78
+{
79
+	Suite *s;
80
+	TCase *tc_argparse_badarg;
81
+
82
+	s = suite_create("ttail argument parsing checks");
83
+
84
+	tc_argparse_badarg = tcase_create("bad arguments parsing");
85
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad1);
86
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad2);
87
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad3);
88
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad4);
89
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad5);
90
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad6);
91
+	tcase_add_test(tc_argparse_badarg, test_argparse_bad7);
92
+
93
+	suite_add_tcase(s, tc_argparse_badarg);
94
+	return s;
95
+}
96
+
97
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 0
- 421
tests/ttail_argparse_check.c View File

@@ -1,421 +0,0 @@
1
-#include <check.h>
2
-#include <errno.h>
3
-#include <stdio.h>
4
-#include <unistd.h>
5
-
6
-
7
-#include "ttail.h"
8
-#include "ttail_init.h"
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
-void teardown_ttail(void)
17
-{
18
-	ttail_free(ttail);
19
-}
20
-/*
21
- * Empty argument parsing test case
22
- */
23
-void setup_ttail_empty(void)
24
-{
25
-	ttail = ttail_init(1, (char**)&"foo");
26
-}
27
-START_TEST (test_argparse_empty_logfilename)
28
-{
29
-	ck_assert_msg(ttail->logfile_name == NULL,
30
-		"ttail_t.logfile_name should be NULL");
31
-}
32
-END_TEST
33
-START_TEST (test_argparse_empty_logfile)
34
-{
35
-	ck_assert_msg(ttail->logfile == NULL,
36
-		"ttail_t.logfile should be NULL");
37
-}
38
-END_TEST
39
-START_TEST (test_argparse_empty_logfilesz)
40
-{
41
-	ck_assert_msg(ttail->logfile_sz == 0,
42
-		"ttail_t.logfile_sz should be 0");
43
-}
44
-END_TEST
45
-START_TEST (test_argparse_empty_flag)
46
-{
47
-	ck_assert_msg(ttail->flag == 0,
48
-		"ttail_t.flag should be 0");
49
-}
50
-END_TEST
51
-START_TEST (test_argparse_empty_fmt)
52
-{
53
-	ck_assert_msg(ttail->fmt == NULL,
54
-		"ttail_t.fmt should be NULL");
55
-}
56
-END_TEST
57
-START_TEST (test_argparse_empty_verbose)
58
-{
59
-	ck_assert_msg(ttail->verbose == 0,
60
-		"ttail_t.verbose should be 0");
61
-}
62
-END_TEST
63
-START_TEST (test_argparse_empty_prefixsz)
64
-{
65
-	ck_assert_msg(ttail->prefix_sz == -1,
66
-		"ttail_t.prefix_sz should be NULL");
67
-}
68
-END_TEST
69
-START_TEST (test_argparse_empty_session)
70
-{
71
-	ck_assert_msg(ttail->session == NULL,
72
-		"ttail_t.session should be NULL");
73
-}
74
-END_TEST
75
-
76
-/*
77
- * Bad arguments
78
- */
79
-
80
-START_TEST (test_argparse_bad1)
81
-{
82
-	ttail_t *t;
83
-	char *args[] = {"foo", "--sdfsdf"};
84
-	t = ttail_init(2, args);
85
-	ck_assert(t == NULL);
86
-}
87
-END_TEST
88
-
89
-START_TEST (test_argparse_bad2)
90
-{
91
-	ttail_t *t;
92
-	char *args[] = {"foo", "-x"};
93
-	t = ttail_init(2, args);
94
-	ck_assert(t == NULL);
95
-}
96
-END_TEST
97
-
98
-START_TEST (test_argparse_bad3)
99
-{
100
-	ttail_t *t;
101
-	char *args[] = {"foo", "-p"};
102
-	t = ttail_init(2, args);
103
-	ck_assert(t == NULL);
104
-}
105
-END_TEST
106
-
107
-START_TEST (test_argparse_bad4)
108
-{
109
-	ttail_t *t;
110
-	char *args[] = {"foo", "-f"};
111
-	t = ttail_init(2, args);
112
-	ck_assert(t == NULL);
113
-}
114
-END_TEST
115
-
116
-START_TEST (test_argparse_bad5)
117
-{
118
-	ttail_t *t;
119
-	char *args[] = {"foo", "-d"};
120
-	t = ttail_init(2, args);
121
-	ck_assert(t == NULL);
122
-}
123
-END_TEST
124
-
125
-START_TEST (test_argparse_bad6)
126
-{
127
-	ttail_t *t;
128
-	char *args[] = {"foo", "-m"};
129
-	t = ttail_init(2, args);
130
-	ck_assert(t == NULL);
131
-}
132
-END_TEST
133
-
134
-START_TEST (test_argparse_bad7)
135
-{
136
-	ttail_t *t;
137
-	char *args[] = {"foo", "-l"};
138
-	t = ttail_init(2, args);
139
-	ck_assert(t == NULL);
140
-}
141
-END_TEST
142
-
143
-
144
-/*
145
- * file argument parsing
146
- */
147
-
148
-void setup_fname(void)
149
-{
150
-	int i;
151
-	FILE *fp;
152
-	for(i=0;i<__Fname_sz;i++)
153
-	{
154
-		fname[i] = NULL;
155
-	}
156
-
157
-	for(i=0; i<__Fname_sz; i++)
158
-	{
159
-		fname[i] = tempnam(NULL, "ttail_check");
160
-		if(i%2)
161
-		{
162
-			if((fp=fopen(fname[i], "w+")) == NULL)
163
-			{
164
-				perror("Unable to create file for testing");
165
-				ck_abort_msg("Unable to create file for testing");
166
-			}
167
-			if(fclose(fp))
168
-			{
169
-				perror("Unable to close file for testing");
170
-				ck_abort_msg("Unable to close file for testing");
171
-
172
-			}
173
-		}
174
-	}
175
-}
176
-
177
-void teardown_fname(void)
178
-{
179
-	int i;
180
-	for(i=0; i<__Fname_sz; i++)
181
-	{
182
-		unlink(fname[i]);
183
-		if(fname[i] != NULL)
184
-		{
185
-			free(fname[i]);
186
-		}
187
-	}
188
-}
189
-
190
-START_TEST (test_argparse_file_non_exist)
191
-{
192
-	ttail_t *t;
193
-	char *args[4] = {"foo", "-d", "Mar 6 13:37", NULL};
194
-
195
-	args[3] = fname[FNAME_NO_EXIST];
196
-	t = ttail_init(4, args);
197
-	ck_assert_msg(t != NULL, "init failed");
198
-
199
-	ck_assert_msg(t->logfile_sz == 1,
200
-		"ttail_t.logfile_sz should be 1");
201
-	ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
202
-		"ttail_t.logfile_name[0] does not contain the filename");
203
-	ck_assert_msg(t->logfile[0] == NULL,
204
-		"ttail_t.logfile[0] should be NULL");
205
-	
206
-	ttail_free(t);
207
-
208
-}
209
-END_TEST
210
-
211
-START_TEST (test_argparse_file_exist)
212
-{
213
-	ttail_t *t;
214
-	char *args[4] = {"foo", "-d", "Mar 10 13:37", NULL};
215
-
216
-	args[3] = fname[FNAME_EXIST];
217
-
218
-	t = ttail_init(4, args);
219
-	ck_assert_msg(t != NULL, "init failed");
220
-
221
-	ck_assert_msg(t->logfile_sz == 1,
222
-		"ttail_t.logfile_sz should be 1");
223
-	ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
224
-		"ttail_t.logfile_name[0] does not contain the filename");
225
-	ck_assert_msg(t->logfile[0] != NULL,
226
-		"ttail_t.logfile[0] shouldn't be NULL");
227
-	
228
-	ttail_free(t);
229
-
230
-}
231
-END_TEST
232
-
233
-START_TEST (test_argparse_file_multiple)
234
-{
235
-	ttail_t *t;
236
-	int i;
237
-	char *args[8] = {"foo", "-d", "mar 10 13:37", NULL, NULL, NULL, NULL,
238
-		NULL};
239
-	
240
-	for(i=0; i<__Fname_sz; i++)
241
-	{
242
-		args[i+3] = fname[i];
243
-	}
244
-
245
-	t = ttail_init(8, args);
246
-	ck_assert_msg(t != NULL, "init failed");
247
-	
248
-	ck_assert_msg(t->logfile_sz == __Fname_sz,
249
-		"ttail_t.logfile_sz doesn't have the good value");
250
-
251
-	for(i=0;i<__Fname_sz; i++)
252
-	{
253
-		ck_assert_msg(strcmp(t->logfile_name[i], args[i+3]) == 0,
254
-			"some filename corrupted in ttail_t.logfile_name");
255
-		if(i%2)
256
-		{
257
-			ck_assert_msg(t->logfile[i] != NULL,
258
-				"logfile not opened");
259
-		} else {
260
-			ck_assert_msg(t->logfile[i] == NULL,
261
-				"logfile should be NULL");
262
-
263
-		}
264
-	}
265
-
266
-	
267
-}
268
-END_TEST
269
-
270
-START_TEST (test_argparse_reprefix_short)
271
-{
272
-	ttail_t *t;
273
-	char *args[] = {"foo", "-r", "^[^ ]+ "};
274
-	t = ttail_init(3, args);
275
-	ck_assert(t != NULL);
276
-	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
277
-}
278
-END_TEST
279
-
280
-START_TEST (test_argparse_reprefix_long)
281
-{
282
-	ttail_t *t;
283
-	char *args[] = {"foo", "--re-prefix", "^[^ ]+ "};
284
-	t = ttail_init(3, args);
285
-	ck_assert(t != NULL);
286
-	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
287
-}
288
-END_TEST
289
-
290
-START_TEST (test_argparse_prefixlen_short)
291
-{
292
-	ttail_t *t;
293
-	char *args[] = {"foo", "-p", "10"};
294
-	t = ttail_init(3, args);
295
-	ck_assert(t != NULL);
296
-	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
297
-	ck_assert_int_eq(t->prefix_sz, 10);
298
-}
299
-END_TEST
300
-
301
-START_TEST (test_argparse_prefixlen_long)
302
-{
303
-	ttail_t *t;
304
-	char *args[] = {"foo", "--prefix-len", "42"};
305
-	t = ttail_init(3, args);
306
-	ck_assert(t != NULL);
307
-	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
308
-	ck_assert_int_eq(t->prefix_sz, 42);
309
-}
310
-END_TEST
311
-
312
-
313
-START_TEST (test_argparse_prefix_multiple)
314
-{
315
-	ttail_t *t;
316
-	char *args[] = {"foo", "--re-prefix", "^[^ ]+ ", "-p", "20"};
317
-	t = ttail_init(5, args);
318
-	ck_assert(t == NULL);
319
-}
320
-END_TEST
321
-
322
-START_TEST (test_argparse_fmt_short)
323
-{
324
-	ttail_t *t;
325
-	char *args[] = {"foo", "-f", "%m"};
326
-	t = ttail_init(3, args);
327
-	ck_assert(t != NULL);
328
-}
329
-END_TEST
330
-
331
-START_TEST (test_argparse_fmt_long)
332
-{
333
-	ttail_t *t;
334
-	char *args[] = {"foo", "--date-format", "%m"};
335
-	t = ttail_init(3, args);
336
-	ck_assert(t != NULL);
337
-}
338
-END_TEST
339
-
340
-START_TEST (test_argparse_fmt_multiple)
341
-{
342
-	ttail_t *t;
343
-	char *args[] = {"foo", "-f", "%m", "-f", "%d"};
344
-	t = ttail_init(5, args);
345
-	ck_assert(t == NULL);
346
-}
347
-END_TEST
348
-
349
-Suite * ttail_init_suite(void)
350
-{
351
-	Suite *s;
352
-	TCase *tc_argparse_empty;
353
-	TCase *tc_argparse_badarg;
354
-	TCase *tc_argparse_files;
355
-	TCase *tc_argparse_prefix;
356
-	TCase *tc_argparse_fmt;
357
-
358
-	s = suite_create("ttail argument parsing checks");
359
-
360
-	tc_argparse_empty = tcase_create("empty arguments parsing");
361
-	tcase_add_checked_fixture(tc_argparse_empty,
362
-		setup_ttail_empty, teardown_ttail);
363
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilename);
364
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfile);
365
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilesz);
366
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_flag);
367
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_fmt);
368
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_verbose);
369
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_prefixsz);
370
-	tcase_add_test(tc_argparse_empty, test_argparse_empty_session);
371
-
372
-	tc_argparse_badarg = tcase_create("bad arguments parsing");
373
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad1);
374
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad2);
375
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad3);
376
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad4);
377
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad5);
378
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad6);
379
-	tcase_add_test(tc_argparse_badarg, test_argparse_bad7);
380
-
381
-	tc_argparse_files = tcase_create("files options parse");
382
-	tcase_add_checked_fixture(tc_argparse_files,
383
-		setup_fname, teardown_fname);
384
-	tcase_add_test(tc_argparse_files, test_argparse_file_non_exist);
385
-	tcase_add_test(tc_argparse_files, test_argparse_file_exist);
386
-	tcase_add_test(tc_argparse_files, test_argparse_file_multiple);
387
-
388
-	tc_argparse_prefix = tcase_create("re-prefix arguments parsing");
389
-	tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_short);
390
-	tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_long);
391
-	tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_short);
392
-	tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_long);
393
-	tcase_add_test(tc_argparse_prefix, test_argparse_prefix_multiple);
394
-
395
-	tc_argparse_fmt = tcase_create("date format arguments parsing");
396
-	tcase_add_test(tc_argparse_fmt, test_argparse_fmt_short);
397
-	tcase_add_test(tc_argparse_fmt, test_argparse_fmt_long);
398
-	tcase_add_test(tc_argparse_fmt, test_argparse_fmt_multiple);
399
-
400
-	suite_add_tcase(s, tc_argparse_empty);
401
-	suite_add_tcase(s, tc_argparse_badarg);
402
-	suite_add_tcase(s, tc_argparse_files);
403
-	suite_add_tcase(s, tc_argparse_prefix);
404
-	suite_add_tcase(s, tc_argparse_fmt);
405
-	return s;
406
-}
407
-
408
-int main(void)
409
-{
410
-	int number_failed = 0;
411
-	SRunner *sr;
412
-
413
-	sr = srunner_create(ttail_init_suite());
414
-	srunner_set_fork_status(sr, CK_FORK);
415
-
416
-	srunner_run_all(sr,CK_VERBOSE);
417
-	number_failed = srunner_ntests_failed(sr);
418
-	srunner_free(sr);
419
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
420
-
421
-}

+ 53
- 0
tests/ttail_argparse_date_fmt.c View File

@@ -0,0 +1,53 @@
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
+START_TEST (test_argparse_fmt_short)
11
+{
12
+	ttail_t *t;
13
+	char *args[] = {"foo", "-f", "%m"};
14
+	t = ttail_init(3, args);
15
+	ck_assert(t != NULL);
16
+}
17
+END_TEST
18
+
19
+START_TEST (test_argparse_fmt_long)
20
+{
21
+	ttail_t *t;
22
+	char *args[] = {"foo", "--date-format", "%m"};
23
+	t = ttail_init(3, args);
24
+	ck_assert(t != NULL);
25
+}
26
+END_TEST
27
+
28
+START_TEST (test_argparse_fmt_multiple)
29
+{
30
+	ttail_t *t;
31
+	char *args[] = {"foo", "-f", "%m", "-f", "%d"};
32
+	t = ttail_init(5, args);
33
+	ck_assert(t == NULL);
34
+}
35
+END_TEST
36
+
37
+Suite * ttail_init_suite(void)
38
+{
39
+	Suite *s;
40
+	TCase *tc_argparse_fmt;
41
+
42
+	s = suite_create("ttail argument parsing checks");
43
+
44
+	tc_argparse_fmt = tcase_create("date format arguments parsing");
45
+	tcase_add_test(tc_argparse_fmt, test_argparse_fmt_short);
46
+	tcase_add_test(tc_argparse_fmt, test_argparse_fmt_long);
47
+	tcase_add_test(tc_argparse_fmt, test_argparse_fmt_multiple);
48
+
49
+	suite_add_tcase(s, tc_argparse_fmt);
50
+	return s;
51
+}
52
+
53
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 95
- 0
tests/ttail_argparse_empty.c View File

@@ -0,0 +1,95 @@
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
+ttail_t *ttail;
11
+
12
+void teardown_ttail(void)
13
+{
14
+	ttail_free(ttail);
15
+}
16
+/*
17
+ * Empty argument parsing test case
18
+ */
19
+void setup_ttail_empty(void)
20
+{
21
+	ttail = ttail_init(1, (char**)&"foo");
22
+}
23
+START_TEST (test_argparse_empty_logfilename)
24
+{
25
+	ck_assert_msg(ttail->logfile_name == NULL,
26
+		"ttail_t.logfile_name should be NULL");
27
+}
28
+END_TEST
29
+START_TEST (test_argparse_empty_logfile)
30
+{
31
+	ck_assert_msg(ttail->logfile == NULL,
32
+		"ttail_t.logfile should be NULL");
33
+}
34
+END_TEST
35
+START_TEST (test_argparse_empty_logfilesz)
36
+{
37
+	ck_assert_msg(ttail->logfile_sz == 0,
38
+		"ttail_t.logfile_sz should be 0");
39
+}
40
+END_TEST
41
+START_TEST (test_argparse_empty_flag)
42
+{
43
+	ck_assert_msg(ttail->flag == 0,
44
+		"ttail_t.flag should be 0");
45
+}
46
+END_TEST
47
+START_TEST (test_argparse_empty_fmt)
48
+{
49
+	ck_assert_msg(ttail->fmt == NULL,
50
+		"ttail_t.fmt should be NULL");
51
+}
52
+END_TEST
53
+START_TEST (test_argparse_empty_verbose)
54
+{
55
+	ck_assert_msg(ttail->verbose == 0,
56
+		"ttail_t.verbose should be 0");
57
+}
58
+END_TEST
59
+START_TEST (test_argparse_empty_prefixsz)
60
+{
61
+	ck_assert_msg(ttail->prefix_sz == -1,
62
+		"ttail_t.prefix_sz should be NULL");
63
+}
64
+END_TEST
65
+START_TEST (test_argparse_empty_session)
66
+{
67
+	ck_assert_msg(ttail->session == NULL,
68
+		"ttail_t.session should be NULL");
69
+}
70
+END_TEST
71
+
72
+Suite * ttail_init_suite(void)
73
+{
74
+	Suite *s;
75
+	TCase *tc_argparse_empty;
76
+
77
+	s = suite_create("ttail argument parsing checks");
78
+
79
+	tc_argparse_empty = tcase_create("empty arguments parsing");
80
+	tcase_add_checked_fixture(tc_argparse_empty,
81
+		setup_ttail_empty, teardown_ttail);
82
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilename);
83
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfile);
84
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilesz);
85
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_flag);
86
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_fmt);
87
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_verbose);
88
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_prefixsz);
89
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_session);
90
+
91
+	suite_add_tcase(s, tc_argparse_empty);
92
+	return s;
93
+}
94
+
95
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 160
- 0
tests/ttail_argparse_files.c View File

@@ -0,0 +1,160 @@
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
+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
+/*
17
+ * file argument parsing
18
+ */
19
+
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
+START_TEST (test_argparse_file_non_exist)
63
+{
64
+	ttail_t *t;
65
+	char *args[4] = {"foo", "-d", "Mar 6 13:37", NULL};
66
+
67
+	args[3] = fname[FNAME_NO_EXIST];
68
+	t = ttail_init(4, args);
69
+	ck_assert_msg(t != NULL, "init failed");
70
+
71
+	ck_assert_msg(t->logfile_sz == 1,
72
+		"ttail_t.logfile_sz should be 1");
73
+	ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
74
+		"ttail_t.logfile_name[0] does not contain the filename");
75
+	ck_assert_msg(t->logfile[0] == NULL,
76
+		"ttail_t.logfile[0] should be NULL");
77
+	
78
+	ttail_free(t);
79
+
80
+}
81
+END_TEST
82
+
83
+START_TEST (test_argparse_file_exist)
84
+{
85
+	ttail_t *t;
86
+	char *args[4] = {"foo", "-d", "Mar 10 13:37", NULL};
87
+
88
+	args[3] = fname[FNAME_EXIST];
89
+
90
+	t = ttail_init(4, args);
91
+	ck_assert_msg(t != NULL, "init failed");
92
+
93
+	ck_assert_msg(t->logfile_sz == 1,
94
+		"ttail_t.logfile_sz should be 1");
95
+	ck_assert_msg(strcmp(t->logfile_name[0], args[3]) == 0,
96
+		"ttail_t.logfile_name[0] does not contain the filename");
97
+	ck_assert_msg(t->logfile[0] != NULL,
98
+		"ttail_t.logfile[0] shouldn't be NULL");
99
+	
100
+	ttail_free(t);
101
+
102
+}
103
+END_TEST
104
+
105
+START_TEST (test_argparse_file_multiple)
106
+{
107
+	ttail_t *t;
108
+	int i;
109
+	char *args[8] = {"foo", "-d", "mar 10 13:37", NULL, NULL, NULL, NULL,
110
+		NULL};
111
+	
112
+	for(i=0; i<__Fname_sz; i++)
113
+	{
114
+		args[i+3] = fname[i];
115
+	}
116
+
117
+	t = ttail_init(8, args);
118
+	ck_assert_msg(t != NULL, "init failed");
119
+	
120
+	ck_assert_msg(t->logfile_sz == __Fname_sz,
121
+		"ttail_t.logfile_sz doesn't have the good value");
122
+
123
+	for(i=0;i<__Fname_sz; i++)
124
+	{
125
+		ck_assert_msg(strcmp(t->logfile_name[i], args[i+3]) == 0,
126
+			"some filename corrupted in ttail_t.logfile_name");
127
+		if(i%2)
128
+		{
129
+			ck_assert_msg(t->logfile[i] != NULL,
130
+				"logfile not opened");
131
+		} else {
132
+			ck_assert_msg(t->logfile[i] == NULL,
133
+				"logfile should be NULL");
134
+
135
+		}
136
+	}
137
+
138
+	
139
+}
140
+END_TEST
141
+
142
+Suite * ttail_init_suite(void)
143
+{
144
+	Suite *s;
145
+	TCase *tc_argparse_files;
146
+
147
+	s = suite_create("ttail argument parsing checks");
148
+
149
+	tc_argparse_files = tcase_create("files options parse");
150
+	tcase_add_checked_fixture(tc_argparse_files,
151
+		setup_fname, teardown_fname);
152
+	tcase_add_test(tc_argparse_files, test_argparse_file_non_exist);
153
+	tcase_add_test(tc_argparse_files, test_argparse_file_exist);
154
+	tcase_add_test(tc_argparse_files, test_argparse_file_multiple);
155
+
156
+	suite_add_tcase(s, tc_argparse_files);
157
+	return s;
158
+}
159
+
160
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 80
- 0
tests/ttail_argparse_re_prefix.c View File

@@ -0,0 +1,80 @@
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
+START_TEST (test_argparse_reprefix_short)
11
+{
12
+	ttail_t *t;
13
+	char *args[] = {"foo", "-r", "^[^ ]+ "};
14
+	t = ttail_init(3, args);
15
+	ck_assert(t != NULL);
16
+	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
17
+}
18
+END_TEST
19
+
20
+START_TEST (test_argparse_reprefix_long)
21
+{
22
+	ttail_t *t;
23
+	char *args[] = {"foo", "--re-prefix", "^[^ ]+ "};
24
+	t = ttail_init(3, args);
25
+	ck_assert(t != NULL);
26
+	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
27
+}
28
+END_TEST
29
+
30
+START_TEST (test_argparse_prefixlen_short)
31
+{
32
+	ttail_t *t;
33
+	char *args[] = {"foo", "-p", "10"};
34
+	t = ttail_init(3, args);
35
+	ck_assert(t != NULL);
36
+	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
37
+	ck_assert_int_eq(t->prefix_sz, 10);
38
+}
39
+END_TEST
40
+
41
+START_TEST (test_argparse_prefixlen_long)
42
+{
43
+	ttail_t *t;
44
+	char *args[] = {"foo", "--prefix-len", "42"};
45
+	t = ttail_init(3, args);
46
+	ck_assert(t != NULL);
47
+	ck_assert((t->flag & TTAIL_FLAG_PREFIX) == TTAIL_FLAG_PREFIX);
48
+	ck_assert_int_eq(t->prefix_sz, 42);
49
+}
50
+END_TEST
51
+
52
+
53
+START_TEST (test_argparse_prefix_multiple)
54
+{
55
+	ttail_t *t;
56
+	char *args[] = {"foo", "--re-prefix", "^[^ ]+ ", "-p", "20"};
57
+	t = ttail_init(5, args);
58
+	ck_assert(t == NULL);
59
+}
60
+END_TEST
61
+
62
+Suite * ttail_init_suite(void)
63
+{
64
+	Suite *s;
65
+	TCase *tc_argparse_prefix;
66
+
67
+	s = suite_create("ttail argument parsing checks");
68
+
69
+	tc_argparse_prefix = tcase_create("re-prefix arguments parsing");
70
+	tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_short);
71
+	tcase_add_test(tc_argparse_prefix, test_argparse_reprefix_long);
72
+	tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_short);
73
+	tcase_add_test(tc_argparse_prefix, test_argparse_prefixlen_long);
74
+	tcase_add_test(tc_argparse_prefix, test_argparse_prefix_multiple);
75
+
76
+	suite_add_tcase(s, tc_argparse_prefix);
77
+	return s;
78
+}
79
+
80
+TTAIL_CHECK_MAIN(ttail_init_suite)

+ 27
- 0
tests/ttail_check.h View File

@@ -0,0 +1,27 @@
1
+#ifndef _ttail_check_h__
2
+#define _ttail_check_h__
3
+
4
+#include <check.h>
5
+#include <errno.h>
6
+#include <stdio.h>
7
+#include <unistd.h>
8
+#include <libgen.h>
9
+
10
+#include "ttail.h"
11
+#include "ttail_init.h"
12
+
13
+
14
+#define TTAIL_CHECK_MAIN(suite) int main(int argc, char **argv) {\
15
+	int n_fail;\
16
+	SRunner *sr;\
17
+	chdir(dirname(argv[0])); /* move in ./tests dir */ \
18
+	sr = srunner_create(suite());\
19
+	srunner_set_fork_status(sr, CK_FORK);\
20
+	srunner_run_all(sr, CK_VERBOSE);\
21
+	n_fail = srunner_ntests_failed(sr);\
22
+	srunner_free(sr);\
23
+	return (n_fail == 0) ? EXIT_SUCCESS : EXIT_FAILURE;\
24
+}
25
+
26
+#endif
27
+

Loading…
Cancel
Save