Browse Source

Add first tests

Yann Weber 7 years ago
parent
commit
9de22a2677
4 changed files with 130 additions and 4 deletions
  1. 6
    0
      src/main.c
  2. 5
    4
      tests/Makefile.am
  3. 116
    0
      tests/ttail_init_check.c
  4. 3
    0
      tests/ttail_init_check.h

+ 6
- 0
src/main.c View File

@@ -0,0 +1,6 @@
1
+#include "include/ttail.h"
2
+
3
+int main(int argc, char **argv)
4
+{
5
+	return 0;
6
+}

+ 5
- 4
tests/Makefile.am View File

@@ -1,5 +1,6 @@
1
-TESTS = 
2
-check_PROGRAMS = 
1
+TESTS = ttail_init_check
2
+check_PROGRAMS = ttail_init_check
3 3
 
4
-#_CFLAGS = @CHECK_CFLAGS@ -I$(top_builddir)/src/include/
5
-#_LDADD =  @CHECK_LIBS@
4
+ttail_init_check_SOURCES = ttail_init_check.c
5
+ttail_init_check_CFLAGS = @CHECK_CFLAGS@
6
+ttail_init_check_LDADD =  $(top_builddir)/src/libttail.a @CHECK_LIBS@

+ 116
- 0
tests/ttail_init_check.c View File

@@ -0,0 +1,116 @@
1
+#include <check.h>
2
+
3
+#include "../src/include/ttail.h"
4
+
5
+ttail_t *ttail;
6
+
7
+void teardown_ttail(void)
8
+{
9
+	ttail_free(ttail);
10
+}
11
+/*
12
+ * Empty argument parsing test case
13
+ */
14
+void setup_ttail_empty(void)
15
+{
16
+	ttail = ttail_init(1, (char**)&"foo");
17
+}
18
+START_TEST (test_argparse_empty_logfilename)
19
+{
20
+	ck_assert_msg(ttail->logfile_name == NULL,
21
+		"ttail_t.logfile_name should be NULL");
22
+}
23
+END_TEST
24
+START_TEST (test_argparse_empty_logfile)
25
+{
26
+	ck_assert_msg(ttail->logfile == NULL,
27
+		"ttail_t.logfile should be NULL");
28
+}
29
+END_TEST
30
+START_TEST (test_argparse_empty_logfilesz)
31
+{
32
+	ck_assert_msg(ttail->logfile_sz == 0,
33
+		"ttail_t.logfile_sz should be 0");
34
+}
35
+END_TEST
36
+START_TEST (test_argparse_empty_prefix_flag)
37
+{
38
+	ck_assert_msg(ttail->date_prefix_flag == 0,
39
+		"ttail_t.date_prefix_flag should be 0");
40
+}
41
+END_TEST
42
+START_TEST (test_argparse_empty_fmt)
43
+{
44
+	ck_assert_msg(ttail->fmt == NULL,
45
+		"ttail_t.fmt should be NULL");
46
+}
47
+END_TEST
48
+START_TEST (test_argparse_empty_verbose)
49
+{
50
+	ck_assert_msg(ttail->verbose == 0,
51
+		"ttail_t.verbose should be 0");
52
+}
53
+END_TEST
54
+
55
+/*
56
+ * file argument parsing
57
+ */
58
+
59
+START_TEST (test_init_file_non_exist)
60
+{
61
+	ttail_t *t;
62
+	char *args[3] = {"foo", "-f", "__non__existing__"};
63
+
64
+	t = ttail_init(3, args);
65
+
66
+	ck_assert_msg(t->logfile_sz == 1,
67
+		"ttail_t.logfile_sz should be 1");
68
+	ck_assert_msg(strcmp(t->logfile_name[0], args[2]) == 0,
69
+		"ttail_t.logfile_name[0] does not contain the filename");
70
+	ck_assert_msg(t->logfile[0] == NULL,
71
+		"ttail_t.logfile[0] should be NULL");
72
+	
73
+	ttail_free(t);
74
+
75
+}
76
+END_TEST
77
+
78
+Suite * ttail_init_suite(void)
79
+{
80
+	Suite *s;
81
+	TCase *tc_argparse_empty;
82
+	TCase *tc_init_files;
83
+
84
+	s = suite_create("ttail init methods tests");
85
+
86
+	tc_argparse_empty = tcase_create("Empty arguments parsing");
87
+	tcase_add_checked_fixture(tc_argparse_empty,
88
+		setup_ttail_empty, teardown_ttail);
89
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilename);
90
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfile);
91
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_logfilesz);
92
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_prefix_flag);
93
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_fmt);
94
+	tcase_add_test(tc_argparse_empty, test_argparse_empty_verbose);
95
+
96
+	tc_init_files = tcase_create("files options handling");
97
+	tcase_add_test(tc_init_files, test_init_file_non_exist);
98
+
99
+	suite_add_tcase(s, tc_init_files);
100
+	suite_add_tcase(s, tc_argparse_empty);
101
+	return s;
102
+}
103
+
104
+int main(void)
105
+{
106
+	int number_failed = 0;
107
+	SRunner *sr;
108
+
109
+	sr = srunner_create(ttail_init_suite());
110
+
111
+	srunner_run_all(sr,CK_VERBOSE);
112
+	number_failed = srunner_ntests_failed(sr);
113
+	srunner_free(sr);
114
+	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
115
+
116
+}

+ 3
- 0
tests/ttail_init_check.h View File

@@ -0,0 +1,3 @@
1
+#include <check.h>
2
+
3
+Suite * ttail_init_suite(void);

Loading…
Cancel
Save