[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step1 r298771 - in /team/dvossel/f...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 17 17:06:54 UTC 2010


Author: dvossel
Date: Fri Dec 17 11:06:49 2010
New Revision: 298771

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=298771
Log:
Updates to format capability unit tests

Modified:
    team/dvossel/fixtheworld_phase1_step1/main/format.c
    team/dvossel/fixtheworld_phase1_step1/main/format_cap.c
    team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c

Modified: team/dvossel/fixtheworld_phase1_step1/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format.c?view=diff&rev=298771&r1=298770&r2=298771
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format.c Fri Dec 17 11:06:49 2010
@@ -100,6 +100,9 @@
 
 struct ast_format *ast_format_set(struct ast_format *format, enum ast_format_id id, int set_attributes, ... )
 {
+	if (format->id != id) {
+		memset(&format->fattr, 0, sizeof(format->fattr));
+	}
 	format->id = id;
 
 	if (set_attributes) {
@@ -255,6 +258,10 @@
 int ast_format_attr_reg_interface(struct ast_format_attr_interface *interface)
 {
 	struct interface_ao2_wrapper *wrapper;
+
+	/* check for duplicates first, remove if they exist */
+	ast_format_attr_unreg_interface(interface);
+
 	if (!interfaces &&
 			!(interfaces = ao2_container_alloc(256,
 			interface_hash_cb,
@@ -263,7 +270,7 @@
 		return -1;
 	}
 
-	if (!(wrapper = ao2_alloc(sizeof(wrapper), NULL))) {
+	if (!(wrapper = ao2_alloc(sizeof(*wrapper), NULL))) {
 		return -1;
 	}
 

Modified: team/dvossel/fixtheworld_phase1_step1/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format_cap.c?view=diff&rev=298771&r1=298770&r2=298771
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format_cap.c Fri Dec 17 11:06:49 2010
@@ -78,6 +78,9 @@
 
 void *ast_cap_destroy(struct ast_cap *cap)
 {
+	if (!cap) {
+		return NULL;
+	}
 	ao2_ref(cap->formats, -1);
 	ast_free(cap);
 	return NULL;
@@ -156,26 +159,47 @@
 	return 0;
 }
 
+/* this struct is just used for the ast_cap_joint function so we
+ * can provide both a format and a result ast_cap structure as arguments
+ * to the make_joint ao2 callback function. */
+struct find_joint_data {
+	/* format to compare to for joint capabilities */
+	struct ast_format *format;
+	/* if joint formmat exists with above format, add it to the result container */
+	struct ast_cap *joint_cap;
+};
+
+static int find_joint_cb(void *obj, void *arg, int flag)
+{
+	struct ast_format *format = (struct ast_format *) obj;
+	struct find_joint_data *data = (struct find_joint_data*) arg;
+
+	struct ast_format tmp = { 0, };
+	if (!ast_format_joint(format, data->format, &tmp)) {
+		ast_cap_add(data->joint_cap, &tmp);
+	}
+
+	return 0;
+}
+
 struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2)
 {
 	struct ao2_iterator it;
 	struct ast_cap *result = ast_cap_alloc();
 	struct ast_format *tmp;
-
+	struct find_joint_data data;
 	if (!result) {
 		return NULL;
 	}
-
-	/* for each format in cap1, see if that format is
-	 * compatible with cap2. If so copy it to the result */
+	data.joint_cap = result;
+
 	it = ao2_iterator_init(cap1->formats, 0);
 	while ((tmp = ao2_iterator_next(&it))) {
-
-//todohere, This is wrong.  we need to be using ast_format_joint here
-		if (ast_cap_iscompatible(cap2, tmp)) {
-			/* copy joint format */
-			ast_cap_add(result, tmp);
-		}
+		data.format = tmp;
+		ao2_callback(cap2->formats,
+			OBJ_MULTIPLE | OBJ_NODATA,
+			find_joint_cb,
+			&data);
 		ao2_ref(tmp, -1);
 	}
 	ao2_iterator_destroy(&it);
@@ -183,6 +207,7 @@
 	if (ao2_container_count(result->formats)) {
 		return result;
 	}
+
 	result = ast_cap_destroy(result);
 	return NULL;
 }

Modified: team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c?view=diff&rev=298771&r1=298770&r2=298771
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c Fri Dec 17 11:06:49 2010
@@ -47,7 +47,7 @@
 };
 
 /*! These are the values for the TEST_ATTR_KEY_SAMP_RATE key */
-enum test_samp_values {
+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),
@@ -57,7 +57,7 @@
 
 /*! This is the attribute structure used for our test interface. */
 struct test_attr {
-	enum test_samp_values samp_flags;
+	enum test_attr_vals_samp samp_flags;
 	char string[32];
 };
 
@@ -110,7 +110,7 @@
 	{
 		switch (key) {
 		case TEST_ATTR_KEY_SAMP_RATE:
-			attr->samp_flags |= va_arg(ap, int);
+			attr->samp_flags = (va_arg(ap, int) | attr->samp_flags);
 			break;
 		case TEST_ATTR_KEY_STRING:
 			string = va_arg(ap, char *);
@@ -301,6 +301,7 @@
  */
 AST_TEST_DEFINE(format_test3)
 {
+	int res = AST_TEST_PASS;
 	struct ast_format tmpformat = { 0, };
 	struct ast_cap *cap1;
 	struct ast_cap *cap2;
@@ -329,6 +330,8 @@
 
 	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;
 	}
 
@@ -344,6 +347,7 @@
 			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_FORMATNEW_ATTR_END));
 
 	/* Test is compatible */
@@ -354,7 +358,8 @@
 		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMATNEW_JPEG, 0)) ||
 		!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMATNEW_T140, 0))) {
 		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 1.\n");
-		return AST_TEST_FAIL;
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
 	}
 
 	/* Test things that are not compatible */
@@ -362,7 +367,8 @@
 		ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMATNEW_SPEEX16, 0)) ||
 		ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMATNEW_H261, 0))) {
 		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 2.\n");
-		return AST_TEST_FAIL;
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
 	}
 
 	/* Test compatiblity with format with attributes. */
@@ -373,14 +379,16 @@
 			AST_FORMATNEW_ATTR_END))) {
 
 		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 3.\n");
-		return AST_TEST_FAIL;
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
 	}
 	if (!ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMATNEW_TESTLAW, 1,
 			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
 			AST_FORMATNEW_ATTR_END))) {
 
 		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 4.\n");
-		return AST_TEST_FAIL;
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
 	}
 	if (ast_cap_iscompatible(cap1, ast_format_set(&tmpformat, AST_FORMATNEW_TESTLAW, 1,
 			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
@@ -388,7 +396,8 @@
 			AST_FORMATNEW_ATTR_END))) {
 
 		ast_test_status_update(test, "ast cap1 failed to properly detect compatibility test 5.\n");
-		return AST_TEST_FAIL;
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
 	}
 
 	/* Lets start testing the functions that compare ast_cap objects.
@@ -401,7 +410,10 @@
 	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMATNEW_T140, 0));
 	ast_cap_add(cap2, ast_format_set(&tmpformat, AST_FORMATNEW_TESTLAW, 1,
 			TEST_ATTR_KEY_STRING, "testing caps hooray",
-			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
+			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_FORMATNEW_ATTR_END));
 
@@ -411,7 +423,8 @@
 
 	if (!cap_joint) {
 		ast_test_status_update(test, "failed to create joint capabilities correctly.\n");
-		return AST_TEST_FAIL;
+		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_FORMATNEW_GSM, 0)) ||
@@ -420,13 +433,53 @@
 		!ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMATNEW_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_FORMATNEW_ATTR_END))) {
 
-//todohere MAKE THIS PASS.
 		ast_test_status_update(test, "ast cap_joint failed to properly detect compatibility test 1.\n");
-		return AST_TEST_FAIL;
-	}
-
+		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_FORMATNEW_SIREN7, 0)) ||
+		ast_cap_iscompatible(cap_joint, ast_format_set(&tmpformat, AST_FORMATNEW_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_FORMATNEW_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_FORMATNEW_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_FORMATNEW_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_FORMATNEW_GSM, 0))) {
+		ast_test_status_update(test, "ast_cap_remove failed 4. \n");
+		res = AST_TEST_FAIL;
+		goto test3_cleanup;
+	}
+
+test3_cleanup:
 	ast_cap_destroy(cap1);
 	ast_cap_destroy(cap2);
 	ast_cap_destroy(cap_joint);
@@ -434,10 +487,10 @@
 	/* 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;
+		res = AST_TEST_FAIL;
+	}
+
+	return res;
 }
 
 static int unload_module(void)




More information about the asterisk-commits mailing list