Coverage Report

Created: 2026-08-08 06:43

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