/src/pigeonhole/src/testsuite/tst-test-script-compile.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | #include "sieve-common.h" |
4 | | #include "sieve-script.h" |
5 | | #include "sieve-commands.h" |
6 | | #include "sieve-validator.h" |
7 | | #include "sieve-generator.h" |
8 | | #include "sieve-interpreter.h" |
9 | | #include "sieve-code.h" |
10 | | #include "sieve-binary.h" |
11 | | #include "sieve-dump.h" |
12 | | #include "sieve.h" |
13 | | |
14 | | #include "testsuite-common.h" |
15 | | #include "testsuite-script.h" |
16 | | |
17 | | /* |
18 | | * Test_script_compile command |
19 | | * |
20 | | * Syntax: |
21 | | * test_script_compile <scriptpath: string> |
22 | | */ |
23 | | |
24 | | static bool tst_test_script_compile_validate |
25 | | (struct sieve_validator *valdtr, struct sieve_command *cmd); |
26 | | static bool tst_test_script_compile_generate |
27 | | (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd); |
28 | | |
29 | | const struct sieve_command_def tst_test_script_compile = { |
30 | | .identifier = "test_script_compile", |
31 | | .type = SCT_TEST, |
32 | | .positional_args = 1, |
33 | | .subtests = 0, |
34 | | .block_allowed = FALSE, |
35 | | .block_required = FALSE, |
36 | | .validate = tst_test_script_compile_validate, |
37 | | .generate = tst_test_script_compile_generate |
38 | | }; |
39 | | |
40 | | /* |
41 | | * Operation |
42 | | */ |
43 | | |
44 | | static bool tst_test_script_compile_operation_dump |
45 | | (const struct sieve_dumptime_env *denv, sieve_size_t *address); |
46 | | static int tst_test_script_compile_operation_execute |
47 | | (const struct sieve_runtime_env *renv, sieve_size_t *address); |
48 | | |
49 | | const struct sieve_operation_def test_script_compile_operation = { |
50 | | .mnemonic = "TEST_SCRIPT_COMPILE", |
51 | | .ext_def = &testsuite_extension, |
52 | | .code = TESTSUITE_OPERATION_TEST_SCRIPT_COMPILE, |
53 | | .dump = tst_test_script_compile_operation_dump, |
54 | | .execute = tst_test_script_compile_operation_execute |
55 | | }; |
56 | | |
57 | | /* |
58 | | * Validation |
59 | | */ |
60 | | |
61 | | static bool tst_test_script_compile_validate |
62 | | (struct sieve_validator *valdtr ATTR_UNUSED, struct sieve_command *tst) |
63 | 0 | { |
64 | 0 | struct sieve_ast_argument *arg = tst->first_positional; |
65 | |
|
66 | 0 | if ( !sieve_validate_positional_argument |
67 | 0 | (valdtr, tst, arg, "script", 1, SAAT_STRING) ) { |
68 | 0 | return FALSE; |
69 | 0 | } |
70 | | |
71 | 0 | return sieve_validator_argument_activate(valdtr, tst, arg, FALSE); |
72 | 0 | } |
73 | | |
74 | | /* |
75 | | * Code generation |
76 | | */ |
77 | | |
78 | | static bool tst_test_script_compile_generate |
79 | | (const struct sieve_codegen_env *cgenv, struct sieve_command *tst) |
80 | 0 | { |
81 | 0 | sieve_operation_emit(cgenv->sblock, tst->ext, &test_script_compile_operation); |
82 | | |
83 | | /* Generate arguments */ |
84 | 0 | return sieve_generate_arguments(cgenv, tst, NULL); |
85 | 0 | } |
86 | | |
87 | | /* |
88 | | * Code dump |
89 | | */ |
90 | | |
91 | | static bool tst_test_script_compile_operation_dump |
92 | | (const struct sieve_dumptime_env *denv, sieve_size_t *address) |
93 | 0 | { |
94 | 0 | sieve_code_dumpf(denv, "TEST_SCRIPT_COMPILE:"); |
95 | 0 | sieve_code_descend(denv); |
96 | |
|
97 | 0 | if ( !sieve_opr_string_dump(denv, address, "script-name") ) |
98 | 0 | return FALSE; |
99 | | |
100 | 0 | return TRUE; |
101 | 0 | } |
102 | | |
103 | | /* |
104 | | * Intepretation |
105 | | */ |
106 | | |
107 | | static int tst_test_script_compile_operation_execute |
108 | | (const struct sieve_runtime_env *renv, sieve_size_t *address) |
109 | 0 | { |
110 | 0 | string_t *script_name; |
111 | 0 | bool result = TRUE; |
112 | 0 | int ret; |
113 | | |
114 | | /* |
115 | | * Read operands |
116 | | */ |
117 | |
|
118 | 0 | if ( (ret=sieve_opr_string_read(renv, address, "script-name", &script_name)) |
119 | 0 | <= 0 ) |
120 | 0 | return ret; |
121 | | |
122 | | /* |
123 | | * Perform operation |
124 | | */ |
125 | | |
126 | 0 | if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) { |
127 | 0 | sieve_runtime_trace(renv, 0, "testsuite: test_script_compile test"); |
128 | 0 | sieve_runtime_trace_descend(renv); |
129 | 0 | } |
130 | | |
131 | | /* Attempt script compile */ |
132 | |
|
133 | 0 | result = testsuite_script_compile(renv, str_c(script_name)); |
134 | | |
135 | | /* Set result */ |
136 | 0 | sieve_interpreter_set_test_result(renv->interp, result); |
137 | |
|
138 | 0 | return SIEVE_EXEC_OK; |
139 | 0 | } |
140 | | |
141 | | |
142 | | |
143 | | |