1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2001-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:
24%%----------------------------------------------------------------------
25
26-module(megaco_binary_term_id_SUITE).
27
28
29%%----------------------------------------------------------------------
30%% External exports
31%%----------------------------------------------------------------------
32
33%% Test suite exports
34-export([
35         suite/0, all/0, groups/0,
36	 init_per_suite/1,    end_per_suite/1,
37         init_per_group/2,    end_per_group/2,
38	 init_per_testcase/2, end_per_testcase/2,
39
40         te01/1, te02/1, te03/1, te04/1, te05/1,
41	 te06/1, te07/1, te08/1, te09/1, te10/1,
42	 te11/1, te12/1, te13/1, te14/1, te15/1,
43	 te16/1, te17/1, te18/1, te19/1,
44
45         td01/1, td02/1, td03/1, td04/1, td05/1,
46         td06/1
47        ]).
48
49
50%%----------------------------------------------------------------------
51%% Include files
52%%----------------------------------------------------------------------
53
54-include_lib("megaco/include/megaco.hrl").
55-include_lib("megaco/src/engine/megaco_message_internal.hrl").
56-include("megaco_test_lib.hrl").
57
58
59
60
61%%======================================================================
62%% Common Test interface functions
63%%======================================================================
64
65suite() ->
66    [{ct_hooks, [ts_install_cth]}].
67
68all() ->
69    [
70     {group, encode_first},
71     {group, decode_first}
72    ].
73
74groups() ->
75    [
76     {encode_first, [], encode_first_cases()},
77     {decode_first, [], decode_first_cases()}
78    ].
79
80encode_first_cases() ->
81    [
82     te01,
83     te02,
84     te03,
85     te04,
86     te05,
87     te06,
88     te07,
89     te08,
90     te09,
91     te10,
92     te11,
93     te12,
94     te13,
95     te14,
96     te15,
97     te16,
98     te17,
99     te18,
100     te19
101    ].
102
103decode_first_cases() ->
104    [
105     td01,
106     td02,
107     td03,
108     td04,
109     td05,
110     td06
111    ].
112
113
114
115%%
116%% -----
117%%
118
119init_per_suite(suite) ->
120    [];
121init_per_suite(doc) ->
122    [];
123init_per_suite(Config0) when is_list(Config0) ->
124
125    ?ANNOUNCE_SUITE_INIT(),
126
127    p("init_per_suite -> entry with"
128      "~n      Config: ~p"
129      "~n      Nodes:  ~p", [Config0, erlang:nodes()]),
130
131    case ?LIB:init_per_suite([{sysmon, false}|Config0]) of
132        {skip, _} = SKIP ->
133            SKIP;
134
135        Config1 when is_list(Config1) ->
136
137            p("init_per_suite -> end when"
138              "~n      Config: ~p"
139              "~n      Nodes:  ~p", [Config1, erlang:nodes()]),
140
141            Config1
142    end.
143
144end_per_suite(suite) -> [];
145end_per_suite(doc) -> [];
146end_per_suite(Config0) when is_list(Config0) ->
147
148    p("end_per_suite -> entry with"
149      "~n      Config: ~p"
150      "~n      Nodes:  ~p", [Config0, erlang:nodes()]),
151
152    Config1 = ?LIB:end_per_suite(Config0),
153
154    p("end_per_suite -> end when"
155      "~n      Nodes:  ~p", [erlang:nodes()]),
156
157    Config1.
158
159
160%%
161%% -----
162%%
163
164init_per_group(_GroupName, Config) ->
165    p("init_per_group -> entry with"
166      "~n   Config: ~p"
167      "~n", [Config]),
168    Config.
169
170end_per_group(_GroupName, Config) ->
171    p("end_per_group -> entry with"
172      "~n   Config: ~p"
173      "~n", [Config]),
174    Config.
175
176
177
178%%
179%% -----
180%%
181
182init_per_testcase(Case, Config) ->
183
184    p("init_per_testcase -> entry with"
185      "~n   Config: ~p"
186      "~n   Nodes:  ~p", [Config, erlang:nodes()]),
187
188    megaco_test_lib:init_per_testcase(Case, Config).
189
190end_per_testcase(Case, Config) ->
191
192    p("end_per_testcase -> entry with"
193      "~n   Config: ~p"
194      "~n   Nodes:  ~p", [Config, erlang:nodes()]),
195
196    megaco_test_lib:end_per_testcase(Case, Config).
197
198
199%%======================================================================
200%% External functions
201%%======================================================================
202
203
204%% --------------------------------------------------------
205%% Start test cases
206%% --------------------------------------------------------
207
208%% basic_enc_dec01
209te01(doc) ->
210    "Basic encoding & then decoding test [1,1]\n  (asn -> binary -> asn)";
211
212te01(suite) ->
213    [];
214
215te01(Config) when is_list(Config) ->
216    {Exp,Res} = te01(),
217    ok = check(te01(doc),Exp,Res).
218
219
220te01() ->
221    %% put(encode_debug,dbg),
222    %% put(decode_debug,dbg),
223    Res = encode_decode(config1(),mtid01()),
224    erase(encode_debug),
225    erase(decode_debug),
226    {ok,Res}.
227
228
229%% --------------------------------------------------------
230
231%% basic_enc_dec02
232te02(doc) ->
233    "Basic encoding & then decoding test [1,2]";
234
235te02(suite) ->
236    [];
237
238te02(Config) when is_list(Config) ->
239    {Exp,Res} = te02(),
240    ok = check(te02(doc),Exp,Res).
241
242te02() ->
243    %% put(encode_debug,dbg),
244    %% put(decode_debug,dbg),
245    Res = encode_decode(config1(),mtid02()),
246    erase(encode_debug),
247    erase(decode_debug),
248    {ok,Res}.
249
250
251%% --------------------------------------------------------
252
253%% basic_enc_dec03
254te03(doc) ->
255    "Basic encoding & then decoding test [1,3]";
256
257te03(suite) ->
258    [];
259
260te03(Config) when is_list(Config) ->
261    {Exp,Res} = te03(),
262    ok = check(te03(doc),Exp,Res).
263
264te03() ->
265    %% put(encode_debug,dbg),
266    %% put(decode_debug,dbg),
267    Res = encode_decode(config1(),mtid03()),
268    erase(encode_debug),
269    erase(decode_debug),
270    {ok,Res}.
271
272
273%% --------------------------------------------------------
274
275%% basic_enc_dec04
276te04(doc) ->
277    "Basic encoding & then decoding test [1,4]\n  (asn -> binary -> asn)";
278
279te04(suite) ->
280    [];
281
282te04(Config) when is_list(Config) ->
283    {Exp,Res} = te04(),
284    ok = check(te04(doc),Exp,Res).
285
286te04() ->
287    %% put(encode_debug,dbg),
288    %% put(decode_debug,dbg),
289    Res = encode_decode(config1(),mtid04()),
290    erase(encode_debug),
291    erase(decode_debug),
292    {ok,Res}.
293
294
295%% --------------------------------------------------------
296
297%% basic_enc_dec05
298te05(doc) ->
299    "Basic encoding & then decoding test [1,5]\n  (asn -> binary -> asn)";
300
301te05(suite) ->
302    [];
303
304te05(Config) when is_list(Config) ->
305    {Exp,Res} = te05(),
306    ok = check(te05(doc),Exp,Res).
307
308te05() ->
309    %% put(encode_debug,dbg),
310    %% put(decode_debug,dbg),
311    Res = encode_decode(config1(),mtid05()),
312    erase(encode_debug),
313    erase(decode_debug),
314    {ok,Res}.
315
316
317%% --------------------------------------------------------
318
319%% no_wildcard_spec_but_fond_some_enc_dec
320te06(doc) ->
321    "Specified NO wildcards, but found some just the same [1,6]\n  (asn -> binary -> asn)";
322
323te06(suite) ->
324    [];
325
326te06(Config) when is_list(Config) ->
327    {Exp,Res} = te06(),
328    ok = check(te06(doc),Exp,Res).
329
330te06() ->
331    %% put(encode_debug,dbg),
332    %% put(decode_debug,dbg),
333    Res = encode_decode(config1(),mtid06()),
334    erase(encode_debug),
335    erase(decode_debug),
336    {error,Res}.
337
338
339%% --------------------------------------------------------
340
341%% invalid_char_enc_dec
342te07(doc) ->
343    "Invalid character found (2) [1,7]\n  (asn -> binary -> asn)";
344
345te07(suite) ->
346    [];
347
348te07(Config) when is_list(Config) ->
349    {Exp,Res} = te07(),
350    ok = check(te07(doc),Exp,Res).
351
352te07() ->
353    %% put(encode_debug,dbg),
354    %% put(decode_debug,dbg),
355    Res = encode_decode(config1(),mtid07()),
356    erase(encode_debug),
357    erase(decode_debug),
358    {error,Res}.
359
360
361%% --------------------------------------------------------
362
363%% erroneous_first_level_length_enc_dec01
364te08(doc) ->
365    "Erroneous length of first level (a character after wildcard) [1,8]\n  (asn -> binary -> asn)";
366
367te08(suite) ->
368    [];
369
370te08(Config) when is_list(Config) ->
371    {Exp,Res} = te08(),
372    ok = check(te08(doc),Exp,Res).
373
374te08() ->
375    %% put(encode_debug,dbg),
376    %% put(decode_debug,dbg),
377    Res = encode_decode(config1(),mtid08()),
378    erase(encode_debug),
379    erase(decode_debug),
380    {error,Res}.
381
382
383%% --------------------------------------------------------
384
385%% erroneous_first_level_length_enc_dec02
386te09(doc) ->
387    "Erroneous length of first level (a character after last valid) [1,9]\n  (asn -> binary -> asn)";
388
389te09(suite) ->
390    [];
391
392te09(Config) when is_list(Config) ->
393    {Exp,Res} = te09(),
394    ok = check(te09(doc),Exp,Res).
395
396te09() ->
397    %% put(encode_debug,dbg),
398    %% put(decode_debug,dbg),
399    Res = encode_decode(config1(),mtid09()),
400    erase(encode_debug),
401    erase(decode_debug),
402    {error,Res}.
403
404
405%% --------------------------------------------------------
406
407%% basic_enc_dec_with_one_rec_wildcard01
408te10(doc) ->
409    "Basic encode & decode with one recursive wildcard [1,10]\n  (asn -> binary -> asn)\n   (NOTE THAT THIS SHOULD LATER BE A LEVEL WILDCARD)";
410
411te10(suite) ->
412    [];
413
414te10(Config) when is_list(Config) ->
415    {Exp,Res} = te10(),
416    ok = check(te10(doc),Exp,Res).
417
418te10() ->
419    %% put(encode_debug,dbg),
420    %% put(decode_debug,dbg),
421    Res = encode_decode(config1(),mtid10()),
422    erase(encode_debug),
423    erase(decode_debug),
424    {ok,Res}.
425
426
427%% --------------------------------------------------------
428
429%% basic_enc_dec_with_one_rec_wildcard02
430te11(doc) ->
431    "Basic encode & decode with one recursive wildcard [1,11]\n  (asn -> binary -> asn)";
432
433te11(suite) ->
434    [];
435
436te11(Config) when is_list(Config) ->
437    {Exp,Res} = te11(),
438    ok = check(te11(doc),Exp,Res).
439
440te11() ->
441    %% put(encode_debug,dbg),
442    %% put(decode_debug,dbg),
443    Res = encode_decode(config1(),mtid11()),
444    erase(encode_debug),
445    erase(decode_debug),
446    {ok,Res}.
447
448
449%% --------------------------------------------------------
450
451%% basic_enc_dec_with_one_rec_wildcard03
452te12(doc) ->
453    "Basic encode & decode with one recursive wildcard [1,12]\n  (asn -> binary -> asn)";
454
455te12(suite) ->
456    [];
457
458te12(Config) when is_list(Config) ->
459    {Exp,Res} = te12(),
460    ok = check(te12(doc),Exp,Res).
461
462te12() ->
463    %% put(encode_debug,dbg),
464    %% put(decode_debug,dbg),
465    Res = encode_decode(config1(),mtid12()),
466    erase(encode_debug),
467    erase(decode_debug),
468    {ok,Res}.
469
470
471%% --------------------------------------------------------
472
473%% basic_enc_dec_with_one_rec_wildcard04
474te13(doc) ->
475    "Basic encode & decode with one recursive wildcard [1,13]\n  (asn -> binary -> asn)";
476
477te13(suite) ->
478    [];
479
480te13(Config) when is_list(Config) ->
481    {Exp,Res} = te13(),
482    ok = check(te13(doc),Exp,Res).
483
484te13() ->
485    %% put(encode_debug,dbg),
486    %% put(decode_debug,dbg),
487    Res = encode_decode(config1(),mtid13()),
488    erase(encode_debug),
489    erase(decode_debug),
490    {ok,Res}.
491
492
493%% --------------------------------------------------------
494
495%% basic_enc_dec_with_one_rec_wildcard05
496te14(doc) ->
497    "Basic encode & decode with one recursive wildcard [2,13]\n  (asn -> binary -> asn)";
498
499te14(suite) ->
500    [];
501
502te14(Config) when is_list(Config) ->
503    {Exp,Res} = te14(),
504    ok = check(te14(doc),Exp,Res).
505
506te14() ->
507    %% put(encode_debug,dbg),
508    %% put(decode_debug,dbg),
509    Res = encode_decode(config2(),mtid13()),
510    erase(encode_debug),
511    erase(decode_debug),
512    {ok,Res}.
513
514
515%% --------------------------------------------------------
516
517%% basic_enc_dec_with_one_wildcard_1level
518te15(doc) ->
519    "Basic encode & decode with one wildcard in the first level\nand then one empty level [1,15]\n  (asn -> binary -> asn)";
520
521te15(suite) ->
522    [];
523
524te15(Config) when is_list(Config) ->
525    {Exp,Res} = te15(),
526    ok = check(te15(doc),Exp,Res).
527
528te15() ->
529    %% put(encode_debug,dbg),
530    %% put(decode_debug,dbg),
531    Res = encode_decode(config1(),mtid15()),
532    erase(encode_debug),
533    erase(decode_debug),
534    {error,Res}.
535
536
537%% --------------------------------------------------------
538
539%% basic_enc_dec_with_one_rec_wildcard06
540te16(doc) ->
541    "Basic encode & decode with one recursive wildcard [2,15]\n  (asn -> binary -> asn)";
542
543te16(suite) ->
544    [];
545
546te16(Config) when is_list(Config) ->
547    {Exp,Res} = te16(),
548    ok = check(te16(doc),Exp,Res).
549
550te16() ->
551    %% put(encode_debug,dbg),
552    %% put(decode_debug,dbg),
553    Res = encode_decode(config2(),mtid15()),
554    erase(encode_debug),
555    erase(decode_debug),
556    {error,Res}.
557
558
559%% --------------------------------------------------------
560
561%% basic_enc_dec_with_one_rec_wildcard07
562te17(doc) ->
563    "Basic encode & decode with one recursive wildcard [2,11]\n  (asn -> binary -> asn)";
564
565te17(suite) ->
566    [];
567
568te17(Config) when is_list(Config) ->
569    {Exp,Res} = te17(),
570    ok = check(te17(doc),Exp,Res).
571
572te17() ->
573    %% put(encode_debug,dbg),
574    %% put(decode_debug,dbg),
575    Res = encode_decode(config2(),mtid11()),
576    erase(encode_debug),
577    erase(decode_debug),
578    {ok,Res}.
579
580
581%% --------------------------------------------------------
582
583%% basic_enc_dec_with_one_rec_wildcard08
584te18(doc) ->
585    "Basic encode & decode with one recursive wildcard [4,16]\n  (asn -> binary -> asn)";
586
587te18(suite) ->
588    [];
589
590te18(Config) when is_list(Config) ->
591    {Exp,Res} = te18(),
592    ok = check(te18(doc),Exp,Res).
593
594te18() ->
595    put(encode_debug,dbg),
596    put(decode_debug,dbg),
597    Res = encode_decode(config4(),mtid16()),
598    erase(encode_debug),
599    erase(decode_debug),
600    {ok,Res}.
601
602
603%% --------------------------------------------------------
604
605%% basic_enc_dec_with_one_rec_wildcard09
606te19(doc) ->
607    "Basic encode & decode with one recursive wildcard [4,17]\n  (asn -> binary -> asn)";
608
609te19(suite) ->
610    [];
611
612te19(Config) when is_list(Config) ->
613    {Exp,Res} = te19(),
614    ok = check(te19(doc),Exp,Res).
615
616te19() ->
617    %% put(encode_debug,dbg),
618    %% put(decode_debug,dbg),
619    Res = encode_decode(config4(),mtid17()),
620    erase(encode_debug),
621    erase(decode_debug),
622    {ok,Res}.
623
624
625%% --------------------------------------------------------
626
627%% root_term_dec_enc
628td01(doc) ->
629    "Root termination decoding & then encoding test [1,1]\n  (binary -> asn -> binary)";
630
631td01(suite) ->
632    [];
633
634td01(Config) when is_list(Config) ->
635    {Exp,Res} = td01(),
636    ok = check(td01(doc),Exp,Res).
637
638td01() ->
639    %% put(encode_debug,dbg),
640    %% put(decode_debug,dbg),
641    Res = decode_encode(config1(),atid1()),
642    erase(encode_debug),
643    erase(decode_debug),
644    {ok,Res}.
645
646
647%% --------------------------------------------------------
648
649%% One byte to much (should be two bytes but is three)
650%% basic_dec_enc01
651td02(doc) ->
652    "Basic decoding & then encoding test [1,2]\n  (binary -> asn -> binary)";
653
654td02(suite) ->
655    [];
656
657td02(Config) when is_list(Config) ->
658    {Exp,Res} = td02(),
659    ok = check(td02(doc),Exp,Res).
660
661td02() ->
662    %% put(encode_debug,dbg),
663    %% put(decode_debug,dbg),
664    Res = decode_encode(config1(),atid2()),
665    erase(encode_debug),
666    erase(decode_debug),
667    {error,Res}.
668
669
670%% --------------------------------------------------------
671
672%% basic_dec_enc02
673td03(doc) ->
674    "Basic decoding & then encoding test [2,2]\n  (binary -> asn -> binary)";
675
676td03(suite) ->
677    [];
678
679td03(Config) when is_list(Config) ->
680    {Exp,Res} = td03(),
681    ok = check(td03(doc),Exp,Res).
682
683td03() ->
684    %% put(encode_debug,dbg),
685    %% put(decode_debug,dbg),
686    Res = decode_encode(config2(),atid2()),
687    erase(encode_debug),
688    erase(decode_debug),
689    {ok,Res}.
690
691
692%% --------------------------------------------------------
693
694%% basic_dec_enc03
695td04(doc) ->
696    "Basic decoding & then encoding test [2,3]\n  (binary -> asn -> binary)";
697
698td04(suite) ->
699    [];
700
701td04(Config) when is_list(Config) ->
702    {Exp,Res} = td04(),
703    ok = check(td04(doc),Exp,Res).
704
705td04() ->
706    %% put(encode_debug,dbg),
707    %% put(decode_debug,dbg),
708    Res = decode_encode(config2(),atid3()),
709    erase(encode_debug),
710    erase(decode_debug),
711    {ok,Res}.
712
713
714%% --------------------------------------------------------
715
716%% basic_dec_enc04
717td05(doc) ->
718    "Basic decoding & then encoding test [2,4]\n  (binary -> asn -> binary)";
719
720td05(suite) ->
721    [];
722
723td05(Config) when is_list(Config) ->
724    {Exp,Res} = td05(),
725    ok = check(td05(doc),Exp,Res).
726
727td05() ->
728    %% put(encode_debug,dbg),
729    %% put(decode_debug,dbg),
730    Res = decode_encode(config2(),atid4()),
731    erase(encode_debug),
732    erase(decode_debug),
733    {ok,Res}.
734
735
736%% --------------------------------------------------------
737
738%% basic_dec_enc05
739td06(doc) ->
740    "Basic decoding & then encoding test [3,5]\n  (binary -> asn -> binary)";
741
742td06(suite) ->
743    [];
744
745td06(Config) when is_list(Config) ->
746    {Exp,Res} = td06(),
747    ok = check(td06(doc),Exp,Res).
748
749td06() ->
750    %% put(encode_debug,dbg),
751    %% put(decode_debug,dbg),
752    Res = decode_encode(config3(),atid5()),
753    erase(encode_debug),
754    erase(decode_debug),
755    {ok,Res}.
756
757
758%% --------------------------------------------------------
759%% --------------------------------------------------------
760
761encode_decode(C,T) ->
762    case encode(C,T) of
763	{ok,T1} ->
764	    case decode(C,T1) of
765		{ok,T2} ->
766		    {ok,T,T1,T2};
767		{error,R2} ->
768		    {error,{decode_error,T,T1,R2}};
769		{exit,E2} ->
770		    {error,{decode_exit,T,T1,E2}}
771	    end;
772	{error,R1} ->
773	    {error,{encode_error,T,R1}};
774	{exit,E1} ->
775	    {error,{encode_exit,T,E1}}
776    end.
777
778decode_encode(C,T) ->
779    case decode(C,T) of
780	{ok,T1} ->
781	    case encode(C,T1) of
782		{ok,T2} ->
783		    {ok,T,T1,T2};
784		{error,R2} ->
785		    {error,{encode_error,T,T1,R2}};
786		{exit,E2} ->
787		    {error,{encode_exit,T,T1,E2}}
788	    end;
789	{error,R1} ->
790	    {error,{decode_error,T,R1}};
791	{exit,E1} ->
792	    {error,{decode_exit,T,E1}}
793    end.
794
795%% ------------------
796
797config1() -> [3,8,5].
798config2() -> [3,5,4,8,4].
799config3() -> [3,5,4,16,4].
800config4() -> [8,8,8].  % Default config
801
802mtid01() ->
803    #megaco_term_id{contains_wildcards = false,
804		    id = [[$1,$0,$1],
805			  [$1,$1,$0,$1,$0,$0,$0,$1],
806			  [$1,$1,$0,$1,$1]]}.
807mtid02() ->
808    #megaco_term_id{contains_wildcards = true,
809		    id = [[$1,$0,$$],[$1,$1,$0,$1,$$],[$1,$1,$*]]}.
810mtid03() ->
811    #megaco_term_id{contains_wildcards = true,
812		    id = [[$1,$0,$1],[$1,$0,$1,$$],[$1,$1,$*]]}.
813mtid04() ->
814    #megaco_term_id{contains_wildcards = true,
815		    id = [[$1,$0,$$],[$1,$1,$0,$1,$$],[$1,$1,$1,$0,$0]]}.
816mtid05() ->
817    #megaco_term_id{contains_wildcards = true,
818		    id = [[$1,$0,$1],[$1,$1,$0,$1,$$],[$1,$1,$1,$0,$0]]}.
819mtid06() ->
820    #megaco_term_id{contains_wildcards = false,
821		    id = [[$1,$0,$$],[$1,$1,$0,$1,$$],[$1,$1,$*]]}.
822mtid07() ->
823    #megaco_term_id{contains_wildcards = true,
824		    id = [[$1,$0,$*],[$1,2,$0,$1,$$],[$1,$1,$1,$0,$0]]}.
825mtid08() ->
826    #megaco_term_id{contains_wildcards = true,
827		    id = [[$1,$0,$*,$1],[$1,$1,$0,$1,$$],[$1,$1,$1,$0,$0]]}.
828mtid09() ->
829    #megaco_term_id{contains_wildcards = true,
830		    id = [[$1,$0,$0,$1],[$1,$1,$0,$1,$$],[$1,$1,$1,$0,$0]]}.
831mtid10() ->
832    #megaco_term_id{contains_wildcards = true,
833		    id = [[$1,$0,$1],[$1,$0,$1,$$],[$$]]}.
834mtid11() ->
835    #megaco_term_id{contains_wildcards = true,
836		    id = [[$1,$0,$1],[$1,$0,$1,$$]]}.
837mtid12() ->
838    #megaco_term_id{contains_wildcards = true,
839		    id = [[$1,$0,$1],[$1,$0,$1,$0,$1,$1,$$]]}.
840mtid13() ->
841    #megaco_term_id{contains_wildcards = true,
842		    id = [[$1,$0,$*]]}.
843%% Empty last level
844%% mtid14() ->
845%%    #megaco_term_id{contains_wildcards = true,
846%%		    id = [[$1,$0,$*],[$1,$0,$0,$$],[]]}.
847
848%% Empty second level and missing last level
849mtid15() ->
850    #megaco_term_id{contains_wildcards = true,
851		    id = [[$1,$0,$*],[]]}.
852%% Megaco all wildcard termination id
853mtid16() ->
854	#megaco_term_id{contains_wildcards = true,
855			id                 = [[?megaco_all]]}.
856%% Megaco choose wildcard termination id
857mtid17() ->
858	#megaco_term_id{contains_wildcards = true,
859			id                 = [[?megaco_choose]]}.
860
861aroot() ->
862    #'TerminationID'{wildcard = [],
863		     id       = [16#FF, 16#FF, 16#FF, 16#FF,
864				 16#FF, 16#FF, 16#FF, 16#FF]}.
865atid1() -> aroot().
866atid2() ->
867    #'TerminationID'{wildcard = [],
868		     id       = [2#00000001, 02#00011110, 2#0]}.
869atid3() ->
870    #'TerminationID'{wildcard = [[2#00010111], [2#00000111]],
871		     id       = [2#0, 2#00011110, 2#0]}.
872atid4() ->
873    #'TerminationID'{wildcard = [[2#01001111]],
874		     id       = [2#0000001, 2#0, 2#0]}.
875%%
876atid5() ->
877    #'TerminationID'{wildcard = [[2#01001111]],
878		     id       = [2#00000001, 2#00110011,
879				 2#00000000, 2#00000000]}.
880
881%%--
882
883
884%% ------------------
885
886encode(C,T) ->
887    encode(get(encode_debug),C,T).
888
889encode(L,C,T) ->
890    put(dsev,L),
891    Res = encode1(C,T),
892    erase(dsev),
893    Res.
894
895encode1(C,T) ->
896    case (catch megaco_binary_term_id:encode(C,T)) of
897	{'EXIT',Reason} ->
898	    {exit,Reason};
899	Else ->
900	    Else
901    end.
902
903decode(C,T) ->
904    decode(get(decode_debug),C,T).
905
906decode(L,C,T) ->
907    put(dsev,L),
908    Res = decode1(C,T),
909    erase(dsev),
910    Res.
911
912decode1(C,T) ->
913    case (catch megaco_binary_term_id:decode(C,T)) of
914	{'EXIT',Reason} ->
915	    {exit,Reason};
916	Else ->
917	    Else
918    end.
919
920
921
922
923%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924
925check(D,ok,{ok,T1,T2,T3}) ->
926    Result = case check_ok_result(T1,T3) of
927		 ok ->
928		     ok;
929		 {error,Reason} ->
930		     io:format("  => inconsistent result"
931			       "~n  Start and end record differ"
932			       "~n  ~s"
933			       "~n  ~s"
934			       "~n  ~w"
935			       "~n",
936			       [D,Reason,T2]),
937		     warning
938	     end,
939    Result;
940check(D,error,{ok,T1,T2,T3}) ->
941    io:format("  => failed"
942	      "~n  ~s"
943	      "~n  ~p"
944	      "~n  ~p"
945	      "~n  ~p"
946	      "~n",
947	      [D,T1,T2,T3]),
948    error;
949check(_D,error,{error,_Reason}) ->
950    ok;
951check(D,ok,{error,Reason}) ->
952    io:format("  => failed"
953	      "~n  ~s"
954	      "~n  Failed for reason"
955	      "~n  ~p"
956	      "~n",
957	      [D,Reason]),
958    error.
959
960
961check_ok_result(R,R) when is_record(R,megaco_term_id) ->
962    ok; % Same record type and same record content
963check_ok_result(S,E) when is_record(S,megaco_term_id) andalso
964                          is_record(E,megaco_term_id) ->
965    Reason = check_megaco_term_id_record(S,E),
966    {error,Reason}; % Same record type but different record content
967check_ok_result(R,R) when is_record(R,'TerminationID') ->
968    ok;
969check_ok_result(S,E) when is_record(S,'TerminationID') andalso
970                          is_record(E,'TerminationID') ->
971    Reason = check_TerminationID_record(S,E),
972    {error,Reason}; % Same record type but different record content
973check_ok_result(_S,_E) ->
974    {error,"NOT THE SAME RECORD TYPES"}. % OOPS, Not even the same record type
975
976check_megaco_term_id_record(#megaco_term_id{contains_wildcards = Cw1,
977					    id = Id1},
978			    #megaco_term_id{contains_wildcards = Cw2,
979					    id = Id2}) ->
980    Result = case check_megaco_term_id_cw(Cw1,Cw2) of
981		 ok ->
982		     check_megaco_term_id_id(Id1,Id2);
983		 {error,R1} ->
984		     R2 = check_megaco_term_id_id(Id1,Id2),
985		     io_lib:format("~s~s",[R1,R2])
986             end,
987    lists:flatten(Result).
988
989check_megaco_term_id_cw(Cw,Cw) ->
990    ok;
991check_megaco_term_id_cw(Cw1,Cw2) ->
992    R = io_lib:format("~n   The 'contains_wildcard' property of the start"
993		      "~n   megaco_term_id record "
994		      "~n   has value ~w "
995		      "~n   but the end record "
996		      "~n   has value ~w",
997		      [Cw1,Cw2]),
998    {error,R}.
999
1000check_megaco_term_id_id(Id,Id) ->
1001    ok;
1002check_megaco_term_id_id(Id1,Id2) ->
1003    R = io_lib:format("~n   The 'id' property of the start"
1004		      "~n   megaco_term_id record "
1005		      "~n   has value ~w "
1006		      "~n   but the end record "
1007		      "~n   has value ~w",
1008		      [Id1,Id2]),
1009    {error,R}.
1010
1011
1012check_TerminationID_record(#'TerminationID'{wildcard = W1, id = Id1},
1013			   #'TerminationID'{wildcard = W2, id = Id2}) ->
1014    Result = case check_TerminationID_w(W1,W2) of
1015		 ok ->
1016		     check_TerminationID_id(Id1,Id2);
1017		 {error,R1} ->
1018		     R2 = check_TerminationID_id(Id1,Id2),
1019		     io_lib:format("~s~s",[R1,R2])
1020             end,
1021    lists:flatten(Result).
1022
1023check_TerminationID_w(W,W) ->
1024    ok;
1025check_TerminationID_w(W1,W2) ->
1026    R = io_lib:format("~n   The 'wildcard' property of the start"
1027		      "~n   'TerminationID' record "
1028		      "~n   has value ~w "
1029		      "~n   but the end record "
1030		      "~n   has value ~w",
1031		      [W1,W2]),
1032    {error,R}.
1033
1034check_TerminationID_id(Id,Id) ->
1035    ok;
1036check_TerminationID_id(Id1,Id2) ->
1037    R = io_lib:format("~n   The 'id' property of the start"
1038		      "~n   'TerminationID' record "
1039		      "~n   has value ~w "
1040		      "~n   but the end record "
1041		      "~n   has value ~w",
1042		      [Id1,Id2]),
1043    {error,R}.
1044
1045
1046%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047
1048%% p(F) ->
1049%%     p(F, []).
1050
1051p(F, A) ->
1052    p(get(sname), F, A).
1053
1054p(S, F, A) when is_list(S) ->
1055    io:format("*** [~s] ~p ~s ***"
1056	      "~n   " ++ F ++ "~n",
1057	      [?FTS(), self(), S | A]);
1058p(_S, F, A) ->
1059    io:format("*** [~s] ~p *** "
1060	      "~n   " ++ F ++ "~n",
1061	      [?FTS(), self() | A]).
1062
1063
1064