[asterisk-commits] mnicholson: trunk r238716 - /trunk/tests/test_ast_format_str_reduce.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 8 15:04:55 CST 2010


Author: mnicholson
Date: Fri Jan  8 15:04:51 2010
New Revision: 238716

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=238716
Log:
Added a test for ast_format_reduce_str().

(related to issue #16560)

Added:
    trunk/tests/test_ast_format_str_reduce.c   (with props)

Added: trunk/tests/test_ast_format_str_reduce.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_ast_format_str_reduce.c?view=auto&rev=238716
==============================================================================
--- trunk/tests/test_ast_format_str_reduce.c (added)
+++ trunk/tests/test_ast_format_str_reduce.c Fri Jan  8 15:04:51 2010
@@ -1,0 +1,117 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * Matthew Nicholson <mnichiolson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Test ast_format_str_reduce
+ *
+ * \author Matthew Nicholson <mnichiolson at digium.com>
+ */
+
+/*** MODULEINFO
+	<defaultenabled>no</defaultenabled>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/file.h"
+#include "asterisk/test.h"
+
+/* this is an array containting a list of strings to test and the expected
+ * result for each test string.  The list should be terminated by an entry
+ * containing NULL for both elements {NULL, NULL}) */
+static char *test_strings[][2] = {
+	{"wav",                       "wav"},
+	{"wav|ulaw",                  "wav|ulaw"},
+	{"pcm|wav",                   "pcm|wav"},
+	{"pcm|wav|ulaw",              "pcm|wav"},
+	{"wav|ulaw|pcm",              "wav|ulaw"},
+	{"wav|ulaw|pcm|alaw",         "wav|ulaw|alaw"},
+	{"pcm|ulaw|ul|mu|ulw",        "pcm"},
+	{"wav|ulaw|pcm|alaw|sln|raw", "wav|ulaw|alaw|sln"},
+	{"wav|gsm|wav49",             "wav|gsm|wav49"},
+	{"WAV|gsm|wav49",             "WAV|gsm"},
+	{NULL, NULL},
+};
+
+/* this is a NULL terminated array contating a list of strings that should
+ * cause ast_format_str_reduce() to fail */
+static char *fail_strings[] = {
+	"this will fail",            /* format does not exist */
+	"this one|should|fail also", /* format does not exist */
+	NULL,
+};
+
+AST_TEST_DEFINE(ast_format_str_reduce_test_1)
+{
+	int i;
+	char *c;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "ast_format_str_reduce_test_1";
+		info->category = "main/file/";
+		info->summary = "reduce format strings";
+		info->description = "Reduce some format strings and make sure the results match what we expect.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	for (i = 0; test_strings[i][0]; i++) {
+		c = ast_strdupa(test_strings[i][0]);
+		if (!(c = ast_format_str_reduce(c))) {
+			ast_str_set(&args->ast_test_error_str, 0, "Error running ast_format_str_reduce() on string '%s'\n", test_strings[i][0]);
+			return AST_TEST_FAIL;
+		}
+
+		if (strcmp(test_strings[i][1], c)) {
+			ast_str_set(&args->ast_test_error_str, 0, "Format string '%s' reduced to '%s'.  Expected '%s'\n", test_strings[i][0], c, test_strings[i][1]);
+			return AST_TEST_FAIL;
+		}
+	}
+
+	for (i = 0; fail_strings[i]; i++) {
+		c = ast_strdupa(fail_strings[i]);
+		if ((c = ast_format_str_reduce(c))) {
+			ast_str_set(&args->ast_test_error_str, 0, "ast_format_str_reduce() succeded on string '%s' with result '%s', but we expected it to fail\n", fail_strings[i], c);
+			return AST_TEST_FAIL;
+		}
+	}
+
+	return AST_TEST_PASS;
+}
+
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(ast_format_str_reduce_test_1);
+	return 0;
+}
+
+static int load_module(void)
+{
+
+	AST_TEST_REGISTER(ast_format_str_reduce_test_1);
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_format_str_reduce() test module");

Propchange: trunk/tests/test_ast_format_str_reduce.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/tests/test_ast_format_str_reduce.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/tests/test_ast_format_str_reduce.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list