/src/pigeonhole/src/testsuite/cmd-test-fail.c
Line | Count | Source |
1 | | /* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file |
2 | | */ |
3 | | |
4 | | #include "sieve-common.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 | | |
13 | | #include "testsuite-common.h" |
14 | | |
15 | | /* |
16 | | * Test_fail command |
17 | | * |
18 | | * Syntax: |
19 | | * test_fail <reason: string> |
20 | | */ |
21 | | |
22 | | static bool |
23 | | cmd_test_fail_validate(struct sieve_validator *valdtr, |
24 | | struct sieve_command *cmd); |
25 | | static bool |
26 | | cmd_test_fail_generate(const struct sieve_codegen_env *cgenv, |
27 | | struct sieve_command *ctx); |
28 | | |
29 | | const struct sieve_command_def cmd_test_fail = { |
30 | | .identifier = "test_fail", |
31 | | .type = SCT_COMMAND, |
32 | | .positional_args = 1, |
33 | | .subtests = 0, |
34 | | .block_allowed = FALSE, |
35 | | .block_required = FALSE, |
36 | | .validate = cmd_test_fail_validate, |
37 | | .generate = cmd_test_fail_generate, |
38 | | }; |
39 | | |
40 | | /* |
41 | | * Test operation |
42 | | */ |
43 | | |
44 | | static bool |
45 | | cmd_test_fail_operation_dump(const struct sieve_dumptime_env *denv, |
46 | | sieve_size_t *address); |
47 | | static int |
48 | | cmd_test_fail_operation_execute(const struct sieve_runtime_env *renv, |
49 | | sieve_size_t *address); |
50 | | |
51 | | const struct sieve_operation_def test_fail_operation = { |
52 | | .mnemonic = "TEST_FAIL", |
53 | | .ext_def = &testsuite_extension, |
54 | | .code = TESTSUITE_OPERATION_TEST_FAIL, |
55 | | .dump = cmd_test_fail_operation_dump, |
56 | | .execute = cmd_test_fail_operation_execute, |
57 | | }; |
58 | | |
59 | | /* |
60 | | * Validation |
61 | | */ |
62 | | |
63 | | static bool |
64 | | cmd_test_fail_validate(struct sieve_validator *valdtr ATTR_UNUSED, |
65 | | struct sieve_command *cmd) |
66 | 0 | { |
67 | 0 | struct sieve_ast_argument *arg = cmd->first_positional; |
68 | |
|
69 | 0 | if (!sieve_validate_positional_argument(valdtr, cmd, arg, "reason", 1, |
70 | 0 | SAAT_STRING)) |
71 | 0 | return FALSE; |
72 | | |
73 | 0 | return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE); |
74 | 0 | } |
75 | | |
76 | | /* |
77 | | * Code generation |
78 | | */ |
79 | | |
80 | | static bool |
81 | | cmd_test_fail_generate(const struct sieve_codegen_env *cgenv, |
82 | | struct sieve_command *cmd) |
83 | 0 | { |
84 | 0 | sieve_operation_emit(cgenv->sblock, cmd->ext, &test_fail_operation); |
85 | | |
86 | | /* Generate arguments */ |
87 | 0 | if (!sieve_generate_arguments(cgenv, cmd, NULL)) |
88 | 0 | return FALSE; |
89 | | |
90 | 0 | return TRUE; |
91 | 0 | } |
92 | | |
93 | | /* |
94 | | * Code dump |
95 | | */ |
96 | | |
97 | | static bool |
98 | | cmd_test_fail_operation_dump(const struct sieve_dumptime_env *denv, |
99 | | sieve_size_t *address) |
100 | 0 | { |
101 | 0 | sieve_code_dumpf(denv, "TEST_FAIL:"); |
102 | 0 | sieve_code_descend(denv); |
103 | |
|
104 | 0 | if (!sieve_opr_string_dump(denv, address, "reason")) |
105 | 0 | return FALSE; |
106 | | |
107 | 0 | return TRUE; |
108 | 0 | } |
109 | | |
110 | | /* |
111 | | * Intepretation |
112 | | */ |
113 | | |
114 | | static int |
115 | | cmd_test_fail_operation_execute(const struct sieve_runtime_env *renv, |
116 | | sieve_size_t *address) |
117 | 0 | { |
118 | 0 | string_t *reason; |
119 | 0 | int ret; |
120 | |
|
121 | 0 | ret = sieve_opr_string_read(renv, address, "reason", &reason); |
122 | 0 | if (ret <= 0) |
123 | 0 | return ret; |
124 | | |
125 | 0 | sieve_runtime_trace(renv, SIEVE_TRLVL_COMMANDS, "testsuite: " |
126 | 0 | "test_fail command; FAIL current test"); |
127 | |
|
128 | 0 | return testsuite_test_fail(renv, reason); |
129 | 0 | } |