1%%
2%% %CopyrightBegin%
3%%
4%% Copyright Ericsson AB 2001-2017. 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-module(testContextSwitchingTypes).
22
23-export([test/2]).
24
25-include_lib("common_test/include/ct.hrl").
26
27test(jer,_Config) -> ok;
28test(_Rule,Config) ->
29    ValT_1 = 'ContextSwitchingTypes':'val1-T'(),
30    check_EXTERNAL(enc_dec('T', ValT_1)),
31
32    ValT_2 = 'ContextSwitchingTypes':'val2-T'(),
33    check_EXTERNAL(enc_dec('T', ValT_2)),
34
35    ValT_3 = 'ContextSwitchingTypes':'val3-T'(),
36    check_EXTERNAL(enc_dec('T', ValT_3)),
37
38    ValT_4 = 'ContextSwitchingTypes':'val4-T'(),
39    check_EXTERNAL(enc_dec('T', ValT_4)),
40
41    {ok,ValT2} = asn1ct:value('ContextSwitchingTypes', 'T',
42			      [{i,proplists:get_value(case_dir, Config)}]),
43    io:format("ValT2 ~p~n",[ValT2]),
44    check_EXTERNAL(enc_dec('T', ValT2)),
45
46    ValEP = 'ContextSwitchingTypes':'val1-EP'(),
47    ValEPDec = enc_dec('EP', ValEP),
48    io:format("~p\n~p\n", [ValEP,ValEPDec]),
49
50    ValCS = 'ContextSwitchingTypes':'val1-CS'(),
51    ValCSDec = enc_dec('EP', ValCS),
52    io:format("~p\n~p\n", [ValCS,ValCSDec]),
53    ok.
54
55
56check_EXTERNAL({'EXTERNAL',Identif,DVD,DV})->
57    %% EXTERNAL in the 1994 format.
58    case Identif of
59	{'context-negotiation',_} ->
60	    ok;
61	{'presentation-context-id',Id} ->
62	    true = is_integer(Id);
63	{syntax,ObjId} ->
64	    check_object_identifier(ObjId)
65    end,
66    check_EXTERNAL_DVD(DVD),
67    check_EXTERNAL_DV(DV);
68check_EXTERNAL({'EXTERNAL',ObjId,IndirectRef,Descriptor,Enc})->
69    %% EXTERNAL in the 1990 format.
70    check_object_identifier(ObjId),
71    true = is_integer(IndirectRef),
72    true = is_binary(Descriptor) orelse is_list(Descriptor),
73    case Enc of
74	{arbitrary,_} -> ok;
75	{'single-ASN1-type',_} -> ok;
76	{'octet-aligned',_} -> ok
77    end.
78
79check_EXTERNAL_DVD(DVD) when is_list(DVD) -> ok;
80check_EXTERNAL_DVD(asn1_NOVALUE) -> ok.
81
82check_EXTERNAL_DV(DV) when is_list(DV); is_binary(DV) -> ok.
83
84check_object_identifier(Tuple) when is_tuple(Tuple) ->
85    %% An OBJECT IDENTIFIER is a tuple with integer elements.
86    case [E || E <- tuple_to_list(Tuple),
87	       not is_integer(E)] of
88	[] -> ok
89    end.
90
91enc_dec(T, V0) ->
92    M = 'ContextSwitchingTypes',
93    {ok,Enc} = M:encode(T, V0),
94    asn1_test_lib:map_roundtrip(M, T, Enc),
95    {ok,V} = M:decode(T, Enc),
96    V.
97