aboutsummaryrefslogtreecommitdiffstats
path: root/lib/asn1/test/testConstraints.erl
diff options
context:
space:
mode:
authorGustav Simonsson <[email protected]>2012-06-28 14:46:06 +0200
committerGustav Simonsson <[email protected]>2012-06-28 14:54:51 +0200
commit5fdcb7a097a3956ebf52c24721c91f60aeb96aa1 (patch)
treeba880be14ee3615ee3b88930a1ffdeb39d8e0b97 /lib/asn1/test/testConstraints.erl
parent67d2e30e77db74d0852421c21362d1a9374780e1 (diff)
downloadotp-5fdcb7a097a3956ebf52c24721c91f60aeb96aa1.tar.gz
otp-5fdcb7a097a3956ebf52c24721c91f60aeb96aa1.tar.bz2
otp-5fdcb7a097a3956ebf52c24721c91f60aeb96aa1.zip
Add support for larger integer ranges in per encode/decode
Encoding and decoding of integer ranges can now be done with an upper bound larger than the previous limit of 16^10. The new upper bound in per encoding and decodings for constrained whole numbers is 2^2040 (close to 16^508) which is the limit if the length field encoding in the encoding of a constrained whole number is limited to a single octet. Related support seq: seq12060
Diffstat (limited to 'lib/asn1/test/testConstraints.erl')
-rw-r--r--lib/asn1/test/testConstraints.erl62
1 files changed, 58 insertions, 4 deletions
diff --git a/lib/asn1/test/testConstraints.erl b/lib/asn1/test/testConstraints.erl
index 1ce68ec522..d32e99eaaf 100644
--- a/lib/asn1/test/testConstraints.erl
+++ b/lib/asn1/test/testConstraints.erl
@@ -52,8 +52,6 @@ int_constraints(Rules) ->
?line {error,_Reason2} =
asn1_wrapper:encode('Constraints','SingleValue',1000)
end,
-
-
%%==========================================================
%% SingleValue2 ::= INTEGER (1..20)
@@ -86,8 +84,6 @@ int_constraints(Rules) ->
asn1_wrapper:encode('Constraints','SingleValue',1000)
end,
-
-
%%==========================================================
%% Range2to19 ::= INTEGER (1<..<20)
%%==========================================================
@@ -116,7 +112,65 @@ int_constraints(Rules) ->
?line {error,_Reason6} =
asn1_wrapper:encode('Constraints','Range2to19',20)
end,
+
+ %%==========================================================
+ %% Tests for Range above 16^4 up to maximum supported by asn1 assuming the
+ %% octet length field is encoded on max 8 bits
+ %%==========================================================
+ LastNumWithoutLengthEncoding = 65536,
+ ?line {ok,BytesFoo} = asn1_wrapper:encode('Constraints','Range256to65536',
+ LastNumWithoutLengthEncoding),
+ ?line {ok,LastNumWithoutLengthEncoding} =
+ asn1_wrapper:decode('Constraints','Range256to65536',lists:flatten(BytesFoo)),
+
+ FirstNumWithLengthEncoding = 65537,
+ ?line {ok,BytesBar} = asn1_wrapper:encode('LargeConstraints','RangeMax',
+ FirstNumWithLengthEncoding),
+ ?line {ok,FirstNumWithLengthEncoding} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesBar)),
+
+ FirstNumOver16_6 = 16777217,
+ ?line {ok, BytesBaz} =
+ asn1_wrapper:encode('LargeConstraints','RangeMax', FirstNumOver16_6),
+ ?line {ok, FirstNumOver16_6} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesBaz)),
+
+ FirstNumOver16_8 = 4294967297,
+ ?line {ok, BytesQux} =
+ asn1_wrapper:encode('LargeConstraints','RangeMax', FirstNumOver16_8),
+ ?line {ok, FirstNumOver16_8} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesQux)),
+
+ FirstNumOver16_10 = 1099511627776,
+ ?line {ok, BytesBur} =
+ asn1_wrapper:encode('LargeConstraints','RangeMax', FirstNumOver16_10),
+ ?line {ok, FirstNumOver16_10} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesBur)),
+
+ FirstNumOver16_10 = 1099511627776,
+ ?line {ok, BytesBur} =
+ asn1_wrapper:encode('LargeConstraints','RangeMax', FirstNumOver16_10),
+ ?line {ok, FirstNumOver16_10} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesBur)),
+
+ HalfMax = 1 bsl (128*8),
+ ?line {ok, BytesHalfMax} =
+ asn1_wrapper:encode('LargeConstraints','RangeMax', HalfMax),
+ ?line {ok, HalfMax} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesHalfMax)),
+
+ Max = 1 bsl (255*8),
+ ?line {ok, BytesMax} =
+ asn1_wrapper:encode('LargeConstraints','RangeMax', Max),
+ ?line {ok, Max} =
+ asn1_wrapper:decode('LargeConstraints','RangeMax',lists:flatten(BytesMax)),
+ %% Random number within longlong range
+ LongLong = 12672809400538808320,
+ ?line {ok, BytesLongLong} =
+ asn1_wrapper:encode('Constraints','LongLong', LongLong),
+ ?line {ok, LongLong} =
+ asn1_wrapper:decode('Constraints','LongLong',lists:flatten(BytesLongLong)),
%%==========================================================
%% Constraint Combinations (Duboisson p. 285)