[asterisk-commits] tilghman: branch tilghman/str_substitution r181844 - in /team/tilghman/str_su...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 12 16:10:28 CDT 2009


Author: tilghman
Date: Thu Mar 12 16:10:25 2009
New Revision: 181844

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=181844
Log:
More tests, and fixup a problem in CURL found with the tests

Modified:
    team/tilghman/str_substitution/funcs/func_curl.c
    team/tilghman/str_substitution/tests/test_substitution.c

Modified: team/tilghman/str_substitution/funcs/func_curl.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/funcs/func_curl.c?view=diff&rev=181844&r1=181843&r2=181844
==============================================================================
--- team/tilghman/str_substitution/funcs/func_curl.c (original)
+++ team/tilghman/str_substitution/funcs/func_curl.c Thu Mar 12 16:10:25 2009
@@ -455,15 +455,17 @@
 	int hashcompat = 0;
 	AST_LIST_HEAD(global_curl_info, curl_settings) *list = NULL;
 
-	*buf = '\0';
-	
+	if (buf) {
+		*buf = '\0';
+	}
+
 	if (ast_strlen_zero(info)) {
 		ast_log(LOG_WARNING, "CURL requires an argument (URL)\n");
 		ast_free(str);
 		return -1;
 	}
 
-	AST_STANDARD_APP_ARGS(args, info);	
+	AST_STANDARD_APP_ARGS(args, info);
 
 	if (chan) {
 		ast_autoservice_start(chan);
@@ -553,7 +555,7 @@
 
 	if (chan)
 		ast_autoservice_stop(chan);
-	
+
 	return ret;
 }
 

Modified: team/tilghman/str_substitution/tests/test_substitution.c
URL: http://svn.digium.com/svn-view/asterisk/team/tilghman/str_substitution/tests/test_substitution.c?view=diff&rev=181844&r1=181843&r2=181844
==============================================================================
--- team/tilghman/str_substitution/tests/test_substitution.c (original)
+++ team/tilghman/str_substitution/tests/test_substitution.c Thu Mar 12 16:10:25 2009
@@ -121,6 +121,17 @@
 		okay = 0;
 	}
 	ast_cli(fd, "Testing '%s' . . . . . %s\n", expression, okay ? "passed" : "FAILED");
+}
+
+static void test_2way_function(int fd, struct ast_channel *c, const char *encode1, const char *encode2, const char *decode1, const char *decode2)
+{
+	struct ast_str *str = ast_str_thread_get(&buf_buf, 16), *expression = ast_str_alloca(120);
+
+	ast_str_set(&expression, 0, "%s%s%s", encode1, "foobarbaz", encode2);
+	ast_str_substitute_variables(&str, 0, c, ast_str_buffer(expression));
+	ast_str_set(&expression, 0, "%s%s%s", decode1, ast_str_buffer(str), decode2);
+	ast_str_substitute_variables(&str, 0, c, ast_str_buffer(expression));
+	ast_cli(fd, "Testing '%s%s' and '%s%s' . . . . . %s\n", encode1, encode2, decode1, decode2, !strcmp(ast_str_buffer(str), "foobarbaz") ? "passed" : "FAILED");
 }
 
 static char *handle_cli_test_substitution(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
@@ -158,6 +169,13 @@
 	test_chan_variable(a->fd, c, "CHANNEL(musicclass)");
 	test_chan_variable(a->fd, c, "CHANNEL(parkinglot)");
 	test_chan_variable(a->fd, c, "CALLERID(name)");
+	test_chan_variable(a->fd, c, "CURLOPT(proxyuserpwd)");
+	test_chan_variable(a->fd, c, "CDR(foo)");
+	test_chan_variable(a->fd, c, "ENV(foo)");
+	test_chan_variable(a->fd, c, "GLOBAL(foo)");
+	test_chan_variable(a->fd, c, "GROUP()");
+	test_2way_function(a->fd, c, "${AES_ENCRYPT(abcdefghijklmnop,", ")}", "${AES_DECRYPT(abcdefghijklmnop,", ")}");
+	test_2way_function(a->fd, c, "${BASE64_ENCODE(", ")}", "${BASE64_DECODE(", ")}");
 
 	/* For testing dialplan functions */
 	for (i = 0; ; i++) {
@@ -165,14 +183,12 @@
 		if (cmd == NULL) {
 			break;
 		}
-		if (strcmp(cmd, "CHANNEL") && strcmp(cmd, "CALLERID")) {
+		if (strcmp(cmd, "CHANNEL") && strcmp(cmd, "CALLERID") && strcmp(cmd, "CURLOPT") && strncmp(cmd, "AES", 3) && strncmp(cmd, "BASE64", 6) && strcmp(cmd, "CDR") && strcmp(cmd, "ENV") && strcmp(cmd, "GLOBAL") && strcmp(cmd, "GROUP") && strcmp(cmd, "CUT") && strcmp(cmd, "LISTFILTER") && strcmp(cmd, "PP_EACH_EXTENSION") && strcmp(cmd, "SET")) {
 			struct ast_custom_function *acf = ast_custom_function_find(cmd);
 			if (acf->read && acf->read2) {
 				char expression[80];
 				snprintf(expression, sizeof(expression), "${%s(foo)}", cmd);
 				test_chan_function(a->fd, c, expression);
-			} else {
-				ast_cli(a->fd, "No test defined for function '%s'\n", cmd);
 			}
 		}
 		ast_free(cmd);




More information about the asterisk-commits mailing list