Asterisk - The Open Source Telephony Project  18.5.0
Functions | Variables
test_aoc.c File Reference

Generic AOC encode decode tests. More...

#include "asterisk.h"
#include "asterisk/utils.h"
#include "asterisk/module.h"
#include "asterisk/test.h"
#include "asterisk/aoc.h"
Include dependency graph for test_aoc.c:

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
 AST_TEST_DEFINE (aoc_event_generation_test)
 
 AST_TEST_DEFINE (aoc_encode_decode_test)
 
static int load_module (void)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "AOC unit tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 

Detailed Description

Generic AOC encode decode tests.

Author
David Vossel dvoss.nosp@m.el@d.nosp@m.igium.nosp@m..com

Definition in file test_aoc.c.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 689 of file test_aoc.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 689 of file test_aoc.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 689 of file test_aoc.c.

◆ AST_TEST_DEFINE() [1/2]

AST_TEST_DEFINE ( aoc_event_generation_test  )

Definition at line 41 of file test_aoc.c.

References ast_aoc_add_unit_entry(), AST_AOC_BILLING_CREDIT_CARD, AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_UNIT, AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION, AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, AST_AOC_CHARGED_ITEM_USER_USER_INFO, ast_aoc_create(), AST_AOC_D, ast_aoc_decoded2str(), ast_aoc_destroy_decoded(), AST_AOC_E, AST_AOC_MULT_ONE, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETHOUSANDTH, AST_AOC_MULT_TEN, AST_AOC_MULT_THOUSAND, AST_AOC_S, ast_aoc_s_add_rate_duration(), ast_aoc_s_add_rate_flat(), ast_aoc_s_add_rate_volume(), ast_aoc_set_association_id(), ast_aoc_set_association_number(), ast_aoc_set_billing_id(), ast_aoc_set_currency_info(), ast_aoc_set_total_type(), AST_AOC_SUBTOTAL, AST_AOC_TIME_SCALE_DAY, AST_AOC_TIME_SCALE_HOUR, AST_AOC_TIME_SCALE_SECOND, AST_AOC_TIME_SCALE_TENTH_SECOND, AST_AOC_VOLUME_UNIT_SEGMENT, ast_free, ast_str_buffer(), ast_str_create, ast_str_reset(), AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, sip_to_pjsip::info(), NULL, TEST_EXECUTE, and TEST_INIT.

42 {
43  int res = AST_TEST_PASS;
44  struct ast_aoc_decoded *decoded = NULL;
45  struct ast_str *msg = NULL;
46 
47  switch (cmd) {
48  case TEST_INIT:
49  info->name = "aoc_event_test";
50  info->category = "/main/aoc/";
51  info->summary = "Advice of Charge event generation test";
52  info->description =
53  "Creates AOC messages, verify event string matches expected results";
54  return AST_TEST_NOT_RUN;
55  case TEST_EXECUTE:
56  break;
57  }
58 
59  if (!(msg = ast_str_create(1024))) {
60  goto cleanup_aoc_event_test;
61  }
62 
63  /* ---- TEST 1, AOC-D event generation */
64  if (!(decoded = ast_aoc_create(AST_AOC_D, AST_AOC_CHARGE_CURRENCY, 0))) {
65 
66  ast_test_status_update(test, "failed to create AOC-D message for event generation.\n");
67  res = AST_TEST_FAIL;
68  goto cleanup_aoc_event_test;
69  }
70  /* Add billing id information */
72 
73  /* Set currency information, verify results */
74  if ((ast_aoc_set_currency_info(decoded, 100, AST_AOC_MULT_ONE, "usd")) ||
76 
77  ast_test_status_update(test, "failed to set currency info in AOC-D msg\n");
78  res = AST_TEST_FAIL;
79  goto cleanup_aoc_event_test;
80  }
81  if (ast_aoc_decoded2str(decoded, &msg)) {
82 
83  ast_test_status_update(test, "failed to generate AOC-D msg string.\n");
84  res = AST_TEST_FAIL;
85  goto cleanup_aoc_event_test;
86  }
87  if (strncmp(ast_str_buffer(msg),
88  "AOC-D\r\n"
89  "Type: Currency\r\n"
90  "BillingID: CreditCard\r\n"
91  "TypeOfCharging: SubTotal\r\n"
92  "Currency: usd\r\n"
93  "Currency/Amount/Cost: 100\r\n"
94  "Currency/Amount/Multiplier: 1\r\n",
95  strlen(ast_str_buffer(msg)))) {
96 
97  ast_test_status_update(test, "AOC-D msg event did not match expected results\n");
98  res = AST_TEST_FAIL;
99  goto cleanup_aoc_event_test;
100  }
101  decoded = ast_aoc_destroy_decoded(decoded);
102  ast_str_reset(msg);
103 
104 
105  /* ---- TEST 2, AOC-S event generation */
106  if (!(decoded = ast_aoc_create(AST_AOC_S, 0, 0))) {
107  ast_test_status_update(test, "failed to create AOC-S message for event generation.\n");
108 
109  res = AST_TEST_FAIL;
110  goto cleanup_aoc_event_test;
111  }
112 
113  ast_aoc_s_add_rate_flat(decoded,
115  123,
117  "pineapple");
118 
122  937,
124  "oranges");
125 
128  937,
130  "bananas",
131  848,
133  949,
135  1);
136 
139  937,
141  "bananas",
142  1111,
144  2222,
146  0);
147 
148  if (ast_aoc_decoded2str(decoded, &msg)) {
149 
150  ast_test_status_update(test, "failed to generate AOC-D msg string.\n");
151  res = AST_TEST_FAIL;
152  goto cleanup_aoc_event_test;
153  }
154 
155 
156  if (strncmp(ast_str_buffer(msg),
157  "AOC-S\r\n"
158  "NumberRates: 4\r\n"
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",
190  strlen(ast_str_buffer(msg)))) {
191 
192  ast_test_status_update(test, "AOC-S msg event did not match expected results\n");
193  res = AST_TEST_FAIL;
194  goto cleanup_aoc_event_test;
195  }
196  decoded = ast_aoc_destroy_decoded(decoded);
197  ast_str_reset(msg);
198 
199  /* ---- TEST 3, AOC-E event generation with various charging association information*/
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");
202 
203  res = AST_TEST_FAIL;
204  goto cleanup_aoc_event_test;
205  }
206  if ((ast_aoc_add_unit_entry(decoded, 1, 111, 1, 1)) ||
207  (!ast_aoc_add_unit_entry(decoded, 0, 2222, 0, 2)) || /* we expect this to fail, and it should not be added to entry list */
208  (ast_aoc_add_unit_entry(decoded, 1, 3333, 0, 3)) ||
209  (ast_aoc_add_unit_entry(decoded, 0, 44444, 1, 4))) {
210 
211  ast_test_status_update(test, "failed to set unit info for AOC-E message\n");
212  res = AST_TEST_FAIL;
213  goto cleanup_aoc_event_test;
214  }
215 
216  if (ast_aoc_decoded2str(decoded, &msg)) {
217  ast_test_status_update(test, "failed to generate AOC-E msg string.\n");
218  res = AST_TEST_FAIL;
219  goto cleanup_aoc_event_test;
220  }
221 
222  if (strncmp(ast_str_buffer(msg),
223  "AOC-E\r\n"
224  "Type: Units\r\n"
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",
231  strlen(ast_str_buffer(msg)))) {
232 
233  ast_test_status_update(test, "AOC-E msg event did not match expected results, with no charging association info\n");
234  res = AST_TEST_FAIL;
235  goto cleanup_aoc_event_test;
236  }
237 
238  /* add AOC-E charging association number info */
239  if (ast_aoc_set_association_number(decoded, "555-555-5555", 16)) {
240  ast_test_status_update(test, "failed to set the charging association number info correctly, 3\n");
241  res = AST_TEST_FAIL;
242  goto cleanup_aoc_event_test;
243  }
244 
245  ast_str_reset(msg);
246  if (ast_aoc_decoded2str(decoded, &msg)) {
247  ast_test_status_update(test, "failed to generate AOC-E msg string.\n");
248  res = AST_TEST_FAIL;
249  goto cleanup_aoc_event_test;
250  }
251 
252  if (strncmp(ast_str_buffer(msg),
253  "AOC-E\r\n"
254  "ChargingAssociation/Number: 555-555-5555\r\n"
255  "ChargingAssociation/Number/Plan: 16\r\n"
256  "Type: Units\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",
263  strlen(ast_str_buffer(msg)))) {
264 
265  ast_test_status_update(test, "AOC-E msg event did not match expected results, with charging association number\n");
266  res = AST_TEST_FAIL;
267  goto cleanup_aoc_event_test;
268  }
269 
270  /* add AOC-E charging association id info */
271  if (ast_aoc_set_association_id(decoded, 2222)) {
272  ast_test_status_update(test, "failed to set the charging association number info correctly, 3\n");
273  res = AST_TEST_FAIL;
274  goto cleanup_aoc_event_test;
275  }
276 
277  ast_str_reset(msg);
278  if (ast_aoc_decoded2str(decoded, &msg)) {
279  ast_test_status_update(test, "failed to generate AOC-E msg string.\n");
280  res = AST_TEST_FAIL;
281  goto cleanup_aoc_event_test;
282  }
283 
284  if (strncmp(ast_str_buffer(msg),
285  "AOC-E\r\n"
286  "ChargingAssociation/ID: 2222\r\n"
287  "Type: Units\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",
294  strlen(ast_str_buffer(msg)))) {
295 
296  ast_test_status_update(test, "AOC-E msg event did not match expected results with charging association id.\n");
297  res = AST_TEST_FAIL;
298  goto cleanup_aoc_event_test;
299  }
300 
301 
302 cleanup_aoc_event_test:
303 
304  decoded = ast_aoc_destroy_decoded(decoded);
305  ast_free(msg);
306  return res;
307 }
int ast_aoc_decoded2str(const struct ast_aoc_decoded *decoded, struct ast_str **msg)
Convert decoded aoc msg to string representation.
Definition: aoc.c:1960
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.
Definition: aoc.c:770
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.
Definition: aoc.c:977
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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.
Definition: aoc.c:801
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:307
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.
Definition: aoc.c:822
#define NULL
Definition: resample.c:96
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
set the charging accociation number for an AOC-E message
Definition: aoc.c:1056
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
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
Definition: aoc.c:1024
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
def info(msg)
#define ast_free(a)
Definition: astmm.h:182
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.
Definition: aoc.c:907
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
Definition: aoc.c:276
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:653
Definition: aoc.h:64
Definition: aoc.h:66
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
Definition: aoc.c:1040
Definition: aoc.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:620
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.
Definition: aoc.c:919

◆ AST_TEST_DEFINE() [2/2]

AST_TEST_DEFINE ( aoc_encode_decode_test  )

Definition at line 309 of file test_aoc.c.

References ast_aoc_unit_entry::amount, ARRAY_LEN, ast_aoc_add_unit_entry(), AST_AOC_BILLING_CALL_DEFLECTION, AST_AOC_BILLING_CALL_FWD_BUSY, AST_AOC_BILLING_CALL_FWD_NO_REPLY, AST_AOC_BILLING_CALL_FWD_UNCONDITIONAL, AST_AOC_BILLING_CALL_TRANSFER, AST_AOC_BILLING_CREDIT_CARD, AST_AOC_BILLING_NA, AST_AOC_BILLING_NORMAL, AST_AOC_BILLING_REVERSE_CHARGE, AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_NA, AST_AOC_CHARGE_UNIT, AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, AST_AOC_CHARGED_ITEM_CALL_SETUP, AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT, AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE, AST_AOC_CHARGING_ASSOCIATION_ID, AST_AOC_CHARGING_ASSOCIATION_NUMBER, ast_aoc_create(), AST_AOC_D, ast_aoc_destroy_decoded(), AST_AOC_E, ast_aoc_get_association_info(), ast_aoc_get_billing_id(), ast_aoc_get_charge_type(), ast_aoc_get_currency_amount(), ast_aoc_get_currency_multiplier(), ast_aoc_get_currency_name(), ast_aoc_get_msg_type(), ast_aoc_get_request(), ast_aoc_get_termination_request(), ast_aoc_get_total_type(), ast_aoc_get_unit_count(), ast_aoc_get_unit_info(), AST_AOC_MULT_ONE, AST_AOC_MULT_ONEHUNDREDTH, AST_AOC_MULT_ONETHOUSANDTH, AST_AOC_MULT_THOUSAND, AST_AOC_REQUEST, AST_AOC_REQUEST_D, AST_AOC_REQUEST_E, AST_AOC_REQUEST_S, AST_AOC_S, ast_aoc_s_add_rate_duration(), ast_aoc_s_add_rate_flat(), ast_aoc_s_add_rate_free(), ast_aoc_s_add_rate_na(), ast_aoc_s_add_rate_volume(), ast_aoc_set_association_id(), ast_aoc_set_association_number(), ast_aoc_set_billing_id(), ast_aoc_set_currency_info(), ast_aoc_set_termination_request(), ast_aoc_set_total_type(), AST_AOC_SUBTOTAL, ast_aoc_test_encode_decode_match(), AST_AOC_TIME_SCALE_DAY, AST_AOC_TIME_SCALE_HUNDREDTH_SECOND, AST_AOC_TIME_SCALE_SECOND, AST_AOC_VOLUME_UNIT_SEGMENT, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_aoc_charging_association::charge, ast_aoc_charging_association::charging_type, ast_aoc_charging_association::id, sip_to_pjsip::info(), ast_aoc_charging_association_number::number, ast_aoc_charging_association::number, ast_aoc_charging_association_number::plan, request(), TEST_EXECUTE, TEST_INIT, ast_aoc_unit_entry::type, ast_aoc_unit_entry::valid_amount, and ast_aoc_unit_entry::valid_type.

310 {
311  int res = AST_TEST_PASS;
312  struct ast_aoc_decoded *decoded;
313 
314  switch (cmd) {
315  case TEST_INIT:
316  info->name = "aoc_encode_decode_test";
317  info->category = "/main/aoc/";
318  info->summary = "Advice of Charge encode and decode test";
319  info->description =
320  "This tests the Advice of Charge encode and decode routines.";
321  return AST_TEST_NOT_RUN;
322  case TEST_EXECUTE:
323  break;
324  }
325 
326  /* ---- Test 1 ---- create AOC-D message, encode message, and decode message once again. */
327  /* create AOC-D message */
328  if (!(decoded = ast_aoc_create(AST_AOC_D, AST_AOC_CHARGE_CURRENCY, 0)) ||
329  (ast_aoc_get_msg_type(decoded) != AST_AOC_D) ||
331 
332  ast_test_status_update(test, "Test 1: failed to create AOC-D message\n");
333  res = AST_TEST_FAIL;
334  goto cleanup_aoc_test;
335  }
336 
337  /* Add billing id information */
340 
341  ast_test_status_update(test, "TEST 1, could not set billing id correctly\n");
342  res = AST_TEST_FAIL;
343  goto cleanup_aoc_test;
344 
345  }
346 
347  /* Set currency information, verify results*/
348  if ((ast_aoc_set_currency_info(decoded, 100, AST_AOC_MULT_ONE, "usd")) ||
351  (ast_aoc_get_currency_amount(decoded) != 100) ||
353  (strcmp(ast_aoc_get_currency_name(decoded), "usd"))) {
354 
355  ast_test_status_update(test, "Test 1: failed to set currency info\n");
356  res = AST_TEST_FAIL;
357  goto cleanup_aoc_test;
358  }
359 
360  /* Set a currency name larger than 10 characters which is the maximum
361  * length allowed by the ETSI aoc standard. The name is expected to truncate
362  * to 10 characters. */
363  if ((ast_aoc_set_currency_info(decoded, 100, AST_AOC_MULT_ONE, "12345678901234567890")) ||
364  (ast_aoc_get_currency_amount(decoded) != 100) ||
366  (strcmp(ast_aoc_get_currency_name(decoded), "1234567890"))) {
367 
368  ast_test_status_update(test, "Test 1: failed to set currency info currency name exceeding limit\n");
369  res = AST_TEST_FAIL;
370  goto cleanup_aoc_test;
371  }
372 
373  /* Encode the message */
374  if (ast_aoc_test_encode_decode_match(decoded)) {
375  ast_test_status_update(test, "Test1: encode decode routine did not match expected results \n");
376  res = AST_TEST_FAIL;
377  goto cleanup_aoc_test;
378  }
379  /* cleanup decoded msg */
380  decoded = ast_aoc_destroy_decoded(decoded);
381 
382  /* ---- Test 2 ---- create AOC-E message with charge type == unit */
383  /* create AOC-E message */
384  if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_UNIT, 0)) ||
385  (ast_aoc_get_msg_type(decoded) != AST_AOC_E) ||
387 
388  ast_test_status_update(test, "Test 2: failed to create AOC-E message\n");
389  res = AST_TEST_FAIL;
390  goto cleanup_aoc_test;
391  }
392 
393  /* Set unit information, verify results*/
394  if ((ast_aoc_add_unit_entry(decoded, 1, 1, 1, 2)) ||
395  (!ast_aoc_add_unit_entry(decoded, 0, 123, 0, 123)) || /* this entry should fail since either number nor type are present */
396  (ast_aoc_add_unit_entry(decoded, 0, 2, 1, 3)) ||
397  (ast_aoc_add_unit_entry(decoded, 1, 3, 0, 4))) {
398 
399  ast_test_status_update(test, "Test 2: failed to set unit info\n");
400  res = AST_TEST_FAIL;
401  goto cleanup_aoc_test;
402  }
403 
404  /* verify unit list is correct */
405  if (ast_aoc_get_unit_count(decoded) == 3) {
406  int i;
407  const struct ast_aoc_unit_entry *unit;
408  for (i = 0; i < 3; i++) {
409  if (!(unit = ast_aoc_get_unit_info(decoded, 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",
413  unit->amount,
414  unit->type,
415  i+1,
416  i+2);
417  res = AST_TEST_FAIL;
418  goto cleanup_aoc_test;
419  }
420  }
421  } else {
422  ast_test_status_update(test, "TEST 2, invalid unit list entry count \n");
423  res = AST_TEST_FAIL;
424  goto cleanup_aoc_test;
425  }
426 
427 
428  /* Test charging association information */
429  {
430  const struct ast_aoc_charging_association *ca;
431  if ((ast_aoc_set_association_id(decoded, 1234)) ||
432  (!(ca = ast_aoc_get_association_info(decoded)))) {
433  ast_test_status_update(test, "TEST 2, could not set charging association id info correctly\n");
434  res = AST_TEST_FAIL;
435  goto cleanup_aoc_test;
436  }
437 
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");
440  }
441 
442  if ((ast_aoc_set_association_number(decoded, "1234", 16)) ||
443  (!(ca = ast_aoc_get_association_info(decoded)))) {
444  ast_test_status_update(test, "TEST 2, could not set charging association number info correctly, 3\n");
445  res = AST_TEST_FAIL;
446  goto cleanup_aoc_test;
447  }
448 
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");
453  }
454  }
455 
456  /* Test every billing id possiblity */
457  {
458  int billid[9] = {
468  };
469  int i;
470 
471  /* these should fail */
472  if (!(ast_aoc_set_billing_id(decoded, (AST_AOC_BILLING_NA - 1))) ||
474 
475  ast_test_status_update(test, "TEST 2, setting invalid billing id should fail\n");
476  res = AST_TEST_FAIL;
477  goto cleanup_aoc_test;
478  }
479 
480  for (i = 0; i < ARRAY_LEN(billid); i++) {
481  if ((ast_aoc_set_billing_id(decoded, billid[i]) ||
482  (ast_aoc_get_billing_id(decoded) != billid[i]))) {
483 
484  ast_test_status_update(test, "TEST 2, could not set billing id correctly, iteration #%d\n", i);
485  res = AST_TEST_FAIL;
486  goto cleanup_aoc_test;
487  }
488  }
489  }
490  /* Encode the message */
491  if (ast_aoc_test_encode_decode_match(decoded)) {
492  ast_test_status_update(test, "Test2: encode decode routine did not match expected results \n");
493  res = AST_TEST_FAIL;
494  goto cleanup_aoc_test;
495  }
496  /* cleanup decoded msg */
497  decoded = ast_aoc_destroy_decoded(decoded);
498 
499  /* ---- Test 3 ---- create AOC-Request. test all possible combinations */
500  {
501  int request[7] = { /* all possible request combinations */
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)
509  };
510  int i;
511 
512  for (i = 0; i < ARRAY_LEN(request); i++) {
513  if (!(decoded = ast_aoc_create(AST_AOC_REQUEST, 0, request[i])) ||
514  (ast_aoc_get_msg_type(decoded) != AST_AOC_REQUEST) ||
515  (ast_aoc_get_termination_request(decoded)) ||
516  (ast_aoc_get_request(decoded) != request[i])) {
517 
518  ast_test_status_update(test, "Test 3: failed to create AOC-Request message, iteration #%d\n", i);
519  res = AST_TEST_FAIL;
520  goto cleanup_aoc_test;
521  }
522 
523  /* Encode the message */
524  if (ast_aoc_test_encode_decode_match(decoded)) {
525  ast_test_status_update(test, "Test3: encode decode routine did not match expected results, iteration #%d\n", i);
526  res = AST_TEST_FAIL;
527  goto cleanup_aoc_test;
528  }
529  /* cleanup decoded msg */
530  decoded = ast_aoc_destroy_decoded(decoded);
531  }
532 
533 
534  /* Test termination Request Type */
535  if (!(decoded = ast_aoc_create(AST_AOC_REQUEST, 0, AST_AOC_REQUEST_E)) ||
536  (ast_aoc_set_termination_request(decoded)) ||
537  (!ast_aoc_get_termination_request(decoded)) ||
538  (ast_aoc_get_msg_type(decoded) != AST_AOC_REQUEST) ||
539  (ast_aoc_get_request(decoded) != AST_AOC_REQUEST_E)) {
540 
541  ast_test_status_update(test, "Test 3: failed to create AOC-Request message with Termination Request set\n");
542  res = AST_TEST_FAIL;
543  goto cleanup_aoc_test;
544  }
545 
546  /* Encode the message */
547  if (ast_aoc_test_encode_decode_match(decoded)) {
548  ast_test_status_update(test, "Test3: encode decode routine did not match expected results with termination request set\n");
549  res = AST_TEST_FAIL;
550  goto cleanup_aoc_test;
551  }
552  /* cleanup decoded msg */
553  decoded = ast_aoc_destroy_decoded(decoded);
554  }
555 
556  /* ---- Test 4 ---- Make stuff blow up */
557  if ((decoded = ast_aoc_create(AST_AOC_D, 1234567, 0))) {
558 
559  ast_test_status_update(test, "Test 4: aoc-d creation with no valid charge type should fail\n");
560  res = AST_TEST_FAIL;
561  goto cleanup_aoc_test;
562  }
563  if ((decoded = ast_aoc_create(AST_AOC_REQUEST, 0, 0))) {
564 
565  ast_test_status_update(test, "Test 4: aoc request creation with no data should have failed\n");
566  res = AST_TEST_FAIL;
567  goto cleanup_aoc_test;
568  }
569  if ((decoded = ast_aoc_create(AST_AOC_REQUEST, -12345678, -23456789))) {
570 
571  ast_test_status_update(test, "Test 4: aoc request creation with random data should have failed\n");
572  res = AST_TEST_FAIL;
573  goto cleanup_aoc_test;
574  }
575 
576  /* ---- Test 5 ---- create AOC-E message with charge type == FREE and charge type == NA */
577  /* create AOC-E message */
578  if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_FREE, 0)) ||
579  (ast_aoc_get_msg_type(decoded) != AST_AOC_E) ||
581 
582  ast_test_status_update(test, "Test 5: failed to create AOC-E message, charge type Free\n");
583  res = AST_TEST_FAIL;
584  goto cleanup_aoc_test;
585  }
586  if (ast_aoc_test_encode_decode_match(decoded)) {
587  ast_test_status_update(test, "Test5: encode decode routine did not match expected results, charge type Free\n");
588  res = AST_TEST_FAIL;
589  goto cleanup_aoc_test;
590  }
591  /* cleanup decoded msg */
592  decoded = ast_aoc_destroy_decoded(decoded);
593 
594  /* create AOC-E message */
595  if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_NA, 0)) ||
596  (ast_aoc_get_msg_type(decoded) != AST_AOC_E) ||
598 
599  ast_test_status_update(test, "Test 5: failed to create AOC-E message, charge type NA\n");
600  res = AST_TEST_FAIL;
601  goto cleanup_aoc_test;
602  }
603  if (ast_aoc_test_encode_decode_match(decoded)) {
604  ast_test_status_update(test, "Test5: encode decode routine did not match expected results, charge type NA.\n");
605  res = AST_TEST_FAIL;
606  goto cleanup_aoc_test;
607  }
608  /* cleanup decoded msg */
609  decoded = ast_aoc_destroy_decoded(decoded);
610 
611 
612 /* ---- TEST 6, AOC-S encode decode */
613  if (!(decoded = ast_aoc_create(AST_AOC_S, 0, 0))) {
614  ast_test_status_update(test, "failed to create AOC-S message for encode decode testing.\n");
615 
616  res = AST_TEST_FAIL;
617  goto cleanup_aoc_test;
618  }
619 
622  937,
624  "jkasdf",
625  235328,
627  905423,
629  1);
630 
631  ast_aoc_s_add_rate_flat(decoded,
633  1337,
635  "MONEYS");
636 
640  5555,
642  "pounds");
643 
646  78923,
648  "SNAP",
649  9354,
651  234933,
653  0);
654 
658 
659  if (ast_aoc_test_encode_decode_match(decoded)) {
660  ast_test_status_update(test, "Test6: encode decode routine for AOC-S did not match expected results\n");
661  res = AST_TEST_FAIL;
662  goto cleanup_aoc_test;
663  }
664  /* cleanup decoded msg */
665  decoded = ast_aoc_destroy_decoded(decoded);
666 
667 
668 
669 cleanup_aoc_test:
670 
671  decoded = ast_aoc_destroy_decoded(decoded);
672  return res;
673 }
char valid_amount
Definition: aoc.h:179
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.
Definition: aoc.c:770
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int ast_aoc_set_termination_request(struct ast_aoc_decoded *decoded)
Mark the AST_AOC_REQUEST message as a termination request.
Definition: aoc.c:1069
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.
Definition: aoc.c:977
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
Definition: aoc.c:902
union ast_aoc_charging_association::@221 charge
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.
Definition: aoc.c:801
unsigned int type
Definition: aoc.h:182
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
Definition: aoc.c:914
struct ast_aoc_charging_association_number number
Definition: aoc.h:197
void * ast_aoc_destroy_decoded(struct ast_aoc_decoded *decoded)
free an ast_aoc_decoded object
Definition: aoc.c:307
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.
Definition: aoc.c:822
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.
Definition: aoc.c:857
int ast_aoc_set_association_number(struct ast_aoc_decoded *decoded, const char *num, uint8_t plan)
set the charging accociation number for an AOC-E message
Definition: aoc.c:1056
#define ast_test_status_update(a, b, c...)
Definition: test.h:129
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.
Definition: aoc.c:869
unsigned int ast_aoc_get_currency_amount(struct ast_aoc_decoded *decoded)
get the currency amount for AOC-D and AOC-E messages
Definition: aoc.c:940
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
Definition: aoc.c:1024
int ast_aoc_test_encode_decode_match(struct ast_aoc_decoded *decoded)
test aoc encode decode routines.
Definition: aoc.c:1330
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.
Definition: aoc.c:1010
def info(msg)
int ast_aoc_get_termination_request(struct ast_aoc_decoded *decoded)
get whether or not the AST_AOC_REQUEST message as a termination request.
Definition: aoc.c:1079
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
Definition: aoc.c:1035
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.
Definition: aoc.c:907
const char * ast_aoc_get_currency_name(struct ast_aoc_decoded *decoded)
get the currency name for AOC-D and AOC-E messages
Definition: aoc.c:972
static int request(void *obj)
Definition: chan_pjsip.c:2559
char valid_type
Definition: aoc.h:181
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
Definition: aoc.c:276
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
Definition: aoc.c:897
Definition: aoc.h:64
Definition: aoc.h:66
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
Definition: aoc.c:1040
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
Definition: aoc.c:892
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
Definition: aoc.c:945
Definition: aoc.h:178
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
Definition: aoc.c:1019
unsigned int amount
Definition: aoc.h:180
Definition: aoc.h:65
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.
Definition: aoc.c:919
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
Definition: aoc.c:1051

◆ load_module()

static int load_module ( void  )
static

Definition at line 682 of file test_aoc.c.

References AST_MODULE_LOAD_SUCCESS, and AST_TEST_REGISTER.

683 {
684  AST_TEST_REGISTER(aoc_encode_decode_test);
685  AST_TEST_REGISTER(aoc_event_generation_test);
687 }
#define AST_TEST_REGISTER(cb)
Definition: test.h:127

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 675 of file test_aoc.c.

References AST_TEST_UNREGISTER.

676 {
677  AST_TEST_UNREGISTER(aoc_encode_decode_test);
678  AST_TEST_UNREGISTER(aoc_event_generation_test);
679  return 0;
680 }
#define AST_TEST_UNREGISTER(cb)
Definition: test.h:128

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "AOC unit tests" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 689 of file test_aoc.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 689 of file test_aoc.c.