Skip to content
Snippets Groups Projects
Commit 84b5f74b authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Testsuite: added support for executing results.

parent 0e272ca2
No related branches found
No related tags found
No related merge requests found
......@@ -20,10 +20,15 @@ struct sieve_result;
struct sieve_result *sieve_result_create
(struct sieve_error_handler *ehandler);
void sieve_result_ref(struct sieve_result *result);
void sieve_result_unref(struct sieve_result **result);
pool_t sieve_result_pool(struct sieve_result *result);
struct sieve_error_handler *sieve_result_get_error_handler(struct sieve_result *result);
struct sieve_error_handler *sieve_result_get_error_handler
(struct sieve_result *result);
/*
* Extension support
......
......@@ -42,7 +42,8 @@ tests = \
tst-test-script-compile.c \
tst-test-script-run.c \
tst-test-error.c \
tst-test-result.c
tst-test-result.c \
tst-test-result-execute.c
testsuite_SOURCES = \
testsuite-common.c \
......
......@@ -59,7 +59,8 @@ const struct sieve_operation *testsuite_operations[] = {
&test_script_compile_operation,
&test_script_run_operation,
&test_error_operation,
&test_result_operation
&test_result_operation,
&test_result_execute_operation
};
/*
......@@ -110,6 +111,7 @@ static bool ext_testsuite_validator_load(struct sieve_validator *valdtr)
sieve_validator_register_command(valdtr, &tst_test_script_run);
sieve_validator_register_command(valdtr, &tst_test_error);
sieve_validator_register_command(valdtr, &tst_test_result);
sieve_validator_register_command(valdtr, &tst_test_result_execute);
sieve_validator_argument_override(valdtr, SAT_VAR_STRING,
&testsuite_string_argument);
......
......@@ -339,7 +339,7 @@ static struct sieve_error_handler *_testsuite_script_ehandler_create(void)
return ehandler;
}
static void testsuite_script_clear_messages(void)
void testsuite_script_clear_messages(void)
{
if ( _testsuite_scriptmsg_pool != NULL ) {
if ( array_count(&_testsuite_script_errors) == 0 )
......
......@@ -64,6 +64,7 @@ extern const struct sieve_command tst_test_script_compile;
extern const struct sieve_command tst_test_script_run;
extern const struct sieve_command tst_test_error;
extern const struct sieve_command tst_test_result;
extern const struct sieve_command tst_test_result_execute;
/*
* Operations
......@@ -77,7 +78,8 @@ enum testsuite_operation_code {
TESTSUITE_OPERATION_TEST_SCRIPT_COMPILE,
TESTSUITE_OPERATION_TEST_SCRIPT_RUN,
TESTSUITE_OPERATION_TEST_ERROR,
TESTSUITE_OPERATION_TEST_RESULT
TESTSUITE_OPERATION_TEST_RESULT,
TESTSUITE_OPERATION_TEST_RESULT_EXECUTE,
};
extern const struct sieve_operation test_operation;
......@@ -88,6 +90,7 @@ extern const struct sieve_operation test_script_compile_operation;
extern const struct sieve_operation test_script_run_operation;
extern const struct sieve_operation test_error_operation;
extern const struct sieve_operation test_result_operation;
extern const struct sieve_operation test_result_execute_operation;
/*
* Operands
......@@ -119,6 +122,7 @@ int testsuite_testcase_result(void);
bool testsuite_script_compile(const char *script_path);
bool testsuite_script_run(const struct sieve_runtime_env *renv);
void testsuite_script_clear_messages(void);
void testsuite_script_get_error_init(void);
const char *testsuite_script_get_error_next(bool location);
......
......@@ -2,7 +2,9 @@
*/
#include "sieve-common.h"
#include "sieve-error.h"
#include "sieve-actions.h"
#include "sieve-interpreter.h"
#include "sieve-result.h"
#include "testsuite-common.h"
......@@ -41,3 +43,37 @@ struct sieve_result_iterate_context *testsuite_result_iterate_init(void)
return sieve_result_iterate_init(_testsuite_result);
}
bool testsuite_result_execute(const struct sieve_runtime_env *renv)
{
struct sieve_script_env scriptenv;
struct sieve_exec_status estatus;
int ret;
if ( _testsuite_result == NULL ) {
sieve_runtime_error(renv, sieve_error_script_location(renv->script,0),
"testsuite: no result evaluated yet");
return FALSE;
}
testsuite_script_clear_messages();
/* Compose script execution environment */
memset(&scriptenv, 0, sizeof(scriptenv));
scriptenv.default_mailbox = "INBOX";
scriptenv.namespaces = NULL;
scriptenv.username = "user";
scriptenv.hostname = "host.example.com";
scriptenv.postmaster_address = "postmaster@example.com";
scriptenv.smtp_open = NULL;
scriptenv.smtp_close = NULL;
scriptenv.duplicate_mark = NULL;
scriptenv.duplicate_check = NULL;
/* Execute the result */
ret=sieve_result_execute
(_testsuite_result, renv->msgdata, &scriptenv, &estatus);
return ( ret > 0 );
}
......@@ -11,4 +11,6 @@ void testsuite_result_assign(struct sieve_result *result);
struct sieve_result_iterate_context *testsuite_result_iterate_init(void);
bool testsuite_result_execute(const struct sieve_runtime_env *renv);
#endif /* __TESTSUITE_RESULT_H */
/* Copyright (c) 2002-2008 Dovecot Sieve authors, see the included COPYING file
*/
#include "sieve-common.h"
#include "sieve-script.h"
#include "sieve-commands.h"
#include "sieve-validator.h"
#include "sieve-generator.h"
#include "sieve-interpreter.h"
#include "sieve-code.h"
#include "sieve-binary.h"
#include "sieve-dump.h"
#include "sieve.h"
#include "testsuite-common.h"
#include "testsuite-result.h"
/*
* Test_result_execute command
*
* Syntax:
* test_result_execute
*/
static bool tst_test_result_execute_generate
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
const struct sieve_command tst_test_result_execute = {
"test_result_execute",
SCT_TEST,
0, 0, FALSE, FALSE,
NULL, NULL, NULL,
tst_test_result_execute_generate,
NULL
};
/*
* Operation
*/
static int tst_test_result_execute_operation_execute
(const struct sieve_operation *op,
const struct sieve_runtime_env *renv, sieve_size_t *address);
const struct sieve_operation test_result_execute_operation = {
"test_result_execute",
&testsuite_extension,
TESTSUITE_OPERATION_TEST_RESULT_EXECUTE,
NULL,
tst_test_result_execute_operation_execute
};
/*
* Code generation
*/
static bool tst_test_result_execute_generate
(const struct sieve_codegen_env *cgenv,
struct sieve_command_context *tst ATTR_UNUSED)
{
sieve_operation_emit_code(cgenv->sbin, &test_result_execute_operation);
return TRUE;
}
/*
* Intepretation
*/
static int tst_test_result_execute_operation_execute
(const struct sieve_operation *op ATTR_UNUSED,
const struct sieve_runtime_env *renv,
sieve_size_t *address ATTR_UNUSED)
{
bool result = TRUE;
/*
* Perform operation
*/
result = testsuite_result_execute(renv);
/* Set result */
sieve_interpreter_set_test_result(renv->interp, result);
return SIEVE_EXEC_OK;
}
......@@ -10,7 +10,11 @@ test "RFC Example 1" {
}
if not test_script_run {
test_fail "script execute failed";
test_fail "script run failed";
}
if not test_result_execute {
test_fail "result execute failed";
}
}
......@@ -22,6 +26,10 @@ test "RFC Example 2" {
if not test_script_run {
test_fail "script execute failed";
}
if not test_result_execute {
test_fail "result execute failed";
}
}
/* tel: not supported
......@@ -33,6 +41,10 @@ test "RFC Example 3" {
if not test_script_run {
test_fail "script execute failed";
}
if not test_result_execute {
test_fail "result execute failed";
}
}
*/
......@@ -45,6 +57,10 @@ test "RFC Example 5" {
if not test_script_run {
test_fail "script execute failed";
}
if not test_result_execute {
test_fail "result execute failed";
}
}
*/
......@@ -56,4 +72,8 @@ test "RFC Example 6" {
if not test_script_run {
test_fail "script execute failed";
}
if not test_result_execute {
test_fail "result execute failed";
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.