dovecot-2.2-pigeonhole: Added basic testsuite items for new Siev...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Mon Nov 17 01:20:48 UTC 2014


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/a4f2d618bae2
changeset: 1968:a4f2d618bae2
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Mon Nov 17 02:20:40 2014 +0100
description:
Added basic testsuite items for new Sieve metadata support.

diffstat:

 Makefile.am                                   |    1 +
 src/lib-sieve/plugins/metadata/tst-metadata.c |    2 +
 src/testsuite/Makefile.am                     |    3 +-
 src/testsuite/cmd-test-imap-metadata.c        |  176 ++++++++++++++++++++++++++
 src/testsuite/ext-testsuite.c                 |    4 +-
 src/testsuite/testsuite-common.h              |    3 +
 src/testsuite/testsuite-mailstore.c           |  133 +++++++++++++++++-
 src/testsuite/testsuite-mailstore.h           |   12 +
 src/testsuite/testsuite.c                     |    2 +-
 tests/extensions/metadata/execute.svtest      |   58 ++++++++
 10 files changed, 379 insertions(+), 15 deletions(-)

diffs (truncated from 563 to 300 lines):

diff -r 0677417707c0 -r a4f2d618bae2 Makefile.am
--- a/Makefile.am	Sun Nov 16 23:16:38 2014 +0100
+++ b/Makefile.am	Mon Nov 17 02:20:40 2014 +0100
@@ -158,6 +158,7 @@
 	tests/extensions/duplicate/errors.svtest \
 	tests/extensions/duplicate/execute.svtest \
 	tests/extensions/duplicate/execute-vnd.svtest \
+	tests/extensions/metadata/execute.svtest \
 	tests/extensions/vnd.dovecot/debug/execute.svtest \
 	tests/deprecated/notify/basic.svtest \
 	tests/deprecated/notify/mailto.svtest \
diff -r 0677417707c0 -r a4f2d618bae2 src/lib-sieve/plugins/metadata/tst-metadata.c
--- a/src/lib-sieve/plugins/metadata/tst-metadata.c	Sun Nov 16 23:16:38 2014 +0100
+++ b/src/lib-sieve/plugins/metadata/tst-metadata.c	Mon Nov 17 02:20:40 2014 +0100
@@ -299,6 +299,8 @@
 		*annotation_r = avalue.value;
 	}
 	(void)imap_metadata_transaction_commit(&imtrans, NULL, NULL);
+	if ( box != NULL )
+		mailbox_free(&box);
 	return status;
 }
 
diff -r 0677417707c0 -r a4f2d618bae2 src/testsuite/Makefile.am
--- a/src/testsuite/Makefile.am	Sun Nov 16 23:16:38 2014 +0100
+++ b/src/testsuite/Makefile.am	Mon Nov 17 02:20:40 2014 +0100
@@ -24,7 +24,8 @@
 	cmd-test-result.c \
 	cmd-test-message.c \
 	cmd-test-mailbox.c \
-	cmd-test-binary.c
+	cmd-test-binary.c \
+	cmd-test-imap-metadata.c
 
 tests = \
 	tst-test-script-compile.c \
diff -r 0677417707c0 -r a4f2d618bae2 src/testsuite/cmd-test-imap-metadata.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/testsuite/cmd-test-imap-metadata.c	Mon Nov 17 02:20:40 2014 +0100
@@ -0,0 +1,176 @@
+/* Copyright (c) 2002-2014 Pigeonhole authors, see the included COPYING file
+ */
+
+#include "sieve-common.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 "testsuite-common.h"
+#include "testsuite-mailstore.h"
+
+/*
+ * Commands
+ */
+
+static bool cmd_test_imap_metadata_validate
+	(struct sieve_validator *valdtr, struct sieve_command *cmd);
+static bool cmd_test_imap_metadata_generate
+	(const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
+
+/* Test_mailbox_create command
+ *
+ * Syntax:
+ *   test_imap_metadata_set
+ *     <mailbox: string> <annotation: string> <value:string>
+ */
+
+const struct sieve_command_def cmd_test_imap_metadata_set = {
+	"test_imap_metadata_set",
+	SCT_COMMAND,
+	3, 0, FALSE, FALSE,
+	NULL, NULL,
+	cmd_test_imap_metadata_validate,
+	NULL,
+	cmd_test_imap_metadata_generate,
+	NULL
+};
+
+/*
+ * Operations
+ */
+
+static bool cmd_test_imap_metadata_operation_dump
+	(const struct sieve_dumptime_env *denv, sieve_size_t *address);
+static int cmd_test_imap_metadata_operation_execute
+	(const struct sieve_runtime_env *renv, sieve_size_t *address);
+
+/* Test_mailbox_create operation */
+
+const struct sieve_operation_def test_imap_metadata_set_operation = {
+	"TEST_IMAP_METADATA_SET",
+	&testsuite_extension,
+	TESTSUITE_OPERATION_TEST_IMAP_METADATA_SET,
+	cmd_test_imap_metadata_operation_dump,
+	cmd_test_imap_metadata_operation_execute
+};
+
+/*
+ * Validation
+ */
+
+static bool cmd_test_imap_metadata_validate
+(struct sieve_validator *valdtr, struct sieve_command *cmd)
+{
+	struct sieve_ast_argument *arg = cmd->first_positional;
+
+	if ( !sieve_validate_positional_argument
+		(valdtr, cmd, arg, "mailbox", 1, SAAT_STRING) )
+		return FALSE;
+
+	if (!sieve_validator_argument_activate(valdtr, cmd, arg, FALSE))
+		return FALSE;
+
+	arg = sieve_ast_argument_next(arg);
+
+	if ( !sieve_validate_positional_argument
+		(valdtr, cmd, arg, "annotation", 2, SAAT_STRING) )
+		return FALSE;
+
+	if (!sieve_validator_argument_activate(valdtr, cmd, arg, FALSE))
+		return FALSE;
+
+	arg = sieve_ast_argument_next(arg);
+
+	if ( !sieve_validate_positional_argument
+		(valdtr, cmd, arg, "value", 3, SAAT_STRING) )
+		return FALSE;
+
+	if (!sieve_validator_argument_activate(valdtr, cmd, arg, FALSE))
+		return FALSE;
+	return TRUE;
+}
+
+/*
+ * Code generation
+ */
+
+static bool cmd_test_imap_metadata_generate
+(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
+{
+	/* Emit operation */
+	if ( sieve_command_is(cmd, cmd_test_imap_metadata_set) )
+		sieve_operation_emit
+			(cgenv->sblock, cmd->ext, &test_imap_metadata_set_operation);
+	else
+		i_unreached();
+
+ 	/* Generate arguments */
+	if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
+		return FALSE;
+	return TRUE;
+}
+
+/*
+ * Code dump
+ */
+
+static bool cmd_test_imap_metadata_operation_dump
+(const struct sieve_dumptime_env *denv, sieve_size_t *address)
+{
+	sieve_code_dumpf(denv, "%s:", sieve_operation_mnemonic(denv->oprtn));
+
+	sieve_code_descend(denv);
+
+	return (sieve_opr_string_dump(denv, address, "mailbox") &&
+		sieve_opr_string_dump(denv, address, "annotation") &&
+		sieve_opr_string_dump(denv, address, "value"));
+}
+
+/*
+ * Intepretation
+ */
+
+static int cmd_test_imap_metadata_operation_execute
+(const struct sieve_runtime_env *renv, sieve_size_t *address)
+{
+	const struct sieve_operation *oprtn = renv->oprtn;
+	string_t *mailbox = NULL, *annotation = NULL, *value = NULL;
+	int ret;
+
+	/*
+	 * Read operands
+	 */
+
+	if ( (ret=sieve_opr_string_read
+		(renv, address, "mailbox", &mailbox)) <= 0 )
+		return ret;
+	if ( (ret=sieve_opr_string_read
+		(renv, address, "annotation", &annotation)) <= 0 )
+		return ret;
+	if ( (ret=sieve_opr_string_read
+		(renv, address, "value", &value)) <= 0 )
+		return ret;
+
+	/*
+	 * Perform operation
+	 */
+
+	if ( sieve_operation_is(oprtn, test_imap_metadata_set_operation) ) {
+		if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
+			sieve_runtime_trace(renv, 0, "testsuite/test_imap_metadata_set command");
+			sieve_runtime_trace_descend(renv);
+			sieve_runtime_trace(renv, 0, "set annotation `%s'", str_c(mailbox));
+		}
+
+		if (testsuite_mailstore_set_imap_metadata
+			(str_c(mailbox), str_c(annotation), str_c(value)) < 0)
+			return SIEVE_EXEC_FAILURE;
+	}
+
+	return SIEVE_EXEC_OK;
+}
diff -r 0677417707c0 -r a4f2d618bae2 src/testsuite/ext-testsuite.c
--- a/src/testsuite/ext-testsuite.c	Sun Nov 16 23:16:38 2014 +0100
+++ b/src/testsuite/ext-testsuite.c	Mon Nov 17 02:20:40 2014 +0100
@@ -74,7 +74,8 @@
 	&test_mailbox_create_operation,
 	&test_mailbox_delete_operation,
 	&test_binary_load_operation,
-	&test_binary_save_operation
+	&test_binary_save_operation,
+	&test_imap_metadata_set_operation
 };
 
 /*
@@ -134,6 +135,7 @@
 	sieve_validator_register_command(valdtr, ext, &cmd_test_mailbox_delete);
 	sieve_validator_register_command(valdtr, ext, &cmd_test_binary_load);
 	sieve_validator_register_command(valdtr, ext, &cmd_test_binary_save);
+	sieve_validator_register_command(valdtr, ext, &cmd_test_imap_metadata_set);
 
 	sieve_validator_register_command(valdtr, ext, &tst_test_script_compile);
 	sieve_validator_register_command(valdtr, ext, &tst_test_script_run);
diff -r 0677417707c0 -r a4f2d618bae2 src/testsuite/testsuite-common.h
--- a/src/testsuite/testsuite-common.h	Sun Nov 16 23:16:38 2014 +0100
+++ b/src/testsuite/testsuite-common.h	Mon Nov 17 02:20:40 2014 +0100
@@ -78,6 +78,7 @@
 extern const struct sieve_command_def cmd_test_mailbox_delete;
 extern const struct sieve_command_def cmd_test_binary_load;
 extern const struct sieve_command_def cmd_test_binary_save;
+extern const struct sieve_command_def cmd_test_imap_metadata_set;
 
 /*
  * Tests
@@ -117,6 +118,7 @@
 	TESTSUITE_OPERATION_TEST_MAILBOX_DELETE,
 	TESTSUITE_OPERATION_TEST_BINARY_LOAD,
 	TESTSUITE_OPERATION_TEST_BINARY_SAVE,
+	TESTSUITE_OPERATION_TEST_IMAP_METADATA_SET
 };
 
 extern const struct sieve_operation_def test_operation;
@@ -141,6 +143,7 @@
 extern const struct sieve_operation_def test_mailbox_delete_operation;
 extern const struct sieve_operation_def test_binary_load_operation;
 extern const struct sieve_operation_def test_binary_save_operation;
+extern const struct sieve_operation_def test_imap_metadata_set_operation;
 
 /*
  * Operands
diff -r 0677417707c0 -r a4f2d618bae2 src/testsuite/testsuite-mailstore.c
--- a/src/testsuite/testsuite-mailstore.c	Sun Nov 16 23:16:38 2014 +0100
+++ b/src/testsuite/testsuite-mailstore.c	Mon Nov 17 02:20:40 2014 +0100
@@ -6,10 +6,13 @@
 #include "imem.h"
 #include "array.h"
 #include "strfuncs.h"
+#include "str-sanitize.h"
+#include "abspath.h"
 #include "unlink-directory.h"
 #include "env-util.h"
 #include "mail-namespace.h"
 #include "mail-storage.h"
+#include "imap-metadata.h"
 
 #include "sieve-common.h"
 #include "sieve-error.h"
@@ -34,7 +37,10 @@
  * State
  */
 
-static char *testsuite_mailstore_tmp = NULL;
+static struct mail_user *testsuite_mailstore_user = NULL;
+
+static char *testsuite_mailstore_location = NULL;
+static char *testsuite_mailstore_attrs = NULL;
 
 static char *testsuite_mailstore_folder = NULL;
 static struct mailbox *testsuite_mailstore_box = NULL;
@@ -47,28 +53,66 @@
 
 void testsuite_mailstore_init(void)
 {
-	testsuite_mailstore_tmp = i_strconcat
-		(testsuite_tmp_dir_get(), "/mailstore", NULL);
+	struct mail_user *mail_user_dovecot, *mail_user;


More information about the dovecot-cvs mailing list