aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/test/testPrim.erl
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2017-08-30 20:55:08 +0200
committerSverker Eriksson <[email protected]>2017-08-30 20:55:08 +0200
commit7c67bbddb53c364086f66260701bc54a61c9659c (patch)
tree92ab0d4b91d5e2f6e7a3f9d61ea25089e8a71fe0 /lib/asn1/test/testPrim.erl
parent97dc5e7f396129222419811c173edc7fa767b0f8 (diff)
parent3b7a6ffddc819bf305353a593904cea9e932e7dc (diff)
downloadotp-7c67bbddb53c364086f66260701bc54a61c9659c.tar.gz
otp-7c67bbddb53c364086f66260701bc54a61c9659c.tar.bz2
otp-7c67bbddb53c364086f66260701bc54a61c9659c.zip
Merge tag 'OTP-19.0' into sverker/19/binary_to_atom-utf8-crash/ERL-474/OTP-14590
Diffstat (limited to 'lib/asn1/test/testPrim.erl')
-rw-r--r--lib/asn1/test/testPrim.erl189
1 files changed, 111 insertions, 78 deletions
diff --git a/lib/asn1/test/testPrim.erl b/lib/asn1/test/testPrim.erl
index a6e68a9fe0..96a2dd6c79 100644
--- a/lib/asn1/test/testPrim.erl
+++ b/lib/asn1/test/testPrim.erl
@@ -1,18 +1,19 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1997-2013. All Rights Reserved.
+%% Copyright Ericsson AB 1997-2016. 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/.
+%% Licensed under the Apache License, Version 2.0 (the "License");
+%% you may not use this file except in compliance with the License.
+%% You may obtain a copy of the License at
%%
-%% 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.
+%% http://www.apache.org/licenses/LICENSE-2.0
+%%
+%% Unless required by applicable law or agreed to in writing, software
+%% distributed under the License is distributed on an "AS IS" BASIS,
+%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+%% See the License for the specific language governing permissions and
+%% limitations under the License.
%%
%% %CopyrightEnd%
%%
@@ -27,7 +28,7 @@
-export([null/1]).
-export([real/1]).
--include_lib("test_server/include/test_server.hrl").
+-include_lib("common_test/include/ct.hrl").
bool(Rules) ->
Types = ['Bool','BoolCon','BoolPri','BoolApp',
@@ -36,8 +37,7 @@ bool(Rules) ->
case Rules of
ber ->
[begin
- {error,{asn1,{encode_boolean,517}}} =
- (catch 'Prim':encode(T, 517))
+ {error,{asn1,{encode_boolean,517}}} = enc_error(T, 517)
end || T <- Types],
ok;
_ ->
@@ -78,8 +78,37 @@ int(Rules) ->
roundtrip('ASeq', {'ASeq',false,250,true,200,true,199,true,77788}),
roundtrip('ASeq', {'ASeq',true,0,false,0,true,0,true,68789}),
+ %%==========================================================
+ %% Longitude ::= INTEGER {
+ %% oneMicrodegreeEast(10),
+ %% oneMicrodegreeWest(-10),
+ %% unavailable(1800000001)
+ %% } (-1799999999..1800000001)
+ %%==========================================================
+
+ Enc10 = encoding(Rules, oneMicrodegreeEast),
+ Enc10 = roundtrip('Longitude', oneMicrodegreeEast),
+ Enc10 = roundtrip('Longitude', 10, oneMicrodegreeEast),
+
+ Enc20 = encoding(Rules, oneMicrodegreeWest),
+ Enc20 = roundtrip('Longitude', oneMicrodegreeWest),
+ Enc20 = roundtrip('Longitude', -10, oneMicrodegreeWest),
+
+ Enc30 = roundtrip('Longitude', unavailable),
+ Enc30 = roundtrip('Longitude', 1800000001, unavailable),
+
ok.
+encoding(Rules, Type) ->
+ asn1_test_lib:hex_to_bin(encoding_1(Rules, Type)).
+
+encoding_1(ber, oneMicrodegreeEast) -> "02010A";
+encoding_1(per, oneMicrodegreeEast) -> "C06B49D2 09";
+encoding_1(uper, oneMicrodegreeEast) -> "6B49D209";
+
+encoding_1(ber, oneMicrodegreeWest) -> "0201F6";
+encoding_1(per, oneMicrodegreeWest) -> "C06B49D1 F5";
+encoding_1(uper, oneMicrodegreeWest) -> "6B49D1F5".
enum(Rules) ->
@@ -90,15 +119,20 @@ enum(Rules) ->
roundtrip('Enum', monday),
roundtrip('Enum', thursday),
- {error,{asn1,{_,4}}} = (catch 'Prim':encode('Enum', 4)),
+ {error,{asn1,{_,4}}} = enc_error('Enum', 4),
case Rules of
Per when Per =:= per; Per =:= uper ->
- {ok,<<0>>} = 'Prim':encode('SingleEnumVal', true),
- {ok,<<0>>} = 'Prim':encode('SingleEnumValExt', true);
+ <<0>> = roundtrip('SingleEnumVal', true),
+ <<0>> = roundtrip('SingleEnumValExt', true);
ber ->
ok
end,
+
+ roundtrip('NegEnumVal', neg),
+ roundtrip('NegEnumVal', zero),
+ roundtrip('EnumVal128', val),
+
ok.
@@ -128,15 +162,36 @@ null(_Rules) ->
%%==========================================================
%% Null ::= NULL
%%==========================================================
-
- {ok,Bytes1} = asn1_wrapper:encode('Prim','Null',monday),
- {ok,'NULL'} = asn1_wrapper:decode('Prim','Null',lists:flatten(Bytes1)),
+ roundtrip('Null', monday, 'NULL'),
ok.
roundtrip(T, V) ->
- {ok,E} = 'Prim':encode(T, V),
- {ok,V} = 'Prim':decode(T, E),
- E.
+ roundtrip(T, V, V).
+
+roundtrip(Type, Value, ExpectedValue) ->
+ case get(no_ok_wrapper) of
+ false ->
+ asn1_test_lib:roundtrip_enc('Prim', Type, Value, ExpectedValue);
+ true ->
+ M = 'Prim',
+ Enc = M:encode(Type, Value),
+ ExpectedValue = M:decode(Type, Enc),
+ Enc
+ end.
+
+enc_error(T, V) ->
+ case get(no_ok_wrapper) of
+ false ->
+ 'Prim':encode(T, V);
+ true ->
+ try 'Prim':encode(T, V) of
+ _ ->
+ ?t:fail()
+ catch
+ _:Reason ->
+ Reason
+ end
+ end.
real(_Rules) ->
%%==========================================================
@@ -144,67 +199,45 @@ real(_Rules) ->
%%==========================================================
%% Base 2
- ?line {ok,Bytes1} = asn1_wrapper:encode('Real','AngleInRadians',{1,2,1}),
- ?line {ok,{1,2,1}} = asn1_wrapper:decode('Real','AngleInRadians',Bytes1),
-
- ?line {ok,Bytes2} = asn1_wrapper:encode('Real','AngleInRadians',{129,2,1}),
- ?line {ok,{129,2,1}} = asn1_wrapper:decode('Real','AngleInRadians',Bytes2),
-
- ?line {ok,Bytes3} = asn1_wrapper:encode('Real','AngleInRadians',{128,2,1}),
- ?line {ok,{1,2,8}} = asn1_wrapper:decode('Real','AngleInRadians',Bytes3),
-
- ?line {ok,Bytes4} = asn1_wrapper:encode('Real','AngleInRadians',{128,2,-7}),
- ?line {ok,{1,2,0}} = asn1_wrapper:decode('Real','AngleInRadians',Bytes4),
-
- ?line {ok,Bytes5} = asn1_wrapper:encode('Real','AngleInRadians',{16#f1f1f1,2,128}),
- ?line {ok,{16#f1f1f1,2,128}} = asn1_wrapper:decode('Real','AngleInRadians',Bytes5),
+ real_roundtrip('AngleInRadians', {1,2,1}),
+ real_roundtrip('AngleInRadians', {129,2,1}),
+ real_roundtrip('AngleInRadians', {128,2,1}, {1,2,8}),
+ real_roundtrip('AngleInRadians', {128,2,-7}, {1,2,0}),
+ real_roundtrip('AngleInRadians', {16#f1f1f1,2,128}),
%% Base 10, tuple format
- ?line {ok,Bytes6} = asn1_wrapper:encode('Real','AngleInRadians',{1,10,1}),
- ?line {ok,"1.E1"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes6),
-
- ?line {ok,Bytes7} = asn1_wrapper:encode('Real','AngleInRadians',{100,10,1}),
- ?line {ok,"1.E3"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes7),
-
- ?line {ok,Bytes8} = asn1_wrapper:encode('Real','AngleInRadians',{-100,10,1}),
- ?line {ok,"-1.E3"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes8),
-
- ?line {ok,Bytes9} = asn1_wrapper:encode('Real','AngleInRadians',{00002,10,1}),
- ?line {ok,"2.E1"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes9),
-
- ?line {ok,Bytes10} = asn1_wrapper:encode('Real','AngleInRadians',{123000,10,0}),
- ?line {ok,"123.E3"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes10),
-
- ?line {ok,Bytes11} = asn1_wrapper:encode('Real','AngleInRadians',{123456789,10,123456789}),
- ?line {ok,"123456789.E123456789"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes11),
-
- ?line {ok,Bytes12} = asn1_wrapper:encode('Real','AngleInRadians',{-12345,10,-12345}),
- ?line {ok,"-12345.E-12345"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes12),
+ real_roundtrip('AngleInRadians', {1,10,1}, "1.E1"),
+ real_roundtrip('AngleInRadians', {100,10,1}, "1.E3"),
+ real_roundtrip('AngleInRadians', {-100,10,1}, "-1.E3"),
+ real_roundtrip('AngleInRadians', {2,10,1}, "2.E1"),
+ real_roundtrip('AngleInRadians', {123000,10,0}, "123.E3"),
+ real_roundtrip('AngleInRadians', {123456789,10,123456789},
+ "123456789.E123456789" ),
+ real_roundtrip('AngleInRadians', {-12345,10,-12345}, "-12345.E-12345"),
%% Base 10, string format NR3
-
- ?line {ok,Bytes13} = asn1_wrapper:encode('Real','AngleInRadians',"123.123E123"),
- ?line {ok,"123123.E120"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes13),
-
- ?line {ok,Bytes14} = asn1_wrapper:encode('Real','AngleInRadians',"0.0E0"),
- ?line {ok,"0.E+0"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes14),
-
- ?line {ok,Bytes15} = asn1_wrapper:encode('Real','AngleInRadians',"0.0123"),
- ?line {ok,"123.E-4"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes15),
- ?line {ok,Bytes16} = asn1_wrapper:encode('Real','AngleInRadians',"0"),
- ?line {ok,"0.E+0"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes16),
-
- ?line {ok,Bytes17} = asn1_wrapper:encode('Real','AngleInRadians',"-123.45"),
- ?line {ok,"-12345.E-2"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes17),
+ real_roundtrip('AngleInRadians', "123.123E123", "123123.E120"),
+ real_roundtrip('AngleInRadians', "0.0E0", "0.E+0"),
+ real_roundtrip('AngleInRadians', "0.0123", "123.E-4"),
+ real_roundtrip('AngleInRadians', "0", "0.E+0"),
+ real_roundtrip('AngleInRadians', "-123.45", "-12345.E-2"),
+ real_roundtrip('AngleInRadians', "123456789E123456789",
+ "123456789.E123456789"),
+ real_roundtrip('AngleInRadians', "01.000E1", "1.E1"),
+ real_roundtrip('AngleInRadians', "120.0001", "1200001.E-4"),
- ?line {ok,Bytes18} =
- asn1_wrapper:encode('Real','AngleInRadians',"123456789E123456789"),
- ?line {ok,"123456789.E123456789"} =
- asn1_wrapper:decode('Real','AngleInRadians',Bytes18),
+ ok.
- ?line {ok,Bytes19} = asn1_wrapper:encode('Real','AngleInRadians',"01.000E1"),
- ?line {ok,"1.E1"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes19),
+real_roundtrip(T, V) ->
+ real_roundtrip(T, V, V).
- ?line {ok,Bytes20} = asn1_wrapper:encode('Real','AngleInRadians',"120.0001"),
- ?line {ok,"1200001.E-4"} = asn1_wrapper:decode('Real','AngleInRadians',Bytes20).
+real_roundtrip(Type, Value, ExpectedValue) ->
+ case get(no_ok_wrapper) of
+ false ->
+ asn1_test_lib:roundtrip('Real', Type, Value, ExpectedValue);
+ true ->
+ M = 'Real',
+ ExpectedValue = M:decode(Type, M:encode(Type, Value)),
+ ok
+ end.