Coverage Report

Created: 2026-07-30 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/testsuite/tst-test-multiscript.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-stringlist.h"
10
#include "sieve-code.h"
11
#include "sieve-binary.h"
12
#include "sieve-dump.h"
13
#include "sieve.h"
14
15
#include "testsuite-common.h"
16
#include "testsuite-script.h"
17
18
/*
19
 * Test_multiscript command
20
 *
21
 * Syntax:
22
 *   test_multiscript <scripts: string-list>
23
 */
24
25
static bool tst_test_multiscript_validate
26
  (struct sieve_validator *validator, struct sieve_command *cmd);
27
static bool tst_test_multiscript_generate
28
  (const struct sieve_codegen_env *cgenv, struct sieve_command *tst);
29
30
const struct sieve_command_def tst_test_multiscript = {
31
  .identifier = "test_multiscript",
32
  .type = SCT_TEST,
33
  .positional_args = 1,
34
  .subtests = 0,
35
  .block_allowed = FALSE,
36
  .block_required = FALSE,
37
  .validate = tst_test_multiscript_validate,
38
  .generate = tst_test_multiscript_generate,
39
};
40
41
/*
42
 * Operation
43
 */
44
45
static bool tst_test_multiscript_operation_dump
46
  (const struct sieve_dumptime_env *denv, sieve_size_t *address);
47
static int tst_test_multiscript_operation_execute
48
  (const struct sieve_runtime_env *renv, sieve_size_t *address);
49
50
const struct sieve_operation_def test_multiscript_operation = {
51
  .mnemonic = "TEST_MULTISCRIPT",
52
  .ext_def = &testsuite_extension,
53
  .code = TESTSUITE_OPERATION_TEST_MULTISCRIPT,
54
  .dump = tst_test_multiscript_operation_dump,
55
  .execute = tst_test_multiscript_operation_execute
56
};
57
58
/*
59
 * Validation
60
 */
61
62
static bool tst_test_multiscript_validate
63
(struct sieve_validator *valdtr, struct sieve_command *tst)
64
0
{
65
0
  struct sieve_ast_argument *arg = tst->first_positional;
66
67
0
  if ( !sieve_validate_positional_argument
68
0
    (valdtr, tst, arg, "scripts", 1, SAAT_STRING_LIST) ) {
69
0
    return FALSE;
70
0
  }
71
72
0
  return sieve_validator_argument_activate(valdtr, tst, arg, FALSE);
73
0
}
74
75
/*
76
 * Code generation
77
 */
78
79
static bool tst_test_multiscript_generate
80
(const struct sieve_codegen_env *cgenv, struct sieve_command *tst)
81
0
{
82
0
  sieve_operation_emit(cgenv->sblock, tst->ext, &test_multiscript_operation);
83
84
  /* Generate arguments */
85
0
  return sieve_generate_arguments(cgenv, tst, NULL);
86
0
}
87
88
/*
89
 * Code dump
90
 */
91
92
static bool tst_test_multiscript_operation_dump
93
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
94
0
{
95
0
  sieve_code_dumpf(denv, "TEST_MULTISCRIPT:");
96
0
  sieve_code_descend(denv);
97
98
0
  if ( !sieve_opr_stringlist_dump(denv, address, "scripts") )
99
0
    return FALSE;
100
101
0
  return TRUE;
102
0
}
103
104
/*
105
 * Intepretation
106
 */
107
108
static int tst_test_multiscript_operation_execute
109
(const struct sieve_runtime_env *renv, sieve_size_t *address)
110
0
{
111
0
  struct sieve_stringlist *scripts_list;
112
0
  string_t *script_name;
113
0
  ARRAY_TYPE (const_string) scriptfiles;
114
0
  bool result = TRUE;
115
0
  int ret;
116
117
  /*
118
   * Read operands
119
   */
120
121
0
  if ( (ret=sieve_opr_stringlist_read(renv, address, "scripts", &scripts_list))
122
0
    <= 0 )
123
0
    return ret;
124
125
  /*
126
   * Perform operation
127
   */
128
129
0
  sieve_runtime_trace(renv, SIEVE_TRLVL_TESTS,
130
0
    "testsuite: test_multiscript test");
131
0
  sieve_runtime_trace_descend(renv);
132
133
0
  t_array_init(&scriptfiles, 16);
134
135
0
  script_name = NULL;
136
0
  while ( result &&
137
0
    (ret=sieve_stringlist_next_item(scripts_list, &script_name)) > 0 ) {
138
0
    const char *script = t_strdup(str_c(script_name));
139
140
0
    array_append(&scriptfiles, &script, 1);
141
0
  }
142
143
0
  result = result && (ret >= 0) &&
144
0
    testsuite_script_multiscript(renv, &scriptfiles);
145
146
  /* Set result */
147
0
  sieve_interpreter_set_test_result(renv->interp, result);
148
149
0
  return SIEVE_EXEC_OK;
150
0
}
151
152
153
154