40 .description =
"Unit test codec",
41 .type = AST_MEDIA_TYPE_AUDIO,
49 .
name =
"unit_test_double",
50 .description =
"Unit test codec",
51 .type = AST_MEDIA_TYPE_AUDIO,
59 .
name =
"unit_test_unknown",
60 .description =
"Unit test codec",
61 .type = AST_MEDIA_TYPE_UNKNOWN,
68 static struct ast_codec audio_without_rate = {
69 .
name =
"unit_test_audio_without_rate",
70 .description =
"Unit test codec",
71 .type = AST_MEDIA_TYPE_AUDIO,
78 .
name =
"unit_test_audio_get",
79 .description =
"Unit test codec",
80 .type = AST_MEDIA_TYPE_AUDIO,
87 static struct ast_codec audio_get_unknown = {
88 .
name =
"unit_test_audio_get_unknown",
89 .description =
"Unit test codec",
90 .type = AST_MEDIA_TYPE_AUDIO,
98 .
name =
"unit_test_audio_get_id",
99 .description =
"Unit test codec",
100 .type = AST_MEDIA_TYPE_AUDIO,
111 info->name =
"codec_register";
112 info->category =
"/main/core_codec/";
113 info->summary =
"codec registration unit test";
115 "Test registration of a core codec that is known to be unknown";
116 return AST_TEST_NOT_RUN;
122 ast_test_status_update(
test,
"Unsuccessfully registered a codec that is known to be unknown\n");
123 return AST_TEST_FAIL;
126 return AST_TEST_PASS;
133 info->name =
"codec_register_twice";
134 info->category =
"/main/core_codec/";
135 info->summary =
"codec registration unit test";
137 "Test double registration of a core codec to confirm it fails";
138 return AST_TEST_NOT_RUN;
144 ast_test_status_update(
test,
"Unsuccessfully registered a codec that is known to be unknown\n");
145 return AST_TEST_FAIL;
149 ast_test_status_update(
test,
"Successfully registered a codec twice\n");
150 return AST_TEST_FAIL;
153 return AST_TEST_PASS;
160 info->name =
"codec_register_unknown";
161 info->category =
"/main/core_codec/";
162 info->summary =
"codec registration unit test";
164 "Test that registration of an unknown codec type fails";
165 return AST_TEST_NOT_RUN;
171 ast_test_status_update(
test,
"Successfully registered a codec with an unknown media type\n");
172 return AST_TEST_FAIL;
175 return AST_TEST_PASS;
182 info->name =
"codec_register_audio_no_sample_rate";
183 info->category =
"/main/core_codec/";
184 info->summary =
"codec registration unit test";
186 "Test that registration of an audio codec without sample rate fails";
187 return AST_TEST_NOT_RUN;
193 ast_test_status_update(
test,
"Successfully registered an audio codec without a sample rate\n");
194 return AST_TEST_FAIL;
197 return AST_TEST_PASS;
206 info->name =
"codec_get";
207 info->category =
"/main/core_codec/";
208 info->summary =
"codec get unit test";
210 "Test that getting of a known codec succeeds";
211 return AST_TEST_NOT_RUN;
217 ast_test_status_update(
test,
"Unsucessfully registered a codec for getting\n");
218 return AST_TEST_FAIL;
221 codec =
ast_codec_get(
"unit_test_audio_get", AST_MEDIA_TYPE_AUDIO, 8000);
223 ast_test_status_update(
test,
"Unsuccessfully retrieved a codec we just registered\n");
224 return AST_TEST_FAIL;
225 }
else if (strcmp(codec->name, audio_get.
name)) {
226 ast_test_status_update(
test,
"Name of retrieved codec does not match registered codec\n");
227 return AST_TEST_FAIL;
228 }
else if (codec->type != audio_get.
type) {
229 ast_test_status_update(
test,
"Type of retrieved codec does not match registered codec\n");
230 return AST_TEST_FAIL;
231 }
else if (codec->sample_rate != audio_get.
sample_rate) {
232 ast_test_status_update(
test,
"Sample rate of retrieved codec does not match registered codec\n");
233 return AST_TEST_FAIL;
236 return AST_TEST_PASS;
245 info->name =
"codec_get_unregistered";
246 info->category =
"/main/core_codec/";
247 info->summary =
"codec get unit test";
249 "Test that getting of a codec that is not registered fails";
250 return AST_TEST_NOT_RUN;
257 ast_test_status_update(
test,
"Successfully got a codec named '%s' when getting a codec named 'goats'\n",
259 return AST_TEST_FAIL;
262 return AST_TEST_PASS;
271 info->name =
"codec_get_unknown";
272 info->category =
"/main/core_codec/";
273 info->summary =
"codec get unit test";
275 "Test that getting of a known codec using name and unknown type succeeds";
276 return AST_TEST_NOT_RUN;
282 ast_test_status_update(
test,
"Unsucessfully registered a codec for getting\n");
283 return AST_TEST_FAIL;
286 codec =
ast_codec_get(
"unit_test_audio_get_unknown", AST_MEDIA_TYPE_UNKNOWN, 8000);
288 ast_test_status_update(
test,
"Unsuccessfully retrieved a codec we just registered\n");
289 return AST_TEST_FAIL;
290 }
else if (strcmp(codec->name, audio_get_unknown.
name)) {
291 ast_test_status_update(
test,
"Name of retrieved codec does not match registered codec\n");
292 return AST_TEST_FAIL;
293 }
else if (codec->type != audio_get_unknown.
type) {
294 ast_test_status_update(
test,
"Type of retrieved codec does not match registered codec\n");
295 return AST_TEST_FAIL;
296 }
else if (codec->sample_rate != audio_get_unknown.
sample_rate) {
297 ast_test_status_update(
test,
"Sample rate of retrieved codec does not match registered codec\n");
298 return AST_TEST_FAIL;
301 return AST_TEST_PASS;
311 info->name =
"codec_get_unknown";
312 info->category =
"/main/core_codec/";
313 info->summary =
"codec get unit test";
315 "Test that getting of a known codec using name and unknown type succeeds";
316 return AST_TEST_NOT_RUN;
322 ast_test_status_update(
test,
"Unsucessfully registered a codec for getting\n");
323 return AST_TEST_FAIL;
326 named =
ast_codec_get(
"unit_test_audio_get_id", AST_MEDIA_TYPE_AUDIO, 8000);
328 ast_test_status_update(
test,
"Unsuccessfully retrieved a codec we just registered\n");
329 return AST_TEST_FAIL;
334 ast_test_status_update(
test,
"Unsuccessfully retrieved a codec using id of a named codec we just got\n");
335 return AST_TEST_FAIL;
338 return AST_TEST_PASS;
341 static int unload_module(
void)
343 AST_TEST_UNREGISTER(codec_register);
344 AST_TEST_UNREGISTER(codec_register_twice);
345 AST_TEST_UNREGISTER(codec_register_unknown);
346 AST_TEST_UNREGISTER(codec_register_audio_no_sample_rate);
347 AST_TEST_UNREGISTER(codec_get);
348 AST_TEST_UNREGISTER(codec_get_unregistered);
349 AST_TEST_UNREGISTER(codec_get_unknown);
350 AST_TEST_UNREGISTER(codec_get_id);
354 static int load_module(
void)
356 AST_TEST_REGISTER(codec_register);
357 AST_TEST_REGISTER(codec_register_twice);
358 AST_TEST_REGISTER(codec_register_unknown);
359 AST_TEST_REGISTER(codec_register_audio_no_sample_rate);
360 AST_TEST_REGISTER(codec_get);
361 AST_TEST_REGISTER(codec_get_unregistered);
362 AST_TEST_REGISTER(codec_get_unknown);
363 AST_TEST_REGISTER(codec_get_id);
const char * name
Name for this codec.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_codec * ast_codec_get_by_id(int id)
Retrieve a codec given the unique identifier.
struct ast_codec * ast_codec_get(const char *name, enum ast_media_type type, unsigned int sample_rate)
Retrieve a codec given a name, type, and sample rate.
#define ast_codec_register(codec)
This function is used to register a codec with the Asterisk core. Registering allows it to be passed ...
unsigned int sample_rate
Sample rate (number of samples carried in a second)
#define AST_TEST_DEFINE(hdr)
enum ast_media_type type
Type of media this codec contains.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Represents a media codec within Asterisk.