/src/pigeonhole/src/testsuite/ext-testsuite.c
Line | Count | Source |
1 | | /* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file |
2 | | */ |
3 | | |
4 | | /* Extension testsuite |
5 | | * ------------------- |
6 | | * |
7 | | * Authors: Stephan Bosch |
8 | | * Specification: vendor-specific |
9 | | * (FIXME: provide specification for test authors) |
10 | | * |
11 | | */ |
12 | | |
13 | | /* |
14 | | * Purpose: This custom extension is used to add sieve commands and tests that |
15 | | * act the Sieve engine and on the test suite itself. This practically |
16 | | * provides the means to completely control and thereby test the Sieve |
17 | | * compiler and interpreter. This extension transforms the basic Sieve |
18 | | * language into something much more powerful and suitable to perform |
19 | | * complex self-test operations. Of course, this extension is only |
20 | | * available (as vnd.dovecot.testsuite) when the sieve engine is used |
21 | | * from within the testsuite commandline tool. Test scripts have the |
22 | | * extension .svtest by convention to distinguish them from any normal |
23 | | * sieve scripts that may reside in the same directory. |
24 | | * |
25 | | * WARNING: Although this code can serve as an example on how to write |
26 | | * extensions to the Sieve interpreter, it is generally _NOT_ to be |
27 | | * used as a source for ideas on new Sieve extensions. Many of the |
28 | | * commands and tests that this extension introduces conflict with the |
29 | | * goal and the implied restrictions of the Sieve language. These |
30 | | * restrictions were put in place with good reason. Therefore, do |
31 | | * _NOT_ export functionality provided by this testsuite extension to |
32 | | * your custom extensions that are to be put to general use. |
33 | | */ |
34 | | |
35 | | #include <stdio.h> |
36 | | |
37 | | #include "sieve-common.h" |
38 | | |
39 | | #include "sieve-code.h" |
40 | | #include "sieve-extensions.h" |
41 | | #include "sieve-commands.h" |
42 | | #include "sieve-validator.h" |
43 | | #include "sieve-generator.h" |
44 | | #include "sieve-interpreter.h" |
45 | | #include "sieve-result.h" |
46 | | |
47 | | #include "testsuite-common.h" |
48 | | #include "testsuite-variables.h" |
49 | | #include "testsuite-arguments.h" |
50 | | |
51 | | /* |
52 | | * Operations |
53 | | */ |
54 | | |
55 | | const struct sieve_operation_def *testsuite_operations[] = { |
56 | | &test_operation, |
57 | | &test_finish_operation, |
58 | | &test_fail_operation, |
59 | | &test_config_set_operation, |
60 | | &test_config_unset_operation, |
61 | | &test_config_reload_operation, |
62 | | &test_set_operation, |
63 | | &test_script_compile_operation, |
64 | | &test_script_run_operation, |
65 | | &test_multiscript_operation, |
66 | | &test_error_operation, |
67 | | &test_result_action_operation, |
68 | | &test_result_execute_operation, |
69 | | &test_result_reset_operation, |
70 | | &test_result_print_operation, |
71 | | &test_message_smtp_operation, |
72 | | &test_message_mailbox_operation, |
73 | | &test_message_print_operation, |
74 | | &test_mailbox_create_operation, |
75 | | &test_mailbox_delete_operation, |
76 | | &test_binary_load_operation, |
77 | | &test_binary_save_operation, |
78 | | &test_imap_metadata_set_operation |
79 | | }; |
80 | | |
81 | | /* |
82 | | * Operands |
83 | | */ |
84 | | |
85 | | const struct sieve_operand_def *testsuite_operands[] = { |
86 | | &testsuite_object_operand, |
87 | | &testsuite_substitution_operand, |
88 | | &testsuite_namespace_operand |
89 | | }; |
90 | | |
91 | | /* |
92 | | * Extension |
93 | | */ |
94 | | |
95 | | /* Forward declarations */ |
96 | | |
97 | | static bool ext_testsuite_validator_load |
98 | | (const struct sieve_extension *ext, struct sieve_validator *valdtr); |
99 | | static bool ext_testsuite_generator_load |
100 | | (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv); |
101 | | static bool ext_testsuite_interpreter_load |
102 | | (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, |
103 | | sieve_size_t *address); |
104 | | static bool ext_testsuite_binary_load |
105 | | (const struct sieve_extension *ext, struct sieve_binary *sbin); |
106 | | |
107 | | /* Extension object */ |
108 | | |
109 | | const struct sieve_extension_def testsuite_extension = { |
110 | | .name = "vnd.dovecot.testsuite", |
111 | | .validator_load = ext_testsuite_validator_load, |
112 | | .generator_load = ext_testsuite_generator_load, |
113 | | .interpreter_load = ext_testsuite_interpreter_load, |
114 | | .binary_load = ext_testsuite_binary_load, |
115 | | SIEVE_EXT_DEFINE_OPERATIONS(testsuite_operations), |
116 | | SIEVE_EXT_DEFINE_OPERANDS(testsuite_operands) |
117 | | }; |
118 | | |
119 | | /* Extension implementation */ |
120 | | |
121 | | static bool ext_testsuite_validator_load |
122 | | (const struct sieve_extension *ext, struct sieve_validator *valdtr) |
123 | 0 | { |
124 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test); |
125 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_fail); |
126 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_config_set); |
127 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_config_unset); |
128 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_config_reload); |
129 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_set); |
130 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_result_print); |
131 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_result_reset); |
132 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_message); |
133 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_message_print); |
134 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_mailbox_create); |
135 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_mailbox_delete); |
136 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_binary_load); |
137 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_binary_save); |
138 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_test_imap_metadata_set); |
139 | |
|
140 | 0 | sieve_validator_register_command(valdtr, ext, &tst_test_script_compile); |
141 | 0 | sieve_validator_register_command(valdtr, ext, &tst_test_script_run); |
142 | 0 | sieve_validator_register_command(valdtr, ext, &tst_test_multiscript); |
143 | 0 | sieve_validator_register_command(valdtr, ext, &tst_test_error); |
144 | 0 | sieve_validator_register_command(valdtr, ext, &tst_test_result_action); |
145 | 0 | sieve_validator_register_command(valdtr, ext, &tst_test_result_execute); |
146 | | |
147 | | /* sieve_validator_argument_override(valdtr, SAT_VAR_STRING, ext, |
148 | | &testsuite_string_argument);*/ |
149 | |
|
150 | 0 | testsuite_variables_init(ext, valdtr); |
151 | |
|
152 | 0 | return testsuite_validator_context_initialize(valdtr); |
153 | 0 | } |
154 | | |
155 | | static bool ext_testsuite_generator_load |
156 | | (const struct sieve_extension *ext, const struct sieve_codegen_env *cgenv) |
157 | 0 | { |
158 | 0 | return testsuite_generator_context_initialize(cgenv->gentr, ext); |
159 | 0 | } |
160 | | |
161 | | static bool ext_testsuite_interpreter_load |
162 | | (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, |
163 | | sieve_size_t *address ATTR_UNUSED) |
164 | 0 | { |
165 | 0 | return testsuite_interpreter_context_initialize(renv->interp, ext); |
166 | 0 | } |
167 | | |
168 | | static bool ext_testsuite_binary_load |
169 | | (const struct sieve_extension *ext ATTR_UNUSED, struct sieve_binary *sbin ATTR_UNUSED) |
170 | 0 | { |
171 | 0 | return TRUE; |
172 | 0 | } |
173 | | |
174 | | |
175 | | |