[svn-commits] file: branch group/media_formats r407183 - /team/group/media_formats/tests/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Feb 3 08:45:48 CST 2014


Author: file
Date: Mon Feb  3 08:45:43 2014
New Revision: 407183

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407183
Log:
Add the beginnings of the format capabilities unit tests.

Right now just focusing on manipulation.

Added:
    team/group/media_formats/tests/test_format_cap.c   (with props)

Added: team/group/media_formats/tests/test_format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/group/media_formats/tests/test_format_cap.c?view=auto&rev=407183
==============================================================================
--- team/group/media_formats/tests/test_format_cap.c (added)
+++ team/group/media_formats/tests/test_format_cap.c Mon Feb  3 08:45:43 2014
@@ -1,0 +1,346 @@
+/*
+ * 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 Format Capabilities 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"
+#include "asterisk/format_cap_ng.h"
+
+AST_TEST_DEFINE(format_cap_alloc)
+{
+	struct ast_format_cap *caps;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "format_cap_alloc";
+		info->category = "/main/format_cap/";
+		info->summary = "format capabilities allocation unit test";
+		info->description =
+			"Test that allocation of a format capabilities structure succeeds";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+	ao2_ref(caps, -1);
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_cap_add_single)
+{
+	RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_codec *, codec, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, format, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, retrieved, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "format_cap_add_single";
+		info->category = "/main/format_cap/";
+		info->summary = "format capabilities adding unit test";
+		info->description =
+			"Test that adding a single format to a format capabilities structure succeeds";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+
+	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;
+	}
+
+	if (ast_format_cap_ng_add(caps, format, 42)) {
+		ast_test_status_update(test, "Could not add newly created format to capabilities structure\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_count(caps) != 1) {
+		ast_test_status_update(test, "Number of formats in capabilities structure should be 1 but is %zd\n",
+			ast_format_cap_ng_count(caps));
+		return AST_TEST_FAIL;
+	}
+
+	retrieved = ast_format_cap_ng_get_format(caps, 0);
+	if (!retrieved) {
+		ast_test_status_update(test, "Attempted to get single format from capabilities structure but got nothing\n");
+		return AST_TEST_FAIL;
+	} else if (retrieved != format) {
+		ast_test_status_update(test, "Retrieved format is not the same as the one we added\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_get_framing(caps, retrieved) != 42) {
+		ast_test_status_update(test, "Framing for format in capabilities structure does not match what we provided\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_cap_add_multiple)
+{
+	RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, retrieved, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "format_cap_add_multiple";
+		info->category = "/main/format_cap/";
+		info->summary = "format capabilities adding unit test";
+		info->description =
+			"Test that adding multiple formats to a format capabilities structure succeeds";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+
+	ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+	if (!ulaw) {
+		ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	ulaw_format = ast_format_ng_create(ulaw);
+	if (!ulaw_format) {
+		ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
+	if (!alaw) {
+		ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	alaw_format = ast_format_ng_create(alaw);
+	if (!alaw_format) {
+		ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (ast_format_cap_ng_add(caps, ulaw_format, 42)) {
+		ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_add(caps, alaw_format, 84)) {
+		ast_test_status_update(test, "Could not add newly created alaw format to capabilities structure\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_count(caps) != 2) {
+		ast_test_status_update(test, "Number of formats in capabilities structure should be 2 but is %zd\n",
+			ast_format_cap_ng_count(caps));
+		return AST_TEST_FAIL;
+	}
+
+	retrieved = ast_format_cap_ng_get_format(caps, 0);
+	if (!retrieved) {
+		ast_test_status_update(test, "Attempted to get first format from capabilities structure but got nothing\n");
+		return AST_TEST_FAIL;
+	} else if (retrieved != ulaw_format) {
+		ast_test_status_update(test, "First retrieved format is not the ulaw one we added\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_get_framing(caps, retrieved) != 42) {
+		ast_test_status_update(test, "Framing for ulaw format in capabilities structure does not match what we provided\n");
+	}
+	ao2_ref(retrieved, -1);
+
+	retrieved = ast_format_cap_ng_get_format(caps, 1);
+	if (!retrieved) {
+		ast_test_status_update(test, "Attempted to get second format from capabilities structure but got nothing\n");
+		return AST_TEST_FAIL;
+	} else if (retrieved != alaw_format) {
+		ast_test_status_update(test, "First retrieved format is not the alaw one we added\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_get_framing(caps, retrieved) != 84) {
+		ast_test_status_update(test, "Framing for alaw format in capabilities structure does not match what we provided\n");
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_cap_add_all_unknown)
+{
+	RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "format_cap_add_all_unknown";
+		info->category = "/main/format_cap/";
+		info->summary = "format capabilities adding unit test";
+		info->description =
+			"Test that adding of all formats to a format capabilities structure succeeds";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_add_all_by_type(caps, AST_MEDIA_TYPE_UNKNOWN)) {
+		ast_test_status_update(test, "Failed to add all media formats of all types to capabilities structure\n");
+		return AST_TEST_FAIL;
+	} else if (!ast_format_cap_ng_has_type(caps, AST_MEDIA_TYPE_AUDIO)) {
+		ast_test_status_update(test, "Added all media formats but no audio formats exist when they should\n");
+		return AST_TEST_FAIL;
+	} else if (!ast_format_cap_ng_has_type(caps, AST_MEDIA_TYPE_VIDEO)) {
+		ast_test_status_update(test, "Added all media formats but no video formats exist when they should\n");
+		return AST_TEST_FAIL;
+	} else if ((ast_format_cap_ng_count(caps) + 1) != ast_codec_get_max()) {
+		ast_test_status_update(test, "The number of formats in the capabilities structure does not match known number\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+AST_TEST_DEFINE(format_cap_set_framing)
+{
+	RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_codec *, ulaw, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, ulaw_format, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_codec *, alaw, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format *, alaw_format, NULL, ao2_cleanup);
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "format_cap_set_framing";
+		info->category = "/main/format_cap/";
+		info->summary = "format capabilities framing unit test";
+		info->description =
+			"Test that global framing on a format capabilities structure is used when it should be";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_format_cap_ng_set_framing(caps, 160);
+
+	ulaw = ast_codec_get("ulaw", AST_MEDIA_TYPE_AUDIO, 8000);
+	if (!ulaw) {
+		ast_test_status_update(test, "Could not retrieve built-in ulaw codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	ulaw_format = ast_format_ng_create(ulaw);
+	if (!ulaw_format) {
+		ast_test_status_update(test, "Could not create ulaw format using built-in codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	alaw = ast_codec_get("alaw", AST_MEDIA_TYPE_AUDIO, 8000);
+	if (!alaw) {
+		ast_test_status_update(test, "Could not retrieve built-in alaw codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	alaw_format = ast_format_ng_create(alaw);
+	if (!alaw_format) {
+		ast_test_status_update(test, "Could not create alaw format using built-in codec\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (ast_format_cap_ng_add(caps, ulaw_format, 42)) {
+		ast_test_status_update(test, "Could not add newly created ulaw format to capabilities structure\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_add(caps, alaw_format, 0)) {
+		ast_test_status_update(test, "Could not add newly created alaw format to capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (ast_format_cap_ng_get_framing(caps, ulaw_format) != 42) {
+		ast_test_status_update(test, "Added ulaw format to capabilities structure with explicit framing but did not get it back\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_get_framing(caps, alaw_format) != 160) {
+		ast_test_status_update(test, "Added alaw format to capabilities structure with no explicit framing but did not get global back\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(format_cap_alloc);
+	AST_TEST_UNREGISTER(format_cap_add_single);
+	AST_TEST_UNREGISTER(format_cap_add_multiple);
+	AST_TEST_UNREGISTER(format_cap_add_all_unknown);
+	AST_TEST_UNREGISTER(format_cap_set_framing);
+	return 0;
+}
+
+static int load_module(void)
+{
+	AST_TEST_REGISTER(format_cap_alloc);
+	AST_TEST_REGISTER(format_cap_add_single);
+	AST_TEST_REGISTER(format_cap_add_multiple);
+	AST_TEST_REGISTER(format_cap_add_all_unknown);
+	AST_TEST_REGISTER(format_cap_set_framing);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Format capabilities API test module");

Propchange: team/group/media_formats/tests/test_format_cap.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/group/media_formats/tests/test_format_cap.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/group/media_formats/tests/test_format_cap.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the svn-commits mailing list