Преглед на файлове

Add tests for _ttail_norm_dates

Yann Weber преди 7 години
родител
ревизия
3a4fe6be94
променени са 2 файла, в които са добавени 199 реда и са изтрити 2 реда
  1. 1
    2
      src/include/ttail_init.h
  2. 198
    0
      tests/ttail_init_norm_dates.c

+ 1
- 2
src/include/ttail_init.h Целия файл

@@ -290,7 +290,7 @@ int _ttail_set_date_fmt(ttail_t*, char*, int);
290 290
  */
291 291
 int _ttail_set_date_relative(ttail_t*, char*, int);
292 292
 
293
-/**@brief Normalize dates
293
+/**@brief Normalize dates using ttail.fmt
294 294
  *
295 295
  *When dates are relatives from now all the struct tm fields are set. In 
296 296
  *logfiles year or seconds can be missing from date format. In those case we 
@@ -299,7 +299,6 @@ int _ttail_set_date_relative(ttail_t*, char*, int);
299 299
  *ttail_format_guess() calls
300 300
  *@param ttail_t* An initialized ttail_t
301 301
  *@return -1 if error 0 else
302
- *@todo checks
303 302
  */
304 303
 int _ttail_norm_dates(ttail_t*);
305 304
 

+ 198
- 0
tests/ttail_init_norm_dates.c Целия файл

@@ -0,0 +1,198 @@
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_norm_dates_flags_none)
11
+{
12
+	struct tm tm;
13
+	int ret;
14
+
15
+	ttail->flag = 0;
16
+	ttail_set_fmt(ttail, "%H %Y");
17
+	tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
18
+	tm.tm_year = 2;
19
+	ttail->date_min = tm;
20
+	ttail->date_max = tm;
21
+
22
+	ret = _ttail_norm_dates(ttail);
23
+	ck_assert_int_eq(ret, 0);
24
+	
25
+	tm = ttail->date_min;
26
+	ck_assert_int_eq(tm.tm_sec, 2);
27
+	ck_assert_int_eq(tm.tm_min, 2);
28
+	ck_assert_int_eq(tm.tm_hour, 2);
29
+	ck_assert_int_eq(tm.tm_mday, 2);
30
+	ck_assert_int_eq(tm.tm_mon, 2);
31
+	ck_assert_int_eq(tm.tm_year, 2);
32
+
33
+	tm = ttail->date_max;
34
+	ck_assert_int_eq(tm.tm_sec, 2);
35
+	ck_assert_int_eq(tm.tm_min, 2);
36
+	ck_assert_int_eq(tm.tm_hour, 2);
37
+	ck_assert_int_eq(tm.tm_mday, 2);
38
+	ck_assert_int_eq(tm.tm_mon, 2);
39
+	ck_assert_int_eq(tm.tm_year, 2);
40
+}
41
+END_TEST
42
+
43
+START_TEST (test_norm_dates_flags_min)
44
+{
45
+	struct tm tm;
46
+	int ret;
47
+
48
+	ttail->flag |= TTAIL_FLAG_DATE_MIN;
49
+	ttail_set_fmt(ttail, "%H %Y");
50
+	tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
51
+	tm.tm_year = 2;
52
+	ttail->date_min = tm;
53
+	ttail->date_max = tm;
54
+
55
+	ret = _ttail_norm_dates(ttail);
56
+	ck_assert_int_eq(ret, 0);
57
+	
58
+	tm = ttail->date_min;
59
+	ck_assert_int_eq(tm.tm_sec, -1);
60
+	ck_assert_int_eq(tm.tm_min, -1);
61
+	ck_assert_int_eq(tm.tm_hour, 2);
62
+	ck_assert_int_eq(tm.tm_mday, -1);
63
+	ck_assert_int_eq(tm.tm_mon, -1);
64
+	ck_assert_int_eq(tm.tm_year, 2);
65
+
66
+	tm = ttail->date_max;
67
+	ck_assert_int_eq(tm.tm_sec, 2);
68
+	ck_assert_int_eq(tm.tm_min, 2);
69
+	ck_assert_int_eq(tm.tm_hour, 2);
70
+	ck_assert_int_eq(tm.tm_mday, 2);
71
+	ck_assert_int_eq(tm.tm_mon, 2);
72
+	ck_assert_int_eq(tm.tm_year, 2);
73
+}
74
+END_TEST
75
+
76
+START_TEST (test_norm_dates_flags_max)
77
+{
78
+	struct tm tm;
79
+	int ret;
80
+
81
+	ttail->flag |= TTAIL_FLAG_DATE_MAX;
82
+	ttail_set_fmt(ttail, "%H %Y");
83
+	tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
84
+	tm.tm_year = 2;
85
+	ttail->date_min = tm;
86
+	ttail->date_max = tm;
87
+
88
+	ret = _ttail_norm_dates(ttail);
89
+	ck_assert_int_eq(ret, 0);
90
+	
91
+	tm = ttail->date_min;
92
+	ck_assert_int_eq(tm.tm_sec, 2);
93
+	ck_assert_int_eq(tm.tm_min, 2);
94
+	ck_assert_int_eq(tm.tm_hour, 2);
95
+	ck_assert_int_eq(tm.tm_mday, 2);
96
+	ck_assert_int_eq(tm.tm_mon, 2);
97
+	ck_assert_int_eq(tm.tm_year, 2);
98
+
99
+	tm = ttail->date_max;
100
+	ck_assert_int_eq(tm.tm_sec, -1);
101
+	ck_assert_int_eq(tm.tm_min, -1);
102
+	ck_assert_int_eq(tm.tm_hour, 2);
103
+	ck_assert_int_eq(tm.tm_mday, -1);
104
+	ck_assert_int_eq(tm.tm_mon, -1);
105
+	ck_assert_int_eq(tm.tm_year, 2);
106
+}
107
+END_TEST
108
+
109
+START_TEST (test_norm_dates_flags_both)
110
+{
111
+	struct tm tm;
112
+	int ret;
113
+
114
+	ttail->flag |= TTAIL_FLAG_DATE_MAX;
115
+	ttail->flag |= TTAIL_FLAG_DATE_MIN;
116
+	ttail_set_fmt(ttail, "%H %Y");
117
+	tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
118
+	tm.tm_year = 2;
119
+	ttail->date_min = tm;
120
+	ttail->date_max = tm;
121
+
122
+	ret = _ttail_norm_dates(ttail);
123
+	ck_assert_int_eq(ret, 0);
124
+	
125
+	tm = ttail->date_min;
126
+	ck_assert_int_eq(tm.tm_sec, -1);
127
+	ck_assert_int_eq(tm.tm_min, -1);
128
+	ck_assert_int_eq(tm.tm_hour, 2);
129
+	ck_assert_int_eq(tm.tm_mday, -1);
130
+	ck_assert_int_eq(tm.tm_mon, -1);
131
+	ck_assert_int_eq(tm.tm_year, 2);
132
+
133
+	tm = ttail->date_max;
134
+	ck_assert_int_eq(tm.tm_sec, -1);
135
+	ck_assert_int_eq(tm.tm_min, -1);
136
+	ck_assert_int_eq(tm.tm_hour, 2);
137
+	ck_assert_int_eq(tm.tm_mday, -1);
138
+	ck_assert_int_eq(tm.tm_mon, -1);
139
+	ck_assert_int_eq(tm.tm_year, 2);
140
+}
141
+END_TEST
142
+
143
+START_TEST (test_norm_dates_flags_full)
144
+{
145
+	struct tm tm;
146
+	int ret;
147
+
148
+	ttail->flag |= TTAIL_FLAG_DATE_MAX;
149
+	ttail->flag |= TTAIL_FLAG_DATE_MIN;
150
+	ttail_set_fmt(ttail, "%Y %m %d %H-%M-%S");
151
+	tm.tm_sec = tm.tm_min = tm.tm_hour = tm.tm_mday = tm.tm_mon = \
152
+	tm.tm_year = 2;
153
+	ttail->date_min = tm;
154
+	ttail->date_max = tm;
155
+
156
+	ret = _ttail_norm_dates(ttail);
157
+	ck_assert_int_eq(ret, 0);
158
+	
159
+	tm = ttail->date_min;
160
+	ck_assert_int_eq(tm.tm_sec, 2);
161
+	ck_assert_int_eq(tm.tm_min, 2);
162
+	ck_assert_int_eq(tm.tm_hour, 2);
163
+	ck_assert_int_eq(tm.tm_mday, 2);
164
+	ck_assert_int_eq(tm.tm_mon, 2);
165
+	ck_assert_int_eq(tm.tm_year, 2);
166
+
167
+	tm = ttail->date_max;
168
+	ck_assert_int_eq(tm.tm_sec, 2);
169
+	ck_assert_int_eq(tm.tm_min, 2);
170
+	ck_assert_int_eq(tm.tm_hour, 2);
171
+	ck_assert_int_eq(tm.tm_mday, 2);
172
+	ck_assert_int_eq(tm.tm_mon, 2);
173
+	ck_assert_int_eq(tm.tm_year, 2);
174
+}
175
+END_TEST
176
+
177
+
178
+Suite * ttail_init_suite(void)
179
+{
180
+	Suite *s;
181
+	TCase	*tc_init_norm_dates;
182
+
183
+	s = suite_create("ttail init checks");
184
+
185
+	tc_init_norm_dates = tcase_create("ttail_init_check() checks");
186
+	tcase_add_checked_fixture(tc_init_norm_dates,
187
+		setup_ttail_empty, teardown_ttail);
188
+	tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_none);
189
+	tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_min);
190
+	tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_max);
191
+	tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_both);
192
+	tcase_add_test(tc_init_norm_dates, test_norm_dates_flags_full);
193
+
194
+	suite_add_tcase(s, tc_init_norm_dates);
195
+	return s;
196
+}
197
+
198
+TTAIL_CHECK_MAIN(ttail_init_suite)

Loading…
Отказ
Запис