File: parser_test.c

package info (click to toggle)
cfengine3 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,256 kB
  • ctags: 9,613
  • sloc: ansic: 116,129; sh: 12,366; yacc: 1,088; makefile: 1,006; lex: 391; perl: 197; xml: 21; sed: 4
file content (274 lines) | stat: -rw-r--r-- 7,572 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
#include <test.h>

#include <policy.h>
#include <misc_lib.h>                                          /* xsnprintf */
#include <parser.h>


static Policy *TestParsePolicy(const char *filename)
{
    char path[PATH_MAX];
    xsnprintf(path, sizeof(path), "%s/%s", TESTDATADIR, filename);

    return ParserParseFile(AGENT_TYPE_COMMON, path, PARSER_WARNING_ALL, PARSER_WARNING_ALL);
}

void test_benchmark(void)
{
    Policy *p = TestParsePolicy("benchmark.cf");
    assert_true(p);
    PolicyDestroy(p);
}

void test_no_bundle_or_body_keyword(void)
{
    assert_false(TestParsePolicy("no_bundle_or_body_keyword.cf"));
}

void test_bundle_invalid_type(void)
{
    assert_false(TestParsePolicy("bundle_invalid_type.cf"));
}

void test_body_invalid_type(void)
{
    assert_false(TestParsePolicy("body_invalid_type.cf"));
}

void test_constraint_ifvarclass_invalid(void)
{
    Policy *p = TestParsePolicy("constraint_ifvarclass_invalid.cf");
    assert_false(p);
}

void test_bundle_args_invalid_type(void)
{
    assert_false(TestParsePolicy("bundle_args_invalid_type.cf"));
}

void test_bundle_args_forgot_cp(void)
{
    assert_false(TestParsePolicy("bundle_args_forgot_cp.cf"));
}

void test_bundle_body_forgot_ob(void)
{
    assert_false(TestParsePolicy("bundle_body_forgot_ob.cf"));
}

void test_bundle_invalid_promise_type(void)
{
    assert_false(TestParsePolicy("bundle_invalid_promise_type.cf"));
}

void test_bundle_body_wrong_promise_type_token(void)
{
    assert_false(TestParsePolicy("bundle_body_wrong_promise_type_token.cf"));
}

void test_bundle_body_wrong_statement(void)
{
    assert_false(TestParsePolicy("bundle_body_wrong_statement.cf"));
}

void test_bundle_body_forgot_semicolon(void)
{
    assert_false(TestParsePolicy("bundle_body_forgot_semicolon.cf"));
}

void test_bundle_body_promiser_statement_contains_colon(void)
{
    assert_false(TestParsePolicy("bundle_body_promiser_statement_contains_colon.cf"));
}

void test_bundle_body_promiser_statement_missing_assign(void)
{
    assert_false(TestParsePolicy("bundle_body_promiser_statement_missing_assign.cf"));
}

void test_bundle_body_promisee_missing_arrow(void)
{
    assert_false(TestParsePolicy("bundle_body_promise_missing_arrow.cf"));
}

void test_bundle_body_promiser_wrong_constraint_token(void)
{
    assert_false(TestParsePolicy("bundle_body_promiser_wrong_constraint_token.cf"));
}

void test_bundle_body_promiser_unknown_constraint_id(void)
{
    assert_false(TestParsePolicy("bundle_body_promiser_unknown_constraint_id.cf"));
}

void test_body_edit_line_common_constraints(void)
{
    assert_true(TestParsePolicy("body_edit_line_common_constraints.cf"));
}

void test_body_edit_xml_common_constraints(void)
{
    assert_true(TestParsePolicy("body_edit_xml_common_constraints.cf"));
}

void test_promise_promiser_nonscalar(void)
{
    assert_false(TestParsePolicy("promise_promiser_nonscalar.cf"));
}

void test_bundle_body_promiser_forgot_colon(void)
{
    assert_false(TestParsePolicy("bundle_body_promiser_forgot_colon.cf"));
}

void test_bundle_body_promisee_no_colon_allowed(void)
{
    assert_false(TestParsePolicy("bundle_body_promisee_no_colon_allowed.cf"));
}

void test_bundle_body_forget_cb_eof(void)
{
    assert_false(TestParsePolicy("bundle_body_forget_cb_eof.cf"));
}

void test_bundle_body_forget_cb_body(void)
{
    assert_false(TestParsePolicy("bundle_body_forget_cb_body.cf"));
}

void test_bundle_body_forget_cb_bundle(void)
{
    assert_false(TestParsePolicy("bundle_body_forget_cb_bundle.cf"));
}

void test_body_selection_wrong_token(void)
{
    assert_false(TestParsePolicy("body_selection_wrong_token.cf"));
}

void test_body_selection_forgot_semicolon(void)
{
    assert_false(TestParsePolicy("body_selection_forgot_semicolon.cf"));
}

void test_body_selection_unknown_selection_id(void)
{
    assert_false(TestParsePolicy("body_selection_unknown_selection_id.cf"));
}

void test_body_body_forget_cb_eof(void)
{
    assert_false(TestParsePolicy("body_body_forget_cb_eof.cf"));
}

void test_body_body_forget_cb_body(void)
{
    assert_false(TestParsePolicy("body_body_forget_cb_body.cf"));
}

void test_body_body_forget_cb_bundle(void)
{
    assert_false(TestParsePolicy("body_body_forget_cb_bundle.cf"));
}

void test_rval_list_forgot_colon(void)
{
    assert_false(TestParsePolicy("rval_list_forgot_colon.cf"));
}

void test_rval_list_wrong_input_type(void)
{
    assert_false(TestParsePolicy("rval_list_wrong_input_type.cf"));
}

void test_rval_function_forgot_colon(void)
{
    assert_false(TestParsePolicy("rval_function_forgot_colon.cf"));
}

void test_rval_function_wrong_input_type(void)
{
    assert_false(TestParsePolicy("rval_function_wrong_input_type.cf"));
}

void test_rval_wrong_input_type(void)
{
    assert_false(TestParsePolicy("rval_wrong_input_type.cf"));
}

void test_rval_list_forgot_cb_semicolon(void)
{
    assert_false(TestParsePolicy("rval_list_forgot_cb_semicolon.cf"));
}

void test_rval_list_forgot_cb_colon(void)
{
    assert_false(TestParsePolicy("rval_list_forgot_cb_colon.cf"));
}

void test_rval_function_forgot_cp_semicolon(void)
{
    assert_false(TestParsePolicy("rval_function_forgot_cp_semicolon.cf"));
}

void test_rval_function_forgot_cp_colon(void)
{
    assert_false(TestParsePolicy("rval_function_forgot_cp_colon.cf"));
}

int main()
{
    PRINT_TEST_BANNER();
    const UnitTest tests[] =
    {
        unit_test(test_benchmark),

        unit_test(test_bundle_invalid_type),
        unit_test(test_bundle_args_invalid_type),
        unit_test(test_bundle_args_forgot_cp),
        unit_test(test_bundle_body_forgot_ob),
        unit_test(test_bundle_invalid_promise_type),
        unit_test(test_bundle_body_wrong_promise_type_token),
        unit_test(test_bundle_body_wrong_statement),
        unit_test(test_bundle_body_forgot_semicolon),
        unit_test(test_bundle_body_promiser_statement_contains_colon),
        unit_test(test_bundle_body_promiser_statement_missing_assign),
        unit_test(test_bundle_body_promisee_missing_arrow),
        unit_test(test_bundle_body_promiser_wrong_constraint_token),
        unit_test(test_bundle_body_promiser_unknown_constraint_id),
        unit_test(test_bundle_body_promiser_forgot_colon),
        unit_test(test_bundle_body_promisee_no_colon_allowed),
        unit_test(test_bundle_body_forget_cb_eof),
        unit_test(test_bundle_body_forget_cb_body),
        unit_test(test_bundle_body_forget_cb_bundle),
        unit_test(test_body_edit_line_common_constraints),
        unit_test(test_body_edit_xml_common_constraints),

        unit_test(test_body_invalid_type),
        unit_test(test_body_selection_wrong_token),
        unit_test(test_body_selection_forgot_semicolon),
        unit_test(test_body_selection_unknown_selection_id),
        unit_test(test_body_body_forget_cb_eof),
        unit_test(test_body_body_forget_cb_body),
        unit_test(test_body_body_forget_cb_bundle),

        unit_test(test_promise_promiser_nonscalar),

        unit_test(test_constraint_ifvarclass_invalid),

        unit_test(test_rval_list_forgot_colon),
        unit_test(test_rval_list_wrong_input_type),
        unit_test(test_rval_list_forgot_cb_semicolon),
        unit_test(test_rval_list_forgot_cb_colon),
        unit_test(test_rval_function_forgot_colon),
        unit_test(test_rval_function_wrong_input_type),
        unit_test(test_rval_function_forgot_cp_semicolon),
        unit_test(test_rval_function_forgot_cp_colon),
        unit_test(test_rval_wrong_input_type),

        unit_test(test_no_bundle_or_body_keyword)

    };

    return run_tests(tests);
}