etc/services - sync with NetBSD-8
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hx509 / test_expr.c
blob02f4f1f923c8be9fdf1f72705bffa03a060f738e
1 /* $NetBSD: test_expr.c,v 1.1.1.2 2014/04/24 12:45:42 pettai Exp $ */
4 #include "hx_locl.h"
5 #include <err.h>
7 struct foo {
8 int val;
9 char *str;
10 } foo[] = {
11 { 0, "FALSE" },
12 { 1, "TRUE" },
13 { 0, "!TRUE" },
14 { 0, "! TRUE" },
15 { 0, "!\tTRUE" },
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\"" }
45 int
46 main(int argc, char **argv)
48 struct hx_expr *expr;
49 hx509_context context;
50 hx509_env env = NULL, env2 = NULL;
51 int val, i, ret;
53 #if 0
54 extern int yydebug;
55 yydebug = 1;
56 #endif
58 ret = hx509_context_init(&context);
59 if (ret)
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);
69 if (expr == NULL)
70 errx(1, "_hx509_expr_parse failed for %d: %s", i, foo[i].str);
72 val = _hx509_expr_eval(context, env, expr);
73 if (foo[i].val) {
74 if (val == 0)
75 errx(1, "_hx509_expr_eval not true when it should: %d: %s",
76 i, foo[i].str);
77 } else {
78 if (val)
79 errx(1, "_hx509_expr_eval true when it should not: %d: %s",
80 i, foo[i].str);
83 _hx509_expr_free(expr);
86 hx509_env_free(&env);
88 return 0;