⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 megaco_codec_prev3a_test.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 5 页
字号:
    TMRs = lists:flatten(io_lib:format("T:~s,S:~s,L:~s,Z:~s", [T, S, L,Z])),    build_dm_timers_message(TMRs).build_dm_timers_message(TMRs) ->    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{~s,(0s| 00s|[1-7]xlxx|8lxxxxxxx|#xxxxxxx|*xx|9l1xxxxxxxxxx|9l011x.s)}}}}", [TMRs]),    lists:flatten(M).verify_dm_timers(TMRs, #'MegacoMessage'{mess = Mess}) ->    #'Message'{messageBody = Body} = Mess,    case get_dm_timers(Body) of	TMRs ->	    ok;	{error, Reason} ->	    exit({invalid_timer, {TMRs, Reason}});	TMRs1 ->	    exit({invalid_timer_values, {TMRs, TMRs1}})    end.get_dm_timers({transactions, T}) when list(T) ->    get_dm_timers1(T);get_dm_timers(Other) ->    {error, {invalid_transactions, Other}}.get_dm_timers1([{transactionRequest,T}|Ts])   when record(T,'TransactionRequest') ->    case get_dm_timers2(T) of	{ok, Timers} ->	    Timers;	_ ->	    get_dm_timers1(Ts)    end;get_dm_timers1([_|Ts]) ->    get_dm_timers1(Ts);get_dm_timers1([]) ->    {error, {no_timers, 'TransactionRequest'}}.get_dm_timers2(#'TransactionRequest'{actions = Actions}) when list(Actions) ->    get_dm_timers3(Actions).get_dm_timers3([#'ActionRequest'{commandRequests = Cmds}|Ars]) when list(Cmds) ->    case get_dm_timers4(Cmds) of	{ok, Timers} ->	    {ok, Timers};	_ ->	    get_dm_timers3(Ars)    end;get_dm_timers3([_|Ars]) ->    get_dm_timers3(Ars);get_dm_timers3([]) ->    {error, {no_timers, 'ActionRequest'}}.get_dm_timers4([#'CommandRequest'{command = Cmd}|Cmds]) ->    case get_dm_timers5(Cmd) of	{ok, Timers} ->	    {ok, Timers};	_ ->	    get_dm_timers4(Cmds)    end;get_dm_timers4([_|Cmds]) ->    get_dm_timers4(Cmds);get_dm_timers4([]) ->    {error, {no_timers, 'CommandRequest'}}.get_dm_timers5({modReq, #'AmmRequest'{descriptors = Descriptors}}) ->    get_dm_timers6(Descriptors);get_dm_timers5(R) ->    {error, {no_modReq, R}}.get_dm_timers6([{digitMapDescriptor, #'DigitMapDescriptor'{digitMapValue = Val}}|_]) ->    case Val of	#'DigitMapValue'{startTimer    = T,			 shortTimer    = S,			 longTimer     = L,			 durationTimer = asn1_NOVALUE} ->	    {ok, {T, S, L}};	#'DigitMapValue'{startTimer    = T,			 shortTimer    = S,			 longTimer     = L,			 durationTimer = Z} ->	    {ok, {T, S, L, Z}};	_ ->	    {error, no_value_in_dm}    end;get_dm_timers6([_|Descs]) ->    get_dm_timers6(Descs);get_dm_timers6([]) ->    {error, {no_timers, descriptors}}.%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%bin_test_msgs(suite) ->    [];bin_test_msgs(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    Msgs = msgs1(binary) ++ msgs4(binary) ++ msgs5(binary) ++ msgs6(binary),    %% Msgs = msgs5(binary),     DynamicDecode = false,    test_msgs(megaco_binary_encoder, DynamicDecode, ?EC, Msgs).   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ber_test_msgs(suite) ->    [];ber_test_msgs(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    Msgs = msgs1(binary) ++ msgs4(binary) ++ msgs5(binary) ++ msgs6(binary),    %% Msgs = msgs6(binary),    DynamicDecode = false,    test_msgs(megaco_ber_encoder, DynamicDecode, ?EC, Msgs).   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ber_bin_test_msgs(suite) ->    [];ber_bin_test_msgs(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    Msgs = msgs1(binary) ++ msgs4(binary) ++ msgs5(binary) ++ msgs6(binary),    DynamicDecode = true,    test_msgs(megaco_ber_bin_encoder, DynamicDecode, ?EC, Msgs).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%per_test_msgs(suite) ->    [];per_test_msgs(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    Msgs = msgs1(binary) ++ msgs4(binary) ++ msgs5(binary) ++ msgs6(binary),    DynamicDecode = false,    test_msgs(megaco_per_encoder, DynamicDecode, ?EC, Msgs).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%per_bin_test_msgs(suite) ->    [];per_bin_test_msgs(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    Msgs = msgs1(binary) ++ msgs4(binary) ++ msgs5(binary) ++ msgs6(binary),    DynamicDecode = false,    test_msgs(megaco_per_bin_encoder, DynamicDecode, ?EC, Msgs).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%erl_dist_m_test_msgs(suite) ->    [];erl_dist_m_test_msgs(Config) when list(Config) ->    ?ACQUIRE_NODES(1, Config),    Msgs = msgs1(erlang) ++ 	msgs2(erlang) ++ 	msgs3(erlang) ++ 	msgs4(erlang) ++ 	msgs5(erlang) ++ 	msgs6(erlang),    DynamicDecode = false,    Conf = [megaco_compressed],     test_msgs(megaco_erl_dist_encoder, DynamicDecode, Conf, Msgs).%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #%% Ticket test cases:%% --------------------------------------------------------------%% Observe that this decode SHALL failcompact_otp4011_msg1(suite) ->    [];compact_otp4011_msg1(Config) when list(Config) ->%     put(severity,trc),%     put(dbg,true),    d("compact_otp4011_msg1 -> entry", []),    ?ACQUIRE_NODES(1, Config),    M = "!/" ?VERSION_STR " ML T=233350{C=${A=stedevice/01{M{O{MO=SR,RV=OFF,RG=OFF,tdmc/ec=OFF,MO=SR}}}}}",    ok = compact_otp4011(M),%     erase(severity),%     erase(dbg),    ok.%% --------------------------------------------------------------%% Observe that this decode SHALL failcompact_otp4011_msg2(suite) ->    [];compact_otp4011_msg2(Config) when list(Config) ->    d("compact_otp4011_msg2 -> entry", []),    ?ACQUIRE_NODES(1, Config),    M = "!/" ?VERSION_STR " ML T=233350{C=${A=stedevice/01{M{O{MO=SO,RV=OFF,RG=OFF,tdmc/ec=OFF,MO=SR}}}}}",%     put(severity,trc),%     put(dbg,true),    ok = compact_otp4011(M).%% --------------------------------------------------------------%% Observe that this decode SHALL failcompact_otp4011_msg3(suite) ->    [];compact_otp4011_msg3(Config) when list(Config) ->    d("compact_otp4011_msg3 -> entry", []),    ?ACQUIRE_NODES(1, Config),    M = "!/" ?VERSION_STR " ML T=233350{C=${A=stedevice/01{M{O{MO=SR,RV=OFF,RG=OFF,tdmc/ec=OFF,MO=SO}}}}}",%     put(severity,trc),%     put(dbg,true),    ok = compact_otp4011(M).compact_otp4011(M) ->    d("compact_otp4011 -> entry with"      "~n   M: '~s'", [M]),    Bin = list_to_binary(M),    case decode_message(megaco_compact_text_encoder, false, ?EC, Bin) of	{ok, _} ->	    exit({decoded_erroneous_message,M});	{error, Error} when list(Error) -> % Expected result	    d("compact_otp4011 -> expected error result (so far)", []),	    case lists:keysearch(reason,1,Error) of		{value, {reason,Reason}} ->		    d("compact_otp4011 -> expected error: "		      "~n   Reason: ~p", [Reason]),		    case Reason of			{0, megaco_text_parser_prev3a, 			 {do_merge_control_streamParms, [A,B]}} 			when list(A), record(B, 'LocalControlDescriptor') ->			    case lists:keysearch(mode,1,A) of				{value, {mode, _Mode}} 				when B#'LocalControlDescriptor'.streamMode /= asn1_NOVALUE ->				    d("compact_otp4011 -> expected error",[]),				    ok;				Other ->				    exit({unexpected_mode_reason, {A,B,Other}})			    end;			Other ->			    exit({unexpected_reason, Other})		    end;		false ->		    d("compact_otp4011 -> OUPS, wrong kind of error", []),		    exit({unexpected_result, Error})	    end;	Else ->	    d("compact_otp4011 -> unexpected decode result: ~p", [Else]),	    exit({unexpected_decode_result, Else})    end.%% --------------------------------------------------------------%% Note that this decode SHALL fail, because of the misspelled%% MEGCAO instead of the correct MEGACO.compact_otp4013_msg1(suite) ->    [];compact_otp4013_msg1(Config) when list(Config) ->    d("compact_otp4013_msg1 -> entry", []),    ?ACQUIRE_NODES(1, Config),    M = "MEGCAO/3 MG1 T=12345678{C=-{SC=root{SV{MT=RS,RE=901}}}}",    Bin = list_to_binary(M),    case decode_message(megaco_compact_text_encoder, false, ?EC, Bin) of	{ok, _} ->	    exit({decoded_erroneous_message,M});	{error, Reason} when is_list(Reason) ->	    {value, {reason, no_version_found, _}} = 		lists:keysearch(reason, 1, Reason),	    {value, {token, [{'SafeChars',_,"megcao/3"}|_]}} = 		lists:keysearch(token, 1, Reason),	    ok;	Else ->	    exit({unexpected_decode_result,Else})    end.	    %% --------------------------------------------------------------%% %% compact_otp4085_msg1(suite) ->    [];compact_otp4085_msg1(Config) when list(Config) ->    d("compact_otp4085_msg1 -> entry", []),    ?ACQUIRE_NODES(1, Config),    M = compact_otp4085_erroneous_msg(),    Bin = list_to_binary(M),    case decode_message(megaco_compact_text_encoder, false, ?EC, Bin) of	{ok, M} ->	    exit({decoded_erroneous_message,M});	{error, Error} when list(Error) -> % Expected result	    t("compact_otp4085_msg1 -> decode failed", []),	    case lists:keysearch(reason, 1, Error) of		{value, {reason,{999999, Module, Crap}}} ->		    t("compact_otp4085_msg1 -> THE ACTUAL ERROR: "		      "~n   LINE NUMBER: 999999"		      "~n   Module: ~p"		      "~n   Crap:   ~p", [Module, Crap]),		    %% ok;		    exit({decode_failed_999999, Module, Crap});		{value, {reason,{Line, Module, Crap}}} ->		    t("compact_otp4085_msg1 -> Expected: "		      "~n   Line:   ~p"		      "~n   Module: ~p"		      "~n   Crap:   ~p", [Line, Module, Crap]),		    ok;		false ->		    exit({unexpected_result, Error})	    end;	Else ->	    exit({unexpected_decode_result, Else})    end.%% --------------------------------------------------------------%% This test case is just to show that the message used in%% compact_otp4085_msg1 is actually ok when you add '}' at the end.compact_otp4085_msg2(suite) ->    [];compact_otp4085_msg2(Config) when list(Config) ->    d("compact_otp4085_msg1 -> entry", []),    ?ACQUIRE_NODES(1, Config),    M1 = compact_otp4085_erroneous_msg() ++ "}",    Bin = list_to_binary(M1),    case decode_message(megaco_compact_text_encoder, false, ?EC, Bin) of	{ok, M2} ->	    l("compact_otp4085_msg1 -> successfull decode"	      "~n   M2: ~p", [M2]),	    ok;	Else ->	    e("compact_otp4085_msg1 -> decode error"	      "~n   Else: ~p", [Else]),	    exit({unexpected_decode_result,Else})    end.%% This message lack the ending parentesis (}).compact_otp4085_erroneous_msg() ->    M = "!/" 	?VERSION_STR 	" ML T=11223342{C=${A=${M{O{MO=SR,RV=OFF,RG=OFF},L{v=0,"	"c=ATM NSAP $ ,"	"a=eecid:$ ,"	"m=audio - AAL1/ATMF -,"	"}}},A=stee1181/01{M{O{MO=SR,RV=OFF,RG=OFF,tdmc/ec=off}}}}",    M.%% --------------------------------------------------------------%% %% compact_otp4280_msg1(suite) ->    [];compact_otp4280_msg1(Config) when list(Config) ->    d("compact_otp4280_msg1 -> entry", []),    ?ACQUIRE_NODES(1, Config),    Bin = list_to_binary(compact_otp4280_msg()),    case decode_message(megaco_compact_text_encoder, false, ?EC, Bin) of	{ok, _Msg} ->	    ok;	{error, Error} when list(Error) -> 	    t("compact_otp4280_msg1 -> decode failed", []),	    case lists:keysearch(reason, 1, Error) of		{value, {reason,{Line, Module, Reason} = R}} ->		    t("compact_otp4280_msg1 -> "		      "~n   Line:   ~w"		      "~n   Module: ~w"		      "~n   Reason: ~w", [Line, Module, Reason]),		    exit({decode_failed, R});		false ->		    exit({unexpected_result, Error})	    end;	Else ->	    exit({unexpected_decode_result, Else})    end.compact_otp4280_msg() ->    M = "!/"	?VERSION_STR	" mgw1 P=71853646{C=-{AV=root{M{TS{root/maxnumberofcontexts=49500,"	"root/maxterminationspercontext=2,root/normalmgexecutiontime=200,"	"root/normalmgcexecutiontime=150,"	"root/provisionalresponsetimervalue=2000,BF=OFF,SI=IV}}}}}",    M.%% --------------------------------------------------------------%% This ticket is about comments in a messagecompact_otp4299_msg1(suite) ->    [];compact_otp4299_msg1(Config) when list(Config) ->    d("compact_otp4299_msg1 -> entry", []),    ?ACQUIRE_NODES(1, Config),    Bin = list_to_binary(compact_otp4299_msg()),    case decode_message(megaco_compact_text_encoder, false, ?EC, Bin) of	{ok, _Msg} ->	    ok;	{error, Reason} ->	    exit({decode_error, Reason});	Else ->	    exit({unexpected_decode_result, Else})    end.%% Same message, but this time decoded using the flex scannercompact_otp4299_msg2(suite) ->    [];compact_otp4299_msg2(Config) when list(Config) ->    d("compact_otp4299_msg2 -> entry", []),    ?ACQUIRE_NODES(1, Config),    {Pid, Conf} = compact_otp4299_msg2_init(),    M1  = compact_otp4299_msg(),    d("compact_otp4299_msg2 -> M1: ~n~s", [M1]),    Bin = list_to_binary(M1),    Res = decode_message(megaco_compact_text_encoder, false, 			 [?EC_V3,Conf], Bin),    compact_otp4299_msg2_finish(Pid),    case Res of	{ok, M2} ->	    d("compact_otp4299_msg2 -> M2: ~n~p", [M2]),	    ok;	{error, Reason} ->	    exit({decode_error, Reason});	Else ->	    exit({unexpected_decode_result, Else})    end.compact_otp4299_msg2_init() ->    Flag = process_flag(trap_exit, true),    Res = (catch start_flex_scanner()),    process_flag(trap_exit, Flag),    case Res of	{error, Reason} ->	    skip(Reason);	{Pid, Conf} when pid(Pid) ->	    {Pid, Conf}    end.compact_otp4299_msg2_finish(Pid) ->    stop_flex_scanner(Pid).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -