Merged revisions 278023 via svnmerge from
[asterisk/asterisk.git] / tests / test_ast_format_str_reduce.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2010, Digium, Inc.
5  *
6  * Matthew Nicholson <mnichiolson@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18
19 /*! \file
20  *
21  * \brief Test ast_format_str_reduce
22  *
23  * \author Matthew Nicholson <mnichiolson@digium.com>
24  */
25
26 /*** MODULEINFO
27         <depend>TEST_FRAMEWORK</depend>
28         <depend>format_g723</depend>
29         <depend>format_g726</depend>
30         <depend>format_g729</depend>
31         <depend>format_gsm</depend>
32         <depend>format_ogg_vorbis</depend>
33         <depend>format_pcm</depend>
34         <depend>format_siren14</depend>
35         <depend>format_siren7</depend>
36         <depend>format_sln</depend>
37         <depend>format_wav</depend>
38         <depend>format_wav_gsm</depend>
39  ***/
40
41 #include "asterisk.h"
42
43 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
44
45 #include "asterisk/module.h"
46 #include "asterisk/file.h"
47 #include "asterisk/test.h"
48
49 /* this is an array containing a list of strings to test and the expected
50  * result for each test string.  The list should be terminated by an entry
51  * containing NULL for both elements {NULL, NULL}) */
52 static char *test_strings[][2] = {
53         {"wav",                       "wav"},
54         {"wav|ulaw",                  "wav|ulaw"},
55         {"pcm|wav",                   "pcm|wav"},
56         {"pcm|wav|ulaw",              "pcm|wav"},
57         {"wav|ulaw|pcm",              "wav|ulaw"},
58         {"wav|ulaw|pcm|alaw",         "wav|ulaw|alaw"},
59         {"pcm|ulaw|ul|mu|ulw",        "pcm"},
60         {"wav|ulaw|pcm|alaw|sln|raw", "wav|ulaw|alaw|sln"},
61         {"wav|gsm|wav49",             "wav|gsm|wav49"},
62         {"WAV|gsm|wav49",             "WAV|gsm"},
63         {"wav|invalid|gsm",           "wav|gsm"},
64         {"invalid|gsm",               "gsm"},
65         {"ulaw|gsm|invalid",          "ulaw|gsm"},
66         {"g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14|sln", "g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14"},
67         {NULL, NULL},
68 };
69
70 /* this is a NULL terminated array containing a list of strings that should
71  * cause ast_format_str_reduce() to fail */
72 static char *fail_strings[] = {
73         "this will fail",            /* format does not exist */
74         "this one|should|fail also", /* format does not exist */
75         NULL,
76 };
77
78 AST_TEST_DEFINE(ast_format_str_reduce_test_1)
79 {
80         int i;
81         char *c;
82
83         switch (cmd) {
84         case TEST_INIT:
85                 info->name = "ast_format_str_reduce_test_1";
86                 info->category = "/main/file/";
87                 info->summary = "reduce format strings";
88                 info->description = "Reduce some format strings and make sure the results match what we expect.";
89                 return AST_TEST_NOT_RUN;
90         case TEST_EXECUTE:
91                 break;
92         }
93
94         for (i = 0; test_strings[i][0]; i++) {
95                 c = ast_strdupa(test_strings[i][0]);
96                 if (!(c = ast_format_str_reduce(c))) {
97                         ast_test_status_update(test, "Error running ast_format_str_reduce() on string '%s'\n",
98                                         test_strings[i][0]);
99                         return AST_TEST_FAIL;
100                 }
101
102                 if (strcmp(test_strings[i][1], c)) {
103                         ast_test_status_update(test, "Format string '%s' reduced to '%s'.  Expected '%s'\n",
104                                         test_strings[i][0], c, test_strings[i][1]);
105                         return AST_TEST_FAIL;
106                 }
107         }
108
109         for (i = 0; fail_strings[i]; i++) {
110                 c = ast_strdupa(fail_strings[i]);
111                 if ((c = ast_format_str_reduce(c))) {
112                         ast_test_status_update(test, "ast_format_str_reduce() succeded on string '%s' "
113                                         "with result '%s', but we expected it to fail\n",
114                                         fail_strings[i], c);
115                         return AST_TEST_FAIL;
116                 }
117         }
118
119         return AST_TEST_PASS;
120 }
121
122 static int unload_module(void)
123 {
124         AST_TEST_UNREGISTER(ast_format_str_reduce_test_1);
125         return 0;
126 }
127
128 static int load_module(void)
129 {
130
131         AST_TEST_REGISTER(ast_format_str_reduce_test_1);
132
133         return AST_MODULE_LOAD_SUCCESS;
134 }
135
136 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_format_str_reduce() test module");