1
1
#include "test-lib.h"
2
2
#include "trailer.h"
3
3
4
- static void t_trailer_iterator (const char * msg , size_t num_expected )
4
+ struct contents {
5
+ const char * raw ;
6
+ const char * key ;
7
+ const char * val ;
8
+ };
9
+
10
+ static void t_trailer_iterator (const char * msg , size_t num_expected ,
11
+ struct contents * contents )
5
12
{
6
13
struct trailer_iterator iter ;
7
14
size_t i = 0 ;
8
15
9
16
trailer_iterator_init (& iter , msg );
10
- while (trailer_iterator_advance (& iter ))
17
+ while (trailer_iterator_advance (& iter )) {
18
+ if (num_expected ) {
19
+ check_str (iter .raw , contents [i ].raw );
20
+ check_str (iter .key .buf , contents [i ].key );
21
+ check_str (iter .val .buf , contents [i ].val );
22
+ }
11
23
i ++ ;
24
+ }
12
25
trailer_iterator_release (& iter );
13
26
14
27
check_uint (i , = = , num_expected );
15
28
}
16
29
17
30
static void run_t_trailer_iterator (void )
18
31
{
32
+
19
33
static struct test_cases {
20
34
const char * name ;
21
35
const char * msg ;
22
36
size_t num_expected ;
37
+ struct contents contents [10 ];
23
38
} tc [] = {
24
39
{
25
40
"empty input" ,
26
41
"" ,
27
- 0
42
+ 0 ,
43
+ {{0 }},
28
44
},
29
45
{
30
46
"no newline at beginning" ,
31
47
"Fixes: x\n"
32
48
"Acked-by: x\n"
33
49
"Reviewed-by: x\n" ,
34
- 0
50
+ 0 ,
51
+ {{0 }},
35
52
},
36
53
{
37
54
"newline at beginning" ,
38
55
"\n"
39
56
"Fixes: x\n"
40
57
"Acked-by: x\n"
41
58
"Reviewed-by: x\n" ,
42
- 3
59
+ 3 ,
60
+ {
61
+ {
62
+ .raw = "Fixes: x\n" ,
63
+ .key = "Fixes" ,
64
+ .val = "x" ,
65
+ },
66
+ {
67
+ .raw = "Acked-by: x\n" ,
68
+ .key = "Acked-by" ,
69
+ .val = "x" ,
70
+ },
71
+ {
72
+ .raw = "Reviewed-by: x\n" ,
73
+ .key = "Reviewed-by" ,
74
+ .val = "x" ,
75
+ },
76
+ {
77
+ 0
78
+ },
79
+ },
43
80
},
44
81
{
45
82
"without body text" ,
@@ -48,7 +85,27 @@ static void run_t_trailer_iterator(void)
48
85
"Fixes: x\n"
49
86
"Acked-by: x\n"
50
87
"Reviewed-by: x\n" ,
51
- 3
88
+ 3 ,
89
+ {
90
+ {
91
+ .raw = "Fixes: x\n" ,
92
+ .key = "Fixes" ,
93
+ .val = "x" ,
94
+ },
95
+ {
96
+ .raw = "Acked-by: x\n" ,
97
+ .key = "Acked-by" ,
98
+ .val = "x" ,
99
+ },
100
+ {
101
+ .raw = "Reviewed-by: x\n" ,
102
+ .key = "Reviewed-by" ,
103
+ .val = "x" ,
104
+ },
105
+ {
106
+ 0
107
+ },
108
+ },
52
109
},
53
110
{
54
111
"with body text, without divider" ,
@@ -63,7 +120,32 @@ static void run_t_trailer_iterator(void)
63
120
"Acked-by: x\n"
64
121
"Reviewed-by: x\n"
65
122
"Signed-off-by: x\n" ,
66
- 4
123
+ 4 ,
124
+ {
125
+ {
126
+ .raw = "Fixes: x\n" ,
127
+ .key = "Fixes" ,
128
+ .val = "x" ,
129
+ },
130
+ {
131
+ .raw = "Acked-by: x\n" ,
132
+ .key = "Acked-by" ,
133
+ .val = "x" ,
134
+ },
135
+ {
136
+ .raw = "Reviewed-by: x\n" ,
137
+ .key = "Reviewed-by" ,
138
+ .val = "x" ,
139
+ },
140
+ {
141
+ .raw = "Signed-off-by: x\n" ,
142
+ .key = "Signed-off-by" ,
143
+ .val = "x" ,
144
+ },
145
+ {
146
+ 0
147
+ },
148
+ },
67
149
},
68
150
{
69
151
"with body text, without divider (second trailer block)" ,
@@ -85,7 +167,22 @@ static void run_t_trailer_iterator(void)
85
167
*/
86
168
"Helped-by: x\n"
87
169
"Signed-off-by: x\n" ,
88
- 2
170
+ 2 ,
171
+ {
172
+ {
173
+ .raw = "Helped-by: x\n" ,
174
+ .key = "Helped-by" ,
175
+ .val = "x" ,
176
+ },
177
+ {
178
+ .raw = "Signed-off-by: x\n" ,
179
+ .key = "Signed-off-by" ,
180
+ .val = "x" ,
181
+ },
182
+ {
183
+ 0
184
+ },
185
+ },
89
186
},
90
187
{
91
188
"with body text, with divider" ,
@@ -103,7 +200,17 @@ static void run_t_trailer_iterator(void)
103
200
* always ignores the divider.
104
201
*/
105
202
"Signed-off-by: x\n" ,
106
- 1
203
+ 1 ,
204
+ {
205
+ {
206
+ .raw = "Signed-off-by: x\n" ,
207
+ .key = "Signed-off-by" ,
208
+ .val = "x" ,
209
+ },
210
+ {
211
+ 0
212
+ },
213
+ },
107
214
},
108
215
{
109
216
"with non-trailer lines in trailer block" ,
@@ -125,7 +232,32 @@ static void run_t_trailer_iterator(void)
125
232
* because we still want to iterate through the entire
126
233
* block.
127
234
*/
128
- 4
235
+ 4 ,
236
+ {
237
+ {
238
+ .raw = "not a trailer line\n" ,
239
+ .key = "not a trailer line" ,
240
+ .val = "" ,
241
+ },
242
+ {
243
+ .raw = "not a trailer line\n" ,
244
+ .key = "not a trailer line" ,
245
+ .val = "" ,
246
+ },
247
+ {
248
+ .raw = "not a trailer line\n" ,
249
+ .key = "not a trailer line" ,
250
+ .val = "" ,
251
+ },
252
+ {
253
+ .raw = "Signed-off-by: x\n" ,
254
+ .key = "Signed-off-by" ,
255
+ .val = "x" ,
256
+ },
257
+ {
258
+ 0
259
+ },
260
+ },
129
261
},
130
262
{
131
263
"with non-trailer lines (one too many) in trailer block" ,
@@ -140,7 +272,8 @@ static void run_t_trailer_iterator(void)
140
272
"not a trailer line\n"
141
273
"not a trailer line\n"
142
274
"Signed-off-by: x\n" ,
143
- 0
275
+ 0 ,
276
+ {{0 }},
144
277
},
145
278
{
146
279
"with non-trailer lines (only 1) in trailer block, but no Git-generated trailers" ,
@@ -162,13 +295,15 @@ static void run_t_trailer_iterator(void)
162
295
"Acked-by: x\n"
163
296
"Acked-by: x\n"
164
297
"not a trailer line\n" ,
165
- 0
298
+ 0 ,
299
+ {{0 }},
166
300
},
167
301
};
168
302
169
303
for (int i = 0 ; i < sizeof (tc ) / sizeof (tc [0 ]); i ++ ) {
170
304
TEST (t_trailer_iterator (tc [i ].msg ,
171
- tc [i ].num_expected ),
305
+ tc [i ].num_expected ,
306
+ tc [i ].contents ),
172
307
"%s" , tc [i ].name );
173
308
}
174
309
}
0 commit comments