24
24
static bool cmd_test_generate
25
25
(const struct sieve_codegen_env *cgenv, struct sieve_command *md);
27
const struct sieve_command_def cmd_test = {
27
const struct sieve_command_def cmd_test = {
41
41
/* Test operation */
45
45
static int cmd_test_operation_execute
46
46
(const struct sieve_runtime_env *renv, sieve_size_t *address);
48
const struct sieve_operation_def test_operation = {
48
const struct sieve_operation_def test_operation = {
51
51
TESTSUITE_OPERATION_TEST,
52
cmd_test_operation_dump,
53
cmd_test_operation_execute
52
cmd_test_operation_dump,
53
cmd_test_operation_execute
56
56
/* Test_finish operation */
58
58
static int cmd_test_finish_operation_execute
59
59
(const struct sieve_runtime_env *renv, sieve_size_t *address);
61
const struct sieve_operation_def test_finish_operation = {
61
const struct sieve_operation_def test_finish_operation = {
64
64
TESTSUITE_OPERATION_TEST_FINISH,
66
cmd_test_finish_operation_execute
66
cmd_test_finish_operation_execute
73
73
static bool cmd_test_validate
74
(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd)
74
(struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *cmd)
76
76
struct sieve_ast_argument *arg = cmd->first_positional;
78
78
/* Check valid command placement */
79
79
if ( !sieve_command_is_toplevel(cmd) )
82
82
"tests cannot be nested: test command must be issued at top-level");
86
86
if ( !sieve_validate_positional_argument
87
87
(valdtr, cmd, arg, "test-name", 1, SAAT_STRING) ) {
91
91
return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE);
98
98
static inline struct testsuite_generator_context *
99
99
_get_generator_context(struct sieve_generator *gentr)
101
return (struct testsuite_generator_context *)
101
return (struct testsuite_generator_context *)
102
102
sieve_generator_extension_get_context(gentr, testsuite_ext);
105
105
static bool cmd_test_generate
106
106
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
108
struct testsuite_generator_context *genctx =
108
struct testsuite_generator_context *genctx =
109
109
_get_generator_context(cgenv->gentr);
111
111
sieve_operation_emit(cgenv->sbin, cmd->ext, &test_operation);
113
113
/* Generate arguments */
114
114
if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
117
117
/* Prepare jumplist */
118
118
sieve_jumplist_reset(genctx->exit_jumps);
121
121
if ( !sieve_generate_block(cgenv, cmd->ast_node) )
124
124
sieve_operation_emit(cgenv->sbin, cmd->ext, &test_finish_operation);
126
126
/* Resolve exit jumps to this point */
127
sieve_jumplist_resolve(genctx->exit_jumps);
127
sieve_jumplist_resolve(genctx->exit_jumps);
136
136
static bool cmd_test_operation_dump
137
137
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
139
139
sieve_code_dumpf(denv, "TEST:");
140
140
sieve_code_descend(denv);
143
143
sieve_opr_string_dump(denv, address, "test name");
156
156
sieve_runtime_trace_error(renv, "invalid test name operand");
157
157
return SIEVE_EXEC_BIN_CORRUPT;
160
160
sieve_runtime_trace(renv, "TEST \"%s\"", str_c(test_name));
162
162
testsuite_test_start(test_name);
166
166
static int cmd_test_finish_operation_execute
167
(const struct sieve_runtime_env *renv ATTR_UNUSED,
167
(const struct sieve_runtime_env *renv ATTR_UNUSED,
168
168
sieve_size_t *address ATTR_UNUSED)
170
170
sieve_runtime_trace(renv, "TEST FINISHED");
172
172
testsuite_test_succeed(NULL);
173
173
return SIEVE_EXEC_OK;