[svn-commits] dvossel: branch group/aoc r251409 - in /team/group/aoc: main/ tests/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 9 13:17:15 CST 2010


Author: dvossel
Date: Tue Mar  9 13:17:11 2010
New Revision: 251409

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251409
Log:
update to unit test, encode and decode routines

At this point the unit test verifies encoding and
decoding of all the different message types.


Modified:
    team/group/aoc/main/aoc.c
    team/group/aoc/tests/test_aoc.c

Modified: team/group/aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/aoc.c?view=diff&rev=251409&r1=251408&r2=251409
==============================================================================
--- team/group/aoc/main/aoc.c (original)
+++ team/group/aoc/main/aoc.c Tue Mar  9 13:17:11 2010
@@ -56,6 +56,8 @@
 
 #define AOC_ENCODE_VERSION 1
 
+#define AOC_CURRENCY_NAME_SIZE 10+1
+
 /* AOC Payload Header. Holds all the encoded AOC data to pass on the wire */
 struct ast_aoc_encoded {
 	uint8_t  version;
@@ -74,7 +76,7 @@
 	/* currency information */
 	enum ast_aoc_currency_multiplier multiplier;
 	unsigned int currency_amount;
-	char currency_name[10+1];
+	char currency_name[AOC_CURRENCY_NAME_SIZE];
 
 	/* unit information */
 	int unit_count;
@@ -99,7 +101,7 @@
 struct aoc_ie_currency {
 	uint8_t  multiplier;
 	uint32_t amount;
-	char name[10+1];
+	char name[AOC_CURRENCY_NAME_SIZE];
 };
 
 #define AOC_IE_UNIT 2
@@ -165,20 +167,43 @@
 		case AOC_IE_CURRENCY:
 			if (len == sizeof(struct aoc_ie_currency)) {
 				struct aoc_ie_currency ie;
-
 				memcpy(&ie, data + 2, len);
 				decoded->currency_amount = ntohl(ie.amount);
 				decoded->multiplier = ie.multiplier; /* only one byte */
+				memcpy(decoded->currency_name, ie.name, sizeof(decoded->currency_name));
+
 			} else {
 				ast_log(LOG_WARNING, "Recieved invalid currency ie\n");
 			}
 		break;
 		case AOC_IE_UNIT:
-
+			if (len == sizeof(struct aoc_ie_unit)) {
+				struct aoc_ie_unit ie;
+				memcpy(&ie, data + 2, len);
+				ast_aoc_add_unit_entry(decoded, ntohl(ie.amount), ie.type);
+			} else {
+				ast_log(LOG_WARNING, "Recieved invalid unit ie\n");
+			}
+		break;
 		case AOC_IE_BILLING:
-
+			if (len == sizeof(struct aoc_ie_billing)) {
+				struct aoc_ie_billing ie;
+				memcpy(&ie, data + 2, len);
+				decoded->billing_id = ie.id; /* only one byte */
+			} else {
+				ast_log(LOG_WARNING, "Recieved invalid billing ie\n");
+			}
+		break;
 		case AOC_IE_CHARGING_ASSOCIATION:
-
+			if (len == sizeof(struct aoc_ie_charging_association)) {
+				struct aoc_ie_charging_association ie;
+				memcpy(&ie, data + 2, len);
+				decoded->charging_association_id = ntohl(ie.charge_id);
+				memcpy(decoded->charging_association_number, ie.charge_number, sizeof(decoded->charging_association_number));
+			} else {
+				ast_log(LOG_WARNING, "Recieved invalid charging association ie\n");
+			}
+		break;
 		default:
 			ast_log(LOG_WARNING, "Unknown AOC Information Element, ignoring.\n");
 		}
@@ -218,12 +243,12 @@
 			decoded->request_flag |= AOC_REQUEST_E;
 		}
 	} else {
-		if (encoded->flags & AOC_ENCODED_CHARGE_CURRENCY) {
+		if ((encoded->flags & AOC_ENCODED_CHARGE_UNIT) == AOC_ENCODED_CHARGE_UNIT) {
+			decoded->charge_type = AOC_CHARGE_UNIT;
+		} else if ((encoded->flags & AOC_ENCODED_CHARGE_CURRENCY) == AOC_ENCODED_CHARGE_CURRENCY) {
 			decoded->charge_type = AOC_CHARGE_CURRENCY;
-		} else if (encoded->flags & AOC_ENCODED_CHARGE_FREE) {
+		} else if ((encoded->flags & AOC_ENCODED_CHARGE_FREE) == AOC_ENCODED_CHARGE_FREE) {
 			decoded->charge_type = AOC_CHARGE_FREE;
-		} else if (encoded->flags & AOC_ENCODED_CHARGE_UNIT) {
-			decoded->charge_type = AOC_CHARGE_UNIT;
 		} else {
 			decoded->charge_type = AOC_CHARGE_NA;
 		}
@@ -269,6 +294,7 @@
 		struct aoc_ie_currency ie = {
 			.amount = htonl(decoded->currency_amount),
 			.multiplier = decoded->multiplier, /* only one byte */
+			.name = { 0, },
 		};
 		if (!ast_strlen_zero(decoded->currency_name)) {
 			ast_copy_string(ie.name, decoded->currency_name, sizeof(ie.name));
@@ -289,13 +315,13 @@
 
 	if (decoded->billing_id) {
 		struct aoc_ie_billing ie;
-		ie.id = htons(decoded->billing_id);
+		ie.id = htons(decoded->billing_id); /* only one byte */
 		aoc_append_ie(ied, AOC_IE_BILLING, (const void *) &ie, sizeof(ie));
 	}
 
 	if (decoded->charging_association_id ||
 		!ast_strlen_zero(decoded->charging_association_number)) {
-		struct aoc_ie_charging_association ie;
+		struct aoc_ie_charging_association ie = { 0 };
 		ie.charge_id = htonl(decoded->charging_association_id);
 		if (!ast_strlen_zero(decoded->charging_association_number)) {
 			ast_copy_string(ie.charge_number, decoded->charging_association_number, sizeof(ie.charge_number));
@@ -523,7 +549,7 @@
 		return -1;
 	}
 
-	if (memcmp(new, decoded, sizeof(new))) {
+	if (memcmp(new, decoded, sizeof(struct ast_aoc_decoded))) {
 		res = -1;
 	}
 

Modified: team/group/aoc/tests/test_aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/tests/test_aoc.c?view=diff&rev=251409&r1=251408&r2=251409
==============================================================================
--- team/group/aoc/tests/test_aoc.c (original)
+++ team/group/aoc/tests/test_aoc.c Tue Mar  9 13:17:11 2010
@@ -56,7 +56,6 @@
 	}
 
 	/* ---- Test 1 ---- create AOC-D message, encode message, and decode message once again. */
-
 	/* create AOC-D message */
 	if (!(decoded = ast_aoc_create(AOC_D, AOC_CHARGE_CURRENCY, 0)) ||
 		(ast_aoc_get_msg_type(decoded) != AOC_D) ||
@@ -69,6 +68,8 @@
 
 	/* Set currency information, verify results*/
 	if ((ast_aoc_set_currency_info(decoded, 100, AOC_MULT_ONE, "usd")) ||
+		(ast_aoc_set_total_type(decoded, AOC_SUBTOTAL)) ||
+		(ast_aoc_get_total_type(decoded) != AOC_SUBTOTAL) ||
 		(ast_aoc_get_currency_amount(decoded) != 100) ||
 		(ast_aoc_get_currency_multiplier(decoded) != AOC_MULT_ONE) ||
 		(strcmp(ast_aoc_get_currency_name(decoded), "usd"))) {
@@ -100,6 +101,93 @@
 	/* cleanup decoded msg */
 	decoded = ast_aoc_destroy_decoded(decoded);
 
+	/* ---- Test 2 ---- create AOC-E message with charge type == unit */
+	/* create AOC-D message */
+	if (!(decoded = ast_aoc_create(AOC_E, AOC_CHARGE_UNIT, 0)) ||
+		(ast_aoc_get_msg_type(decoded) != AOC_E) ||
+		(ast_aoc_get_charge_type(decoded) != AOC_CHARGE_UNIT)) {
+
+		ast_test_status_update(test, "Test 2: failed to create AOC-E message\n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+
+	/* Set unit information, verify results*/
+	if ((ast_aoc_add_unit_entry(decoded, 1, 2)) ||
+		(ast_aoc_add_unit_entry(decoded, 2, 3)) ||
+		(ast_aoc_add_unit_entry(decoded, 3, 4)) ||
+		(ast_aoc_add_unit_entry(decoded, 4, 5))) {
+
+		ast_test_status_update(test, "Test 2: failed to set unit info\n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+
+	/* verify unit list is correct */
+	if (ast_aoc_get_unit_count(decoded) == 4) {
+		int i;
+		const struct ast_aoc_unit_entry *unit;
+		for (i = 0; i < 4; i++) {
+			if (!(unit = ast_aoc_get_unit_info(decoded, i)) ||
+				(unit->amount != (i+1)) ||
+				(unit->type != (i+2))) {
+				ast_test_status_update(test, "TEST 2, invalid unit entry result, got %d,%d, expected %d,%d\n",
+					unit->amount,
+					unit->type,
+					i+1,
+					i+2);
+				res = AST_TEST_FAIL;
+				goto cleanup_aoc_test;
+			}
+		}
+	} else {
+		ast_test_status_update(test, "TEST 2, invalid unit list entry count \n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+
+	/* Encode the message */
+	if (ast_aoc_test_encode_decode_match(decoded)) {
+		ast_test_status_update(test, "Test2: encode decode routine did not match expected results \n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+	/* cleanup decoded msg */
+	decoded = ast_aoc_destroy_decoded(decoded);
+
+	/* ---- Test 3 ---- create AOC-Request. test all possible combinations */
+	{
+		int request[7] = { /* all possible request combinations */
+			0,
+			AOC_REQUEST_S,
+			AOC_REQUEST_D,
+			AOC_REQUEST_E,
+			(AOC_REQUEST_S | AOC_REQUEST_D),
+			(AOC_REQUEST_S | AOC_REQUEST_E),
+			(AOC_REQUEST_D | AOC_REQUEST_E),
+		};
+		int i;
+
+		for (i = 0; i < ARRAY_LEN(request); i++) {
+			if (!(decoded = ast_aoc_create(AOC_REQUEST, 0, request[i])) ||
+				(ast_aoc_get_msg_type(decoded) != AOC_REQUEST) ||
+				(ast_aoc_get_request(decoded) != request[i])) {
+
+				ast_test_status_update(test, "Test 3: failed to create AOC-Request message, iteration #%d\n", i);
+				res = AST_TEST_FAIL;
+				goto cleanup_aoc_test;
+			}
+
+			/* Encode the message */
+			if (ast_aoc_test_encode_decode_match(decoded)) {
+				ast_test_status_update(test, "Test3: encode decode routine did not match expected results, iteration #%d\n", i);
+				res = AST_TEST_FAIL;
+				goto cleanup_aoc_test;
+			}
+			/* cleanup decoded msg */
+			decoded = ast_aoc_destroy_decoded(decoded);
+		}
+	}
 cleanup_aoc_test:
 
 	decoded = ast_aoc_destroy_decoded(decoded);




More information about the svn-commits mailing list