[asterisk-commits] file: branch group/media_formats r407195 - /team/group/media_formats/tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Feb 3 12:21:06 CST 2014


Author: file
Date: Mon Feb  3 12:21:02 2014
New Revision: 407195

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407195
Log:
Add a test for format_cap_get_compatible.

Modified:
    team/group/media_formats/tests/test_format_cap.c

Modified: 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=diff&rev=407195&r1=407194&r2=407195
==============================================================================
--- team/group/media_formats/tests/test_format_cap.c (original)
+++ team/group/media_formats/tests/test_format_cap.c Mon Feb  3 12:21:02 2014
@@ -803,6 +803,93 @@
 	return AST_TEST_PASS;
 }
 
+AST_TEST_DEFINE(format_cap_get_compatible)
+{
+	RAII_VAR(struct ast_format_cap *, alaw_caps, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format_cap *, ulaw_caps, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_format_cap *, compatible_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_get_compatible";
+		info->category = "/main/format_cap/";
+		info->summary = "format capabilities negotiation unit test";
+		info->description =
+			"Test that getting the compatible formats between two capabilities structures succeeds";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	alaw_caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!alaw_caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+
+	ulaw_caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!ulaw_caps) {
+		ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+		return AST_TEST_FAIL;
+	}
+
+	compatible_caps = ast_format_cap_ng_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+	if (!compatible_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(ulaw_caps, ulaw_format, 0)) {
+		ast_test_status_update(test, "Could not add ulaw format to ulaw capabilities\n");
+		return AST_TEST_FAIL;
+	} else if (ast_format_cap_ng_add(alaw_caps, alaw_format, 0)) {
+		ast_test_status_update(test, "Could not add alaw format to alaw capabilities\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_format_cap_ng_get_compatible(ulaw_caps, alaw_caps, compatible_caps);
+	if (ast_format_cap_ng_count(compatible_caps)) {
+		ast_test_status_update(test, "A compatible format exists when none should\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_format_cap_ng_get_compatible(ulaw_caps, ulaw_caps, compatible_caps);
+	if (!ast_format_cap_ng_count(compatible_caps)) {
+		ast_test_status_update(test, "No compatible formats exist when 1 should\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
 static int unload_module(void)
 {
 	AST_TEST_UNREGISTER(format_cap_alloc);
@@ -819,6 +906,7 @@
 	AST_TEST_UNREGISTER(getformatname_multiple);
 	AST_TEST_UNREGISTER(format_cap_get_compatible_format);
 	AST_TEST_UNREGISTER(format_cap_iscompatible_format);
+	AST_TEST_UNREGISTER(format_cap_get_compatible);
 	return 0;
 }
 
@@ -838,6 +926,7 @@
 	AST_TEST_REGISTER(getformatname_multiple);
 	AST_TEST_REGISTER(format_cap_get_compatible_format);
 	AST_TEST_REGISTER(format_cap_iscompatible_format);
+	AST_TEST_REGISTER(format_cap_get_compatible);
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list