1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2003-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: Test encoding/decoding (codec) module of Megaco/H.248 v1
24%%----------------------------------------------------------------------
25
26-module(megaco_codec_v1_SUITE).
27
28%% ----
29
30-compile({no_auto_import,[error/1]}).
31
32%% ----
33
34-include_lib("megaco/include/megaco.hrl").
35-include_lib("megaco/include/megaco_message_v1.hrl").
36-include("megaco_test_lib.hrl").
37
38%% ----
39
40-export([msgs/0]).
41-export([rfc3525_msgs_display/0, rfc3525_msgs_test/0]).
42
43-export([
44 	 suite/0, all/0, groups/0,
45         init_per_suite/1, end_per_suite/1,
46         init_per_group/2, end_per_group/2,
47         init_per_testcase/2, end_per_testcase/2,
48
49	 pretty_test_msgs/1,
50
51	 compact_test_msgs/1,
52
53	 flex_pretty_init/1,
54	 flex_pretty_finish/1,
55	 flex_pretty_test_msgs/1,
56
57	 flex_compact_init/1,
58	 flex_compact_finish/1,
59	 flex_compact_test_msgs/1,
60	 flex_compact_dm_timers1/1,
61	 flex_compact_dm_timers2/1,
62	 flex_compact_dm_timers3/1,
63	 flex_compact_dm_timers4/1,
64	 flex_compact_dm_timers5/1,
65	 flex_compact_dm_timers6/1,
66
67	 bin_test_msgs/1,
68
69	 ber_test_msgs/1,
70
71	 per_test_msgs/1,
72
73	 erl_dist_m_test_msgs/1,
74
75	 compact_otp4011_msg1/1,
76	 compact_otp4011_msg2/1,
77	 compact_otp4011_msg3/1,
78	 compact_otp4013_msg1/1,
79	 compact_otp4085_msg1/1,
80	 compact_otp4085_msg2/1,
81	 compact_otp4280_msg1/1,
82	 compact_otp4299_msg1/1,
83	 compact_otp4299_msg2/1,
84	 compact_otp4359_msg1/1,
85	 compact_otp4920_msg0/1,
86	 compact_otp4920_msg1/1,
87	 compact_otp4920_msg2/1,
88	 compact_otp4920_msg3/1,
89	 compact_otp4920_msg4/1,
90	 compact_otp4920_msg5/1,
91	 compact_otp4920_msg6/1,
92	 compact_otp4920_msg7/1,
93	 compact_otp4920_msg8/1,
94	 compact_otp4920_msg9/1,
95	 compact_otp4920_msg10/1,
96	 compact_otp4920_msg11/1,
97	 compact_otp4920_msg12/1,
98	 compact_otp4920_msg20/1,
99	 compact_otp4920_msg21/1,
100	 compact_otp4920_msg22/1,
101	 compact_otp4920_msg23/1,
102	 compact_otp4920_msg24/1,
103	 compact_otp4920_msg25/1,
104	 compact_otp5186_msg01/1,
105	 compact_otp5186_msg02/1,
106	 compact_otp5186_msg03/1,
107	 compact_otp5186_msg04/1,
108	 compact_otp5186_msg05/1,
109	 compact_otp5186_msg06/1,
110	 compact_otp5793_msg01/1,
111	 compact_otp5993_msg01/1,
112	 compact_otp5993_msg02/1,
113	 compact_otp5993_msg03/1,
114	 compact_otp6017_msg01/1,
115	 compact_otp6017_msg02/1,
116	 compact_otp6017_msg03/1,
117
118         flex_compact_otp7431_msg01a/1,
119         flex_compact_otp7431_msg01b/1,
120         flex_compact_otp7431_msg02/1,
121         flex_compact_otp7431_msg03/1,
122         flex_compact_otp7431_msg04/1,
123         flex_compact_otp7431_msg05/1,
124         flex_compact_otp7431_msg06/1,
125         flex_compact_otp7431_msg07/1,
126
127	 pretty_otp4632_msg1/1,
128	 pretty_otp4632_msg2/1,
129	 pretty_otp4632_msg3/1,
130	 pretty_otp4632_msg4/1,
131	 pretty_otp4710_msg1/1,
132	 pretty_otp4710_msg2/1,
133	 pretty_otp4945_msg1/1,
134	 pretty_otp4945_msg2/1,
135	 pretty_otp4945_msg3/1,
136	 pretty_otp4945_msg4/1,
137	 pretty_otp4945_msg5/1,
138	 pretty_otp4945_msg6/1,
139	 pretty_otp4949_msg1/1,
140	 pretty_otp4949_msg2/1,
141	 pretty_otp4949_msg3/1,
142	 pretty_otp5042_msg1/1,
143	 pretty_otp5068_msg1/1,
144	 pretty_otp5085_msg1/1,
145	 pretty_otp5085_msg2/1,
146	 pretty_otp5085_msg3/1,
147	 pretty_otp5085_msg4/1,
148	 pretty_otp5085_msg5/1,
149	 pretty_otp5085_msg6/1,
150	 pretty_otp5085_msg7/1,
151         pretty_otp5600_msg1/1,
152         pretty_otp5600_msg2/1,
153         pretty_otp5601_msg1/1,
154         pretty_otp5793_msg01/1,
155	 pretty_otp5882_msg01/1,
156         pretty_otp6490_msg01/1,
157         pretty_otp6490_msg02/1,
158         pretty_otp6490_msg03/1,
159         pretty_otp6490_msg04/1,
160         pretty_otp6490_msg05/1,
161         pretty_otp6490_msg06/1,
162         pretty_otp7671_msg01/1,
163         pretty_otp7671_msg02/1,
164         pretty_otp7671_msg03/1,
165         pretty_otp7671_msg04/1,
166         pretty_otp7671_msg05/1,
167
168	 flex_pretty_otp5042_msg1/1,
169	 flex_pretty_otp5085_msg1/1,
170	 flex_pretty_otp5085_msg2/1,
171	 flex_pretty_otp5085_msg3/1,
172	 flex_pretty_otp5085_msg4/1,
173	 flex_pretty_otp5085_msg5/1,
174	 flex_pretty_otp5085_msg6/1,
175	 flex_pretty_otp5085_msg7/1,
176         flex_pretty_otp5600_msg1/1,
177         flex_pretty_otp5600_msg2/1,
178         flex_pretty_otp5601_msg1/1,
179         flex_pretty_otp5793_msg01/1,
180         flex_pretty_otp7431_msg01/1,
181         flex_pretty_otp7431_msg02/1,
182         flex_pretty_otp7431_msg03/1,
183         flex_pretty_otp7431_msg04/1,
184         flex_pretty_otp7431_msg05/1,
185         flex_pretty_otp7431_msg06/1,
186         flex_pretty_otp7431_msg07/1
187	]).
188
189-export([display_text_messages/0, generate_text_messages/0]).
190
191
192-export([msg15b/0, msg22f/0]).
193
194-export([
195	 %% Decode
196	 profile_decode_compact_text_message/1,
197	 profile_decode_compact_text_messages/0,
198	 prof1/0, prof2/0,
199	 profile_decode_compact_flex_text_message/1,
200	 profile_decode_compact_flex_text_messages/0,
201	 profile_decode_pretty_text_message/1,
202	 profile_decode_pretty_text_messages/0,
203	 profile_decode_pretty_flex_text_message/1,
204	 profile_decode_pretty_flex_text_messages/0,
205
206	 %% Encode
207	 profile_encode_compact_text_messages/0,
208	 profile_encode_pretty_text_messages/0
209	]).
210
211
212%% ----
213
214-define(V1,           v1).
215-define(EC,           []).
216-define(VERSION,      1).
217-define(VERSION_STR,  "1").
218-define(DEFAULT_PORT, 55555).
219-define(MSG_LIB,      megaco_test_msg_v1_lib).
220-define(MG1_MID_NO_PORT, {ip4Address,
221                          #'IP4Address'{address = [124, 124, 124, 222]}}).
222-define(MG1_MID, {ip4Address, #'IP4Address'{address = [124, 124, 124, 222],
223                                            portNumber = ?DEFAULT_PORT}}).
224-define(MG2_MID, {ip4Address, #'IP4Address'{address = [125, 125, 125, 111],
225                                            portNumber = ?DEFAULT_PORT}}).
226-define(MG3_MID, {ip6Address, #'IP6Address'{address = [0,0,0,0,
227						       0,0,0,0,
228						       0,0,0,0,
229						       125, 125, 125, 111],
230                                            portNumber = ?DEFAULT_PORT}}).
231-define(MGC_MID, {ip4Address, #'IP4Address'{address = [123, 123, 123, 4],
232                                            portNumber = ?DEFAULT_PORT}}).
233
234-define(A4444, ["11111111", "00000000", "00000000"]).
235-define(A4445, ["11111111", "00000000", "11111111"]).
236-define(A5555, ["11111111", "11111111", "00000000"]).
237-define(A5556, ["11111111", "11111111", "11111111"]).
238
239
240%%======================================================================
241%% Common Test interface functions
242%%======================================================================
243
244suite() ->
245    [{ct_hooks, [ts_install_cth]}].
246
247all() ->
248    [
249     {group, text},
250     {group, binary},
251     {group, erl_dist},
252     {group, tickets}
253    ].
254
255groups() ->
256    [
257     {text,                 [], text_cases()},
258     {binary,               [], binary_cases()},
259     {erl_dist,             [], erl_dist_cases()},
260     {pretty,               [], pretty_cases()},
261     {compact,              [], compact_cases()},
262     {flex_pretty,          [], flex_pretty_cases()},
263     {flex_compact,         [], flex_compact_cases()},
264     {bin,                  [], bin_cases()},
265     {ber,                  [], ber_cases()},
266     {per,                  [], per_cases()},
267     {erl_dist_m,           [], erl_dist_m_cases()},
268     {tickets,              [], tickets_cases()},
269     {compact_tickets,      [], compact_tickets_cases()},
270     {flex_compact_tickets, [], flex_compact_tickets_cases()},
271     {pretty_tickets,       [], pretty_tickets_cases()},
272     {flex_pretty_tickets,  [], flex_pretty_tickets_cases()}
273    ].
274
275text_cases() ->
276    [
277     {group, pretty},
278     {group, flex_pretty},
279     {group, compact},
280     {group, flex_compact}
281    ].
282
283binary_cases() ->
284    [
285     {group, bin},
286     {group, ber},
287     {group, per}
288    ].
289
290erl_dist_cases() ->
291    [
292     {group, erl_dist_m}
293    ].
294
295pretty_cases() ->
296    [
297     pretty_test_msgs
298    ].
299
300compact_cases() ->
301    [
302     compact_test_msgs
303    ].
304
305flex_pretty_cases() ->
306    [
307     flex_pretty_test_msgs
308    ].
309
310flex_compact_cases() ->
311    [
312     flex_compact_test_msgs,
313     flex_compact_dm_timers1,
314     flex_compact_dm_timers2,
315     flex_compact_dm_timers3,
316     flex_compact_dm_timers4,
317     flex_compact_dm_timers5,
318     flex_compact_dm_timers6
319    ].
320
321bin_cases() ->
322    [
323     bin_test_msgs
324    ].
325
326ber_cases() ->
327    [
328     ber_test_msgs
329    ].
330
331per_cases() ->
332    [
333     per_test_msgs
334    ].
335
336erl_dist_m_cases() ->
337    [
338     erl_dist_m_test_msgs
339    ].
340
341tickets_cases() ->
342    [
343     {group, compact_tickets},
344     {group, pretty_tickets},
345     {group, flex_compact_tickets},
346     {group, flex_pretty_tickets}
347    ].
348
349compact_tickets_cases() ->
350    [
351     compact_otp4011_msg1,
352     compact_otp4011_msg2,
353     compact_otp4011_msg3,
354     compact_otp4013_msg1,
355     compact_otp4085_msg1,
356     compact_otp4085_msg2,
357     compact_otp4280_msg1,
358     compact_otp4299_msg1,
359     compact_otp4299_msg2,
360     compact_otp4359_msg1,
361     compact_otp4920_msg0,
362     compact_otp4920_msg1,
363     compact_otp4920_msg2,
364     compact_otp4920_msg3,
365     compact_otp4920_msg4,
366     compact_otp4920_msg5,
367     compact_otp4920_msg6,
368     compact_otp4920_msg7,
369     compact_otp4920_msg8,
370     compact_otp4920_msg9,
371     compact_otp4920_msg10,
372     compact_otp4920_msg11,
373     compact_otp4920_msg12,
374     compact_otp4920_msg20,
375     compact_otp4920_msg21,
376     compact_otp4920_msg22,
377     compact_otp4920_msg23,
378     compact_otp4920_msg24,
379     compact_otp4920_msg25,
380     compact_otp5186_msg01,
381     compact_otp5186_msg02,
382     compact_otp5186_msg03,
383     compact_otp5186_msg04,
384     compact_otp5186_msg05,
385     compact_otp5186_msg06,
386     compact_otp5793_msg01,
387     compact_otp5993_msg01,
388     compact_otp5993_msg02,
389     compact_otp5993_msg03,
390     compact_otp6017_msg01,
391     compact_otp6017_msg02,
392     compact_otp6017_msg03
393    ].
394
395flex_compact_tickets_cases() ->
396    [
397     flex_compact_otp7431_msg01a,
398     flex_compact_otp7431_msg01b,
399     flex_compact_otp7431_msg02,
400     flex_compact_otp7431_msg03,
401     flex_compact_otp7431_msg04,
402     flex_compact_otp7431_msg05,
403     flex_compact_otp7431_msg06,
404     flex_compact_otp7431_msg07
405    ].
406
407pretty_tickets_cases() ->
408    [
409     pretty_otp4632_msg1,
410     pretty_otp4632_msg2,
411     pretty_otp4632_msg3,
412     pretty_otp4632_msg4,
413     pretty_otp4710_msg1,
414     pretty_otp4710_msg2,
415     pretty_otp4945_msg1,
416     pretty_otp4945_msg2,
417     pretty_otp4945_msg3,
418     pretty_otp4945_msg4,
419     pretty_otp4945_msg5,
420     pretty_otp4945_msg6,
421     pretty_otp4949_msg1,
422     pretty_otp4949_msg2,
423     pretty_otp4949_msg3,
424     pretty_otp5042_msg1,
425     pretty_otp5068_msg1,
426     pretty_otp5085_msg1,
427     pretty_otp5085_msg2,
428     pretty_otp5085_msg3,
429     pretty_otp5085_msg4,
430     pretty_otp5085_msg5,
431     pretty_otp5085_msg6,
432     pretty_otp5085_msg7,
433     pretty_otp5600_msg1,
434     pretty_otp5600_msg2,
435     pretty_otp5601_msg1,
436     pretty_otp5793_msg01,
437     pretty_otp5882_msg01,
438     pretty_otp6490_msg01,
439     pretty_otp6490_msg02,
440     pretty_otp6490_msg03,
441     pretty_otp6490_msg04,
442     pretty_otp6490_msg05,
443     pretty_otp6490_msg06,
444     pretty_otp7671_msg01,
445     pretty_otp7671_msg02,
446     pretty_otp7671_msg03,
447     pretty_otp7671_msg04,
448     pretty_otp7671_msg05
449    ].
450
451flex_pretty_tickets_cases() ->
452    [
453     flex_pretty_otp5042_msg1,
454     flex_pretty_otp5085_msg1,
455     flex_pretty_otp5085_msg2,
456     flex_pretty_otp5085_msg3,
457     flex_pretty_otp5085_msg4,
458     flex_pretty_otp5085_msg5,
459     flex_pretty_otp5085_msg6,
460     flex_pretty_otp5085_msg7,
461     flex_pretty_otp5600_msg1,
462     flex_pretty_otp5600_msg2,
463     flex_pretty_otp5601_msg1,
464     flex_pretty_otp5793_msg01,
465     flex_pretty_otp7431_msg01,
466     flex_pretty_otp7431_msg02,
467     flex_pretty_otp7431_msg03,
468     flex_pretty_otp7431_msg04,
469     flex_pretty_otp7431_msg05,
470     flex_pretty_otp7431_msg06,
471     flex_pretty_otp7431_msg07
472    ].
473
474
475%%
476%% -----
477%%
478
479init_per_suite(suite) ->
480    [];
481init_per_suite(doc) ->
482    [];
483init_per_suite(Config0) when is_list(Config0) ->
484
485    ?ANNOUNCE_SUITE_INIT(),
486
487    p("init_per_suite -> entry with"
488      "~n      Config: ~p"
489      "~n      Nodes:  ~p", [Config0, erlang:nodes()]),
490
491    case ?LIB:init_per_suite(Config0) of
492        {skip, _} = SKIP ->
493            SKIP;
494
495        Config1 when is_list(Config1) ->
496
497            %% We need a (local) monitor on this node also
498            megaco_test_sys_monitor:start(),
499
500            p("init_per_suite -> end when"
501              "~n      Config: ~p"
502              "~n      Nodes:  ~p", [Config1, erlang:nodes()]),
503
504            Config1
505    end.
506
507end_per_suite(suite) -> [];
508end_per_suite(doc) -> [];
509end_per_suite(Config0) when is_list(Config0) ->
510
511    p("end_per_suite -> entry with"
512      "~n      Config: ~p"
513      "~n      Nodes:  ~p", [Config0, erlang:nodes()]),
514
515    megaco_test_sys_monitor:stop(),
516    Config1 = ?LIB:end_per_suite(Config0),
517
518    p("end_per_suite -> end when"
519      "~n      Nodes:  ~p", [erlang:nodes()]),
520
521    Config1.
522
523
524%%
525%% -----
526%%
527
528init_per_group(flex_pretty_tickets = Group, Config) ->
529    ?ANNOUNCE_GROUP_INIT(Group),
530    flex_pretty_init(Config);
531init_per_group(flex_compact_tickets = Group, Config) ->
532    ?ANNOUNCE_GROUP_INIT(Group),
533    flex_compact_init(Config);
534init_per_group(flex_compact = Group, Config) ->
535    ?ANNOUNCE_GROUP_INIT(Group),
536    flex_compact_init(Config);
537init_per_group(flex_pretty = Group, Config) ->
538    ?ANNOUNCE_GROUP_INIT(Group),
539    flex_pretty_init(Config);
540init_per_group(Group, Config) ->
541    ?ANNOUNCE_GROUP_INIT(Group),
542    Config.
543
544end_per_group(flex_pretty_tickets, Config) ->
545    flex_pretty_finish(Config);
546end_per_group(flex_compact_tickets, Config) ->
547    flex_compact_finish(Config);
548end_per_group(flex_compact, Config) ->
549    flex_compact_finish(Config);
550end_per_group(flex_pretty, Config) ->
551    flex_pretty_finish(Config);
552end_per_group(_GroupName, Config) ->
553    Config.
554
555
556
557%%
558%% -----
559%%
560
561init_per_testcase(Case, Config) ->
562    %% We do *not* reset events with each test case
563    %% The test cases are so short we don't bother,
564    %% and also we would drown in mprintouts...
565    put(verbosity, trc),
566    megaco_test_lib:init_per_testcase(Case, Config).
567
568end_per_testcase(Case, Config) ->
569    erase(verbosity),
570    megaco_test_lib:end_per_testcase(Case, Config).
571
572
573%%======================================================================
574
575display_text_messages() ->
576    Msgs =
577	msgs1() ++
578	msgs3(),
579    megaco_codec_test_lib:display_text_messages(?VERSION, Msgs).
580
581
582generate_text_messages() ->
583    Msgs =
584	msgs1(),
585    megaco_codec_test_lib:generate_text_messages(?V1, ?VERSION, ?EC, Msgs).
586
587
588%% ----
589
590prof1() ->
591    megaco_codec_v1_test:profile_decode_compact_text_message(msg10).
592
593prof2() ->
594    megaco_codec_v1_test:profile_decode_compact_flex_text_message(msg10).
595
596%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg01a)).
597%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg01b)).
598%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg02)).
599%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg10)).
600%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg11)).
601%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg12)).
602%% (catch megaco_codec_v1_test:profile_decode_compact_text_message(msg13)).
603profile_decode_compact_text_message(MsgTag) when is_atom(MsgTag) ->
604    Config = [],
605    Slogan = list_to_atom("decode_compact_v1_" ++ atom_to_list(MsgTag)),
606    profile_decode_compact_text_message(Slogan, Config, MsgTag).
607
608profile_decode_compact_flex_text_message(MsgTag) when is_atom(MsgTag) ->
609    Conf   = flex_init([]),
610    Config = flex_scanner_conf(Conf),
611    Slogan = list_to_atom("decode_compact_flex_v1_" ++  atom_to_list(MsgTag)),
612    Res    = profile_decode_compact_text_message(Slogan, [Config], MsgTag),
613    flex_finish(Conf),
614    Res.
615
616profile_decode_compact_text_message(Slogan, Config, MsgTag) ->
617    Codec = megaco_compact_text_encoder,
618    profile_decode_text_message(Slogan, Codec, Config, MsgTag).
619
620%% (catch megaco_codec_v1_test:profile_decode_pretty_text_message(msg01a)).
621%% (catch megaco_codec_v1_test:profile_decode_pretty_text_message(msg01b)).
622%% (catch megaco_codec_v1_test:profile_decode_pretty_text_message(msg02)).
623profile_decode_pretty_text_message(MsgTag) when is_atom(MsgTag) ->
624    Config = [],
625    Slogan = list_to_atom("decode_pretty_v1_" ++ atom_to_list(MsgTag)),
626    profile_decode_pretty_text_message(Slogan, Config, MsgTag).
627
628profile_decode_pretty_flex_text_message(MsgTag) when is_atom(MsgTag) ->
629    Conf   = flex_init([]),
630    Config = flex_scanner_conf(Conf),
631    Slogan = list_to_atom("decode_pretty_flex_v1_" ++  atom_to_list(MsgTag)),
632    Res    = profile_decode_pretty_text_message(Slogan, [Config], MsgTag),
633    flex_finish(Conf),
634    Res.
635
636profile_decode_pretty_text_message(Slogan, Config, MsgTag) ->
637    Codec = megaco_pretty_text_encoder,
638    profile_decode_text_message(Slogan, Codec, Config, MsgTag).
639
640profile_decode_text_message(Slogan, Codec, Config, MsgTag) ->
641    Msgs = msgs1(),
642    case lists:keysearch(MsgTag, 1, Msgs) of
643	{value, Msg} ->
644	    [Res] = profile_decode_text_messages(Slogan, Codec, Config, [Msg]),
645	    Res;
646	false ->
647	    {error, {no_such_message, MsgTag}}
648    end.
649
650
651%% (catch megaco_codec_v1_test:profile_decode_compact_text_messages()).
652profile_decode_compact_text_messages() ->
653    Config = [],
654    Slogan = decode_compact_v1,
655    profile_decode_compact_text_messages(Slogan, Config).
656
657%% (catch megaco_codec_v1_test:profile_decode_compact_flex_text_messages()).
658profile_decode_compact_flex_text_messages() ->
659    Conf   = flex_init([]),
660    Config = flex_scanner_conf(Conf),
661    Slogan = decode_compact_flex_v1,
662    Res = profile_decode_compact_text_messages(Slogan, [Config]),
663    flex_finish(Conf),
664    Res.
665
666profile_decode_compact_text_messages(Slogan, Config) ->
667    Codec = megaco_compact_text_encoder,
668    profile_decode_text_messages(Slogan, Codec, Config).
669
670%% (catch megaco_codec_v1_test:profile_decode_pretty_text_messages()).
671profile_decode_pretty_text_messages() ->
672    Config = [],
673    Slogan = decode_pretty_v1,
674    profile_decode_pretty_text_messages(Slogan, Config).
675
676%% (catch megaco_codec_v1_test:profile_decode_pretty_flex_text_messages()).
677profile_decode_pretty_flex_text_messages() ->
678    Conf   = flex_init([]),
679    Config = flex_scanner_conf(Conf),
680    Slogan = decode_pretty_flex_v1,
681    Res    = profile_decode_pretty_text_messages(Slogan, [Config]),
682    flex_finish(Conf),
683    Res.
684
685
686profile_decode_pretty_text_messages(Slogan, Config) ->
687    Codec = megaco_pretty_text_encoder,
688    profile_decode_text_messages(Slogan, Codec, Config).
689
690profile_decode_text_messages(Slogan, Codec, Config) ->
691    Msgs = msgs1(),
692    profile_decode_text_messages(Slogan, Codec, Config, Msgs).
693
694profile_decode_text_messages(Slogan, Codec, Config, Msgs0) ->
695    Msgs      = [Msg || {_, Msg, _, _} <- Msgs0],
696    EncodeRes = encode_text_messages(Codec, Config, Msgs, []),
697    Bins      = [Bin || {ok, Bin} <- EncodeRes],
698    Fun = fun() ->
699		decode_text_messages(Codec, Config, Bins, [])
700	  end,
701    %% Make a dry run, just to make sure all modules are loaded:
702    io:format("make a dry run...~n", []),
703    (catch Fun()),
704    io:format("make the run...~n", []),
705    megaco_profile:profile(Slogan, Fun).
706
707%% (catch megaco_codec_v1_test:profile_encode_compact_text_messages()).
708profile_encode_compact_text_messages() ->
709    Codec  = megaco_compact_text_encoder,
710    Config = [],
711    Slogan = encode_compact_v1,
712    profile_encode_text_messages(Slogan, Codec, Config).
713
714%% (catch megaco_codec_v1_test:profile_encode_pretty_text_messages()).
715profile_encode_pretty_text_messages() ->
716    Codec  = megaco_pretty_text_encoder,
717    Config = [],
718    Slogan = encode_pretty_v1,
719    profile_encode_text_messages(Slogan, Codec, Config).
720
721profile_encode_text_messages(Slogan, Codec, Config) ->
722    Msgs = msgs1(),
723    profile_encode_text_messages(Slogan, Codec, Config, Msgs).
724
725profile_encode_text_messages(Slogan, Codec, Config, Msgs0) ->
726    Msgs = [Msg || {_, Msg, _, _} <- Msgs0],
727    Fun = fun() ->
728		encode_text_messages(Codec, Config, Msgs, [])
729	  end,
730    %% Make a dry run, just to make sure all modules are loaded:
731    io:format("make a dry run...~n", []),
732    (catch Fun()),
733    io:format("make the run...~n", []),
734    megaco_profile:profile(Slogan, Fun).
735
736encode_text_messages(_Codec, _Config, [], Acc) ->
737    Acc;
738encode_text_messages(Codec, Config, [Msg|Msgs], Acc) ->
739    Res = Codec:encode_message(Config, ?VERSION, Msg),
740    encode_text_messages(Codec, Config, Msgs, [Res | Acc]).
741
742decode_text_messages(_Codec, _Config, [], Acc) ->
743    Acc;
744decode_text_messages(Codec, Config, [Msg|Msgs], Acc) ->
745    Res = Codec:decode_message(Config, dynamic, Msg),
746    decode_text_messages(Codec, Config, Msgs, [Res | Acc]).
747
748
749
750%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
751
752pretty_test_msgs(suite) ->
753    [];
754pretty_test_msgs(Config) when is_list(Config) ->
755    ?ACQUIRE_NODES(1, Config),
756    Msgs = msgs1() ++ msgs2() ++ msgs3(),
757    DynamicDecode = false,
758    test_msgs(megaco_pretty_text_encoder, DynamicDecode, [], Msgs).
759
760
761%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
762
763flex_pretty_init(Config) ->
764    flex_init(Config).
765
766flex_pretty_finish(Config) ->
767    flex_finish(Config).
768
769
770flex_pretty_test_msgs(suite) ->
771    [];
772flex_pretty_test_msgs(Config) when is_list(Config) ->
773    ?ACQUIRE_NODES(1, Config),
774    %% Msgs = msgs1(),
775    Msgs = msgs1() ++ msgs2() ++ msgs3(),
776    Conf = flex_scanner_conf(Config),
777    DynamicDecode = false,
778    test_msgs(megaco_pretty_text_encoder, DynamicDecode, [Conf], Msgs).
779
780flex_pretty_otp5042_msg1(suite) ->
781    [];
782flex_pretty_otp5042_msg1(Config) when is_list(Config) ->
783    d("flex_pretty_otp5042_msg1 -> entry", []),
784    ?ACQUIRE_NODES(1, Config),
785    Msg0 = pretty_otp5042_msg1(),
786    Bin0 = list_to_binary(Msg0),
787    Conf = flex_scanner_conf(Config),
788    case decode_message(megaco_pretty_text_encoder, false, [Conf], Bin0) of
789	{error, [{reason, Reason}|_]} ->
790	    case Reason of
791		{_, _Mod, {not_an_integer, PropertyParm}} ->
792		    exit({not_an_integer, PropertyParm});
793		_ ->
794		    io:format("flex_pretty_otp5042_msg1 -> "
795			      "~n   Reason: ~w"
796			      "~n", [Reason]),
797		    exit({unexpected_decode_result, Reason})
798	    end;
799	{ok, M} ->
800	    t("flex_pretty_otp5042_msg1 -> successfull decode:"
801	      "~n~p", [M]),
802	    ok
803    end.
804
805
806flex_pretty_otp5085_msg1(suite) ->
807    [];
808flex_pretty_otp5085_msg1(Config) when is_list(Config) ->
809    d("flex_pretty_otp5085_msg1 -> entry", []),
810    ?ACQUIRE_NODES(1, Config),
811    Conf = flex_scanner_conf(Config),
812    pretty_otp5085(ok, pretty_otp5085_msg1(), [Conf]).
813
814flex_pretty_otp5085_msg2(suite) ->
815    [];
816flex_pretty_otp5085_msg2(Config) when is_list(Config) ->
817    d("flex_pretty_otp5085_msg2 -> entry", []),
818    ?ACQUIRE_NODES(1, Config),
819    Conf = flex_scanner_conf(Config),
820    pretty_otp5085(error, pretty_otp5085_msg2(), [Conf]).
821
822flex_pretty_otp5085_msg3(suite) ->
823    [];
824flex_pretty_otp5085_msg3(Config) when is_list(Config) ->
825    d("flex_pretty_otp5085_msg3 -> entry", []),
826    ?ACQUIRE_NODES(1, Config),
827    Conf = flex_scanner_conf(Config),
828    pretty_otp5085(ok, pretty_otp5085_msg3(), [Conf]).
829
830flex_pretty_otp5085_msg4(suite) ->
831    [];
832flex_pretty_otp5085_msg4(Config) when is_list(Config) ->
833    d("flex_pretty_otp5085_msg4 -> entry", []),
834    ?ACQUIRE_NODES(1, Config),
835    Conf = flex_scanner_conf(Config),
836    pretty_otp5085(ok, pretty_otp5085_msg4(), [Conf]).
837
838flex_pretty_otp5085_msg5(suite) ->
839    [];
840flex_pretty_otp5085_msg5(Config) when is_list(Config) ->
841    d("flex_pretty_otp5085_msg5 -> entry", []),
842    ?ACQUIRE_NODES(1, Config),
843    Conf = flex_scanner_conf(Config),
844    pretty_otp5085(ok, pretty_otp5085_msg5(), [Conf]).
845
846flex_pretty_otp5085_msg6(suite) ->
847    [];
848flex_pretty_otp5085_msg6(Config) when is_list(Config) ->
849    d("flex_pretty_otp5085_msg6 -> entry", []),
850    ?ACQUIRE_NODES(1, Config),
851    Conf = flex_scanner_conf(Config),
852    pretty_otp5085(ok, pretty_otp5085_msg6(), [Conf]).
853
854flex_pretty_otp5085_msg7(suite) ->
855    [];
856flex_pretty_otp5085_msg7(Config) when is_list(Config) ->
857    d("flex_pretty_otp5085_msg7 -> entry", []),
858    ?ACQUIRE_NODES(1, Config),
859    Conf = flex_scanner_conf(Config),
860    pretty_otp5085(ok, pretty_otp5085_msg7(), [Conf]).
861
862flex_pretty_otp5600_msg1(suite) ->
863    [];
864flex_pretty_otp5600_msg1(Config) when is_list(Config) ->
865    d("flex_pretty_otp5600_msg1 -> entry", []),
866    ?ACQUIRE_NODES(1, Config),
867    Conf = flex_scanner_conf(Config),
868    pretty_otp5600(ok, pretty_otp5600_msg1(), [Conf]).
869
870flex_pretty_otp5600_msg2(suite) ->
871    [];
872flex_pretty_otp5600_msg2(Config) when is_list(Config) ->
873    d("flex_pretty_otp5600_msg2 -> entry", []),
874    ?ACQUIRE_NODES(1, Config),
875    Conf = flex_scanner_conf(Config),
876    pretty_otp5600(ok, pretty_otp5600_msg2(), [Conf]).
877
878flex_pretty_otp5601_msg1(suite) ->
879    [];
880flex_pretty_otp5601_msg1(Config) when is_list(Config) ->
881    d("flex_pretty_otp5601_msg1 -> entry", []),
882    ?ACQUIRE_NODES(1, Config),
883    Conf = flex_scanner_conf(Config),
884    pretty_otp5601(ok, pretty_otp5601_msg1(), [Conf]).
885
886flex_pretty_otp5793_msg01(suite) ->
887    [];
888flex_pretty_otp5793_msg01(Config) when is_list(Config) ->
889    d("flex_pretty_otp5793_msg01 -> entry", []),
890    ?ACQUIRE_NODES(1, Config),
891    Conf = flex_scanner_conf(Config),
892    pretty_otp5793(ok, pretty_otp5793_msg1(), [Conf]).
893
894flex_pretty_otp7431_msg01(suite) ->
895    [];
896flex_pretty_otp7431_msg01(Config) when is_list(Config) ->
897    d("flex_pretty_otp7431_msg01 -> entry", []),
898    ?ACQUIRE_NODES(1, Config),
899    Conf = flex_scanner_conf(Config),
900    flex_pretty_otp7431(ok, flex_pretty_otp7431_msg1(), [Conf]).
901
902flex_pretty_otp7431_msg02(suite) ->
903    [];
904flex_pretty_otp7431_msg02(Config) when is_list(Config) ->
905%%     put(severity,trc),
906%%     put(dbg,true),
907    d("flex_pretty_otp7431_msg02 -> entry", []),
908    ?ACQUIRE_NODES(1, Config),
909    Conf = flex_scanner_conf(Config),
910    flex_pretty_otp7431(error, flex_pretty_otp7431_msg2(), [Conf]).
911
912flex_pretty_otp7431_msg03(suite) ->
913    [];
914flex_pretty_otp7431_msg03(Config) when is_list(Config) ->
915%%     put(severity,trc),
916%%     put(dbg,true),
917    d("flex_pretty_otp7431_msg03 -> entry", []),
918    ?ACQUIRE_NODES(1, Config),
919    Conf = flex_scanner_conf(Config),
920    flex_pretty_otp7431(error, flex_pretty_otp7431_msg3(), [Conf]).
921
922flex_pretty_otp7431_msg04(suite) ->
923    [];
924flex_pretty_otp7431_msg04(Config) when is_list(Config) ->
925    d("flex_pretty_otp7431_msg04 -> entry", []),
926    ?ACQUIRE_NODES(1, Config),
927    Conf = flex_scanner_conf(Config),
928    flex_pretty_otp7431(error, flex_pretty_otp7431_msg4(), [Conf]).
929
930flex_pretty_otp7431_msg05(suite) ->
931    [];
932flex_pretty_otp7431_msg05(Config) when is_list(Config) ->
933    d("flex_pretty_otp7431_msg05 -> entry", []),
934    ?ACQUIRE_NODES(1, Config),
935    Conf = flex_scanner_conf(Config),
936    flex_pretty_otp7431(error, flex_pretty_otp7431_msg5(), [Conf]).
937
938flex_pretty_otp7431_msg06(suite) ->
939    [];
940flex_pretty_otp7431_msg06(Config) when is_list(Config) ->
941    d("flex_pretty_otp7431_msg06 -> entry", []),
942    ?ACQUIRE_NODES(1, Config),
943    Conf = flex_scanner_conf(Config),
944    flex_pretty_otp7431(error, flex_pretty_otp7431_msg6(), [Conf]).
945
946flex_pretty_otp7431_msg07(suite) ->
947    [];
948flex_pretty_otp7431_msg07(Config) when is_list(Config) ->
949    d("flex_pretty_otp7431_msg07 -> entry", []),
950    ?ACQUIRE_NODES(1, Config),
951    Conf = flex_scanner_conf(Config),
952    flex_pretty_otp7431(error, flex_pretty_otp7431_msg7(), [Conf]).
953
954flex_pretty_otp7431(Expected, Msg, Conf) ->
955    otp7431(Expected, megaco_pretty_text_encoder, Msg, Conf).
956
957otp7431(Expected, Codec, Msg0, Conf) ->
958    Bin0 = list_to_binary(Msg0),
959    case decode_message(Codec, false, Conf, Bin0) of
960	{ok, _Msg1} when Expected =:= ok ->
961 	    io:format(" decoded", []),
962	    ok;
963	{error, {bad_property_parm, Reason}} when (Expected =:= error) andalso
964						  is_list(Reason) ->
965	    io:format("expected result: ~s", [Reason]),
966	    ok;
967	Else ->
968	    io:format("unexpected result", []),
969	    exit({unexpected_decode_result, Else})
970    end.
971
972
973flex_pretty_otp7431_msg1() ->
974"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
975   Context = 2000 {
976      Add = A4444,
977      Add = A4445 {
978         Media {
979            Stream = 1 {
980               Local {
981v=0
982o=- 2890844526 2890842807 IN IP4 124.124.124.222
983s=-
984t= 0 0
985c=IN IP4 124.124.124.222
986m=audio 2222 RTP/AVP 4
987a=ptime:30
988a=recvonly
989               } ; RTP profile for G.723.1 is 4
990            }
991         }
992      }
993   }
994}".
995
996flex_pretty_otp7431_msg2() ->
997"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
998   Context = 2000 {
999      Add = A4444,
1000      Add = A4445 {
1001         Media {
1002            Stream = 1 {
1003               Local {
1004v=0
1005o=- 2890844526 2890842807 IN IP4 124.124.124.222
1006s=-
1007t= 0 0
1008c=IN IP4 124.124.124.222
1009m=audio 2222 RTP/AVP 4
1010a=ptime:30
1011a=             }
1012            }
1013         }
1014      }
1015   }
1016}".
1017
1018flex_pretty_otp7431_msg3() ->
1019"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
1020   Context = 2000 {
1021      Add = A4444,
1022      Add = A4445 {
1023         Media {
1024            Stream = 1 {
1025               Local {
1026v=0
1027o=- 2890844526 2890842807 IN IP4 124.124.124.222
1028s=-
1029t= 0 0
1030c=IN IP4 124.124.124.222
1031m=audio 2222 RTP/AVP 4
1032a=ptime:30
1033a             }
1034            }
1035         }
1036      }
1037   }
1038}".
1039
1040flex_pretty_otp7431_msg4() ->
1041"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
1042   Context = 2000 {
1043      Add = A4444,
1044      Add = A4445 {
1045         Media {
1046            Stream = 1 {
1047               Local {
1048v=0
1049o=- 2890844526 2890842807 IN IP4 124.124.124.222
1050s=-
1051t= 0 0
1052c=IN IP4 124.124.124.222
1053m=audio 2222 RTP/AVP 4
1054a=ptime:30
1055a}
1056            }
1057         }
1058      }
1059   }
1060}".
1061
1062flex_pretty_otp7431_msg5() ->
1063"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
1064   Context = 2000 {
1065      Add = A4444,
1066      Add = A4445 {
1067         Media {
1068            Stream = 1 {
1069               Local {
1070v=            }
1071            }
1072         }
1073      }
1074   }
1075}".
1076
1077flex_pretty_otp7431_msg6() ->
1078"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
1079   Context = 2000 {
1080      Add = A4444,
1081      Add = A4445 {
1082         Media {
1083            Stream = 1 {
1084               Local {
1085v            }
1086            }
1087         }
1088      }
1089   }
1090}".
1091
1092flex_pretty_otp7431_msg7() ->
1093"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
1094   Context = 2000 {
1095      Add = A4444,
1096      Add = A4445 {
1097         Media {
1098            Stream = 1 {
1099               Local {
1100v}
1101            }
1102         }
1103      }
1104   }
1105}".
1106
1107
1108
1109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1110
1111compact_test_msgs(suite) ->
1112    [];
1113compact_test_msgs(Config) when is_list(Config) ->
1114    ?ACQUIRE_NODES(1, Config),
1115    Msgs = msgs1() ++ msgs2() ++ msgs3(),
1116    DynamicDecode = false,
1117    test_msgs(megaco_compact_text_encoder, DynamicDecode, [], Msgs).
1118
1119
1120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1121
1122flex_compact_init(Config) ->
1123    flex_init(Config).
1124
1125
1126flex_compact_finish(Config) ->
1127    flex_finish(Config).
1128
1129
1130flex_compact_test_msgs(suite) ->
1131    [];
1132flex_compact_test_msgs(Config) when is_list(Config) ->
1133    ?ACQUIRE_NODES(1, Config),
1134    Msgs = msgs1() ++ msgs2() ++ msgs3(),
1135    %% Msgs = msgs1(),
1136    Conf = flex_scanner_conf(Config),
1137    DynamicDecode = true,
1138    test_msgs(megaco_compact_text_encoder, DynamicDecode, [Conf], Msgs).
1139
1140
1141flex_compact_dm_timers1(suite) ->
1142    [];
1143flex_compact_dm_timers1(Config) when is_list(Config) ->
1144    ?ACQUIRE_NODES(1, Config),
1145    M = build_dm_timers_message("1", "2", "3"),
1146    B = list_to_binary(M),
1147    Conf = flex_scanner_conf(Config),
1148    case decode_message(megaco_compact_text_encoder, false, [Conf], B) of
1149	{ok, M1} when is_record(M1,'MegacoMessage') ->
1150	    t("flex_compact_dm_timers1 -> "
1151	      "~n   M:  ~s"
1152	      "~n   M1: ~p", [M, M1]),
1153	    verify_dm_timers(1,2,3, M1);
1154	Else ->
1155	    exit({decode_failed, M, Else})
1156    end.
1157
1158
1159flex_compact_dm_timers2(suite) ->
1160    [];
1161flex_compact_dm_timers2(Config) when is_list(Config) ->
1162    ?ACQUIRE_NODES(1, Config),
1163    M = build_dm_timers_message("02", "03", "04"),
1164    B = list_to_binary(M),
1165    Conf = flex_scanner_conf(Config),
1166    case decode_message(megaco_compact_text_encoder, false, [Conf], B) of
1167	{ok, M1} when is_record(M1,'MegacoMessage') ->
1168	    t("flex_compact_dm_timers2 -> "
1169	      "~n   M:  ~s"
1170	      "~n   M1: ~p", [M, M1]),
1171	    verify_dm_timers(2,3,4, M1);
1172	Else ->
1173	    exit({decode_failed, M, Else})
1174    end.
1175
1176
1177flex_compact_dm_timers3(suite) ->
1178    [];
1179flex_compact_dm_timers3(Config) when is_list(Config) ->
1180    ?ACQUIRE_NODES(1, Config),
1181    M = build_dm_timers_message("1", "02", "31"),
1182    B = list_to_binary(M),
1183    Conf = flex_scanner_conf(Config),
1184    case decode_message(megaco_compact_text_encoder, false, [Conf], B) of
1185	{ok, M1} when is_record(M1,'MegacoMessage') ->
1186	    t("flex_compact_dm_timers3 -> "
1187	      "~n   M:  ~s"
1188	      "~n   M1: ~p", [M, M1]),
1189	    verify_dm_timers(1,2,31, M1);
1190	Else ->
1191	    exit({decode_failed, M, Else})
1192    end.
1193
1194
1195flex_compact_dm_timers4(suite) ->
1196    [];
1197flex_compact_dm_timers4(Config) when is_list(Config) ->
1198    ?ACQUIRE_NODES(1, Config),
1199    M = build_dm_timers_message("10", "21", "99"),
1200    B = list_to_binary(M),
1201    Conf = flex_scanner_conf(Config),
1202    case decode_message(megaco_compact_text_encoder, false, [Conf], B) of
1203	{ok, M1} when is_record(M1,'MegacoMessage') ->
1204	    t("flex_compact_dm_timers4 -> "
1205	      "~n   M:  ~s"
1206	      "~n   M1: ~p", [M, M1]),
1207	    verify_dm_timers(10,21,99, M1);
1208	Else ->
1209	    exit({decode_failed, M, Else})
1210    end.
1211
1212
1213flex_compact_dm_timers5(suite) ->
1214    [];
1215flex_compact_dm_timers5(Config) when is_list(Config) ->
1216    ?ACQUIRE_NODES(1, Config),
1217    M = build_dm_timers_message("99", "23", "11"),
1218    B = list_to_binary(M),
1219    Conf = flex_scanner_conf(Config),
1220    case decode_message(megaco_compact_text_encoder, false, [Conf], B) of
1221	{ok, M1} when is_record(M1,'MegacoMessage') ->
1222	    t("flex_compact_dm_timers5 -> "
1223	      "~n   M:  ~s"
1224	      "~n   M1: ~p", [M, M1]),
1225	    verify_dm_timers(99,23,11, M1);
1226	Else ->
1227	    exit({decode_failed, M, Else})
1228    end.
1229
1230
1231flex_compact_dm_timers6(suite) ->
1232    [];
1233flex_compact_dm_timers6(Config) when is_list(Config) ->
1234    ?ACQUIRE_NODES(1, Config),
1235    M = build_dm_timers_message("77", "09", "1"),
1236    B = list_to_binary(M),
1237    Conf = flex_scanner_conf(Config),
1238    case decode_message(megaco_compact_text_encoder, false, [Conf], B) of
1239	{ok, M1} when is_record(M1,'MegacoMessage') ->
1240	    t("flex_compact_dm_timers6 -> "
1241	      "~n   M:  ~s"
1242	      "~n   M1: ~p", [M, M1]),
1243	    verify_dm_timers(77,9,1, M1);
1244	Else ->
1245	    exit({decode_failed, M, Else})
1246    end.
1247
1248
1249build_dm_timers_message(T, S, L) ->
1250    M = io_lib:format("!/" ?VERSION_STR " [123.123.123.4]:55555\nT=10001{C=-{MF=11111111/00000000/00000000{E=2223{al/on,dd/ce{DM=dialplan00}},SG{cg/rt},DM=dialplan00{T:~s,S:~s,L:~s,(0s| 00s|[1-7]xlxx|8lxxxxxxx|#xxxxxxx|*xx|9l1xxxxxxxxxx|9l011x.s)}}}}", [T, S, L]),
1251    lists:flatten(M).
1252
1253
1254verify_dm_timers(T,S,L, #'MegacoMessage'{mess = Mess}) ->
1255    #'Message'{messageBody = Body} = Mess,
1256    case get_dm_timers(Body) of
1257	{T, S, L} ->
1258	    ok;
1259	{T1, S1, L1} ->
1260	    exit({invalid_timer_values, {{T, S, L}, {T1, S1, L1}}});
1261	{error, Reason} ->
1262	    exit({invalid_timer, {T, S, L, Reason}})
1263    end.
1264
1265get_dm_timers({transactions, T}) when is_list(T) ->
1266    get_dm_timers1(T);
1267get_dm_timers(Other) ->
1268    {error, {invalid_transactions, Other}}.
1269
1270get_dm_timers1([{transactionRequest,T}|Ts]) when is_record(T,'TransactionRequest') ->
1271    case get_dm_timers2(T) of
1272	{ok, Timers} ->
1273	    Timers;
1274	_ ->
1275	    get_dm_timers1(Ts)
1276    end;
1277get_dm_timers1([_|Ts]) ->
1278    get_dm_timers1(Ts);
1279get_dm_timers1([]) ->
1280    {error, {no_timers, 'TransactionRequest'}}.
1281
1282
1283get_dm_timers2(#'TransactionRequest'{actions = Actions}) when is_list(Actions) ->
1284    get_dm_timers3(Actions).
1285
1286
1287get_dm_timers3([#'ActionRequest'{commandRequests = Cmds}|Ars]) when is_list(Cmds) ->
1288    case get_dm_timers4(Cmds) of
1289	{ok, Timers} ->
1290	    {ok, Timers};
1291	_ ->
1292	    get_dm_timers3(Ars)
1293    end;
1294get_dm_timers3([_|Ars]) ->
1295    get_dm_timers3(Ars);
1296get_dm_timers3([]) ->
1297    {error, {no_timers, 'ActionRequest'}}.
1298
1299get_dm_timers4([#'CommandRequest'{command = Cmd}|Cmds]) ->
1300    case get_dm_timers5(Cmd) of
1301	{ok, Timers} ->
1302	    {ok, Timers};
1303	_ ->
1304	    get_dm_timers4(Cmds)
1305    end;
1306get_dm_timers4([_|Cmds]) ->
1307    get_dm_timers4(Cmds);
1308get_dm_timers4([]) ->
1309    {error, {no_timers, 'CommandRequest'}}.
1310
1311
1312get_dm_timers5({modReq, #'AmmRequest'{descriptors = Descriptors}}) ->
1313    get_dm_timers6(Descriptors);
1314get_dm_timers5(R) ->
1315    {error, {no_modReq, R}}.
1316
1317
1318get_dm_timers6([{digitMapDescriptor, #'DigitMapDescriptor'{digitMapValue = Val}}|_]) ->
1319    case Val of
1320	#'DigitMapValue'{startTimer   = T,
1321			 shortTimer   = S,
1322			 longTimer    = L} ->
1323	    {ok, {T, S, L}};
1324	_ ->
1325	    {error, no_value_in_dm}
1326    end;
1327get_dm_timers6([_|Descs]) ->
1328    get_dm_timers6(Descs);
1329get_dm_timers6([]) ->
1330    {error, {no_timers, descriptors}}.
1331
1332
1333%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1334
1335bin_test_msgs(suite) ->
1336    [];
1337bin_test_msgs(Config) when is_list(Config) ->
1338    ?ACQUIRE_NODES(1, Config),
1339    Msgs = msgs1(),
1340    DynamicDecode = false,
1341    test_msgs(megaco_binary_encoder, DynamicDecode, [], Msgs).
1342
1343
1344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345
1346ber_test_msgs(suite) ->
1347    [];
1348ber_test_msgs(Config) when is_list(Config) ->
1349    ?ACQUIRE_NODES(1, Config),
1350    Msgs = msgs1(),
1351    DynamicDecode = false,
1352    test_msgs(megaco_ber_encoder, DynamicDecode, [], Msgs).
1353
1354
1355%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1356
1357per_test_msgs(suite) ->
1358    [];
1359per_test_msgs(Config) when is_list(Config) ->
1360    ?ACQUIRE_NODES(1, Config),
1361    Msgs = msgs1(),
1362    DynamicDecode = false,
1363    test_msgs(megaco_per_encoder, DynamicDecode, [], Msgs).
1364
1365
1366%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1367
1368erl_dist_m_test_msgs(suite) ->
1369    [];
1370erl_dist_m_test_msgs(Config) when is_list(Config) ->
1371    ?ACQUIRE_NODES(1, Config),
1372    Msgs = msgs1() ++ msgs2() ++ msgs3(),
1373    DynamicDecode = false,
1374    Conf = [megaco_compressed],
1375    test_msgs(megaco_erl_dist_encoder, DynamicDecode, Conf, Msgs).
1376
1377
1378%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1379
1380%% # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
1381%% Ticket test cases:
1382
1383
1384%% --------------------------------------------------------------
1385%% Observe that this decode SHALL fail
1386compact_otp4011_msg1(suite) ->
1387    [];
1388compact_otp4011_msg1(Config) when is_list(Config) ->
1389%     put(severity,trc),
1390%     put(dbg,true),
1391    d("compact_otp4011_msg1 -> entry", []),
1392    ?ACQUIRE_NODES(1, Config),
1393    M = "!/" ?VERSION_STR
1394	" ML T=233350{C=${A=stedevice/01{M{O{MO=SR,RV=OFF,RG=OFF,tdmc/ec=OFF,MO=SR}}}}}",
1395    ok = compact_otp4011(M).
1396
1397
1398%% --------------------------------------------------------------
1399%% Observe that this decode SHALL fail
1400compact_otp4011_msg2(suite) ->
1401    [];
1402compact_otp4011_msg2(Config) when is_list(Config) ->
1403    d("compact_otp4011_msg2 -> entry", []),
1404    ?ACQUIRE_NODES(1, Config),
1405    M = "!/" ?VERSION_STR
1406	" ML T=233350{C=${A=stedevice/01{M{O{MO=SO,RV=OFF,RG=OFF,tdmc/ec=OFF,MO=SR}}}}}",
1407%     put(severity,trc),
1408%     put(dbg,true),
1409    ok = compact_otp4011(M).
1410
1411
1412%% --------------------------------------------------------------
1413%% Observe that this decode SHALL fail
1414compact_otp4011_msg3(suite) ->
1415    [];
1416compact_otp4011_msg3(Config) when is_list(Config) ->
1417    d("compact_otp4011_msg3 -> entry", []),
1418    ?ACQUIRE_NODES(1, Config),
1419    M = "!/" ?VERSION_STR
1420	" ML T=233350{C=${A=stedevice/01{M{O{MO=SR,RV=OFF,RG=OFF,tdmc/ec=OFF,MO=SO}}}}}",
1421    %%     put(severity,trc),
1422    %%     put(dbg,true),
1423    ok = compact_otp4011(M).
1424
1425
1426compact_otp4011(M) ->
1427    d("compact_otp4011 -> entry with"
1428      "~n   M: '~s'", [M]),
1429    Bin = list_to_binary(M),
1430    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1431	{ok, _} ->
1432	    exit({decoded_erroneous_message,M});
1433	{error, Error} when is_list(Error) -> % Expected result
1434	    d("compact_otp4011 -> expected error result (so far)", []),
1435	    case lists:keysearch(reason,1,Error) of
1436		{value, {reason,Reason}} ->
1437		    d("compact_otp4011 -> expected error: "
1438		      "~n   Reason: ~p", [Reason]),
1439		    case Reason of
1440			{0, megaco_text_parser_v1,
1441			 {do_merge_control_streamParms, [A,B]}}
1442			when is_list(A) andalso is_record(B, 'LocalControlDescriptor') ->
1443			    case lists:keysearch(mode,1,A) of
1444				{value, {mode, _Mode}}
1445				when B#'LocalControlDescriptor'.streamMode =/= asn1_NOVALUE ->
1446				    d("compact_otp4011 -> expected error",[]),
1447				    ok;
1448				Other ->
1449				    exit({unexpected_mode_reason, {A,B,Other}})
1450			    end;
1451			Other ->
1452			    exit({unexpected_reason, Other})
1453		    end;
1454
1455		false ->
1456		    d("compact_otp4011 -> OUPS, wrong kind of error", []),
1457		    exit({unexpected_result, Error})
1458	    end;
1459	Else ->
1460	    d("compact_otp4011 -> unexpected decode result: ~p", [Else]),
1461	    exit({unexpected_decode_result, Else})
1462    end.
1463
1464%% --------------------------------------------------------------
1465%% Note that this decode SHALL fail, because of the misspelled
1466%% MEGCAO instead of the correct MEGACO.
1467compact_otp4013_msg1(suite) ->
1468    [];
1469compact_otp4013_msg1(Config) when is_list(Config) ->
1470    %% put(severity,trc),
1471    %% put(dbg,true),
1472    d("compact_otp4013_msg1 -> entry", []),
1473    ?ACQUIRE_NODES(1, Config),
1474    M = "MEGCAO/1 MG1 T=12345678{C=-{SC=root{SV{MT=RS,RE=901}}}}",
1475    Bin = list_to_binary(M),
1476    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1477	{ok, _} ->
1478	    exit({decoded_erroneous_message,M});
1479	{error, Reason} when is_list(Reason) ->
1480	    {value, {reason, no_version_found, _}} =
1481		lists:keysearch(reason, 1, Reason),
1482	    {value, {token, [{'SafeChars',_,"megcao/1"}|_]}} =
1483		lists:keysearch(token, 1, Reason),
1484	    ok;
1485	Else ->
1486	    exit({unexpected_decode_result,Else})
1487    end.
1488
1489
1490
1491%% --------------------------------------------------------------
1492%%
1493%%
1494compact_otp4085_msg1(suite) ->
1495    [];
1496compact_otp4085_msg1(Config) when is_list(Config) ->
1497    d("compact_otp4085_msg1 -> entry", []),
1498    ?ACQUIRE_NODES(1, Config),
1499    M = compact_otp4085_erroneous_msg(),
1500    Bin = list_to_binary(M),
1501    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1502	{ok, M} ->
1503	    exit({decoded_erroneous_message,M});
1504	{error, Error} when is_list(Error) -> % Expected result
1505	    t("compact_otp4085_msg1 -> decode failed", []),
1506	    case lists:keysearch(reason, 1, Error) of
1507		{value, {reason,{999999, Module, Crap}}} ->
1508		    t("compact_otp4085_msg1 -> THE ACTUAL ERROR: "
1509		      "~n   LINE NUMBER: 999999"
1510		      "~n   Module: ~p"
1511		      "~n   Crap:   ~p", [Module, Crap]),
1512		    %% ok;
1513		    exit({decode_failed_999999, Module, Crap});
1514		{value, {reason,{Line, Module, Crap}}} ->
1515		    t("compact_otp4085_msg1 -> Expected: "
1516		      "~n   Line:   ~p"
1517		      "~n   Module: ~p"
1518		      "~n   Crap:   ~p", [Line, Module, Crap]),
1519		    ok;
1520		false ->
1521		    exit({unexpected_result, Error})
1522	    end;
1523	Else ->
1524	    exit({unexpected_decode_result, Else})
1525    end.
1526
1527
1528%% --------------------------------------------------------------
1529%% This test case is just to show that the message used in
1530%% compact_otp4085_msg1 is actually ok when you add '}' at the end.
1531compact_otp4085_msg2(suite) ->
1532    [];
1533compact_otp4085_msg2(Config) when is_list(Config) ->
1534    d("compact_otp4085_msg1 -> entry", []),
1535    ?ACQUIRE_NODES(1, Config),
1536    M1 = compact_otp4085_erroneous_msg() ++ "}",
1537    Bin = list_to_binary(M1),
1538    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1539	{ok, M2} ->
1540	    l("compact_otp4085_msg1 -> successfull decode"
1541	      "~n   M2: ~p", [M2]),
1542	    ok;
1543	Else ->
1544	    e("compact_otp4085_msg1 -> decode error"
1545	      "~n   Else: ~p", [Else]),
1546	    exit({unexpected_decode_result,Else})
1547    end.
1548
1549
1550%% This message lack the ending parentesis (}).
1551compact_otp4085_erroneous_msg() ->
1552    M = "!/"
1553	?VERSION_STR
1554	" ML T=11223342{C=${A=${M{O{MO=SR,RV=OFF,RG=OFF},L{v=0,"
1555	"c=ATM NSAP $ ,"
1556	"a=eecid:$ ,"
1557	"m=audio - AAL1/ATMF -,"
1558	"}}},A=stee1181/01{M{O{MO=SR,RV=OFF,RG=OFF,tdmc/ec=off}}}}",
1559    M.
1560
1561%% --------------------------------------------------------------
1562%%
1563%%
1564compact_otp4280_msg1(suite) ->
1565    [];
1566compact_otp4280_msg1(Config) when is_list(Config) ->
1567    d("compact_otp4280_msg1 -> entry", []),
1568    ?ACQUIRE_NODES(1, Config),
1569    Bin = list_to_binary(compact_otp4280_msg()),
1570    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1571	{ok, _Msg} ->
1572	    ok;
1573	{error, Error} when is_list(Error) ->
1574	    t("compact_otp4280_msg1 -> decode failed", []),
1575	    case lists:keysearch(reason, 1, Error) of
1576		{value, {reason,{Line, Module, Reason} = R}} ->
1577		    t("compact_otp4280_msg1 -> "
1578		      "~n   Line:   ~w"
1579		      "~n   Module: ~w"
1580		      "~n   Reason: ~w", [Line, Module, Reason]),
1581		    exit({decode_failed, R});
1582		false ->
1583		    exit({unexpected_result, Error})
1584	    end;
1585	Else ->
1586	    exit({unexpected_decode_result, Else})
1587    end.
1588
1589compact_otp4280_msg() ->
1590    M = "!/"
1591	?VERSION_STR
1592	" mgw1 P=71853646{C=-{AV=root{M{TS{root/maxnumberofcontexts=49500,"
1593	"root/maxterminationspercontext=2,root/normalmgexecutiontime=200,"
1594	"root/normalmgcexecutiontime=150,"
1595	"root/provisionalresponsetimervalue=2000,BF=OFF,SI=IV}}}}}",
1596    M.
1597
1598
1599%% --------------------------------------------------------------
1600%% This ticket is about comments in a message
1601compact_otp4299_msg1(suite) ->
1602    [];
1603compact_otp4299_msg1(Config) when is_list(Config) ->
1604    d("compact_otp4299_msg1 -> entry", []),
1605    ?ACQUIRE_NODES(1, Config),
1606    Bin = list_to_binary(compact_otp4299_msg()),
1607    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1608	{ok, _Msg} ->
1609	    ok;
1610
1611	{error, Reason} ->
1612	    exit({decode_error, Reason});
1613
1614	Else ->
1615	    exit({unexpected_decode_result, Else})
1616    end.
1617
1618
1619%% Same message, but this time decoded using the flex scanner
1620compact_otp4299_msg2(suite) ->
1621    [];
1622compact_otp4299_msg2(Config) when is_list(Config) ->
1623    d("compact_otp4299_msg2 -> entry", []),
1624    ?ACQUIRE_NODES(1, Config),
1625
1626    {Pid, Conf} = compact_otp4299_msg2_init(),
1627
1628    Bin = list_to_binary(compact_otp4299_msg()),
1629    Res = decode_message(megaco_compact_text_encoder, false, [Conf], Bin),
1630    compact_otp4299_msg2_finish(Pid),
1631
1632    case Res of
1633	{ok, _Msg} ->
1634	    ok;
1635
1636	{error, Reason} ->
1637	    exit({decode_error, Reason});
1638
1639	Else ->
1640	    exit({unexpected_decode_result, Else})
1641    end.
1642
1643
1644compact_otp4299_msg2_init() ->
1645    Flag = process_flag(trap_exit, true),
1646    Res = (catch start_flex_scanner()),
1647    process_flag(trap_exit, Flag),
1648    case Res of
1649	{error, Reason} ->
1650	    skip(Reason);
1651	{ok, FlexConfig} ->
1652	    FlexConfig
1653    end.
1654
1655compact_otp4299_msg2_finish(Pid) ->
1656    stop_flex_scanner(Pid).
1657
1658
1659compact_otp4299_msg() ->
1660    M = ";KALLE\n"
1661	"!/" ?VERSION_STR " mg58_1 P=005197711{; YET ANOTHER COMMENT\n"
1662	"C=035146207{A=mg58_1_1_4_1_23/19; BEFORE COMMA\n"
1663	",; AFTER COMMA\n"
1664	"A=eph58_1/0xA4023371{M{L{\n"
1665	"v=0\n"
1666	"c=ATM NSAP 39.0102.0304.0506.0708.090a.0b58.0100.0000.0000.00\n"
1667	"m=audio - AAL1/ATMF -\n"
1668	"a=eecid:A4023371\n"
1669	"}}; HOBBE\n}; KALLE \"HOBBE \n}}"
1670	";KALLE\n\n",
1671    M.
1672
1673
1674%% --------------------------------------------------------------
1675%%
1676%%
1677compact_otp4359_msg1(suite) ->
1678    [];
1679compact_otp4359_msg1(Config) when is_list(Config) ->
1680    d("compact_otp4359_msg1 -> entry", []),
1681    ?ACQUIRE_NODES(1, Config),
1682    Bin = list_to_binary(compact_otp4359_msg()),
1683    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1684	{ok, #'MegacoMessage'{mess = Mess}} ->
1685	    {transactions, Trans} = Mess#'Message'.messageBody,
1686	    case Trans of
1687		[{transactionRequest,#'TransactionRequest'{transactionId = asn1_NOVALUE}}] ->
1688		    ok;
1689		_ ->
1690		    exit({unexpected_transactions, Trans})
1691	    end;
1692	Else ->
1693	    t("compact_otp4359_msg1 -> "
1694	      "~n   Else: ~w", [Else]),
1695	    exit({unexpected_decode_result, Else})
1696    end.
1697
1698compact_otp4359_msg() ->
1699    M = "!/" ?VERSION_STR " ml2 T={C=${A=${M{O {MO=SR,RG=OFF,RV=OFF}}}}}",
1700    M.
1701
1702
1703%% --------------------------------------------------------------
1704%%
1705%%
1706compact_otp4920_msg0(suite) ->
1707    [];
1708compact_otp4920_msg0(Config) when is_list(Config) ->
1709    d("compact_otp4920_msg0 -> entry", []),
1710    ?ACQUIRE_NODES(1, Config),
1711%    put(dbg,true),
1712    compact_otp4920_msg_1(compact_otp4920_msg0(), true).
1713
1714compact_otp4920_msg1(suite) ->
1715    [];
1716compact_otp4920_msg1(Config) when is_list(Config) ->
1717    d("compact_otp4920_msg1 -> entry", []),
1718    ?ACQUIRE_NODES(1, Config),
1719%     put(dbg,true),
1720    compact_otp4920_msg_1(compact_otp4920_msg1(), false).
1721
1722compact_otp4920_msg2(suite) ->
1723    [];
1724compact_otp4920_msg2(Config) when is_list(Config) ->
1725    d("compact_otp4920_msg2 -> entry", []),
1726    ?ACQUIRE_NODES(1, Config),
1727    compact_otp4920_msg_1(compact_otp4920_msg2(), false).
1728
1729compact_otp4920_msg3(suite) ->
1730    [];
1731compact_otp4920_msg3(Config) when is_list(Config) ->
1732    d("compact_otp4920_msg3 -> entry", []),
1733    ?ACQUIRE_NODES(1, Config),
1734    compact_otp4920_msg_1(compact_otp4920_msg3(), true).
1735
1736compact_otp4920_msg4(suite) ->
1737    [];
1738compact_otp4920_msg4(Config) when is_list(Config) ->
1739    d("compact_otp4920_msg4 -> entry", []),
1740    ?ACQUIRE_NODES(1, Config),
1741    compact_otp4920_msg_1(compact_otp4920_msg4(), true).
1742
1743compact_otp4920_msg5(suite) ->
1744    [];
1745compact_otp4920_msg5(Config) when is_list(Config) ->
1746    d("compact_otp4920_msg5 -> entry", []),
1747    ?ACQUIRE_NODES(1, Config),
1748    compact_otp4920_msg_1(compact_otp4920_msg5(), true).
1749
1750compact_otp4920_msg6(suite) ->
1751    [];
1752compact_otp4920_msg6(Config) when is_list(Config) ->
1753    d("compact_otp4920_msg6 -> entry", []),
1754    ?ACQUIRE_NODES(1, Config),
1755    compact_otp4920_msg_1(compact_otp4920_msg6(), true).
1756
1757compact_otp4920_msg7(suite) ->
1758    [];
1759compact_otp4920_msg7(Config) when is_list(Config) ->
1760    d("compact_otp4920_msg7 -> entry", []),
1761    ?ACQUIRE_NODES(1, Config),
1762%    put(dbg,true),
1763    compact_otp4920_msg_1(compact_otp4920_msg7(), true).
1764
1765compact_otp4920_msg8(suite) ->
1766    [];
1767compact_otp4920_msg8(Config) when is_list(Config) ->
1768    d("compact_otp4920_msg8 -> entry", []),
1769    ?ACQUIRE_NODES(1, Config),
1770%    put(dbg,true),
1771    compact_otp4920_msg_1(compact_otp4920_msg8(), false).
1772
1773compact_otp4920_msg9(suite) ->
1774    [];
1775compact_otp4920_msg9(Config) when is_list(Config) ->
1776    d("compact_otp4920_msg9 -> entry", []),
1777    ?ACQUIRE_NODES(1, Config),
1778    compact_otp4920_msg_1(compact_otp4920_msg9(), false).
1779
1780compact_otp4920_msg10(suite) ->
1781    [];
1782compact_otp4920_msg10(Config) when is_list(Config) ->
1783    d("compact_otp4920_msg10 -> entry", []),
1784    ?ACQUIRE_NODES(1, Config),
1785    compact_otp4920_msg_1(compact_otp4920_msg10(), false).
1786
1787compact_otp4920_msg11(suite) ->
1788    [];
1789compact_otp4920_msg11(Config) when is_list(Config) ->
1790    d("compact_otp4920_msg11 -> entry", []),
1791    ?ACQUIRE_NODES(1, Config),
1792    compact_otp4920_msg_1(compact_otp4920_msg11(), false).
1793
1794compact_otp4920_msg12(suite) ->
1795    [];
1796compact_otp4920_msg12(Config) when is_list(Config) ->
1797    d("compact_otp4920_msg12 -> entry", []),
1798    ?ACQUIRE_NODES(1, Config),
1799    compact_otp4920_msg_1(compact_otp4920_msg12(), true).
1800
1801%% Duplicate padding
1802compact_otp4920_msg20(suite) ->
1803    [];
1804compact_otp4920_msg20(Config) when is_list(Config) ->
1805    d("compact_otp4920_msg20 -> entry", []),
1806    ?ACQUIRE_NODES(1, Config),
1807    compact_otp4920_msg_2(compact_otp4920_msg20(), bad_mid_duplicate_padding).
1808
1809%% Length
1810compact_otp4920_msg21(suite) ->
1811    [];
1812compact_otp4920_msg21(Config) when is_list(Config) ->
1813    d("compact_otp4920_msg21 -> entry", []),
1814    ?ACQUIRE_NODES(1, Config),
1815    compact_otp4920_msg_2(compact_otp4920_msg21(), bad_mid_ip6addr_length).
1816
1817%% Length
1818compact_otp4920_msg22(suite) ->
1819    [];
1820compact_otp4920_msg22(Config) when is_list(Config) ->
1821    d("compact_otp4920_msg22 -> entry", []),
1822    ?ACQUIRE_NODES(1, Config),
1823    compact_otp4920_msg_2(compact_otp4920_msg22(), bad_mid_ip6addr_length).
1824
1825%% Length
1826compact_otp4920_msg23(suite) ->
1827    [];
1828compact_otp4920_msg23(Config) when is_list(Config) ->
1829    d("compact_otp4920_msg23 -> entry", []),
1830    ?ACQUIRE_NODES(1, Config),
1831    compact_otp4920_msg_2(compact_otp4920_msg23(), bad_mid_ip6addr_length).
1832
1833%% Length
1834compact_otp4920_msg24(suite) ->
1835    [];
1836compact_otp4920_msg24(Config) when is_list(Config) ->
1837    d("compact_otp4920_msg24 -> entry", []),
1838    ?ACQUIRE_NODES(1, Config),
1839    compact_otp4920_msg_2(compact_otp4920_msg24(), bad_mid_ip6addr_length).
1840
1841%% Length
1842compact_otp4920_msg25(suite) ->
1843    [];
1844compact_otp4920_msg25(Config) when is_list(Config) ->
1845    d("compact_otp4920_msg25 -> entry", []),
1846    ?ACQUIRE_NODES(1, Config),
1847    compact_otp4920_msg_2(compact_otp4920_msg25(), bad_mid_ip6addr_length).
1848
1849compact_otp4920_msg_1(M1, CheckEqual) ->
1850    Bin1 = list_to_binary(M1),
1851    case decode_message(megaco_compact_text_encoder, false, [], Bin1) of
1852	{ok, Msg} ->
1853 	    io:format(" decoded", []),
1854	    case encode_message(megaco_compact_text_encoder, [], Msg) of
1855		{ok, Bin1} ->
1856		    io:format(", encoded - equal:", []),
1857		    ok;
1858		{ok, Bin2} when CheckEqual =:= true ->
1859		    M2 = binary_to_list(Bin2),
1860		    io:format(", encoded - not equal:", []),
1861		    exit({messages_not_equal, M1, M2});
1862		{ok, _Bin2} ->
1863		    io:format(", encoded:", []),
1864		    ok;
1865		Else ->
1866		    io:format(", encode failed:", []),
1867		    exit({unexpected_encode_result, Else})
1868	    end;
1869	Else ->
1870	    io:format("decode failed:", []),
1871	    exit({unexpected_decode_result, Else})
1872    end.
1873
1874compact_otp4920_msg_2(M1, ExpectedReason) ->
1875    Bin = list_to_binary(M1),
1876    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
1877	{ok, Msg} ->
1878	    io:format("unexpected successfull decode", []),
1879	    exit({unexpected_encode_ok, Msg});
1880	{error, [{reason, {__Line, _Mod, Reason}}|_]} ->
1881	    case element(1, Reason) of
1882		ExpectedReason ->
1883		    ok;
1884		_ ->
1885		    exit({unexpected_decode_error_reason,
1886			  ExpectedReason, Reason})
1887	    end;
1888	{error, [{reason, {_Mod, Reason}}|_]} ->
1889	    case element(1, Reason) of
1890		ExpectedReason ->
1891		    ok;
1892		_ ->
1893		    exit({unexpected_decode_error_reason,
1894			  ExpectedReason, Reason})
1895	    end;
1896	Else ->
1897	    io:format("unexpected decode result", []),
1898	    exit({unexpected_decode_result, Else})
1899
1900    end.
1901
1902compact_otp4920_msg0() ->
1903    M = "!/" ?VERSION_STR " [192.168.30.1]\nT=100{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1904    M.
1905
1906compact_otp4920_msg1() ->
1907    M = "!/" ?VERSION_STR " [2031:0000:130F:0000:0000:09C0:876A:130B]\nT=101{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1908    M.
1909
1910compact_otp4920_msg2() ->
1911    M = "!/" ?VERSION_STR " [2031:0:130F:0:0:9C0:876A:130B]\nT=102{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1912    M.
1913
1914compact_otp4920_msg3() ->
1915    M = "!/" ?VERSION_STR " [2031:0:130F::9C0:876A:130B]\nT=103{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1916    M.
1917
1918compact_otp4920_msg4() ->
1919    M = "!/" ?VERSION_STR " [::1]\nT=104{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1920    M.
1921
1922compact_otp4920_msg5() ->
1923    M = "!/" ?VERSION_STR " [::]\nT=105{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1924    M.
1925
1926compact_otp4920_msg6() ->
1927    M = "!/" ?VERSION_STR " [1::]\nT=106{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1928    M.
1929
1930compact_otp4920_msg7() ->
1931    M = "!/" ?VERSION_STR " [FEDC:1::]\nT=107{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1932    M.
1933
1934compact_otp4920_msg8() ->
1935    M = "!/" ?VERSION_STR " [2031:0:130F:0:0:9C0:135.106.19.11]\nT=108{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1936    M.
1937
1938compact_otp4920_msg9() ->
1939    M = "!/" ?VERSION_STR " [2031:0:130F::9C0:135.106.19.11]\nT=109{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1940    M.
1941
1942compact_otp4920_msg10() ->
1943    M = "!/" ?VERSION_STR " [::FFFF:192.168.30.1]\nT=110{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1944    M.
1945
1946compact_otp4920_msg11() ->
1947    M = "!/" ?VERSION_STR " [::192.168.30.1]\nT=111{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1948    M.
1949
1950compact_otp4920_msg12() ->
1951    M = "!/" ?VERSION_STR " [::C0A8:1E01]\nT=112{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1952    M.
1953
1954%% Illegal: only one :: allowed
1955compact_otp4920_msg20() ->
1956    M = "!/" ?VERSION_STR " [2031::130F::9C0]\nT=120{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1957    M.
1958
1959%% Illegal: length
1960compact_otp4920_msg21() ->
1961    M = "!/" ?VERSION_STR " [2031:FFEE:0000:130F:0000:0000:09C0:876A:130B]\nT=121{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1962    M.
1963
1964%% Illegal: length
1965compact_otp4920_msg22() ->
1966    M = "!/" ?VERSION_STR " [2031:FFEE:0:130F:0:0:9C0:135.106.19.11]\nT=122{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1967    M.
1968
1969%% Illegal: length
1970compact_otp4920_msg23() ->
1971    M = "!/" ?VERSION_STR " [2031:FFEE:0000:130F:2132:4354::09C0:876A:130B]\nT=123{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1972    M.
1973
1974%% Illegal: length
1975compact_otp4920_msg24() ->
1976    M = "!/" ?VERSION_STR " [::2031:FFEE:0000:130F:2132:4354:09C0:876A:130B]\nT=124{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1977    M.
1978
1979%% Illegal: length
1980compact_otp4920_msg25() ->
1981    M = "!/" ?VERSION_STR " [2031:FFEE:0000:130F:2132:4354:09C0:876A:130B::]\nT=125{C=${A=${M{O{MO=SR,RG=OFF,RV=OFF}}}}}",
1982    M.
1983
1984
1985compact_otp5186_msg01(suite) ->
1986    [];
1987compact_otp5186_msg01(Config) when is_list(Config) ->
1988    d("compact_otp5186_msg01 -> entry", []),
1989    ?ACQUIRE_NODES(1, Config),
1990    compact_otp5186_msg_1(compact_otp5186_msg01(), error, ignore).
1991
1992compact_otp5186_msg02(suite) ->
1993    [];
1994compact_otp5186_msg02(Config) when is_list(Config) ->
1995    d("compact_otp5186_msg02 -> entry", []),
1996    ?ACQUIRE_NODES(1, Config),
1997    compact_otp5186_msg_1(compact_otp5186_msg02(), ok, ok).
1998
1999compact_otp5186_msg03(suite) ->
2000    [];
2001compact_otp5186_msg03(Config) when is_list(Config) ->
2002    d("compact_otp5186_msg03 -> entry", []),
2003    ?ACQUIRE_NODES(1, Config),
2004    compact_otp5186_msg_2(compact_otp5186_msg03(), ok, ok).
2005
2006compact_otp5186_msg04(suite) ->
2007    [];
2008compact_otp5186_msg04(Config) when is_list(Config) ->
2009    d("compact_otp5186_msg04 -> entry", []),
2010    ?ACQUIRE_NODES(1, Config),
2011    compact_otp5186_msg_2(compact_otp5186_msg04(), ok, ok).
2012
2013compact_otp5186_msg05(suite) ->
2014    [];
2015compact_otp5186_msg05(Config) when is_list(Config) ->
2016    d("compact_otp5186_msg05 -> entry", []),
2017    ?ACQUIRE_NODES(1, Config),
2018    compact_otp5186_msg_2(compact_otp5186_msg05(), ok, ok).
2019
2020compact_otp5186_msg06(suite) ->
2021    [];
2022compact_otp5186_msg06(Config) when is_list(Config) ->
2023    d("compact_otp5186_msg06 -> entry", []),
2024    ?ACQUIRE_NODES(1, Config),
2025    compact_otp5186_msg_2(compact_otp5186_msg06(), ok, ok).
2026
2027compact_otp5186_msg_1(M1, DecodeExpect, EncodeExpect) ->
2028    Bin1 = list_to_binary(M1),
2029    case decode_message(megaco_compact_text_encoder, false, [], Bin1) of
2030	{ok, Msg} when DecodeExpect =:= ok ->
2031 	    io:format(" decoded", []),
2032	    case encode_message(megaco_compact_text_encoder, [], Msg) of
2033		{ok, Bin1} when EncodeExpect =:= ok ->
2034		    io:format(", encoded - equal:", []),
2035		    ok;
2036		{ok, Bin2} when EncodeExpect =:= ok ->
2037		    M2 = binary_to_list(Bin2),
2038		    io:format(", encoded - not equal:", []),
2039		    exit({messages_not_equal, Msg, M1, M2});
2040		{ok, Bin3} when EncodeExpect =:= error ->
2041		    M3 = binary_to_list(Bin3),
2042		    io:format(", unexpected encode:", []),
2043		    exit({unexpected_encode_success, Msg, M1, M3});
2044		_Else when EncodeExpect =:= error ->
2045		    io:format(", encode failed ", []),
2046		    ok
2047	    end;
2048	{ok, Msg} when DecodeExpect =:= error ->
2049 	    io:format(" decoded", []),
2050	    exit({unexpected_decode_success, Msg});
2051	_Else when DecodeExpect =:= error ->
2052	    io:format(" decode failed ", []),
2053	    ok;
2054	Else when DecodeExpect =:= ok ->
2055	    io:format(" decode failed ", []),
2056	    exit({unexpected_decode_result, Else})
2057    end.
2058
2059compact_otp5186_msg_2(Msg1, EncodeExpect, DecodeExpect) ->
2060    case encode_message(megaco_compact_text_encoder, [], Msg1) of
2061	{ok, Bin} when EncodeExpect =:= ok ->
2062 	    io:format(" encoded", []),
2063	    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
2064		{ok, Msg1} when DecodeExpect =:= ok ->
2065		    io:format(", decoded - equal:", []),
2066		    ok;
2067		{ok, Msg2} when DecodeExpect =:= ok ->
2068		    M = binary_to_list(Bin),
2069		    case (catch compact_otp5186_check_megamsg(Msg1, Msg2)) of
2070			ok ->
2071			    io:format(", decoded - not equal - ok:", []),
2072			    ok;
2073			{'EXIT', Reason} ->
2074			    io:format(", decoded - not equal:", []),
2075			    exit({messages_not_equal, M, Reason, Msg1, Msg2})
2076		    end;
2077		{ok, Msg3} when DecodeExpect =:= error ->
2078		    M = binary_to_list(Bin),
2079		    io:format(", decoded:", []),
2080		    exit({unexpected_decode_success, M, Msg1, Msg3});
2081		Else when DecodeExpect =:= ok ->
2082		    M = binary_to_list(Bin),
2083		    io:format(", decode failed ", []),
2084		    exit({unexpected_decode_success, Msg1, M, Else});
2085		_Else when DecodeExpect =:= error ->
2086		    io:format(", decode failed ", []),
2087		    ok
2088	    end;
2089	{ok, Bin} when EncodeExpect =:= error ->
2090	    M = binary_to_list(Bin),
2091	    io:format(" encoded", []),
2092	    exit({unexpected_encode_success, Msg1, M});
2093	_Else when EncodeExpect =:= error ->
2094	    io:format(" encode failed ", []),
2095	    ok;
2096	Else when EncodeExpect =:= ok ->
2097	    io:format(" encode failed ", []),
2098	    exit({unexpected_encode_result, Else})
2099    end.
2100
2101
2102%% --
2103
2104compact_otp5186_msg01() ->
2105    "!/1 <mg5>\nP=67111298{C=2699{AV=mg5_ipeph/0x0f0001{}}}".
2106
2107compact_otp5186_msg02() ->
2108    "!/1 <mg5>\nP=67111298{C=2699{AV=mg5_ipeph/0x0f0001}}".
2109
2110compact_otp5186_msg03() ->
2111    {'MegacoMessage',
2112     asn1_NOVALUE,
2113     {'Message',
2114      1,
2115      {domainName,{'DomainName',"mg5",asn1_NOVALUE}},
2116      {transactions,
2117       [{transactionReply,
2118	 {'TransactionReply',67111298,asn1_NOVALUE,
2119	  {actionReplies,[
2120			  {'ActionReply',2699,asn1_NOVALUE,asn1_NOVALUE,
2121			   [
2122			    {auditValueReply,
2123			     {auditResult,
2124			      {'AuditResult',
2125			       {megaco_term_id,false,["mg5_ipeph","0x0f0001"]},
2126			       [
2127			       ]
2128			      }
2129			     }
2130			    }
2131			   ]
2132			  }
2133			 ]
2134	  }
2135	 }
2136	}
2137       ]
2138      }
2139     }
2140    }.
2141
2142compact_otp5186_msg04() ->
2143    {'MegacoMessage',asn1_NOVALUE,
2144     {'Message',1,{domainName,{'DomainName',"mg5",asn1_NOVALUE}},
2145      {transactions,
2146       [{transactionReply,
2147	 {'TransactionReply',67111298,asn1_NOVALUE,
2148	  {actionReplies,[
2149			  {'ActionReply',2699,asn1_NOVALUE,asn1_NOVALUE,
2150			   [
2151			    {auditValueReply,
2152			     {auditResult,
2153			      {'AuditResult',
2154			       {megaco_term_id,false,["mg5_ipeph","0x0f0001"]},
2155			       [
2156				{emptyDescriptors,
2157				 {'AuditDescriptor',asn1_NOVALUE}
2158				}
2159			       ]
2160			      }
2161			     }
2162			    }
2163			   ]
2164			  }
2165			 ]
2166	  }
2167	 }
2168	}
2169       ]
2170      }
2171     }
2172    }.
2173
2174compact_otp5186_msg05() ->
2175    {'MegacoMessage',
2176     asn1_NOVALUE,
2177     {'Message',
2178      1,
2179      {domainName,{'DomainName',"mg5",asn1_NOVALUE}},
2180      {transactions,
2181       [{transactionReply,
2182	 {'TransactionReply',67111298,asn1_NOVALUE,
2183	  {actionReplies,[
2184			  {'ActionReply',2699,asn1_NOVALUE,asn1_NOVALUE,
2185			   [
2186			    {addReply,
2187			     {'AmmsReply',
2188			      [
2189			       {megaco_term_id,false,["mg5_ipeph","0x0f0001"]}
2190			      ],
2191			      [
2192			      ]
2193			     }
2194			    }
2195			   ]
2196			  }
2197			 ]
2198	  }
2199	 }
2200	}
2201       ]
2202      }
2203     }
2204    }.
2205
2206compact_otp5186_msg06() ->
2207    {'MegacoMessage',asn1_NOVALUE,
2208     {'Message',1,{domainName,{'DomainName',"mg5",asn1_NOVALUE}},
2209      {transactions,
2210       [{transactionReply,
2211	 {'TransactionReply',67111298,asn1_NOVALUE,
2212	  {actionReplies,[
2213			  {'ActionReply',2699,asn1_NOVALUE,asn1_NOVALUE,
2214			   [
2215			    {addReply,
2216			     {'AmmsReply',
2217			      [
2218			       {megaco_term_id,false,["mg5_ipeph","0x0f0001"]}
2219			      ],
2220			      [
2221			       {emptyDescriptors,
2222				{'AuditDescriptor',asn1_NOVALUE}
2223			       }
2224			      ]
2225			     }
2226			    }
2227			   ]
2228			  }
2229			 ]
2230	  }
2231	 }
2232	}
2233       ]
2234      }
2235     }
2236    }.
2237
2238%% --
2239
2240compact_otp5186_check_megamsg(M1, M1) ->
2241    ok;
2242compact_otp5186_check_megamsg(#'MegacoMessage'{authHeader = AH,
2243					       mess = M1},
2244			      #'MegacoMessage'{authHeader = AH,
2245					       mess = M2}) ->
2246    compact_otp5186_check_mess(M1, M2);
2247compact_otp5186_check_megamsg(#'MegacoMessage'{authHeader = AH1},
2248			      #'MegacoMessage'{authHeader = AH2}) ->
2249    exit({not_equal, authHeader, AH1, AH2}).
2250
2251compact_otp5186_check_mess(M, M) ->
2252    ok;
2253compact_otp5186_check_mess(#'Message'{version     = V,
2254				      mId         = MId,
2255				      messageBody = B1},
2256			   #'Message'{version     = V,
2257				      mId         = MId,
2258				      messageBody = B2}) ->
2259    compact_otp5186_check_body(B1, B2);
2260compact_otp5186_check_mess(#'Message'{version     = V,
2261				      mId         = MId1},
2262			   #'Message'{version     = V,
2263				      mId         = MId2}) ->
2264    exit({not_equal, mId, MId1, MId2});
2265compact_otp5186_check_mess(#'Message'{version     = V1,
2266				      mId         = MId},
2267			   #'Message'{version     = V2,
2268				      mId         = MId}) ->
2269    exit({not_equal, version, V1, V2}).
2270
2271compact_otp5186_check_body(B, B) ->
2272    ok;
2273compact_otp5186_check_body({transactions, T1}, {transactions, T2}) ->
2274    compact_otp5186_check_trans(T1, T2);
2275compact_otp5186_check_body({messageError, E1}, {messageError, E2}) ->
2276    compact_otp5186_check_merr(E1, E2);
2277compact_otp5186_check_body(B1, B2) ->
2278    exit({not_equal, messageBody, B1, B2}).
2279
2280compact_otp5186_check_trans([], []) ->
2281    ok;
2282compact_otp5186_check_trans([], T2) ->
2283    exit({not_equal, transactions, [], T2});
2284compact_otp5186_check_trans(T1, []) ->
2285    exit({not_equal, transactions, T1, []});
2286compact_otp5186_check_trans([Tran1|Trans1], [Tran2|Trans2]) ->
2287    compact_otp5186_check_trans(Trans1, Trans2),
2288    compact_otp5186_check_transaction(Tran1, Tran2).
2289
2290compact_otp5186_check_merr(ME, ME) ->
2291    ok;
2292compact_otp5186_check_merr(#'ErrorDescriptor'{errorCode = EC,
2293					      errorText = ET1},
2294			   #'ErrorDescriptor'{errorCode = EC,
2295					      errorText = ET2}) ->
2296    exit({not_equal, errorText, ET1, ET2});
2297compact_otp5186_check_merr(#'ErrorDescriptor'{errorCode = EC1,
2298					      errorText = ET},
2299			   #'ErrorDescriptor'{errorCode = EC2,
2300					      errorText = ET}) ->
2301    exit({not_equal, errorCode, EC1, EC2}).
2302
2303compact_otp5186_check_transaction(T, T) ->
2304    ok;
2305compact_otp5186_check_transaction({transactionReply, TR1},
2306				  {transactionReply, TR2}) ->
2307    compact_otp5186_check_transRep(TR1, TR2);
2308compact_otp5186_check_transaction(T1, T2) ->
2309    exit({unexpected_transactions, T1, T2}).
2310
2311compact_otp5186_check_transRep(T, T) ->
2312    ok;
2313compact_otp5186_check_transRep(#'TransactionReply'{transactionId     = TId,
2314						   immAckRequired    = IAR,
2315						   transactionResult = TR1},
2316			       #'TransactionReply'{transactionId     = TId,
2317						   immAckRequired    = IAR,
2318						   transactionResult = TR2}) ->
2319    compact_otp5186_check_transRes(TR1, TR2);
2320compact_otp5186_check_transRep(T1, T2) ->
2321    exit({unexpected_transaction_reply, T1, T2}).
2322
2323compact_otp5186_check_transRes(TR, TR) ->
2324    ok;
2325compact_otp5186_check_transRes({actionReplies, AR1},
2326			       {actionReplies, AR2}) ->
2327    compact_otp5186_check_actReps(AR1, AR2);
2328compact_otp5186_check_transRes(TR1, TR2) ->
2329    exit({unexpected_transaction_result, TR1, TR2}).
2330
2331compact_otp5186_check_actReps([], []) ->
2332    ok;
2333compact_otp5186_check_actReps(AR1, []) ->
2334    exit({not_equal, actionReplies, AR1, []});
2335compact_otp5186_check_actReps([], AR2) ->
2336    exit({not_equal, actionReplies, [], AR2});
2337compact_otp5186_check_actReps([AR1|ARs1], [AR2|ARs2]) ->
2338    compact_otp5186_check_actRep(AR1, AR2),
2339    compact_otp5186_check_actReps(ARs1, ARs2).
2340
2341compact_otp5186_check_actRep(AR, AR) ->
2342    ok;
2343compact_otp5186_check_actRep(#'ActionReply'{contextId       = ID,
2344					    errorDescriptor = ED,
2345					    contextReply    = CtxRep,
2346					    commandReply    = CmdRep1},
2347			     #'ActionReply'{contextId       = ID,
2348					    errorDescriptor = ED,
2349					    contextReply    = CtxRep,
2350					    commandReply    = CmdRep2}) ->
2351    compact_otp5186_check_cmdReps(CmdRep1, CmdRep2);
2352compact_otp5186_check_actRep(AR1, AR2) ->
2353    exit({unexpected_actionReply, AR1, AR2}).
2354
2355compact_otp5186_check_cmdReps([], []) ->
2356    ok;
2357compact_otp5186_check_cmdReps(CR1, []) ->
2358    exit({not_equal, commandReplies, CR1, []});
2359compact_otp5186_check_cmdReps([], CR2) ->
2360    exit({not_equal, commandReplies, [], CR2});
2361compact_otp5186_check_cmdReps([CR1|CRs1], [CR2|CRs2]) ->
2362    compact_otp5186_check_cmdRep(CR1, CR2),
2363    compact_otp5186_check_cmdReps(CRs1, CRs2).
2364
2365compact_otp5186_check_cmdRep(CR, CR) ->
2366    ok;
2367compact_otp5186_check_cmdRep({auditValueReply, AVR1},
2368			     {auditValueReply, AVR2}) ->
2369    compact_otp5186_check_auditReply(AVR1, AVR2);
2370compact_otp5186_check_cmdRep({addReply, AVR1},
2371			     {addReply, AVR2}) ->
2372    compact_otp5186_check_ammsReply(AVR1, AVR2);
2373compact_otp5186_check_cmdRep(CR1, CR2) ->
2374    exit({unexpected_commandReply, CR1, CR2}).
2375
2376compact_otp5186_check_auditReply(AR, AR) ->
2377    ok;
2378compact_otp5186_check_auditReply({auditResult, AR1},
2379				 {auditResult, AR2}) ->
2380    compact_otp5186_check_auditRes(AR1, AR2);
2381compact_otp5186_check_auditReply(AR1, AR2) ->
2382    exit({unexpected_auditReply, AR1, AR2}).
2383
2384compact_otp5186_check_ammsReply(AR, AR) ->
2385    ok;
2386compact_otp5186_check_ammsReply(#'AmmsReply'{terminationID = ID,
2387					     terminationAudit = TA1},
2388				#'AmmsReply'{terminationID = ID,
2389					     terminationAudit = TA2}) ->
2390    %% This is just to simplify the test
2391    F = fun(asn1_NOVALUE) -> [];
2392	   (E) -> E
2393	end,
2394    compact_otp5186_check_termAudit(F(TA1), F(TA2));
2395compact_otp5186_check_ammsReply(AR1, AR2) ->
2396    exit({unexpected_ammsReply, AR1, AR2}).
2397
2398compact_otp5186_check_auditRes(AR, AR) ->
2399    ok;
2400compact_otp5186_check_auditRes(#'AuditResult'{terminationID = ID,
2401					      terminationAuditResult = TAR1},
2402			       #'AuditResult'{terminationID = ID,
2403					      terminationAuditResult = TAR2}) ->
2404    compact_otp5186_check_termAuditRes(TAR1, TAR2);
2405compact_otp5186_check_auditRes(AR1, AR2) ->
2406    exit({unexpected_auditResult, AR1, AR2}).
2407
2408compact_otp5186_check_termAuditRes([], []) ->
2409    ok;
2410%% An empty empty descriptor is removed
2411compact_otp5186_check_termAuditRes([{emptyDescriptors,
2412				     #'AuditDescriptor'{auditToken = asn1_NOVALUE}}|TAR1], []) ->
2413    compact_otp5186_check_termAuditRes(TAR1, []);
2414compact_otp5186_check_termAuditRes(TAR1, []) ->
2415    exit({not_equal, termAuditRes, TAR1, []});
2416%% An empty empty descriptor is removed
2417compact_otp5186_check_termAuditRes([], [{emptyDescriptors,
2418					 #'AuditDescriptor'{auditToken = asn1_NOVALUE}}|TAR2]) ->
2419    compact_otp5186_check_termAuditRes([], TAR2);
2420compact_otp5186_check_termAuditRes([], TAR2) ->
2421    exit({not_equal, termAuditRes, [], TAR2});
2422compact_otp5186_check_termAuditRes([ARP1|TAR1], [ARP2|TAR2]) ->
2423    compact_otp5186_check_auditRetParm(ARP1, ARP2),
2424    compact_otp5186_check_termAuditRes(TAR1, TAR2).
2425
2426compact_otp5186_check_termAudit([], []) ->
2427    ok;
2428%% An empty empty descriptor is removed
2429compact_otp5186_check_termAudit([{emptyDescriptors,
2430				  #'AuditDescriptor'{auditToken = asn1_NOVALUE}}|TAR1], []) ->
2431    compact_otp5186_check_termAudit(TAR1, []);
2432compact_otp5186_check_termAudit(TAR1, []) ->
2433    exit({not_equal, termAudit, TAR1, []});
2434%% An empty empty descriptor is removed
2435compact_otp5186_check_termAudit([],
2436				[{emptyDescriptors,
2437				  #'AuditDescriptor'{auditToken = asn1_NOVALUE}}|TAR2]) ->
2438    compact_otp5186_check_termAudit([], TAR2);
2439compact_otp5186_check_termAudit([], TAR2) ->
2440    exit({not_equal, termAudit, [], TAR2});
2441compact_otp5186_check_termAudit([ARP1|TAR1], [ARP2|TAR2]) ->
2442    compact_otp5186_check_auditRetParm(ARP1, ARP2),
2443    compact_otp5186_check_termAudit(TAR1, TAR2).
2444
2445compact_otp5186_check_auditRetParm(ARP, ARP) ->
2446    ok;
2447compact_otp5186_check_auditRetParm({emptyDescriptors, AD1},
2448				   {emptyDescriptors, AD2}) ->
2449    compact_otp5186_check_auditDesc(AD1, AD2);
2450compact_otp5186_check_auditRetParm(ARP1, ARP2) ->
2451    exit({unexpected_auditRetParm, ARP1, ARP2}).
2452
2453compact_otp5186_check_auditDesc(AD, AD) ->
2454    ok;
2455compact_otp5186_check_auditDesc(#'AuditDescriptor'{auditToken = L1},
2456				#'AuditDescriptor'{auditToken = L2}) ->
2457    compact_otp5186_check_auditDesc_auditItems(L1, L2);
2458compact_otp5186_check_auditDesc(AD1, AD2) ->
2459    exit({unexpected_auditDesc, AD1, AD2}).
2460
2461compact_otp5186_check_auditDesc_auditItems([], []) ->
2462    ok;
2463compact_otp5186_check_auditDesc_auditItems(AI1, []) ->
2464    exit({not_equal, auditItems, AI1, []});
2465compact_otp5186_check_auditDesc_auditItems([], AI2) ->
2466    exit({not_equal, auditItems, [], AI2});
2467compact_otp5186_check_auditDesc_auditItems([AI1|AIs1], [AI2|AIs2]) ->
2468    compact_otp5186_check_auditDesc_auditItem(AI1, AI2),
2469    compact_otp5186_check_auditDesc_auditItems(AIs1, AIs2).
2470
2471compact_otp5186_check_auditDesc_auditItem(AI, AI) ->
2472    ok;
2473compact_otp5186_check_auditDesc_auditItem(AI1, AI2) ->
2474    exit({not_equal, auditItem, AI1, AI2}).
2475
2476compact_otp5793_msg01(suite) ->
2477    [];
2478compact_otp5793_msg01(Config) when is_list(Config) ->
2479    d("compact_otp5793_msg01 -> entry", []),
2480    ?ACQUIRE_NODES(1, Config),
2481    compact_otp5793(ok, pretty_otp5793_msg1()).
2482
2483compact_otp5793(Expected, Msg) ->
2484    expect_codec(Expected, megaco_compact_text_encoder, Msg, []).
2485
2486
2487%% --------------------------------------------------------------
2488
2489compact_otp5993_msg01(suite) ->
2490    [];
2491compact_otp5993_msg01(Config) when is_list(Config) ->
2492    d("compact_otp5993_msg01 -> entry", []),
2493    ?ACQUIRE_NODES(1, Config),
2494    compact_otp5993_msg_1(compact_otp5993_msg01(), ok, ok).
2495
2496compact_otp5993_msg02(suite) ->
2497    [];
2498compact_otp5993_msg02(Config) when is_list(Config) ->
2499    d("compact_otp5993_msg02 -> entry", []),
2500    ?ACQUIRE_NODES(1, Config),
2501    compact_otp5993_msg_1(compact_otp5993_msg02(), ok, ok).
2502
2503compact_otp5993_msg03(suite) ->
2504    [];
2505compact_otp5993_msg03(Config) when is_list(Config) ->
2506    d("compact_otp5993_msg03 -> entry", []),
2507    ?ACQUIRE_NODES(1, Config),
2508    compact_otp5993_msg_1(compact_otp5993_msg03(), ok, ok).
2509
2510compact_otp5993_msg_1(Msg1, EncodeExpect, DecodeExpect) ->
2511    case encode_message(megaco_compact_text_encoder, [], Msg1) of
2512	{ok, Bin} when EncodeExpect =:= ok ->
2513 	    io:format(" encoded", []),
2514 	    %% io:format(" encoded:~n~s~n", [binary_to_list(Bin)]),
2515	    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
2516		{ok, Msg1} when DecodeExpect =:= ok ->
2517		    io:format(", decoded - equal:", []),
2518		    ok;
2519		{ok, Msg3} when DecodeExpect =:= error ->
2520		    M = binary_to_list(Bin),
2521		    io:format(", decoded:", []),
2522		    exit({unexpected_decode_success, M, Msg1, Msg3});
2523		Else when DecodeExpect =:= ok ->
2524		    M = binary_to_list(Bin),
2525		    io:format(", decode failed ", []),
2526		    exit({unexpected_decode_failure, Msg1, M, Else});
2527		_Else when DecodeExpect =:= error ->
2528		    io:format(", decode failed ", []),
2529		    ok
2530	    end;
2531	{ok, Bin} when EncodeExpect =:= error ->
2532	    M = binary_to_list(Bin),
2533	    io:format(" encoded", []),
2534	    exit({unexpected_encode_success, Msg1, M});
2535	_Else when EncodeExpect =:= error ->
2536	    io:format(" encode failed ", []),
2537	    ok;
2538	Else when EncodeExpect =:= ok ->
2539	    io:format(" encode failed ", []),
2540	    exit({unexpected_encode_result, Else})
2541    end.
2542
2543compact_otp5993_msg01() ->
2544    MT = h221,
2545    T  = #megaco_term_id{id = ?A4444},
2546    TL = [T],
2547    MD = #'MuxDescriptor'{muxType  = MT,
2548			  termList = TL},
2549    compact_otp5993_msg(MD).
2550
2551compact_otp5993_msg02() ->
2552    MT = h223,
2553    T1 = #megaco_term_id{id = ?A4445},
2554    T2 = #megaco_term_id{id = ?A5556},
2555    TL = [T1, T2],
2556    MD = #'MuxDescriptor'{muxType  = MT,
2557			  termList = TL},
2558    compact_otp5993_msg(MD).
2559
2560compact_otp5993_msg(MD) when is_record(MD, 'MuxDescriptor') ->
2561    AmmDesc  = {muxDescriptor, MD},
2562    AmmReq   = #'AmmRequest'{terminationID = [hd(MD#'MuxDescriptor'.termList)],
2563			     descriptors   = [AmmDesc]},
2564    Cmd      = {addReq, AmmReq},
2565    CmdReq   = #'CommandRequest'{command = Cmd},
2566    ActReq   = #'ActionRequest'{contextId       = 5993,
2567				commandRequests = [CmdReq]},
2568    TransReq = #'TransactionRequest'{transactionId = 3995,
2569				     actions       = [ActReq]},
2570    Trans    = {transactionRequest, TransReq},
2571    Body     = {transactions, [Trans]},
2572    Msg      = #'Message'{version = ?VERSION,
2573			  mId     = ?MG1_MID,
2574			  messageBody = Body},
2575    #'MegacoMessage'{mess = Msg}.
2576
2577compact_otp5993_msg03() ->
2578    T1       = #megaco_term_id{id = ?A4445},
2579    T2       = #megaco_term_id{id = ?A5556},
2580    TIDs     = [T1, T2],
2581    AudRep   = {contextAuditResult, TIDs},
2582    CmdRep   = {auditValueReply, AudRep},
2583    ActRep   = #'ActionReply'{contextId    = 5993,
2584			      commandReply = [CmdRep]},
2585    TransRes = {actionReplies, [ActRep]},
2586    TransRep = #'TransactionReply'{transactionId     = 3995,
2587				   transactionResult = TransRes},
2588    Trans    = {transactionReply, TransRep},
2589    Body     = {transactions, [Trans]},
2590    Msg      = #'Message'{version     = ?VERSION,
2591			  mId         = ?MG1_MID,
2592			  messageBody = Body},
2593    #'MegacoMessage'{mess = Msg}.
2594
2595
2596%% --------------------------------------------------------------
2597
2598compact_otp6017_msg01(suite) ->
2599    [];
2600compact_otp6017_msg01(Config) when is_list(Config) ->
2601    d("compact_otp6017_msg01 -> entry", []),
2602    ?ACQUIRE_NODES(1, Config),
2603    ok = compact_otp6017(0),
2604    ok.
2605
2606compact_otp6017_msg02(suite) ->
2607    [];
2608compact_otp6017_msg02(Config) when is_list(Config) ->
2609    d("compact_otp6017_msg02 -> entry", []),
2610    ?ACQUIRE_NODES(1, Config),
2611    ok = compact_otp6017(16#FFFFFFFE),
2612    ok.
2613
2614compact_otp6017_msg03(suite) ->
2615    [];
2616compact_otp6017_msg03(Config) when is_list(Config) ->
2617    d("compact_otp6017_msg03 -> entry", []),
2618    ?ACQUIRE_NODES(1, Config),
2619    ok = compact_otp6017(16#FFFFFFFF),
2620    ok.
2621
2622compact_otp6017(BadCID) ->
2623    M   = compact_otp6017_msg(BadCID),
2624    Bin = list_to_binary(M),
2625    case decode_message(megaco_compact_text_encoder, false, [], Bin) of
2626	{ok, Msg} ->
2627	    exit({unexpected_decode_success, {Msg, M}});
2628	{error, Reason} when is_list(Reason) -> % Expected result
2629	    case lists:keysearch(reason, 1, Reason) of
2630		{value, {reason, {_Line, _Mod, {bad_ContextID, BadCID}}}} ->
2631		    io:format(" ~w", [BadCID]),
2632		    ok;
2633		{value, {reason, ActualReason}} ->
2634		    exit({unexpected_reason, ActualReason});
2635		false ->
2636		    exit({reason_not_found, Reason})
2637	    end;
2638	Crap ->
2639	    exit({unexpected_decode_result, Crap})
2640    end.
2641
2642
2643compact_otp6017_msg(CID) when is_integer(CID) ->
2644    "MEGACO/" ?VERSION_STR " MG1 T=12345678{C=" ++
2645	integer_to_list(CID) ++
2646	"{SC=root{SV{MT=RS,RE=901}}}}".
2647
2648
2649%% ==============================================================
2650%%
2651%% F l e x   C o m p a c t   T e s t c a s e s
2652%%
2653
2654flex_compact_otp7431_msg01a(suite) ->
2655    [];
2656flex_compact_otp7431_msg01a(Config) when is_list(Config) ->
2657    %% put(severity,trc),
2658    %% put(dbg,true),
2659    d("flex_comppact_otp7431_msg01a -> entry", []),
2660    Conf = flex_scanner_conf(Config),
2661    flex_compact_otp7431(ok, flex_compact_otp7431_msg1a(), [Conf]).
2662
2663flex_compact_otp7431_msg01b(suite) ->
2664    [];
2665flex_compact_otp7431_msg01b(Config) when is_list(Config) ->
2666    %% put(severity,trc),
2667    %% put(dbg,true),
2668    d("flex_comppact_otp7431_msg01b -> entry", []),
2669    Conf = flex_scanner_conf(Config),
2670    flex_compact_otp7431(ok, flex_compact_otp7431_msg1b(), [Conf]).
2671
2672flex_compact_otp7431_msg02(suite) ->
2673    [];
2674flex_compact_otp7431_msg02(Config) when is_list(Config) ->
2675    %% put(severity,trc),
2676    %% put(dbg,true),
2677    d("flex_comppact_otp7431_msg02 -> entry", []),
2678    Conf = flex_scanner_conf(Config),
2679    flex_compact_otp7431(error, flex_compact_otp7431_msg2(), [Conf]).
2680
2681flex_compact_otp7431_msg03(suite) ->
2682    [];
2683flex_compact_otp7431_msg03(Config) when is_list(Config) ->
2684    %% put(severity,trc),
2685    %% put(dbg,true),
2686    d("flex_comppact_otp7431_msg03 -> entry", []),
2687    Conf = flex_scanner_conf(Config),
2688    flex_compact_otp7431(error, flex_compact_otp7431_msg3(), [Conf]).
2689
2690flex_compact_otp7431_msg04(suite) ->
2691    [];
2692flex_compact_otp7431_msg04(Config) when is_list(Config) ->
2693    %% put(severity,trc),
2694    %% put(dbg,true),
2695    d("flex_comppact_otp7431_msg04 -> entry", []),
2696    Conf = flex_scanner_conf(Config),
2697    flex_compact_otp7431(error, flex_compact_otp7431_msg4(), [Conf]).
2698
2699flex_compact_otp7431_msg05(suite) ->
2700    [];
2701flex_compact_otp7431_msg05(Config) when is_list(Config) ->
2702    %% put(severity,trc),
2703    %% put(dbg,true),
2704    d("flex_comppact_otp7431_msg05 -> entry", []),
2705    Conf = flex_scanner_conf(Config),
2706    flex_compact_otp7431(error, flex_compact_otp7431_msg5(), [Conf]).
2707
2708flex_compact_otp7431_msg06(suite) ->
2709    [];
2710flex_compact_otp7431_msg06(Config) when is_list(Config) ->
2711    %% put(severity,trc),
2712    %% put(dbg,true),
2713    d("flex_comppact_otp7431_msg06 -> entry", []),
2714    Conf = flex_scanner_conf(Config),
2715    flex_compact_otp7431(error, flex_compact_otp7431_msg6(), [Conf]).
2716
2717flex_compact_otp7431_msg07(suite) ->
2718    [];
2719flex_compact_otp7431_msg07(Config) when is_list(Config) ->
2720    %% put(severity,trc),
2721    %% put(dbg,true),
2722    d("flex_comppact_otp7431_msg07 -> entry", []),
2723    Conf = flex_scanner_conf(Config),
2724    flex_compact_otp7431(error, flex_compact_otp7431_msg7(), [Conf]).
2725
2726
2727flex_compact_otp7431(Expected, Msg, Conf) ->
2728    otp7431(Expected, megaco_compact_text_encoder, Msg, Conf).
2729
2730flex_compact_otp7431_msg1a() ->
2731    "!/1 [124.124.124.222]:55555
2732P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2733v=0
2734o=- 2890844526 2890842807 IN IP4 124.124.124.222
2735s=-
2736t= 0 0
2737c=IN IP4 124.124.124.222
2738m=audio 2222 RTP/AVP 4
2739a=ptime:30
2740a=recvonly
2741}}}}}}".
2742
2743flex_compact_otp7431_msg1b() ->
2744    "!/1 [124.124.124.222]:55555
2745P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2746v=0
2747o=- 2890844526 2890842807 IN IP4 124.124.124.222
2748s=-
2749t= 0 0
2750c=IN IP4 124.124.124.222
2751m=audio 2222 RTP/AVP 4
2752a=ptime:30
2753a=recvonly
2754
2755
2756
2757}}}}}}".
2758
2759flex_compact_otp7431_msg2() ->
2760    "!/1 [124.124.124.222]:55555
2761P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2762v=0
2763o=- 2890844526 2890842807 IN IP4 124.124.124.222
2764s=-
2765t= 0 0
2766c=IN IP4 124.124.124.222
2767m=audio 2222 RTP/AVP 4
2768a=ptime:30
2769a=     }
2770}}}}}".
2771
2772
2773flex_compact_otp7431_msg3() ->
2774    "!/1 [124.124.124.222]:55555
2775P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2776v=0
2777o=- 2890844526 2890842807 IN IP4 124.124.124.222
2778s=-
2779t= 0 0
2780c=IN IP4 124.124.124.222
2781m=audio 2222 RTP/AVP 4
2782a=ptime:30
2783a     }
2784}}}}}".
2785
2786
2787flex_compact_otp7431_msg4() ->
2788    "!/1 [124.124.124.222]:55555
2789P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2790v=0
2791o=- 2890844526 2890842807 IN IP4 124.124.124.222
2792s=-
2793t= 0 0
2794c=IN IP4 124.124.124.222
2795m=audio 2222 RTP/AVP 4
2796a=ptime:30
2797a}
2798}}}}}".
2799
2800
2801flex_compact_otp7431_msg5() ->
2802    "!/1 [124.124.124.222]:55555
2803P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2804v=       }
2805}}}}}".
2806
2807
2808flex_compact_otp7431_msg6() ->
2809    "!/1 [124.124.124.222]:55555
2810P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2811v       }
2812}}}}}".
2813
2814flex_compact_otp7431_msg7() ->
2815    "!/1 [124.124.124.222]:55555
2816P=10003{C=2000{A=a4444,A=a4445{M{ST=1{L{
2817v}
2818}}}}}".
2819
2820
2821%% ==============================================================
2822%%
2823%% P r e t t y   T e s t c a s e s
2824%%
2825
2826pretty_otp4632_msg1(suite) ->
2827    [];
2828pretty_otp4632_msg1(Config) when is_list(Config) ->
2829    d("pretty_otp4632_msg1 -> entry", []),
2830    ?ACQUIRE_NODES(1, Config),
2831    Msg0 = pretty_otp4632_msg1(),
2832    case encode_message(megaco_pretty_text_encoder, [], Msg0) of
2833	{ok, BinMsg} when is_binary(BinMsg) ->
2834	    {ok, Msg1} = decode_message(megaco_pretty_text_encoder, false,
2835					[], BinMsg),
2836	    ok = chk_MegacoMessage(Msg0,Msg1);
2837	Else ->
2838	    t("pretty_otp4632_msg1 -> "
2839	      "~n   Else: ~w", [Else]),
2840	    exit({unexpected_decode_result, Else})
2841    end.
2842
2843pretty_otp4632_msg1() ->
2844    msg4(?MG1_MID_NO_PORT, "901 mg col boot").
2845
2846pretty_otp4632_msg2(suite) ->
2847    [];
2848pretty_otp4632_msg2(Config) when is_list(Config) ->
2849    d("pretty_otp4632_msg2 -> entry", []),
2850    ?ACQUIRE_NODES(1, Config),
2851    Msg0 = pretty_otp4632_msg2(),
2852    case encode_message(megaco_pretty_text_encoder, [], Msg0) of
2853	{ok, BinMsg} when is_binary(BinMsg) ->
2854	    {ok, Msg1} = decode_message(megaco_pretty_text_encoder, false,
2855					[], BinMsg),
2856	    ok = chk_MegacoMessage(Msg0,Msg1);
2857	Else ->
2858	    t("pretty_otp4632_msg2 -> "
2859	      "~n   Else: ~w", [Else]),
2860	    exit({unexpected_decode_result, Else})
2861    end.
2862
2863pretty_otp4632_msg2() ->
2864    msg4(?MG1_MID_NO_PORT, "901").
2865
2866
2867pretty_otp4632_msg3(suite) ->
2868    [];
2869pretty_otp4632_msg3(Config) when is_list(Config) ->
2870    d("pretty_otp4632_msg3 -> entry", []),
2871    ?ACQUIRE_NODES(1, Config),
2872    Msg0 = pretty_otp4632_msg3(),
2873    Bin0 = list_to_binary(Msg0),
2874    case decode_message(megaco_pretty_text_encoder,
2875			false, [], Bin0) of
2876	{ok, Msg} when is_record(Msg, 'MegacoMessage') ->
2877	    {ok, Bin1} = encode_message(megaco_pretty_text_encoder, [], Msg),
2878	    Msg1 = binary_to_list(Bin1),
2879	    %% io:format("Msg1:~n~s~n", [Msg1]),
2880	    Msg0 = Msg1,
2881	    ok;
2882	Else ->
2883	    t("pretty_otp4632_msg3 -> "
2884	      "~n   Else: ~w", [Else]),
2885	    exit({unexpected_decode_result, Else})
2886    end.
2887
2888pretty_otp4632_msg3() ->
2889    M = "MEGACO/" ?VERSION_STR " [124.124.124.222]\nTransaction = 9998 {\n\tContext = - {\n\t\tServiceChange = root {\n\t\t\tServices {\n\t\t\t\tMethod = Restart,\n\t\t\t\tServiceChangeAddress = 55555,\n\t\t\t\tProfile = resgw/1,\n\t\t\t\tReason = \"901\"\n\t\t\t}\n\t\t}\n\t}\n}",
2890    M.
2891
2892
2893pretty_otp4632_msg4(suite) ->
2894    [];
2895pretty_otp4632_msg4(Config) when is_list(Config) ->
2896    d("pretty_otp4632_msg4 -> entry", []),
2897    ?ACQUIRE_NODES(1, Config),
2898    Msg0 = pretty_otp4632_msg4(),
2899    Bin0 = list_to_binary(Msg0),
2900    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
2901	{ok, Msg} when is_record(Msg, 'MegacoMessage') ->
2902	    {ok, Bin1} = encode_message(megaco_pretty_text_encoder, [], Msg),
2903	    Msg1 = binary_to_list(Bin1),
2904	    %% io:format("Msg1:~n~s~n", [Msg1]),
2905	    pretty_otp4632_msg4_chk(Msg0,Msg1);
2906	Else ->
2907	    t("pretty_otp4632_msg4 -> "
2908	      "~n   Else: ~w", [Else]),
2909	    exit({unexpected_decode_result, Else})
2910    end.
2911
2912
2913pretty_otp4632_msg4() ->
2914    M = "MEGACO/" ?VERSION_STR " [124.124.124.222]\nTransaction = 9998 {\n\tContext = - {\n\t\tServiceChange = root {\n\t\t\tServices {\n\t\t\t\tMethod = Restart,\n\t\t\t\tServiceChangeAddress = 55555,\n\t\t\t\tProfile = resgw/1,\n\t\t\t\tReason = 901\n\t\t\t}\n\t\t}\n\t}\n}",
2915    M.
2916
2917
2918pretty_otp4632_msg4_chk([], []) ->
2919    exit(messages_not_eq);
2920pretty_otp4632_msg4_chk([], Rest1) ->
2921    exit({messages_not_eq1, Rest1});
2922pretty_otp4632_msg4_chk(Rest0, []) ->
2923    exit({messages_not_eq0, Rest0});
2924pretty_otp4632_msg4_chk([$R,$e,$a,$s,$o,$n,$ ,$=,$ ,$9,$0,$1|_Rest0],
2925			[$R,$e,$a,$s,$o,$n,$ ,$=,$ ,$",$9,$0,$1,$"|_Rest1]) ->
2926    ok;
2927pretty_otp4632_msg4_chk([_|Rest0], [_|Rest1]) ->
2928    pretty_otp4632_msg4_chk(Rest0,Rest1).
2929
2930
2931pretty_otp4710_msg1(suite) ->
2932    [];
2933pretty_otp4710_msg1(Config) when is_list(Config) ->
2934    d("pretty_otp4710_msg1 -> entry", []),
2935    ?ACQUIRE_NODES(1, Config),
2936    Msg0 = pretty_otp4710_msg1(),
2937    case encode_message(megaco_pretty_text_encoder, [], Msg0) of
2938	{ok, Bin} when is_binary(Bin) ->
2939	    {ok, Msg1} = decode_message(megaco_pretty_text_encoder, false,
2940					[], Bin),
2941	    ok = chk_MegacoMessage(Msg0,Msg1);
2942	Else ->
2943	    t("pretty_otp4710_msg1 -> "
2944	      "~n   Else: ~w", [Else]),
2945	    exit({unexpected_decode_result, Else})
2946    end.
2947
2948pretty_otp4710_msg1() ->
2949    msg40().
2950
2951
2952pretty_otp4710_msg2(suite) ->
2953    [];
2954pretty_otp4710_msg2(Config) when is_list(Config) ->
2955    d("pretty_otp4710_msg2 -> entry", []),
2956    ?ACQUIRE_NODES(1, Config),
2957    Msg0 = pretty_otp4710_msg2(),
2958    Bin0 = list_to_binary(Msg0),
2959    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
2960	{ok, Msg} when is_record(Msg, 'MegacoMessage') ->
2961	    {ok, Bin1} = encode_message(megaco_pretty_text_encoder, [], Msg),
2962	    Msg1 = binary_to_list(Bin1),
2963	    %% io:format("Msg1:~n~s~n", [Msg1]),
2964	    pretty_otp4710_msg2_chk(Msg0,Msg1);
2965	Else ->
2966	    t("pretty_otp4710_msg2 -> "
2967	      "~n   Else: ~w", [Else]),
2968	    exit({unexpected_decode_result, Else})
2969    end.
2970
2971pretty_otp4710_msg2() ->
2972    "Authentication = 0xEFCDAB89:0x12345678:0x1234567889ABCDEF76543210\nMEGACO/" ?VERSION_STR " [124.124.124.222]\nTransaction = 9998 {\n\tContext = - {\n\t\tServiceChange = root {\n\t\t\tServices {\n\t\t\t\tMethod = Restart,\n\t\t\t\tServiceChangeAddress = 55555,\n\t\t\t\tProfile = resgw/1,\n\t\t\t\tReason = \"901 mg col boot\"\n\t\t\t}\n\t\t}\n\t}\n}".
2973
2974pretty_otp4710_msg2_chk(Msg,Msg) ->
2975    ok;
2976pretty_otp4710_msg2_chk(
2977  [$A,$u,$t,$h,$e,$n,$t,$i,$c,$a,$t,$i,$o,$n,$=,$ |Msg0],
2978  [$A,$u,$t,$h,$e,$n,$t,$i,$c,$a,$t,$i,$o,$n,$=,$ |Msg1]) ->
2979    {AH0, Rest0} = pretty_otp4710_msg2_chk_ah(Msg0, []),
2980    {AH1, Rest1} = pretty_otp4710_msg2_chk_ah(Msg1, []),
2981    case AH0 == AH1 of
2982	true ->
2983	    exit({message_not_equal, Rest0, Rest1});
2984	false ->
2985	    exit({auth_header_not_equal, AH0, AH1})
2986    end.
2987
2988pretty_otp4710_msg2_chk_ah([], _Acc) ->
2989    exit(no_auth_header_found);
2990pretty_otp4710_msg2_chk_ah([$M,$E,$G,$A,$C,$O,$/,_|Rest], Acc) ->
2991    {lists:reverse(Acc), Rest};
2992pretty_otp4710_msg2_chk_ah([C|R], Acc) ->
2993    pretty_otp4710_msg2_chk_ah(R, [C|Acc]).
2994
2995
2996pretty_otp4945_msg1(suite) ->
2997    [];
2998pretty_otp4945_msg1(Config) when is_list(Config) ->
2999    d("pretty_otp4945_msg1 -> entry", []),
3000    ?ACQUIRE_NODES(1, Config),
3001    Msg0 = pretty_otp4945_msg1(),
3002    Bin0 = list_to_binary(Msg0),
3003    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3004	{error, [{reason, Reason}|_]} ->
3005	    case Reason of
3006		{missing_required_serviceChangeParm, [serviceChangeReason]} ->
3007		    ok;
3008		Else ->
3009		    t("pretty_otp4945_msg1 -> "
3010		      "~n   Else: ~w", [Else]),
3011		    exit({unexpected_decode_result, Else})
3012	    end;
3013	Else ->
3014	    io:format("pretty_otp4945_msg1 -> "
3015		      "~n   Else: ~w"
3016		      "~n", [Else]),
3017	    exit({unexpected_decode_result, Else})
3018    end.
3019
3020pretty_otp4945_msg1() ->
3021"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
3022   Context = - {
3023      ServiceChange = ROOT {
3024         Services {
3025            Method = Restart,
3026            ServiceChangeAddress = 55555,
3027            Profile = ResGW/1
3028         }
3029      }
3030   }
3031}".
3032
3033
3034pretty_otp4945_msg2(suite) ->
3035    [];
3036pretty_otp4945_msg2(Config) when is_list(Config) ->
3037    d("pretty_otp4945_msg2 -> entry", []),
3038    ?ACQUIRE_NODES(1, Config),
3039    Msg0 = pretty_otp4945_msg2(),
3040    Bin0 = list_to_binary(Msg0),
3041    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3042	{error, [{reason, Reason}|_]} ->
3043	    case Reason of
3044		{missing_required_serviceChangeParm, [serviceChangeMethod]} ->
3045		    ok;
3046		Else ->
3047		    t("pretty_otp4945_msg2 -> "
3048		      "~n   Else: ~w", [Else]),
3049		    exit({unexpected_decode_result, Else})
3050	    end;
3051	Else ->
3052	    t("pretty_otp4945_msg2 -> "
3053	      "~n   Else: ~w", [Else]),
3054	    exit({unexpected_decode_result, Else})
3055    end.
3056
3057pretty_otp4945_msg2() ->
3058"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
3059   Context = - {
3060      ServiceChange = ROOT {
3061         Services {
3062            Reason = 901,
3063            ServiceChangeAddress = 55555,
3064            Profile = ResGW/1
3065         }
3066      }
3067   }
3068}".
3069
3070
3071pretty_otp4945_msg3(suite) ->
3072    [];
3073pretty_otp4945_msg3(Config) when is_list(Config) ->
3074    d("pretty_otp4945_msg3 -> entry", []),
3075    ?ACQUIRE_NODES(1, Config),
3076    Msg0 = pretty_otp4945_msg3(),
3077    Bin0 = list_to_binary(Msg0),
3078    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3079	{error, [{reason, Reason}|_]} ->
3080	    case Reason of
3081		{missing_required_serviceChangeParm, [serviceChangeReason, serviceChangeMethod]} ->
3082		    ok;
3083		{missing_required_serviceChangeParm, [serviceChangeMethod, serviceChangeReason]} ->
3084		    ok;
3085		Else ->
3086		    t("pretty_otp4945_msg3 -> "
3087		      "~n   Else: ~w", [Else]),
3088		    exit({unexpected_decode_result, Else})
3089	    end;
3090	Else ->
3091	    t("pretty_otp4945_msg3 -> "
3092	      "~n   Else: ~w", [Else]),
3093	    exit({unexpected_decode_result, Else})
3094    end.
3095
3096pretty_otp4945_msg3() ->
3097"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
3098   Context = - {
3099      ServiceChange = ROOT {
3100         Services {
3101            ServiceChangeAddress = 55555,
3102            Profile = ResGW/1
3103         }
3104      }
3105   }
3106}".
3107
3108
3109pretty_otp4945_msg4(suite) ->
3110    [];
3111pretty_otp4945_msg4(Config) when is_list(Config) ->
3112    d("pretty_otp4945_msg4 -> entry", []),
3113    ?ACQUIRE_NODES(1, Config),
3114    Msg0 = pretty_otp4945_msg4(),
3115    Bin0 = list_to_binary(Msg0),
3116    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3117	{ok, _} ->
3118	    ok;
3119	Else ->
3120	    t("pretty_otp4945_msg4 -> "
3121	      "~n   Else: ~w", [Else]),
3122	    exit({unexpected_decode_result, Else})
3123    end.
3124
3125pretty_otp4945_msg4() ->
3126"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
3127   Context = - {
3128      ServiceChange = ROOT {
3129         Services {
3130            Method = Restart,
3131            Reason = 901,
3132            ServiceChangeAddress = 55555,
3133            Profile = ResGW/1
3134         }
3135      }
3136   }
3137}".
3138
3139
3140pretty_otp4945_msg5(suite) ->
3141    [];
3142pretty_otp4945_msg5(Config) when is_list(Config) ->
3143    d("pretty_otp4945_msg5 -> entry", []),
3144    ?ACQUIRE_NODES(1, Config),
3145    Msg0 = pretty_otp4945_msg5(),
3146    Bin0 = list_to_binary(Msg0),
3147    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3148	{error, [{reason, Reason}|_]} ->
3149	    case Reason of
3150		{at_most_once_serviceChangeParm, {profile, _Val1, _Val2}} ->
3151		    ok;
3152		Else ->
3153		    io:format("pretty_otp4945_msg6 -> "
3154			      "~n   Else: ~w"
3155			      "~n", [Else]),
3156		    exit({unexpected_decode_result, Else})
3157	    end;
3158	Else ->
3159	    t("pretty_otp4945_msg5 -> "
3160	      "~n   Else: ~w", [Else]),
3161	    exit({unexpected_decode_result, Else})
3162    end.
3163
3164pretty_otp4945_msg5() ->
3165"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
3166   Context = - {
3167      ServiceChange = ROOT {
3168         Services {
3169            Method = Restart,
3170            Reason = 901,
3171            Profile = ResGW/1,
3172            ServiceChangeAddress = 55555,
3173            Profile = ResGW/2
3174         }
3175      }
3176   }
3177}".
3178
3179
3180pretty_otp4945_msg6(suite) ->
3181    [];
3182pretty_otp4945_msg6(Config) when is_list(Config) ->
3183    d("pretty_otp4945_msg6 -> entry", []),
3184    ?ACQUIRE_NODES(1, Config),
3185    Msg0 = pretty_otp4945_msg6(),
3186    Bin0 = list_to_binary(Msg0),
3187    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3188	{error, [{reason, Reason}|_]} ->
3189	    case Reason of
3190		{not_both_address_mgcid_serviceChangeParm, _Val1, _Val2} ->
3191		    ok;
3192		Else ->
3193		    io:format("pretty_otp4945_msg6 -> "
3194			      "~n   Else: ~w"
3195			      "~n", [Else]),
3196		    exit({unexpected_decode_result, Else})
3197	    end;
3198	Else ->
3199	    t("pretty_otp4945_msg6 -> "
3200	      "~n   Else: ~w", [Else]),
3201	    exit({unexpected_decode_result, Else})
3202    end.
3203
3204pretty_otp4945_msg6() ->
3205"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
3206   Context = - {
3207      ServiceChange = ROOT {
3208         Services {
3209            Method = Restart,
3210               Reason = 901,
3211               ServiceChangeAddress = 55555,
3212               MgcIdToTry = kalle,
3213               Profile = ResGW/1
3214            }
3215         }
3216   }
3217}".
3218
3219
3220pretty_otp4949_msg1(suite) ->
3221    [];
3222pretty_otp4949_msg1(Config) when is_list(Config) ->
3223    d("pretty_otp4949_msg1 -> entry", []),
3224    ?ACQUIRE_NODES(1, Config),
3225    Msg0 = pretty_otp4949_msg1(),
3226    Bin0 = list_to_binary(Msg0),
3227    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3228	{ok, _} ->
3229	    ok;
3230	Else ->
3231	    t("pretty_otp4949_msg1 -> "
3232	      "~n   Else: ~w", [Else]),
3233	    exit({unexpected_decode_result, Else})
3234    end.
3235
3236pretty_otp4949_msg1() ->
3237"MEGACO/" ?VERSION_STR " [124.124.124.222] Reply = 9998 {
3238   Context = - {
3239      ServiceChange = ROOT {
3240         Services {
3241            ServiceChangeAddress = 55555,
3242            Profile = ResGW/1
3243         }
3244      }
3245   }
3246}".
3247
3248
3249pretty_otp4949_msg2(suite) ->
3250    [];
3251pretty_otp4949_msg2(Config) when is_list(Config) ->
3252    d("pretty_otp4949_msg2 -> entry", []),
3253    ?ACQUIRE_NODES(1, Config),
3254    Msg0 = pretty_otp4949_msg2(),
3255    Bin0 = list_to_binary(Msg0),
3256    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3257	{error, [{reason, Reason}|_]} ->
3258	    case Reason of
3259		{at_most_once_servChgReplyParm, {profile, _Val1, _Val2}} ->
3260		    ok;
3261		Else ->
3262		    io:format("pretty_otp4949_msg2 -> "
3263			      "~n   Else: ~w"
3264			      "~n", [Else]),
3265		    exit({unexpected_decode_result, Else})
3266	    end;
3267	Else ->
3268	    t("pretty_otp4949_msg2 -> "
3269	      "~n   Else: ~w", [Else]),
3270	    exit({unexpected_decode_result, Else})
3271    end.
3272
3273pretty_otp4949_msg2() ->
3274"MEGACO/" ?VERSION_STR " [124.124.124.222] Reply = 9998 {
3275   Context = - {
3276      ServiceChange = ROOT {
3277         Services {
3278            Profile = ResGW/1,
3279            ServiceChangeAddress = 55555,
3280            Profile = ResGW/2
3281         }
3282      }
3283   }
3284}".
3285
3286
3287pretty_otp4949_msg3(suite) ->
3288    [];
3289pretty_otp4949_msg3(Config) when is_list(Config) ->
3290    d("pretty_otp4949_msg3 -> entry", []),
3291    ?ACQUIRE_NODES(1, Config),
3292    Msg0 = pretty_otp4949_msg3(),
3293    Bin0 = list_to_binary(Msg0),
3294    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3295	{error, [{reason, Reason}|_]} ->
3296	    case Reason of
3297		{not_both_address_mgcid_servChgReplyParm, _Val1, _Val2} ->
3298		    ok;
3299		Else ->
3300		    io:format("pretty_otp4949_msg3 -> "
3301			      "~n   Else: ~w"
3302			      "~n", [Else]),
3303		    exit({unexpected_decode_result, Else})
3304	    end;
3305	Else ->
3306	    t("pretty_otp4949_msg3 -> "
3307	      "~n   Else: ~w", [Else]),
3308	    exit({unexpected_decode_result, Else})
3309    end.
3310
3311pretty_otp4949_msg3() ->
3312"MEGACO/" ?VERSION_STR " [124.124.124.222] Reply = 9998 {
3313   Context = - {
3314      ServiceChange = ROOT {
3315         Services {
3316            ServiceChangeAddress = 55555,
3317            MgcIdToTry = kalle,
3318            Profile = ResGW/1
3319         }
3320      }
3321   }
3322}".
3323
3324
3325pretty_otp5042_msg1(suite) ->
3326    [];
3327pretty_otp5042_msg1(Config) when is_list(Config) ->
3328    d("pretty_otp5042_msg1 -> entry", []),
3329    ?ACQUIRE_NODES(1, Config),
3330    Msg0 = pretty_otp5042_msg1(),
3331    Bin0 = list_to_binary(Msg0),
3332    case decode_message(megaco_pretty_text_encoder, false, [], Bin0) of
3333	{error, [{reason, Reason}|_]} ->
3334	    case Reason of
3335		{_, _Mod, {not_an_integer, PropertyParm}} ->
3336		    exit({not_an_integer, PropertyParm});
3337		_ ->
3338		    io:format("pretty_otp5042_msg1 -> "
3339			      "~n   Reason: ~w"
3340			      "~n", [Reason]),
3341		    exit({unexpected_decode_result, Reason})
3342	    end;
3343	{ok, M} ->
3344	    t("pretty_otp5042_msg1 -> successfull decode:"
3345	      "~n~p", [M]),
3346	    ok
3347    end.
3348
3349pretty_otp5042_msg1() ->
3350"MEGACO/" ?VERSION_STR " <CATAPULT>:2944
3351Transaction = 102 {
3352Context =  5 { Notify =  MUX/1 { ObservedEvents = 1 {
3353h245bh/h245msgin { Stream =  1
3354, h245enc =
33550270020600088175000653401004100403E802E00180018001780680000034301160000700088175010101007A0100020001800001320000C0000219D005027F0070500100040100021080000319D005027F00504001008000041C001250000700088175010000400280010003000880000518AA027F400006850130008011020100000001030002000300040005000006
3356 }  }
3357 }  }  }".
3358
3359
3360pretty_otp5068_msg1(suite) ->
3361    [];
3362pretty_otp5068_msg1(Config) when is_list(Config) ->
3363    d("pretty_otp5068_msg1 -> entry", []),
3364    ?ACQUIRE_NODES(1, Config),
3365    Msg = pretty_otp5068_msg1(),
3366    case encode_message(megaco_pretty_text_encoder, [], Msg) of
3367	{error, Reason} ->
3368% 	    io:format("pretty_otp5068_msg1 -> "
3369% 		      "~n   Reason: ~w"
3370% 		      "~n", [Reason]),
3371	    exit({unexpected_encode_result, Reason});
3372	{ok, Bin} ->
3373% 	    io:format("pretty_otp5068_msg1 -> successfull encode:"
3374% 		      "~n~s~n", [binary_to_list(Bin)]),
3375	    case decode_message(megaco_pretty_text_encoder, false, [], Bin) of
3376		{ok, _} ->
3377% 		    io:format("pretty_otp5068_msg1 -> ok~n", []),
3378		    ok;
3379		Else ->
3380		    %% io:format("~npretty_otp5068_msg1 -> ~n~p~n", [Else]),
3381		    exit({unexpected_decode_result, Else})
3382	    end
3383    end.
3384
3385pretty_otp5068_msg1() ->
3386{'MegacoMessage',
3387 asn1_NOVALUE,
3388 {'Message',
3389  2,
3390  {deviceName,[109,103,51,51]},
3391  {transactions,
3392   [{transactionReply,
3393     {'TransactionReply',
3394      190,
3395      asn1_NOVALUE,
3396      {actionReplies,
3397       [{'ActionReply',  %% Comments: This is repeated many times.
3398	 0,
3399	 asn1_NOVALUE,
3400	 asn1_NOVALUE,
3401	 [{auditValueReply,
3402	   {auditResult,
3403	    {'AuditResult',
3404	     {megaco_term_id,false,
3405	      [[99,101,100,101,118,49,47,52,47,49,47,49],[51,49]]},
3406	     [{mediaDescriptor,
3407	       {'MediaDescriptor',
3408		{'TerminationStateDescriptor',
3409		 [],
3410		 asn1_NOVALUE,
3411		 inSvc},
3412		asn1_NOVALUE}}]}}}]}]}}}]}}}.
3413
3414
3415pretty_otp5085_msg1(suite) ->
3416    [];
3417pretty_otp5085_msg1(Config) when is_list(Config) ->
3418    d("pretty_otp5085_msg1 -> entry", []),
3419    ?ACQUIRE_NODES(1, Config),
3420    pretty_otp5085(ok, pretty_otp5085_msg1()).
3421
3422pretty_otp5085_msg2(suite) ->
3423    [];
3424pretty_otp5085_msg2(Config) when is_list(Config) ->
3425    d("pretty_otp5085_msg2 -> entry", []),
3426    ?ACQUIRE_NODES(1, Config),
3427    pretty_otp5085(error, pretty_otp5085_msg2()).
3428
3429pretty_otp5085_msg3(suite) ->
3430    [];
3431pretty_otp5085_msg3(Config) when is_list(Config) ->
3432    d("pretty_otp5085_msg3 -> entry", []),
3433    ?ACQUIRE_NODES(1, Config),
3434    pretty_otp5085(ok, pretty_otp5085_msg3()).
3435
3436pretty_otp5085_msg4(suite) ->
3437    [];
3438pretty_otp5085_msg4(Config) when is_list(Config) ->
3439    d("pretty_otp5085_msg4 -> entry", []),
3440    ?ACQUIRE_NODES(1, Config),
3441    pretty_otp5085(ok, pretty_otp5085_msg4()).
3442
3443pretty_otp5085_msg5(suite) ->
3444    [];
3445pretty_otp5085_msg5(Config) when is_list(Config) ->
3446    d("pretty_otp5085_msg5 -> entry", []),
3447    ?ACQUIRE_NODES(1, Config),
3448    pretty_otp5085(ok, pretty_otp5085_msg5()).
3449
3450pretty_otp5085_msg6(suite) ->
3451    [];
3452pretty_otp5085_msg6(Config) when is_list(Config) ->
3453    d("pretty_otp5085_msg6 -> entry", []),
3454    ?ACQUIRE_NODES(1, Config),
3455    pretty_otp5085(ok, pretty_otp5085_msg6()).
3456
3457pretty_otp5085_msg7(suite) ->
3458    [];
3459pretty_otp5085_msg7(Config) when is_list(Config) ->
3460    d("pretty_otp5085_msg7 -> entry", []),
3461    ?ACQUIRE_NODES(1, Config),
3462    pretty_otp5085(ok, pretty_otp5085_msg7()).
3463
3464pretty_otp5085(Expected, Msg) ->
3465    pretty_otp5085(Expected, Msg, []).
3466
3467pretty_otp5085(Expected, Msg, Conf) ->
3468    t("pretty_otp5085 -> entry with"
3469      "~n   Expected: ~p"
3470      "~n   Msg:      ~p", [Expected, Msg]),
3471    case (catch encode_message(megaco_pretty_text_encoder, Conf, Msg)) of
3472	{error, Reason} when Expected =:= error ->
3473 	    d("pretty_otp5085 -> encode failed as expected"
3474	      "~n   Reason: ~w", [Reason]),
3475	    ok;
3476	{error, Reason} ->
3477 	    e("pretty_otp5085 -> encode failed unexpectedly: "
3478	      "~n   Reason: ~w", [Reason]),
3479	    exit({unexpected_encode_result, Reason});
3480	{ok, Bin} when Expected =:= error ->
3481 	    e("pretty_otp5085 -> encode succeded unexpectedly: "
3482	      "~n   ~w", [binary_to_list(Bin)]),
3483	    exit({unexpected_encode_result, binary_to_list(Bin)});
3484	{ok, Bin} ->
3485	    d("pretty_otp5085 -> successfull encode as expected:"
3486	      "~n~s", [binary_to_list(Bin)]),
3487	    case decode_message(megaco_pretty_text_encoder, false, Conf, Bin) of
3488		{ok, Msg} ->
3489 		    d("pretty_otp5085 -> successfull decode~n", []),
3490		    ok;
3491		{ok, Msg2} ->
3492 		    e("pretty_otp5085 -> successfull decode"
3493		      " - but not equal", []),
3494		    exit({unexpected_decode_result, Msg, Msg2});
3495		Else ->
3496 		    e("pretty_otp5085 -> decode failed:~n~p", [Else]),
3497		    exit({unexpected_decode_result, Else})
3498	    end
3499    end.
3500
3501pretty_otp5085_msg1() ->
3502    {'MegacoMessage',
3503     asn1_NOVALUE,
3504     {'Message',
3505      ?VERSION,
3506      {deviceName,"mg36"},
3507      {transactions,
3508       [{transactionReply,
3509	 {'TransactionReply',
3510	  230,
3511	  asn1_NOVALUE,
3512	  {actionReplies,
3513	   [{'ActionReply',
3514	     400,
3515	     {'ErrorDescriptor',504,asn1_NOVALUE},
3516	     asn1_NOVALUE,
3517	     []
3518	    }
3519	   ]
3520	  }
3521	 }
3522	}
3523       ]
3524      }
3525     }
3526    }.
3527
3528pretty_otp5085_msg2() ->
3529    {'MegacoMessage',
3530     asn1_NOVALUE,
3531     {'Message',
3532      ?VERSION,
3533      {deviceName,"mg36"},
3534      {transactions,
3535       [{transactionReply,
3536	 {'TransactionReply',
3537	  230,
3538	  asn1_NOVALUE,
3539	  {actionReplies,
3540	   [{'ActionReply',
3541	     400,
3542	     asn1_NOVALUE,
3543	     asn1_NOVALUE,
3544	     []
3545	    }
3546	   ]
3547	  }
3548	 }
3549	}
3550       ]
3551      }
3552     }
3553    }.
3554
3555pretty_otp5085_msg3() ->
3556    {'MegacoMessage',
3557     asn1_NOVALUE,
3558     {'Message',
3559      ?VERSION,
3560      {deviceName,"mg36"},
3561      {transactions,
3562       [{transactionReply,
3563	 {'TransactionReply',
3564	  230,
3565	  asn1_NOVALUE,
3566	  {actionReplies,
3567	   [{'ActionReply',
3568	     400,
3569	     asn1_NOVALUE,
3570	     #'ContextRequest'{priority = 3},
3571	     []
3572	    }
3573	   ]
3574	  }
3575	 }
3576	}
3577       ]
3578      }
3579     }
3580    }.
3581
3582pretty_otp5085_msg4() ->
3583    {'MegacoMessage',
3584     asn1_NOVALUE,
3585     {'Message',
3586      ?VERSION,
3587      {deviceName,"mg36"},
3588      {transactions,
3589       [{transactionReply,
3590	 {'TransactionReply',
3591	  230,
3592	  asn1_NOVALUE,
3593	  {actionReplies,
3594	   [{'ActionReply',
3595	     400,
3596	     asn1_NOVALUE,
3597	     asn1_NOVALUE,
3598	     [{addReply,    cre_ammsReply([#megaco_term_id{id = ?A4444}])},
3599	      {notifyReply, cre_notifyReply([#megaco_term_id{id = ?A5555}])}]
3600	    }
3601	   ]
3602	  }
3603	 }
3604	}
3605       ]
3606      }
3607     }
3608    }.
3609
3610pretty_otp5085_msg5() ->
3611    {'MegacoMessage',
3612     asn1_NOVALUE,
3613     {'Message',
3614      ?VERSION,
3615      {deviceName,"mg36"},
3616      {transactions,
3617       [{transactionReply,
3618	 {'TransactionReply',
3619	  230,
3620	  asn1_NOVALUE,
3621	  {actionReplies,
3622	   [{'ActionReply',
3623	     400,
3624	     asn1_NOVALUE,
3625	     #'ContextRequest'{priority = 5},
3626	     [{addReply,    cre_ammsReply([#megaco_term_id{id = ?A4444}])},
3627	      {notifyReply, cre_notifyReply([#megaco_term_id{id = ?A5555}])}]
3628	    }
3629	   ]
3630	  }
3631	 }
3632	}
3633       ]
3634      }
3635     }
3636    }.
3637
3638pretty_otp5085_msg6() ->
3639    {'MegacoMessage',
3640     asn1_NOVALUE,
3641     {'Message',
3642      ?VERSION,
3643      {deviceName,"msg36"},
3644      {transactions,
3645       [{transactionReply,
3646	 {'TransactionReply',
3647	  230,
3648	  asn1_NOVALUE,
3649	  {actionReplies,
3650	   [{'ActionReply',
3651	     400,
3652	     {'ErrorDescriptor',504,asn1_NOVALUE},
3653	     #'ContextRequest'{priority = 6},
3654	     [{addReply,    cre_ammsReply([#megaco_term_id{id = ?A4444}])},
3655	      {notifyReply, cre_notifyReply([#megaco_term_id{id = ?A5555}])}]
3656	    }
3657	   ]
3658	  }
3659	 }
3660	}
3661       ]
3662      }
3663     }
3664    }.
3665
3666pretty_otp5085_msg7() ->
3667    {'MegacoMessage',
3668     asn1_NOVALUE,
3669     {'Message',
3670      ?VERSION,
3671      {deviceName,"msg36"},
3672      {transactions,
3673       [{transactionReply,
3674	 {'TransactionReply',
3675	  230,
3676	  asn1_NOVALUE,
3677	  {actionReplies,
3678	   [{'ActionReply',
3679	     400,
3680	     {'ErrorDescriptor',504,asn1_NOVALUE},
3681	     #'ContextRequest'{priority = 7},
3682	     [{notifyReply, cre_notifyReply([#megaco_term_id{id = ?A5555}])}]
3683	    }
3684	   ]
3685	  }
3686	 }
3687	}
3688       ]
3689      }
3690     }
3691    }.
3692
3693
3694pretty_otp5600_msg1(suite) ->
3695    [];
3696pretty_otp5600_msg1(Config) when is_list(Config) ->
3697    d("pretty_otp5600_msg1 -> entry", []),
3698    ?ACQUIRE_NODES(1, Config),
3699    %%     put(severity,trc),
3700    %%     put(dbg,true),
3701    pretty_otp5600(ok, pretty_otp5600_msg1()).
3702
3703pretty_otp5600_msg2(suite) ->
3704    [];
3705pretty_otp5600_msg2(Config) when is_list(Config) ->
3706    d("pretty_otp5600_msg2 -> entry", []),
3707    ?ACQUIRE_NODES(1, Config),
3708%%     put(severity,trc),
3709%%     put(dbg,true),
3710    pretty_otp5600(ok, pretty_otp5600_msg2()).
3711
3712pretty_otp5600(Expected, Msg) ->
3713    pretty_otp5600(Expected, Msg, []).
3714
3715pretty_otp5600(Expected, Msg, Conf) ->
3716    t("pretty_otp5600 -> entry with"
3717      "~n   Expected: ~p"
3718      "~n   Msg:      ~p", [Expected, Msg]),
3719    case (catch encode_message(megaco_pretty_text_encoder, Conf, Msg)) of
3720        {error, Reason} when Expected =:= error ->
3721            d("pretty_otp5600 -> encode failed as expected"
3722              "~n   Reason: ~w", [Reason]),
3723            ok;
3724        {error, Reason} ->
3725            e("pretty_otp5600 -> encode failed unexpectedly: "
3726              "~n   Reason: ~w", [Reason]),
3727            exit({unexpected_encode_result, Reason});
3728        {ok, Bin} when Expected =:= error ->
3729            e("pretty_otp5600 -> encode succeded unexpectedly: "
3730              "~n   ~w", [binary_to_list(Bin)]),
3731            exit({unexpected_encode_result, binary_to_list(Bin)});
3732        {ok, Bin} ->
3733            d("pretty_otp5600 -> successfull encode as expected:"
3734              "~n~s", [binary_to_list(Bin)]),
3735            case decode_message(megaco_pretty_text_encoder, false, Conf, Bin) of
3736                {ok, Msg} ->
3737                    d("pretty_otp5600 -> successfull decode~n", []),
3738                    ok;
3739                {ok, Msg2} ->
3740                    e("pretty_otp5600 -> successfull decode"
3741                      " - but not equal", []),
3742                    exit({unexpected_decode_result, Msg, Msg2});
3743                Else ->
3744                    e("pretty_otp5600 -> decode failed:~n~p", [Else]),
3745                    exit({unexpected_decode_result, Else})
3746            end
3747    end.
3748
3749pretty_otp5600_msg1() ->
3750    SRE = #'SecondRequestedEvent'{ pkgdName = "al/on",
3751                                   evParList = [] },
3752
3753    SED = #'SecondEventsDescriptor'{ requestID = 2,
3754                                     eventList = [ SRE ] },
3755
3756    SIG = { signal, #'Signal'{ signalName = "cg/dt",
3757                               sigParList = [] } },
3758
3759    RA = #'RequestedActions'{ secondEvent = SED,
3760                              signalsDescriptor = [ SIG ] },
3761
3762    RE = #'RequestedEvent'{ pkgdName = "al/of",
3763                            eventAction = RA,
3764                            evParList = [] },
3765
3766    EV = #'EventsDescriptor'{ requestID = 1, eventList = [ RE ] },
3767
3768    TermID = {megaco_term_id, true, [[$*]] },
3769
3770    AMMR = #'AmmRequest'{ terminationID = [ TermID ],
3771                          descriptors = [ { eventsDescriptor, EV } ] },
3772
3773    CR = #'CommandRequest'{command = {modReq, AMMR}},
3774
3775    AR = #'ActionRequest'{contextId = ?megaco_null_context_id,
3776                          commandRequests = [CR]},
3777    ARs = [AR],
3778    TR = #'TransactionRequest'{transactionId = 5600, actions = ARs},
3779    TRs = [{transactionRequest, TR}],
3780    Mess = #'Message'{version = ?VERSION,
3781                      mId = ?MGC_MID,
3782                      messageBody = {transactions, TRs}},
3783    #'MegacoMessage'{mess = Mess}.
3784
3785pretty_otp5600_msg2() ->
3786    SIG = { signal, #'Signal'{ signalName = "cg/dt",
3787                               sigParList = [] } },
3788
3789    SRA = #'SecondRequestedActions'{ signalsDescriptor = [ SIG ] },
3790
3791    SRE = #'SecondRequestedEvent'{ pkgdName    = "al/on",
3792                                   eventAction = SRA,
3793                                   evParList   = [] },
3794
3795    SED = #'SecondEventsDescriptor'{ requestID = 2,
3796				     eventList = [ SRE ] },
3797
3798    RA = #'RequestedActions'{ secondEvent = SED },
3799
3800    RE = #'RequestedEvent'{ pkgdName = "al/of",
3801			    eventAction = RA,
3802			    evParList = [] },
3803
3804    EV = #'EventsDescriptor'{ requestID = 1, eventList = [ RE ] },
3805
3806    TermID = {megaco_term_id, true, [[$*]] },
3807
3808    AMMR = #'AmmRequest'{ terminationID = [ TermID ],
3809			  descriptors = [ { eventsDescriptor, EV } ] },
3810
3811    CR = #'CommandRequest'{command = {modReq, AMMR}},
3812
3813    AR = #'ActionRequest'{contextId = ?megaco_null_context_id,
3814                          commandRequests = [CR]},
3815    ARs = [AR],
3816    TR = #'TransactionRequest'{transactionId = 5600, actions = ARs},
3817    TRs = [{transactionRequest, TR}],
3818    Mess = #'Message'{version = ?VERSION,
3819                      mId = ?MGC_MID,
3820                      messageBody = {transactions, TRs}},
3821    #'MegacoMessage'{mess = Mess}.
3822
3823
3824pretty_otp5601_msg1(suite) ->
3825    [];
3826pretty_otp5601_msg1(Config) when is_list(Config) ->
3827    d("pretty_otp5601_msg1 -> entry", []),
3828    ?ACQUIRE_NODES(1, Config),
3829    %% put(severity,trc),
3830    %% put(dbg,true),
3831    pretty_otp5601(ok, pretty_otp5601_msg1()).
3832
3833pretty_otp5601(Expected, Msg) ->
3834    pretty_otp5601(Expected, Msg, []).
3835
3836pretty_otp5601(Expected, Msg, Conf) ->
3837    t("pretty_otp5601 -> entry with"
3838      "~n   Expected: ~p"
3839      "~n   Msg:      ~p", [Expected, Msg]),
3840    case (catch encode_message(megaco_pretty_text_encoder, Conf, Msg)) of
3841	{error, Reason} when Expected =:= error ->
3842 	    d("pretty_otp5601 -> encode failed as expected"
3843	      "~n   Reason: ~w", [Reason]),
3844	    ok;
3845	{error, Reason} ->
3846 	    e("pretty_otp5601 -> encode failed unexpectedly: "
3847	      "~n   Reason: ~w", [Reason]),
3848	    exit({unexpected_encode_result, Reason});
3849	{ok, Bin} when Expected =:= error ->
3850 	    e("pretty_otp5601 -> encode succeded unexpectedly: "
3851	      "~n   ~w", [binary_to_list(Bin)]),
3852	    exit({unexpected_encode_result, binary_to_list(Bin)});
3853	{ok, Bin} ->
3854	    d("pretty_otp5601 -> successfull encode as expected:"
3855	      "~n~s", [binary_to_list(Bin)]),
3856	    case decode_message(megaco_pretty_text_encoder, false, Conf, Bin) of
3857		{ok, Msg} ->
3858 		    d("pretty_otp5601 -> successfull decode~n", []),
3859		    ok;
3860		{ok, Msg2} ->
3861 		    e("pretty_otp5601 -> successfull decode"
3862		      " - but not equal", []),
3863		    exit({unexpected_decode_result, Msg, Msg2});
3864		Else ->
3865 		    e("pretty_otp5601 -> decode failed:~n~p", [Else]),
3866		    exit({unexpected_decode_result, Else})
3867	    end
3868    end.
3869
3870pretty_otp5601_msg1() ->
3871    SRE1 = #'SecondRequestedEvent'{ pkgdName = "al/on",
3872				    evParList = [] },
3873
3874    SRA = #'SecondRequestedActions'{ eventDM = { digitMapName, "dialllan0" }},
3875
3876    SRE2 = #'SecondRequestedEvent'{ pkgdName = "dd/ce",
3877				    eventAction = SRA,
3878				    evParList = [] },
3879
3880    SED = #'SecondEventsDescriptor'{ requestID = 2,
3881				     eventList = [ SRE1, SRE2 ] },
3882
3883    RA = #'RequestedActions'{ secondEvent = SED },
3884
3885    RE = #'RequestedEvent'{ pkgdName = "al/of",
3886			    eventAction = RA,
3887			    evParList = [] },
3888
3889    EV = #'EventsDescriptor'{ requestID = 1, eventList = [ RE ] },
3890
3891    TermID = {megaco_term_id, true, [[$*]] },
3892
3893    AMMR = #'AmmRequest'{ terminationID = [ TermID ],
3894			  descriptors = [ { eventsDescriptor, EV } ] },
3895
3896    CR = #'CommandRequest'{command = {modReq, AMMR}},
3897
3898    AR = #'ActionRequest'{contextId = ?megaco_null_context_id,
3899			  commandRequests = [CR]},
3900    ARs = [AR],
3901    TR = #'TransactionRequest'{transactionId = 5600, actions = ARs},
3902    TRs = [{transactionRequest, TR}],
3903    Mess = #'Message'{version = ?VERSION,
3904		      mId = ?MGC_MID,
3905		      messageBody = {transactions, TRs}},
3906    #'MegacoMessage'{mess = Mess}.
3907
3908pretty_otp5793_msg01(suite) ->
3909    [];
3910pretty_otp5793_msg01(Config) when is_list(Config) ->
3911    d("pretty_otp5793_msg01 -> entry", []),
3912    ?ACQUIRE_NODES(1, Config),
3913%     put(severity,trc),
3914%     put(dbg,true),
3915    pretty_otp5793(ok, pretty_otp5793_msg1()).
3916
3917pretty_otp5793(Expected, Msg) ->
3918    expect_codec(Expected, megaco_pretty_text_encoder, Msg, []).
3919
3920pretty_otp5793(Expected, Msg, Conf) ->
3921    expect_codec(Expected, megaco_pretty_text_encoder, Msg, Conf).
3922
3923
3924pretty_otp5793_msg1() ->
3925    {'MegacoMessage',asn1_NOVALUE,
3926     {'Message',2,
3927      {deviceName,"bs_sbg_4/99"},
3928      {transactions,
3929       [{transactionReply,
3930	 {'TransactionReply',
3931	  370,
3932	  asn1_NOVALUE,
3933	  {actionReplies,
3934	   [{'ActionReply',
3935	     3,
3936	     asn1_NOVALUE,
3937	     asn1_NOVALUE,
3938	     [{auditValueReply,
3939	       {contextAuditResult,
3940		[{megaco_term_id,
3941		  false,
3942		  ["ip",
3943		   "104",
3944		   "1",
3945		   "18"]}]}},
3946	      {auditValueReply,
3947	       {contextAuditResult,
3948		[{megaco_term_id,
3949		  false,
3950		  ["ip",
3951		   "104",
3952		   "2",
3953		   "19"]}]}}]}]}}}]}}}.
3954
3955
3956pretty_otp5882_msg01(suite) ->
3957    [];
3958pretty_otp5882_msg01(Config) when is_list(Config) ->
3959    d("pretty_otp5882_msg01 -> entry", []),
3960    ?ACQUIRE_NODES(1, Config),
3961    %% put(severity,trc),
3962    %% put(dbg,true),
3963    pretty_otp5882().
3964
3965pretty_otp5882() ->
3966    otp5882(megaco_pretty_text_encoder, []).
3967
3968otp5882(Codec, Conf) ->
3969    Msg  = pretty_otp5882_msg01(),
3970    case (catch encode_message(Codec, Conf, Msg)) of
3971	{error, {message_encode_failed, {error, {ActualReason, _}}, _}} ->
3972	    case ActualReason of
3973		{invalid_LocalControlDescriptor, empty} ->
3974		    ok;
3975		_ ->
3976		    exit({unexpected_error_actual_reason, ActualReason})
3977	    end;
3978	{error, Reason} ->
3979	    exit({unexpected_error_reason, Reason});
3980	{ok, Bin} ->
3981	    exit({unexpected_encode_sucess, binary_to_list(Bin)})
3982    end.
3983
3984pretty_otp5882_msg01() ->
3985    LCD = #'LocalControlDescriptor'{}, % Create illegal LCD
3986    Parms      = cre_streamParms(LCD),
3987    StreamDesc = cre_streamDesc(1, Parms),
3988    MediaDesc  = cre_mediaDesc(StreamDesc),
3989    AmmReq     = cre_ammReq([#megaco_term_id{id = ?A4445}],
3990			    [{mediaDescriptor, MediaDesc}]),
3991    CmdReq     = cre_commandReq({modReq, AmmReq}),
3992    ActReq     = #'ActionRequest'{contextId       = 5882,
3993				  commandRequests = [CmdReq]},
3994    Actions    = [ActReq],
3995    TransReq   = #'TransactionRequest'{transactionId = 5882,
3996				       actions       = Actions},
3997    Trans      = {transactionRequest, TransReq},
3998    Body       = {transactions, [Trans]},
3999    Mid        = ?MG1_MID,
4000    megaco_message(?VERSION, Mid, Body).
4001
4002
4003%% --------------------------------------------------------------
4004%%
4005pretty_otp6490_msg01(suite) ->
4006    [];
4007pretty_otp6490_msg01(Config) when is_list(Config) ->
4008    %% put(severity, trc),
4009    %% put(dbg,      true),
4010    d("pretty_otp6490_msg01 -> entry", []),
4011    %% ?ACQUIRE_NODES(1, Config),
4012    ok = pretty_otp6490( pretty_otp6490_msg01(), [] ),
4013    %% erase(dbg),
4014    %% erase(severity),
4015    ok.
4016
4017pretty_otp6490_msg02(suite) ->
4018    [];
4019pretty_otp6490_msg02(Config) when is_list(Config) ->
4020    %% put(severity, trc),
4021    %% put(dbg,      true),
4022    d("pretty_otp6490_msg02 -> entry", []),
4023    %% ?ACQUIRE_NODES(1, Config),
4024    ok = pretty_otp6490( pretty_otp6490_msg02(), [] ),
4025    %% erase(severity),
4026    %% erase(dbg),
4027    ok.
4028
4029pretty_otp6490_msg03(suite) ->
4030    [];
4031pretty_otp6490_msg03(Config) when is_list(Config) ->
4032    %% put(severity, trc),
4033    %% put(dbg,      true),
4034    d("pretty_otp6490_msg03 -> entry", []),
4035    %% ?ACQUIRE_NODES(1, Config),
4036    ok = pretty_otp6490( pretty_otp6490_msg03(), [] ),
4037    %% erase(severity),
4038    %% erase(dbg),
4039    ok.
4040
4041pretty_otp6490_msg04(suite) ->
4042    [];
4043pretty_otp6490_msg04(Config) when is_list(Config) ->
4044    %% put(severity, trc),
4045    %% put(dbg,      true),
4046    d("pretty_otp6490_msg04 -> entry", []),
4047    %% ?ACQUIRE_NODES(1, Config),
4048    ok = pretty_otp6490( pretty_otp6490_msg04(), [] ),
4049    %% erase(severity),
4050    %% erase(dbg),
4051    ok.
4052
4053pretty_otp6490_msg05(suite) ->
4054    [];
4055pretty_otp6490_msg05(Config) when is_list(Config) ->
4056    %% put(severity, trc),
4057    %% put(dbg,      true),
4058    d("pretty_otp6490_msg05 -> entry", []),
4059    %% ?ACQUIRE_NODES(1, Config),
4060    ok = pretty_otp6490( pretty_otp6490_msg05(), [] ),
4061    %% erase(severity),
4062    %% erase(dbg),
4063    ok.
4064
4065pretty_otp6490_msg06(suite) ->
4066    [];
4067pretty_otp6490_msg06(Config) when is_list(Config) ->
4068    %% put(severity, trc),
4069    %% put(dbg,      true),
4070    d("pretty_otp6490_msg06 -> entry", []),
4071    %% ?ACQUIRE_NODES(1, Config),
4072    ok = pretty_otp6490( pretty_otp6490_msg06(), [] ),
4073    %% erase(severity),
4074    %% erase(dbg),
4075    ok.
4076
4077pretty_otp6490(Msg, Conf) ->
4078    pretty_otp6490(Msg, Conf, ok).
4079
4080pretty_otp6490(Msg, Conf, ExpectedEncode) ->
4081    pretty_otp6490(Msg, Conf, ExpectedEncode, ok).
4082
4083pretty_otp6490(Msg, Conf, ExpectedEncode, ExpectedDecode) ->
4084    otp6490(Msg, megaco_pretty_text_encoder, Conf,
4085            ExpectedEncode, ExpectedDecode).
4086
4087otp6490(Msg, Codec, Conf, ExpectedEncode, ExpectedDecode) ->
4088    case (catch encode_message(Codec, Conf, Msg)) of
4089        {error, _Reason} when ExpectedEncode =:= error ->
4090            ok;
4091        {error, Reason} when ExpectedEncode =:= ok ->
4092            exit({unexpected_encode_failure, Reason});
4093        {ok, Bin} when ExpectedEncode =:= error ->
4094            exit({unexpected_encode_success, Msg, binary_to_list(Bin)});
4095        {ok, Bin} when ExpectedEncode =:= ok ->
4096            case decode_message(Codec, false, Conf, Bin) of
4097                {ok, Msg} when ExpectedDecode == ok ->
4098                    ok;
4099                {ok, Msg} when ExpectedDecode =:= error ->
4100                    exit({unexpected_decode_success, Msg});
4101                {ok, Msg2} when ExpectedDecode =:= ok ->
4102                    exit({unexpected_decode_result, Msg, Msg2});
4103                {ok, Msg2} when ExpectedDecode =:= error ->
4104                    exit({unexpected_decode_success, Msg, Msg2});
4105                {error, _Reason} when ExpectedDecode =:= error ->
4106                    ok;
4107                {error, Reason} when ExpectedDecode =:= ok ->
4108                    exit({unexpected_decode_failure, Msg, Reason})
4109            end
4110    end.
4111
4112
4113pretty_otp6490_msg(EBD) ->
4114    AmmDesc    = ?MSG_LIB:cre_AmmDescriptor(EBD),
4115    AmmReq     = cre_ammReq([#megaco_term_id{id = ?A4445}], [AmmDesc]),
4116    CmdReq     = cre_commandReq({modReq, AmmReq}),
4117    CID        = cre_CtxID(64901),
4118    ActReq     = cre_ActReq(CID, [CmdReq]),
4119    Actions    = [ActReq],
4120    TransId    = cre_TransId(64902),
4121    TransReq   = cre_TransReq(TransId, Actions),
4122    Trans      = cre_Trans(TransReq),
4123    Mid        = ?MG1_MID,
4124    Mess       = cre_Msg(Mid, [Trans]),
4125    cre_MegacoMessage(Mess).
4126
4127pretty_otp6490_msg01() ->
4128    EvSpecs = [], % This will result in an error
4129    EBD     = EvSpecs, % This is because the lib checks that the size is valid
4130    pretty_otp6490_msg(EBD).
4131
4132pretty_otp6490_msg02() ->
4133    EvPar    = ?MSG_LIB:cre_EventParameter("sune", ["mangs"]),
4134    PkgdName = ?MSG_LIB:cre_PkgdName("foo", "a"),
4135    EvName   = ?MSG_LIB:cre_EventName(PkgdName),
4136    EvSpec   = ?MSG_LIB:cre_EventSpec(EvName, [EvPar]),
4137    EvSpecs  = [EvSpec],
4138    EBD      = ?MSG_LIB:cre_EventBufferDescriptor(EvSpecs),
4139    pretty_otp6490_msg(EBD).
4140
4141pretty_otp6490_msg03() ->
4142    EvPar1   = ?MSG_LIB:cre_EventParameter("sune",   ["mangs"]),
4143    EvPar2   = ?MSG_LIB:cre_EventParameter("kalle",  ["anka"]),
4144    EvPar3   = ?MSG_LIB:cre_EventParameter("flippa", ["ur"]),
4145    PkgdName = ?MSG_LIB:cre_PkgdName("foo", "a"),
4146    EvName   = ?MSG_LIB:cre_EventName(PkgdName),
4147    EvSpec   = ?MSG_LIB:cre_EventSpec(EvName, [EvPar1,EvPar2,EvPar3]),
4148    EvSpecs  = [EvSpec],
4149    EBD      = ?MSG_LIB:cre_EventBufferDescriptor(EvSpecs),
4150    pretty_otp6490_msg(EBD).
4151
4152pretty_otp6490_msg04() ->
4153    EvPar1    = ?MSG_LIB:cre_EventParameter("sune",   ["mangs"]),
4154    EvPar2    = ?MSG_LIB:cre_EventParameter("kalle",  ["anka"]),
4155    EvPar3    = ?MSG_LIB:cre_EventParameter("flippa", ["ur"]),
4156    PkgdName1 = ?MSG_LIB:cre_PkgdName("foo", "a"),
4157    EvName1   = ?MSG_LIB:cre_EventName(PkgdName1),
4158    EvSpec1   = ?MSG_LIB:cre_EventSpec(EvName1, [EvPar1,EvPar2,EvPar3]),
4159    EvPar4    = ?MSG_LIB:cre_EventParameter("hej",    ["hopp"]),
4160    PkgdName2 = ?MSG_LIB:cre_PkgdName("bar", "b"),
4161    EvName2   = ?MSG_LIB:cre_EventName(PkgdName2),
4162    EvSpec2   = ?MSG_LIB:cre_EventSpec(EvName2, [EvPar4]),
4163    EvSpecs   = [EvSpec1,EvSpec2],
4164    EBD       = ?MSG_LIB:cre_EventBufferDescriptor(EvSpecs),
4165    pretty_otp6490_msg(EBD).
4166
4167pretty_otp6490_msg05() ->
4168    EvPar    = ?MSG_LIB:cre_EventParameter("sune", ["mangs"]),
4169    PkgdName = ?MSG_LIB:cre_PkgdName("foo", root),
4170    EvName   = ?MSG_LIB:cre_EventName(PkgdName),
4171    EvSpec   = ?MSG_LIB:cre_EventSpec(EvName, [EvPar]),
4172    EvSpecs  = [EvSpec],
4173    EBD      = ?MSG_LIB:cre_EventBufferDescriptor(EvSpecs),
4174    pretty_otp6490_msg(EBD).
4175
4176pretty_otp6490_msg06() ->
4177    EvPar    = ?MSG_LIB:cre_EventParameter("sune", ["mangs"]),
4178    PkgdName = ?MSG_LIB:cre_PkgdName(root, root),
4179    EvName   = ?MSG_LIB:cre_EventName(PkgdName),
4180    EvSpec   = ?MSG_LIB:cre_EventSpec(EvName, [EvPar]),
4181    EvSpecs  = [EvSpec],
4182    EBD      = ?MSG_LIB:cre_EventBufferDescriptor(EvSpecs),
4183    pretty_otp6490_msg(EBD).
4184
4185
4186%% --------------------------------------------------------------
4187%%
4188
4189pretty_otp7671_msg01(suite) ->
4190    [];
4191pretty_otp7671_msg01(Config) when is_list(Config) ->
4192%%     put(severity, trc),
4193%%     put(dbg,      true),
4194    d("pretty_otp7671_msg01 -> entry", []),
4195    %% ?ACQUIRE_NODES(1, Config),
4196    ok = pretty_otp7671( pretty_otp7671_msg01(), [] ),
4197%%     erase(dbg),
4198%%     erase(severity),
4199    ok.
4200
4201pretty_otp7671_msg02(suite) ->
4202    [];
4203pretty_otp7671_msg02(Config) when is_list(Config) ->
4204%%     put(severity, trc),
4205%%     put(dbg,      true),
4206    d("pretty_otp7671_msg02 -> entry", []),
4207    %% ?ACQUIRE_NODES(1, Config),
4208    ok = pretty_otp7671( pretty_otp7671_msg02(), [] ),
4209%%     erase(dbg),
4210%%     erase(severity),
4211    ok.
4212
4213pretty_otp7671_msg03(suite) ->
4214    [];
4215pretty_otp7671_msg03(Config) when is_list(Config) ->
4216%%     put(severity, trc),
4217%%     put(dbg,      true),
4218    d("pretty_otp7671_msg03 -> entry", []),
4219    %% ?ACQUIRE_NODES(1, Config),
4220    ok = pretty_otp7671( pretty_otp7671_msg03(), [] ),
4221%%     erase(dbg),
4222%%     erase(severity),
4223    ok.
4224
4225pretty_otp7671_msg04(suite) ->
4226    [];
4227pretty_otp7671_msg04(Config) when is_list(Config) ->
4228%%     put(severity, trc),
4229%%     put(dbg,      true),
4230    d("pretty_otp7671_msg04 -> entry", []),
4231    %% ?ACQUIRE_NODES(1, Config),
4232    ok = pretty_otp7671( pretty_otp7671_msg04(), [] , error, ignore),
4233%%     erase(dbg),
4234%%     erase(severity),
4235    ok.
4236
4237pretty_otp7671_msg05(suite) ->
4238    [];
4239pretty_otp7671_msg05(Config) when is_list(Config) ->
4240%%     put(severity, trc),
4241%%     put(dbg,      true),
4242    d("pretty_otp7671_msg05 -> entry", []),
4243    Check = fun(M1, M2) -> cmp_otp7671_msg05(M1, M2) end,
4244    ok = pretty_otp7671( pretty_otp7671_msg05(), [] , ok, ok, Check),
4245%%     erase(dbg),
4246%%     erase(severity),
4247    ok.
4248
4249
4250pretty_otp7671(Msg, Conf) ->
4251    pretty_otp7671(Msg, Conf, ok).
4252
4253pretty_otp7671(Msg, Conf, ExpectedEncode) ->
4254    pretty_otp7671(Msg, Conf, ExpectedEncode, ok).
4255
4256pretty_otp7671(Msg, Conf, ExpectedEncode, ExpectedDecode) ->
4257    otp7671(Msg, megaco_pretty_text_encoder, Conf,
4258            ExpectedEncode, ExpectedDecode).
4259
4260pretty_otp7671(Msg, Conf, ExpectedEncode, ExpectedDecode, Check) ->
4261    otp7671(Msg, megaco_pretty_text_encoder, Conf,
4262            ExpectedEncode, ExpectedDecode, Check).
4263
4264otp7671(Msg, Codec, Conf, ExpectedEncode, ExpectedDecode) ->
4265    Check = fun(M1, M2) ->
4266		    exit({unexpected_decode_result, M1, M2})
4267	    end,
4268    otp7671(Msg, Codec, Conf, ExpectedEncode, ExpectedDecode, Check).
4269
4270otp7671(Msg, Codec, Conf, ExpectedEncode, ExpectedDecode, Check) ->
4271    case (catch encode_message(Codec, Conf, Msg)) of
4272        {error, _Reason} when ExpectedEncode =:= error ->
4273            ok;
4274        {error, Reason} when ExpectedEncode =:= ok ->
4275            exit({unexpected_encode_failure, Reason});
4276        {ok, Bin} when ExpectedEncode =:= error ->
4277            exit({unexpected_encode_success, Msg, binary_to_list(Bin)});
4278        {ok, Bin} when ExpectedEncode =:= ok ->
4279            case decode_message(Codec, false, Conf, Bin) of
4280                {ok, Msg} when ExpectedDecode =:= ok ->
4281		    io:format("otp7671 -> decoded:identical~n", []),
4282                    ok;
4283                {ok, Msg2} when ExpectedDecode =:= ok ->
4284		    Check(Msg, Msg2);
4285                {ok, Msg} when ExpectedDecode =:= error ->
4286                    exit({unexpected_decode_success, Msg});
4287                {ok, Msg2} when ExpectedDecode =:= error ->
4288                    exit({unexpected_decode_success, Msg, Msg2});
4289                {error, _Reason} when ExpectedDecode =:= error ->
4290                    ok;
4291                {error, Reason} when ExpectedDecode == ok ->
4292                    exit({unexpected_decode_failure, Msg, Reason})
4293            end
4294    end.
4295
4296
4297pretty_otp7671_msg(DigitMapDesc) ->
4298    AmmReq = cre_ammReq([#megaco_term_id{id = ?A4444}],
4299			[{digitMapDescriptor, DigitMapDesc}]),
4300    CmdReq = cre_commandReq({modReq, AmmReq}),
4301    msg_request(?MGC_MID, 10001, ?megaco_null_context_id, [CmdReq]).
4302
4303pretty_otp7671_msg01() ->
4304    Name         = "dialplan01",
4305    DigitMapDesc = cre_digitMapDesc(Name),
4306    pretty_otp7671_msg(DigitMapDesc).
4307
4308pretty_otp7671_msg02() ->
4309    Name         = "dialplan02",
4310    Body         = "(0s| 00s|[1-7]xlxx|8lxxxxxxx|#xxxxxxx|*xx|9l1xxxxxxxxxx|9l011x.s)",
4311    Value        = cre_digitMapValue(Body),
4312    DigitMapDesc = cre_digitMapDesc(Name, Value),
4313    pretty_otp7671_msg(DigitMapDesc).
4314
4315pretty_otp7671_msg03() ->
4316    Body         = "(0s| 00s|[1-7]xlxx|8lxxxxxxx|#xxxxxxx|*xx|9l1xxxxxxxxxx|9l011x.s)",
4317    Value        = cre_digitMapValue(Body),
4318    DigitMapDesc = cre_digitMapDesc(Value),
4319    pretty_otp7671_msg(DigitMapDesc).
4320
4321pretty_otp7671_msg04() ->
4322    DigitMapDesc = cre_digitMapDesc(asn1_NOVALUE, asn1_NOVALUE),
4323    pretty_otp7671_msg(DigitMapDesc).
4324
4325pretty_otp7671_msg05() ->
4326    {'MegacoMessage',asn1_NOVALUE,
4327     {'Message',?VERSION,
4328      {domainName,{'DomainName',"tgc",asn1_NOVALUE}},
4329      {transactions,
4330       [{transactionRequest,
4331	 {'TransactionRequest',12582952,
4332	  [{'ActionRequest',0,asn1_NOVALUE,asn1_NOVALUE,
4333	    [{'CommandRequest',
4334	      {modReq,
4335	       {'AmmRequest',
4336		[{megaco_term_id,false,["root"]}],
4337		[{digitMapDescriptor,
4338		  {'DigitMapDescriptor',"dialplan1",
4339		   {'DigitMapValue',asn1_NOVALUE,asn1_NOVALUE,asn1_NOVALUE,[]}}}]}},
4340	      asn1_NOVALUE,asn1_NOVALUE}]}]}}]}}}.
4341
4342cmp_otp7671_msg05(#'MegacoMessage'{authHeader = asn1_NOVALUE,
4343				   mess       = M1},
4344		  #'MegacoMessage'{authHeader = asn1_NOVALUE,
4345				   mess       = M2}) ->
4346    #'Message'{messageBody = Body1} = M1,
4347    #'Message'{messageBody = Body2} = M2,
4348    {transactions, Trans1} = Body1,
4349    {transactions, Trans2} = Body2,
4350    [{transactionRequest, TR1}] = Trans1,
4351    [{transactionRequest, TR2}] = Trans2,
4352    #'TransactionRequest'{actions = Acts1} = TR1,
4353    #'TransactionRequest'{actions = Acts2} = TR2,
4354    [#'ActionRequest'{commandRequests = CR1}] = Acts1,
4355    [#'ActionRequest'{commandRequests = CR2}] = Acts2,
4356    [#'CommandRequest'{command = Cmd1}] = CR1,
4357    [#'CommandRequest'{command = Cmd2}] = CR2,
4358    {modReq, #'AmmRequest'{descriptors = Descs1}} = Cmd1,
4359    {modReq, #'AmmRequest'{descriptors = Descs2}} = Cmd2,
4360    [{digitMapDescriptor,
4361      #'DigitMapDescriptor'{digitMapName = Name,
4362			    digitMapValue = Value1}}] = Descs1,
4363    [{digitMapDescriptor,
4364      #'DigitMapDescriptor'{digitMapName = Name,
4365			    digitMapValue = Value2}}] = Descs2,
4366    #'DigitMapValue'{startTimer    = asn1_NOVALUE,
4367		     shortTimer    = asn1_NOVALUE,
4368		     longTimer     = asn1_NOVALUE,
4369		     digitMapBody  = []} = Value1,
4370    asn1_NOVALUE = Value2,
4371    ok.
4372
4373
4374%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4375
4376expect_codec(Expect, Codec, Msg, Conf) ->
4377    t("expect_codec -> entry with"
4378      "~n   Expect: ~p"
4379      "~n   Msg:    ~p", [Expect, Msg]),
4380    case (catch encode_message(Codec, Conf, Msg)) of
4381	{error, _Reason} when Expect =:= error ->
4382 	    d("expect_codec -> encode failed as expected"
4383	      "~n   _Reason: ~w", [_Reason]),
4384	    ok;
4385	{error, Reason} ->
4386 	    e("expect_codec -> encode failed unexpectedly: "
4387	      "~n   Reason: ~w", [Reason]),
4388	    exit({unexpected_encode_result, Reason});
4389	{ok, Bin} when Expect =:= error ->
4390 	    e("expect_codec -> encode succeded unexpectedly: "
4391	      "~n   ~w", [binary_to_list(Bin)]),
4392	    exit({unexpected_encode_result, binary_to_list(Bin)});
4393	{ok, Bin} ->
4394	    d("expect_codec -> successfull encode as expected:"
4395	      "~n~s", [binary_to_list(Bin)]),
4396	    case (catch decode_message(Codec, false, Conf, Bin)) of
4397		{ok, Msg} ->
4398 		    d("expect_codec -> successfull decode~n", []),
4399		    ok;
4400		{ok, Msg2} ->
4401 		    e("expect_codec -> successfull decode"
4402		      " - but not equal", []),
4403		    chk_MegacoMessage(Msg, Msg2);
4404		%% exit({unexpected_decode_result, Msg, Msg2});
4405		Else ->
4406 		    e("expect_codec -> decode failed:~n~p", [Else]),
4407		    exit({unexpected_decode_result, Else})
4408	    end;
4409	Else ->
4410	    e("expect_codec -> encode failed:~n~p", [Else]),
4411	    exit({unexpected_encode_result, Else})
4412    end.
4413
4414
4415%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4416
4417msgs() ->
4418    Msgs = msgs1() ++ msgs2() ++ msgs3(),
4419    [M || {_, M, _, _} <- Msgs].
4420
4421msgs1() ->
4422    Plain =
4423	fun(Codec, DD, Ver, EC, M) ->
4424		megaco_codec_test_lib:plain_encode_decode(Codec, DD, Ver,
4425							  EC, M)
4426	end,
4427    [
4428     {msg01a, msg1a(),  Plain, [{dbg,false}]},
4429     {msg01b, msg1b(),  Plain, [{dbg,false}]},
4430     {msg02,  msg2(),   Plain, [{dbg,false}]},
4431     {msg03,  msg3(),   Plain, [{dbg,false}]},
4432     {msg04,  msg4(),   Plain, [{dbg,false}]},
4433     {msg05,  msg5(),   Plain, [{dbg,false}]},
4434     {msg06a, msg6a(),  Plain, [{dbg,false}]},
4435     {msg06b, msg6b(),  Plain, [{dbg,false}]},
4436     {msg07,  msg7(),   Plain, [{dbg,false}]},
4437     {msg08a, msg8a(),  Plain, [{dbg,false}]},
4438     {msg08b, msg8b(),  Plain, [{dbg,false}]},
4439     {msg09,  msg9(),   Plain, [{dbg,false}]},
4440     {msg10,  msg10(),  Plain, [{dbg,false}]},
4441     {msg11,  msg11(),  Plain, [{dbg,false}]},
4442     {msg12,  msg12(),  Plain, [{dbg,false}]},
4443     {msg13,  msg13(),  Plain, [{dbg,false}]},
4444     {msg14,  msg14(),  Plain, [{dbg,false}]},
4445     {msg15,  msg15(),  Plain, [{dbg,false}]},
4446     {msg16,  msg16(),  Plain, [{dbg,false}]},
4447     {msg17,  msg17(),  Plain, [{dbg,false}]},
4448     {msg18,  msg18(),  Plain, [{dbg,false}]},
4449     {msg19,  msg19(),  Plain, [{dbg,false}]},
4450     {msg20,  msg20(),  Plain, [{dbg,false}]},
4451     {msg21,  msg21(),  Plain, [{dbg,false}]},
4452     {msg22a, msg22a(), Plain, [{dbg,false}]},
4453     {msg22b, msg22b(), Plain, [{dbg,false}]},
4454     {msg22c, msg22c(), Plain, [{dbg,false}]},
4455     {msg22d, msg22d(), Plain, [{dbg,false}]},
4456     {msg22e, msg22e(), Plain, [{dbg,false}]},
4457     {msg22f, msg22f(), Plain, [{dbg,false}]},
4458     {msg23a, msg23a(), Plain, [{dbg,false}]},
4459     {msg23b, msg23b(), Plain, [{dbg,false}]},
4460     {msg23c, msg23c(), Plain, [{dbg,false}]},
4461     {msg23d, msg23d(), Plain, [{dbg,false}]},
4462     {msg24,  msg24(),  Plain, [{dbg,false}]},
4463     {msg25,  msg25(),  Plain, [{dbg,false}]},
4464     {msg30a, msg30a(), Plain, [{dbg,false}]},
4465     {msg30b, msg30b(), Plain, [{dbg,false}]},
4466     {msg30c, msg30c(), Plain, [{dbg,false}]},
4467     {msg30d, msg30d(), Plain, [{dbg,false}]}
4468    ].
4469
4470msgs2() ->
4471    TransFirst =
4472	fun(Codec, DD, Ver, EC, M) ->
4473		megaco_codec_test_lib:trans_first_encode_decode(Codec, DD,
4474								Ver, EC, M)
4475	end,
4476    ActionsFirst =
4477	fun(Codec, DD, Ver, EC, M) ->
4478		megaco_codec_test_lib:actions_first_encode_decode(Codec, DD,
4479								  Ver, EC, M)
4480	end,
4481    ActionFirst =
4482	fun(Codec, DD, Ver, EC, M) ->
4483		megaco_codec_test_lib:action_first_encode_decode(Codec, DD,
4484								 Ver, EC, M)
4485	end,
4486    [
4487     {msg01a_tf,  msg1a(),  TransFirst,   [{dbg,false}]},
4488     {msg02_tf,   msg2(),   TransFirst,   [{dbg,false}]},
4489     {msg10_tf,   msg10(),  TransFirst,   [{dbg,false}]},
4490     {msg11_tf,   msg11(),  TransFirst,   [{dbg,false}]},
4491     {msg23d_tf,  msg23d(), TransFirst,   [{dbg,false}]},
4492     {msg30b_tf,  msg30b(), TransFirst,   [{dbg,false}]},
4493     {msg30c_tf,  msg30c(), TransFirst,   [{dbg,false}]},
4494     {msg01a_asf, msg1a(),  ActionsFirst, [{dbg,false}]},
4495     {msg02_asf,  msg2(),   ActionsFirst, [{dbg,false}]},
4496     {msg10_asf,  msg10(),  ActionsFirst, [{dbg,false}]},
4497     {msg23d_asf, msg23d(), ActionsFirst, [{dbg,false}]},
4498     {msg01a_af,  msg1a(),  ActionFirst,  [{dbg,false}]},
4499     {msg02_af,   msg2(),   ActionFirst,  [{dbg,false}]},
4500     {msg10_af,   msg10(),  ActionFirst,  [{dbg,false}]},
4501     {msg23d_af,  msg23d(), ActionFirst,  [{dbg,false}]}
4502    ].
4503
4504
4505msgs3() ->
4506    Plain =
4507	fun(Codec, DD, Ver, EC, M) ->
4508		megaco_codec_test_lib:plain_encode_decode(Codec, DD, Ver,
4509							  EC, M)
4510	end,
4511    [{msgs3_name(Name), rfc3525_decode(M), Plain, [{dbg, false}]} ||
4512	{Name, M} <- rfc3525_msgs()].
4513
4514msgs3_name(N) ->
4515    list_to_atom("rfc3525_" ++ atom_to_list(N)).
4516
4517rfc3525_decode(M) when is_list(M) ->
4518    rfc3525_decode(list_to_binary(M));
4519rfc3525_decode(M) when is_binary(M) ->
4520    case (catch decode_message(megaco_pretty_text_encoder, false, [], M)) of
4521	{ok, Msg} ->
4522	    Msg;
4523	Error ->
4524	    {error, {rfc3525_decode_error, Error}}
4525    end.
4526
4527
4528%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4529
4530msg_actions([], Actions) ->
4531    lists:reverse(Actions);
4532msg_actions([{CtxId, CmdReqs}|ActionInfo], Actions) ->
4533    Action = #'ActionRequest'{contextId       = CtxId,
4534			      commandRequests = CmdReqs},
4535    msg_actions(ActionInfo, [Action|Actions]).
4536
4537megaco_trans_req([], Transactions) ->
4538    {transactions, lists:reverse(Transactions)};
4539megaco_trans_req([{TransId, ActionInfo}|TransInfo], Transactions) ->
4540    Actions  = msg_actions(ActionInfo, []),
4541    TransReq = {transactionRequest,
4542		#'TransactionRequest'{transactionId = TransId,
4543				      actions       = Actions}},
4544    megaco_trans_req(TransInfo, [TransReq|Transactions]).
4545
4546megaco_message(Version, Mid, Body) ->
4547    #'MegacoMessage'{mess = #'Message'{version     = Version,
4548                                       mId         = Mid,
4549                                       messageBody = Body}}.
4550
4551megaco_message(Auth, Version, Mid, Body) ->
4552    #'MegacoMessage'{authHeader = Auth,
4553		     mess = #'Message'{version     = Version,
4554                                       mId         = Mid,
4555                                       messageBody = Body}}.
4556
4557msg_request(Mid, TransInfo) ->
4558    TransReq = megaco_trans_req(TransInfo, []),
4559    megaco_message(1, Mid, TransReq).
4560
4561msg_request(Mid, TransId, ContextId, CmdReq) when is_list(CmdReq) ->
4562    Actions = [#'ActionRequest'{contextId = ContextId,
4563                                commandRequests = CmdReq}],
4564    Req = {transactions,
4565           [{transactionRequest,
4566             #'TransactionRequest'{transactionId = TransId,
4567                                   actions = Actions}}]},
4568    megaco_message(?VERSION, Mid, Req).
4569
4570msg_request(Auth, Mid, TransId, ContextId, CmdReq) when is_list(CmdReq) ->
4571    Actions = [#'ActionRequest'{contextId = ContextId,
4572                                commandRequests = CmdReq}],
4573    Req = {transactions,
4574           [{transactionRequest,
4575             #'TransactionRequest'{transactionId = TransId,
4576                                   actions = Actions}}]},
4577    megaco_message(Auth, ?VERSION, Mid, Req).
4578
4579msg_reply(Mid, TransId, ContextId, CmdReply) when is_list(CmdReply) ->
4580    ReplyData = [{ContextId, CmdReply}],
4581    msg_replies(Mid, TransId, ReplyData).
4582
4583msg_replies(Mid, TransId, ReplyData) when is_list(ReplyData) ->
4584    Actions = [cre_actionReply(ContextId, CmdReply) ||
4585		  {ContextId, CmdReply} <- ReplyData],
4586    Req = {transactions,
4587           [{transactionReply, cre_transactionReply(TransId, Actions)}]},
4588    cre_megacoMessage(?VERSION, Mid, Req).
4589
4590
4591msg_ack(Mid, [Range|_] = Ranges) when is_tuple(Range) ->
4592    msg_ack(Mid, [Ranges]);
4593
4594msg_ack(Mid, Ranges) ->
4595    %% TRAs = make_tras(Ranges, []),
4596    TRAs = make_tras(Ranges),
4597    Req  = {transactions, TRAs},
4598    cre_megacoMessage(?VERSION, Mid, Req).
4599
4600make_tras(TRARanges) ->
4601    F = fun(R) -> {transactionResponseAck, make_tra(R)} end,
4602    lists:map(F, TRARanges).
4603
4604make_tra(Ranges) ->
4605    F = fun({F,L}) -> cre_transactionAck(F,L) end,
4606    lists:map(F, Ranges).
4607
4608
4609%% -------------------------------------------------------------------------
4610
4611
4612msg1(Mid, Tid) ->
4613    Gain  = cre_propertyParm("tdmc/gain", "2"),
4614    Ec    = cre_propertyParm("tdmc/ec", "g165"),
4615    LCD   = cre_localControlDesc(sendRecv,[Gain, Ec]),
4616    V     = cre_propertyParm("v", "0"),
4617    %% C    = cre_propertyParm("c", "IN IP4 $ "),
4618    C     = cre_propertyParm("c", [$I,$N,$ ,$I,$P,$4,$ ,$$,$ ]),
4619    M     = cre_propertyParm("m", "audio $ RTP/AVP 0"),
4620    A     = cre_propertyParm("a", "fmtp:PCMU VAD=X-NNVAD"),
4621    LD    = cre_localRemoteDesc([[V, C, M, A]]),
4622    Parms = cre_streamParms(LCD,LD),
4623    StreamDesc = cre_streamDesc(1,Parms),
4624    MediaDesc  = cre_mediaDesc(StreamDesc),
4625    ReqEvent   = cre_requestedEvent("al/of"),
4626    EventsDesc = cre_eventsDesc(2222,[ReqEvent]),
4627    AmmReq     = cre_ammReq([#megaco_term_id{id = Tid}],
4628			    [{mediaDescriptor, MediaDesc},
4629			     {eventsDescriptor, EventsDesc}]),
4630    CmdReq     = cre_commandReq({modReq, AmmReq}),
4631    msg_request(Mid, 9999, ?megaco_null_context_id, [CmdReq]).
4632
4633
4634msg1a() ->
4635    msg1a(?MGC_MID).
4636msg1a(Mid) ->
4637    msg1(Mid, ?A4444).
4638
4639msg1b() ->
4640    msg1b(?MGC_MID).
4641msg1b(Mid) ->
4642    msg1(Mid, ?A4445).
4643
4644
4645%% --------------------------
4646
4647
4648msg2() ->
4649    msg2(?MGC_MID).
4650msg2(Mid) ->
4651    msg2(Mid, ?A4444).
4652msg2(Mid, Tid) ->
4653    Gain  = cre_propertyParm("tdmc/gain", "2"),
4654    Ec    = cre_propertyParm("tdmc/ec", "g165"),
4655    LCD   = cre_localControlDesc(sendRecv,[Gain, Ec]),
4656    V     = cre_propertyParm("v", "0"),
4657    %% C    = cre_propertyParm("c", "IN IP4 $ "),
4658    C     = cre_propertyParm("c", [$I,$N,$ ,$I,$P,$4,$ ,$$,$ ]),
4659    M     = cre_propertyParm("m", "audio $ RTP/AVP 0"),
4660    A     = cre_propertyParm("a", "fmtp:PCMU VAD=X-NNVAD"),
4661    LD    = cre_localRemoteDesc([[V, C, M, A]]),
4662    Parms = cre_streamParms(LCD,LD),
4663    StreamDesc = cre_streamDesc(1,Parms),
4664    MediaDesc  = cre_mediaDesc(StreamDesc),
4665    EventParm  = cre_eventParm("strict",["exact"]),
4666    ReqEvent   = cre_requestedEvent("al/of", [EventParm]),
4667    EventsDesc = cre_eventsDesc(2222,[ReqEvent]),
4668    AmmReq     = cre_ammReq([#megaco_term_id{id = Tid}],
4669			    [{mediaDescriptor, MediaDesc},
4670			     {eventsDescriptor, EventsDesc}]),
4671    CmdReq     = cre_commandReq({modReq, AmmReq}),
4672    msg_request(Mid, 9999, ?megaco_null_context_id, [CmdReq]).
4673
4674
4675%% --------------------------
4676
4677msg3() ->
4678    msg3(?MG1_MID).
4679msg3(Mid) ->
4680    TimeStamp = cre_timeNotation("19990729", "22000000"),
4681    Event     = cre_observedEvent("al/of",TimeStamp),
4682    Desc      = cre_observedEventsDesc(2222,[Event]),
4683    NotifyReq = cre_notifyReq([#megaco_term_id{id = ?A4444}],Desc),
4684    CmdReq    = cre_commandReq({notifyReq, NotifyReq}),
4685    msg_request(Mid, 10000, ?megaco_null_context_id, [CmdReq]).
4686
4687
4688%% --------------------------
4689
4690msg4() ->
4691    msg4(?MG1_MID_NO_PORT, "901 mg col boot").
4692msg4(Mid, Reason) when is_list(Reason) ->
4693    Address = {portNumber, ?DEFAULT_PORT},
4694    Profile = cre_serviceChangeProf("resgw",1),
4695    Parm    = cre_serviceChangeParm(restart,Address,[Reason],Profile),
4696    Req     = cre_serviceChangeReq([?megaco_root_termination_id],Parm),
4697    CmdReq  = cre_commandReq({serviceChangeReq, Req}),
4698    msg_request(Mid, 9998, ?megaco_null_context_id, [CmdReq]).
4699
4700
4701%% --------------------------
4702
4703msg5() ->
4704    msg5(?MGC_MID).
4705msg5(Mid) ->
4706    Address = {portNumber, ?DEFAULT_PORT},
4707    Profile = cre_serviceChangeProf("resgw",1),
4708    Parm    = cre_serviceChangeResParm(Address,Profile),
4709    Reply   = cre_serviceChangeReply([?megaco_root_termination_id],
4710				     {serviceChangeResParms,Parm}),
4711    msg_reply(Mid, 9998, ?megaco_null_context_id,
4712	      [{serviceChangeReply, Reply}]).
4713
4714
4715%% --------------------------
4716
4717msg6(Mid, Tid) ->
4718    Reply = cre_ammsReply([#megaco_term_id{id = Tid}]),
4719    msg_reply(Mid, 9999, ?megaco_null_context_id, [{modReply, Reply}]).
4720
4721msg6a() ->
4722    msg6a(?MG1_MID).
4723msg6a(Mid) ->
4724    msg6(Mid, ?A4444).
4725
4726msg6b() ->
4727    msg6b(?MG2_MID).
4728msg6b(Mid) ->
4729    msg6(Mid, ?A5555).
4730
4731
4732%% --------------------------
4733
4734msg7() ->
4735    msg7(?MGC_MID).
4736msg7(Mid) ->
4737    Reply = cre_notifyReply([#megaco_term_id{id = ?A4444}]),
4738    msg_reply(Mid, 10000, ?megaco_null_context_id, [{notifyReply, Reply}]).
4739
4740
4741%% --------------------------
4742
4743msg8(Mid, DigitMapValue) ->
4744    Strict = cre_eventParm("strict",["state"]),
4745    On     = cre_requestedEvent("al/on", [Strict]),
4746    Name   = "dialplan00",
4747    Action = cre_requestedActions(Name),
4748    Ce     = cre_requestedEvent("dd/ce", Action),
4749    EventsDesc = cre_eventsDesc(2223,[On, Ce]),
4750    Signal     = cre_signal("cg/rt"),
4751    DigMapDesc = cre_digitMapDesc(Name, DigitMapValue),
4752    AmmReq     = cre_ammReq([#megaco_term_id{id = ?A4444}],
4753                           [{eventsDescriptor, EventsDesc},
4754			    {signalsDescriptor, [{signal, Signal}]},
4755			    {digitMapDescriptor, DigMapDesc}]),
4756    CmdReq     = cre_commandReq({modReq, AmmReq}),
4757    msg_request(Mid, 10001, ?megaco_null_context_id, [CmdReq]).
4758
4759msg8a() ->
4760    msg8a(?MGC_MID).
4761msg8a(Mid) ->
4762    Body = "(0s| 00s|[1-7]xlxx|8lxxxxxxx|#xxxxxxx|*xx|9l1xxxxxxxxxx|9l011x.s)",
4763    Value = cre_digitMapValue(Body),
4764    msg8(Mid, Value).
4765
4766msg8b() ->
4767    msg8b(?MGC_MID).
4768msg8b(Mid) ->
4769    Body = "(0s| 00s|[1-7]xlxx|8lxxxxxxx|#xxxxxxx|*xx|9l1xxxxxxxxxx|9l011x.s)",
4770    Value = cre_digitMapValue(Body, 1, 23, 99),
4771    msg8(Mid, Value).
4772
4773
4774%% --------------------------
4775
4776msg9() ->
4777    msg9(?MG1_MID).
4778msg9(Mid) ->
4779    TimeStamp = cre_timeNotation("19990729","22010001"),
4780    Parm      = cre_eventParm("ds",["916135551212"]),
4781    Event     = cre_observedEvent("dd/ce",TimeStamp,[Parm]),
4782    Desc      = cre_observedEventsDesc(2223,[Event]),
4783    NotifyReq = cre_notifyReq([#megaco_term_id{id = ?A4444}], Desc),
4784    CmdReq    = cre_commandReq({notifyReq, NotifyReq}),
4785    msg_request(Mid, 10002, ?megaco_null_context_id, [CmdReq]).
4786
4787
4788%% --------------------------
4789
4790msg10() ->
4791    msg10(?MGC_MID).
4792msg10(Mid) ->
4793    AmmReq = cre_ammReq([#megaco_term_id{id = ?A4444}],[]),
4794    CmdReq = cre_commandReq({addReq, AmmReq}),
4795    Jit = cre_propertyParm("nt/jit", "40"),
4796    LCD = cre_localControlDesc(recvOnly,[Jit]),
4797    V   = cre_propertyParm("v", "0"),
4798    C   = cre_propertyParm("c", "IN IP4 $ "),
4799    M   = cre_propertyParm("m", "audio $ RTP/AVP 4"),
4800    A   = cre_propertyParm("a", "ptime:30"),
4801    V2  = cre_propertyParm("v", "0"),
4802    C2  = cre_propertyParm("c", "IN IP4 $ "),
4803    M2  = cre_propertyParm("m", "audio $ RTP/AVP 0"),
4804    LD  = cre_localRemoteDesc([[V, C, M, A], [V2, C2, M2]]),
4805    Parms      = cre_streamParms(LCD, LD),
4806    StreamDesc = cre_streamDesc(1,Parms),
4807    MediaDesc  = cre_mediaDesc(StreamDesc),
4808    ChooseTid  = #megaco_term_id{contains_wildcards = true,
4809				 id = [[?megaco_choose]]},
4810    AmmReq2    = cre_ammReq([ChooseTid],[{mediaDescriptor, MediaDesc}]),
4811    CmdReq2    = cre_commandReq({addReq, AmmReq2}),
4812    msg_request(Mid, 10003, ?megaco_choose_context_id, [CmdReq, CmdReq2]).
4813
4814
4815msg11() ->
4816    msg11(?MG1_MID).
4817msg11(Mid) ->
4818    V  = cre_propertyParm("v", "0"),
4819    C  = cre_propertyParm("c", "IN IP4 124.124.124.222"),
4820    M  = cre_propertyParm("m", "audio 2222 RTP/AVP 4"),
4821    A  = cre_propertyParm("a", "ptime:30"),
4822    A2 = cre_propertyParm("a", "recvonly"),
4823    LD = cre_localRemoteDesc([[V, C, M, A, A2]]),
4824    Parms      = cre_streamParmsL(LD),
4825    StreamDesc = cre_streamDesc(1, Parms),
4826    MediaDesc  = cre_mediaDesc(StreamDesc),
4827    Reply  = cre_ammsReply([#megaco_term_id{id = ?A4444}]),
4828    Reply2 = cre_ammsReply([#megaco_term_id{id = ?A4445}],
4829			   [{mediaDescriptor, MediaDesc}]),
4830    msg_reply(Mid, 10003, 2000, [{addReply, Reply}, {addReply, Reply2}]).
4831
4832
4833%% --------------------------
4834
4835msg12() ->
4836    msg12(?MGC_MID).
4837msg12(Mid) ->
4838    LCD        = cre_localControlDesc(sendRecv),
4839    Parms      = cre_streamParms(LCD),
4840    StreamDesc = cre_streamDesc(1,Parms),
4841    MediaDesc  = cre_mediaDesc(StreamDesc),
4842    Signal     = cre_signal("al/ri"),
4843    Descs      = [{mediaDescriptor, MediaDesc},
4844		  {signalsDescriptor, [{signal, Signal}]}],
4845    AmmReq     = cre_ammReq([#megaco_term_id{id = ?A5555}], Descs),
4846    CmdReq     = cre_commandReq({addReq, AmmReq}),
4847    Jit        = cre_propertyParm("nt/jit", "40"),
4848    LCD2       = cre_localControlDesc(sendRecv, [Jit]),
4849    V      = cre_propertyParm("v", "0"),
4850    C      = cre_propertyParm("c", "IN IP4 $ "),
4851    M      = cre_propertyParm("m", "audio $ RTP/AVP 4"),
4852    A      = cre_propertyParm("a", "ptime:30"),
4853    LD2    = cre_localRemoteDesc([[V, C, M, A]]),
4854    V2     = cre_propertyParm("v", "0"),
4855    C2     = cre_propertyParm("c", "IN IP4 124.124.124.222"),
4856    M2     = cre_propertyParm("m", "audio 2222 RTP/AVP 4"),
4857    RD2    = cre_localRemoteDesc([[V2, C2, M2]]),
4858    Parms2 = cre_streamParms(LCD2,LD2,RD2),
4859    StreamDesc2 = cre_streamDesc(1,Parms2),
4860    MediaDesc2  = cre_mediaDesc(StreamDesc2),
4861    ChooseTid   = #megaco_term_id{contains_wildcards = true,
4862				  id = [[?megaco_choose]]},
4863    AmmReq2     = cre_ammReq([ChooseTid],[{mediaDescriptor, MediaDesc2}]),
4864    CmdReq2     = cre_commandReq({addReq, AmmReq2}),
4865    msg_request(Mid, 50003, ?megaco_choose_context_id, [CmdReq, CmdReq2]).
4866
4867
4868%% --------------------------
4869
4870msg13() ->
4871    msg13(?MG2_MID).
4872msg13(Mid) ->
4873    V     = cre_propertyParm("v", "0"),
4874    C     = cre_propertyParm("c", "IN IP4 125.125.125.111"),
4875    M     = cre_propertyParm("m", "audio 1111 RTP/AVP 4"),
4876    LD    = cre_localRemoteDesc([[V, C, M]]),
4877    Parms = cre_streamParmsL(LD),
4878    StreamDesc = cre_streamDesc(1,Parms),
4879    MediaDesc  = cre_mediaDesc(StreamDesc),
4880    Reply      = cre_ammsReply([#megaco_term_id{id = ?A5556}],
4881			       [{mediaDescriptor, MediaDesc}]),
4882    msg_reply(Mid, 50003, 5000, [{addReply, Reply}]).
4883
4884
4885%% --------------------------
4886
4887msg14() ->
4888    msg14(?MGC_MID).
4889msg14(Mid) ->
4890    Signal  = cre_signal("cg/rt"),
4891    AmmReq1 = cre_ammReq([#megaco_term_id{id = ?A4444}],
4892			 [{signalsDescriptor, [{signal, Signal}]}]),
4893    CmdReq1 = cre_commandReq({modReq, AmmReq1}),
4894
4895    Gain    = cre_propertyParm("tdmc/gain", "2"),
4896    Ec      = cre_propertyParm("tdmc/ec", "g165"),
4897    LCD     = cre_localControlDesc(sendRecv, [Gain, Ec]),
4898    Parms2  = cre_streamParms(LCD),
4899    StreamDesc2 = cre_streamDesc(1,Parms2),
4900    MediaDesc2  = cre_mediaDesc(StreamDesc2),
4901    AmmReq2     = cre_ammReq([#megaco_term_id{id = ?A4445}],
4902			     [{mediaDescriptor, MediaDesc2}]),
4903    CmdReq2     = cre_commandReq({modReq, AmmReq2}),
4904
4905    V      = cre_propertyParm("v", "0"),
4906    C      = cre_propertyParm("c", "IN IP4 125.125.125.111"),
4907    M      = cre_propertyParm("m", "audio 1111 RTP/AVP 4"),
4908    RD     = cre_localRemoteDesc([[V, C, M]]),
4909    Parms3 = cre_streamParmsR(RD),
4910    StreamDesc3 = cre_streamDesc(1,Parms3),
4911    MediaDesc3  = cre_mediaDesc(StreamDesc3),
4912    AmmReq3     = cre_ammReq([#megaco_term_id{id = ?A4445}],
4913			     [{mediaDescriptor, MediaDesc3}]),
4914    CmdReq3     = cre_commandReq({modReq, AmmReq3}),
4915    msg_request(Mid, 10005, 2000, [CmdReq1, CmdReq2, CmdReq3]).
4916
4917
4918%% --------------------------
4919
4920msg15() ->
4921    msg15(?MG1_MID).
4922msg15(Mid) ->
4923    Reply  = cre_ammsReply([#megaco_term_id{id = ?A4444}]),
4924    Reply2 = cre_ammsReply([#megaco_term_id{id = ?A4445}]),
4925    msg_reply(Mid, 10005, 2000, [{modReply, Reply}, {modReply, Reply2}]).
4926
4927
4928msg15b() ->
4929    msg15b(?MG1_MID).
4930
4931msg15b(Mid) ->
4932    %% We reuse the amms reply stuff
4933    Reply1 = cre_ammsReply([#megaco_term_id{id = ?A4444}]),
4934    Reply2 = cre_ammsReply([#megaco_term_id{id = ?A4445}]),
4935    ActionReplyData =
4936	[{modReply, Reply1}, {modReply, Reply2}],
4937    ReplyData =
4938	[{2001, ActionReplyData},
4939	 {2002, ActionReplyData},
4940	 {2003, ActionReplyData},
4941	 {2004, ActionReplyData},
4942	 {2005, ActionReplyData},
4943	 {2006, ActionReplyData},
4944	 {2007, ActionReplyData},
4945	 {2008, ActionReplyData},
4946	 {2009, ActionReplyData},
4947	 {2010, ActionReplyData},
4948	 {2011, ActionReplyData},
4949	 {2012, ActionReplyData},
4950	 {2013, ActionReplyData},
4951	 {2014, ActionReplyData},
4952	 {2015, ActionReplyData},
4953	 {2016, ActionReplyData},
4954	 {2017, ActionReplyData},
4955	 {2018, ActionReplyData},
4956	 {2019, ActionReplyData},
4957	 {2020, ActionReplyData},
4958	 {2021, ActionReplyData},
4959	 {2022, ActionReplyData},
4960	 {2023, ActionReplyData},
4961	 {2024, ActionReplyData},
4962	 {2025, ActionReplyData},
4963	 {2026, ActionReplyData},
4964	 {2027, ActionReplyData},
4965	 {2028, ActionReplyData},
4966	 {2029, ActionReplyData},
4967	 {2030, ActionReplyData},
4968	 {2031, ActionReplyData}],
4969     msg_replies(Mid, 10005, ReplyData).
4970
4971
4972%% --------------------------
4973
4974msg16() ->
4975    msg16(?MG2_MID).
4976msg16(Mid) ->
4977    TimeStamp = cre_timeNotation("19990729","22020002"),
4978    Event     = cre_observedEvent("al/of",TimeStamp),
4979    Desc      = cre_observedEventsDesc(1234,[Event]),
4980    NotifyReq = cre_notifyReq([#megaco_term_id{id = ?A5555}],Desc),
4981    CmdReq    = cre_commandReq({notifyReq, NotifyReq}),
4982    msg_request(Mid, 50005, 5000, [CmdReq]).
4983
4984
4985%% --------------------------
4986
4987msg17() ->
4988    msg17(?MGC_MID).
4989msg17(Mid) ->
4990    Reply = cre_notifyReply([#megaco_term_id{id = ?A5555}]),
4991    msg_reply(Mid, 50005, ?megaco_null_context_id, [{notifyReply, Reply}]).
4992
4993
4994%% --------------------------
4995
4996msg18() ->
4997    msg18(?MGC_MID).
4998msg18(Mid) ->
4999    On         = cre_requestedEvent("al/on"),
5000    EventsDesc = cre_eventsDesc(1235,[On]),
5001    AmmReq     = cre_ammReq([#megaco_term_id{id = ?A5555}],
5002			    [{eventsDescriptor, EventsDesc},
5003			     {signalsDescriptor, []}]),
5004    CmdReq     = cre_commandReq({modReq, AmmReq}),
5005    msg_request(Mid, 50006, 5000, [CmdReq]).
5006
5007
5008%% --------------------------
5009
5010msg19() ->
5011    msg19(?MG2_MID).
5012msg19(Mid) ->
5013    Reply = cre_ammsReply([#megaco_term_id{id = ?A4445}]),
5014    msg_reply(Mid, 50006, 5000, [{modReply, Reply}]).
5015
5016
5017%% --------------------------
5018
5019msg20() ->
5020    msg20(?MGC_MID).
5021msg20(Mid) ->
5022    LCD        = cre_localControlDesc(sendRecv),
5023    Parms      = cre_streamParms(LCD),
5024    StreamDesc = cre_streamDesc(1,Parms),
5025    MediaDesc  = cre_mediaDesc(StreamDesc),
5026    AmmReq     = cre_ammReq([#megaco_term_id{id = ?A4445}],
5027			    [{mediaDescriptor, MediaDesc}]),
5028    CmdReq     = cre_commandReq({modReq, AmmReq}),
5029    AmmReq2    = cre_ammReq([#megaco_term_id{id = ?A4444}],
5030                            [{signalsDescriptor, []}]),
5031    CmdReq2    = cre_commandReq({modReq, AmmReq2}),
5032    msg_request(Mid, 10006, 2000, [CmdReq, CmdReq2]).
5033
5034
5035%% --------------------------
5036
5037msg21() ->
5038    msg21(?MGC_MID).
5039msg21(Mid) ->
5040    Tokens    = [mediaToken, eventsToken, signalsToken,
5041		 digitMapToken, statsToken, packagesToken],
5042    AuditDesc = cre_auditDesc(Tokens),
5043    Req       = cre_auditReq(#megaco_term_id{id = ?A5556},AuditDesc),
5044    CmdReq    = cre_commandReq({auditValueRequest, Req}),
5045    msg_request(Mid, 50007, ?megaco_null_context_id, [CmdReq]).
5046
5047
5048%% --------------------------
5049
5050msg22a() ->
5051    msg22(1).
5052
5053msg22b() ->
5054    msg22(10).
5055
5056msg22c() ->
5057    msg22(25).
5058
5059msg22d() ->
5060    msg22(50).
5061
5062msg22e() ->
5063    msg22(75).
5064
5065msg22f() ->
5066    msg22(100).
5067
5068msg22(N) ->
5069    msg22(?MG2_MID, N).
5070msg22(Mid, N) ->
5071    Jit = cre_propertyParm("nt/jit", "40"),
5072    LCD = cre_localControlDesc(sendRecv,[Jit]),
5073    LDV = cre_propertyParm("v", "0"),
5074    LDC = cre_propertyParm("c", "IN IP4 125.125.125.111"),
5075    LDM = cre_propertyParm("m", "audio 1111 RTP/AVP  4"),
5076    LDA = cre_propertyParm("a", "ptime:30"),
5077    LD  = cre_localRemoteDesc([[LDV, LDC, LDM, LDA]]),
5078    RDV = cre_propertyParm("v", "0"),
5079    RDC = cre_propertyParm("c", "IN IP4 124.124.124.222"),
5080    RDM = cre_propertyParm("m", "audio 2222 RTP/AVP  4"),
5081    RDA = cre_propertyParm("a", "ptime:30"),
5082    RD  = cre_localRemoteDesc([[RDV, RDC, RDM, RDA]]),
5083    StreamParms   = cre_streamParms(LCD,LD,RD),
5084    StreamDesc    = cre_streamDesc(1,StreamParms),
5085    Media         = cre_mediaDesc(StreamDesc),
5086    PackagesItem  = cre_packagesItem("nt",1),
5087    PackagesItem2 = cre_packagesItem("rtp",1),
5088    Stat       = cre_statisticsParm("rtp/ps","1200"),
5089    Stat2      = cre_statisticsParm("nt/os","62300"),
5090    Stat3      = cre_statisticsParm("rtp/pr","700"),
5091    Stat4      = cre_statisticsParm("nt/or","45100"),
5092    Stat5      = cre_statisticsParm("rtp/pl","0.2"),
5093    Stat6      = cre_statisticsParm("rtp/jit","20"),
5094    Stat7      = cre_statisticsParm("rtp/delay","40"),
5095    Statistics = [Stat, Stat2, Stat3, Stat4, Stat5, Stat6, Stat7],
5096    Audits     = [{mediaDescriptor, Media},
5097		  {packagesDescriptor, [PackagesItem, PackagesItem2]},
5098		  {statisticsDescriptor, Statistics}],
5099    Reply      = {auditResult,
5100		  cre_auditRes(#megaco_term_id{id = ?A5556},Audits)},
5101    msg_reply(Mid, 50007, ?megaco_null_context_id,
5102	      lists:duplicate(N,{auditValueReply, Reply})).
5103%%     msg_reply(Mid, 50007, ?megaco_null_context_id,
5104%% 	      lists.duplicate([{auditValueReply, Reply}]).
5105
5106
5107%% --------------------------
5108
5109msg23a() ->
5110    msg23a(?MG2_MID).
5111msg23a(Mid) ->
5112    TimeStamp = cre_timeNotation("19990729","24020002"),
5113    Event     = cre_observedEvent("al/on",TimeStamp),
5114    Desc      = cre_observedEventsDesc(1235,[Event]),
5115    NotifyReq = cre_notifyReq([#megaco_term_id{id = ?A5555}],Desc),
5116    CmdReq    = cre_commandReq({notifyReq, NotifyReq}),
5117    msg_request(Mid, 50008, 5000, [CmdReq]).
5118
5119
5120msg23b() ->
5121    msg23b(?MG2_MID).
5122msg23b(Mid) ->
5123    TimeStamp  = cre_timeNotation("19990729","24020002"),
5124    Event      = cre_observedEvent("al/on",TimeStamp),
5125    Desc       = cre_observedEventsDesc(1235,[Event]),
5126    NotifyReq1 = cre_notifyReq([#megaco_term_id{id = ?A5555}],Desc),
5127    CmdReq1    = cre_commandReq({notifyReq, NotifyReq1}),
5128    NotifyReq2 = cre_notifyReq([#megaco_term_id{id = ?A5556}],Desc),
5129    CmdReq2    = cre_commandReq({notifyReq, NotifyReq2}),
5130    ActionInfo = [{5000, [CmdReq1]}, {5001, [CmdReq2]}],
5131    TransInfo  = [{50008, ActionInfo}],
5132    msg_request(Mid, TransInfo).
5133
5134
5135msg23c() ->
5136    msg23c(?MG2_MID).
5137msg23c(Mid) ->
5138    TimeStamp  = cre_timeNotation("19990729","24020002"),
5139    Event      = cre_observedEvent("al/on",TimeStamp),
5140    Desc       = cre_observedEventsDesc(1235,[Event]),
5141    NotifyReq1 = cre_notifyReq([#megaco_term_id{id = ?A5555}],Desc),
5142    CmdReq1    = cre_commandReq({notifyReq, NotifyReq1}),
5143    NotifyReq2 = cre_notifyReq([#megaco_term_id{id = ?A5556}],Desc),
5144    CmdReq2    = cre_commandReq({notifyReq, NotifyReq2}),
5145    ActionInfo1 = [{5000, [CmdReq1]}],
5146    ActionInfo2 = [{5001, [CmdReq2]}],
5147    TransInfo   = [{50008, ActionInfo1}, {50009, ActionInfo2}],
5148    msg_request(Mid, TransInfo).
5149
5150
5151msg23d() ->
5152    msg23d(?MG2_MID).
5153msg23d(Mid) ->
5154    TimeStamp  = cre_timeNotation("19990729","24020002"),
5155    Event      = cre_observedEvent("al/on",TimeStamp),
5156    Desc       = cre_observedEventsDesc(1235,[Event]),
5157    NotifyReq1 = cre_notifyReq([#megaco_term_id{id = ?A5555}],Desc),
5158    CmdReq1    = cre_commandReq({notifyReq, NotifyReq1}),
5159    NotifyReq2 = cre_notifyReq([#megaco_term_id{id = ?A5556}],Desc),
5160    CmdReq2    = cre_commandReq({notifyReq, NotifyReq2}),
5161    NotifyReq3 = cre_notifyReq([#megaco_term_id{id = ?A4444}],Desc),
5162    CmdReq3    = cre_commandReq({notifyReq, NotifyReq3}),
5163    NotifyReq4 = cre_notifyReq([#megaco_term_id{id = ?A4445}],Desc),
5164    CmdReq4    = cre_commandReq({notifyReq, NotifyReq4}),
5165    ActionInfo1 = [{5000, [CmdReq1]}, {5001, [CmdReq2]}],
5166    ActionInfo2 = [{5003, [CmdReq3]}, {5004, [CmdReq4]}],
5167    TransInfo   = [{50008, ActionInfo1}, {50009, ActionInfo2}],
5168    msg_request(Mid, TransInfo).
5169
5170
5171%% --------------------------
5172
5173msg24() ->
5174    msg24(?MGC_MID).
5175msg24(Mid) ->
5176    AuditDesc = cre_auditDesc([statsToken]),
5177    SubReq    = cre_subtractReq([#megaco_term_id{id = ?A5555}], AuditDesc),
5178    SubReq2   = cre_subtractReq([#megaco_term_id{id = ?A5556}], AuditDesc),
5179    CmdReq    = cre_commandReq({subtractReq, SubReq}),
5180    CmdReq2   = cre_commandReq({subtractReq, SubReq2}),
5181    msg_request(Mid, 50009, 5000, [CmdReq, CmdReq2]).
5182
5183
5184%% --------------------------
5185
5186msg25() ->
5187    msg25(?MG2_MID).
5188msg25(Mid) ->
5189    Stat11 = cre_statisticsParm("nt/os","45123"),
5190    Stat12 = cre_statisticsParm("nt/dur", "40"),
5191    Stats1 = [Stat11, Stat12],
5192    Reply1 = cre_ammsReply([#megaco_term_id{id = ?A5555}],
5193			   [{statisticsDescriptor, Stats1}]),
5194    Stat21 = cre_statisticsParm("rtp/ps","1245"),
5195    Stat22 = cre_statisticsParm("nt/os", "62345"),
5196    Stat23 = cre_statisticsParm("rtp/pr", "780"),
5197    Stat24 = cre_statisticsParm("nt/or", "45123"),
5198    Stat25 = cre_statisticsParm("rtp/pl", "10"),
5199    Stat26 = cre_statisticsParm("rtp/jit", "27"),
5200    Stat27 = cre_statisticsParm("rtp/delay","48"),
5201    Stats2 = [Stat21, Stat22, Stat23, Stat24, Stat25, Stat26, Stat27],
5202    Reply2 = cre_ammsReply([#megaco_term_id{id = ?A5556}],
5203                          [{statisticsDescriptor, Stats2}]),
5204    msg_reply(Mid, 50009, 5000,
5205	      [{subtractReply, Reply1}, {subtractReply, Reply2}]).
5206
5207
5208msg30a() ->
5209    msg_ack(?MG2_MID, [{9,9}]).
5210
5211msg30b() ->
5212    msg_ack(?MG2_MID, [{9,13}]).
5213
5214msg30c() ->
5215    msg_ack(?MG2_MID,
5216	    [{9,13},   {15,15},  {33,40},  {50,60},  {70,80},  {85,90},
5217	     {101,105},{109,119},{121,130},{140,160},{170,175},{180,189},
5218	     {201,205},{209,219},{221,230},{240,260},{270,275},{280,289},
5219	     {301,305},{309,319},{321,330},{340,360},{370,375},{380,389},
5220	     {401,405},{409,419},{421,430},{440,460},{470,475},{480,489},
5221	     {501,505},{509,519},{521,530},{540,560},{570,575},{580,589}
5222	    ]).
5223
5224%% Don't think this will be used by the megaco stack, but since it
5225%% seem's to be a valid construction...
5226msg30d() ->
5227    msg_ack(?MG2_MID,
5228	    [[{9,13},   {15,15},  {33,40},  {50,60},  {70,80},  {85,90}],
5229	     [{101,105},{109,119},{121,130},{140,160},{170,175},{180,189}],
5230	     [{201,205},{209,219},{221,230},{240,260},{270,275},{280,289}],
5231	     [{301,305},{309,319},{321,330},{340,360},{370,375},{380,389}],
5232	     [{401,405},{409,419},{421,430},{440,460},{470,475},{480,489}],
5233	     [{501,505},{509,519},{521,530},{540,560},{570,575},{580,589}]
5234	    ]).
5235
5236
5237
5238msg40() ->
5239    msg40(?MG1_MID_NO_PORT, "901 mg col boot").
5240msg40(Mid, Reason) when is_list(Reason) ->
5241    Address = {portNumber, ?DEFAULT_PORT},
5242    Profile = cre_serviceChangeProf("resgw",1),
5243    Parm    = cre_serviceChangeParm(restart,Address,[Reason],Profile),
5244    Req     = cre_serviceChangeReq([?megaco_root_termination_id],Parm),
5245    CmdReq  = cre_commandReq({serviceChangeReq, Req}),
5246    Auth    = cre_authHeader(),
5247    msg_request(Auth, Mid, 9998, ?megaco_null_context_id, [CmdReq]).
5248
5249
5250%% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5251%% Pretty RFC 3525 messages:
5252
5253%% Added Reason
5254rfc3525_msg1() ->
5255"MEGACO/" ?VERSION_STR " [124.124.124.222] Transaction = 9998 {
5256   Context = - {
5257      ServiceChange = ROOT {
5258         Services {
5259	    Method = Restart,
5260            Reason = 901,
5261	    ServiceChangeAddress = 55555,
5262            Profile = ResGW/1
5263         }
5264      }
5265   }
5266}".
5267
5268rfc3525_msg2() ->
5269"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Reply = 9998 {
5270   Context = - {
5271      ServiceChange = ROOT {
5272         Services {
5273            ServiceChangeAddress = 55555,
5274            Profile = ResGW/1
5275         }
5276      }
5277   }
5278}".
5279
5280
5281%% Removed "," after LocalControl ending "}"
5282rfc3525_msg3() ->
5283"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 9999 {
5284   Context = - {
5285      Modify = A4444 {
5286         Media {
5287            Stream = 1 {
5288               LocalControl {
5289                  Mode = SendReceive,
5290                  tdmc/gain=2,  ; in dB,
5291                  tdmc/ec=on
5292               }
5293            }
5294         },
5295         Events = 2222 {
5296            al/of {strict=state}
5297         }
5298      }
5299   }
5300}".
5301
5302%% Removed the outermost "{}" pair (before the Reply token)
5303rfc3525_msg4() ->
5304"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 9999 {
5305   Context = - {
5306      Modify = A4444
5307   }
5308}".
5309
5310rfc3525_msg6() ->
5311"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Transaction = 10000 {
5312   Context = - {
5313      Notify = A4444 {
5314         ObservedEvents =2222 {
5315            19990729T22000000:al/of{init=false}
5316         }
5317      }
5318   }
5319}".
5320
5321
5322rfc3525_msg7() ->
5323"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Reply = 10000 {
5324   Context = - {
5325      Notify = A4444
5326   }
5327}".
5328
5329rfc3525_msg8() ->
5330"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 10001 {
5331   Context = - {
5332      Modify = A4444 {
5333         Events = 2223 {
5334            al/on {strict=state},
5335            dd/ce {DigitMap=Dialplan0}
5336	 },
5337         Signals {cg/dt},
5338         DigitMap = Dialplan0 {
5339            (0| 00|[1-7]xxx|8xxxxxxx|fxxxxxxx|exx|91xxxxxxxxxx|9011x.)
5340         }
5341      }
5342   }
5343}".
5344
5345rfc3525_msg9() ->
5346"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10001 {
5347   Context = - {
5348      Modify = A4444
5349   }
5350}".
5351
5352rfc3525_msg10() ->
5353"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Transaction = 10002 {
5354   Context = - {
5355      Notify = A4444 {
5356         ObservedEvents =2223 {
5357            19990729T22010001:dd/ce {
5358               ds=\"916135551212\",
5359               Meth=UM
5360            }
5361         }
5362      }
5363   }
5364}".
5365
5366
5367rfc3525_msg11() ->
5368"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Reply = 10002 {
5369   Context = - {
5370      Notify = A4444
5371   }
5372}".
5373
5374%% Added ?
5375rfc3525_msg12() ->
5376"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 10003 {
5377   Context = $ {
5378      Add = A4444,
5379      Add = $ {
5380         Media {
5381            Stream = 1 {
5382               LocalControl {
5383                  Mode = ReceiveOnly,
5384                  nt/jit=40 ; in ms
5385               },
5386               Local {
5387                  v=0 c=IN IP4 $ m=audio $ RTP/AVP 4 a=ptime:30 v=0 c=IN IP4 $ m=audio $ RTP/AVP 0
5388               }
5389            }
5390         }
5391      }
5392   }
5393}".
5394
5395%% Added ?
5396rfc3525_msg13() ->
5397"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10003 {
5398   Context = 2000 {
5399      Add = A4444,
5400      Add = A4445 {
5401         Media {
5402            Stream = 1 {
5403               Local {
5404v=0
5405o=- 2890844526 2890842807 IN IP4 124.124.124.222
5406s=-
5407t= 0 0
5408c=IN IP4 124.124.124.222
5409m=audio 2222 RTP/AVP 4
5410a=ptime:30
5411a=recvonly
5412               } ; RTP profile for G.723.1 is 4
5413            }
5414         }
5415      }
5416   }
5417}".
5418
5419%%
5420%% Added ?
5421rfc3525_msg14() ->
5422"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 50003 {
5423   Context = $ {
5424      Add = A5555 {
5425         Media {
5426            Stream = 1 {
5427               LocalControl {
5428                  Mode = SendReceive
5429               }
5430            }
5431         },
5432         Events = 1234 {
5433            al/of {strict=state}
5434         },
5435         Signals {al/ri}
5436      },
5437      Add = $ {
5438         Media {
5439            Stream = 1 {
5440               LocalControl {
5441                  Mode = SendReceive,
5442                  nt/jit=40 ; in ms
5443               },
5444               Local {
5445                  v=0 c=IN IP4 $ m=audio $ RTP/AVP 4 a=ptime:30
5446               },
5447               Remote {
5448                  v=0 c=IN IP4 124.124.124.222 m=audio 2222 RTP/AVP 4 a=ptime:30
5449               } ; RTP profile for G.723.1 is 4
5450            }
5451         }
5452      }
5453   }
5454}".
5455
5456%% Added ?
5457rfc3525_msg15() ->
5458"MEGACO/" ?VERSION_STR " [125.125.125.111]:55555 Reply = 50003 {
5459   Context = 5000 {
5460      Add = A5555,
5461      Add = A5556 {
5462         Media {
5463            Stream = 1 {
5464               Local {
5465                  v=0 o=- 7736844526 7736842807 IN IP4 125.125.125.111 s=- t= 0 0 c=IN IP4 125.125.125.111 m=audio 1111 RTP/AVP 4
5466               } ; RTP profile for G723.1 is 4
5467            }
5468         }
5469      }
5470   }
5471}".
5472
5473%% Added ?
5474rfc3525_msg16a() ->
5475"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 10005 {
5476   Context = 2000 {
5477      Modify = A4444 {
5478         Signals {cg/rt}
5479      },
5480      Modify = A4445 {
5481         Media {
5482            Stream = 1 {
5483               Remote {
5484                  v=0 o=- 7736844526 7736842807 IN IP4 125.125.125.111 s=- t= 0 0 c=IN IP4 125.125.125.111 m=audio 1111 RTP/AVP 4
5485	       } ; RTP profile for G723.1 is 4
5486            }
5487         }
5488      }
5489   }
5490}".
5491
5492rfc3525_msg16b() ->
5493"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10005 {
5494   Context = 2000 {
5495      Modify = A4444,
5496      Modify = A4445
5497   }
5498}".
5499
5500rfc3525_msg17a() ->
5501"MEGACO/" ?VERSION_STR " [125.125.125.111]:55555 Transaction = 50005 {
5502   Context = 5000 {
5503      Notify = A5555 {
5504         ObservedEvents = 1234 {
5505            19990729T22020002:al/of{init=false}
5506         }
5507      }
5508   }
5509}".
5510
5511rfc3525_msg17b() ->
5512"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Reply = 50005 {
5513   Context = - {
5514      Notify = A5555
5515   }
5516}".
5517
5518%% Removed "{ }" after Signals
5519rfc3525_msg17c() ->
5520"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 50006 {
5521   Context = 5000 {
5522      Modify = A5555 {
5523         Events = 1235 {
5524            al/on{strict=state}
5525         },
5526         Signals ; to turn off ringing
5527      }
5528   }
5529}".
5530
5531rfc3525_msg17d() ->
5532"MEGACO/" ?VERSION_STR " [125.125.125.111]:55555 Reply = 50006 {
5533   Context = 5000 {
5534      Modify = A4445
5535   }
5536}".
5537
5538%% Removed "{ }" after Signals
5539rfc3525_msg18a() ->
5540"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 10006 {
5541   Context = 2000 {
5542      Modify = A4445 {
5543         Media {
5544            Stream = 1 {
5545               LocalControl {
5546                  Mode = SendReceive
5547               }
5548            }
5549         }
5550      },
5551      Modify = A4444 {
5552         Signals
5553      }
5554   }
5555}".
5556
5557rfc3525_msg18b() ->
5558"MEGACO/" ?VERSION_STR " [124.124.124.222]:55555 Reply = 10006 {
5559   Context = 2000 {
5560      Modify = A4445,
5561      Modify = A4444
5562   }
5563}".
5564
5565rfc3525_msg19() ->
5566"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 50007 {
5567   Context = - {
5568      AuditValue = A5556 {
5569         Audit {
5570            Media, DigitMap, Events, Signals, Packages, Statistics
5571         }
5572      }
5573   }
5574}".
5575
5576%% Added ?
5577rfc3525_msg20() ->
5578"MEGACO/" ?VERSION_STR " [125.125.125.111]:55555 Reply = 50007 {
5579   Context = - {
5580      AuditValue = A5556 {
5581         Media {
5582            TerminationState {
5583               ServiceStates = InService,
5584               Buffer = OFF
5585            },
5586            Stream = 1 {
5587               LocalControl {
5588                  Mode = SendReceive,
5589                  nt/jit=40
5590               },
5591               Local {
5592                  v=0 o=- 7736844526 7736842807 IN IP4 125.125.125.111 s=- t= 0 0 c=IN IP4 125.125.125.111 m=audio 1111 RTP/AVP  4 a=ptime:30
5593               },
5594               Remote {
5595                  v=0 o=- 2890844526 2890842807 IN IP4 124.124.124.222 s=- t= 0 0 c=IN IP4 124.124.124.222 m=audio 2222 RTP/AVP  4 a=ptime:30
5596               }
5597            }
5598         },
5599         Events,
5600         Signals,
5601         DigitMap,
5602         Packages {nt-1, rtp-1},
5603         Statistics {
5604            rtp/ps=1200,  ; packets sent
5605            nt/os=62300, ; octets sent
5606            rtp/pr=700, ; packets received
5607            nt/or=45100, ; octets received
5608            rtp/pl=0.2,  ; % packet loss
5609            rtp/jit=20,
5610            rtp/delay=40 ; avg latency
5611         }
5612      }
5613   }
5614}".
5615
5616rfc3525_msg21a() ->
5617"MEGACO/" ?VERSION_STR " [125.125.125.111]:55555 Transaction = 50008 {
5618   Context = 5000 {
5619      Notify = A5555 {
5620         ObservedEvents =1235 {
5621            19990729T24020002:al/on {init=false}
5622         }
5623      }
5624   }
5625}".
5626
5627rfc3525_msg21b() ->
5628"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Reply = 50008 {
5629   Context = - {
5630      Notify = A5555
5631   }
5632}".
5633
5634rfc3525_msg22a() ->
5635"MEGACO/" ?VERSION_STR " [123.123.123.4]:55555 Transaction = 50009 {
5636   Context = 5000 {
5637      Subtract = A5555 {
5638         Audit {
5639            Statistics
5640         }
5641      },
5642      Subtract = A5556 {
5643         Audit {
5644            Statistics
5645         }
5646      }
5647   }
5648}".
5649
5650%% Added ?
5651rfc3525_msg22b() ->
5652"MEGACO/" ?VERSION_STR " [125.125.125.111]:55555 Reply = 50009 {
5653   Context = 5000 {
5654      Subtract = A5555 {
5655         Statistics {
5656            nt/os=45123, ; Octets Sent
5657            nt/dur=40 ; in seconds
5658         }
5659      },
5660      Subtract = A5556 {
5661         Statistics {
5662            rtp/ps=1245, ; packets sent
5663            nt/os=62345, ; octets sent
5664            rtp/pr=780, ; packets received
5665            nt/or=45123, ; octets received
5666            rtp/pl=10, ;  % packets lost
5667            rtp/jit=27,
5668            rtp/delay=48 ; average latency
5669         }
5670      }
5671   }
5672}".
5673
5674
5675rfc3525_msgs() ->
5676    [
5677     {msg1,   rfc3525_msg1()},
5678     {msg2,   rfc3525_msg2()},
5679     {msg3,   rfc3525_msg3()},
5680     {msg4,   rfc3525_msg4()},
5681     {msg6,   rfc3525_msg6()},
5682     {msg7,   rfc3525_msg7()},
5683     {msg8,   rfc3525_msg8()},
5684     {msg9,   rfc3525_msg9()},
5685     {msg10,  rfc3525_msg10()},
5686     {msg11,  rfc3525_msg11()},
5687     {msg12,  rfc3525_msg12()},
5688     {msg13,  rfc3525_msg13()},
5689     {msg14,  rfc3525_msg14()},
5690     {msg15,  rfc3525_msg15()},
5691     {msg16a, rfc3525_msg16a()},
5692     {msg16b, rfc3525_msg16b()},
5693     {msg17a, rfc3525_msg17a()},
5694     {msg17b, rfc3525_msg17b()},
5695     {msg17c, rfc3525_msg17c()},
5696     {msg17d, rfc3525_msg17d()},
5697     {msg18a, rfc3525_msg18a()},
5698     {msg18b, rfc3525_msg18b()},
5699     {msg19,  rfc3525_msg19()},
5700     {msg20,  rfc3525_msg20()},
5701     {msg21a, rfc3525_msg21a()},
5702     {msg21b, rfc3525_msg21b()},
5703     {msg22a, rfc3525_msg22a()},
5704     {msg22b, rfc3525_msg22b()}
5705    ].
5706
5707
5708rfc3525_msgs_display() ->
5709    Msgs = rfc3525_msgs(),
5710    Fun = fun({Name, Msg}) ->
5711		  io:format("~w: ~n~s~n~n", [Name, Msg])
5712	  end,
5713    lists:foreach(Fun, Msgs).
5714
5715rfc3525_msgs_test() ->
5716    put(dbg,true),
5717    Res = rfc3525_msgs_test(megaco_pretty_text_encoder, [], 1),
5718    erase(dbg),
5719    io:format("~w~n", [Res]).
5720
5721rfc3525_msgs_test(Codec, Config, Ver) ->
5722    io:format("-----------------------------------------"
5723	      "~ntesting with"
5724	      "~n   Codec:   ~w"
5725	      "~n   Config:  ~w"
5726	      "~n   Version: ~w"
5727	      "~n", [Codec, Config, Ver]),
5728    Msgs = rfc3525_msgs(),
5729    Test = fun({N,M1}) ->
5730		   %% io:format("testing ~w: ", [N]),
5731		   io:format("~n*** testing ~w *** ~n~s~n", [N,M1]),
5732		   Bin1 = erlang:list_to_binary(M1),
5733		   case (catch Codec:decode_message(Config, Ver, Bin1)) of
5734		       {ok, M2} ->
5735			   %% io:format("d", []),
5736			   io:format("decoded:~n~p~n", [M2]),
5737			   case (catch Codec:encode_message(Config, Ver, M2)) of
5738			       {ok, Bin2} when is_binary(Bin2) ->
5739				   %% io:format("e~n", []),
5740				   io:format("encode: ~n~s~n", [erlang:binary_to_list(Bin2)]),
5741				   {N,ok};
5742			       {ok, M3} ->
5743				   %% io:format("e~n", []),
5744				   io:format("encode: ~n~s~n", [M3]),
5745				   {N,ok};
5746			       E ->
5747				   io:format("~n~p~n", [E]),
5748				   {N,encode_error}
5749			   end;
5750		       E ->
5751			   io:format("~n~p~n", [E]),
5752			   {N,decode_error}
5753		   end
5754	  end,
5755    [Test(M) || M <- Msgs].
5756
5757%% --------------------------
5758
5759
5760%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5761
5762skip(Reason) ->
5763    megaco_codec_test_lib:skip(Reason).
5764
5765
5766%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5767
5768decode_message(Codec, DynamicDecode, Conf, Bin) ->
5769    megaco_codec_test_lib:decode_message(Codec, DynamicDecode, ?VERSION,
5770					 Conf, Bin).
5771encode_message(Codec, Conf, Msg) ->
5772    megaco_codec_test_lib:encode_message(Codec, ?VERSION, Conf, Msg).
5773
5774test_msgs(Codec, DynamicDecode, Conf, Msgs) ->
5775    megaco_codec_test_lib:test_msgs(Codec, DynamicDecode, ?VERSION, Conf,
5776				    fun chk_MegacoMessage/2, Msgs).
5777
5778
5779%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5780
5781chk_MegacoMessage(M,M) when is_record(M,'MegacoMessage') ->
5782    ok;
5783chk_MegacoMessage(#'MegacoMessage'{authHeader = Auth1,
5784				   mess       = Mess1},
5785		  #'MegacoMessage'{authHeader = Auth2,
5786				   mess       = Mess2}) ->
5787    chk_opt_AuthenticationHeader(Auth1,Auth2),
5788    chk_Message(Mess1,Mess2),
5789    ok;
5790chk_MegacoMessage(M1, M2) ->
5791    wrong_type({'MegacoMessage', M1, M2}).
5792
5793chk_opt_AuthenticationHeader(A,A) ->
5794    ok;
5795chk_opt_AuthenticationHeader(A1,A2) ->
5796    not_equal({auth,A1,A2}).
5797
5798chk_Message(M,M) when is_record(M,'Message') ->
5799    ok;
5800chk_Message(#'Message'{version     = Version1,
5801		       mId         = MID1,
5802		       messageBody = Body1},
5803	    #'Message'{version     = Version2,
5804		       mId         = MID2,
5805		       messageBody = Body2}) ->
5806    chk_version(Version1,Version2),
5807    chk_MId(MID1,MID2),
5808    chk_messageBody(Body1,Body2),
5809    ok;
5810chk_Message(M1,M2) ->
5811    wrong_type({'Message',M1,M2}).
5812
5813
5814chk_version(V,V) when is_integer(V) ->
5815    ok;
5816chk_version(V1,V2) when is_integer(V1) andalso is_integer(V2) ->
5817    not_equal({version,V1,V2});
5818chk_version(V1,V2) ->
5819    wrong_type({integer,V1,V2}).
5820
5821
5822chk_MId(M,M) ->
5823    {equal,mid};
5824chk_MId({Tag,M1},{Tag,M2}) ->
5825    Res = chk_MId(Tag,M1,M2),
5826    equal(Res);
5827chk_MId(M1,M2) ->
5828    not_equal({mid,M1,M2}).
5829
5830chk_MId(ip4Address,M1,M2) -> chk_IP4Address(M1, M2);
5831chk_MId(ip6Address,M1,M2) -> chk_IP6Address(M1, M2);
5832chk_MId(domainName,M1,M2) -> chk_DomainName(M1, M2);
5833chk_MId(deviceName,M1,M2) -> chk_PathName(M1, M2);
5834chk_MId(mtpAddress,M1,M2) -> chk_mtpAddress(M1, M2);
5835chk_MId(Tag,M1,M2) ->
5836    wrong_type({invalid_tag,Tag,M1,M2}).
5837
5838
5839chk_IP4Address(M, M) ->
5840    ok;
5841chk_IP4Address(M1, M2) ->
5842    not_equal({ip4Address,M1,M2}).
5843
5844chk_IP6Address(M, M) ->
5845    ok;
5846chk_IP6Address(M1, M2) ->
5847    not_equal({ip6Address,M1,M2}).
5848
5849chk_DomainName(D, D) when is_record(D,'DomainName') ->
5850    ok;
5851chk_DomainName(#'DomainName'{name       = Name1,
5852			     portNumber = Port1},
5853	       #'DomainName'{name       = Name2,
5854			     portNumber = Port2}) ->
5855    chk_DomainName_name(Name1,Name2),
5856    chk_DomainName_opt_portNumber(Port1,Port2),
5857    equal('DomainName');
5858chk_DomainName(D1,D2) ->
5859    wrong_type({'DomainName',D1,D2}).
5860
5861chk_DomainName_name(N,N) when is_list(N) ->
5862    ok;
5863chk_DomainName_name(N1,N2) when is_list(N1) andalso is_list(N2) ->
5864    not_equal({'DomainName',name,N1,N2});
5865chk_DomainName_name(N1,N2) ->
5866    wrong_type({'DomainName',name,N1,N2}).
5867
5868chk_DomainName_opt_portNumber(asn1_NOVALUE, asn1_NOVALUE) ->
5869    ok;
5870chk_DomainName_opt_portNumber(P,P)
5871  when is_integer(P) andalso (P >= 0) ->
5872    ok;
5873chk_DomainName_opt_portNumber(P1,P2)
5874  when (is_integer(P1) andalso (P1 >= 0) andalso
5875	is_integer(P2) andalso (P2 >= 0)) ->
5876    not_equal({'DomainName',portNumber,P1,P2});
5877chk_DomainName_opt_portNumber(P1,P2) ->
5878    wrong_type({'DomainName',portNumber,P1,P2}).
5879
5880
5881chk_PathName(P, P) ->
5882    ok;
5883chk_PathName(P1, P2) ->
5884    not_equal({pathname,P1,P2}).
5885
5886chk_mtpAddress(M, M) ->
5887    ok;
5888chk_mtpAddress(M1, M2) ->
5889    not_equal({mtpAddress, M1, M2}).
5890
5891
5892chk_messageBody({messageError, B},
5893		{messageError, B}) when is_record(B,'ErrorDescriptor') ->
5894    ok;
5895chk_messageBody({messageError,B1},{messageError,B2}) ->
5896    chk_ErrorDescriptor(B1,B2),
5897    equal({messageBody, messageError});
5898chk_messageBody({transactions,T},{transactions,T}) when is_list(T) ->
5899    ok;
5900chk_messageBody({transactions,T1},{transactions,T2}) ->
5901    chk_transactions(T1,T2),
5902    ok;
5903chk_messageBody(B1,B2) ->
5904    wrong_type({messageBody,B1,B2}).
5905
5906
5907chk_transactions(T,T) when is_list(T) ->
5908    ok;
5909chk_transactions(T1,T2)
5910  when is_list(T1) andalso is_list(T2) andalso (length(T1) =:= length(T2)) ->
5911    chk_transactions1(T1,T2);
5912chk_transactions(T1,T2)
5913  when is_list(T1) andalso is_list(T2) ->
5914    not_equal({transactions, T1, T2});
5915chk_transactions(T1, T2) ->
5916    wrong_type({transactions,T1,T2}).
5917
5918chk_transactions1([],[]) ->
5919    equal(transactions);
5920chk_transactions1([T|Ts1],[T|Ts2]) ->
5921    chk_transactions1(Ts1,Ts2);
5922chk_transactions1([T1|_Ts1],[T2|_Ts2]) ->
5923    chk_transaction(T1,T2),
5924    ok.
5925
5926chk_transaction(T,T) ->
5927    ok;
5928chk_transaction({transactionRequest,T1},{transactionRequest,T2}) ->
5929    chk_transactionRequest(T1,T2),
5930    ok;
5931chk_transaction({transactionPending,T1},{transactionPending,T2}) ->
5932    chk_transactionPending(T1,T2),
5933    equal({transactionPending,T1,T2});
5934chk_transaction({transactionReply,T1},{transactionReply,T2}) ->
5935    chk_transactionReply(T1,T2),
5936    equal({transactionReply,T1,T2});
5937chk_transaction({transactionResponseAck,T1},{transactionResponseAck,T2}) ->
5938    chk_transactionAck(T1,T2),
5939    equal({transactionResponseAck,T1,T2});
5940chk_transaction({Tag1,_T1},{Tag2,_T2}) ->
5941    wrong_type({transaction_tag,Tag1,Tag2}).
5942
5943
5944chk_transactionRequest(T,T) when is_record(T,'TransactionRequest') ->
5945    ok;
5946chk_transactionRequest(T1,T2) when is_record(T1,'TransactionRequest') andalso
5947				   is_record(T2,'TransactionRequest') ->
5948    chk_transactionId(T1#'TransactionRequest'.transactionId,
5949		      T2#'TransactionRequest'.transactionId),
5950    chk_actionRequests(T1#'TransactionRequest'.actions,
5951		       T2#'TransactionRequest'.actions),
5952    ok;
5953chk_transactionRequest(T1,T2) ->
5954    wrong_type({transactionRequest,T1,T2}).
5955
5956
5957chk_transactionPending(T,T) when is_record(T,'TransactionPending') ->
5958    ok;
5959chk_transactionPending(#'TransactionPending'{transactionId = Id1},
5960		       #'TransactionPending'{transactionId = Id2}) ->
5961    chk_transactionId(Id1,Id2),
5962    equal(transactionPending);
5963chk_transactionPending(T1,T2) ->
5964    wrong_type({transactionPending,T1,T2}).
5965
5966chk_transactionReply(T,T) when is_record(T,'TransactionReply') ->
5967    ok;
5968chk_transactionReply(#'TransactionReply'{transactionId     = Id1,
5969					 immAckRequired    = ImmAck1,
5970					 transactionResult = TransRes1},
5971		     #'TransactionReply'{transactionId     = Id2,
5972					 immAckRequired    = ImmAck2,
5973					 transactionResult = TransRes2}) ->
5974    chk_transactionId(Id1,Id2),
5975    ImmAck1 = ImmAck2,
5976    chk_transactionReply_transactionResult(TransRes1,TransRes2),
5977    equal(transactionReply);
5978chk_transactionReply(T1,T2) ->
5979    wrong_type({transactionReply,T1,T2}).
5980
5981chk_transactionReply_transactionResult(R,R) ->
5982    ok;
5983chk_transactionReply_transactionResult(R1,R2) ->
5984    not_equal({transactionReply_transactionResult,R1,R2}).
5985
5986chk_transactionAck(T,T) when is_record(T,'TransactionAck') ->
5987    ok;
5988chk_transactionAck(#'TransactionAck'{firstAck = F1,
5989				     lastAck  = L1},
5990		   #'TransactionAck'{firstAck = F2,
5991				     lastAck  = L2}) ->
5992    chk_transactionId(F1,F2),
5993    chk_opt_transactionId(L1,L2),
5994    equal('TransactionAck');
5995chk_transactionAck(T1,T2) ->
5996    wrong_type({transactionAck,T1,T2}).
5997
5998
5999chk_actionRequests(A,A) when is_list(A) andalso (length(A) =:= 0) ->
6000    ok;
6001chk_actionRequests(A,A) when is_list(A) ->
6002    case hd(A) of
6003	A when is_record(A,'ActionRequest') ->
6004	    ok;
6005	Else ->
6006	    wrong_type({'ActionRequest',Else})
6007    end;
6008chk_actionRequests(A1,A2)
6009  when is_list(A1) andalso is_list(A2) andalso (length(A1) =:= length(A2)) ->
6010    chk_actionRequests1(A1,A2);
6011chk_actionRequests(A1,A2) ->
6012    wrong_type({actionRequests,A1,A2}).
6013
6014chk_actionRequests1([],[]) ->
6015    equal(actionRequests);
6016chk_actionRequests1([A|As1],[A|As2]) when is_record(A,'ActionRequest') ->
6017    chk_actionRequests1(As1,As2);
6018chk_actionRequests1([A1|_As1],[A2|_As2]) ->
6019    chk_actionRequest(A1,A2),
6020    ok.
6021
6022chk_actionRequest(A,A) when is_record(A,'ActionRequest') ->
6023    ok;
6024chk_actionRequest(#'ActionRequest'{contextId           = Id1,
6025				   contextRequest      = Req1,
6026				   contextAttrAuditReq = AuditReq1,
6027				   commandRequests     = CmdReqs1},
6028		  #'ActionRequest'{contextId           = Id2,
6029				   contextRequest      = Req2,
6030				   contextAttrAuditReq = AuditReq2,
6031				   commandRequests     = CmdReqs2}) ->
6032    t("chk_actionRequest -> entry with"
6033      "~n   CmdReqs1: ~p"
6034      "~n   CmdReqs2: ~p",[CmdReqs1,CmdReqs2]),
6035    chk_contextId(Id1,Id2),
6036    chk_opt_contextRequest(Req1,Req2),
6037    chk_opt_contextAttrAuditReq(AuditReq1,AuditReq2),
6038    chk_commandRequests(CmdReqs1,CmdReqs2),
6039    ok.
6040
6041chk_contextId(Id,Id) when is_integer(Id) ->
6042    ok;
6043chk_contextId(Id1,Id2) when is_integer(Id1) andalso is_integer(Id2) ->
6044    not_equal({contextId,Id1,Id2});
6045chk_contextId(Id1,Id2) ->
6046    wrong_type({contextId,Id1,Id2}).
6047
6048chk_opt_contextRequest(asn1_NOVALUE, asn1_NOVALUE) ->
6049    ok;
6050chk_opt_contextRequest(R,R) when is_record(R,'ContextRequest') ->
6051    ok;
6052chk_opt_contextRequest(#'ContextRequest'{priority    = Prio1,
6053					 emergency   = Em1,
6054					 topologyReq = TopReq1} = C1,
6055		       #'ContextRequest'{priority    = Prio2,
6056					 emergency   = Em2,
6057					 topologyReq = TopReq2} = C2) ->
6058    chk_contextRequest_priority(Prio1,Prio2),
6059    chk_contextRequest_emergency(Em1,Em2),
6060    chk_topologyRequest(TopReq1,TopReq2),
6061    equal({'ContextRequest',C1,C2}).
6062
6063chk_contextRequest_priority(asn1_NOVALUE,asn1_NOVALUE) ->
6064    ok;
6065chk_contextRequest_priority(P,P) when is_integer(P) ->
6066    ok;
6067chk_contextRequest_priority(P1,P2) when is_integer(P1) andalso is_integer(P2) ->
6068    not_equal({contextRequest_priority,P1,P2});
6069chk_contextRequest_priority(P1,P2) ->
6070    wrong_type({contextRequest_priority,P1,P2}).
6071
6072chk_contextRequest_emergency(asn1_NOVALUE,asn1_NOVALUE) ->
6073    ok;
6074chk_contextRequest_emergency(true,true) ->
6075    ok;
6076chk_contextRequest_emergency(false,false) ->
6077    ok;
6078chk_contextRequest_emergency(E1,E2) ->
6079    not_equal({contextRequest_emergency,E1,E2}).
6080
6081chk_topologyRequest(asn1_NOVALUE,asn1_NOVALUE) ->
6082    ok;
6083chk_topologyRequest(T,T) when is_record(T,'TopologyRequest') ->
6084    ok;
6085chk_topologyRequest(#'TopologyRequest'{terminationFrom   = F1,
6086				       terminationTo     = T1,
6087				       topologyDirection = D1} = T1,
6088		    #'TopologyRequest'{terminationFrom   = F2,
6089				       terminationTo     = T2,
6090				       topologyDirection = D2} = T2) ->
6091    chk_terminationId(F1,F2),
6092    chk_terminationId(T1,T2),
6093    chk_topologyRequest_topologyDirection(D1,D2),
6094    equal({'TopologyRequest',D1,D2}).
6095
6096chk_topologyRequest_topologyDirection(bothway,bothway) ->
6097    ok;
6098chk_topologyRequest_topologyDirection(isolate,isolate) ->
6099    ok;
6100chk_topologyRequest_topologyDirection(oneway,oneway) ->
6101    ok;
6102chk_topologyRequest_topologyDirection(D1,D2) ->
6103    not_equal({topologyRequest_topologyDirection, D1, D2}).
6104
6105chk_opt_contextAttrAuditReq(asn1_NOVALUE,asn1_NOVALUE) ->
6106    ok;
6107chk_opt_contextAttrAuditReq(R,R) when is_record(R,'ContextAttrAuditRequest') ->
6108    ok;
6109chk_opt_contextAttrAuditReq(#'ContextAttrAuditRequest'{topology  = T1,
6110						       emergency = E1,
6111						       priority  = P1} = R1,
6112			    #'ContextAttrAuditRequest'{topology  = T2,
6113						       emergency = E2,
6114						       priority  = P2} = R2)  ->
6115    T1 = T2,
6116    E1 = E2,
6117    P1 = P2,
6118    equal({'ContextAttrAuditRequest',R1,R2}).
6119
6120chk_commandRequests(C1,C2)
6121  when is_list(C1) andalso is_list(C2) andalso (length(C1) =:= length(C2)) ->
6122    t("chk_commandRequests -> entry with"
6123      "~n   C1: ~p"
6124      "~n   C2: ~p", [C1, C2]),
6125    chk_commandRequests1(C1,C2);
6126chk_commandRequests(C1,C2) ->
6127    t("chk_commandRequests -> entry",[]),
6128    wrong_type({commandRequests,C1,C2}).
6129
6130chk_commandRequests1([],[]) ->
6131    ok;
6132chk_commandRequests1([C1|Cs1],[C2|Cs2]) ->
6133    chk_commandRequest(C1,C2),
6134    chk_commandRequests1(Cs1,Cs2).
6135
6136chk_commandRequest(C,C) when is_record(C,'CommandRequest') ->
6137    ok;
6138chk_commandRequest(#'CommandRequest'{command        = Cmd1,
6139				     optional       = O1,
6140				     wildcardReturn = W1},
6141		   #'CommandRequest'{command        = Cmd2,
6142				     optional       = O2,
6143				     wildcardReturn = W2}) ->
6144    t("chk_commandRequest -> entry with"
6145      "~n   C1: ~p"
6146      "~n   C2: ~p", [Cmd1, Cmd2]),
6147    chk_commandRequest_command(Cmd1,Cmd2),
6148    O1 = O2,
6149    W1 = W2,
6150    ok;
6151chk_commandRequest(C1,C2) ->
6152    wrong_type({commandRequest,C1,C2}).
6153
6154chk_commandRequest_command({addReq,C1},{addReq,C2}) ->
6155    chk_AmmRequest(C1,C2);
6156chk_commandRequest_command({moveReq,C1},{moveReq,C2}) ->
6157    chk_AmmRequest(C1,C2);
6158chk_commandRequest_command({modReq,C1},{modReq,C2}) ->
6159    chk_AmmRequest(C1,C2);
6160chk_commandRequest_command({subtractReq,C1},{subtractReq,C2}) ->
6161    chk_SubtractRequest(C1,C2);
6162chk_commandRequest_command({auditCapRequest,C1},{auditCapRequest,C2}) ->
6163    chk_AuditRequest(C1,C2);
6164chk_commandRequest_command({auditValueRequest,C1},{auditValueRequest,C2}) ->
6165    chk_AuditRequest(C1,C2);
6166chk_commandRequest_command({notifyReq,C1},{notifyReq,C2}) ->
6167    chk_NotifyRequest(C1,C2);
6168chk_commandRequest_command({serviceChangeReq,C1},{serviceChangeReq,C2}) ->
6169    chk_ServiceChangeRequest(C1,C2);
6170chk_commandRequest_command(C1,C2) ->
6171    wrong_type({commandRequest_command,C1,C2}).
6172
6173
6174chk_AmmRequest(R,R) when is_record(R,'AmmRequest') ->
6175    ok;
6176chk_AmmRequest(#'AmmRequest'{terminationID = Tids1,
6177			     descriptors   = D1},
6178	       #'AmmRequest'{terminationID = Tids2,
6179			     descriptors   = D2}) ->
6180    chk_terminationIds(Tids1,Tids2),
6181    chk_AmmRequest_descriptors(D1,D2),
6182    ok;
6183chk_AmmRequest(R1,R2) ->
6184    wrong_type({'AmmRequest',R1,R2}).
6185
6186chk_AmmRequest_descriptors([],[]) ->
6187    ok;
6188chk_AmmRequest_descriptors(D1,D2)
6189  when is_list(D1) andalso is_list(D2) andalso (length(D1) =:= length(D2)) ->
6190    chk_AmmRequest_descriptors1(D1,D2);
6191chk_AmmRequest_descriptors(D1,D2) ->
6192    wrong_type({ammRequest_descriptors,D1,D2}).
6193
6194chk_AmmRequest_descriptors1([],[]) ->
6195    ok;
6196chk_AmmRequest_descriptors1([D1|Ds1],[D2|Ds2]) ->
6197    chk_AmmRequest_descriptor(D1,D2),
6198    chk_AmmRequest_descriptors1(Ds1,Ds2).
6199
6200chk_AmmRequest_descriptor({mediaDescriptor,D1},{mediaDescriptor,D2}) ->
6201    chk_MediaDescriptor(D1,D2);
6202chk_AmmRequest_descriptor({modemDescriptor,D1},{modemDescriptor,D2}) ->
6203    chk_ModemDescriptor(D1,D2);
6204chk_AmmRequest_descriptor({muxDescriptor,D1},{muxDescriptor,D2}) ->
6205    chk_MuxDescriptor(D1,D2);
6206chk_AmmRequest_descriptor({eventsDescriptor,D1},{eventsDescriptor,D2}) ->
6207    chk_EventsDescriptor(D1,D2);
6208chk_AmmRequest_descriptor({eventBufferDescriptor,D1},{eventBufferDescriptor,D2}) ->
6209    chk_EventBufferDescriptor(D1,D2);
6210chk_AmmRequest_descriptor({signalsDescriptor,D1},{signalsDescriptor,D2}) ->
6211    chk_SignalsDescriptor(D1,D2);
6212chk_AmmRequest_descriptor({digitMapDescriptor,D1},{digitMapDescriptor,D2}) ->
6213    chk_DigitMapDescriptor(D1,D2);
6214chk_AmmRequest_descriptor({auditDescriptor,D1},{auditDescriptor,D2}) ->
6215    chk_AuditDescriptor(D1,D2);
6216chk_AmmRequest_descriptor({Tag1,_D1},{Tag2,_D2}) ->
6217    wrong_type({ammRequest_descriptor_tag,Tag1,Tag2}).
6218
6219
6220chk_SubtractRequest(R,R) when is_record(R,'SubtractRequest') ->
6221    ok;
6222chk_SubtractRequest(#'SubtractRequest'{terminationID   = Tids1,
6223				       auditDescriptor = D1} = R1,
6224		    #'SubtractRequest'{terminationID   = Tids2,
6225				       auditDescriptor = D2} = R2) ->
6226    chk_terminationIds(Tids1, Tids2),
6227    chk_opt_AuditDescriptor(D1, D2),
6228    equal({'SubtractRequest',R1,R2});
6229chk_SubtractRequest(R1,R2) ->
6230    wrong_type({'SubtractRequest',R1,R2}).
6231
6232
6233chk_AuditRequest(R,R) when is_record(R,'AuditRequest') ->
6234    ok;
6235chk_AuditRequest(#'AuditRequest'{terminationID   = Tid1,
6236				 auditDescriptor = D1} = R1,
6237		 #'AuditRequest'{terminationID   = Tid2,
6238				 auditDescriptor = D2} = R2) ->
6239    chk_terminationId(Tid1,Tid2),
6240    chk_AuditDescriptor(D1,D2),
6241    equal({'AuditRequest',R1,R2});
6242chk_AuditRequest(R1,R2) ->
6243    wrong_type({'AuditRequest',R1,R2}).
6244
6245
6246chk_NotifyRequest(R,R) when is_record(R,'NotifyRequest') ->
6247    ok;
6248chk_NotifyRequest(#'NotifyRequest'{terminationID            = Tids1,
6249				   observedEventsDescriptor = ObsDesc1,
6250				   errorDescriptor          = ErrDesc1} = R1,
6251		  #'NotifyRequest'{terminationID            = Tids2,
6252				   observedEventsDescriptor = ObsDesc2,
6253				   errorDescriptor          = ErrDesc2} = R2) ->
6254    chk_terminationIds(Tids1,Tids2),
6255    chk_ObservedEventsDescriptor(ObsDesc1,ObsDesc2),
6256    chk_opt_ErrorDescriptor(ErrDesc1,ErrDesc2),
6257    equal({'NotifyRequest',R1,R2});
6258chk_NotifyRequest(R1,R2) ->
6259    wrong_type({'NotifyRequest',R1,R2}).
6260
6261
6262chk_ServiceChangeRequest(R,R) when is_record(R,'ServiceChangeRequest') ->
6263    ok;
6264chk_ServiceChangeRequest(#'ServiceChangeRequest'{terminationID      = Tids1,
6265						 serviceChangeParms = P1} = R1,
6266			 #'ServiceChangeRequest'{terminationID      = Tids2,
6267						 serviceChangeParms = P2} = R2) ->
6268    chk_terminationIds(Tids1,Tids2),
6269    chk_ServiceChangeParm(P1,P2),
6270    equal({'ServiceChangeRequest',R1,R2});
6271chk_ServiceChangeRequest(R1,R2) ->
6272    wrong_type({'ServiceChangeRequest',R1,R2}).
6273
6274
6275chk_MediaDescriptor(D, D) when is_record(D,'MediaDescriptor') ->
6276    ok;
6277chk_MediaDescriptor(#'MediaDescriptor'{termStateDescr = Tsd1,
6278				       streams        = S1} = D1,
6279		    #'MediaDescriptor'{termStateDescr = Tsd2,
6280				       streams        = S2} = D2) ->
6281%%     io:format("chk_MediaDescriptor -> entry with"
6282%% 	      "~n   Tsd1: ~p"
6283%% 	      "~n   Tsd2: ~p"
6284%% 	      "~n   S1:   ~p"
6285%% 	      "~n   S2:   ~p"
6286%% 	      "~n", [Tsd1, Tsd2, S1, S2]),
6287    chk_MediaDescriptor_tsd(Tsd1, Tsd2),
6288    chk_MediaDescriptor_streams(S1, S2),
6289    equal({'MediaDescriptor',D1,D2});
6290chk_MediaDescriptor(D1,D2) ->
6291    wrong_type({'MediaDescriptor',D1,D2}).
6292
6293chk_MediaDescriptor_tsd(D, D) ->
6294    ok;
6295chk_MediaDescriptor_tsd(D1, D2) ->
6296    not_equal({termStateDescr, D1, D2}).
6297
6298chk_MediaDescriptor_streams({oneStream, S}, {oneStream, S}) ->
6299    ok;
6300chk_MediaDescriptor_streams({oneStream, S1}, {oneStream, S2}) ->
6301    not_equal({oneStream, S1, S2});
6302chk_MediaDescriptor_streams({multiStream, MS}, {multiStream, MS}) ->
6303    ok;
6304chk_MediaDescriptor_streams({multiStream, MS1}, {multiStream, MS2}) ->
6305    chk_StreamDescriptors(MS1, MS2);
6306chk_MediaDescriptor_streams(S1, S2) ->
6307    not_equal({streams, S1, S2}).
6308
6309chk_StreamDescriptors([], []) ->
6310    ok;
6311chk_StreamDescriptors([SD1|MS1], [SD2|MS2]) ->
6312    chk_StreamDescriptor(SD1, SD2),
6313    chk_StreamDescriptors(MS1, MS2).
6314
6315chk_StreamDescriptor(SD, SD) when is_record(SD, 'StreamDescriptor') ->
6316    ok;
6317chk_StreamDescriptor(#'StreamDescriptor'{streamID    = SID1,
6318					 streamParms = SP1} = SD1,
6319		     #'StreamDescriptor'{streamID    = SID2,
6320					 streamParms = SP2} = SD2) ->
6321    SID1 = SID2,
6322    chk_StreamParms(SP1, SP2),
6323    equal({'StreamDescriptor',SD1, SD2});
6324chk_StreamDescriptor(SD1, SD2) ->
6325    wrong_type({'StreamDescriptor',SD1,SD2}).
6326
6327
6328chk_StreamParms(SP, SP) when is_record(SP, 'StreamParms') ->
6329    ok;
6330chk_StreamParms(#'StreamParms'{localControlDescriptor = LCD1,
6331			       localDescriptor        = LD1,
6332			       remoteDescriptor       = RD1} = SP1,
6333		#'StreamParms'{localControlDescriptor = LCD2,
6334			       localDescriptor        = LD2,
6335			       remoteDescriptor       = RD2} = SP2) ->
6336    LCD1 = LCD2,
6337    LD1  = LD2,
6338    RD1  = RD2,
6339    equal({'StreamParms', SP1, SP2});
6340chk_StreamParms(SP1, SP2) ->
6341    wrong_type({'StreamDescriptor', SP1, SP2}).
6342
6343chk_ModemDescriptor(D,D) when is_record(D,'ModemDescriptor') ->
6344    ok;
6345chk_ModemDescriptor(#'ModemDescriptor'{mtl = T1,
6346				       mpl = P1} = D1,
6347		    #'ModemDescriptor'{mtl = T2,
6348				       mpl = P2} = D2) ->
6349    T1 = T2,
6350    P1 = P2,
6351    equal({'ModemDescriptor',D1,D2});
6352chk_ModemDescriptor(D1,D2) ->
6353    wrong_type({'ModemDescriptor',D1,D2}).
6354
6355chk_MuxDescriptor(D,D) when is_record(D,'MuxDescriptor') ->
6356    ok;
6357chk_MuxDescriptor(#'MuxDescriptor'{muxType  = T1,
6358				   termList = I1} = D1,
6359		  #'MuxDescriptor'{muxType  = T2,
6360				   termList = I2} = D2) ->
6361    T1 = T2,
6362    I1 = I2,
6363    equal({'MuxDescriptor',D1,D2});
6364chk_MuxDescriptor(D1,D2) ->
6365    wrong_type({'MuxDescriptor',D1,D2}).
6366
6367chk_EventsDescriptor(D,D) when is_record(D,'EventsDescriptor') ->
6368    ok;
6369chk_EventsDescriptor(#'EventsDescriptor'{requestID = I1,
6370					 eventList = E1} = D1,
6371		     #'EventsDescriptor'{requestID = I2,
6372					 eventList = E2} = D2) ->
6373    I1 = I2,
6374    E1 = E2,
6375    equal({'EventsDescriptor',D1,D2});
6376chk_EventsDescriptor(D1,D2) ->
6377    wrong_type({'EventsDescriptor',D1,D2}).
6378
6379chk_EventBufferDescriptor(D1,D2)
6380  when is_list(D1) andalso is_list(D2) andalso (length(D1) =:= length(D2)) ->
6381    chk_EventBufferDescriptor1(D1,D2);
6382chk_EventBufferDescriptor(D1,D2) ->
6383    wrong_type({eventBufferDescriptor,D1,D2}).
6384
6385chk_EventBufferDescriptor1([],[]) ->
6386    ok;
6387chk_EventBufferDescriptor1([ES1|D1],[ES2|D2]) ->
6388    chk_EventSpec(ES1,ES2),
6389    chk_EventBufferDescriptor1(D1,D2).
6390
6391chk_EventSpec(ES,ES) when is_record(ES,'EventSpec') ->
6392    ok;
6393chk_EventSpec(#'EventSpec'{eventName    = N1,
6394			   streamID     = I1,
6395			   eventParList = P1} = ES1,
6396	      #'EventSpec'{eventName    = N2,
6397			   streamID     = I2,
6398			   eventParList = P2} = ES2) ->
6399    N1 = N2,
6400    chk_opt_StreamId(I1,I2),
6401    chk_EventParameters(P1,P2),
6402    equal({'EventSpec',ES1,ES2});
6403chk_EventSpec(ES1,ES2) ->
6404    wrong_type({'EventSpec',ES1,ES2}).
6405
6406
6407chk_opt_ErrorDescriptor(asn1_NOVALUE,asn1_NOVALUE) ->
6408    ok;
6409chk_opt_ErrorDescriptor(E1,E2) ->
6410    chk_ErrorDescriptor(E1,E2).
6411
6412chk_ErrorDescriptor(E,E) when is_record(E,'ErrorDescriptor') ->
6413    ok;
6414chk_ErrorDescriptor(#'ErrorDescriptor'{errorCode = Code1,
6415				       errorText = Text1} = E1,
6416		    #'ErrorDescriptor'{errorCode = Code2,
6417				       errorText = Text2} = E2) ->
6418    chk_ErrorCode(Code1,Code2),
6419    chk_opt_ErrorText(Text1,Text2),
6420    equal({'ErrorDescriptor',E1,E2});
6421chk_ErrorDescriptor(E1,E2) ->
6422    wrong_type({'ErrorDescriptor',E1,E2}).
6423
6424chk_ErrorCode(C,C) when is_integer(C) ->
6425    ok;
6426chk_ErrorCode(C1,C2) when is_integer(C1) andalso is_integer(C2) ->
6427    not_equal({errorCode,C1,C2});
6428chk_ErrorCode(C1,C2) ->
6429    throw({wrong_type,{errorCode,C1,C2}}).
6430
6431chk_opt_ErrorText(asn1_NOVALUE,asn1_NOVALUE) ->
6432    ok;
6433chk_opt_ErrorText(T,T) when is_list(T) ->
6434    ok;
6435chk_opt_ErrorText(T1,T2) when is_list(T1) andalso is_list(T2) ->
6436    not_equal({errorText,T1,T2});
6437chk_opt_ErrorText(T1,T2) ->
6438    wrong_type({errorText,T1,T2}).
6439
6440
6441chk_SignalsDescriptor(D1,D2)
6442  when is_list(D1) andalso is_list(D2) andalso (length(D1) =:= length(D2)) ->
6443    chk_SignalsDescriptor1(D1,D2);
6444chk_SignalsDescriptor(D1,D2) ->
6445    wrong_type({signalsDescriptor,D1,D2}).
6446
6447chk_SignalsDescriptor1([],[]) ->
6448    ok;
6449chk_SignalsDescriptor1([S1|D1],[S2|D2]) ->
6450    chk_SignalRequest(S1,S2),
6451    chk_SignalsDescriptor1(D1,D2).
6452
6453chk_SignalRequest({signal,S1},{signal,S2}) ->
6454    chk_Signal(S1,S2);
6455chk_SignalRequest({seqSigList,S1},{seqSigList,S2}) ->
6456    chk_SeqSignalList(S1,S2);
6457chk_SignalRequest(R1,R2) ->
6458    wrong_type({signalRequest,R1,R2}).
6459
6460chk_SeqSignalList(S,S) when is_record(S,'SeqSigList') ->
6461    ok;
6462chk_SeqSignalList(#'SeqSigList'{id         = Id1,
6463				signalList = SigList1} = S1,
6464		  #'SeqSigList'{id         = Id2,
6465				signalList = SigList2} = S2) ->
6466    Id1 = Id2,
6467    chk_Signals(SigList1,SigList2),
6468    equal({'SeqSigList',S1,S2});
6469chk_SeqSignalList(S1,S2) ->
6470    wrong_type({'SeqSigList',S1,S2}).
6471
6472
6473chk_Signals([],[]) ->
6474    ok;
6475chk_Signals([Sig1|Sigs1],[Sig2|Sigs2]) ->
6476    chk_Signal(Sig1,Sig2),
6477    chk_Signals(Sigs1,Sigs2).
6478
6479
6480chk_Signal(S,S) when is_record(S,'Signal') ->
6481    ok;
6482chk_Signal(#'Signal'{signalName       = N1,
6483		     streamID         = I1,
6484		     sigType          = T1,
6485		     duration         = D1,
6486		     notifyCompletion = C1,
6487		     keepActive       = K1,
6488		     sigParList       = P1} = S1,
6489	   #'Signal'{signalName       = N2,
6490		     streamID         = I2,
6491		     sigType          = T2,
6492		     duration         = D2,
6493		     notifyCompletion = C2,
6494		     keepActive       = K2,
6495		     sigParList       = P2} = S2) ->
6496    N1 = N2,
6497    chk_opt_StreamId(I1,I2),
6498    chk_opt_SignalType(T1,T2),
6499    chk_opt_duration(D1,D2),
6500    chk_opt_NotifyCompletion(C1,C2),
6501    chk_opt_keepAlive(K1,K2),
6502    chk_sigParameters(P1,P2),
6503    equal({'Signal',S1,S2});
6504chk_Signal(S1,S2) ->
6505    wrong_type({'Signal',S1,S2}).
6506
6507chk_DigitMapDescriptor(D,D) when is_record(D,'DigitMapDescriptor') ->
6508    ok;
6509chk_DigitMapDescriptor(#'DigitMapDescriptor'{digitMapName  = N1,
6510					     digitMapValue = V1},
6511		       #'DigitMapDescriptor'{digitMapName  = N2,
6512					     digitMapValue = V2}) ->
6513    chk_opt_digitMapName(N1,N2),
6514    chk_opt_digitMapValue(V1,V2),
6515    ok;
6516chk_DigitMapDescriptor(D1,D2) ->
6517    wrong_type({'DigitMapDescriptor',D1,D2}).
6518
6519chk_opt_digitMapName(asn1_NOVALUE,asn1_NOVALUE) ->
6520    ok;
6521chk_opt_digitMapName(N1,N2) ->
6522    chk_digitMapName(N1,N2).
6523
6524chk_digitMapName(N,N) ->
6525    ok;
6526chk_digitMapName(N1,N2) ->
6527    not_equal({digitMapName,N1,N2}).
6528
6529chk_opt_digitMapValue(asn1_NOVALUE,asn1_NOVALUE) ->
6530    ok;
6531chk_opt_digitMapValue(V1,V2) ->
6532    chk_digitMapValue(V1,V2).
6533
6534chk_digitMapValue(V,V) when is_record(V,'DigitMapValue') ->
6535    ok;
6536chk_digitMapValue(#'DigitMapValue'{digitMapBody = Body1,
6537				   startTimer   = Start1,
6538				   shortTimer   = Short1,
6539				   longTimer    = Long1},
6540		  #'DigitMapValue'{digitMapBody = Body2,
6541				   startTimer   = Start2,
6542				   shortTimer   = Short2,
6543				   longTimer    = Long2}) ->
6544    chk_digitMapValue_digitMapBody(Body1,Body2), % Could contain trailing '\n', ...
6545    chk_opt_timer(Start1,Start2),
6546    chk_opt_timer(Short1,Short2),
6547    chk_opt_timer(Long1,Long2),
6548    ok;
6549chk_digitMapValue(V1,V2) ->
6550    wrong_type({digitMapValue,V1,V2}).
6551
6552chk_digitMapValue_digitMapBody(B,B) when is_list(B) ->
6553    ok;
6554chk_digitMapValue_digitMapBody(B1, B2)
6555  when is_list(B1) andalso is_list(B2) andalso (length(B1) > length(B2))  ->
6556    case string:str(B2, B1) of
6557	0 ->
6558	    ok;
6559	_ ->
6560	    not_equal({digitMapValue_digitMapBody,B1,B2})
6561    end;
6562chk_digitMapValue_digitMapBody(B1, B2)
6563  when is_list(B1) andalso is_list(B2) andalso (length(B1) < length(B2))  ->
6564    case string:str(B1, B2) of
6565	0 ->
6566	    ok;
6567	_ ->
6568	    not_equal({digitMapValue_digitMapBody,B1,B2})
6569    end;
6570chk_digitMapValue_digitMapBody(B1,B2) when is_list(B1) andalso is_list(B2) ->
6571    not_equal({digitMapValue_digitMapBody,B1,B2});
6572chk_digitMapValue_digitMapBody(B1,B2) ->
6573    wrong_type({digitMapValue_digitMapBody,B1,B2}).
6574
6575
6576chk_opt_AuditDescriptor(asn1_NOVALUE,asn1_NOVALUE) ->
6577    ok;
6578chk_opt_AuditDescriptor(D1,D2) ->
6579    chk_AuditDescriptor(D1,D2).
6580
6581chk_AuditDescriptor(D,D) when is_record(D,'AuditDescriptor') ->
6582    ok;
6583chk_AuditDescriptor(#'AuditDescriptor'{auditToken = T1} = D1,
6584		    #'AuditDescriptor'{auditToken = T2} = D2) ->
6585    chk_opt_auditToken(T1,T2),
6586    equal({'AuditDescriptor',D1,D2});
6587chk_AuditDescriptor(D1,D2) ->
6588    wrong_type({'AuditDescriptor',D1,D2}).
6589
6590chk_opt_auditToken(asn1_NOVALUE,asn1_NOVALUE) ->
6591    ok;
6592chk_opt_auditToken(T1,T2) ->
6593    chk_auditToken(T1,T2).
6594
6595chk_auditToken(T1,T2)
6596  when is_list(T1) andalso is_list(T2) andalso (length(T1) =:= length(T2)) ->
6597    chk_auditToken1(T1,T2);
6598chk_auditToken(T1,T2) ->
6599    wrong_type({auditToken,T1,T2}).
6600
6601chk_auditToken1([],[]) ->
6602    ok;
6603chk_auditToken1([H1|T1],[H2|T2]) ->
6604    chk_auditToken2(H1,H2),
6605    chk_auditToken1(T1,T2).
6606
6607chk_auditToken2(muxToken,muxToken) ->
6608    ok;
6609chk_auditToken2(modemToken,modemToken) ->
6610    ok;
6611chk_auditToken2(mediaToken,mediaToken) ->
6612    ok;
6613chk_auditToken2(eventsToken,eventsToken) ->
6614    ok;
6615chk_auditToken2(signalsToken,signalsToken) ->
6616    ok;
6617chk_auditToken2(digitMapToken,digitMapToken) ->
6618    ok;
6619chk_auditToken2(statsToken,statsToken) ->
6620    ok;
6621chk_auditToken2(observedEventsToken,observedEventsToken) ->
6622    ok;
6623chk_auditToken2(packagesToken,packagesToken) ->
6624    ok;
6625chk_auditToken2(eventBufferToken,eventBufferToken) ->
6626    ok;
6627chk_auditToken2(T1,T2) when is_atom(T1) andalso is_atom(T2) ->
6628    not_equal({auditToken,T1,T2});
6629chk_auditToken2(T1,T2) ->
6630    wrong_type({auditToken,T1,T2}).
6631
6632chk_ObservedEventsDescriptor(D,D)
6633  when is_record(D,'ObservedEventsDescriptor') ->
6634    ok;
6635chk_ObservedEventsDescriptor(
6636  #'ObservedEventsDescriptor'{requestId        = Id1,
6637			      observedEventLst = E1} = D1,
6638  #'ObservedEventsDescriptor'{requestId        = Id2,
6639			      observedEventLst = E2} = D2) ->
6640    Id1 = Id2,
6641    chk_ObservedEvents(E1,E2),
6642    equal({'ObservedEventsDescriptor',D1,D2});
6643chk_ObservedEventsDescriptor(D1,D2) ->
6644    wrong_type({'ObservedEventsDescriptor',D1,D2}).
6645
6646
6647chk_ObservedEvents(E1,E2)
6648  when is_list(E1) andalso is_list(E2) andalso (length(E1) =:= length(E2)) ->
6649    chk_ObservedEvents1(E1,E2);
6650chk_ObservedEvents(E1,E2) ->
6651    wrong_type({observedEvents,E1,E2}).
6652
6653
6654chk_ObservedEvents1([],[]) ->
6655    ok;
6656chk_ObservedEvents1([Ev1|Evs1],[Ev2|Evs2]) ->
6657    chk_ObservedEvent(Ev1,Ev2),
6658    chk_ObservedEvents1(Evs1,Evs2).
6659
6660chk_ObservedEvent(#'ObservedEvent'{eventName    = N1,
6661				   streamID     = I1,
6662				   eventParList = P1,
6663				   timeNotation = T1} = E1,
6664		  #'ObservedEvent'{eventName    = N2,
6665				   streamID     = I2,
6666				   eventParList = P2,
6667				   timeNotation = T2} = E2) ->
6668    N1 = N2,
6669    chk_opt_StreamId(I1,I2),
6670    chk_EventParameters(P1,P2),
6671    chk_opt_TimeNotation(T1,T2),
6672    equal({'ObservedEvent',E1,E2});
6673chk_ObservedEvent(E1,E2) ->
6674    wrong_type({'ObservedEvent',E1,E2}).
6675
6676
6677chk_opt_TimeNotation(asn1_NOVALUE,asn1_NOVALUE) ->
6678    ok;
6679chk_opt_TimeNotation(T1,T2) ->
6680    chk_TimeNotation(T1,T2).
6681
6682chk_TimeNotation(T,T) when is_record(T,'TimeNotation') ->
6683    ok;
6684chk_TimeNotation(#'TimeNotation'{date = Date1,
6685				 time = Time1} = T1,
6686		 #'TimeNotation'{date = Date2,
6687				 time = Time2} = T2) ->
6688    Date1 = Date2,
6689    Time1 = Time2,
6690    equal({'TimeNotation',T1,T2});
6691chk_TimeNotation(T1,T2) ->
6692    wrong_type({'TimeNotation',T1,T2}).
6693
6694
6695chk_opt_timer(asn1_NOVALUE,asn1_NOVALUE) ->
6696    ok;
6697chk_opt_timer(T1,T2) ->
6698    chk_timer(T1,T2).
6699
6700chk_timer(T,T) when is_integer(T) ->
6701    {equal,timer};
6702chk_timer(T1,T2) when is_integer(T1) andalso is_integer(T2) ->
6703    throw({not_equal,{timer,T1,T2}});
6704chk_timer(T1,T2) ->
6705    throw({wrong_type,{timer,T1,T2}}).
6706
6707
6708chk_opt_SignalType(asn1_NOVALUE,asn1_NOVALUE) ->
6709    {equal,signalType};
6710chk_opt_SignalType(T1,T2) ->
6711    chk_SignalType(T1,T2).
6712
6713chk_SignalType(brief,brief) ->
6714    {equal,signalType};
6715chk_SignalType(onOffonOff,onOffonOff) ->
6716    {equal,signalType};
6717chk_SignalType(timeOut,timeOut) ->
6718    {equal,signalType};
6719chk_SignalType(T1,T2) ->
6720    throw({wrong_type,{signalType,T1,T2}}).
6721
6722
6723chk_opt_duration(asn1_NOVALUE,asn1_NOVALUE) ->
6724    {equal,duration};
6725chk_opt_duration(D1,D2) ->
6726    chk_duration(D1,D2).
6727
6728chk_duration(D,D) when is_integer(D) ->
6729    {equal,duration};
6730chk_duration(D1,D2) when is_integer(D1) andalso is_integer(D2) ->
6731    throw({not_equal,{duration,D1,D2}});
6732chk_duration(D1,D2) ->
6733    throw({wrong_type,{duration,D1,D2}}).
6734
6735
6736chk_opt_NotifyCompletion(asn1_NOVALUE,asn1_NOVALUE) ->
6737    {equal,notifyCompletion};
6738chk_opt_NotifyCompletion(N1,N2) ->
6739    chk_NotifyCompletion(N1,N2).
6740
6741chk_NotifyCompletion([],[]) ->
6742    {equal,notifyCompletion};
6743chk_NotifyCompletion([Item1|Items1],[Item2|Items2]) ->
6744    chk_NotifyCompletion1(Item1,Item2),
6745    chk_NotifyCompletion(Items1,Items2);
6746chk_NotifyCompletion(C1,C2) ->
6747    throw({wrong_type,{notifyCompletion,C1,C2}}).
6748
6749chk_NotifyCompletion1(onTimeOut,onTimeOut) ->
6750    {equal,notifyCompletion_part};
6751chk_NotifyCompletion1(onInterruptByEvent,onInterruptByEvent) ->
6752    {equal,notifyCompletion_part};
6753chk_NotifyCompletion1(onInterruptByNewSignalDescr,onInterruptByNewSignalDescr) ->
6754    {equal,notifyCompletion_part};
6755chk_NotifyCompletion1(otherReason,otherReason) ->
6756    {equal,notifyCompletion_part};
6757chk_NotifyCompletion1(C1,C2) ->
6758    throw({wrong_type,{notifyCompletion_part,C1,C2}}).
6759
6760
6761chk_opt_keepAlive(asn1_NOVALUE,asn1_NOVALUE) ->
6762    {equal,keepAlive};
6763chk_opt_keepAlive(K1,K2) ->
6764    chk_keepAlive(K1,K2).
6765
6766chk_keepAlive(true,true) ->
6767    ok;
6768chk_keepAlive(false,false) ->
6769    ok;
6770chk_keepAlive(K1,K2) ->
6771    wrong_type({keepAlive,K1,K2}).
6772
6773
6774chk_ServiceChangeParm(P,P) when  is_record(P,'ServiceChangeParm') ->
6775    ok;
6776chk_ServiceChangeParm(#'ServiceChangeParm'{serviceChangeMethod  = M1,
6777					   serviceChangeAddress = A1,
6778					   serviceChangeVersion = V1,
6779					   serviceChangeProfile = P1,
6780					   serviceChangeReason  = R1,
6781					   serviceChangeDelay   = D1,
6782					   serviceChangeMgcId   = Mid1,
6783					   timeStamp            = T1} = P1,
6784		      #'ServiceChangeParm'{serviceChangeMethod  = M2,
6785					   serviceChangeAddress = A2,
6786					   serviceChangeVersion = V2,
6787					   serviceChangeProfile = P2,
6788					   serviceChangeReason  = R2,
6789					   serviceChangeDelay   = D2,
6790					   serviceChangeMgcId   = Mid2,
6791					   timeStamp            = T2} = P2) ->
6792    M1 = M2,
6793    A1 = A2,
6794    V1 = V2,
6795    P1 = P2,
6796    R1 = R2,
6797    D1 = D2,
6798    Mid1 = Mid2,
6799    T1 = T2,
6800    equal({'ServiceChangeParm',P1,P2});
6801chk_ServiceChangeParm(P1,P2) ->
6802    wrong_type({'ServiceChangeParm',P1,P2}).
6803
6804
6805chk_sigParameters(S1,S2)
6806  when is_list(S1) andalso is_list(S2) andalso (length(S1) =:= length(S2)) ->
6807    chk_sigParameters1(S1,S2);
6808chk_sigParameters(S1,S2) ->
6809    wrong_type({sigParameters,S1,S2}).
6810
6811chk_sigParameters1([],[]) ->
6812    ok;
6813chk_sigParameters1([H1|T1],[H2|T2]) ->
6814    chk_sigParameter(H1,H2),
6815    chk_sigParameters1(T1,T2);
6816chk_sigParameters1(P1,P2) ->
6817    wrong_type({sigParameters,P1,P2}).
6818
6819chk_sigParameter(#'SigParameter'{sigParameterName = N1,
6820				 value            = V1,
6821				 extraInfo        = E1},
6822		 #'SigParameter'{sigParameterName = N2,
6823				 value            = V2,
6824				 extraInfo        = E2}) ->
6825    N1 = N2,
6826    chk_Value(V1,V2),
6827    chk_opt_extraInfo(E1,E2),
6828    ok;
6829chk_sigParameter(P1,P2) ->
6830    wrong_type({'SigParameter',P1,P2}).
6831
6832
6833chk_opt_StreamId(asn1_NOVALUE,asn1_NOVALUE) ->
6834    ok;
6835chk_opt_StreamId(I1,I2) ->
6836    chk_StreamId(I1,I2).
6837
6838chk_StreamId(I,I) when is_integer(I) ->
6839    ok;
6840chk_StreamId(I1,I2) when is_integer(I1) andalso is_integer(I2) ->
6841    not_equal({streamId,I1,I2});
6842chk_StreamId(I1,I2) ->
6843    wrong_type({streamId,I1,I2}).
6844
6845
6846chk_EventParameters(EP1,EP2)
6847  when is_list(EP1) andalso is_list(EP2) andalso (length(EP1) =:= length(EP2)) ->
6848    chk_EventParameters1(EP1,EP2);
6849chk_EventParameters(EP1,EP2) ->
6850    wrong_type({eventParameters,EP1,EP2}).
6851
6852chk_EventParameters1([],[]) ->
6853    ok;
6854chk_EventParameters1([EP1|EPS1],[EP2|EPS2]) ->
6855    chk_EventParameter(EP1,EP2),
6856    chk_EventParameters1(EPS1,EPS2).
6857
6858chk_EventParameter(EP,EP) when is_record(EP,'EventParameter') ->
6859    ok;
6860chk_EventParameter(#'EventParameter'{eventParameterName = N1,
6861				     value              = V1,
6862				     extraInfo          = E1} = EP1,
6863		   #'EventParameter'{eventParameterName = N2,
6864				     value              = V2,
6865				     extraInfo          = E2} = EP2) ->
6866    N1 = N2,
6867    chk_Value(V1,V2),
6868    chk_opt_extraInfo(E1,E2),
6869    equal({'EventParameter',EP1,EP2});
6870chk_EventParameter(EP1,EP2) ->
6871    wrong_type({'EventParameter',EP1,EP2}).
6872
6873
6874chk_Value(V,V) when is_list(V) ->
6875    chk_Value(V);
6876chk_Value(V1,V2)
6877  when is_list(V1) andalso is_list(V2) andalso (length(V1) =:= length(V2)) ->
6878    chk_Value1(V1,V2);
6879chk_Value(V1,V2) ->
6880    wrong_type({value,V1,V2}).
6881
6882chk_Value([]) ->
6883    ok;
6884chk_Value([H|T]) when is_list(H) ->
6885    chk_Value(T);
6886chk_Value([H|_T]) ->
6887    wrong_type({value_part,H}).
6888
6889chk_Value1([],[]) ->
6890    ok;
6891chk_Value1([H|T1],[H|T2]) when is_list(H) ->
6892    chk_Value1(T1,T2);
6893chk_Value1([H|_T1],[H|_T2]) ->
6894    wrong_type({value_part,H});
6895chk_Value1([H1|_T1],[H2|_T2]) when is_list(H1) andalso is_list(H2) ->
6896    not_equal({value_part,H1,H2});
6897chk_Value1(V1,V2) ->
6898    wrong_type({value,V1,V2}).
6899
6900
6901chk_opt_extraInfo(asn1_NOVALUE,asn1_NOVALUE) ->
6902    ok;
6903chk_opt_extraInfo(E1,E2) ->
6904    chk_extraInfo(E1,E2).
6905
6906chk_extraInfo({relation,greaterThan},{relation,greaterThan}) ->
6907    ok;
6908chk_extraInfo({relation,smallerThan},{relation,smallerThan}) ->
6909    ok;
6910chk_extraInfo({relation,unequalTo},{relation,unequalTo}) ->
6911    ok;
6912chk_extraInfo({range,true},{range,true}) ->
6913    ok;
6914chk_extraInfo({range,false},{range,false}) ->
6915    ok;
6916chk_extraInfo({sublist,true},{sublist,true}) ->
6917    ok;
6918chk_extraInfo({sublist,false},{sublist,false}) ->
6919    ok;
6920chk_extraInfo(E1,E2) ->
6921    wrong_type({extraInfo,E1,E2}).
6922
6923
6924chk_opt_transactionId(asn1_NOVALUE,asn1_NOVALUE) ->
6925    ok;
6926chk_opt_transactionId(Id1,Id2) ->
6927    chk_transactionId(Id1,Id2).
6928
6929chk_transactionId(Id,Id) when is_integer(Id) ->
6930    ok;
6931chk_transactionId(Id1,Id2) when is_integer(Id1) andalso is_integer(Id2) ->
6932    not_equal({transactionId,Id1,Id2});
6933chk_transactionId(Id1,Id2) ->
6934    wrong_type({transactionId,Id1,Id2}).
6935
6936
6937chk_terminationIds(Tids1,Tids2)
6938  when is_list(Tids1) andalso is_list(Tids2) andalso (length(Tids1) =:= length(Tids2)) ->
6939    chk_terminationIds1(Tids1,Tids2);
6940chk_terminationIds(Tids1,Tids2) ->
6941    wrong_type({terminationIds,Tids1,Tids2}).
6942
6943chk_terminationIds1([],[]) ->
6944    ok;
6945chk_terminationIds1([Tid1|Tids1],[Tid2|Tids2]) ->
6946    chk_terminationId(Tid1,Tid2),
6947    chk_terminationIds1(Tids1,Tids2).
6948
6949chk_terminationId(Id,Id) when is_record(Id,'TerminationID') ->
6950    ok;
6951chk_terminationId(Id,Id) when is_record(Id,megaco_term_id) ->
6952    ok;
6953chk_terminationId(#'TerminationID'{wildcard = W1,
6954				   id       = I1} = Tid1,
6955		  #'TerminationID'{wildcard = W2,
6956				   id       = I2} = Tid2) ->
6957    chk_terminationId_wildcard(W1,W2),
6958    chk_terminationId_id(I1,I2),
6959    equal({'TerminationID',Tid1,Tid2});
6960chk_terminationId(#megaco_term_id{contains_wildcards = W1,
6961				  id                 = I1} = Tid1,
6962		  #megaco_term_id{contains_wildcards = W2,
6963				  id                 = I2} = Tid2) ->
6964    chk_terminationId_wildcard(W1,W2),
6965    chk_terminationId_id(I1,I2),
6966    equal({megaco_term_id,Tid1,Tid2});
6967chk_terminationId(Tid1,Tid2) ->
6968    wrong_type({terminationId,Tid1,Tid2}).
6969
6970chk_terminationId_wildcard(W,W) ->
6971    ok;
6972chk_terminationId_wildcard(W1,W2) ->
6973    not_equal({terminationId_wildcard,W1,W2}).
6974
6975chk_terminationId_id(I,I) ->
6976    ok;
6977chk_terminationId_id(I1,I2) ->
6978    not_equal({terminationId_id,I1,I2}).
6979
6980
6981equal(What) ->
6982    error({equal, What}).
6983
6984not_equal(What) ->
6985    error({not_equal, What}).
6986
6987wrong_type(What) ->
6988    error({wrong_type, What}).
6989
6990error(Reason) ->
6991    throw({error, Reason}).
6992
6993
6994%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6995
6996cre_MegacoMessage(Mess) ->
6997    ?MSG_LIB:cre_MegacoMessage(Mess).
6998
6999cre_megacoMessage(V, Mid, Body) ->
7000    #'MegacoMessage'{mess = #'Message'{version     = V,
7001                                       mId         = Mid,
7002                                       messageBody = Body}}.
7003
7004cre_Msg(Mid, Body) ->
7005    cre_Msg(?VERSION, Mid, Body).
7006
7007cre_Msg(V, Mid, Body) ->
7008    ?MSG_LIB:cre_Message(V, Mid, Body).
7009
7010cre_authHeader() ->
7011    SecParmIdx = [239, 205, 171, 137],
7012    SeqNum     = [18, 52, 86, 120],
7013    AD         = [18, 52, 86, 120, 137, 171, 205, 239, 118, 84, 50, 16],
7014    cre_authHeader(SecParmIdx, SeqNum, AD).
7015
7016cre_authHeader(Idx, Num, D) ->
7017    #'AuthenticationHeader'{secParmIndex = Idx,
7018			    seqNum       = Num,
7019			    ad           = D}.
7020
7021cre_TransId(TransId) ->
7022    ?MSG_LIB:cre_TransactionId(TransId).
7023
7024cre_Trans(Trans) ->
7025    ?MSG_LIB:cre_Transaction(Trans).
7026
7027cre_TransReq(TransId, Actions) ->
7028    ?MSG_LIB:cre_TransactionRequest(TransId, Actions).
7029
7030cre_transactionReply(TransId, Actions) ->
7031    #'TransactionReply'{transactionId     = TransId,
7032			transactionResult = {actionReplies, Actions}}.
7033
7034cre_transactionAck(Serial, Serial) ->
7035    #'TransactionAck'{firstAck = Serial};
7036cre_transactionAck(First, Last) ->
7037    #'TransactionAck'{firstAck = First, lastAck = Last}.
7038
7039cre_ActReq(CtxId, CmdReqs) ->
7040    ?MSG_LIB:cre_ActionRequest(CtxId, CmdReqs).
7041
7042cre_actionReply(CtxId, CmdReply) ->
7043    #'ActionReply'{contextId    = CtxId,
7044		   commandReply = CmdReply}.
7045
7046cre_CtxID(Id) ->
7047    ?MSG_LIB:cre_ContextID(Id).
7048
7049%% Parameter related
7050cre_propertyParm(Name, Val) ->
7051    #'PropertyParm'{name  = Name, value = [Val]}.
7052
7053
7054%% Statistics related
7055cre_statisticsParm(Name, Val) ->
7056    #'StatisticsParameter'{statName  = Name, statValue = [Val]}.
7057
7058
7059% Event related
7060cre_eventParm(Name, Val) ->
7061    #'EventParameter'{eventParameterName = Name, value = Val}.
7062
7063cre_observedEvent(Name, Not) ->
7064    #'ObservedEvent'{eventName = Name, timeNotation = Not}.
7065cre_observedEvent(Name, Not, Par) ->
7066    #'ObservedEvent'{eventName = Name, timeNotation = Not, eventParList = Par}.
7067
7068cre_requestedEvent(Name) ->
7069    #'RequestedEvent'{pkgdName = Name}.
7070cre_requestedEvent(Name, ParList) when is_list(ParList) ->
7071    #'RequestedEvent'{pkgdName = Name, evParList = ParList};
7072cre_requestedEvent(Name, Action) when is_tuple(Action) ->
7073    #'RequestedEvent'{pkgdName = Name, eventAction = Action}.
7074
7075
7076cre_observedEventsDesc(Id, EvList) ->
7077    #'ObservedEventsDescriptor'{requestId = Id, observedEventLst = EvList}.
7078
7079cre_eventsDesc(Id, EvList) ->
7080    #'EventsDescriptor'{requestID = Id, eventList = EvList}.
7081
7082
7083%% Service change related
7084cre_serviceChangeParm(M,A,R,P) ->
7085    #'ServiceChangeParm'{serviceChangeMethod  = M, serviceChangeAddress = A,
7086			 serviceChangeReason  = R, serviceChangeProfile = P}.
7087
7088cre_serviceChangeResParm(A,P) ->
7089    #'ServiceChangeResParm'{serviceChangeAddress = A,
7090			    serviceChangeProfile = P}.
7091
7092cre_serviceChangeReq(Tid, P) ->
7093    #'ServiceChangeRequest'{terminationID = Tid, serviceChangeParms = P}.
7094
7095cre_serviceChangeProf(Name, Ver) when is_list(Name) andalso is_integer(Ver) ->
7096    #'ServiceChangeProfile'{profileName = Name, version = Ver}.
7097
7098cre_serviceChangeReply(Tid, Res) ->
7099    #'ServiceChangeReply'{terminationID = Tid, serviceChangeResult = Res}.
7100
7101
7102%% Stream related
7103cre_streamParms(Lcd) ->
7104    #'StreamParms'{localControlDescriptor = Lcd}.
7105cre_streamParms(Lcd, Ld) ->
7106    #'StreamParms'{localControlDescriptor = Lcd, localDescriptor = Ld}.
7107cre_streamParms(Lcd, Ld, Rd) ->
7108    #'StreamParms'{localControlDescriptor = Lcd,
7109		   localDescriptor        = Ld,
7110		   remoteDescriptor       = Rd}.
7111cre_streamParmsL(Ld) ->
7112    #'StreamParms'{localDescriptor = Ld}.
7113cre_streamParmsR(Rd) ->
7114    #'StreamParms'{remoteDescriptor = Rd}.
7115
7116cre_streamDesc(Id, P) ->
7117    #'StreamDescriptor'{streamID = Id, streamParms = P}.
7118
7119
7120%% "Local" related
7121cre_localControlDesc(Mode) ->
7122    #'LocalControlDescriptor'{streamMode = Mode}.
7123cre_localControlDesc(Mode, Parms) ->
7124    #'LocalControlDescriptor'{streamMode = Mode, propertyParms = Parms }.
7125
7126cre_localRemoteDesc(Grps) ->
7127    #'LocalRemoteDescriptor'{propGrps = Grps}.
7128
7129
7130%% DigitMap related
7131cre_digitMapDesc(Value) when is_record(Value, 'DigitMapValue') ->
7132    #'DigitMapDescriptor'{digitMapValue = Value};
7133cre_digitMapDesc(Name) ->
7134    #'DigitMapDescriptor'{digitMapName = Name}.
7135
7136cre_digitMapDesc(Name, Val) ->
7137    #'DigitMapDescriptor'{digitMapName = Name, digitMapValue = Val}.
7138
7139cre_digitMapValue(Body) ->
7140    #'DigitMapValue'{digitMapBody = Body}.
7141
7142cre_digitMapValue(Body, Start, Short, Long) ->
7143    #'DigitMapValue'{startTimer   = Start,
7144		     shortTimer   = Short,
7145		     longTimer    = Long,
7146		     digitMapBody = Body}.
7147
7148%% Media related
7149cre_mediaDesc(StreamDesc) ->
7150    #'MediaDescriptor'{streams = {multiStream, [StreamDesc]}}.
7151
7152
7153%% Notify related
7154cre_notifyReq(Tid, EvsDesc) ->
7155    #'NotifyRequest'{terminationID = Tid, observedEventsDescriptor = EvsDesc}.
7156
7157cre_notifyReply(Tid) ->
7158    #'NotifyReply'{terminationID = Tid}.
7159
7160
7161%% Subtract related
7162cre_subtractReq(Tid, Desc) ->
7163    #'SubtractRequest'{terminationID = Tid, auditDescriptor = Desc}.
7164
7165
7166%% Audit related
7167cre_auditDesc(Tokens) ->
7168    #'AuditDescriptor'{auditToken = Tokens}.
7169
7170cre_auditReq(Tid, Desc) ->
7171    #'AuditRequest'{terminationID   = Tid, auditDescriptor = Desc}.
7172
7173cre_auditRes(Tid, Res) ->
7174    #'AuditResult'{terminationID = Tid, terminationAuditResult = Res}.
7175
7176
7177%% AMM/AMMS related
7178cre_ammReq(Tid, Descs) ->
7179    #'AmmRequest'{terminationID = Tid, descriptors = Descs}.
7180
7181cre_ammsReply(Tid) ->
7182    #'AmmsReply'{terminationID = Tid}.
7183cre_ammsReply(Tid, Descs) ->
7184    #'AmmsReply'{terminationID = Tid, terminationAudit = Descs}.
7185
7186
7187%% Command related
7188cre_commandReq(Cmd) ->
7189    #'CommandRequest'{command = Cmd}.
7190
7191
7192%% Actions related
7193cre_requestedActions(DmName) ->
7194    #'RequestedActions'{eventDM = {digitMapName, DmName}}.
7195
7196
7197%% Signal related
7198cre_signal(Name) ->
7199    #'Signal'{signalName = Name}.
7200
7201
7202%% Others
7203cre_timeNotation(D,T) ->
7204    #'TimeNotation'{date = D, time = T}.
7205
7206cre_packagesItem(_Name, _Ver) ->
7207    #'PackagesItem'{packageName = "nt", packageVersion = 1}.
7208
7209
7210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7211
7212flex_init(Config) ->
7213    megaco_codec_flex_lib:init(Config).
7214
7215flex_finish(Config) ->
7216    megaco_codec_flex_lib:finish(Config).
7217
7218flex_scanner_conf(Config) ->
7219    megaco_codec_flex_lib:scanner_conf(Config).
7220
7221start_flex_scanner() ->
7222    megaco_codec_flex_lib:start().
7223
7224stop_flex_scanner(Pid) ->
7225    megaco_codec_flex_lib:stop(Pid).
7226
7227
7228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7229
7230t(F,A) ->
7231    p(printable(get(severity),trc),trc,F,A).
7232
7233d(F,A) ->
7234    p(printable(get(severity),dbg),dbg,F,A).
7235
7236l(F,A) ->
7237    p(printable(get(severity),log),log,F,A).
7238
7239e(F,A) ->
7240    p(printable(get(severity),err),err,F,A).
7241
7242
7243printable(trc,_) ->
7244    true;
7245printable(dbg,trc) ->
7246    false;
7247printable(dbg,_) ->
7248    true;
7249printable(log,log) ->
7250    true;
7251printable(log,err) ->
7252    true;
7253printable(err,err) ->
7254    true;
7255printable(_,_) ->
7256    false.
7257
7258
7259image_of(trc) ->
7260    "T";
7261image_of(dbg) ->
7262    "D";
7263image_of(log) ->
7264    "L";
7265image_of(err) ->
7266    "E";
7267image_of(L) ->
7268    io_lib:format("~p",[L]).
7269
7270
7271p(true,L,F,A) ->
7272    io:format("~s: " ++ F ++ "~n", [image_of(L)|A]);
7273p(_,_,_,_) ->
7274    ok.
7275
7276p(F, A) ->
7277    io:format("*** [~s] ***"
7278	      "~n   " ++ F ++ "~n",
7279	      [?FTS() | A]).
7280
7281
7282