Coverage Report

Created: 2026-05-30 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/pigeonhole/src/testsuite/tst-test-script-compile.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-script.h"
6
#include "sieve-commands.h"
7
#include "sieve-validator.h"
8
#include "sieve-generator.h"
9
#include "sieve-interpreter.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_script_compile command
20
 *
21
 * Syntax:
22
 *   test_script_compile <scriptpath: string>
23
 */
24
25
static bool tst_test_script_compile_validate
26
  (struct sieve_validator *valdtr, struct sieve_command *cmd);
27
static bool tst_test_script_compile_generate
28
  (const struct sieve_codegen_env *cgenv, struct sieve_command *cmd);
29
30
const struct sieve_command_def tst_test_script_compile = {
31
  .identifier = "test_script_compile",
32
  .type = SCT_TEST,
33
  .positional_args = 1,
34
  .subtests = 0,
35
  .block_allowed = FALSE,
36
  .block_required = FALSE,
37
  .validate = tst_test_script_compile_validate,
38
  .generate = tst_test_script_compile_generate
39
};
40
41
/*
42
 * Operation
43
 */
44
45
static bool tst_test_script_compile_operation_dump
46
  (const struct sieve_dumptime_env *denv, sieve_size_t *address);
47
static int tst_test_script_compile_operation_execute
48
  (const struct sieve_runtime_env *renv, sieve_size_t *address);
49
50
const struct sieve_operation_def test_script_compile_operation = {
51
  .mnemonic = "TEST_SCRIPT_COMPILE",
52
  .ext_def = &testsuite_extension,
53
  .code = TESTSUITE_OPERATION_TEST_SCRIPT_COMPILE,
54
  .dump = tst_test_script_compile_operation_dump,
55
  .execute = tst_test_script_compile_operation_execute
56
};
57
58
/*
59
 * Validation
60
 */
61
62
static bool tst_test_script_compile_validate
63
(struct sieve_validator *valdtr ATTR_UNUSED, 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, "script", 1, SAAT_STRING) ) {
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_script_compile_generate
80
(const struct sieve_codegen_env *cgenv, struct sieve_command *tst)
81
0
{
82
0
  sieve_operation_emit(cgenv->sblock, tst->ext, &test_script_compile_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_script_compile_operation_dump
93
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
94
0
{
95
0
  sieve_code_dumpf(denv, "TEST_SCRIPT_COMPILE:");
96
0
  sieve_code_descend(denv);
97
98
0
  if ( !sieve_opr_string_dump(denv, address, "script-name") )
99
0
    return FALSE;
100
101
0
  return TRUE;
102
0
}
103
104
/*
105
 * Intepretation
106
 */
107
108
static int tst_test_script_compile_operation_execute
109
(const struct sieve_runtime_env *renv, sieve_size_t *address)
110
0
{
111
0
  string_t *script_name;
112
0
  bool result = TRUE;
113
0
  int ret;
114
115
  /*
116
   * Read operands
117
   */
118
119
0
  if ( (ret=sieve_opr_string_read(renv, address, "script-name", &script_name))
120
0
    <= 0 )
121
0
    return ret;
122
123
  /*
124
   * Perform operation
125
   */
126
127
0
  if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) {
128
0
    sieve_runtime_trace(renv, 0, "testsuite: test_script_compile test");
129
0
    sieve_runtime_trace_descend(renv);
130
0
  }
131
132
  /* Attempt script compile */
133
134
0
  result = testsuite_script_compile(renv, str_c(script_name));
135
136
  /* Set result */
137
0
  sieve_interpreter_set_test_result(renv->interp, result);
138
139
0
  return SIEVE_EXEC_OK;
140
0
}
141
142
143
144