dovecot-2.2-pigeonhole: testsuite: Created tests for the Sieve s...

pigeonhole at rename-it.nl pigeonhole at rename-it.nl
Thu Nov 20 00:04:08 UTC 2014


details:   http://hg.rename-it.nl/dovecot-2.2-pigeonhole/rev/d0ca187be049
changeset: 1970:d0ca187be049
user:      Stephan Bosch <stephan at rename-it.nl>
date:      Thu Nov 20 00:53:41 2014 +0100
description:
testsuite: Created tests for the Sieve servermetadata extension.

diffstat:

 src/testsuite/cmd-test-imap-metadata.c   |  150 ++++++++++++++++++++++++++----
 src/testsuite/testsuite-mailstore.c      |    1 +
 tests/extensions/metadata/execute.svtest |   64 ++++++++++++-
 3 files changed, 191 insertions(+), 24 deletions(-)

diffs (truncated from 324 to 300 lines):

diff -r b7fad6e195a8 -r d0ca187be049 src/testsuite/cmd-test-imap-metadata.c
--- a/src/testsuite/cmd-test-imap-metadata.c	Thu Nov 20 00:51:09 2014 +0100
+++ b/src/testsuite/cmd-test-imap-metadata.c	Thu Nov 20 00:53:41 2014 +0100
@@ -17,6 +17,9 @@
  * Commands
  */
 
+static bool cmd_test_imap_metadata_registered
+	(struct sieve_validator *valdtr, const struct sieve_extension *ext,
+		struct sieve_command_registration *cmd_reg);
 static bool cmd_test_imap_metadata_validate
 	(struct sieve_validator *valdtr, struct sieve_command *cmd);
 static bool cmd_test_imap_metadata_generate
@@ -32,8 +35,9 @@
 const struct sieve_command_def cmd_test_imap_metadata_set = {
 	"test_imap_metadata_set",
 	SCT_COMMAND,
-	3, 0, FALSE, FALSE,
-	NULL, NULL,
+	2, 0, FALSE, FALSE,
+	cmd_test_imap_metadata_registered,
+	NULL,
 	cmd_test_imap_metadata_validate,
 	NULL,
 	cmd_test_imap_metadata_generate,
@@ -41,6 +45,21 @@
 };
 
 /*
+ * Command tags
+ */
+
+static bool cmd_test_imap_metadata_validate_mailbox_tag
+	(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
+		struct sieve_command *cmd);
+
+static const struct sieve_argument_def test_imap_metadata_mailbox_tag = {
+	"mailbox",
+	NULL,
+	cmd_test_imap_metadata_validate_mailbox_tag,
+	NULL, NULL, NULL
+};
+
+/*
  * Operations
  */
 
@@ -59,6 +78,53 @@
 	cmd_test_imap_metadata_operation_execute
 };
 
+/* Codes for optional arguments */
+
+enum cmd_vacation_optional {
+	OPT_END,
+	OPT_MAILBOX
+};
+
+/*
+ * Tag validation
+ */
+
+static bool cmd_test_imap_metadata_validate_mailbox_tag
+(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
+	struct sieve_command *cmd)
+{
+	struct sieve_ast_argument *tag = *arg;
+
+	/* Delete this tag */
+	*arg = sieve_ast_arguments_detach(*arg, 1);
+
+	/* Check syntax:
+	 *   :mailbox string
+	 */
+	if ( !sieve_validate_tag_parameter
+		(valdtr, cmd, tag, *arg, NULL, 0, SAAT_STRING, FALSE) ) {
+		return FALSE;
+	}
+
+	/* Skip parameter */
+	*arg = sieve_ast_argument_next(*arg);
+	return TRUE;
+}
+
+/*
+ * Command registration
+ */
+
+static bool cmd_test_imap_metadata_registered
+(struct sieve_validator *valdtr, const struct sieve_extension *ext,
+	struct sieve_command_registration *cmd_reg)
+{
+	sieve_validator_register_tag
+		(valdtr, cmd_reg, ext, &test_imap_metadata_mailbox_tag, OPT_MAILBOX);
+	return TRUE;
+}
+
+
 /*
  * Validation
  */
@@ -69,15 +135,6 @@
 	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;
 
@@ -122,13 +179,36 @@
 static bool cmd_test_imap_metadata_operation_dump
 (const struct sieve_dumptime_env *denv, sieve_size_t *address)
 {
+	int opt_code = 0;
+
 	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"));
+	/* Dump optional operands */
+
+	for (;;) {
+		int opt;
+		bool opok = TRUE;
+
+		if ( (opt=sieve_opr_optional_dump(denv, address, &opt_code)) < 0 )
+			return FALSE;
+
+		if ( opt == 0 ) break;
+
+		switch ( opt_code ) {
+		case OPT_MAILBOX:
+			opok = sieve_opr_string_dump(denv, address, "mailbox");
+			break;
+		default:
+			return FALSE;
+		}
+
+		if ( !opok ) return FALSE;
+	}	
+
+	return 
+		( sieve_opr_string_dump(denv, address, "annotation") &&
+			sieve_opr_string_dump(denv, address, "value") );
 }
 
 /*
@@ -139,6 +219,7 @@
 (const struct sieve_runtime_env *renv, sieve_size_t *address)
 {
 	const struct sieve_operation *oprtn = renv->oprtn;
+	int opt_code = 0;
 	string_t *mailbox = NULL, *annotation = NULL, *value = NULL;
 	int ret;
 
@@ -146,9 +227,30 @@
 	 * Read operands
 	 */
 
-	if ( (ret=sieve_opr_string_read
-		(renv, address, "mailbox", &mailbox)) <= 0 )
-		return ret;
+	/* Optional operands */
+
+	for (;;) {
+		int opt;
+
+		if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 )
+			return SIEVE_EXEC_BIN_CORRUPT;
+
+		if ( opt == 0 ) break;
+
+		switch ( opt_code ) {
+		case OPT_MAILBOX:
+			ret = sieve_opr_string_read(renv, address, "mailbox", &mailbox);
+			break;
+		default:
+			sieve_runtime_trace_error(renv, "unknown optional operand");
+			ret = SIEVE_EXEC_BIN_CORRUPT;
+		}
+
+		if ( ret <= 0 ) return ret;
+	}
+
+	/* Fixed operands */
+
 	if ( (ret=sieve_opr_string_read
 		(renv, address, "annotation", &annotation)) <= 0 )
 		return ret;
@@ -164,11 +266,19 @@
 		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 (mailbox == NULL) {
+				sieve_runtime_trace(renv, 0,
+					"set server annotation `%s'", str_c(annotation));
+			} else {
+				sieve_runtime_trace(renv, 0,
+					"set annotation `%s' for mailbox `%s'",
+					str_c(annotation), str_c(mailbox));
+			}
 		}
 
 		if (testsuite_mailstore_set_imap_metadata
-			(str_c(mailbox), str_c(annotation), str_c(value)) < 0)
+			(( mailbox == NULL ? NULL : str_c(mailbox) ),
+				str_c(annotation), str_c(value)) < 0)
 			return SIEVE_EXEC_FAILURE;
 	}
 
diff -r b7fad6e195a8 -r d0ca187be049 src/testsuite/testsuite-mailstore.c
--- a/src/testsuite/testsuite-mailstore.c	Thu Nov 20 00:51:09 2014 +0100
+++ b/src/testsuite/testsuite-mailstore.c	Thu Nov 20 00:53:41 2014 +0100
@@ -256,6 +256,7 @@
 		box = mailbox_alloc(ns->list, mailbox, 0);
 		imtrans = imap_metadata_transaction_begin(box);
 	} else {
+		box = NULL;
 		imtrans = imap_metadata_transaction_begin_server
 			(testsuite_mailstore_user);
 	}
diff -r b7fad6e195a8 -r d0ca187be049 tests/extensions/metadata/execute.svtest
--- a/tests/extensions/metadata/execute.svtest	Thu Nov 20 00:51:09 2014 +0100
+++ b/tests/extensions/metadata/execute.svtest	Thu Nov 20 00:53:41 2014 +0100
@@ -1,5 +1,6 @@
 require "vnd.dovecot.testsuite";
 require "mboxmetadata";
+require "servermetadata";
 require "fileinto";
 
 test "MetadataExists - None exist" {
@@ -8,8 +9,8 @@
 	}
 }
 
-test_imap_metadata_set "INBOX" "/private/frop" "FROP!";
-test_imap_metadata_set "INBOX" "/private/friep" "FRIEP!";
+test_imap_metadata_set :mailbox "INBOX" "/private/frop" "FROP!";
+test_imap_metadata_set :mailbox "INBOX" "/private/friep" "FRIEP!";
 
 test "MetadataExists - Not all exist" {
 	if metadataexists "INBOX"
@@ -18,8 +19,8 @@
 	}
 }
 
-test_imap_metadata_set "INBOX" "/private/friep" "FRIEP!";
-test_imap_metadata_set "INBOX" "/private/frml" "FRML!";
+test_imap_metadata_set :mailbox "INBOX" "/private/friep" "FRIEP!";
+test_imap_metadata_set :mailbox "INBOX" "/private/frml" "FRML!";
 
 test "MetadataExists - One exists" {
 	if not metadataexists "INBOX" ["/private/frop"] {
@@ -56,3 +57,58 @@
 		test_fail "unexpected match for /private/frml";
 	}
 }
+
+test "ServermetadataExists - None exist" {
+	if servermetadataexists "/private/frop" {
+		test_fail "servermetadataexists confirms existence of unknown annotation";
+	}
+}
+
+test_imap_metadata_set "/private/frop" "FROP!";
+test_imap_metadata_set "/private/friep" "FRIEP!";
+
+test "ServermetadataExists - Not all exist" {
+	if servermetadataexists 
+		["/private/frop", "/private/friep", "/private/frml"] {
+		test_fail "metadataexists confirms existence of unknown annotation";
+	}
+}
+
+test_imap_metadata_set "/private/friep" "FRIEP!";
+test_imap_metadata_set "/private/frml" "FRML!";
+
+test "ServermetadataExists - One exists" {
+	if not servermetadataexists ["/private/frop"] {
+		test_fail "servermetadataexists fails to recognize annotation";
+	}
+}
+
+test "ServermetadataExists - All exist" {
+	if not servermetadataexists
+		["/private/frop", "/private/friep", "/private/frml"] {
+		test_fail "metadataexists fails to recognize annotations";
+	}


More information about the dovecot-cvs mailing list