diff options
author | Björn Gustavsson <[email protected]> | 2014-09-22 14:21:55 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2015-01-12 11:40:24 +0100 |
commit | b92e491aa5bfbaefb0f938bbb245a580837cb8c8 (patch) | |
tree | 23d176c1983dd35a25d398b7ab29ef62afc82788 /lib/asn1/test | |
parent | d73a835b66911935024019fd55089a1e0f7a81d2 (diff) | |
download | otp-b92e491aa5bfbaefb0f938bbb245a580837cb8c8.tar.gz otp-b92e491aa5bfbaefb0f938bbb245a580837cb8c8.tar.bz2 otp-b92e491aa5bfbaefb0f938bbb245a580837cb8c8.zip |
Refactor code involving calls to get_fieldname_element/3
Refactor and clean up code. While at it, add error handling and
test cases. (Also add test cases for the existing values in
ValueTest.asn while we are it.)
Add support for defining INTEGER constants by extracting
fields from objects. Example:
int-from-object INTEGER ::= object.&id
When extracting values from objects in constraints, only one
level of extraction would work. That is, the following would
work:
SomeName ::= INTEGER (object.&int)
but not:
SomeName ::= INTEGER (object.&obj.&int)
Diffstat (limited to 'lib/asn1/test')
-rw-r--r-- | lib/asn1/test/Makefile | 1 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE.erl | 9 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE_data/Constraints.py | 16 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE_data/InfObjExtract.asn1 | 51 | ||||
-rw-r--r-- | lib/asn1/test/asn1_SUITE_data/ValueTest.asn | 22 | ||||
-rw-r--r-- | lib/asn1/test/error_SUITE.erl | 73 | ||||
-rw-r--r-- | lib/asn1/test/testConstraints.erl | 9 | ||||
-rw-r--r-- | lib/asn1/test/testInfObjExtract.erl | 47 | ||||
-rw-r--r-- | lib/asn1/test/testValueTest.erl | 20 |
9 files changed, 242 insertions, 6 deletions
diff --git a/lib/asn1/test/Makefile b/lib/asn1/test/Makefile index 2c9d06cc0a..ff2ae204dc 100644 --- a/lib/asn1/test/Makefile +++ b/lib/asn1/test/Makefile @@ -78,6 +78,7 @@ MODULES= \ testEnumExt \ testInfObjectClass \ testInfObj \ + testInfObjExtract \ testParameterizedInfObj \ testFragmented \ testMergeCompile \ diff --git a/lib/asn1/test/asn1_SUITE.erl b/lib/asn1/test/asn1_SUITE.erl index fef2981b00..668a8a2648 100644 --- a/lib/asn1/test/asn1_SUITE.erl +++ b/lib/asn1/test/asn1_SUITE.erl @@ -135,6 +135,7 @@ groups() -> testChoiceIndefinite, per_open_type, testInfObjectClass, + testInfObjExtract, testParam, testFragmented, testMergeCompile, @@ -766,6 +767,11 @@ testInfObjectClass(Config, Rule, Opts) -> testInfObjectClass:main(Rule), testInfObj:main(Rule). +testInfObjExtract(Config) -> test(Config, fun testInfObjExtract/3). +testInfObjExtract(Config, Rule, Opts) -> + asn1_test_lib:compile("InfObjExtract", Config, [Rule|Opts]), + testInfObjExtract:main(). + testParam(Config) -> test(Config, fun testParam/3, [ber,{ber,[der]},per,uper]). testParam(Config, Rule, Opts) -> @@ -840,8 +846,7 @@ testContextSwitchingTypes(Config, Rule, Opts) -> testTypeValueNotation(Config) -> test(Config, fun testTypeValueNotation/3). testTypeValueNotation(Config, Rule, Opts) -> - asn1_test_lib:compile_all(["SeqTypeRefPrim", "ValueTest"], Config, - [Rule|Opts]), + asn1_test_lib:compile("SeqTypeRefPrim", Config, [Rule|Opts]), testTypeValueNotation:main(Rule, Opts). testValueTest(Config) -> test(Config, fun testValueTest/3). diff --git a/lib/asn1/test/asn1_SUITE_data/Constraints.py b/lib/asn1/test/asn1_SUITE_data/Constraints.py index 3495cd841b..bee619348a 100644 --- a/lib/asn1/test/asn1_SUITE_data/Constraints.py +++ b/lib/asn1/test/asn1_SUITE_data/Constraints.py @@ -144,5 +144,21 @@ NonOverlapping ::= INTEGER (7280..7560 | 23000..24000 | 24960..26900) +-- +-- Test INTEGER constraints from fields in objects. +-- + +INT-HOLDER ::= CLASS { + &id INTEGER UNIQUE, + &obj INT-HOLDER OPTIONAL +} WITH SYNTAX { + ID &id + [OBJ &obj] +} + +int-holder-1 INT-HOLDER ::= { ID 2 } +int-holder-2 INT-HOLDER ::= { ID 4 OBJ int-holder-1 } + +IntObjectConstr ::= INTEGER (int-holder-2.&obj.&id..int-holder-2.&id) END diff --git a/lib/asn1/test/asn1_SUITE_data/InfObjExtract.asn1 b/lib/asn1/test/asn1_SUITE_data/InfObjExtract.asn1 new file mode 100644 index 0000000000..4a8889f940 --- /dev/null +++ b/lib/asn1/test/asn1_SUITE_data/InfObjExtract.asn1 @@ -0,0 +1,51 @@ +InfObjExtract DEFINITIONS AUTOMATIC TAGS ::= +BEGIN + +DATA-CLASS ::= CLASS { + &id INTEGER UNIQUE, + &Type +} WITH SYNTAX { + ID &id + TYPE &Type +} + +data-object-1 DATA-CLASS ::= { ID 1 TYPE BOOLEAN } +data-object-2 DATA-CLASS ::= { ID 2 TYPE OCTET STRING } +data-object-3 DATA-CLASS ::= { ID 3 TYPE BIT STRING } + +ObjSet DATA-CLASS ::= { + holder-object-1.&obj | + data-object-2 | + data-object-3, + ... +} + +holder-object-1 HOLDER-CLASS ::= { + OBJ data-object-1 +} + +holder-object-2 HOLDER-CLASS ::= { + OBJ-SET {data-object-1} +} + +holder-object-3 HOLDER-CLASS ::= { + OBJ-SET {holder-object-2.&ObjSet} +} + +HOLDER-CLASS ::= CLASS { + &obj DATA-CLASS OPTIONAL, + &ObjSet DATA-CLASS OPTIONAL +} WITH SYNTAX { + [OBJ &obj] + [OBJ-SET &ObjSet] +} + +TestSeq{DATA-CLASS:ObjectSet} ::= SEQUENCE { + id DATA-CLASS.&id ({ObjectSet}), + data DATA-CLASS.&Type ({ObjectSet}{@id}) +} + +DataSeq-1 ::= TestSeq{ {ObjSet} } +DataSeq-2 ::= TestSeq{ {holder-object-3.&ObjSet} } + +END diff --git a/lib/asn1/test/asn1_SUITE_data/ValueTest.asn b/lib/asn1/test/asn1_SUITE_data/ValueTest.asn index 8db2fcf17d..51da9d8afb 100644 --- a/lib/asn1/test/asn1_SUITE_data/ValueTest.asn +++ b/lib/asn1/test/asn1_SUITE_data/ValueTest.asn @@ -1,4 +1,4 @@ -ValueTest DEFINITIONS ::= +ValueTest DEFINITIONS AUTOMATIC TAGS ::= BEGIN @@ -41,7 +41,6 @@ objectdescriptor ObjectDescriptor ::= "ObjectDescriptor" graphicstring GraphicString ::= "GraphicString" generalstring GeneralString ::= "GeneralString" bmpstring1 BMPString ::= "BMPString" ---bmpstring2 BMPString ::= [{0,0,0,66},{0,0,0,77},{0,0,0,80},{0,0,0,115},{0,0,0,116},{0,0,0,114},{0,0,0,105},{0,0,0,110},{0,0,0,103}] latinCapitalLetterA UniversalString ::= {0,0,0,65} greekCapitalLetterSigma UniversalString ::= {0,0,3,145} my-universalstring UniversalString ::= {"This is a capital A: ", @@ -61,4 +60,23 @@ someInteger INTEGER ::= 42 integerSeq1 IntegerSeq ::= { a otherInteger } otherInteger INTEGER ::= someInteger +-- +-- Values from objects. +-- +int-from-object-1 INTEGER ::= int-holder-2.&obj.&id +int-from-object-2 INTEGER ::= int-holder-2.&id + +INT-HOLDER ::= CLASS { + &id INTEGER UNIQUE, + &obj INT-HOLDER OPTIONAL +} WITH SYNTAX { + ID &id + [OBJ &obj] +} + +int-holder-1 INT-HOLDER ::= { ID 2 } +int-holder-2 INT-HOLDER ::= { ID 4 OBJ int-holder-1 } + +II ::= INTEGER (int-from-object-1..int-from-object-2) + END diff --git a/lib/asn1/test/error_SUITE.erl b/lib/asn1/test/error_SUITE.erl index 36ec7a8203..630daf75c6 100644 --- a/lib/asn1/test/error_SUITE.erl +++ b/lib/asn1/test/error_SUITE.erl @@ -20,9 +20,9 @@ -module(error_SUITE). -export([suite/0,all/0,groups/0, already_defined/1,bitstrings/1, - classes/1,enumerated/1, + classes/1,constraints/1,enumerated/1, imports/1,instance_of/1,integers/1,objects/1, - parameterization/1,values/1]). + object_field_extraction/1,parameterization/1,values/1]). -include_lib("test_server/include/test_server.hrl"). @@ -36,11 +36,13 @@ groups() -> [already_defined, bitstrings, classes, + constraints, enumerated, imports, instance_of, integers, objects, + object_field_extraction, parameterization, values]}]. @@ -108,6 +110,29 @@ classes(Config) -> ]} = run(P, Config), ok. +constraints(Config) -> + M = 'Constraints', + P = {M, + <<"Constraints DEFINITIONS AUTOMATIC TAGS ::= BEGIN\n" + " II-1 ::= INTEGER (holder-1.&obj)\n" + " II-2 ::= INTEGER ('1234'H<..20)\n" + " II-3 ::= INTEGER (1..<\"abc\")\n" + + " HOLDER ::= CLASS {\n" + " &obj HOLDER OPTIONAL\n" + " }\n" + + " holder-1 HOLDER ::= { &obj holder-2 }\n" + " holder-2 HOLDER ::= { }\n" + "END\n">>}, + {error, + [ + {structured_error,{M,2},asn1ct_check,illegal_value}, + {structured_error,{M,3},asn1ct_check,illegal_integer_value}, + {structured_error,{M,4},asn1ct_check,illegal_integer_value} + ]} = run(P, Config), + ok. + enumerated(Config) -> M = 'Enumerated', P = {M, @@ -235,6 +260,36 @@ objects(Config) -> } = run(P, Config), ok. +object_field_extraction(Config) -> + M = 'ObjectFieldExtraction', + P = {M, + <<"ObjectFieldExtraction DEFINITIONS AUTOMATIC TAGS ::= BEGIN\n" + + " DataObjSet DATA-CLASS ::= {\n" + " holder-object-1.&int,\n" + " ...\n" + " }\n" + + " holder-object-1 HOLDER-CLASS ::= {\n" + " &int 42\n" + " }\n" + + " HOLDER-CLASS ::= CLASS {\n" + " &int INTEGER\n" + " }\n" + + " DATA-CLASS ::= CLASS {\n" + " &id INTEGER\n" + " }\n" + + "END\n">>}, + {error, + [ + {structured_error,{M,2},asn1ct_check,illegal_object} + ] + } = run(P, Config), + ok. + parameterization(Config) -> M = 'Parameterization', P = {M, @@ -260,6 +315,16 @@ values(Config) -> " int1 INTEGER ::= \"string\"\n" " int2 INTEGER ::= os4\n" " int3 INTEGER ::= not-defined\n" + " int4 INTEGER ::= holder-1.&str\n" + " int5 INTEGER ::= holder-2.&obj\n" + + " HOLDER ::= CLASS {\n" + " &str IA5String,\n" + " &obj HOLDER OPTIONAL\n" + " }\n" + + " holder-1 HOLDER ::= { &str \"xyz\" }\n" + " holder-2 HOLDER ::= { &str \"xyz\", &obj holder-1 }\n" "END\n">>}, {error, [ @@ -274,6 +339,10 @@ values(Config) -> {structured_error,{M,7},asn1ct_check, illegal_integer_value}, {structured_error,{M,8},asn1ct_check, + illegal_integer_value}, + {structured_error,{M,9},asn1ct_check, + illegal_integer_value}, + {structured_error,{M,10},asn1ct_check, illegal_integer_value} ] } = run(P, Config), diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl index 3ccf883bd6..aab4f1d4c6 100644 --- a/lib/asn1/test/testConstraints.erl +++ b/lib/asn1/test/testConstraints.erl @@ -231,6 +231,15 @@ int_constraints(Rules) -> seq_roundtrip(Rules, 'SeqOverlapping', 'SeqNonOverlapping', 19000), seq_roundtrip(Rules, 'SeqOverlapping', 'SeqNonOverlapping', 26900), + %%========================================================== + %% Constraints from object fields. + %%========================================================== + range_error(Rules, 'IntObjectConstr', 1), + roundtrip('IntObjectConstr', 2), + roundtrip('IntObjectConstr', 3), + roundtrip('IntObjectConstr', 4), + range_error(Rules, 'IntObjectConstr', 5), + ok. %% PER: Ensure that if the lower bound is Lb, Lb+16#80 is encoded diff --git a/lib/asn1/test/testInfObjExtract.erl b/lib/asn1/test/testInfObjExtract.erl new file mode 100644 index 0000000000..4e148824fe --- /dev/null +++ b/lib/asn1/test/testInfObjExtract.erl @@ -0,0 +1,47 @@ +%% +%% %CopyrightBegin% +%% +%% Copyright Ericsson AB 2014. All Rights Reserved. +%% +%% The contents of this file are subject to the Erlang Public License, +%% Version 1.1, (the "License"); you may not use this file except in +%% compliance with the License. You should have received a copy of the +%% Erlang Public License along with this software. If not, it can be +%% retrieved online at http://www.erlang.org/. +%% +%% Software distributed under the License is distributed on an "AS IS" +%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See +%% the License for the specific language governing rights and limitations +%% under the License. +%% +%% %CopyrightEnd% +%% +%% + +-module(testInfObjExtract). + +-export([main/0]). + +main() -> + roundtrip('DataSeq-1', {'DataSeq-1',1,true}), + roundtrip('DataSeq-1', {'DataSeq-1',2,<<"abc">>}), + roundtrip('DataSeq-1', {'DataSeq-1',3,<<42:5>>}), + roundtrip_error('DataSeq-1', {'DataSeq-1',4,42}), + + roundtrip('DataSeq-2', {'DataSeq-2',1,true}), + roundtrip_error('DataSeq-2', {'DataSeq',2,<<"abc">>}), + roundtrip_error('DataSeq-2', {'DataSeq',3,<<42:5>>}), + roundtrip_error('DataSeq-2', {'DataSeq',999,42}), + ok. + +roundtrip(T, V) -> + asn1_test_lib:roundtrip('InfObjExtract', T, V). + +roundtrip_error(T, V) -> + try asn1_test_lib:roundtrip('InfObjExtract', T, V) of + ok -> + test_server:fail() + catch + _:_ -> + ok + end. diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl index fdd8b006e2..d9cc3de5eb 100644 --- a/lib/asn1/test/testValueTest.erl +++ b/lib/asn1/test/testValueTest.erl @@ -63,4 +63,24 @@ main() -> 42 = M:otherInteger(), {'IntegerSeq',42} = M:integerSeq1(), + %% Value from object + 2 = M:'int-from-object-1'(), + 4 = M:'int-from-object-2'(), + roundtrip_error('II', 1), + roundtrip('II', 2), + roundtrip('II', 3), + roundtrip('II', 4), + roundtrip_error('II', 5), + ok. + +roundtrip(T, V) -> + asn1_test_lib:roundtrip('ValueTest', T, V). + +roundtrip_error(T, V) -> + try asn1_test_lib:roundtrip('ValueTest', T, V) of + ok -> + test_server:fail() + catch _:_ -> + ok + end. |