From 6003a7c9d4319eba8eff7bfb8e4a73d3d1d38786 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 26 Sep 2014 12:03:01 +0200 Subject: Add a new test case to test values in ValueTest.asn1 We only tested that ValueTest.asn1 would compile, no that the values were correct. --- lib/asn1/test/testValueTest.erl | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 lib/asn1/test/testValueTest.erl (limited to 'lib/asn1/test/testValueTest.erl') diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl new file mode 100644 index 0000000000..8359930256 --- /dev/null +++ b/lib/asn1/test/testValueTest.erl @@ -0,0 +1,61 @@ +%% +%% %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(testValueTest). + +-export([main/0]). + +main() -> + M = 'ValueTest', + + %% Basic types + 12 = M:'vANY'(), + true = M:'vBOOLEAN'(), + 12 = M:'vINTEGER'(), + 0 = M:'vINTEGERNNL'(), + button1 = M:'vENUMERATED'(), + [zero,two] = M:'vBS'(), + 'NULL' = M:'vNULL'(), + <<16#31,16#32,16#33>> = M:'vOS'(), + {2,1,1} = M:'vOD'(), + + %% Character strings + "01234567" = M:'numericstring'(), + "PrintableString" = M:'printablestring'(), + "VisibleString" = M:'visiblestring'(), + [0,13] = M:'cr'(), + ["First line",[0,13],"Second line"] = M:'ia5string1'(), + [[5,5],[4,4],[6,6]] = M:'ia5string2'(), + "TeletexString" = M:'teletexstring'(), + "VideotexString" = M:'videotexstring'(), + "97100211-0500" = M:'utctime'(), + "19971002103130.5" = M:'generalizedtime'(), + "ObjectDescriptor" = M:'objectdescriptor'(), + "GraphicString" = M:'graphicstring'(), + "GeneralString" = M:'generalstring'(), + "BMPString" = M:'bmpstring1'(), + [0,0,0,65] = M:'latinCapitalLetterA'(), + [0,0,3,145] = M:'greekCapitalLetterSigma'(), + ["This is a capital A: ", + [0,0,0,65], + ", and a capital sigma: ", + [0,0,3,145], + "; try and spot the difference!"] = M:'my-universalstring'(), + + ok. -- cgit v1.2.3 From d73a835b66911935024019fd55089a1e0f7a81d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 19 Sep 2014 15:42:40 +0200 Subject: Check INTEGER values better There is duplicated effort in that validate_integer() checks whether the integer value is valid, and then normalize_integer() does mostly the same work in order to convert the value to an integer. Eliminate the validate_integer() function and incorporate its checks into normalize_integer(). Also produce proper error messages. --- lib/asn1/test/testValueTest.erl | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/asn1/test/testValueTest.erl') diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl index 8359930256..fdd8b006e2 100644 --- a/lib/asn1/test/testValueTest.erl +++ b/lib/asn1/test/testValueTest.erl @@ -58,4 +58,9 @@ main() -> [0,0,3,145], "; try and spot the difference!"] = M:'my-universalstring'(), + %% Integers + 42 = M:someInteger(), + 42 = M:otherInteger(), + {'IntegerSeq',42} = M:integerSeq1(), + ok. -- cgit v1.2.3 From b92e491aa5bfbaefb0f938bbb245a580837cb8c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Mon, 22 Sep 2014 14:21:55 +0200 Subject: 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) --- lib/asn1/test/testValueTest.erl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'lib/asn1/test/testValueTest.erl') 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. -- cgit v1.2.3 From 081b4f03af69f67abf97f268d5d097918a6f3d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 25 Sep 2014 12:53:56 +0200 Subject: Correct recursion in OCTET STRING value definitions --- lib/asn1/test/testValueTest.erl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'lib/asn1/test/testValueTest.erl') diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl index d9cc3de5eb..24a2862b40 100644 --- a/lib/asn1/test/testValueTest.erl +++ b/lib/asn1/test/testValueTest.erl @@ -72,8 +72,18 @@ main() -> roundtrip('II', 4), roundtrip_error('II', 5), + %% Recursive value definitions. + {'OctetStringSeq',<<16#40,16#41,16#42>>} = M:octetStringSeq1(), + <<16#40,16#41,16#42>> = M:otherOctetString(), + <<16#40,16#41,16#42>> = M:someOctetString(), + {'OctetStringSeq',<<16#40,16#41,16#42>>} = M:octetStringSeq2(), + {'OctetStringSeq',<<16#40,16#41,16#FF>>} = M:octetStringSeq3(), + <<16#40,16#41,16#FF>> = M:'os-1'(), + <<16#40,16#41,16#FF>> = M:'os-2'(), + ok. + roundtrip(T, V) -> asn1_test_lib:roundtrip('ValueTest', T, V). -- cgit v1.2.3 From e43a382e7207a3c01baba2ef202b49766b60fdae Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 7 Oct 2014 17:08:09 +0200 Subject: Clean up and correct validation of OBJECT IDENTIFIER/RELATIVE-OID Besides simplifying the code and doing better error checking and error reporting, fix the following bugs: Support retrieving an OBJECT IDENTIFIER/RELATIVE-OID from an object. Example: oid OBJECT IDENTIFIER ::= some-object.&some-field Allow an integer constant first in an OBJECT IDENTIFIER: integer INTEGER ::= 0 oid OBJECT IDENTIFIER ::= {integer 1} --- lib/asn1/test/testValueTest.erl | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/asn1/test/testValueTest.erl') diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl index 24a2862b40..d1532c3ef0 100644 --- a/lib/asn1/test/testValueTest.erl +++ b/lib/asn1/test/testValueTest.erl @@ -33,7 +33,14 @@ main() -> [zero,two] = M:'vBS'(), 'NULL' = M:'vNULL'(), <<16#31,16#32,16#33>> = M:'vOS'(), + + %% OID {2,1,1} = M:'vOD'(), + {1,2} = M:'integer-first'(), + {2,4,5} = M:'rel-oid-1'(), + {0,2,4,5} = M:'include-roid'(), + {1,2,1} = M:'include-oid'(), + {1,2,1,2,4,5,42} = M:'include-all'(), %% Character strings "01234567" = M:'numericstring'(), -- cgit v1.2.3 From 0775ee9c7dc4957302a756b8b37cf94e372d3ecc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 28 Oct 2014 14:47:50 +0100 Subject: Improve handling of BIT STRING values --- lib/asn1/test/testValueTest.erl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/asn1/test/testValueTest.erl') diff --git a/lib/asn1/test/testValueTest.erl b/lib/asn1/test/testValueTest.erl index d1532c3ef0..8a8e973621 100644 --- a/lib/asn1/test/testValueTest.erl +++ b/lib/asn1/test/testValueTest.erl @@ -88,6 +88,17 @@ main() -> <<16#40,16#41,16#FF>> = M:'os-1'(), <<16#40,16#41,16#FF>> = M:'os-2'(), + %% Recursive BIT STRING definitions. + {'BsSeq',<<2#101101:6>>,[c]} = M:bsSeq1(), + {'BsSeq',<<2#101101:6>>,[c]} = M:bsSeq2(), + {'BsSeq',<<2#101:3>>,[a,c]} = M:bsSeq3(), + <<2#101101:6>> = M:someBitString(), + <<2#101101:6>> = M:otherBitString(), + <<2#101:3>> = M:bsFromObject(), + <<2#101:3>> = M:bsFromObjectInd(), + [c] = M:someNamedBs(), + [c] = M:someOtherNamedBs(), + ok. -- cgit v1.2.3