aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGustav Simonsson <[email protected]>2012-07-11 11:50:46 +0200
committerGustav Simonsson <[email protected]>2012-07-11 11:50:46 +0200
commit7a70f331e65e831585afa195bf29ef7d823e55f6 (patch)
treec4865debd6088f96a2838c455548a0b59e9a29d1 /lib
parenteac9c3494ce4d684b09779f075317e8943a7928b (diff)
downloadotp-7a70f331e65e831585afa195bf29ef7d823e55f6.tar.gz
otp-7a70f331e65e831585afa195bf29ef7d823e55f6.tar.bz2
otp-7a70f331e65e831585afa195bf29ef7d823e55f6.zip
Make n2n option work for enumerated types without extension
markers. Add test enumeration types for testing n2n option when using the name2num and num2name functions on an enumeration value not in the extension root of an enumeration type with extension marker.
Diffstat (limited to 'lib')
-rw-r--r--lib/asn1/src/asn1ct_gen.erl3
-rw-r--r--lib/asn1/test/asn1_SUITE.erl14
-rw-r--r--lib/asn1/test/asn1_SUITE_data/EnumN2N.asn125
3 files changed, 42 insertions, 0 deletions
diff --git a/lib/asn1/src/asn1ct_gen.erl b/lib/asn1/src/asn1ct_gen.erl
index fda4e1c6d9..06c1b63e0a 100644
--- a/lib/asn1/src/asn1ct_gen.erl
+++ b/lib/asn1/src/asn1ct_gen.erl
@@ -133,6 +133,9 @@ pgen_n2nconversion(_Erules,#typedef{name=TypeName,typespec=#type{def={'ENUMERATE
NN = NN1 ++ NN2,
pgen_name2numfunc(TypeName,NN),
pgen_num2namefunc(TypeName,NN);
+pgen_n2nconversion(_Erules,#typedef{name=TypeName,typespec=#type{def={'ENUMERATED',NN}}}) ->
+ pgen_name2numfunc(TypeName,NN),
+ pgen_num2namefunc(TypeName,NN);
pgen_n2nconversion(_Erules,_) ->
true.
diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl
index 3b9a7532c0..10b929b2a9 100644
--- a/lib/asn1/test/asn1_SUITE.erl
+++ b/lib/asn1/test/asn1_SUITE.erl
@@ -1236,6 +1236,20 @@ testName2Number(Config) ->
0 = 'S1AP-IEs':name2num_CauseMisc('control-processing-overload'),
'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.
+ N2NOptionsExt = [{n2n, 'NoExt'}, {n2n, 'Ext'}, {n2n, 'Ext2'}],
+ asn1_test_lib:compile("EnumN2N", Config, N2NOptionsExt),
+ 0 = 'EnumN2N':name2num_NoExt('blue'),
+ 2 = 'EnumN2N':name2num_NoExt('green'),
+ blue = 'EnumN2N':num2name_NoExt(0),
+ green = 'EnumN2N':num2name_NoExt(2),
+
ok.
ticket_7407(Config) ->
diff --git a/lib/asn1/test/asn1_SUITE_data/EnumN2N.asn1 b/lib/asn1/test/asn1_SUITE_data/EnumN2N.asn1
new file mode 100644
index 0000000000..a724f2f3f5
--- /dev/null
+++ b/lib/asn1/test/asn1_SUITE_data/EnumN2N.asn1
@@ -0,0 +1,25 @@
+EnumN2N DEFINITIONS AUTOMATIC TAGS ::=
+BEGIN
+
+NoExt ::= ENUMERATED {
+ blue(0),
+ red(1),
+ green(2)
+}
+
+Ext ::= ENUMERATED {
+ blue(0),
+ red(1),
+ green(2),
+ ...
+}
+
+Ext2 ::= ENUMERATED {
+ blue(0),
+ red(1),
+ green(2),
+ ...,
+ orange(7)
+}
+
+END