| 1 |
|
| 2 |
#include "hx_locl.h" |
| 3 |
#include <err.h> |
| 4 |
|
| 5 |
struct foo { |
| 6 |
int val; |
| 7 |
char *str; |
| 8 |
} foo[] = { |
| 9 |
{ 0, "FALSE" }, |
| 10 |
{ 1, "TRUE" }, |
| 11 |
{ 0, "!TRUE" }, |
| 12 |
{ 0, "! TRUE" }, |
| 13 |
{ 0, "!\tTRUE" }, |
| 14 |
{ 0, "( FALSE AND FALSE )" }, |
| 15 |
{ 0, "( TRUE AND FALSE )" }, |
| 16 |
{ 1, "( TRUE AND TRUE )" }, |
| 17 |
{ 1, "( TRUE OR TRUE )" }, |
| 18 |
{ 1, "( TRUE OR FALSE )" }, |
| 19 |
{ 0, "( FALSE OR FALSE )" }, |
| 20 |
{ 1, "! ( FALSE OR FALSE )" }, |
| 21 |
|
| 22 |
{ 1, "\"foo\" TAILMATCH \"foo\"" }, |
| 23 |
{ 1, "\"foobar\" TAILMATCH \"bar\"" }, |
| 24 |
{ 0, "\"foobar\" TAILMATCH \"foo\"" }, |
| 25 |
|
| 26 |
{ 1, "\"foo\" == \"foo\"" }, |
| 27 |
{ 0, "\"foo\" == \"bar\"" }, |
| 28 |
{ 0, "\"foo\" != \"foo\"" }, |
| 29 |
{ 1, "\"foo\" != \"bar\"" }, |
| 30 |
{ 1, "%{variable} == \"foo\"" }, |
| 31 |
{ 0, "%{variable} == \"bar\"" }, |
| 32 |
{ 1, "%{context.variable} == \"foo\"" }, |
| 33 |
{ 0, "%{context.variable} == \"bar\"" }, |
| 34 |
{ 1, "\"foo\" IN ( \"bar\", \"foo\")" }, |
| 35 |
{ 0, "\"foo\" IN ( \"bar\", \"baz\")" }, |
| 36 |
{ 0, "\"bar\" IN %{context}" }, |
| 37 |
{ 1, "\"foo\" IN %{context}" }, |
| 38 |
{ 1, "\"variable\" IN %{context}" }, |
| 39 |
|
| 40 |
{ 1, "\"foo\" IN %{context} AND %{context.variable} == \"foo\"" } |
| 41 |
}; |
| 42 |
|
| 43 |
int |
| 44 |
main(int argc, char **argv) |
| 45 |
{ |
| 46 |
struct hx_expr *expr; |
| 47 |
hx509_context context; |
| 48 |
hx509_env env = NULL, env2 = NULL; |
| 49 |
int val, i, ret; |
| 50 |
|
| 51 |
#if 0 |
| 52 |
extern int yydebug; |
| 53 |
yydebug = 1; |
| 54 |
#endif |
| 55 |
|
| 56 |
ret = hx509_context_init(&context); |
| 57 |
if (ret) |
| 58 |
errx(1, "hx509_context_init failed with %d", ret); |
| 59 |
|
| 60 |
hx509_env_add(context, &env, "variable", "foo"); |
| 61 |
hx509_env_add(context, &env2, "variable", "foo"); |
| 62 |
hx509_env_add_binding(context, &env, "context", env2); |
| 63 |
|
| 64 |
for (i = 0; i < sizeof(foo)/sizeof(foo[0]); i++) { |
| 65 |
|
| 66 |
expr = _hx509_expr_parse(foo[i].str); |
| 67 |
if (expr == NULL) |
| 68 |
errx(1, "_hx509_expr_parse failed for %d: %s", i, foo[i].str); |
| 69 |
|
| 70 |
val = _hx509_expr_eval(context, env, expr); |
| 71 |
if (foo[i].val) { |
| 72 |
if (val == 0) |
| 73 |
errx(1, "_hx509_expr_eval not true when it should: %d: %s", |
| 74 |
i, foo[i].str); |
| 75 |
} else { |
| 76 |
if (val) |
| 77 |
errx(1, "_hx509_expr_eval true when it should not: %d: %s", |
| 78 |
i, foo[i].str); |
| 79 |
} |
| 80 |
|
| 81 |
_hx509_expr_free(expr); |
| 82 |
} |
| 83 |
|
| 84 |
hx509_env_free(&env); |
| 85 |
|
| 86 |
return 0; |
| 87 |
} |