4 * (c) 2015 CZ.NIC z.s.p.o.
6 * Can be freely distributed and used under the terms of the GNU GPL.
16 #include "test/birdtest.h"
17 #include "test/bt-utils.h"
19 #include "filter/filter.h"
20 #include "filter/data.h"
21 #include "filter/f-inst.h"
22 #include "conf/conf.h"
24 #define BT_CONFIG_FILE "filter/test.conf"
27 struct parse_config_file_arg
{
33 parse_config_file(const void *argv
)
35 const struct parse_config_file_arg
*arg
= argv
;
36 size_t fn_size
= strlen(arg
->filename
) + 1;
37 char *filename
= alloca(fn_size
);
38 memcpy(filename
, arg
->filename
, fn_size
);
40 *(arg
->cp
) = bt_config_file_parse(filename
);
45 run_function(const void *arg
)
47 const struct f_bt_test_suite
*t
= arg
;
50 return t
->result
== f_same(t
->fn
, t
->cmp
);
52 linpool
*tmp
= lp_new_default(&root_pool
);
53 enum filter_return fret
= f_eval(t
->fn
, tmp
, NULL
);
56 return (fret
< F_REJECT
);
60 bt_assert_filter(int result
, const struct f_line_item
*assert)
62 int bt_suit_case_result
= 1;
67 bt_suit_case_result
= 0;
70 bt_log_suite_case_result(bt_suit_case_result
, "Assertion at line %d (%s)",
71 assert->lineno
, assert->i_FI_ASSERT
.s
);
75 main(int argc
, char *argv
[])
81 bt_assert_hook
= bt_assert_filter
;
83 struct config
*c
= NULL
;
84 struct parse_config_file_arg pcfa
= { .cp
= &c
, .filename
= BT_CONFIG_FILE
};
86 bt_test_suite_base(parse_config_file
, "conf", (const void *) &pcfa
, 0, 0, "parse config file");
89 bt_test_suite_base(parse_config_file
, "reconf", (const void *) &pcfa
, 0, 0, "reconfigure with the same file");
93 WALK_LIST(s
, c
->symbols
)
94 if ((s
->class == SYM_FUNCTION
) || (s
->class == SYM_FILTER
))
95 bt_assert_msg((s
->flags
& SYM_FLAG_SAME
), "Symbol %s same check", s
->name
);
97 struct f_bt_test_suite
*t
;
98 WALK_LIST(t
, c
->tests
)
99 bt_test_suite_base(run_function
, t
->fn_name
, t
, BT_FORKING
, BT_TIMEOUT
, "%s", t
->dsc
);
102 return bt_exit_value();