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

Testsuite: added support for resetting the result.

parent 8488591c
No related branches found
No related tags found
No related merge requests found
......@@ -170,6 +170,17 @@ struct sieve_error_handler *sieve_interpreter_get_error_handler
return interp->ehandler;
}
/* Do not use this function for normal sieve extensions. This is intended for
* the testsuite only.
*/
void sieve_interpreter_set_result
(struct sieve_interpreter *interp, struct sieve_result *result)
{
sieve_result_unref(&interp->runenv.result);
interp->runenv.result = result;
sieve_result_ref(result);
}
/*
* Error handling
*/
......
......@@ -56,6 +56,12 @@ struct sieve_script *sieve_interpreter_script
struct sieve_error_handler *sieve_interpreter_get_error_handler
(struct sieve_interpreter *interp);
/* Do not use this function for normal sieve extensions. This is intended for
* the testsuite only.
*/
void sieve_interpreter_set_result
(struct sieve_interpreter *interp, struct sieve_result *result);
/*
* Program flow
*/
......
......@@ -37,6 +37,7 @@ commands = \
cmd-test.c \
cmd-test-fail.c \
cmd-test-set.c \
cmd-test-result-reset.c \
cmd-test-result-print.c \
cmd-test-message.c
......
/* Copyright (c) 2002-2009 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"
#include "testsuite-smtp.h"
/*
* Test_result_execute command
*
* Syntax:
* test_result_execute
*/
static bool cmd_test_result_reset_generate
(const struct sieve_codegen_env *cgenv, struct sieve_command_context *ctx);
const struct sieve_command cmd_test_result_reset = {
"test_result_reset",
SCT_COMMAND,
0, 0, FALSE, FALSE,
NULL, NULL, NULL,
cmd_test_result_reset_generate,
NULL
};
/*
* Operation
*/
static int cmd_test_result_reset_operation_execute
(const struct sieve_operation *op,
const struct sieve_runtime_env *renv, sieve_size_t *address);
const struct sieve_operation test_result_reset_operation = {
"TEST_RESULT_RESET",
&testsuite_extension,
TESTSUITE_OPERATION_TEST_RESULT_RESET,
NULL,
cmd_test_result_reset_operation_execute
};
/*
* Code generation
*/
static bool cmd_test_result_reset_generate
(const struct sieve_codegen_env *cgenv,
struct sieve_command_context *tst ATTR_UNUSED)
{
sieve_operation_emit_code(cgenv->sbin, &test_result_reset_operation);
return TRUE;
}
/*
* Intepretation
*/
static int cmd_test_result_reset_operation_execute
(const struct sieve_operation *op ATTR_UNUSED,
const struct sieve_runtime_env *renv,
sieve_size_t *address ATTR_UNUSED)
{
testsuite_result_reset(renv);
testsuite_smtp_reset();
return SIEVE_EXEC_OK;
}
......@@ -61,6 +61,7 @@ const struct sieve_operation *testsuite_operations[] = {
&test_error_operation,
&test_result_operation,
&test_result_execute_operation,
&test_result_reset_operation,
&test_result_print_operation,
&test_message_smtp_operation,
&test_message_mailbox_operation
......@@ -110,6 +111,7 @@ static bool ext_testsuite_validator_load(struct sieve_validator *valdtr)
sieve_validator_register_command(valdtr, &cmd_test_fail);
sieve_validator_register_command(valdtr, &cmd_test_set);
sieve_validator_register_command(valdtr, &cmd_test_result_print);
sieve_validator_register_command(valdtr, &cmd_test_result_reset);
sieve_validator_register_command(valdtr, &cmd_test_message);
sieve_validator_register_command(valdtr, &tst_test_script_compile);
......
......@@ -41,6 +41,7 @@ bool testsuite_generator_context_initialize(struct sieve_generator *gentr);
extern const struct sieve_command cmd_test;
extern const struct sieve_command cmd_test_fail;
extern const struct sieve_command cmd_test_set;
extern const struct sieve_command cmd_test_result_reset;
extern const struct sieve_command cmd_test_result_print;
extern const struct sieve_command cmd_test_message;
......@@ -68,6 +69,7 @@ enum testsuite_operation_code {
TESTSUITE_OPERATION_TEST_ERROR,
TESTSUITE_OPERATION_TEST_RESULT,
TESTSUITE_OPERATION_TEST_RESULT_EXECUTE,
TESTSUITE_OPERATION_TEST_RESULT_RESET,
TESTSUITE_OPERATION_TEST_RESULT_PRINT,
TESTSUITE_OPERATION_TEST_MESSAGE_SMTP,
TESTSUITE_OPERATION_TEST_MESSAGE_MAILBOX
......@@ -82,6 +84,7 @@ 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;
extern const struct sieve_operation test_result_reset_operation;
extern const struct sieve_operation test_result_print_operation;
extern const struct sieve_operation test_message_smtp_operation;
extern const struct sieve_operation test_message_mailbox_operation;
......
......@@ -28,13 +28,15 @@ void testsuite_result_deinit(void)
}
}
void testsuite_result_reset(void)
void testsuite_result_reset
(const struct sieve_runtime_env *renv)
{
if ( _testsuite_result != NULL ) {
sieve_result_unref(&_testsuite_result);
}
_testsuite_result = sieve_result_create(testsuite_log_ehandler);;
_testsuite_result = sieve_result_create(testsuite_log_ehandler);
sieve_interpreter_set_result(renv->interp, _testsuite_result);
}
struct sieve_result *testsuite_result_get(void)
......@@ -52,7 +54,6 @@ struct sieve_result_iterate_context *testsuite_result_iterate_init(void)
bool testsuite_result_execute(const struct sieve_runtime_env *renv)
{
struct sieve_script_env scriptenv;
int ret;
if ( _testsuite_result == NULL ) {
......@@ -63,18 +64,6 @@ bool testsuite_result_execute(const struct sieve_runtime_env *renv)
testsuite_log_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, renv->scriptenv, NULL);
......
......@@ -7,7 +7,8 @@
void testsuite_result_init(void);
void testsuite_result_deinit(void);
void testsuite_result_reset(void);
void testsuite_result_reset
(const struct sieve_runtime_env *renv);
struct sieve_result *testsuite_result_get(void);
......
......@@ -181,7 +181,7 @@ static int tst_test_script_run_operation_execute
/* Reset result object */
if ( !append_result )
testsuite_result_reset();
testsuite_result_reset(renv);
/* Run script */
result = testsuite_script_run(renv);
......
......@@ -38,6 +38,8 @@ test "Simple" {
* Multiple recipients
*/
test_result_reset;
test_set "message" text:
From: stephan@rename-it.nl
To: nico@vestingbar.nl
......@@ -54,7 +56,7 @@ test "Multiple recipients" {
test_fail "failed to execute notify";
}
test_message :smtp 1;
test_message :smtp 0;
if not address :is "to" "timo@example.com" {
test_fail "first To address missing";
......@@ -80,13 +82,13 @@ test "Multiple recipients" {
test_fail "subject header set incorrectly";
}
test_message :smtp 2;
test_message :smtp 1;
if not header :matches "Auto-Submitted" "auto-notified*" {
test_fail "auto-submitted header not found for second message";
}
test_message :smtp 3;
test_message :smtp 2;
if not header :matches "Auto-Submitted" "auto-notified*" {
test_fail "auto-submitted header not found for third message";
......
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.