[svn-commits] dvossel: branch group/aoc r251397 - in /team/group/aoc: include/asterisk/ mai...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Mar 8 16:53:27 CST 2010


Author: dvossel
Date: Mon Mar  8 16:53:24 2010
New Revision: 251397

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=251397
Log:
move aoc_decoded and aoc_encoded definitions to aoc.c, addition of first aoc unit test

Modified:
    team/group/aoc/include/asterisk/aoc.h
    team/group/aoc/main/aoc.c
    team/group/aoc/tests/test_aoc.c

Modified: team/group/aoc/include/asterisk/aoc.h
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/include/asterisk/aoc.h?view=diff&rev=251397&r1=251396&r2=251397
==============================================================================
--- team/group/aoc/include/asterisk/aoc.h (original)
+++ team/group/aoc/include/asterisk/aoc.h Mon Mar  8 16:53:24 2010
@@ -1,7 +1,7 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2009-2010, Digium, Inc.
+ * Copyright (C) 2010, Digium, Inc.
  *
  * David Vossel <dvossel at digium.com>
  *
@@ -18,9 +18,7 @@
 
 /*!
  * \file
- * \brief Test Framework API
- *
- * For an overview on how to use the test API, see \ref AstUnitTestAPI
+ * \brief Generic Advice of Charge encode and decode routines
  *
  * \author David Vossel <dvossel at digium.com>
  */
@@ -75,42 +73,16 @@
 	AOC_SUBTOTAL = 1,
 };
 
-/* AOC Payload Header. Holds all the encoded AOC data to pass on the wire */
-struct ast_aoc_encoded {
-	uint8_t  version;
-	uint8_t  flags;
-	uint16_t datalen;
-	unsigned char data[0];
-};
-
 struct ast_aoc_unit_entry {
 	unsigned int amount;
 	unsigned int type; /* 1 - 16 */
 };
 
+/* AOC Payload Header. Holds all the encoded AOC data to pass on the wire */
+struct ast_aoc_encoded;
+
 /* Decoded AOC data */
-struct ast_aoc_decoded {
-	enum ast_aoc_type msg_type;
-	enum ast_aoc_charge_type charge_type;
-	enum ast_aoc_request request_flag;
-	enum ast_aoc_total_type total_type;
-
-	/* currency information */
-	enum ast_aoc_currency_multiplier multiplier;
-	unsigned int currency_amount;
-	char currency_name[10+1];
-
-	/* unit information */
-	int unit_count;
-	struct ast_aoc_unit_entry unit_list[32];
-
-	/* Billing Id */
-	enum ast_aoc_billing_id billing_id;
-
-	/* Charging Association information */
-	int charging_association_id;
-	char charging_association_number[64];
-};
+struct ast_aoc_decoded;
 
 
 /* \brief creates a ast_aoc_decode object of a specific message type
@@ -129,6 +101,10 @@
 		const enum ast_aoc_charge_type charge_type,
 		const enum ast_aoc_request requests);
 
+
+/* \brief free an ast_aoc_decoded object */
+void *ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded);
+
 /* \brief decodes an encoded aoc payload.
  *
  * \param ast_aoc_encoded, the encoded payload to decode.
@@ -213,6 +189,9 @@
 /* \brief get the message type, AOC-D, AOC-E, or AOC Request */
 enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded);
 
+/* \brief get the charging type for an AOC-D or AOC-E message */
+enum ast_aoc_charge_type ast_aoc_get_charge_type(struct ast_aoc_decoded *decoded);
+
 /* \brief get the types of AOC requested for when message type is AOC Request */
 enum ast_aoc_request ast_aoc_get_request(struct ast_aoc_decoded *decoded);
 

Modified: team/group/aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/main/aoc.c?view=diff&rev=251397&r1=251396&r2=251397
==============================================================================
--- team/group/aoc/main/aoc.c (original)
+++ team/group/aoc/main/aoc.c Mon Mar  8 16:53:24 2010
@@ -50,6 +50,38 @@
 
 #define AOC_ENCODED_CHARGE_SUBTOTAL (1 << 7)
 #define AOC_ENCODED_CHARGE_TOTAL    (0 << 7)
+
+/* AOC Payload Header. Holds all the encoded AOC data to pass on the wire */
+struct ast_aoc_encoded {
+	uint8_t  version;
+	uint8_t  flags;
+	uint16_t datalen;
+	unsigned char data[0];
+};
+
+/* Decoded AOC data */
+struct ast_aoc_decoded {
+	enum ast_aoc_type msg_type;
+	enum ast_aoc_charge_type charge_type;
+	enum ast_aoc_request request_flag;
+	enum ast_aoc_total_type total_type;
+
+	/* currency information */
+	enum ast_aoc_currency_multiplier multiplier;
+	unsigned int currency_amount;
+	char currency_name[10+1];
+
+	/* unit information */
+	int unit_count;
+	struct ast_aoc_unit_entry unit_list[32];
+
+	/* Billing Id */
+	enum ast_aoc_billing_id billing_id;
+
+	/* Charging Association information */
+	int charging_association_id;
+	char charging_association_number[64];
+};
 
 struct aoc_pl_ie_hdr {
 	uint8_t ie_id;
@@ -108,6 +140,12 @@
 	return decoded;
 }
 
+void *ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
+{
+	ast_free(decoded);
+	return NULL;
+}
+
 struct ast_aoc_decoded *ast_aoc_decode(struct ast_aoc_encoded *encoded)
 {
 	struct ast_aoc_decoded *decoded = ast_calloc(1, sizeof(struct ast_aoc_decoded));
@@ -139,6 +177,11 @@
 enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
 {
 	return decoded->msg_type;
+}
+
+enum ast_aoc_charge_type ast_aoc_get_charge_type(struct ast_aoc_decoded *decoded)
+{
+	return decoded->charge_type;
 }
 
 enum ast_aoc_request ast_aoc_get_request(struct ast_aoc_decoded *decoded)

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=251397&r1=251396&r2=251397
==============================================================================
--- team/group/aoc/tests/test_aoc.c (original)
+++ team/group/aoc/tests/test_aoc.c Mon Mar  8 16:53:24 2010
@@ -36,10 +36,12 @@
 #include "asterisk/utils.h"
 #include "asterisk/module.h"
 #include "asterisk/test.h"
+#include "asterisk/aoc.h"
 
 AST_TEST_DEFINE(aoc_encode_decode_test)
 {
 	int res = AST_TEST_PASS;
+	struct ast_aoc_decoded *decoded;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -53,7 +55,50 @@
 		break;
 	}
 
+	/* ---- 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) ||
+		(ast_aoc_get_charge_type(decoded) != AOC_CHARGE_CURRENCY)) {
+
+		ast_test_status_update(test, "Test 1: failed to create AOC-D message\n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+
+	/* Set currency information, verify results*/
+	if ((ast_aoc_set_currency_info(decoded, 100, AOC_MULT_ONE, "usd")) ||
+		(ast_aoc_get_currency_amount(decoded) != 100) ||
+		(ast_aoc_get_currency_multiplier(decoded) != AOC_MULT_ONE) ||
+		(strcmp(ast_aoc_get_currency_name(decoded), "usd"))) {
+
+		ast_test_status_update(test, "Test 1: failed to set currency info\n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+
+	/* Set a currency name larger than 10 characters which is the the maximum
+	 * length allowed by the ETSI aoc standard.  The name is expected to truncate
+	 * to 10 characters. */
+	if ((ast_aoc_set_currency_info(decoded, 100, AOC_MULT_ONE, "12345678901234567890")) ||
+		(ast_aoc_get_currency_amount(decoded) != 100) ||
+		(ast_aoc_get_currency_multiplier(decoded) != AOC_MULT_ONE) ||
+		(strcmp(ast_aoc_get_currency_name(decoded), "1234567890"))) {
+
+		ast_test_status_update(test, "Test 1: failed to set currency info currency name exceeding limit\n");
+		res = AST_TEST_FAIL;
+		goto cleanup_aoc_test;
+	}
+
+	//TODO add encode and decode test here
+
+	/* cleanup decoded msg */
+	decoded = ast_aoc_destroy_decoded(decoded);
+
+cleanup_aoc_test:
+
+	decoded = ast_aoc_destroy_decoded(decoded);
 	return res;
 }
 




More information about the svn-commits mailing list