Files
asterisk/tests/test_ast_format_str_reduce.c

138 lines
3.9 KiB
C
Raw Normal View History

/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 2010, Digium, Inc.
*
* Matthew Nicholson <mnichiolson@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@digium.com>
*/
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
<depend>format_g723</depend>
<depend>format_g726</depend>
<depend>format_g729</depend>
<depend>format_gsm</depend>
<depend>format_ogg_vorbis</depend>
<depend>format_pcm</depend>
<depend>format_siren14</depend>
<depend>format_siren7</depend>
<depend>format_sln</depend>
<depend>format_wav</depend>
<depend>format_wav_gsm</depend>
<support_level>core</support_level>
***/
#include "asterisk.h"
git migration: Refactor the ASTERISK_FILE_VERSION macro Git does not support the ability to replace a token with a version string during check-in. While it does have support for replacing a token on clone, this is somewhat sub-optimal: the token is replaced with the object hash, which is not particularly easy for human consumption. What's more, in practice, the source file version was often not terribly useful. Generally, when triaging bugs, the overall version of Asterisk is far more useful than an individual SVN version of a file. As a result, this patch removes Asterisk's support for showing source file versions. Specifically, it does the following: * Rename ASTERISK_FILE_VERSION macro to ASTERISK_REGISTER_FILE, and remove passing the version in with the macro. Other facilities than 'core show file version' make use of the file names, such as setting a debug level only on a specific file. As such, the act of registering source files with the Asterisk core still has use. The macro rename now reflects the new macro purpose. * main/asterisk: - Refactor the file_version structure to reflect that it no longer tracks a version field. - Remove the "core show file version" CLI command. Without the file version, it is no longer useful. - Remove the ast_file_version_find function. The file version is no longer tracked. - Rename ast_register_file_version/ast_unregister_file_version to ast_register_file/ast_unregister_file, respectively. * main/manager: Remove value from the Version key of the ModuleCheck Action. The actual key itself has not been removed, as doing so would absolutely constitute a backwards incompatible change. However, since the file version is no longer tracked, there is no need to attempt to include it in the Version key. * UPGRADE: Add notes for: - Modification to the ModuleCheck AMI Action - Removal of the "core show file version" CLI command Change-Id: I6cf0ff280e1668bf4957dc21f32a5ff43444a40e
2015-04-11 21:38:22 -05:00
ASTERISK_REGISTER_FILE()
#include "asterisk/module.h"
#include "asterisk/file.h"
#include "asterisk/test.h"
/* this is an array containing 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"},
{"wav|invalid|gsm", "wav|gsm"},
{"invalid|gsm", "gsm"},
{"ulaw|gsm|invalid", "ulaw|gsm"},
{"g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14|sln", "g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14"},
{NULL, NULL},
};
/* this is a NULL terminated array containing 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))) {
Various updates to the unit test API. 1) It occurred to me that the difference in usage between the error ast_str and the ast_test_update_status() usage has turned out to be a bit ambiguous in practice. In a lot of cases, the same message was being sent to both. In other cases, it was only sent to one or the other. My opinion now is that in every case, I think it makes sense to do both; we should output it to the CLI as well as save it off for logging purposes. This change results in most of the changes in this diff, since it required changes to all existing unit tests. It also allowed for some simplifications of unit test API implementation code. 2) Update ast_test_status_update() to include the file, function, and line number for the code providing the update. 3) There are some formatting tweaks here and there. Hopefully they aren't too distracting for code review purposes. Reviewboard's diff viewer seems to do a pretty good job of pointing out when something is a whitespace change. 4) I moved the md5_test and sha1_test into the test_utils module. It seemed like a better approach since these tests are so tiny. 5) I changed the number of nodes used in heap_test_2 from 1 million to 100 thousand. The only reason for this was to reduce the time it took for this test to run. 6) Remove an unused function prototype that was at the bottom of utils.h. 7) Simplify test_insert() using the LIST_INSERT_SORTALPHA() macro. The one minor difference in behavior is that it no longer checks for a test registered with the same name. 8) Expand the code in test_alloc() to provide specific error messages for each failure case, to clearly inform developers if they forget to set the name, summary, description, etc. 9) Tweak the output of the "test show registered" CLI command. I swapped the name and category to have the category first. It seemed more natural since that is the sort key. 10) Don't output the status ast_str in the "test show results" CLI command. This is going to tend to be pretty verbose, so just leave that for the detailed test logs (test generate results). Review: https://reviewboard.asterisk.org/r/493/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@245864 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-02-09 23:32:14 +00:00
ast_test_status_update(test, "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)) {
Various updates to the unit test API. 1) It occurred to me that the difference in usage between the error ast_str and the ast_test_update_status() usage has turned out to be a bit ambiguous in practice. In a lot of cases, the same message was being sent to both. In other cases, it was only sent to one or the other. My opinion now is that in every case, I think it makes sense to do both; we should output it to the CLI as well as save it off for logging purposes. This change results in most of the changes in this diff, since it required changes to all existing unit tests. It also allowed for some simplifications of unit test API implementation code. 2) Update ast_test_status_update() to include the file, function, and line number for the code providing the update. 3) There are some formatting tweaks here and there. Hopefully they aren't too distracting for code review purposes. Reviewboard's diff viewer seems to do a pretty good job of pointing out when something is a whitespace change. 4) I moved the md5_test and sha1_test into the test_utils module. It seemed like a better approach since these tests are so tiny. 5) I changed the number of nodes used in heap_test_2 from 1 million to 100 thousand. The only reason for this was to reduce the time it took for this test to run. 6) Remove an unused function prototype that was at the bottom of utils.h. 7) Simplify test_insert() using the LIST_INSERT_SORTALPHA() macro. The one minor difference in behavior is that it no longer checks for a test registered with the same name. 8) Expand the code in test_alloc() to provide specific error messages for each failure case, to clearly inform developers if they forget to set the name, summary, description, etc. 9) Tweak the output of the "test show registered" CLI command. I swapped the name and category to have the category first. It seemed more natural since that is the sort key. 10) Don't output the status ast_str in the "test show results" CLI command. This is going to tend to be pretty verbose, so just leave that for the detailed test logs (test generate results). Review: https://reviewboard.asterisk.org/r/493/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@245864 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-02-09 23:32:14 +00:00
ast_test_status_update(test, "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))) {
Various updates to the unit test API. 1) It occurred to me that the difference in usage between the error ast_str and the ast_test_update_status() usage has turned out to be a bit ambiguous in practice. In a lot of cases, the same message was being sent to both. In other cases, it was only sent to one or the other. My opinion now is that in every case, I think it makes sense to do both; we should output it to the CLI as well as save it off for logging purposes. This change results in most of the changes in this diff, since it required changes to all existing unit tests. It also allowed for some simplifications of unit test API implementation code. 2) Update ast_test_status_update() to include the file, function, and line number for the code providing the update. 3) There are some formatting tweaks here and there. Hopefully they aren't too distracting for code review purposes. Reviewboard's diff viewer seems to do a pretty good job of pointing out when something is a whitespace change. 4) I moved the md5_test and sha1_test into the test_utils module. It seemed like a better approach since these tests are so tiny. 5) I changed the number of nodes used in heap_test_2 from 1 million to 100 thousand. The only reason for this was to reduce the time it took for this test to run. 6) Remove an unused function prototype that was at the bottom of utils.h. 7) Simplify test_insert() using the LIST_INSERT_SORTALPHA() macro. The one minor difference in behavior is that it no longer checks for a test registered with the same name. 8) Expand the code in test_alloc() to provide specific error messages for each failure case, to clearly inform developers if they forget to set the name, summary, description, etc. 9) Tweak the output of the "test show registered" CLI command. I swapped the name and category to have the category first. It seemed more natural since that is the sort key. 10) Don't output the status ast_str in the "test show results" CLI command. This is going to tend to be pretty verbose, so just leave that for the detailed test logs (test generate results). Review: https://reviewboard.asterisk.org/r/493/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@245864 65c4cc65-6c06-0410-ace0-fbb531ad65f3
2010-02-09 23:32:14 +00:00
ast_test_status_update(test, "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");