| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include "asterisk.h" |
| 34 |
|
| 35 |
#include "asterisk/utils.h" |
| 36 |
#include "asterisk/module.h" |
| 37 |
#include "asterisk/test.h" |
| 38 |
#include "asterisk/aoc.h" |
| 39 |
|
| 40 |
|
| 41 |
AST_TEST_DEFINE(aoc_event_generation_test) |
| 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 |
|
| 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 |
|
| 71 |
ast_aoc_set_billing_id(decoded, AST_AOC_BILLING_CREDIT_CARD); |
| 72 |
|
| 73 |
|
| 74 |
if ((ast_aoc_set_currency_info(decoded, 100, AST_AOC_MULT_ONE, "usd")) || |
| 75 |
(ast_aoc_set_total_type(decoded, AST_AOC_SUBTOTAL))) { |
| 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 |
|
| 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, |
| 114 |
AST_AOC_CHARGED_ITEM_BASIC_COMMUNICATION, |
| 115 |
123, |
| 116 |
AST_AOC_MULT_TEN, |
| 117 |
"pineapple"); |
| 118 |
|
| 119 |
ast_aoc_s_add_rate_volume(decoded, |
| 120 |
AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, |
| 121 |
AST_AOC_VOLUME_UNIT_SEGMENT, |
| 122 |
937, |
| 123 |
AST_AOC_MULT_ONEHUNDREDTH, |
| 124 |
"oranges"); |
| 125 |
|
| 126 |
ast_aoc_s_add_rate_duration(decoded, |
| 127 |
AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, |
| 128 |
937, |
| 129 |
AST_AOC_MULT_ONETHOUSANDTH, |
| 130 |
"bananas", |
| 131 |
848, |
| 132 |
AST_AOC_TIME_SCALE_TENTH_SECOND, |
| 133 |
949, |
| 134 |
AST_AOC_TIME_SCALE_HOUR, |
| 135 |
1); |
| 136 |
|
| 137 |
ast_aoc_s_add_rate_duration(decoded, |
| 138 |
AST_AOC_CHARGED_ITEM_USER_USER_INFO, |
| 139 |
937, |
| 140 |
AST_AOC_MULT_THOUSAND, |
| 141 |
"bananas", |
| 142 |
1111, |
| 143 |
AST_AOC_TIME_SCALE_SECOND, |
| 144 |
2222, |
| 145 |
AST_AOC_TIME_SCALE_DAY, |
| 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 |
|
| 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)) || |
| 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 |
|
| 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 |
|
| 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 |
} |
| 308 |
|
| 309 |
AST_TEST_DEFINE(aoc_encode_decode_test) |
| 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 |
|
| 327 |
|
| 328 |
if (!(decoded = ast_aoc_create(AST_AOC_D, AST_AOC_CHARGE_CURRENCY, 0)) || |
| 329 |
(ast_aoc_get_msg_type(decoded) != AST_AOC_D) || |
| 330 |
(ast_aoc_get_charge_type(decoded) != AST_AOC_CHARGE_CURRENCY)) { |
| 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 |
|
| 338 |
if ((ast_aoc_set_billing_id(decoded, AST_AOC_BILLING_NORMAL) || |
| 339 |
(ast_aoc_get_billing_id(decoded) != AST_AOC_BILLING_NORMAL))) { |
| 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 |
|
| 348 |
if ((ast_aoc_set_currency_info(decoded, 100, AST_AOC_MULT_ONE, "usd")) || |
| 349 |
(ast_aoc_set_total_type(decoded, AST_AOC_SUBTOTAL)) || |
| 350 |
(ast_aoc_get_total_type(decoded) != AST_AOC_SUBTOTAL) || |
| 351 |
(ast_aoc_get_currency_amount(decoded) != 100) || |
| 352 |
(ast_aoc_get_currency_multiplier(decoded) != AST_AOC_MULT_ONE) || |
| 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 |
|
| 361 |
|
| 362 |
|
| 363 |
if ((ast_aoc_set_currency_info(decoded, 100, AST_AOC_MULT_ONE, "12345678901234567890")) || |
| 364 |
(ast_aoc_get_currency_amount(decoded) != 100) || |
| 365 |
(ast_aoc_get_currency_multiplier(decoded) != AST_AOC_MULT_ONE) || |
| 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 |
|
| 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 |
|
| 380 |
decoded = ast_aoc_destroy_decoded(decoded); |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_UNIT, 0)) || |
| 385 |
(ast_aoc_get_msg_type(decoded) != AST_AOC_E) || |
| 386 |
(ast_aoc_get_charge_type(decoded) != AST_AOC_CHARGE_UNIT)) { |
| 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 |
|
| 394 |
if ((ast_aoc_add_unit_entry(decoded, 1, 1, 1, 2)) || |
| 395 |
(!ast_aoc_add_unit_entry(decoded, 0, 123, 0, 123)) || |
| 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 |
|
| 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 |
|
| 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 |
|
| 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"); |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
|
| 457 |
{ |
| 458 |
int billid[9] = { |
| 459 |
AST_AOC_BILLING_NA, |
| 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, |
| 468 |
}; |
| 469 |
int i; |
| 470 |
|
| 471 |
|
| 472 |
if (!(ast_aoc_set_billing_id(decoded, (AST_AOC_BILLING_NA - 1))) || |
| 473 |
!(ast_aoc_set_billing_id(decoded, (AST_AOC_BILLING_CALL_TRANSFER + 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 |
|
| 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 |
|
| 497 |
decoded = ast_aoc_destroy_decoded(decoded); |
| 498 |
|
| 499 |
|
| 500 |
{ |
| 501 |
int request[7] = { |
| 502 |
AST_AOC_REQUEST_S, |
| 503 |
AST_AOC_REQUEST_D, |
| 504 |
AST_AOC_REQUEST_E, |
| 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) |
| 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 |
|
| 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 |
|
| 530 |
decoded = ast_aoc_destroy_decoded(decoded); |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
|
| 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 |
|
| 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 |
|
| 553 |
decoded = ast_aoc_destroy_decoded(decoded); |
| 554 |
} |
| 555 |
|
| 556 |
|
| 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 |
|
| 577 |
|
| 578 |
if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_FREE, 0)) || |
| 579 |
(ast_aoc_get_msg_type(decoded) != AST_AOC_E) || |
| 580 |
(ast_aoc_get_charge_type(decoded) != AST_AOC_CHARGE_FREE)) { |
| 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 |
|
| 592 |
decoded = ast_aoc_destroy_decoded(decoded); |
| 593 |
|
| 594 |
|
| 595 |
if (!(decoded = ast_aoc_create(AST_AOC_E, AST_AOC_CHARGE_NA, 0)) || |
| 596 |
(ast_aoc_get_msg_type(decoded) != AST_AOC_E) || |
| 597 |
(ast_aoc_get_charge_type(decoded) != AST_AOC_CHARGE_NA)) { |
| 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 |
|
| 609 |
decoded = ast_aoc_destroy_decoded(decoded); |
| 610 |
|
| 611 |
|
| 612 |
|
| 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 |
|
| 620 |
ast_aoc_s_add_rate_duration(decoded, |
| 621 |
AST_AOC_CHARGED_ITEM_SUPPLEMENTARY_SERVICE, |
| 622 |
937, |
| 623 |
AST_AOC_MULT_THOUSAND, |
| 624 |
"jkasdf", |
| 625 |
235328, |
| 626 |
AST_AOC_TIME_SCALE_SECOND, |
| 627 |
905423, |
| 628 |
AST_AOC_TIME_SCALE_DAY, |
| 629 |
1); |
| 630 |
|
| 631 |
ast_aoc_s_add_rate_flat(decoded, |
| 632 |
AST_AOC_CHARGED_ITEM_CALL_SETUP, |
| 633 |
1337, |
| 634 |
AST_AOC_MULT_ONEHUNDREDTH, |
| 635 |
"MONEYS"); |
| 636 |
|
| 637 |
ast_aoc_s_add_rate_volume(decoded, |
| 638 |
AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, |
| 639 |
AST_AOC_VOLUME_UNIT_SEGMENT, |
| 640 |
5555, |
| 641 |
AST_AOC_MULT_ONEHUNDREDTH, |
| 642 |
"pounds"); |
| 643 |
|
| 644 |
ast_aoc_s_add_rate_duration(decoded, |
| 645 |
AST_AOC_CHARGED_ITEM_CALL_ATTEMPT, |
| 646 |
78923, |
| 647 |
AST_AOC_MULT_ONETHOUSANDTH, |
| 648 |
"SNAP", |
| 649 |
9354, |
| 650 |
AST_AOC_TIME_SCALE_HUNDREDTH_SECOND, |
| 651 |
234933, |
| 652 |
AST_AOC_TIME_SCALE_SECOND, |
| 653 |
0); |
| 654 |
|
| 655 |
ast_aoc_s_add_rate_free(decoded, AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT, 1); |
| 656 |
ast_aoc_s_add_rate_free(decoded, AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT, 0); |
| 657 |
ast_aoc_s_add_rate_na(decoded, AST_AOC_CHARGED_ITEM_SPECIAL_ARRANGEMENT); |
| 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 |
|
| 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 |
} |
| 674 |
|
| 675 |
static int unload_module(void) |
| 676 |
{ |
| 677 |
AST_TEST_UNREGISTER(aoc_encode_decode_test); |
| 678 |
AST_TEST_UNREGISTER(aoc_event_generation_test); |
| 679 |
return 0; |
| 680 |
} |
| 681 |
|
| 682 |
static int load_module(void) |
| 683 |
{ |
| 684 |
AST_TEST_REGISTER(aoc_encode_decode_test); |
| 685 |
AST_TEST_REGISTER(aoc_event_generation_test); |
| 686 |
return AST_MODULE_LOAD_SUCCESS; |
| 687 |
} |
| 688 |
|
| 689 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "AOC unit tests"); |