123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- /*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2014, Digium, Inc.
- *
- * Joshua Colp <jcolp@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 Core Codec API Unit Tests
- *
- * \author Joshua Colp <jcolp@digium.com>
- *
- */
- /*** MODULEINFO
- <depend>TEST_FRAMEWORK</depend>
- <support_level>core</support_level>
- ***/
- #include "asterisk.h"
- ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
- #include "asterisk/test.h"
- #include "asterisk/module.h"
- #include "asterisk/codec.h"
- static struct ast_codec known_unknown = {
- .name = "unit_test",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_AUDIO,
- .sample_rate = 8000,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- static struct ast_codec doubly = {
- .name = "unit_test_double",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_AUDIO,
- .sample_rate = 8000,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- static struct ast_codec unknown = {
- .name = "unit_test_unknown",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_UNKNOWN,
- .sample_rate = 8000,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- static struct ast_codec audio_without_rate = {
- .name = "unit_test_audio_without_rate",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_AUDIO,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- static struct ast_codec audio_get = {
- .name = "unit_test_audio_get",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_AUDIO,
- .sample_rate = 8000,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- static struct ast_codec audio_get_unknown = {
- .name = "unit_test_audio_get_unknown",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_AUDIO,
- .sample_rate = 8000,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- static struct ast_codec audio_get_id = {
- .name = "unit_test_audio_get_id",
- .description = "Unit test codec",
- .type = AST_MEDIA_TYPE_AUDIO,
- .sample_rate = 8000,
- .minimum_ms = 10,
- .maximum_ms = 150,
- .default_ms = 20,
- };
- AST_TEST_DEFINE(codec_register)
- {
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_register";
- info->category = "/main/core_codec/";
- info->summary = "codec registration unit test";
- info->description =
- "Test registration of a core codec that is known to be unknown";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (ast_codec_register(&known_unknown)) {
- ast_test_status_update(test, "Unsuccessfully registered a codec that is known to be unknown\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_register_twice)
- {
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_register_twice";
- info->category = "/main/core_codec/";
- info->summary = "codec registration unit test";
- info->description =
- "Test double registration of a core codec to confirm it fails";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (ast_codec_register(&doubly)) {
- ast_test_status_update(test, "Unsuccessfully registered a codec that is known to be unknown\n");
- return AST_TEST_FAIL;
- }
- if (!ast_codec_register(&doubly)) {
- ast_test_status_update(test, "Successfully registered a codec twice\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_register_unknown)
- {
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_register_unknown";
- info->category = "/main/core_codec/";
- info->summary = "codec registration unit test";
- info->description =
- "Test that registration of an unknown codec type fails";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (!ast_codec_register(&unknown)) {
- ast_test_status_update(test, "Successfully registered a codec with an unknown media type\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_register_audio_no_sample_rate)
- {
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_register_audio_no_sample_rate";
- info->category = "/main/core_codec/";
- info->summary = "codec registration unit test";
- info->description =
- "Test that registration of an audio codec without sample rate fails";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (!ast_codec_register(&audio_without_rate)) {
- ast_test_status_update(test, "Successfully registered an audio codec without a sample rate\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_get)
- {
- RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_get";
- info->category = "/main/core_codec/";
- info->summary = "codec get unit test";
- info->description =
- "Test that getting of a known codec succeeds";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (ast_codec_register(&audio_get)) {
- ast_test_status_update(test, "Unsucessfully registered a codec for getting\n");
- return AST_TEST_FAIL;
- }
- codec = ast_codec_get("unit_test_audio_get", AST_MEDIA_TYPE_AUDIO, 8000);
- if (!codec) {
- ast_test_status_update(test, "Unsuccessfully retrieved a codec we just registered\n");
- return AST_TEST_FAIL;
- } else if (strcmp(codec->name, audio_get.name)) {
- ast_test_status_update(test, "Name of retrieved codec does not match registered codec\n");
- return AST_TEST_FAIL;
- } else if (codec->type != audio_get.type) {
- ast_test_status_update(test, "Type of retrieved codec does not match registered codec\n");
- return AST_TEST_FAIL;
- } else if (codec->sample_rate != audio_get.sample_rate) {
- ast_test_status_update(test, "Sample rate of retrieved codec does not match registered codec\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_get_unregistered)
- {
- RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_get_unregistered";
- info->category = "/main/core_codec/";
- info->summary = "codec get unit test";
- info->description =
- "Test that getting of a codec that is not registered fails";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- codec = ast_codec_get("goats", AST_MEDIA_TYPE_AUDIO, 8000);
- if (codec) {
- ast_test_status_update(test, "Successfully got a codec named '%s' when getting a codec named 'goats'\n",
- codec->name);
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_get_unknown)
- {
- RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_get_unknown";
- info->category = "/main/core_codec/";
- info->summary = "codec get unit test";
- info->description =
- "Test that getting of a known codec using name and unknown type succeeds";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (ast_codec_register(&audio_get_unknown)) {
- ast_test_status_update(test, "Unsucessfully registered a codec for getting\n");
- return AST_TEST_FAIL;
- }
- codec = ast_codec_get("unit_test_audio_get_unknown", AST_MEDIA_TYPE_UNKNOWN, 8000);
- if (!codec) {
- ast_test_status_update(test, "Unsuccessfully retrieved a codec we just registered\n");
- return AST_TEST_FAIL;
- } else if (strcmp(codec->name, audio_get_unknown.name)) {
- ast_test_status_update(test, "Name of retrieved codec does not match registered codec\n");
- return AST_TEST_FAIL;
- } else if (codec->type != audio_get_unknown.type) {
- ast_test_status_update(test, "Type of retrieved codec does not match registered codec\n");
- return AST_TEST_FAIL;
- } else if (codec->sample_rate != audio_get_unknown.sample_rate) {
- ast_test_status_update(test, "Sample rate of retrieved codec does not match registered codec\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- AST_TEST_DEFINE(codec_get_id)
- {
- RAII_VAR(struct ast_codec *, named, NULL, ao2_cleanup);
- RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
- switch (cmd) {
- case TEST_INIT:
- info->name = "codec_get_unknown";
- info->category = "/main/core_codec/";
- info->summary = "codec get unit test";
- info->description =
- "Test that getting of a known codec using name and unknown type succeeds";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- if (ast_codec_register(&audio_get_id)) {
- ast_test_status_update(test, "Unsucessfully registered a codec for getting\n");
- return AST_TEST_FAIL;
- }
- named = ast_codec_get("unit_test_audio_get_id", AST_MEDIA_TYPE_AUDIO, 8000);
- if (!named) {
- ast_test_status_update(test, "Unsuccessfully retrieved a codec we just registered\n");
- return AST_TEST_FAIL;
- }
- codec = ast_codec_get_by_id(named->id);
- if (!codec) {
- ast_test_status_update(test, "Unsuccessfully retrieved a codec using id of a named codec we just got\n");
- return AST_TEST_FAIL;
- }
- return AST_TEST_PASS;
- }
- static int unload_module(void)
- {
- AST_TEST_UNREGISTER(codec_register);
- AST_TEST_UNREGISTER(codec_register_twice);
- AST_TEST_UNREGISTER(codec_register_unknown);
- AST_TEST_UNREGISTER(codec_register_audio_no_sample_rate);
- AST_TEST_UNREGISTER(codec_get);
- AST_TEST_UNREGISTER(codec_get_unregistered);
- AST_TEST_UNREGISTER(codec_get_unknown);
- AST_TEST_UNREGISTER(codec_get_id);
- return 0;
- }
- static int load_module(void)
- {
- AST_TEST_REGISTER(codec_register);
- AST_TEST_REGISTER(codec_register_twice);
- AST_TEST_REGISTER(codec_register_unknown);
- AST_TEST_REGISTER(codec_register_audio_no_sample_rate);
- AST_TEST_REGISTER(codec_get);
- AST_TEST_REGISTER(codec_get_unregistered);
- AST_TEST_REGISTER(codec_get_unknown);
- AST_TEST_REGISTER(codec_get_id);
- return AST_MODULE_LOAD_SUCCESS;
- }
- AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Core codec API test module");
|