43 int res = AST_TEST_PASS;
49 info->name =
"aoc_event_test";
50 info->category =
"/main/aoc/";
51 info->summary =
"Advice of Charge event generation test";
53 "Creates AOC messages, verify event string matches expected results";
54 return AST_TEST_NOT_RUN;
60 goto cleanup_aoc_event_test;
64 if (!(decoded =
ast_aoc_create(AST_AOC_D, AST_AOC_CHARGE_CURRENCY, 0))) {
66 ast_test_status_update(
test,
"failed to create AOC-D message for event generation.\n");
68 goto cleanup_aoc_event_test;
77 ast_test_status_update(
test,
"failed to set currency info in AOC-D msg\n");
79 goto cleanup_aoc_event_test;
83 ast_test_status_update(
test,
"failed to generate AOC-D msg string.\n");
85 goto cleanup_aoc_event_test;
90 "BillingID: CreditCard\r\n"
91 "TypeOfCharging: SubTotal\r\n"
93 "Currency/Amount/Cost: 100\r\n"
94 "Currency/Amount/Multiplier: 1\r\n",
97 ast_test_status_update(
test,
"AOC-D msg event did not match expected results\n");
99 goto cleanup_aoc_event_test;
107 ast_test_status_update(
test,
"failed to create AOC-S message for event generation.\n");
110 goto cleanup_aoc_event_test;
114 AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION,
120 AST_AOC_CHARGED_ITEM_CALL_ATTEMPT,
121 AST_AOC_VOLUME_UNIT_SEGMENT,
123 AST_AOC_MULT_ONEHUNDREDTH,
127 AST_AOC_CHARGED_ITEM_CALL_ATTEMPT,
129 AST_AOC_MULT_ONETHOUSANDTH,
132 AST_AOC_TIME_SCALE_TENTH_SECOND,
134 AST_AOC_TIME_SCALE_HOUR,
138 AST_AOC_CHARGED_ITEM_USER_USER_INFO,
140 AST_AOC_MULT_THOUSAND,
143 AST_AOC_TIME_SCALE_SECOND,
145 AST_AOC_TIME_SCALE_DAY,
150 ast_test_status_update(
test,
"failed to generate AOC-D msg string.\n");
152 goto cleanup_aoc_event_test;
159 "Rate(0)/Chargeable: BasicCommunication\r\n"
160 "Rate(0)/Type: Flat\r\n"
161 "Rate(0)/Flat/Currency: pineapple\r\n"
162 "Rate(0)/Flat/Amount/Cost: 123\r\n"
163 "Rate(0)/Flat/Amount/Multiplier: 10\r\n"
164 "Rate(1)/Chargeable: CallAttempt\r\n"
165 "Rate(1)/Type: Volume\r\n"
166 "Rate(1)/Volume/Currency: oranges\r\n"
167 "Rate(1)/Volume/Amount/Cost: 937\r\n"
168 "Rate(1)/Volume/Amount/Multiplier: 1/100\r\n"
169 "Rate(1)/Volume/Unit: Segment\r\n"
170 "Rate(2)/Chargeable: CallAttempt\r\n"
171 "Rate(2)/Type: Duration\r\n"
172 "Rate(2)/Duration/Currency: bananas\r\n"
173 "Rate(2)/Duration/Amount/Cost: 937\r\n"
174 "Rate(2)/Duration/Amount/Multiplier: 1/1000\r\n"
175 "Rate(2)/Duration/ChargingType: StepFunction\r\n"
176 "Rate(2)/Duration/Time/Length: 848\r\n"
177 "Rate(2)/Duration/Time/Scale: OneTenthSecond\r\n"
178 "Rate(2)/Duration/Granularity/Length: 949\r\n"
179 "Rate(2)/Duration/Granularity/Scale: Hour\r\n"
180 "Rate(3)/Chargeable: UserUserInfo\r\n"
181 "Rate(3)/Type: Duration\r\n"
182 "Rate(3)/Duration/Currency: bananas\r\n"
183 "Rate(3)/Duration/Amount/Cost: 937\r\n"
184 "Rate(3)/Duration/Amount/Multiplier: 1000\r\n"
185 "Rate(3)/Duration/ChargingType: ContinuousCharging\r\n"
186 "Rate(3)/Duration/Time/Length: 1111\r\n"
187 "Rate(3)/Duration/Time/Scale: Second\r\n"
188 "Rate(3)/Duration/Granularity/Length: 2222\r\n"
189 "Rate(3)/Duration/Granularity/Scale: Day\r\n",
192 ast_test_status_update(
test,
"AOC-S msg event did not match expected results\n");
194 goto cleanup_aoc_event_test;
200 if (!(decoded =
ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_UNIT, 0))) {
201 ast_test_status_update(
test,
"failed to create AOC-E message for event generation.\n");
204 goto cleanup_aoc_event_test;
211 ast_test_status_update(
test,
"failed to set unit info for AOC-E message\n");
213 goto cleanup_aoc_event_test;
217 ast_test_status_update(
test,
"failed to generate AOC-E msg string.\n");
219 goto cleanup_aoc_event_test;
225 "BillingID: NotAvailable\r\n"
226 "Units/NumberItems: 3\r\n"
227 "Units/Item(0)/NumberOf: 111\r\n"
228 "Units/Item(0)/TypeOf: 1\r\n"
229 "Units/Item(1)/NumberOf: 3333\r\n"
230 "Units/Item(2)/TypeOf: 4\r\n",
233 ast_test_status_update(
test,
"AOC-E msg event did not match expected results, with no charging association info\n");
235 goto cleanup_aoc_event_test;
240 ast_test_status_update(
test,
"failed to set the charging association number info correctly, 3\n");
242 goto cleanup_aoc_event_test;
247 ast_test_status_update(
test,
"failed to generate AOC-E msg string.\n");
249 goto cleanup_aoc_event_test;
254 "ChargingAssociation/Number: 555-555-5555\r\n"
255 "ChargingAssociation/Number/Plan: 16\r\n"
257 "BillingID: NotAvailable\r\n"
258 "Units/NumberItems: 3\r\n"
259 "Units/Item(0)/NumberOf: 111\r\n"
260 "Units/Item(0)/TypeOf: 1\r\n"
261 "Units/Item(1)/NumberOf: 3333\r\n"
262 "Units/Item(2)/TypeOf: 4\r\n",
265 ast_test_status_update(
test,
"AOC-E msg event did not match expected results, with charging association number\n");
267 goto cleanup_aoc_event_test;
272 ast_test_status_update(
test,
"failed to set the charging association number info correctly, 3\n");
274 goto cleanup_aoc_event_test;
279 ast_test_status_update(
test,
"failed to generate AOC-E msg string.\n");
281 goto cleanup_aoc_event_test;
286 "ChargingAssociation/ID: 2222\r\n"
288 "BillingID: NotAvailable\r\n"
289 "Units/NumberItems: 3\r\n"
290 "Units/Item(0)/NumberOf: 111\r\n"
291 "Units/Item(0)/TypeOf: 1\r\n"
292 "Units/Item(1)/NumberOf: 3333\r\n"
293 "Units/Item(2)/TypeOf: 4\r\n",
296 ast_test_status_update(
test,
"AOC-E msg event did not match expected results with charging association id.\n");
298 goto cleanup_aoc_event_test;
302 cleanup_aoc_event_test:
311 int res = AST_TEST_PASS;
316 info->name =
"aoc_encode_decode_test";
317 info->category =
"/main/aoc/";
318 info->summary =
"Advice of Charge encode and decode test";
320 "This tests the Advice of Charge encode and decode routines.";
321 return AST_TEST_NOT_RUN;
328 if (!(decoded =
ast_aoc_create(AST_AOC_D, AST_AOC_CHARGE_CURRENCY, 0)) ||
332 ast_test_status_update(
test,
"Test 1: failed to create AOC-D message\n");
334 goto cleanup_aoc_test;
341 ast_test_status_update(
test,
"TEST 1, could not set billing id correctly\n");
343 goto cleanup_aoc_test;
355 ast_test_status_update(
test,
"Test 1: failed to set currency info\n");
357 goto cleanup_aoc_test;
368 ast_test_status_update(
test,
"Test 1: failed to set currency info currency name exceeding limit\n");
370 goto cleanup_aoc_test;
375 ast_test_status_update(
test,
"Test1: encode decode routine did not match expected results \n");
377 goto cleanup_aoc_test;
384 if (!(decoded =
ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_UNIT, 0)) ||
388 ast_test_status_update(
test,
"Test 2: failed to create AOC-E message\n");
390 goto cleanup_aoc_test;
399 ast_test_status_update(
test,
"Test 2: failed to set unit info\n");
401 goto cleanup_aoc_test;
408 for (i = 0; i < 3; i++) {
410 ((unit->valid_amount) && (unit->amount != (i+1))) ||
411 ((unit->valid_type) && (unit->type != (i+2)))) {
412 ast_test_status_update(
test,
"TEST 2, invalid unit entry result, got %u,%u, expected %d,%d\n",
418 goto cleanup_aoc_test;
422 ast_test_status_update(
test,
"TEST 2, invalid unit list entry count \n");
424 goto cleanup_aoc_test;
433 ast_test_status_update(
test,
"TEST 2, could not set charging association id info correctly\n");
435 goto cleanup_aoc_test;
438 if ((ca->
charging_type != AST_AOC_CHARGING_ASSOCIATION_ID) || (ca->charge.id != 1234)) {
439 ast_test_status_update(
test,
"TEST 2, could not get charging association id info correctly, 2\n");
444 ast_test_status_update(
test,
"TEST 2, could not set charging association number info correctly, 3\n");
446 goto cleanup_aoc_test;
449 if ((ca->
charging_type != AST_AOC_CHARGING_ASSOCIATION_NUMBER) ||
450 (ca->charge.number.plan != 16) ||
451 (strcmp(ca->charge.number.number,
"1234"))) {
452 ast_test_status_update(
test,
"TEST 2, could not get charging association number info correctly\n");
460 AST_AOC_BILLING_NORMAL,
461 AST_AOC_BILLING_REVERSE_CHARGE,
462 AST_AOC_BILLING_CREDIT_CARD,
463 AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL,
464 AST_AOC_BILLING_CALL_FWD_BUSY,
465 AST_AOC_BILLING_CALL_FWD_NO_REPLY,
466 AST_AOC_BILLING_CALL_DEFLECTION,
467 AST_AOC_BILLING_CALL_TRANSFER,
475 ast_test_status_update(
test,
"TEST 2, setting invalid billing id should fail\n");
477 goto cleanup_aoc_test;
480 for (i = 0; i < ARRAY_LEN(billid); i++) {
484 ast_test_status_update(
test,
"TEST 2, could not set billing id correctly, iteration #%d\n", i);
486 goto cleanup_aoc_test;
492 ast_test_status_update(
test,
"Test2: encode decode routine did not match expected results \n");
494 goto cleanup_aoc_test;
505 (AST_AOC_REQUEST_S | AST_AOC_REQUEST_D),
506 (AST_AOC_REQUEST_S | AST_AOC_REQUEST_E),
507 (AST_AOC_REQUEST_D | AST_AOC_REQUEST_E),
508 (AST_AOC_REQUEST_D | AST_AOC_REQUEST_E | AST_AOC_REQUEST_S)
512 for (i = 0; i < ARRAY_LEN(request); i++) {
513 if (!(decoded =
ast_aoc_create(AST_AOC_REQUEST, 0, request[i])) ||
518 ast_test_status_update(
test,
"Test 3: failed to create AOC-Request message, iteration #%d\n", i);
520 goto cleanup_aoc_test;
525 ast_test_status_update(
test,
"Test3: encode decode routine did not match expected results, iteration #%d\n", i);
527 goto cleanup_aoc_test;
535 if (!(decoded =
ast_aoc_create(AST_AOC_REQUEST, 0, AST_AOC_REQUEST_E)) ||
541 ast_test_status_update(
test,
"Test 3: failed to create AOC-Request message with Termination Request set\n");
543 goto cleanup_aoc_test;
548 ast_test_status_update(
test,
"Test3: encode decode routine did not match expected results with termination request set\n");
550 goto cleanup_aoc_test;
559 ast_test_status_update(
test,
"Test 4: aoc-d creation with no valid charge type should fail\n");
561 goto cleanup_aoc_test;
565 ast_test_status_update(
test,
"Test 4: aoc request creation with no data should have failed\n");
567 goto cleanup_aoc_test;
569 if ((decoded =
ast_aoc_create(AST_AOC_REQUEST, -12345678, -23456789))) {
571 ast_test_status_update(
test,
"Test 4: aoc request creation with random data should have failed\n");
573 goto cleanup_aoc_test;
578 if (!(decoded =
ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_FREE, 0)) ||
582 ast_test_status_update(
test,
"Test 5: failed to create AOC-E message, charge type Free\n");
584 goto cleanup_aoc_test;
587 ast_test_status_update(
test,
"Test5: encode decode routine did not match expected results, charge type Free\n");
589 goto cleanup_aoc_test;
595 if (!(decoded =
ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_NA, 0)) ||
599 ast_test_status_update(
test,
"Test 5: failed to create AOC-E message, charge type NA\n");
601 goto cleanup_aoc_test;
604 ast_test_status_update(
test,
"Test5: encode decode routine did not match expected results, charge type NA.\n");
606 goto cleanup_aoc_test;
614 ast_test_status_update(
test,
"failed to create AOC-S message for encode decode testing.\n");
617 goto cleanup_aoc_test;
621 AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE,
623 AST_AOC_MULT_THOUSAND,
626 AST_AOC_TIME_SCALE_SECOND,
628 AST_AOC_TIME_SCALE_DAY,
632 AST_AOC_CHARGED_ITEM_CALL_SETUP,
634 AST_AOC_MULT_ONEHUNDREDTH,
638 AST_AOC_CHARGED_ITEM_CALL_ATTEMPT,
639 AST_AOC_VOLUME_UNIT_SEGMENT,
641 AST_AOC_MULT_ONEHUNDREDTH,
645 AST_AOC_CHARGED_ITEM_CALL_ATTEMPT,
647 AST_AOC_MULT_ONETHOUSANDTH,
650 AST_AOC_TIME_SCALE_HUNDREDTH_SECOND,
652 AST_AOC_TIME_SCALE_SECOND,
660 ast_test_status_update(
test,
"Test6: encode decode routine for AOC-S did not match expected results\n");
662 goto cleanup_aoc_test;
675 static int unload_module(
void)
677 AST_TEST_UNREGISTER(aoc_encode_decode_test);
678 AST_TEST_UNREGISTER(aoc_event_generation_test);
682 static int load_module(
void)
684 AST_TEST_REGISTER(aoc_encode_decode_test);
685 AST_TEST_REGISTER(aoc_event_generation_test);
int ast_aoc_decoded2str(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Convert decoded aoc msg to string representation.
int ast_aoc_s_add_rate_duration(struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, unsigned int amount, enum ast_aoc_currency_multiplier multiplier, const char *currency_name, unsigned long time, enum ast_aoc_time_scale time_scale, unsigned long granularity_time, enum ast_aoc_time_scale granularity_time_scale, int step_function)
Add AOC-S duration rate entry.
Asterisk main include file. File version handling, generic pbx functions.
int ast_aoc_set_termination_request(struct ast_aoc_decoded *decoded)
Mark the AST_AOC_REQUEST message as a termination request.
int ast_aoc_add_unit_entry(struct ast_aoc_decoded *decoded, const unsigned int amount_is_present, const unsigned int amount, const unsigned int type_is_present, const unsigned int type)
Adds a unit entry into the list of units.
enum ast_aoc_request ast_aoc_get_request(struct ast_aoc_decoded *decoded)
get the types of AOC requested for when message type is AOC Request
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
int ast_aoc_s_add_rate_flat(struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, unsigned int amount, enum ast_aoc_currency_multiplier multiplier, const char *currency_name)
Add AOC-S flat rate entry.
enum ast_aoc_total_type ast_aoc_get_total_type(struct ast_aoc_decoded *decoded)
get the type of total for a AOC-D message
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
int ast_aoc_s_add_rate_volume(struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, enum ast_aoc_volume_unit volume_unit, unsigned int amount, enum ast_aoc_currency_multiplier multiplier, const char *currency_name)
Add AOC-S volume rate entry.
int ast_aoc_s_add_rate_free(struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item, int from_beginning)
Add AOC-S indicating charge item is free.
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
set the charging association number for an AOC-E message
Generic Advice of Charge encode and decode routines.
int ast_aoc_s_add_rate_na(struct ast_aoc_decoded *decoded, enum ast_aoc_s_charged_item charged_item)
Add AOC-S entry indicating charge item is not available.
unsigned int ast_aoc_get_currency_amount(struct ast_aoc_decoded *decoded)
get the currency amount for AOC-D and AOC-E messages
int ast_aoc_set_billing_id(struct ast_aoc_decoded *decoded, const enum ast_aoc_billing_id id)
set the billing id for a AOC-D or AST_AOC_E message
int ast_aoc_test_encode_decode_match(struct ast_aoc_decoded *decoded)
test aoc encode decode routines.
Support for dynamic strings.
const struct ast_aoc_unit_entry * ast_aoc_get_unit_info(struct ast_aoc_decoded *decoded, unsigned int entry_number)
get a specific unit entry.
int ast_aoc_get_termination_request(struct ast_aoc_decoded *decoded)
get whether or not the AST_AOC_REQUEST message as a termination request.
enum ast_aoc_billing_id ast_aoc_get_billing_id(struct ast_aoc_decoded *decoded)
get the billing id for AOC-D and AOC-E messages
int ast_aoc_set_total_type(struct ast_aoc_decoded *decoded, const enum ast_aoc_total_type type)
Sets the type of total for a AOC-D message.
const char * ast_aoc_get_currency_name(struct ast_aoc_decoded *decoded)
get the currency name for AOC-D and AOC-E messages
struct ast_aoc_decoded * ast_aoc_create(const enum ast_aoc_type msg_type, const enum ast_aoc_charge_type charge_type, const enum ast_aoc_request requests)
creates a ast_aoc_decode object of a specific message type
enum ast_aoc_charge_type ast_aoc_get_charge_type(struct ast_aoc_decoded *decoded)
get the charging type for an AOC-D or AOC-E message
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
#define AST_TEST_DEFINE(hdr)
int ast_aoc_set_association_id(struct ast_aoc_decoded *decoded, const int id)
set the charging association id for an AST_AOC_E message
enum ast_aoc_type ast_aoc_get_msg_type(struct ast_aoc_decoded *decoded)
get the message type, AOC-D, AOC-E, or AOC Request
enum ast_aoc_currency_multiplier ast_aoc_get_currency_multiplier(struct ast_aoc_decoded *decoded)
get the currency multiplier for AOC-D and AOC-E messages
unsigned int ast_aoc_get_unit_count(struct ast_aoc_decoded *decoded)
get the number of unit entries for AOC-D and AOC-E messages
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_aoc_set_currency_info(struct ast_aoc_decoded *decoded, const unsigned int amount, const enum ast_aoc_currency_multiplier multiplier, const char *name)
Sets the currency values for a AOC-D or AOC-E message.
const struct ast_aoc_charging_association * ast_aoc_get_association_info(struct ast_aoc_decoded *decoded)
get the charging association info for AOC-E messages