From: Mark Michelson Date: Wed, 4 Apr 2012 20:22:21 +0000 (+0000) Subject: Add tests for Digium phone support. X-Git-Tag: 10.4.0-digiumphones-rc1~3^2~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3979ff87b4397d9f6bc58f7a2e0c4530cfb69c5d;p=thirdparty%2Fasterisk.git Add tests for Digium phone support. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/10-digiumphones@361228 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/tests/test_config.c b/tests/test_config.c new file mode 100644 index 0000000000..c4f9698c29 --- /dev/null +++ b/tests/test_config.c @@ -0,0 +1,196 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2010, Digium, Inc. + * + * Mark Michelson + * + * 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 + * + */ + +/*** MODULEINFO + TEST_FRAMEWORK + core + ***/ + +#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"); + diff --git a/tests/test_custom_control.c b/tests/test_custom_control.c new file mode 100644 index 0000000000..4a6c14cb88 --- /dev/null +++ b/tests/test_custom_control.c @@ -0,0 +1,236 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2011-2012, Digium, Inc. + * + * David Vossel + * + * 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 + */ + +/*** MODULEINFO + TEST_FRAMEWORK + core + ***/ + +#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"); +