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