diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asn1/src/asn1ct_gen.erl | 32 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE.erl | 19 |
2 files changed, 33 insertions, 18 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl index 06c1b63e0a..64a3555f62 100644 --- a/lib/asn1/src/asn1ct_gen.erl +++ b/lib/asn1/src/asn1ct_gen.erl @@ -129,31 +129,39 @@ pgen_types(Rtmod,Erules,N2nConvEnums,Module,[H|T]) -> end, pgen_types(Rtmod,Erules,N2nConvEnums,Module,T). +%% Enumerated type with extension marker pgen_n2nconversion(_Erules,#typedef{name=TypeName,typespec=#type{def={'ENUMERATED',{NN1,NN2}}}}) -> NN = NN1 ++ NN2, - pgen_name2numfunc(TypeName,NN), - pgen_num2namefunc(TypeName,NN); + pgen_name2numfunc(TypeName,NN, extension_marker), + pgen_num2namefunc(TypeName,NN, extension_marker); +%% Without extension marker pgen_n2nconversion(_Erules,#typedef{name=TypeName,typespec=#type{def={'ENUMERATED',NN}}}) -> - pgen_name2numfunc(TypeName,NN), - pgen_num2namefunc(TypeName,NN); + pgen_name2numfunc(TypeName,NN, no_extension_marker), + pgen_num2namefunc(TypeName,NN, no_extension_marker); pgen_n2nconversion(_Erules,_) -> true. -pgen_name2numfunc(_TypeName,[]) -> +pgen_name2numfunc(_TypeName,[], _) -> true; -pgen_name2numfunc(TypeName,[{Atom,Number}]) -> +pgen_name2numfunc(TypeName,[{Atom,Number}], extension_marker) -> + emit(["name2num_",TypeName,"(",{asis,Atom},") ->",Number,";",nl]), + emit(["name2num_",TypeName,"({asn1_enum, Num}) -> Num.",nl,nl]); +pgen_name2numfunc(TypeName,[{Atom,Number}], _) -> emit(["name2num_",TypeName,"(",{asis,Atom},") ->",Number,".",nl,nl]); -pgen_name2numfunc(TypeName,[{Atom,Number}|NNRest]) -> +pgen_name2numfunc(TypeName,[{Atom,Number}|NNRest], EM) -> emit(["name2num_",TypeName,"(",{asis,Atom},") ->",Number,";",nl]), - pgen_name2numfunc(TypeName,NNRest). + pgen_name2numfunc(TypeName,NNRest, EM). -pgen_num2namefunc(_TypeName,[]) -> +pgen_num2namefunc(_TypeName,[], _) -> true; -pgen_num2namefunc(TypeName,[{Atom,Number}]) -> +pgen_num2namefunc(TypeName,[{Atom,Number}], extension_marker) -> + emit(["num2name_",TypeName,"(",Number,") ->",{asis,Atom},";",nl]), + emit(["num2name_",TypeName,"(ExtensionNum) -> {asn1_enum, ExtensionNum}.",nl,nl]); +pgen_num2namefunc(TypeName,[{Atom,Number}], _) -> emit(["num2name_",TypeName,"(",Number,") ->",{asis,Atom},".",nl,nl]); -pgen_num2namefunc(TypeName,[{Atom,Number}|NNRest]) -> +pgen_num2namefunc(TypeName,[{Atom,Number}|NNRest], EM) -> emit(["num2name_",TypeName,"(",Number,") ->",{asis,Atom},";",nl]), - pgen_num2namefunc(TypeName,NNRest). + pgen_num2namefunc(TypeName,NNRest, EM). pgen_objects(_,_,_,[]) -> true; diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl index 10b929b2a9..e9b680d1be 100644 --- a/lib/asn1/test/asn1_SUITE.erl +++ b/lib/asn1/test/asn1_SUITE.erl @@ -1238,18 +1238,25 @@ testName2Number(Config) -> 'unknown-PLMN' = 'S1AP-IEs':num2name_CauseMisc(5), %% OTP-10144 - %% Test that n2n option generates name2num and num2name functions that - %% do not crash on values not within the extension root if the enumeration - %% type has an extension marker. - %% Also, previously name2num and num2name was only generated if the type - %% had an extension marker. So we also tests to check this. + %% Test that n2n option generates name2num and num2name functions supporting + %% values not within the extension root if the enumeration type has an + %% extension marker. N2NOptionsExt = [{n2n, 'NoExt'}, {n2n, 'Ext'}, {n2n, 'Ext2'}], asn1_test_lib:compile("EnumN2N", Config, N2NOptionsExt), + %% Previously, name2num and num2name was not generated if the type didn't + %% have an extension marker: 0 = 'EnumN2N':name2num_NoExt('blue'), 2 = 'EnumN2N':name2num_NoExt('green'), blue = 'EnumN2N':num2name_NoExt(0), green = 'EnumN2N':num2name_NoExt(2), - + + %% Test enumeration extension: + 7 = 'EnumN2N':name2num_Ext2('orange'), + orange = 'EnumN2N':num2name_Ext2(7), + %% 7 is not defined in Ext, only in Ext2. + {asn1_enum, 7} = 'EnumN2N':num2name_Ext(7), + 7 = 'EnumN2N':name2num_Ext({asn1_enum, 7}), + 42 = 'EnumN2N':name2num_Ext2({asn1_enum, 42}), ok. ticket_7407(Config) -> |