[asterisk-commits] file: branch group/media_formats r406914 - /team/group/media_formats/tests/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 29 11:02:37 CST 2014
Author: file
Date: Wed Jan 29 11:02:32 2014
New Revision: 406914
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=406914
Log:
Add the beginnings of the format API unit tests.
Added:
team/group/media_formats/tests/test_core_format.c (with props)
Added: team/group/media_formats/tests/test_core_format.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/tests/test_core_format.c?view=auto&rev=406914
==============================================================================
--- team/group/media_formats/tests/test_core_format.c (added)
+++ team/group/media_formats/tests/test_core_format.c Wed Jan 29 11:02:32 2014
@@ -1,0 +1,340 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Joshua Colp <jcolp at 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 Format API Unit Tests
+ *
+ * \author Joshua Colp <jcolp at 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"
+#include "asterisk/format_ng.h"
+
+AST_TEST_DEFINE(format_create)
+{
+ RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "format_create";
+ info->category = "/main/core_format/";
+ info->summary = "format creation unit test";
+ info->description =
+ "Test creation of a format";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!codec) {
+ ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ format = ast_format_ng_create(codec);
+ if (!format) {
+ ast_test_status_update(test, "Could not create format using built-in codec\n");
+ return AST_TEST_FAIL;
+ } else if (format->codec != codec) {
+ ast_test_status_update(test, "Created format does not contain provided codec\n");
+ return AST_TEST_FAIL;
+ } else if (format->interface) {
+ ast_test_status_update(test, "Created format contains interface when it should not\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_cmp_same_codec)
+{
+ RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, first, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "format_cmp_same_codec";
+ info->category = "/main/core_format/";
+ info->summary = "format comparison unit test";
+ info->description =
+ "Test comparison of two different formats with same codec";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!codec) {
+ ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ first = ast_format_ng_create(codec);
+ if (!first) {
+ ast_test_status_update(test, "Could not create first format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ second = ast_format_ng_create(codec);
+ if (!second) {
+ ast_test_status_update(test, "Could not create second format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (ast_format_ng_cmp(first, second) != AST_FORMAT_CMP_EQUAL) {
+ ast_test_status_update(test, "Two formats that are the same compared as not being equal\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_cmp_different_codec)
+{
+ RAII_VAR(struct ast_codec *, first_codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_codec *, second_codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, first, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "format_cmp_different_codec";
+ info->category = "/main/core_format/";
+ info->summary = "format comparison unit test";
+ info->description =
+ "Test comparison of two different formats with different codec";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ first_codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!first_codec) {
+ ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ first = ast_format_ng_create(first_codec);
+ if (!first) {
+ ast_test_status_update(test, "Could not create first format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ second_codec = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!second_codec) {
+ ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ second = ast_format_ng_create(second_codec);
+ if (!second) {
+ ast_test_status_update(test, "Could not create second format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (ast_format_ng_cmp(first, second) != AST_FORMAT_CMP_NOT_EQUAL) {
+ ast_test_status_update(test, "Two formats that have different codecs did not compare as being not equal\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_joint_same_codec)
+{
+ RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, first, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, joint, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "format_joint_same_codec";
+ info->category = "/main/core_format/";
+ info->summary = "joint format unit test";
+ info->description =
+ "Test joint format creation using two different formats with same codec";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!codec) {
+ ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ first = ast_format_ng_create(codec);
+ if (!first) {
+ ast_test_status_update(test, "Could not create first format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ second = ast_format_ng_create(codec);
+ if (!second) {
+ ast_test_status_update(test, "Could not create second format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ joint = ast_format_ng_joint(first, second);
+ if (!joint) {
+ ast_test_status_update(test, "Failed to create a joint format using two formats of same codec\n");
+ return AST_TEST_FAIL;
+ } else if (joint->codec != codec) {
+ ast_test_status_update(test, "Returned joint format does not contain expected codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_joint_different_codec)
+{
+ RAII_VAR(struct ast_codec *, first_codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_codec *, second_codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, first, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, second, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, joint, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "format_joint_different_codec";
+ info->category = "/main/core_format/";
+ info->summary = "joint format unit test";
+ info->description =
+ "Test that there is no joint format between two different formats with different codec";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ first_codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!first_codec) {
+ ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ first = ast_format_ng_create(first_codec);
+ if (!first) {
+ ast_test_status_update(test, "Could not create first format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ second_codec = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!second_codec) {
+ ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ second = ast_format_ng_create(second_codec);
+ if (!second) {
+ ast_test_status_update(test, "Could not create second format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ joint = ast_format_ng_joint(first, second);
+ if (joint) {
+ ast_test_status_update(test, "Got a joint format between two formats with different codecs\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_copy)
+{
+ RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_format *, copy, NULL, ao2_cleanup);
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "format_copy";
+ info->category = "/main/core_format/";
+ info->summary = "format copying unit test";
+ info->description =
+ "Test copying of a format";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ codec = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+ if (!codec) {
+ ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ format = ast_format_ng_create(codec);
+ if (!format) {
+ ast_test_status_update(test, "Could not create format using built-in codec\n");
+ return AST_TEST_FAIL;
+ }
+
+ copy = ast_format_ng_copy(format);
+ if (!copy) {
+ ast_test_status_update(test, "Copying of a just created format failed\n");
+ return AST_TEST_FAIL;
+ } else if (copy != format) {
+ ast_test_status_update(test, "Copying of a format returned a new format instead of the same one\n");
+ return AST_TEST_FAIL;
+ }
+
+ return AST_TEST_PASS;
+}
+
+static int unload_module(void)
+{
+ AST_TEST_UNREGISTER(format_create);
+ AST_TEST_UNREGISTER(format_cmp_same_codec);
+ AST_TEST_UNREGISTER(format_cmp_different_codec);
+ AST_TEST_UNREGISTER(format_joint_same_codec);
+ AST_TEST_UNREGISTER(format_joint_different_codec);
+ AST_TEST_UNREGISTER(format_copy);
+ return 0;
+}
+
+static int load_module(void)
+{
+ AST_TEST_REGISTER(format_create);
+ AST_TEST_REGISTER(format_cmp_same_codec);
+ AST_TEST_REGISTER(format_cmp_different_codec);
+ AST_TEST_REGISTER(format_joint_same_codec);
+ AST_TEST_REGISTER(format_joint_different_codec);
+ AST_TEST_REGISTER(format_copy);
+ return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Core format API test module");
Propchange: team/group/media_formats/tests/test_core_format.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/group/media_formats/tests/test_core_format.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/group/media_formats/tests/test_core_format.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the asterisk-commits
mailing list