[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step1 r298339 - /team/dvossel/fixt...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Dec 15 16:58:53 UTC 2010


Author: dvossel
Date: Wed Dec 15 10:58:49 2010
New Revision: 298339

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=298339
Log:
Update to the format api unit test.

Modified:
    team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c

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=298339&r1=298338&r2=298339
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/tests/test_format_api.c Wed Dec 15 10:58:49 2010
@@ -39,14 +39,25 @@
 #include "asterisk/format.h"
 #include "asterisk/strings.h"
 
+/*! These are the keys for accessing attributes */
 enum test_attr_keys {
-	TEST_ATTR_NUMBER,
-	TEST_ATTR_STRING,
-};
-
+	TEST_ATTR_KEY_SAMP_RATE,
+	TEST_ATTR_KEY_STRING,
+};
+
+/*! These are the values for the TEST_ATTR_KEY_SAMP_RATE key */
+enum test_samp_values {
+	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 {
-	int number;
-	char string[10];
+	enum test_samp_values samp_flags;
+	char string[32];
 };
 
 static enum ast_format_cmp_res test_cmp(struct ast_format_attr *fattr1, struct ast_format_attr *fattr2)
@@ -54,22 +65,14 @@
 	struct test_attr *attr1 = (struct test_attr *) fattr1;
 	struct test_attr *attr2 = (struct test_attr *) fattr2;
 
-	if (attr1->number && attr1->number != attr2->number) {
+	if ((attr1->samp_flags == attr2->samp_flags) &&
+		!(strcmp(attr1->string, attr2->string))) {
+		return AST_FORMAT_CMP_IDENTICAL;
+	}
+	if ((attr1->samp_flags != (attr1->samp_flags & attr2->samp_flags)) ||
+		(!ast_strlen_zero(attr1->string) && strcmp(attr1->string, attr2->string))) {
 		return AST_FORMAT_CMP_NO_SUBSET;
 	}
-
-	if (!ast_strlen_zero(attr1->string) && strcmp(attr1->string, attr2->string)) {
-		return AST_FORMAT_CMP_NO_SUBSET;
-	}
-
-	if (!attr1->number && ast_strlen_zero(attr1->string)) {
-		return AST_FORMAT_CMP_NO_SUBSET;
-	}
-
-	if (attr1->number && !ast_strlen_zero(attr1->string)) {
-		return AST_FORMAT_CMP_IDENTICAL;
-	}
-
 	return AST_FORMAT_CMP_SUBSET;
 }
 
@@ -79,14 +82,18 @@
 	struct test_attr *attr2 = (struct test_attr *) fattr2;
 	struct test_attr *attr_res = (struct test_attr *) result;
 	int joint = -1;
-	if (attr1->number == attr2->number) {
-		attr_res->number = attr1->number;
+
+	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;
 }
 
@@ -101,10 +108,10 @@
 		key = va_arg(ap, int))
 	{
 		switch (key) {
-		case TEST_ATTR_NUMBER:
-			attr->number = va_arg(ap, int);
+		case TEST_ATTR_KEY_SAMP_RATE:
+			attr->samp_flags |= va_arg(ap, int);
 			break;
-		case TEST_ATTR_STRING:
+		case TEST_ATTR_KEY_STRING:
 			string = va_arg(ap, char *);
 			if (!ast_strlen_zero(string)) {
 				ast_copy_string(attr->string, string, sizeof(attr->string));
@@ -117,6 +124,9 @@
 	va_end(ap);
 }
 
+/*! 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_FORMAT2_TESTLAW,
 	.format_attr_cmp = test_cmp,
@@ -148,57 +158,57 @@
 		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_FORMAT2_TESTLAW, 1,
-		TEST_ATTR_NUMBER, 1234,
+		TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ,
 		AST_FORMAT2_ATTR_END);
-	if (ast_format_isset(&format1, TEST_ATTR_NUMBER, 1234, AST_FORMAT2_ATTR_END)) {
+	if (ast_format_isset(&format1, TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ, AST_FORMAT2_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_NUMBER, 1234567890, AST_FORMAT2_ATTR_END)) {
+	if (!ast_format_isset(&format1, TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_12KHZ, AST_FORMAT2_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_FORMAT2_TESTLAW, 1,
-		TEST_ATTR_STRING,"1234",
+		TEST_ATTR_KEY_STRING,"String",
 		AST_FORMAT2_ATTR_END);
-	if (ast_format_isset(&format1, TEST_ATTR_STRING, "1234", AST_FORMAT2_ATTR_END)) {
+	if (ast_format_isset(&format1, TEST_ATTR_KEY_STRING, "String", AST_FORMAT2_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_STRING, "7777", AST_FORMAT2_ATTR_END)) {
+	if (!ast_format_isset(&format1, TEST_ATTR_KEY_STRING, "Not a string", AST_FORMAT2_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_FORMAT2_TESTLAW, 1,
-		TEST_ATTR_STRING, "MOOOoo",
-		TEST_ATTR_NUMBER, 1234,
+		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_FORMAT2_ATTR_END);
 	/* perform isset with multiple key value pairs. */
 
 	if (ast_format_isset(&format2,
-			TEST_ATTR_STRING, "MOOOoo",
-			TEST_ATTR_NUMBER, 1234,
+			TEST_ATTR_KEY_STRING, "MOOOoo",
+			TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_16KHZ,
 			AST_FORMAT2_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_STRING, "WRONG",
-			TEST_ATTR_NUMBER, 1234,
+			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_FORMAT2_ATTR_END)) {
 
 		ast_test_status_update(test, "format2 did not deterine isset correctly.\n");
@@ -210,7 +220,7 @@
 		ast_test_status_update(test, "failed to get joint attributes.\n");
 		return AST_TEST_FAIL;
 	}
-	if (ast_format_isset(&joint, TEST_ATTR_NUMBER, 1234, AST_FORMAT2_ATTR_END)) {
+	if (ast_format_isset(&joint, TEST_ATTR_KEY_SAMP_RATE, TEST_ATTR_VAL_SAMP_8KHZ, AST_FORMAT2_ATTR_END)) {
 		ast_test_status_update(test, "joint attribute was not what we expected.\n");
 		return AST_TEST_FAIL;
 	}




More information about the svn-commits mailing list