[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r301448 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 12 10:11:43 CST 2011


Author: dvossel
Date: Wed Jan 12 10:11:38 2011
New Revision: 301448

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=301448
Log:
Adding the format api unit tests to this branch

Added:
    team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c   (with props)
Modified:
    team/dvossel/fixtheworld_phase1_step3/main/file.c

Modified: team/dvossel/fixtheworld_phase1_step3/main/file.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/file.c?view=diff&rev=301448&r1=301447&r2=301448
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/file.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/file.c Wed Jan 12 10:11:38 2011
@@ -292,8 +292,6 @@
 
 static void filestream_destructor(void *arg)
 {
-	char *cmd = NULL;
-	size_t size = 0;
 	struct ast_filestream *f = arg;
 
 	/* Stop a running stream if there is one */

Added: team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c?view=auto&rev=301448
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c (added)
+++ team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c Wed Jan 12 10:11:38 2011
@@ -1,0 +1,588 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * David Vossel <dvossel 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 Tests for the ast_event API
+ *
+ * \author David Vossel <dvossel at digium.com>
+ *
+ * \ingroup tests
+ *
+ */
+
+/*** MODULEINFO
+	<depend>TEST_FRAMEWORK</depend>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/test.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cap.h"
+#include "asterisk/strings.h"
+
+/*! These are the keys for accessing attributes */
+enum test_attr_keys {
+	TEST_ATTR_KEY_SAMP_RATE,
+	TEST_ATTR_KEY_STRING,
+};
+
+/*! These are the values for the TEST_ATTR_KEY_SAMP_RATE key */
+enum test_attr_vals_samp {
+	TEST_ATTR_VAL_SAMP_8KHZ  = (1 << 0),
+	TEST_ATTR_VAL_SAMP_12KHZ = (1 << 1),
+	TEST_ATTR_VAL_SAMP_16KHZ = (1 << 2),
+	TEST_ATTR_VAL_SAMP_32KHZ = (1 << 3),
+	TEST_ATTR_VAL_SAMP_48KHZ = (1 << 4),
+};
+
+/*! This is the attribute structure used for our test interface. */
+struct test_attr {
+	enum test_attr_vals_samp samp_flags;
+	char string[32];
+};
+
+static enum ast_format_cmp_res test_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
+{
+	struct test_attr *attr1 = (struct test_attr *) fattr1;
+	struct test_attr *attr2 = (struct test_attr *) fattr2;
+
+	if ((attr1->samp_flags == attr2->samp_flags) &&
+		!(strcmp(attr1->string, attr2->string))) {
+		return AST_FORMAT_CMP_EQUAL;
+	}
+	if ((attr1->samp_flags != (attr1->samp_flags & attr2->samp_flags)) ||
+		(!ast_strlen_zero(attr1->string) && strcmp(attr1->string, attr2->string))) {
+		return AST_FORMAT_CMP_NOT_EQUAL;
+	}
+	return AST_FORMAT_CMP_SUBSET;
+}
+
+static int test_getjoint(struct ast_format_attr *fattr1, struct ast_format_attr *fattr2, struct ast_format_attr *result)
+{
+	struct test_attr *attr1 = (struct test_attr *) fattr1;
+	struct test_attr *attr2 = (struct test_attr *) fattr2;
+	struct test_attr *attr_res = (struct test_attr *) result;
+	int joint = -1;
+
+	attr_res->samp_flags = (attr1->samp_flags & attr2->samp_flags);
+
+	if (attr_res->samp_flags) {
+		joint = 0;
+	}
+
+	if (!strcmp(attr1->string, attr2->string)) {
+		ast_copy_string(attr_res->string, attr1->string, sizeof(attr_res->string));
+		joint = 0;
+	}
+
+	return joint;
+}
+
+static void test_set(struct ast_format_attr *fattr, va_list ap)
+{
+	enum test_attr_keys key;
+	struct test_attr *attr = (struct test_attr *) fattr;
+	char *string;
+
+	for (key = va_arg(ap, int);
+		key != AST_FORMAT_ATTR_END;
+		key = va_arg(ap, int))
+	{
+		switch (key) {
+		case TEST_ATTR_KEY_SAMP_RATE:
+			attr->samp_flags = (va_arg(ap, int) | attr->samp_flags);
+			break;
+		case TEST_ATTR_KEY_STRING:
+			string = va_arg(ap, char *);
+			if (!ast_strlen_zero(string)) {
+				ast_copy_string(attr->string, string, sizeof(attr->string));
+			}
+			break;
+		default:
+			ast_log(LOG_WARNING, "unknown attribute type %d\n", key);
+		}
+	}
+}
+
+/*! uLaw does not actually have any attributes associated with it.
+ * This is just for the purpose of testing. We are guaranteed there
+ * will never exist a interface for uLaw already. */
+static struct ast_format_attr_interface test_interface = {
+	.id = AST_FORMAT_TESTLAW,
+	.format_attr_cmp = test_cmp,
+	.format_attr_get_joint = test_getjoint,
+	.format_attr_set = test_set
+};
+
+/*!
+ * \internal
+ */
+AST_TEST_DEFINE(format_test1)
+{
+	struct ast_format format1 = { 0, };
+	struct ast_format format2 = { 0, };
+	struct ast_format joint = { 0, };
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "ast_format_test1";
+		info->category = "/main/format/";
+		info->summary = "Test ast_format with attributes.";
+		info->description =
+			"This test exercises the Ast Format API by creating and registering "
+			"a custom ast_format_attr_interface and performing various function "
+			"calls on ast_formats using the interface. ";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	if (ast_format_attr_reg_interface(&test_interface)) {
+		ast_test_status_update(test, "test_interface failed to register.\n");
+		return AST_TEST_FAIL;
+	}
+
+	/* set a format with a single attribute. */
+	ast_format_set(&format1, AST_FORMAT_TESTLAW, 1,
+		TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+		AST_FORMAT_ATTR_END);
+	if (ast_format_isset(&format1, TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ, AST_FORMAT_ATTR_END)) {
+		ast_test_status_update(test, "format1 did not set number attribute correctly.\n");
+		return AST_TEST_FAIL;
+	}
+	if (!ast_format_isset(&format1, TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_12KHZ, AST_FORMAT_ATTR_END)) {
+		ast_test_status_update(test, "format1 did not determine isset on number correctly. \n");
+		return AST_TEST_FAIL;
+	}
+
+	/* append the string attribute to a format with previous attributes already set */
+	ast_format_set(&format1, AST_FORMAT_TESTLAW, 1,
+		TEST_ATTR_KEY_STRING,"String",
+		AST_FORMAT_ATTR_END);
+	if (ast_format_isset(&format1, TEST_ATTR_KEY_STRING, "String", AST_FORMAT_ATTR_END)) {
+		ast_test_status_update(test, "format1 did not set string attribute correctly.\n");
+		return AST_TEST_FAIL;
+	}
+	if (!ast_format_isset(&format1, TEST_ATTR_KEY_STRING, "Not a string", AST_FORMAT_ATTR_END)) {
+		ast_test_status_update(test, "format1 did not determine isset on string correctly. \n");
+		return AST_TEST_FAIL;
+	}
+
+	/* set format2 with both STRING and NUMBER at the same time */
+	ast_format_set(&format2, AST_FORMAT_TESTLAW, 1,
+		TEST_ATTR_KEY_STRING, "MOOOoo",
+		TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+		TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+		AST_FORMAT_ATTR_END);
+	/* perform isset with multiple key value pairs. */
+
+	if (ast_format_isset(&format2,
+			TEST_ATTR_KEY_STRING, "MOOOoo",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			AST_FORMAT_ATTR_END)) {
+
+		ast_test_status_update(test, "format2 did not set attributes correctly.\n");
+		return AST_TEST_FAIL;
+	}
+	if (!ast_format_isset(&format2,
+			TEST_ATTR_KEY_STRING, "WRONG",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			AST_FORMAT_ATTR_END)) {
+
+		ast_test_status_update(test, "format2 did not deterine isset correctly.\n");
+		return AST_TEST_FAIL;
+	}
+
+	/* get joint attributes between format1 and format2. */
+	if (ast_format_joint(&format1, &format2, &joint)) {
+		ast_test_status_update(test, "failed to get joint attributes.\n");
+		return AST_TEST_FAIL;
+	}
+	if (ast_format_isset(&joint, TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ, AST_FORMAT_ATTR_END)) {
+		ast_test_status_update(test, "joint attribute was not what we expected.\n");
+		return AST_TEST_FAIL;
+	}
+
+	/* exercise compare functions */
+	if (ast_format_cmp(&format1, &format2) != AST_FORMAT_CMP_NOT_EQUAL) {
+		ast_test_status_update(test, "cmp 1 failed.\n");
+		return AST_TEST_FAIL;
+	}
+	if (ast_format_cmp(&format1, &format1) != AST_FORMAT_CMP_EQUAL) {
+		ast_test_status_update(test, "cmp 2 failed.\n");
+		return AST_TEST_FAIL;
+	}
+	if (ast_format_cmp(&joint, &format1) != AST_FORMAT_CMP_SUBSET) {
+		ast_test_status_update(test, "cmp 3 failed.\n");
+		return AST_TEST_FAIL;
+	}
+
+	/* unregister interface */
+	if (ast_format_attr_unreg_interface(&test_interface)) {
+		ast_test_status_update(test, "test_interface failed to unregister.\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+/*!
+ * \internal
+ */
+AST_TEST_DEFINE(format_test2)
+{
+	struct ast_format format = { 0, };
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "ast_format_test2";
+		info->category = "/main/format/";
+		info->summary = "Test ast_format unique id and category system";
+		info->description =
+			"This test exercises the Ast Format unique id and category "
+			"system by creating formats of various types and verifying "
+			"their category matches what we expect.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	ast_format_set(&format, AST_FORMAT_ULAW, 0);
+	if (AST_FORMAT_GET_TYPE(format.id) != AST_FORMAT_TYPE_AUDIO) {
+		ast_test_status_update(test, "audio type failed\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_format_set(&format, AST_FORMAT_H264, 0);
+	if (AST_FORMAT_GET_TYPE(format.id) != AST_FORMAT_TYPE_VIDEO) {
+		ast_test_status_update(test, "video type failed\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_format_set(&format, AST_FORMAT_JPEG, 0);
+	if (AST_FORMAT_GET_TYPE(format.id) != AST_FORMAT_TYPE_IMAGE) {
+		ast_test_status_update(test, "image type failed\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_format_set(&format, AST_FORMAT_T140, 0);
+	if (AST_FORMAT_GET_TYPE(format.id) != AST_FORMAT_TYPE_TEXT) {
+		ast_test_status_update(test, "text type failed\n");
+		return AST_TEST_FAIL;
+	}
+
+	return AST_TEST_PASS;
+}
+
+/*!
+ * \internal
+ */
+AST_TEST_DEFINE(format_test3)
+{
+	int res = AST_TEST_PASS;
+	struct ast_format tmpformat = { 0, };
+	struct ast_cap *cap1;
+	struct ast_cap *cap2;
+	struct ast_cap *cap_joint;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "ast_format_test3";
+		info->category = "/main/format/";
+		info->summary = "Test ast_format and ast_cap structures";
+		info->description =
+			"This test exercises the Ast Format Capability API by creating "
+			"capability structures and performing various API calls on them.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	cap1 = ast_cap_alloc();
+	cap2 = ast_cap_alloc();
+
+	if (!cap1 || !cap2) {
+		ast_test_status_update(test, "cap alloc failed.\n");
+		return AST_TEST_FAIL;
+	}
+
+	if (ast_format_attr_reg_interface(&test_interface)) {
+		ast_test_status_update(test, "test_interface failed to register.\n");
+		ast_cap_destroy(cap1);
+		ast_cap_destroy(cap2);
+		return AST_TEST_FAIL;
+	}
+
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_ULAW, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_G722, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_ALAW, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_H264, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_H263, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_T140, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_JPEG, 0));
+	ast_cap_add(cap1, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_STRING, "testing caps hooray",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_32KHZ,
+			AST_FORMAT_ATTR_END));
+
+	/* Test is compatible */
+	if (!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_ALAW, 0)) ||
+		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_ULAW, 0)) ||
+		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0)) ||
+		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_H264, 0)) ||
+		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_JPEG, 0)) ||
+		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_T140, 0))) {
+		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 1.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+	/* Test things that are not compatible */
+	if (ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_SPEEX, 0)) ||
+		ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_SPEEX16, 0)) ||
+		ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_H261, 0))) {
+		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 2.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+	/* Test compatiblity with format with attributes. */
+	if (!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_STRING, "testing caps hooray",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			AST_FORMAT_ATTR_END))) {
+
+		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 3.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	if (!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			AST_FORMAT_ATTR_END))) {
+
+		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 4.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	if (ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_48KHZ, /* 48khz was not compatible, so this should fail iscompatible check */
+			AST_FORMAT_ATTR_END))) {
+
+		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 5.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+	/* Lets start testing the functions that compare ast_cap objects.
+	 * Genreate the cap2 object to contain some similar formats as cap1
+	 * and some different formats as well. */
+	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0));
+	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMAT_ULAW, 0));
+	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMAT_SIREN7, 0));
+	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMAT_H261, 0));
+	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMAT_T140, 0));
+	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_STRING, "testing caps hooray",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_12KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_32KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_48KHZ,
+			AST_FORMAT_ATTR_END));
+
+
+	/* find joint formats between cap1 and cap2 */
+	cap_joint = ast_cap_joint(cap1, cap2);
+
+	if (!cap_joint) {
+		ast_test_status_update(test, "failed to create joint capabilities correctly.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* determine if cap_joint is what we think it should be */
+	if (!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0)) ||
+		!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_ULAW, 0)) ||
+		!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_T140, 0)) ||
+		!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_STRING, "testing caps hooray",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			AST_FORMAT_ATTR_END))) {
+
+		ast_test_status_update(test, "ast cap_joint failed to properly detect compatibility test 1.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* make sure joint cap does not have formats that should not be there */
+	if (ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_SIREN7, 0)) ||
+		ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_TESTLAW, 1,
+			TEST_ATTR_KEY_STRING, "testing caps hooray",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_48KHZ,
+			AST_FORMAT_ATTR_END))) {
+
+		ast_test_status_update(test, "ast cap_joint failed to properly detect compatibility test 1.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+	/* Lets test removing a capability */
+	if (ast_cap_remove(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_T140, 0))) {
+		ast_test_status_update(test, "ast_cap_remove failed. \n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* Lets make sure what we just removed does not still exist */
+	if (ast_cap_iscompatible(cap_joint, &tmpformat)) {
+		ast_test_status_update(test, "ast_cap_remove failed 2. \n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* Lets test removing a capability by id.*/
+	if (ast_cap_remove_byid(cap_joint, AST_FORMAT_GSM)) {
+		ast_test_status_update(test, "ast_cap_remove failed 3. \n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* Lets make sure what we just removed does not still exist */
+	if (ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0))) {
+		ast_test_status_update(test, "ast_cap_remove failed 4. \n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+	/* lets test getting joint formats by type */
+	ast_cap_destroy(cap_joint);
+	if (!(cap_joint = ast_cap_get_type(cap1, AST_FORMAT_TYPE_VIDEO))) {
+		ast_test_status_update(test, "ast_cap_get_type failed.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* lets make sure our joint capability structure has what we expect */
+	if (!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_H264, 0)) ||
+		!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_H263, 0))) {
+		ast_test_status_update(test, "get_type failed 2.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+	/* now make sure joint does not have anything but video */
+	if (ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_ALAW, 0)) ||
+		ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_ULAW, 0)) ||
+		ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0)) ||
+		ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_JPEG, 0)) ||
+		ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMAT_T140, 0))) {
+		ast_test_status_update(test, "get_type failed 3.\n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+
+test3_cleanup:
+	ast_cap_destroy(cap1);
+	ast_cap_destroy(cap2);
+	ast_cap_destroy(cap_joint);
+
+	/* unregister interface */
+	if (ast_format_attr_unreg_interface(&test_interface)) {
+		ast_test_status_update(test, "test_interface failed to unregister.\n");
+		res = AST_TEST_FAIL;
+	}
+
+	return res;
+}
+
+/*!
+ * \internal
+ */
+AST_TEST_DEFINE(format_test4)
+{
+	int num = 0;
+	struct ast_format tmpformat = { 0, };
+	struct ast_cap *cap;
+
+	switch (cmd) {
+	case TEST_INIT:
+		info->name = "ast_format_test4";
+		info->category = "/main/format/";
+		info->summary = "Test ast_cap iterator";
+		info->description =
+			"This test exercises the Ast Capability API iterators.";
+		return AST_TEST_NOT_RUN;
+	case TEST_EXECUTE:
+		break;
+	}
+
+	cap = ast_cap_alloc();
+	if (!cap) {
+		ast_test_status_update(test, "alloc failed\n");
+		return AST_TEST_FAIL;
+	}
+
+	ast_cap_add(cap, ast_format_set(&tmpformat, AST_FORMAT_GSM, 0));
+	ast_cap_add(cap, ast_format_set(&tmpformat, AST_FORMAT_ULAW, 0));
+	ast_cap_add(cap, ast_format_set(&tmpformat, AST_FORMAT_G722, 0));
+
+	ast_cap_iter_start(cap);
+	while (!ast_cap_iter_next(cap, &tmpformat)) {
+		num++;
+	}
+	ast_cap_iter_end(cap);
+
+	ast_cap_iter_start(cap);
+	while (!ast_cap_iter_next(cap, &tmpformat)) {
+		num++;
+	}
+	ast_cap_iter_end(cap);
+
+	ast_cap_destroy(cap);
+	ast_test_status_update(test, "%d items iterated over\n", num);
+	return (num == 6) ? AST_TEST_PASS : AST_TEST_FAIL;
+}
+static int unload_module(void)
+{
+	AST_TEST_UNREGISTER(format_test1);
+	AST_TEST_UNREGISTER(format_test2);
+	AST_TEST_UNREGISTER(format_test3);
+	AST_TEST_UNREGISTER(format_test4);
+
+	return 0;
+}
+
+static int load_module(void)
+{
+	AST_TEST_REGISTER(format_test1);
+	AST_TEST_REGISTER(format_test2);
+	AST_TEST_REGISTER(format_test3);
+	AST_TEST_REGISTER(format_test4);
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "ast_format API Tests");

Propchange: team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list