Merge "test_http_media_cache: Fix failing test."
[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         <support_level>core</support_level>
40  ***/
41
42 #include "asterisk.h"
43
44 ASTERISK_REGISTER_FILE()
45
46 #include "asterisk/module.h"
47 #include "asterisk/file.h"
48 #include "asterisk/test.h"
49
50 /* this is an array containing a list of strings to test and the expected
51  * result for each test string.  The list should be terminated by an entry
52  * containing NULL for both elements {NULL, NULL}) */
53 static char *test_strings[][2] = {
54         {"wav",                       "wav"},
55         {"wav|ulaw",                  "wav|ulaw"},
56         {"pcm|wav",                   "pcm|wav"},
57         {"pcm|wav|ulaw",              "pcm|wav"},
58         {"wav|ulaw|pcm",              "wav|ulaw"},
59         {"wav|ulaw|pcm|alaw",         "wav|ulaw|alaw"},
60         {"pcm|ulaw|ul|mu|ulw",        "pcm"},
61         {"wav|ulaw|pcm|alaw|sln|raw", "wav|ulaw|alaw|sln"},
62         {"wav|gsm|wav49",             "wav|gsm|wav49"},
63         {"WAV|gsm|wav49",             "WAV|gsm"},
64         {"wav|invalid|gsm",           "wav|gsm"},
65         {"invalid|gsm",               "gsm"},
66         {"ulaw|gsm|invalid",          "ulaw|gsm"},
67         {"g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14|sln", "g723|g726-40|g729|gsm|ilbc|ogg|wav|WAV|siren7|siren14"},
68         {NULL, NULL},
69 };
70
71 /* this is a NULL terminated array containing a list of strings that should
72  * cause ast_format_str_reduce() to fail */
73 static char *fail_strings[] = {
74         "this will fail",            /* format does not exist */
75         "this one|should|fail also", /* format does not exist */
76         NULL,
77 };
78
79 AST_TEST_DEFINE(ast_format_str_reduce_test_1)
80 {
81         int i;
82         char *c;
83
84         switch (cmd) {
85         case TEST_INIT:
86                 info->name = "ast_format_str_reduce_test_1";
87                 info->category = "/main/file/";
88                 info->summary = "reduce format strings";
89                 info->description = "Reduce some format strings and make sure the results match what we expect.";
90                 return AST_TEST_NOT_RUN;
91         case TEST_EXECUTE:
92                 break;
93         }
94
95         for (i = 0; test_strings[i][0]; i++) {
96                 c = ast_strdupa(test_strings[i][0]);
97                 if (!(c = ast_format_str_reduce(c))) {
98                         ast_test_status_update(test, "Error running ast_format_str_reduce() on string '%s'\n",
99                                         test_strings[i][0]);
100                         return AST_TEST_FAIL;
101                 }
102
103                 if (strcmp(test_strings[i][1], c)) {
104                         ast_test_status_update(test, "Format string '%s' reduced to '%s'.  Expected '%s'\n",
105                                         test_strings[i][0], c, test_strings[i][1]);
106                         return AST_TEST_FAIL;
107                 }
108         }
109
110         for (i = 0; fail_strings[i]; i++) {
111                 c = ast_strdupa(fail_strings[i]);
112                 if ((c = ast_format_str_reduce(c))) {
113                         ast_test_status_update(test, "ast_format_str_reduce() succeded on string '%s' "
114                                         "with result '%s', but we expected it to fail\n",
115                                         fail_strings[i], c);
116                         return AST_TEST_FAIL;
117                 }
118         }
119
120         return AST_TEST_PASS;
121 }
122
123 static int unload_module(void)
124 {
125         AST_TEST_UNREGISTER(ast_format_str_reduce_test_1);
126         return 0;
127 }
128
129 static int load_module(void)
130 {
131
132         AST_TEST_REGISTER(ast_format_str_reduce_test_1);
133
134         return AST_MODULE_LOAD_SUCCESS;
135 }
136
137 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_format_str_reduce() test module");