1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2001-2016. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20%% 21 22 23-module(testDeepTConstr). 24 25-export([main/1]). 26 27-include_lib("common_test/include/ct.hrl"). 28 29main(jer) -> ok; % Table constraints not JER visible 30main(_Erule) -> 31 Val1 = {substrings, 32 {'FilterItem_substrings', 33 {2,6}, 34 [{initial,"SE"}, 35 {any,"DK"}, 36 {final,"N"}]}}, 37 38 Val2 = {substrings, 39 {'FilterItem_substrings', 40 {2,6}, 41 [{initial,"SE"}, 42 {any,"DK"}, 43 {final,"NO"}]}}, 44 45 Reason = must_fail('TConstrChoice', 'FilterItem', Val1), 46 io:format("Reason: ~p~n~n",[Reason]), 47 {ok,Bytes2} = 'TConstrChoice':encode('FilterItem', Val2), 48 {ok,Res} = 'TConstrChoice':decode('FilterItem', Bytes2), 49 50 %% test of OTP-4248. 51 {ok,Bytes3} = 'TConstrChoice':encode('Seq', {'Seq',3,Bytes2}), 52 {ok,{'Seq',3,Bytes4}} = 'TConstrChoice':decode('Seq', Bytes3), 53 {ok,Res} = 'TConstrChoice':decode('FilterItem', Bytes4), 54 55 %% test of TConstr 56 57 Seq1Val = {'Seq1',{'Seq1_a',12,{2,4}}, 58 {'Seq1_b',13,{'Type-object1',14,true}}}, 59 roundtrip('TConstr', 'Seq1', Seq1Val), 60 61 62 Seq2Val = {'Seq2',123,{'Seq2_content',{2,6,7}, 63 {first,{'Type-object3_first',false,47}}, 64 false}}, 65 roundtrip('TConstr', 'Seq2', Seq2Val), 66 67 roundtrip('TConstr', 'Info', {'Info',{'Info_xyz',{1,2}},1234}), 68 69 roundtrip('TConstr', 'Deeper', 70 {'Deeper', 71 {'Deeper_a',12, 72 {'Deeper_a_s',{2,4},42}}, 73 {'Deeper_b',13,{'Type-object1',14,true}}}), 74 75 roundtrip('TConstr', 'Seq3', 76 {'Seq3', 77 {'Seq3_a',42,'TConstr':'id-object1'()}, 78 {'Seq3_b', 79 {'Type-object1',-777,true}, 80 12345, 81 {'Seq3_b_bc',12345789,{'Type-object1',-999,true}}}}), 82 roundtrip('TConstr', 'Seq3-Opt', 83 {'Seq3-Opt', 84 {'Seq3-Opt_a',42,'TConstr':'id-object1'()}, 85 {'Seq3-Opt_b', 86 {'Type-object1',-777,true}, 87 12345, 88 {'Seq3-Opt_b_bc',12345789,{'Type-object1',-999,true}}}}), 89 ok. 90 91 92roundtrip(M, T, V) -> 93 asn1_test_lib:roundtrip(M, T, V). 94 95%% Either encoding or decoding must fail. 96must_fail(M, T, V) -> 97 case M:encode(T, V) of 98 {ok,E} -> 99 {error,Reason} = M:decode(T, E), 100 Reason; 101 {error,Reason} -> 102 Reason 103 end. 104