1 /* $NetBSD: test_expr.c,v 1.1.1.2 2014/04/24 12:45:42 pettai Exp $ */
16 { 0, "( FALSE AND FALSE )" },
17 { 0, "( TRUE AND FALSE )" },
18 { 1, "( TRUE AND TRUE )" },
19 { 1, "( TRUE OR TRUE )" },
20 { 1, "( TRUE OR FALSE )" },
21 { 0, "( FALSE OR FALSE )" },
22 { 1, "! ( FALSE OR FALSE )" },
24 { 1, "\"foo\" TAILMATCH \"foo\"" },
25 { 1, "\"foobar\" TAILMATCH \"bar\"" },
26 { 0, "\"foobar\" TAILMATCH \"foo\"" },
28 { 1, "\"foo\" == \"foo\"" },
29 { 0, "\"foo\" == \"bar\"" },
30 { 0, "\"foo\" != \"foo\"" },
31 { 1, "\"foo\" != \"bar\"" },
32 { 1, "%{variable} == \"foo\"" },
33 { 0, "%{variable} == \"bar\"" },
34 { 1, "%{context.variable} == \"foo\"" },
35 { 0, "%{context.variable} == \"bar\"" },
36 { 1, "\"foo\" IN ( \"bar\", \"foo\")" },
37 { 0, "\"foo\" IN ( \"bar\", \"baz\")" },
38 { 0, "\"bar\" IN %{context}" },
39 { 1, "\"foo\" IN %{context}" },
40 { 1, "\"variable\" IN %{context}" },
42 { 1, "\"foo\" IN %{context} AND %{context.variable} == \"foo\"" }
46 main(int argc
, char **argv
)
49 hx509_context context
;
50 hx509_env env
= NULL
, env2
= NULL
;
58 ret
= hx509_context_init(&context
);
60 errx(1, "hx509_context_init failed with %d", ret
);
62 hx509_env_add(context
, &env
, "variable", "foo");
63 hx509_env_add(context
, &env2
, "variable", "foo");
64 hx509_env_add_binding(context
, &env
, "context", env2
);
66 for (i
= 0; i
< sizeof(foo
)/sizeof(foo
[0]); i
++) {
68 expr
= _hx509_expr_parse(foo
[i
].str
);
70 errx(1, "_hx509_expr_parse failed for %d: %s", i
, foo
[i
].str
);
72 val
= _hx509_expr_eval(context
, env
, expr
);
75 errx(1, "_hx509_expr_eval not true when it should: %d: %s",
79 errx(1, "_hx509_expr_eval true when it should not: %d: %s",
83 _hx509_expr_free(expr
);