[asterisk-commits] mmichelson: branch 10-digiumphones r361228 - /branches/10-digiumphones/tests/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 4 15:22:25 CDT 2012
Author: mmichelson
Date: Wed Apr 4 15:22:21 2012
New Revision: 361228
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=361228
Log:
Add tests for Digium phone support.
Added:
branches/10-digiumphones/tests/test_config.c (with props)
branches/10-digiumphones/tests/test_custom_control.c (with props)
Added: branches/10-digiumphones/tests/test_config.c
URL: http://svnview.digium.com/svn/asterisk/branches/10-digiumphones/tests/test_config.c?view=auto&rev=361228
==============================================================================
--- branches/10-digiumphones/tests/test_config.c (added)
+++ branches/10-digiumphones/tests/test_config.c Wed Apr 4 15:22:21 2012
@@ -1,0 +1,196 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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 Configuration unit tests
+ *
+ * \author Mark Michelson <mmichelson at digium.com>
+ *
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$");
+
+#include "asterisk/config.h"
+#include "asterisk/module.h"
+#include "asterisk/test.h"
+
+const char cat1[] = "Capitals";
+const char cat1varname1[] = "Germany";
+const char cat1varvalue1[] = "Berlin";
+const char cat1varname2[] = "China";
+const char cat1varvalue2[] = "Beijing";
+const char cat1varname3[] = "Canada";
+const char cat1varvalue3[] = "Ottawa";
+
+const char cat2[] = "Protagonists";
+const char cat2varname1[] = "1984";
+const char cat2varvalue1[] = "Winston Smith";
+const char cat2varname2[] = "Green Eggs And Ham";
+const char cat2varvalue2[] = "Sam I Am";
+const char cat2varname3[] = "The Kalevala";
+const char cat2varvalue3[] = "Vainamoinen";
+
+struct pair {
+ const char *name;
+ const char *val;
+};
+
+struct association {
+ const char *category;
+ struct pair vars[3];
+} categories [] = {
+ { cat1,
+ {
+ { cat1varname1, cat1varvalue1 },
+ { cat1varname2, cat1varvalue2 },
+ { cat1varname3, cat1varvalue3 },
+ }
+ },
+ { cat2,
+ {
+ { cat2varname1, cat2varvalue1 },
+ { cat2varname2, cat2varvalue2 },
+ { cat2varname3, cat2varvalue3 },
+ }
+ },
+};
+
+static struct ast_config *build_cfg(void)
+{
+ struct ast_config *cfg;
+ struct association *cat_iter;
+ struct pair *var_iter;
+ size_t i;
+ size_t j;
+
+ cfg = ast_config_new();
+ if (!cfg) {
+ goto fail;
+ }
+
+ for (i = 0; i < ARRAY_LEN(categories); ++i) {
+ struct ast_category *cat;
+ cat_iter = &categories[i];
+
+ cat = ast_category_new(cat_iter->category, "", 999999);
+ if (!cat) {
+ goto fail;
+ }
+ ast_category_append(cfg, cat);
+
+ for (j = 0; j < ARRAY_LEN(cat_iter->vars); ++j) {
+ struct ast_variable *var;
+ var_iter = &cat_iter->vars[j];
+
+ var = ast_variable_new(var_iter->name, var_iter->val, "");
+ if (!var) {
+ goto fail;
+ }
+ ast_variable_append(cat, var);
+ }
+ }
+
+ return cfg;
+
+fail:
+ ast_config_destroy(cfg);
+ return NULL;
+}
+
+AST_TEST_DEFINE(copy_config)
+{
+ enum ast_test_result_state res = AST_TEST_FAIL;
+ struct ast_config *cfg = NULL;
+ struct ast_config *copy = NULL;
+ const char *cat_iter = NULL;
+ size_t i;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "copy_config";
+ info->category = "/main/config/";
+ info->summary = "Test copying configuration";
+ info->description =
+ "Ensure that variables and categories are copied correctly";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ cfg = build_cfg();
+ if (!cfg) {
+ goto out;
+ }
+
+ copy = ast_config_copy(cfg);
+ if (!copy) {
+ goto out;
+ }
+
+ /* Okay, let's see if the correct content is there */
+ for (i = 0; i < ARRAY_LEN(categories); ++i) {
+ struct ast_variable *var = NULL;
+ size_t j;
+ cat_iter = ast_category_browse(copy, cat_iter);
+ if (strcmp(cat_iter, categories[i].category)) {
+ ast_log(LOG_ERROR, "Category name mismatch, %s does not match %s\n", cat_iter, categories[i].category);
+ goto out;
+ }
+ for (j = 0; j < ARRAY_LEN(categories[i].vars); ++j) {
+ var = var ? var->next : ast_variable_browse(copy, cat_iter);
+ if (strcmp(var->name, categories[i].vars[j].name)) {
+ ast_log(LOG_ERROR, "Variable name mismatch, %s does not match %s\n", var->name, categories[i].vars[j].name);
+ goto out;
+ }
+ if (strcmp(var->value, categories[i].vars[j].val)) {
+ ast_log(LOG_ERROR, "Variable value mismatch, %s does not match %s\n", var->value, categories[i].vars[j].val);
+ goto out;
+ }
+ }
+ }
+
+ res = AST_TEST_PASS;
+
+out:
+ ast_config_destroy(cfg);
+ ast_config_destroy(copy);
+ return res;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(copy_config);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(copy_config);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Config test module");
+
Propchange: branches/10-digiumphones/tests/test_config.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: branches/10-digiumphones/tests/test_config.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: branches/10-digiumphones/tests/test_config.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: branches/10-digiumphones/tests/test_custom_control.c
URL: http://svnview.digium.com/svn/asterisk/branches/10-digiumphones/tests/test_custom_control.c?view=auto&rev=361228
==============================================================================
--- branches/10-digiumphones/tests/test_custom_control.c (added)
+++ branches/10-digiumphones/tests/test_custom_control.c Wed Apr 4 15:22:21 2012
@@ -1,0 +1,236 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2011-2012, Digium, Inc.
+ *
+ * David Vossel <dvossel 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 custom control frame encode and decode functions.
+ *
+ * \author David Vossel <dvossel at digium.com>
+ */
+
+/*** MODULEINFO
+ <depend>TEST_FRAMEWORK</depend>
+ <support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/custom_control_frame.h"
+#include "asterisk/test.h"
+
+AST_TEST_DEFINE(sipinfo_encode_decode_test)
+{
+ struct ast_variable *headers = NULL;
+ struct ast_variable *var = NULL;
+ struct ast_variable **cur = NULL;
+ struct ast_custom_payload *pl = NULL;
+ char *out_content = NULL;
+ char *out_content_type = NULL;
+ char *useragent_filter = NULL;
+ int res = AST_TEST_FAIL;
+ struct {
+ int num_headers_set;
+ char *header1;
+ char *header_val1;
+ char *header2;
+ char *header_val2;
+ char *header3;
+ char *header_val3;
+ char *content;
+ char *content_type;
+ char *useragent_filter;
+ } test_cases[] = {
+ {
+ 3,
+ "X-blah-header",
+ "blah-value",
+ "X-blah2-header",
+ "blah2-value",
+ "X-blah3-header",
+ "blah3-value",
+ "{ 'jsonjunk': hooray }",
+ "application/json",
+ NULL,
+ },
+ {
+ 2,
+ "X-blah-header",
+ "blah-value",
+ "X-blah2-header",
+ "blah2-value",
+ NULL,
+ NULL,
+ "{ 'jsonjunk': hooray }",
+ "application/json",
+ NULL,
+ },
+ {
+ 2,
+ "X-blah-header",
+ "blah-value",
+ "X-blah2-header",
+ "blah2-value",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ },
+ {
+ 3,
+ "X-blah-header",
+ "blah-value",
+ "X-blah2-header",
+ "blah2-value",
+ "X-blah3-header",
+ "blah3-value",
+ "{ 'jsonjunk': hooray }",
+ "application/json",
+ "Digium",
+ },
+ {
+ 2,
+ "X-blah-header",
+ "blah-value",
+ "X-blah2-header",
+ "blah2-value",
+ NULL,
+ NULL,
+ "{ 'jsonjunk': hooray }",
+ "application/json",
+ "Digium",
+ },
+ {
+ 2,
+ "X-blah-header",
+ "blah-value",
+ "X-blah2-header",
+ "blah2-value",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ "Digium",
+ },
+ };
+ int i;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "sipinfo_encode_decode_test";
+ info->category = "/main/custom_control_frame/";
+ info->summary = "encode and decode sip info custom control frames.";
+ info->description = "Verifies the encode and decode routines for AST_CONTROL_CUSTOM sip info payloads.";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ for (i = 0; i < ARRAY_LEN(test_cases); i++) {
+ int num_headers = 0;
+ cur = &headers;
+ if (test_cases[i].header1) {
+ *cur = ast_variable_new(test_cases[i].header1, test_cases[i].header_val1, "");
+ cur = &(*cur)->next;
+ }
+ if (test_cases[i].header2) {
+ *cur = ast_variable_new(test_cases[i].header2, test_cases[i].header_val2, "");
+ cur = &(*cur)->next;
+ }
+ if (test_cases[i].header3) {
+ *cur = ast_variable_new(test_cases[i].header3, test_cases[i].header_val3, "");
+ cur = &(*cur)->next;
+ }
+ if (!(pl = ast_custom_payload_sipinfo_encode(headers, test_cases[i].content, test_cases[i].content_type, test_cases[i].useragent_filter))) {
+ goto sipinfo_cleanup;
+ }
+ ast_variables_destroy(headers);
+ headers = NULL;
+
+ if (ast_custom_payload_sipinfo_decode(pl, &headers, &out_content, &out_content_type, &useragent_filter)) {
+ goto sipinfo_cleanup;
+ }
+
+ for (var = headers; var; var = var->next) {
+ num_headers++;
+ if (num_headers == 1) {
+ if (strcmp(var->name, test_cases[i].header1) || strcmp(var->value, test_cases[i].header_val1)) {
+ goto sipinfo_cleanup;
+ }
+ } else if (num_headers == 2) {
+ if (strcmp(var->name, test_cases[i].header2) || strcmp(var->value, test_cases[i].header_val2)) {
+ goto sipinfo_cleanup;
+ }
+
+ } else if (num_headers == 3) {
+ if (strcmp(var->name, test_cases[i].header3) || strcmp(var->value, test_cases[i].header_val3)) {
+ goto sipinfo_cleanup;
+ }
+ }
+ }
+ if (num_headers != test_cases[i].num_headers_set) {
+ goto sipinfo_cleanup;
+ }
+ if (test_cases[i].content && strcmp(test_cases[i].content, out_content)) {
+ goto sipinfo_cleanup;
+ }
+ if (test_cases[i].content_type && strcmp(test_cases[i].content_type, out_content_type)) {
+ goto sipinfo_cleanup;
+ }
+ if (test_cases[i].useragent_filter && strcmp(test_cases[i].useragent_filter, useragent_filter)) {
+ goto sipinfo_cleanup;
+ }
+ ast_variables_destroy(headers);
+ ast_free(pl);
+ ast_free(out_content);
+ ast_free(out_content_type);
+ ast_free(useragent_filter);
+ headers = NULL;
+ pl = NULL;
+ out_content = out_content_type = useragent_filter = NULL;
+ }
+ res = AST_TEST_PASS;
+
+sipinfo_cleanup:
+
+ ast_free(pl);
+ ast_free(out_content);
+ ast_free(out_content_type);
+ ast_variables_destroy(headers);
+ return res;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(sipinfo_encode_decode_test);
+ return 0;
+}
+
+static int load_module(void)
+{
+
+ AST_TEST_REGISTER(sipinfo_encode_decode_test);
+
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Custom control frames test module");
+
Propchange: branches/10-digiumphones/tests/test_custom_control.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: branches/10-digiumphones/tests/test_custom_control.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: branches/10-digiumphones/tests/test_custom_control.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list