1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2005-2019. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%% 22%%---------------------------------------------------------------------- 23%% Purpose: Verify the application specifics of the Megaco application 24%%---------------------------------------------------------------------- 25-module(megaco_digit_map_SUITE). 26 27-export([ 28 suite/0, all/0, groups/0, 29 init_per_suite/1, end_per_suite/1, 30 init_per_group/2, end_per_group/2, 31 init_per_testcase/2, end_per_testcase/2, 32 33 otp_5750_01/1, 34 otp_5750_02/1, 35 otp_5799_01/1, 36 otp_5826_01/1, 37 otp_5826_02/1, 38 otp_5826_03/1, 39 otp_7449_1/1, 40 otp_7449_2/1 41 42 ]). 43 44 45-include("megaco_test_lib.hrl"). 46 47 48 49%%====================================================================== 50%% Common Test interface functions 51%%====================================================================== 52 53suite() -> 54 [{ct_hooks, [ts_install_cth]}]. 55 56all() -> 57 [ 58 {group, tickets} 59 ]. 60 61groups() -> 62 [ 63 {tickets, [], tickets_cases()}, 64 {otp_5750, [], otp_5750_cases()}, 65 {otp_5799, [], otp_5799_cases()}, 66 {otp_5826, [], otp_5826_cases()}, 67 {otp_7449, [], otp_7449_cases()} 68 ]. 69 70tickets_cases() -> 71 [ 72 {group, otp_5750}, 73 {group, otp_5799}, 74 {group, otp_5826}, 75 {group, otp_7449} 76 ]. 77 78otp_5750_cases() -> 79 [ 80 otp_5750_01, 81 otp_5750_02 82 ]. 83 84otp_5799_cases() -> 85 [ 86 otp_5799_01 87 ]. 88 89otp_5826_cases() -> 90 [ 91 otp_5826_01, 92 otp_5826_02, 93 otp_5826_03 94 ]. 95 96otp_7449_cases() -> 97 [ 98 otp_7449_1, 99 otp_7449_2 100 ]. 101 102 103 104%% 105%% ----- 106%% 107 108init_per_suite(suite) -> 109 []; 110init_per_suite(doc) -> 111 []; 112init_per_suite(Config0) when is_list(Config0) -> 113 114 ?ANNOUNCE_SUITE_INIT(), 115 116 p("init_per_suite -> entry with" 117 "~n Config: ~p" 118 "~n Nodes: ~p", [Config0, erlang:nodes()]), 119 120 case ?LIB:init_per_suite(Config0) of 121 {skip, _} = SKIP -> 122 SKIP; 123 124 Config1 when is_list(Config1) -> 125 126 %% We need a (local) monitor on this node also 127 megaco_test_sys_monitor:start(), 128 129 p("init_per_suite -> end when" 130 "~n Config: ~p" 131 "~n Nodes: ~p", [Config1, erlang:nodes()]), 132 133 Config1 134 end. 135 136end_per_suite(suite) -> []; 137end_per_suite(doc) -> []; 138end_per_suite(Config0) when is_list(Config0) -> 139 140 p("end_per_suite -> entry with" 141 "~n Config: ~p" 142 "~n Nodes: ~p", [Config0, erlang:nodes()]), 143 144 megaco_test_sys_monitor:stop(), 145 Config1 = ?LIB:end_per_suite(Config0), 146 147 p("end_per_suite -> end when" 148 "~n Nodes: ~p", [erlang:nodes()]), 149 150 Config1. 151 152 153%% 154%% ----- 155%% 156 157init_per_group(_GroupName, Config) -> 158 Config. 159 160end_per_group(_GroupName, Config) -> 161 Config. 162 163 164 165%% 166%% ----- 167%% 168 169init_per_testcase(Case, Config) -> 170 171 p("init_per_testcase -> entry with" 172 "~n Config: ~p" 173 "~n Nodes: ~p", [Config, erlang:nodes()]), 174 175 megaco_test_global_sys_monitor:reset_events(), 176 177 megaco_test_lib:init_per_testcase(Case, Config). 178 179end_per_testcase(Case, Config) -> 180 181 p("end_per_testcase -> entry with" 182 "~n Config: ~p" 183 "~n Nodes: ~p", [Config, erlang:nodes()]), 184 185 p("system events during test: " 186 "~n ~p", [megaco_test_global_sys_monitor:events()]), 187 188 megaco_test_lib:end_per_testcase(Case, Config). 189 190 191 192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 193 194otp_5750_01(suite) -> 195 []; 196otp_5750_01(doc) -> 197 []; 198otp_5750_01(Config) when is_list(Config) -> 199 DM = "1 | 123", 200 201 %% First case 202 Tests = 203 [ 204 {1, 205 fun() -> 206 (catch tde(DM, "1")) 207 end, 208 fun({ok, {full, "1"}}) -> 209 ok; 210 (Else) -> 211 {error, {unexpected_digit_map_result, Else}} 212 end}, 213 214 {2, 215 fun() -> 216 (catch tde(DM, "123")) 217 end, 218 fun({ok, {unambiguous, "123"}}) -> 219 ok; 220 (Else) -> 221 {error, {unexpected_digit_map_result, Else}} 222 end}, 223 224 {3, 225 fun() -> 226 (catch tde(DM, "124")) 227 end, 228 fun({error, _}) -> 229 ok; 230 (Else) -> 231 {error, {unexpected_digit_map_result, Else}} 232 end} 233 ], 234 235 dm_tests(Tests), 236 237 ok. 238 239 240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 241 242otp_5750_02(suite) -> 243 []; 244otp_5750_02(doc) -> 245 []; 246otp_5750_02(Config) when is_list(Config) -> 247 DM = "xxx | xxL3 | xxS4", 248 249 %% First case 250 Tests = 251 [ 252 {1, 253 fun() -> 254 (catch otp_5750_02_exec(500, DM, "113")) 255 end, 256 fun({ok, {unambiguous, "113"}}) -> 257 ok; 258 (Else) -> 259 {error, {unexpected_digit_map_result, Else}} 260 end}, 261 262 {2, 263 fun() -> 264 (catch otp_5750_02_exec(500, DM, "114")) 265 end, 266 fun({ok, {unambiguous, "114"}}) -> 267 ok; 268 (Else) -> 269 {error, {unexpected_digit_map_result, Else}} 270 end}, 271 272 {3, 273 fun() -> 274 (catch otp_5750_02_exec(5000, DM, "11ssss3")) 275 end, 276 fun({ok, {unambiguous, "113"}}) -> 277 ok; 278 (Else) -> 279 {error, {unexpected_digit_map_result, Else}} 280 end}, 281 282 {4, 283 fun() -> 284 (catch otp_5750_02_exec(5000, DM, "11ssss4")) 285 end, 286 fun({ok, {unambiguous, "114"}}) -> 287 ok; 288 (Else) -> 289 {error, {unexpected_digit_map_result, Else}} 290 end} 291 292 ], 293 294 dm_tests(Tests), 295 296 ok. 297 298otp_5750_02_exec(To, DM, Evs) -> 299 Pid = self(), 300 Tester = 301 spawn(fun() -> 302 Res = tde(DM, Evs), 303 Pid ! {result, self(), Res} 304 end), 305 receive 306 {result, Tester, Res} -> 307 Res 308 after To -> 309 {error, timeout} 310 end. 311 312 313%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 314 315otp_5799_01(suite) -> 316 []; 317otp_5799_01(doc) -> 318 []; 319otp_5799_01(Config) when is_list(Config) -> 320 DM = "234 | 23456", 321 322 %% First case 323 Tests = 324 [ 325 {1, 326 fun() -> 327 (catch tde(DM, "2349")) 328 end, 329 fun({ok, {full, "234", $9}}) -> 330 ok; 331 (Else) -> 332 {error, {unexpected_digit_map_result, Else}} 333 end} 334 ], 335 336 dm_tests(Tests), 337 338 ok. 339 340 341%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 342 343otp_5826_01(suite) -> 344 []; 345otp_5826_01(doc) -> 346 []; 347otp_5826_01(Config) when is_list(Config) -> 348 DM = "123Z56", 349 350 %% First case 351 Tests = 352 [ 353 {1, 354 fun() -> 355 (catch tde(DM, [$1,$2,$3,{long, $5},$6])) 356 end, 357 fun({ok, {unambiguous, "123Z56"}}) -> 358 ok; 359 (Else) -> 360 {error, {unexpected_digit_map_result, Else}} 361 end}, 362 {2, 363 fun() -> 364 (catch tde(DM, [$1,$2,{long, $3},{long,$5},$6])) 365 end, 366 fun({ok, {unambiguous, "123Z56"}}) -> 367 ok; 368 (Else) -> 369 {error, {unexpected_digit_map_result, Else}} 370 end}, 371 {3, 372 fun() -> 373 (catch tde(DM, [$1,$2,$3,{long,$5},{long,$6}])) 374 end, 375 fun({ok, {unambiguous, "123Z56"}}) -> 376 ok; 377 (Else) -> 378 {error, {unexpected_digit_map_result, Else}} 379 end}, 380 {4, 381 fun() -> 382 (catch tde(DM, [$1,$2,{long, $3},{long,$5},{long,$6}])) 383 end, 384 fun({ok, {unambiguous, "123Z56"}}) -> 385 ok; 386 (Else) -> 387 {error, {unexpected_digit_map_result, Else}} 388 end} 389 ], 390 391 dm_tests(Tests), 392 393 ok. 394 395 396%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 397 398otp_5826_02(suite) -> 399 []; 400otp_5826_02(doc) -> 401 []; 402otp_5826_02(Config) when is_list(Config) -> 403 DM = "12356", 404 405 %% First case 406 Tests = 407 [ 408 {1, 409 fun() -> 410 (catch tde(DM, [$1,$2,$3,{long, $5},$6])) 411 end, 412 fun({ok, {unambiguous, "12356"}}) -> 413 ok; 414 (Else) -> 415 {error, {unexpected_digit_map_result, Else}} 416 end} 417 ], 418 419 dm_tests(Tests), 420 421 ok. 422 423 424%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 425 426otp_5826_03(suite) -> 427 []; 428otp_5826_03(doc) -> 429 []; 430otp_5826_03(Config) when is_list(Config) -> 431 DM = "12346 | 12Z346 | 12Z34Z7 | 1234Z8", 432 433 %% First case 434 Tests = 435 [ 436 {1, 437 fun() -> 438 (catch tde(DM, [$1,$2,{long, $3},$4,$6])) 439 end, 440 fun({ok, {unambiguous, "12Z346"}}) -> 441 ok; 442 (Else) -> 443 {error, {unexpected_digit_map_result, Else}} 444 end}, 445 {2, 446 fun() -> 447 (catch tde(DM, [$1, {long, $2}, {long, $3},$4, $6])) 448 end, 449 fun({ok, {unambiguous, "12Z346"}}) -> 450 ok; 451 (Else) -> 452 {error, {unexpected_digit_map_result, Else}} 453 end}, 454 {3, 455 fun() -> 456 (catch tde(DM, [$1,$2,{long, $3},{long, $4},$6])) 457 end, 458 fun({ok, {unambiguous, "12Z346"}}) -> 459 ok; 460 (Else) -> 461 {error, {unexpected_digit_map_result, Else}} 462 end}, 463 {4, 464 fun() -> 465 (catch tde(DM, [$1,$2,{long, $3},$4,{long, $7}])) 466 end, 467 fun({ok, {unambiguous, "12Z34Z7"}}) -> 468 ok; 469 (Else) -> 470 {error, {unexpected_digit_map_result, Else}} 471 end}, 472 {5, 473 fun() -> 474 (catch tde(DM, [$1,$2,{long, $3},$4,{long, $8}])) 475 end, 476 fun({error, 477 {unexpected_event, {long, $8}, _Collected, _Expected}}) -> 478 ok; 479 (Else) -> 480 {error, {unexpected_digit_map_result, Else}} 481 end}, 482 {6, 483 fun() -> 484 (catch tde(DM, [$1,$2,$3,$4,{long, $8}])) 485 end, 486 fun({ok, {unambiguous, "1234Z8"}}) -> 487 ok; 488 (Else) -> 489 {error, {unexpected_digit_map_result, Else}} 490 end} 491 ], 492 493 dm_tests(Tests), 494 495 ok. 496 497 498%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 499 500otp_7449_1(suite) -> 501 []; 502otp_7449_1(doc) -> 503 []; 504otp_7449_1(Config) when is_list(Config) -> 505 DM = "([0-9ef])", 506 507 %% First case 508 Tests = 509 [ 510 {1, 511 fun() -> 512 (catch tde(DM, [$0])) 513 end, 514 fun({ok, {unambiguous, "0"}}) -> 515 ok; 516 (Else) -> 517 {error, {unexpected_digit_map_result, Else}} 518 end}, 519 {2, 520 fun() -> 521 (catch tde(DM, [$1])) 522 end, 523 fun({ok, {unambiguous, "1"}}) -> 524 ok; 525 (Else) -> 526 {error, {unexpected_digit_map_result, Else}} 527 end}, 528 {3, 529 fun() -> 530 (catch tde(DM, [$2])) 531 end, 532 fun({ok, {unambiguous, "2"}}) -> 533 ok; 534 (Else) -> 535 {error, {unexpected_digit_map_result, Else}} 536 end}, 537 {4, 538 fun() -> 539 (catch tde(DM, [$3])) 540 end, 541 fun({ok, {unambiguous, "3"}}) -> 542 ok; 543 (Else) -> 544 {error, {unexpected_digit_map_result, Else}} 545 end}, 546 {5, 547 fun() -> 548 (catch tde(DM, [$4])) 549 end, 550 fun({ok, {unambiguous, "4"}}) -> 551 ok; 552 (Else) -> 553 {error, {unexpected_digit_map_result, Else}} 554 end}, 555 {6, 556 fun() -> 557 (catch tde(DM, [$5])) 558 end, 559 fun({ok, {unambiguous, "5"}}) -> 560 ok; 561 (Else) -> 562 {error, {unexpected_digit_map_result, Else}} 563 end}, 564 {7, 565 fun() -> 566 (catch tde(DM, [$6])) 567 end, 568 fun({ok, {unambiguous, "6"}}) -> 569 ok; 570 (Else) -> 571 {error, {unexpected_digit_map_result, Else}} 572 end}, 573 {8, 574 fun() -> 575 (catch tde(DM, [$7])) 576 end, 577 fun({ok, {unambiguous, "7"}}) -> 578 ok; 579 (Else) -> 580 {error, {unexpected_digit_map_result, Else}} 581 end}, 582 {9, 583 fun() -> 584 (catch tde(DM, [$8])) 585 end, 586 fun({ok, {unambiguous, "8"}}) -> 587 ok; 588 (Else) -> 589 {error, {unexpected_digit_map_result, Else}} 590 end}, 591 {10, 592 fun() -> 593 (catch tde(DM, [$9])) 594 end, 595 fun({ok, {unambiguous, "9"}}) -> 596 ok; 597 (Else) -> 598 {error, {unexpected_digit_map_result, Else}} 599 end}, 600 {11, 601 fun() -> 602 (catch tde(DM, [$a])) 603 end, 604 fun({error, {unexpected_event, $a, _Collected, _Expected}}) -> 605 ok; 606 (Else) -> 607 {error, {unexpected_digit_map_result, Else}} 608 end}, 609 {12, 610 fun() -> 611 (catch tde(DM, [$e])) 612 end, 613 fun({ok, {unambiguous, "e"}}) -> 614 ok; 615 (Else) -> 616 {error, {unexpected_digit_map_result, Else}} 617 end}, 618 {13, 619 fun() -> 620 (catch tde(DM, [$f])) 621 end, 622 fun({ok, {unambiguous, "f"}}) -> 623 ok; 624 (Else) -> 625 {error, {unexpected_digit_map_result, Else}} 626 end}, 627 {14, 628 fun() -> 629 (catch tde(DM, [$a])) 630 end, 631 fun({error, {unexpected_event, $a, 632 [] = _Collected, 633 [{letter, [{range, $0, $9}, 634 {single, $e}, 635 {single, $f}]}] = _Expected}}) -> 636 ok; 637 (Else) -> 638 {error, {unexpected_digit_map_result, Else}} 639 end} 640 ], 641 642 dm_tests(Tests), 643 644 ok. 645 646 647%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 648 649otp_7449_2(suite) -> 650 []; 651otp_7449_2(doc) -> 652 []; 653otp_7449_2(Config) when is_list(Config) -> 654 DM = "([0-9]ef)", 655 656 %% First case 657 Tests = 658 [ 659 {1, 660 fun() -> 661 (catch tde(DM, [$0,$e,$f])) 662 end, 663 fun({ok, {unambiguous, "0ef"}}) -> 664 ok; 665 (Else) -> 666 {error, {unexpected_digit_map_result, Else}} 667 end}, 668 {2, 669 fun() -> 670 (catch tde(DM, [$1,$e,$f])) 671 end, 672 fun({ok, {unambiguous, "1ef"}}) -> 673 ok; 674 (Else) -> 675 {error, {unexpected_digit_map_result, Else}} 676 end}, 677 {3, 678 fun() -> 679 (catch tde(DM, [$2])) 680 end, 681 fun({error, {unexpected_event, 682 inter_event_timeout, [$2] = _Collected, 683 [{single, $e}] = _Expecting}}) -> 684 ok; 685 (Else) -> 686 {error, {unexpected_digit_map_result, Else}} 687 end}, 688 {4, 689 fun() -> 690 (catch tde(DM, [$3,$f,$f])) 691 end, 692 fun({error, {unexpected_event, $f, [$3] = _Collected, 693 [{single, $e}] = _Expected}}) -> 694 ok; 695 (Else) -> 696 {error, {unexpected_digit_map_result, Else}} 697 end}, 698 {5, 699 fun() -> 700 (catch tde(DM, [$a,$e,$f])) 701 end, 702 fun({error, {unexpected_event, $a, 703 [] = _Collected, 704 [{letter, [{range, $0, $9}]}] = _Expected}}) -> 705 ok; 706 (Else) -> 707 {error, {unexpected_digit_map_result, Else}} 708 end} 709 ], 710 711 dm_tests(Tests), 712 713 ok. 714 715 716%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 717 718dm_tests([]) -> 719 ok; 720dm_tests([{No, Exec, Ver}|Tests]) 721 when is_integer(No) andalso is_function(Exec) andalso is_function(Ver) -> 722 case dm_test(Exec, Ver) of 723 ok -> 724 dm_tests(Tests); 725 {error, Reason} -> 726 ?ERROR({No, Reason}); 727 Error -> 728 ?ERROR({No, Error}) 729 end. 730 731dm_test(Exec, Verify) -> 732 (catch Verify(Exec())). 733 734 735 736%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 737 738tde(DM, Evs) -> megaco:test_digit_event(DM, Evs). 739 740 741 742%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 743 744%% p(F) -> 745%% p(F, []). 746 747p(F, A) -> 748 p(get(sname), F, A). 749 750p(S, F, A) when is_list(S) -> 751 io:format("*** [~s] ~p ~s ***" 752 "~n " ++ F ++ "~n", 753 [?FTS(), self(), S | A]); 754p(_S, F, A) -> 755 io:format("*** [~s] ~p *** " 756 "~n " ++ F ++ "~n", 757 [?FTS(), self() | A]). 758 759 760